diff --git a/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp b/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp index b1db77ea83..df828b028a 100644 --- a/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp +++ b/Code/Tools/ProjectManager/Source/ProjectsScreen.cpp @@ -119,6 +119,8 @@ namespace O3DE::ProjectManager QFrame* ProjectsScreen::CreateProjectsContent(QString buildProjectPath, ProjectButton** projectButton) { + RemoveInvalidProjects(); + QFrame* frame = new QFrame(this); frame->setObjectName("projectsContent"); { @@ -481,6 +483,11 @@ namespace O3DE::ProjectManager return displayFirstTimeContent; } + void ProjectsScreen::RemoveInvalidProjects() + { + PythonBindingsInterface::Get()->RemoveInvalidProjects(); + } + void ProjectsScreen::StartProjectBuild(const ProjectInfo& projectInfo) { if (ProjectUtils::IsVS2019Installed()) diff --git a/Code/Tools/ProjectManager/Source/ProjectsScreen.h b/Code/Tools/ProjectManager/Source/ProjectsScreen.h index 12152e908b..e2929c1107 100644 --- a/Code/Tools/ProjectManager/Source/ProjectsScreen.h +++ b/Code/Tools/ProjectManager/Source/ProjectsScreen.h @@ -59,6 +59,7 @@ namespace O3DE::ProjectManager ProjectButton* CreateProjectButton(ProjectInfo& project, QLayout* flowLayout, bool processing = false); void ResetProjectsContent(); bool ShouldDisplayFirstTimeContent(); + void RemoveInvalidProjects(); void StartProjectBuild(const ProjectInfo& projectInfo); QList::iterator RequiresBuildProjectIterator(const QString& projectPath); diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.cpp b/Code/Tools/ProjectManager/Source/PythonBindings.cpp index f8c45bedeb..11ca5a79c5 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.cpp +++ b/Code/Tools/ProjectManager/Source/PythonBindings.cpp @@ -755,6 +755,15 @@ namespace O3DE::ProjectManager }); } + void PythonBindings::RemoveInvalidProjects() + { + ExecuteWithLockErrorHandling( + [&] + { + m_register.attr("remove_invalid_o3de_projects")(); + }); + } + AZ::Outcome PythonBindings::UpdateProject(const ProjectInfo& projectInfo) { bool updateProjectSucceeded = false; diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.h b/Code/Tools/ProjectManager/Source/PythonBindings.h index 1d98505457..a64727abfe 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.h +++ b/Code/Tools/ProjectManager/Source/PythonBindings.h @@ -50,6 +50,7 @@ namespace O3DE::ProjectManager AZ::Outcome UpdateProject(const ProjectInfo& projectInfo) override; AZ::Outcome AddGemToProject(const QString& gemPath, const QString& projectPath) override; AZ::Outcome RemoveGemFromProject(const QString& gemPath, const QString& projectPath) override; + void RemoveInvalidProjects() override; // ProjectTemplate AZ::Outcome> GetProjectTemplates(const QString& projectPath = {}) override; diff --git a/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h b/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h index 0adc842a05..c4a271cfa1 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h +++ b/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h @@ -141,6 +141,11 @@ namespace O3DE::ProjectManager */ virtual AZ::Outcome RemoveGemFromProject(const QString& gemPath, const QString& projectPath) = 0; + /** + * Removes invalid projects from the manifest + */ + virtual void RemoveInvalidProjects() = 0; + // Project Templates diff --git a/scripts/o3de/o3de/register.py b/scripts/o3de/o3de/register.py index 7ad341784e..3a006735ed 100644 --- a/scripts/o3de/o3de/register.py +++ b/scripts/o3de/o3de/register.py @@ -404,27 +404,28 @@ def register_project_path(json_data: dict, if result != 0: return result - # registering a project has the additional step of setting the project.json 'engine' field - this_engine_json = manifest.get_engine_json_data(engine_path=manifest.get_this_engine_path()) - if not this_engine_json: - return 1 - project_json_data = manifest.get_project_json_data(project_path=project_path) - if not project_json_data: - return 1 - - update_project_json = False - try: - update_project_json = project_json_data['engine'] != this_engine_json['engine_name'] - except KeyError as e: - update_project_json = True - - if update_project_json: - project_json_path = project_path / 'project.json' - project_json_data['engine'] = this_engine_json['engine_name'] - utils.backup_file(project_json_path) - if not manifest.save_o3de_manifest(project_json_data, project_json_path): + if not remove: + # registering a project has the additional step of setting the project.json 'engine' field + this_engine_json = manifest.get_engine_json_data(engine_path=manifest.get_this_engine_path()) + if not this_engine_json: + return 1 + project_json_data = manifest.get_project_json_data(project_path=project_path) + if not project_json_data: return 1 + update_project_json = False + try: + update_project_json = project_json_data['engine'] != this_engine_json['engine_name'] + except KeyError as e: + update_project_json = True + + if update_project_json: + project_json_path = project_path / 'project.json' + project_json_data['engine'] = this_engine_json['engine_name'] + utils.backup_file(project_json_path) + if not manifest.save_o3de_manifest(project_json_data, project_json_path): + return 1 + return 0 @@ -657,6 +658,13 @@ def register(engine_path: pathlib.Path = None, return result +def remove_invalid_o3de_projects() -> None: + json_data = manifest.load_o3de_manifest() + + for project in json_data['projects']: + if not validation.valid_o3de_project_json(pathlib.Path(project).resolve() / 'project.json'): + logger.warn(f"Project path {project} is invalid.") + register(project_path=pathlib.Path(project), remove=True) def remove_invalid_o3de_objects() -> None: json_data = manifest.load_o3de_manifest() @@ -667,10 +675,7 @@ def remove_invalid_o3de_objects() -> None: logger.warn(f"Engine path {engine_path} is invalid.") register(engine_path=engine_path, remove=True) - for project in json_data['projects']: - if not validation.valid_o3de_project_json(pathlib.Path(project).resolve() / 'project.json'): - logger.warn(f"Project path {project} is invalid.") - register(project_path=project, remove=True) + remove_invalid_o3de_projects() for gem in json_data['gems']: if not validation.valid_o3de_gem_json(pathlib.Path(gem).resolve() / 'gem.json'):