Change ProjectSettings to Singleton interface
Signed-off-by: nggieber <52797929+AMZN-nggieber@users.noreply.github.com>
This commit is contained in:
@@ -111,6 +111,14 @@ namespace O3DE::ProjectManager
|
||||
}
|
||||
}
|
||||
|
||||
m_settings = AZStd::make_unique<Settings>();
|
||||
AZ_Assert(m_settings, "Failed to create Settings");
|
||||
|
||||
if (!m_settings->IsInitialized())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const AZ::CommandLine* commandLine = GetCommandLine();
|
||||
AZ_Assert(commandLine, "Failed to get command line");
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <AzFramework/Application/Application.h>
|
||||
#include <QCoreApplication>
|
||||
#include <PythonBindings.h>
|
||||
#include <Settings.h>
|
||||
#include <ProjectManagerWindow.h>
|
||||
#endif
|
||||
|
||||
@@ -36,6 +37,7 @@ namespace O3DE::ProjectManager
|
||||
bool InitLog(const char* logName);
|
||||
|
||||
AZStd::unique_ptr<PythonBindings> m_pythonBindings;
|
||||
AZStd::unique_ptr<Settings> m_settings;
|
||||
QSharedPointer<QCoreApplication> m_app;
|
||||
QSharedPointer<ProjectManagerWindow> m_mainWindow;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <ExternalLinkDialog.h>
|
||||
#include <LinkWidget.h>
|
||||
#include <ProjectManagerSettings.h>
|
||||
#include <SettingsInterface.h>
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
@@ -85,6 +85,7 @@ namespace O3DE::ProjectManager
|
||||
|
||||
void ExternalLinkDialog::SetSkipDialogSetting(bool state)
|
||||
{
|
||||
PMSettings::SetProjectManagerKey(PMSettings::GetExternalLinkWarningKey(), state);
|
||||
auto settings = SettingsInterface::Get();
|
||||
settings->Set(QString(settings->ExternalLinkWarningKey), state);
|
||||
}
|
||||
} // namespace O3DE::ProjectManager
|
||||
|
||||
@@ -8,9 +8,7 @@
|
||||
|
||||
#include <LinkWidget.h>
|
||||
#include <ExternalLinkDialog.h>
|
||||
#include <ProjectManagerSettings.h>
|
||||
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <SettingsInterface.h>
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QEvent>
|
||||
@@ -33,7 +31,8 @@ namespace O3DE::ProjectManager
|
||||
{
|
||||
// Check if user request not to be shown external link warning dialog
|
||||
bool skipDialog = false;
|
||||
PMSettings::GetProjectManagerKey(skipDialog, PMSettings::GetExternalLinkWarningKey());
|
||||
auto settings = SettingsInterface::Get();
|
||||
settings->Get(skipDialog, QString(settings->ExternalLinkWarningKey));
|
||||
|
||||
if (!skipDialog)
|
||||
{
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
#include <ProjectBuilderController.h>
|
||||
#include <ProjectBuilderWorker.h>
|
||||
#include <ProjectButtonWidget.h>
|
||||
#include <ProjectManagerSettings.h>
|
||||
|
||||
#include <AzCore/Settings/SettingsRegistry.h>
|
||||
#include <SettingsInterface.h>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QDesktopServices>
|
||||
@@ -30,7 +28,7 @@ namespace O3DE::ProjectManager
|
||||
m_worker->moveToThread(&m_workerThread);
|
||||
|
||||
// Remove key here in case Project Manager crashing while building that causes HandleResults to not be called
|
||||
PMSettings::SetProjectBuiltSuccessfully(m_projectInfo, false);
|
||||
SettingsInterface::Get()->SetProjectBuiltSuccessfully(m_projectInfo, false);
|
||||
|
||||
connect(&m_workerThread, &QThread::finished, m_worker, &ProjectBuilderWorker::deleteLater);
|
||||
connect(&m_workerThread, &QThread::started, m_worker, &ProjectBuilderWorker::BuildProject);
|
||||
@@ -114,7 +112,7 @@ namespace O3DE::ProjectManager
|
||||
emit NotifyBuildProject(m_projectInfo);
|
||||
}
|
||||
|
||||
PMSettings::SetProjectBuiltSuccessfully(m_projectInfo, false);
|
||||
SettingsInterface::Get()->SetProjectBuiltSuccessfully(m_projectInfo, false);
|
||||
|
||||
emit Done(false);
|
||||
return;
|
||||
@@ -123,7 +121,7 @@ namespace O3DE::ProjectManager
|
||||
{
|
||||
m_projectInfo.m_buildFailed = false;
|
||||
|
||||
PMSettings::SetProjectBuiltSuccessfully(m_projectInfo, true);
|
||||
SettingsInterface::Get()->SetProjectBuiltSuccessfully(m_projectInfo, true);
|
||||
}
|
||||
|
||||
emit Done(true);
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <ProjectManagerSettings.h>
|
||||
|
||||
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
||||
#include <AzCore/IO/ByteContainerStream.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
namespace PMSettings
|
||||
{
|
||||
bool SaveProjectManagerSettings()
|
||||
{
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
AZ::SettingsRegistryMergeUtils::DumperSettings dumperSettings;
|
||||
dumperSettings.m_prettifyOutput = true;
|
||||
dumperSettings.m_jsonPointerPrefix = ProjectManagerKeyPrefix;
|
||||
|
||||
AZStd::string stringBuffer;
|
||||
AZ::IO::ByteContainerStream stringStream(&stringBuffer);
|
||||
if (!AZ::SettingsRegistryMergeUtils::DumpSettingsRegistryToStream(
|
||||
*settingsRegistry, ProjectManagerKeyPrefix, stringStream, dumperSettings))
|
||||
{
|
||||
AZ_Warning("ProjectManager", false, "Could not save Project Manager settings to stream");
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::IO::FixedMaxPath o3deUserPath = AZ::Utils::GetO3deManifestDirectory();
|
||||
o3deUserPath /= AZ::SettingsRegistryInterface::RegistryFolder;
|
||||
o3deUserPath /= "ProjectManager.setreg";
|
||||
|
||||
bool saved = false;
|
||||
constexpr auto configurationMode =
|
||||
AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY;
|
||||
|
||||
AZ::IO::SystemFile outputFile;
|
||||
if (outputFile.Open(o3deUserPath.c_str(), configurationMode))
|
||||
{
|
||||
saved = outputFile.Write(stringBuffer.data(), stringBuffer.size()) == stringBuffer.size();
|
||||
}
|
||||
|
||||
AZ_Warning("ProjectManager", saved, "Unable to save Project Manager registry file to path: %s", o3deUserPath.c_str());
|
||||
return saved;
|
||||
}
|
||||
|
||||
bool GetProjectManagerKey(QString& result, const QString& settingsKey)
|
||||
{
|
||||
bool success = false;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
AZStd::string settingsValue;
|
||||
success = settingsRegistry->Get(settingsValue, settingsKey.toStdString().c_str());
|
||||
|
||||
result = settingsValue.c_str();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool GetProjectManagerKey(bool& result, const QString& settingsKey)
|
||||
{
|
||||
bool success = false;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
success = settingsRegistry->Get(result, settingsKey.toStdString().c_str());
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SetProjectManagerKey(const QString& settingsKey, const QString& settingsValue, bool saveToDisk)
|
||||
{
|
||||
bool success = false;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
success = settingsRegistry->Set(settingsKey.toStdString().c_str(), settingsValue.toStdString().c_str());
|
||||
|
||||
if (saveToDisk)
|
||||
{
|
||||
SaveProjectManagerSettings();
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SetProjectManagerKey(const QString& settingsKey, bool settingsValue, bool saveToDisk)
|
||||
{
|
||||
bool success = false;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
success = settingsRegistry->Set(settingsKey.toStdString().c_str(), settingsValue);
|
||||
|
||||
if (saveToDisk)
|
||||
{
|
||||
SaveProjectManagerSettings();
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool RemoveProjectManagerKey(const QString& settingsKey, bool saveToDisk)
|
||||
{
|
||||
bool success = false;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
success = settingsRegistry->Remove(settingsKey.toStdString().c_str());
|
||||
|
||||
if (saveToDisk)
|
||||
{
|
||||
SaveProjectManagerSettings();
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool CopyProjectManagerKeyString(const QString& settingsKeyOrig, const QString& settingsKeyDest, bool removeOrig, bool saveToDisk)
|
||||
{
|
||||
bool success = false;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
AZStd::string settingsValue;
|
||||
success = settingsRegistry->Get(settingsValue, settingsKeyOrig.toStdString().c_str());
|
||||
|
||||
if (success)
|
||||
{
|
||||
success = settingsRegistry->Set(settingsKeyDest.toStdString().c_str(), settingsValue);
|
||||
if (success)
|
||||
{
|
||||
if (removeOrig)
|
||||
{
|
||||
success = settingsRegistry->Remove(settingsKeyOrig.toStdString().c_str());
|
||||
}
|
||||
|
||||
if (saveToDisk)
|
||||
{
|
||||
SaveProjectManagerSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
QString GetProjectKey(const ProjectInfo& projectInfo)
|
||||
{
|
||||
return QString("%1/Projects/%2/%3").arg(ProjectManagerKeyPrefix, projectInfo.m_id, projectInfo.m_projectName);
|
||||
}
|
||||
|
||||
QString GetExternalLinkWarningKey()
|
||||
{
|
||||
return QString("%1/SkipExternalLinkWarning").arg(ProjectManagerKeyPrefix);
|
||||
}
|
||||
|
||||
QString GetProjectsBuiltSuccessfullyKey()
|
||||
{
|
||||
return QString("%1/SuccessfulBuildPaths").arg(ProjectManagerKeyPrefix);
|
||||
}
|
||||
|
||||
bool GetBuiltSuccessfullyPaths(AZStd::set<AZStd::string>& result)
|
||||
{
|
||||
bool success = false;
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
QString builtKey = GetProjectsBuiltSuccessfullyKey();
|
||||
success = settingsRegistry->GetObject<AZStd::set<AZStd::string>>(result, builtKey.toStdString().c_str());
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool GetProjectBuiltSuccessfully(bool& result, const ProjectInfo& projectInfo)
|
||||
{
|
||||
AZStd::set<AZStd::string> builtPathsResult;
|
||||
bool success = GetBuiltSuccessfullyPaths(builtPathsResult);
|
||||
if (success)
|
||||
{
|
||||
// Check if buildPath is listed as successfully built
|
||||
AZStd::string projectPath = projectInfo.m_path.toStdString().c_str();
|
||||
if (builtPathsResult.contains(projectPath))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
// No project built statuses known
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool SetProjectBuiltSuccessfully(const ProjectInfo& projectInfo, bool successfullyBuilt, bool saveToDisk)
|
||||
{
|
||||
AZStd::set<AZStd::string> builtPathsResult;
|
||||
bool success = GetBuiltSuccessfullyPaths(builtPathsResult);
|
||||
|
||||
AZStd::string projectPath = projectInfo.m_path.toStdString().c_str();
|
||||
if (successfullyBuilt)
|
||||
{
|
||||
//Add successfully built path to set
|
||||
builtPathsResult.insert(projectPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove unsuccessfully built path from set
|
||||
builtPathsResult.erase(projectPath);
|
||||
}
|
||||
|
||||
auto settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
if (settingsRegistry)
|
||||
{
|
||||
QString builtKey = GetProjectsBuiltSuccessfullyKey();
|
||||
success = settingsRegistry->SetObject<AZStd::set<AZStd::string>>(builtKey.toStdString().c_str(), builtPathsResult);
|
||||
|
||||
if (saveToDisk)
|
||||
{
|
||||
SaveProjectManagerSettings();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
} // namespace PMSettings
|
||||
} // namespace O3DE::ProjectManager
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QStringList>
|
||||
#include <ProjectInfo.h>
|
||||
#endif
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
namespace PMSettings
|
||||
{
|
||||
static constexpr char ProjectManagerKeyPrefix[] = "/O3DE/ProjectManager";
|
||||
|
||||
bool SaveProjectManagerSettings();
|
||||
bool GetProjectManagerKey(QString& result, const QString& settingsKey);
|
||||
bool GetProjectManagerKey(bool& result, const QString& settingsKey);
|
||||
bool SetProjectManagerKey(const QString& settingsKey, const QString& settingsValue, bool saveToDisk = true);
|
||||
bool SetProjectManagerKey(const QString& settingsKey, bool settingsValue, bool saveToDisk = true);
|
||||
bool RemoveProjectManagerKey(const QString& settingsKey, bool saveToDisk = true);
|
||||
bool CopyProjectManagerKeyString(
|
||||
const QString& settingsKeyOrig, const QString& settingsKeyDest, bool removeOrig = false, bool saveToDisk = true);
|
||||
|
||||
QString GetProjectKey(const ProjectInfo& projectInfo);
|
||||
QString GetExternalLinkWarningKey();
|
||||
|
||||
bool GetProjectBuiltSuccessfully(bool& result, const ProjectInfo& projectInfo);
|
||||
bool SetProjectBuiltSuccessfully(const ProjectInfo& projectInfo, bool successfullyBuilt, bool saveToDisk = true);
|
||||
} // namespace PMSettings
|
||||
} // namespace O3DE::ProjectManager
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <ProjectUtils.h>
|
||||
#include <ProjectBuilderController.h>
|
||||
#include <ScreensCtrl.h>
|
||||
#include <ProjectManagerSettings.h>
|
||||
#include <SettingsInterface.h>
|
||||
|
||||
#include <AzQtComponents/Components/FlowLayout.h>
|
||||
#include <AzCore/Platform.h>
|
||||
@@ -292,7 +292,7 @@ namespace O3DE::ProjectManager
|
||||
if (currentButton)
|
||||
{
|
||||
bool projectBuiltSuccessfully = false;
|
||||
PMSettings::GetProjectBuiltSuccessfully(projectBuiltSuccessfully, project);
|
||||
SettingsInterface::Get()->GetProjectBuiltSuccessfully(projectBuiltSuccessfully, project);
|
||||
|
||||
if (!projectBuiltSuccessfully)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Settings.h>
|
||||
|
||||
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
|
||||
#include <AzCore/IO/ByteContainerStream.h>
|
||||
#include <AzCore/Utils/Utils.h>
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
Settings::Settings(bool saveToDisk)
|
||||
: m_saveToDisk(saveToDisk)
|
||||
{
|
||||
m_settingsRegistry = AZ::SettingsRegistry::Get();
|
||||
|
||||
AZ_Assert(m_settingsRegistry, "Failed to create Settings");
|
||||
}
|
||||
|
||||
bool Settings::IsInitialized()
|
||||
{
|
||||
// Settings intialized correctly if it successfuly got the SettingsRegistry
|
||||
return m_settingsRegistry;
|
||||
}
|
||||
|
||||
bool Settings::Save()
|
||||
{
|
||||
AZ::SettingsRegistryMergeUtils::DumperSettings dumperSettings;
|
||||
dumperSettings.m_prettifyOutput = true;
|
||||
dumperSettings.m_jsonPointerPrefix = ProjectManagerKeyPrefix;
|
||||
|
||||
AZStd::string stringBuffer;
|
||||
AZ::IO::ByteContainerStream stringStream(&stringBuffer);
|
||||
if (!AZ::SettingsRegistryMergeUtils::DumpSettingsRegistryToStream(
|
||||
*m_settingsRegistry, ProjectManagerKeyPrefix, stringStream, dumperSettings))
|
||||
{
|
||||
AZ_Warning("ProjectManager", false, "Could not save Project Manager settings to stream");
|
||||
return false;
|
||||
}
|
||||
|
||||
AZ::IO::FixedMaxPath o3deUserPath = AZ::Utils::GetO3deManifestDirectory();
|
||||
o3deUserPath /= AZ::SettingsRegistryInterface::RegistryFolder;
|
||||
o3deUserPath /= "ProjectManager.setreg";
|
||||
|
||||
bool saved = false;
|
||||
constexpr auto configurationMode =
|
||||
AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY;
|
||||
|
||||
AZ::IO::SystemFile outputFile;
|
||||
if (outputFile.Open(o3deUserPath.c_str(), configurationMode))
|
||||
{
|
||||
saved = outputFile.Write(stringBuffer.data(), stringBuffer.size()) == stringBuffer.size();
|
||||
}
|
||||
|
||||
AZ_Warning("ProjectManager", saved, "Unable to save Project Manager registry file to path: %s", o3deUserPath.c_str());
|
||||
return saved;
|
||||
}
|
||||
|
||||
bool Settings::Get(QString& result, const QString& settingsKey)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
AZStd::string settingsValue;
|
||||
success = m_settingsRegistry->Get(settingsValue, settingsKey.toStdString().c_str());
|
||||
|
||||
result = settingsValue.c_str();
|
||||
return success;
|
||||
}
|
||||
|
||||
bool Settings::Get(bool& result, const QString& settingsKey)
|
||||
{
|
||||
return m_settingsRegistry->Get(result, settingsKey.toStdString().c_str());
|
||||
}
|
||||
|
||||
bool Settings::Set(const QString& settingsKey, const QString& settingsValue)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
success = m_settingsRegistry->Set(settingsKey.toStdString().c_str(), settingsValue.toStdString().c_str());
|
||||
if (m_saveToDisk)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool Settings::Set(const QString& settingsKey, bool settingsValue)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
success = m_settingsRegistry->Set(settingsKey.toStdString().c_str(), settingsValue);
|
||||
if (m_saveToDisk)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool Settings::Remove(const QString& settingsKey)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
success = m_settingsRegistry->Remove(settingsKey.toStdString().c_str());
|
||||
if (m_saveToDisk)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool Settings::Copy(const QString& settingsKeyOrig, const QString& settingsKeyDest, bool removeOrig)
|
||||
{
|
||||
bool success = false;
|
||||
AZStd::string settingsValue;
|
||||
|
||||
success = m_settingsRegistry->Get(settingsValue, settingsKeyOrig.toStdString().c_str());
|
||||
|
||||
if (success)
|
||||
{
|
||||
success = m_settingsRegistry->Set(settingsKeyDest.toStdString().c_str(), settingsValue);
|
||||
if (success)
|
||||
{
|
||||
if (removeOrig)
|
||||
{
|
||||
success = m_settingsRegistry->Remove(settingsKeyOrig.toStdString().c_str());
|
||||
}
|
||||
if (m_saveToDisk)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
QString Settings::GetProjectKey(const ProjectInfo& projectInfo)
|
||||
{
|
||||
return QString("%1/Projects/%2/%3").arg(ProjectManagerKeyPrefix, projectInfo.m_id, projectInfo.m_projectName);
|
||||
}
|
||||
|
||||
bool Settings::GetBuiltSuccessfullyPaths(AZStd::set<AZStd::string>& result)
|
||||
{
|
||||
return m_settingsRegistry->GetObject<AZStd::set<AZStd::string>>(result, ProjectsBuiltSuccessfullyKey);
|
||||
}
|
||||
|
||||
bool Settings::GetProjectBuiltSuccessfully(bool& result, const ProjectInfo& projectInfo)
|
||||
{
|
||||
AZStd::set<AZStd::string> builtPathsResult;
|
||||
bool success = GetBuiltSuccessfullyPaths(builtPathsResult);
|
||||
|
||||
// Check if buildPath is listed as successfully built
|
||||
AZStd::string projectPath = projectInfo.m_path.toStdString().c_str();
|
||||
if (builtPathsResult.contains(projectPath))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
// No project built statuses known
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
bool Settings::SetProjectBuiltSuccessfully(const ProjectInfo& projectInfo, bool successfullyBuilt)
|
||||
{
|
||||
AZStd::set<AZStd::string> builtPathsResult;
|
||||
bool success = GetBuiltSuccessfullyPaths(builtPathsResult);
|
||||
|
||||
AZStd::string projectPath = projectInfo.m_path.toStdString().c_str();
|
||||
if (successfullyBuilt)
|
||||
{
|
||||
//Add successfully built path to set
|
||||
builtPathsResult.insert(projectPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove unsuccessfully built path from set
|
||||
builtPathsResult.erase(projectPath);
|
||||
}
|
||||
|
||||
success = m_settingsRegistry->SetObject<AZStd::set<AZStd::string>>(ProjectsBuiltSuccessfullyKey, builtPathsResult);
|
||||
if (m_saveToDisk)
|
||||
{
|
||||
Save();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
} // namespace O3DE::ProjectManager
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SettingsInterface.h>
|
||||
|
||||
#include <AzCore/std/containers/set.h>
|
||||
|
||||
namespace AZ
|
||||
{
|
||||
class SettingsRegistryInterface;
|
||||
}
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
class Settings
|
||||
: public SettingsInterface::Registrar
|
||||
{
|
||||
public:
|
||||
Settings(bool saveToDisk = true);
|
||||
|
||||
bool IsInitialized() override;
|
||||
|
||||
bool Get(QString& result, const QString& settingsKey) override;
|
||||
bool Get(bool& result, const QString& settingsKey) override;
|
||||
bool Set(const QString& settingsKey, const QString& settingsValue) override;
|
||||
bool Set(const QString& settingsKey, bool settingsValue) override;
|
||||
bool Remove(const QString& settingsKey) override;
|
||||
bool Copy(const QString& settingsKeyOrig, const QString& settingsKeyDest, bool removeOrig = false) override;
|
||||
|
||||
QString GetProjectKey(const ProjectInfo& projectInfo) override;
|
||||
|
||||
bool GetProjectBuiltSuccessfully(bool& result, const ProjectInfo& projectInfo) override;
|
||||
bool SetProjectBuiltSuccessfully(const ProjectInfo& projectInfo, bool successfullyBuilt) override;
|
||||
|
||||
private:
|
||||
bool Save();
|
||||
|
||||
bool GetBuiltSuccessfullyPaths(AZStd::set<AZStd::string>& result);
|
||||
|
||||
bool m_saveToDisk;
|
||||
AZ::SettingsRegistryInterface* m_settingsRegistry = nullptr;
|
||||
};
|
||||
} // namespace O3DE::ProjectManager
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <ProjectInfo.h>
|
||||
|
||||
#include <AzCore/EBus/EBus.h>
|
||||
#include <AzCore/Interface/Interface.h>
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
//! Interface used to interact with the settings functions
|
||||
class ISettings
|
||||
{
|
||||
public:
|
||||
AZ_RTTI(O3DE::ProjectManager::ISettings, "{95D87D95-0E04-462F-8B0B-ED15C0A9F090}");
|
||||
AZ_DISABLE_COPY_MOVE(ISettings);
|
||||
|
||||
static constexpr char ProjectManagerKeyPrefix[] = "/O3DE/ProjectManager";
|
||||
static constexpr char ExternalLinkWarningKey[] = "/O3DE/ProjectManager/SkipExternalLinkWarning";
|
||||
static constexpr char ProjectsBuiltSuccessfullyKey[] = "/O3DE/ProjectManager/SkipExternalLinkWarning";
|
||||
|
||||
ISettings() = default;
|
||||
virtual ~ISettings() = default;
|
||||
|
||||
/**
|
||||
* This checks if Settings is in a usable state
|
||||
* @return true Settings is ready to be used, false otherwise
|
||||
*/
|
||||
virtual bool IsInitialized() = 0;
|
||||
|
||||
/**
|
||||
* Get info about a Gem.
|
||||
* @param path The absolute path to the Gem
|
||||
* @param projectPath (Optional) The absolute path to the Gem project
|
||||
* @return an outcome with GemInfo on success
|
||||
*/
|
||||
virtual bool Get(QString& result, const QString& settingsKey) = 0;
|
||||
virtual bool Get(bool& result, const QString& settingsKey) = 0;
|
||||
virtual bool Set(const QString& settingsKey, const QString& settingsValue) = 0;
|
||||
virtual bool Set(const QString& settingsKey, bool settingsValue) = 0;
|
||||
virtual bool Remove(const QString& settingsKey) = 0;
|
||||
virtual bool Copy(const QString& settingsKeyOrig, const QString& settingsKeyDest, bool removeOrig = false) = 0;
|
||||
|
||||
virtual QString GetProjectKey(const ProjectInfo& projectInfo) = 0;
|
||||
|
||||
virtual bool GetProjectBuiltSuccessfully(bool& result, const ProjectInfo& projectInfo) = 0;
|
||||
virtual bool SetProjectBuiltSuccessfully(const ProjectInfo& projectInfo, bool successfullyBuilt) = 0;
|
||||
};
|
||||
|
||||
using SettingsInterface = AZ::Interface<ISettings>;
|
||||
} // namespace O3DE::ProjectManager
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <UpdateProjectSettingsScreen.h>
|
||||
#include <ProjectUtils.h>
|
||||
#include <DownloadController.h>
|
||||
#include <ProjectManagerSettings.h>
|
||||
#include <SettingsInterface.h>
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QMessageBox>
|
||||
@@ -307,8 +307,9 @@ namespace O3DE::ProjectManager
|
||||
{
|
||||
// Remove project build successfully paths for both old and new project names
|
||||
// because a full rebuild is required when moving projects
|
||||
PMSettings::SetProjectBuiltSuccessfully(m_projectInfo, false);
|
||||
PMSettings::SetProjectBuiltSuccessfully(newProjectSettings, false);
|
||||
auto settings = SettingsInterface::Get();
|
||||
settings->SetProjectBuiltSuccessfully(m_projectInfo, false);
|
||||
settings->SetProjectBuiltSuccessfully(newProjectSettings, false);
|
||||
}
|
||||
|
||||
if (!newProjectSettings.m_newPreviewImagePath.isEmpty())
|
||||
|
||||
@@ -58,8 +58,6 @@ set(FILES
|
||||
Source/CreateProjectCtrl.cpp
|
||||
Source/UpdateProjectCtrl.h
|
||||
Source/UpdateProjectCtrl.cpp
|
||||
Source/ProjectManagerSettings.h
|
||||
Source/ProjectManagerSettings.cpp
|
||||
Source/ProjectsScreen.h
|
||||
Source/ProjectsScreen.cpp
|
||||
Source/ProjectSettingsScreen.h
|
||||
@@ -72,6 +70,9 @@ set(FILES
|
||||
Source/ProjectButtonWidget.cpp
|
||||
Source/ScreenHeaderWidget.h
|
||||
Source/ScreenHeaderWidget.cpp
|
||||
Source/Settings.h
|
||||
Source/Settings.cpp
|
||||
Source/SettingsInterface.h
|
||||
Source/LinkWidget.h
|
||||
Source/LinkWidget.cpp
|
||||
Source/TagWidget.h
|
||||
|
||||
@@ -11,7 +11,7 @@ set(FILES
|
||||
Resources/ProjectManager.qss
|
||||
tests/ApplicationTests.cpp
|
||||
tests/GemCatalogTests.cpp
|
||||
tests/ProjectManagerSettingsTests.cpp
|
||||
tests/SettingsTests.cpp
|
||||
tests/PythonBindingsTests.cpp
|
||||
tests/main.cpp
|
||||
tests/UtilsTests.cpp
|
||||
|
||||
+45
-35
@@ -13,15 +13,15 @@
|
||||
#include <AzCore/UnitTest/TestTypes.h>
|
||||
#include <AzTest/Utils.h>
|
||||
|
||||
#include <ProjectManagerSettings.h>
|
||||
#include <Settings.h>
|
||||
|
||||
namespace O3DE::ProjectManager
|
||||
{
|
||||
class ProjectManagerSettingsTests
|
||||
class SettingsTests
|
||||
: public ::UnitTest::ScopedAllocatorSetupFixture
|
||||
{
|
||||
public:
|
||||
~ProjectManagerSettingsTests() override = default;
|
||||
~SettingsTests() override = default;
|
||||
void SetUp() override
|
||||
{
|
||||
UnitTest::ScopedAllocatorSetupFixture::SetUp();
|
||||
@@ -45,11 +45,15 @@ namespace O3DE::ProjectManager
|
||||
|
||||
m_serializeContext->RegisterGenericType<AZStd::set<AZStd::string>>();
|
||||
|
||||
m_settings = AZStd::make_unique<Settings>(/*saveToDisk*/ false);
|
||||
|
||||
m_projectInfo.m_path = "Z:/ProjectTestPath";
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
m_settings.reset();
|
||||
|
||||
m_registrationContext->EnableRemoveReflection();
|
||||
AZ::JsonSystemComponent::Reflect(m_registrationContext.get());
|
||||
m_registrationContext->DisableRemoveReflection();
|
||||
@@ -70,6 +74,7 @@ namespace O3DE::ProjectManager
|
||||
}
|
||||
|
||||
protected:
|
||||
AZStd::unique_ptr<Settings> m_settings;
|
||||
const QString m_settingsPath = "/Testing/TestKey";
|
||||
const QString m_newSettingsPath = "/Testing/NewTestKey";
|
||||
ProjectInfo m_projectInfo;
|
||||
@@ -81,105 +86,110 @@ namespace O3DE::ProjectManager
|
||||
AZStd::unique_ptr<AZ::JsonRegistrationContext> m_registrationContext;
|
||||
};
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_GetUnsetPathBool_ReturnsFalse)
|
||||
TEST_F(SettingsTests, Settings_IsIntialized_Success)
|
||||
{
|
||||
EXPECT_TRUE(m_settings->IsInitialized());
|
||||
}
|
||||
|
||||
TEST_F(SettingsTests, Settings_GetUnsetPathBool_ReturnsFalse)
|
||||
{
|
||||
bool settingsResult = false;
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
EXPECT_FALSE(settingsResult);
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_SetAndGetValueBool_Success)
|
||||
TEST_F(SettingsTests, Settings_SetAndGetValueBool_Success)
|
||||
{
|
||||
bool settingsResult = false;
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
|
||||
// Don't save to disk in test
|
||||
EXPECT_TRUE(PMSettings::SetProjectManagerKey(m_settingsPath, true, /*saveToDisk*/ false));
|
||||
EXPECT_TRUE(m_settings->Set(m_settingsPath, true));
|
||||
|
||||
settingsResult = false;
|
||||
EXPECT_TRUE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_TRUE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
EXPECT_TRUE(settingsResult);
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_GetUnsetPathString_ReturnsFalse)
|
||||
TEST_F(SettingsTests, Settings_GetUnsetPathString_ReturnsFalse)
|
||||
{
|
||||
QString settingsResult;
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
EXPECT_TRUE(settingsResult.isEmpty());
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_SetAndGetValueString_Success)
|
||||
TEST_F(SettingsTests, Settings_SetAndGetValueString_Success)
|
||||
{
|
||||
QString settingsResult;
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
|
||||
QString settingsValue = "TestValue";
|
||||
|
||||
// Don't save to disk in test
|
||||
EXPECT_TRUE(PMSettings::SetProjectManagerKey(m_settingsPath, settingsValue, /*saveToDisk*/ false));
|
||||
EXPECT_TRUE(m_settings->Set(m_settingsPath, settingsValue));
|
||||
|
||||
EXPECT_TRUE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_TRUE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
EXPECT_TRUE(settingsResult == settingsValue);
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_CopyStringRemoveOriginal_SuccessAndRemovesOriginal)
|
||||
TEST_F(SettingsTests, Settings_CopyStringRemoveOriginal_SuccessAndRemovesOriginal)
|
||||
{
|
||||
QString settingsResult;
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_newSettingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_newSettingsPath));
|
||||
|
||||
QString settingsValue = "TestValue";
|
||||
|
||||
// Don't save to disk in test
|
||||
EXPECT_TRUE(PMSettings::SetProjectManagerKey(m_settingsPath, settingsValue, /*saveToDisk*/ false));
|
||||
EXPECT_TRUE(m_settings->Set(m_settingsPath, settingsValue));
|
||||
|
||||
EXPECT_TRUE(PMSettings::CopyProjectManagerKeyString(m_settingsPath, m_newSettingsPath, /*removeOrig*/ true, /*saveToDisk*/ false));
|
||||
EXPECT_TRUE(m_settings->Copy(m_settingsPath, m_newSettingsPath, /*removeOrig*/ true));
|
||||
|
||||
// Check that old path value is removed
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
|
||||
EXPECT_TRUE(PMSettings::GetProjectManagerKey(settingsResult, m_newSettingsPath));
|
||||
EXPECT_TRUE(m_settings->Get(settingsResult, m_newSettingsPath));
|
||||
EXPECT_TRUE(settingsResult == settingsValue);
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_RemoveProjectManagerKey_RemovesKey)
|
||||
TEST_F(SettingsTests, Settings_RemoveProjectManagerKey_RemovesKey)
|
||||
{
|
||||
QString settingsResult;
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
|
||||
QString settingsValue = "TestValue";
|
||||
|
||||
// Don't save to disk in test
|
||||
EXPECT_TRUE(PMSettings::SetProjectManagerKey(m_settingsPath, settingsValue, /*saveToDisk*/ false));
|
||||
EXPECT_TRUE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_TRUE(m_settings->Set(m_settingsPath, settingsValue));
|
||||
EXPECT_TRUE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
|
||||
EXPECT_TRUE(PMSettings::RemoveProjectManagerKey(m_settingsPath, /*saveToDisk*/ false));
|
||||
EXPECT_FALSE(PMSettings::GetProjectManagerKey(settingsResult, m_settingsPath));
|
||||
EXPECT_TRUE(m_settings->Remove(m_settingsPath));
|
||||
EXPECT_FALSE(m_settings->Get(settingsResult, m_settingsPath));
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_GetUnsetBuildPath_ReturnsFalse)
|
||||
TEST_F(SettingsTests, Settings_GetUnsetBuildPath_ReturnsFalse)
|
||||
{
|
||||
bool buildResult = true;
|
||||
EXPECT_FALSE(PMSettings::GetProjectBuiltSuccessfully(buildResult, m_projectInfo));
|
||||
EXPECT_FALSE(m_settings->GetProjectBuiltSuccessfully(buildResult, m_projectInfo));
|
||||
EXPECT_FALSE(buildResult);
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_SetProjectBuiltSuccessfully_ReturnsTrue)
|
||||
TEST_F(SettingsTests, Settings_SetProjectBuiltSuccessfully_ReturnsTrue)
|
||||
{
|
||||
// Don't save to disk in test
|
||||
EXPECT_TRUE(PMSettings::SetProjectBuiltSuccessfully(m_projectInfo, true, /*saveToDisk*/ false));
|
||||
EXPECT_TRUE(m_settings->SetProjectBuiltSuccessfully(m_projectInfo, true));
|
||||
|
||||
bool buildResult = false;
|
||||
EXPECT_TRUE(PMSettings::GetProjectBuiltSuccessfully(buildResult, m_projectInfo));
|
||||
EXPECT_TRUE(m_settings->GetProjectBuiltSuccessfully(buildResult, m_projectInfo));
|
||||
EXPECT_TRUE(buildResult);
|
||||
}
|
||||
|
||||
TEST_F(ProjectManagerSettingsTests, PMSettings_SetProjectBuiltUnsuccessfully_ReturnsFalse)
|
||||
TEST_F(SettingsTests, Settings_SetProjectBuiltUnsuccessfully_ReturnsFalse)
|
||||
{
|
||||
// Don't save to disk in test
|
||||
EXPECT_TRUE(PMSettings::SetProjectBuiltSuccessfully(m_projectInfo, false, /*saveToDisk*/ false));
|
||||
EXPECT_TRUE(m_settings->SetProjectBuiltSuccessfully(m_projectInfo, false));
|
||||
|
||||
bool buildResult = false;
|
||||
EXPECT_TRUE(PMSettings::GetProjectBuiltSuccessfully(buildResult, m_projectInfo));
|
||||
EXPECT_TRUE(m_settings->GetProjectBuiltSuccessfully(buildResult, m_projectInfo));
|
||||
EXPECT_FALSE(buildResult);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user