Skip to content

Commit 899d337

Browse files
committed
Merge pull request #103044 from KoBeWi/ultimate_upgrade_tool_will_upgrade_your_life_too
Replace UID and Surface upgrade tools with universal one
2 parents 991d01f + a3a1cf0 commit 899d337

7 files changed

+169
-525
lines changed

editor/editor_node.cpp

Lines changed: 15 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,11 @@
158158
#include "editor/plugins/visual_shader_editor_plugin.h"
159159
#include "editor/progress_dialog.h"
160160
#include "editor/project_settings_editor.h"
161+
#include "editor/project_upgrade_tool.h"
161162
#include "editor/register_exporters.h"
162163
#include "editor/scene_tree_dock.h"
163-
#include "editor/surface_upgrade_tool.h"
164164
#include "editor/themes/editor_scale.h"
165165
#include "editor/themes/editor_theme_manager.h"
166-
#include "editor/uid_upgrade_tool.h"
167166
#include "editor/window_wrapper.h"
168167

169168
#include "modules/modules_enabled.gen.h" // For gdscript, mono.
@@ -653,10 +652,7 @@ void EditorNode::_notification(int p_what) {
653652

654653
OS::get_singleton()->benchmark_begin_measure("Editor", "First Scan");
655654

656-
if (run_surface_upgrade_tool || run_uid_upgrade_tool) {
657-
EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorNode::_execute_upgrades), CONNECT_ONE_SHOT);
658-
}
659-
655+
EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorNode::_execute_upgrades), CONNECT_ONE_SHOT);
660656
EditorFileSystem::get_singleton()->scan();
661657
}
662658
} break;
@@ -739,23 +735,6 @@ void EditorNode::_notification(int p_what) {
739735

740736
// Save the project after opening to mark it as last modified, except in headless mode.
741737
if (DisplayServer::get_singleton()->window_can_draw()) {
742-
// Try to determine if this project's Godot version was less than 4.4 - if
743-
// so, we'll ask the user if they want to upgrade the project.
744-
PackedStringArray features = ProjectSettings::get_singleton()->get_setting("application/config/features");
745-
if (!features.is_empty()) {
746-
String version_str = features[0];
747-
PackedStringArray version_parts = version_str.split(".", true, 1);
748-
if (version_parts.size() >= 2) {
749-
if (version_parts[0].is_valid_int() && version_parts[1].is_valid_int()) {
750-
int major_ver = version_parts[0].to_int();
751-
int minor_ver = version_parts[1].to_int();
752-
if (major_ver < 4 || (major_ver == 4 && minor_ver < 4)) {
753-
should_prompt_uid_upgrade_tool = true;
754-
}
755-
}
756-
}
757-
}
758-
759738
ProjectSettings::get_singleton()->save();
760739
}
761740

@@ -900,16 +879,11 @@ void EditorNode::_update_update_spinner() {
900879
}
901880

902881
void EditorNode::_execute_upgrades() {
903-
if (run_surface_upgrade_tool) {
904-
run_surface_upgrade_tool = false;
882+
if (run_project_upgrade_tool) {
883+
run_project_upgrade_tool = false;
905884
// Execute another scan to reimport the modified files.
906-
SurfaceUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT);
907-
SurfaceUpgradeTool::get_singleton()->finish_upgrade();
908-
} else if (run_uid_upgrade_tool) {
909-
run_uid_upgrade_tool = false;
910-
// Execute another scan to reimport the modified files.
911-
UIDUpgradeTool::get_singleton()->connect("upgrade_finished", callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT);
912-
UIDUpgradeTool::get_singleton()->finish_upgrade();
885+
project_upgrade_tool->connect(project_upgrade_tool->UPGRADE_FINISHED, callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan), CONNECT_ONE_SHOT);
886+
project_upgrade_tool->finish_upgrade();
913887
}
914888
}
915889

@@ -1206,20 +1180,10 @@ void EditorNode::_sources_changed(bool p_exist) {
12061180
OS::get_singleton()->benchmark_dump();
12071181
}
12081182

1209-
if (SurfaceUpgradeTool::get_singleton()->is_show_requested()) {
1210-
SurfaceUpgradeTool::get_singleton()->show_popup();
1211-
}
1212-
12131183
// Start preview thread now that it's safe.
12141184
if (!singleton->cmdline_mode) {
12151185
EditorResourcePreview::get_singleton()->start();
12161186
}
1217-
1218-
if (should_prompt_uid_upgrade_tool) {
1219-
should_prompt_uid_upgrade_tool = false;
1220-
uid_upgrade_dialog->popup_on_demand();
1221-
}
1222-
12231187
get_tree()->create_timer(1.0f)->connect("timeout", callable_mp(this, &EditorNode::_remove_lock_file));
12241188
}
12251189
}
@@ -3353,11 +3317,8 @@ void EditorNode::_tool_menu_option(int p_idx) {
33533317
case TOOLS_BUILD_PROFILE_MANAGER: {
33543318
build_profile_manager->popup_centered_clamped(Size2(700, 800) * EDSCALE, 0.8);
33553319
} break;
3356-
case TOOLS_SURFACE_UPGRADE: {
3357-
surface_upgrade_dialog->popup_on_demand();
3358-
} break;
3359-
case TOOLS_UID_UPGRADE: {
3360-
uid_upgrade_dialog->popup_on_demand();
3320+
case TOOLS_PROJECT_UPGRADE: {
3321+
project_upgrade_tool->popup_dialog();
33613322
} break;
33623323
case TOOLS_CUSTOM: {
33633324
if (tool_menu->get_item_submenu(p_idx) == "") {
@@ -6967,18 +6928,11 @@ EditorNode::EditorNode() {
69676928

69686929
_update_vsync_mode();
69696930

6970-
// Warm up the surface upgrade tool as early as possible.
6971-
surface_upgrade_tool = memnew(SurfaceUpgradeTool);
6972-
run_surface_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata("surface_upgrade_tool", "run_on_restart", false);
6973-
if (run_surface_upgrade_tool) {
6974-
SurfaceUpgradeTool::get_singleton()->begin_upgrade();
6975-
}
6976-
6977-
// Same for UID upgrade tool.
6978-
uid_upgrade_tool = memnew(UIDUpgradeTool);
6979-
run_uid_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata(UIDUpgradeTool::META_UID_UPGRADE_TOOL, UIDUpgradeTool::META_RUN_ON_RESTART, false);
6980-
if (run_uid_upgrade_tool) {
6981-
UIDUpgradeTool::get_singleton()->begin_upgrade();
6931+
// Warm up the project upgrade tool as early as possible.
6932+
project_upgrade_tool = memnew(ProjectUpgradeTool);
6933+
run_project_upgrade_tool = EditorSettings::get_singleton()->get_project_metadata(project_upgrade_tool->META_PROJECT_UPGRADE_TOOL, project_upgrade_tool->META_RUN_ON_RESTART, false);
6934+
if (run_project_upgrade_tool) {
6935+
project_upgrade_tool->begin_upgrade();
69826936
}
69836937

69846938
{
@@ -7522,8 +7476,7 @@ EditorNode::EditorNode() {
75227476
project_menu->add_submenu_node_item(TTR("Tools"), tool_menu);
75237477
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/orphan_resource_explorer", TTRC("Orphan Resource Explorer...")), TOOLS_ORPHAN_RESOURCES);
75247478
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/engine_compilation_configuration_editor", TTRC("Engine Compilation Configuration Editor...")), TOOLS_BUILD_PROFILE_MANAGER);
7525-
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/upgrade_mesh_surfaces", TTRC("Upgrade Mesh Surfaces...")), TOOLS_SURFACE_UPGRADE);
7526-
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/upgrade_uids", TTRC("Upgrade UIDs...")), TOOLS_UID_UPGRADE);
7479+
tool_menu->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/upgrade_project", TTRC("Upgrade Project Files...")), TOOLS_PROJECT_UPGRADE);
75277480

75287481
project_menu->add_separator();
75297482
project_menu->add_shortcut(ED_SHORTCUT("editor/reload_current_project", TTRC("Reload Current Project")), PROJECT_RELOAD_CURRENT_PROJECT);
@@ -7806,12 +7759,6 @@ EditorNode::EditorNode() {
78067759
orphan_resources = memnew(OrphanResourcesDialog);
78077760
gui_base->add_child(orphan_resources);
78087761

7809-
surface_upgrade_dialog = memnew(SurfaceUpgradeDialog);
7810-
gui_base->add_child(surface_upgrade_dialog);
7811-
7812-
uid_upgrade_dialog = memnew(UIDUpgradeDialog);
7813-
gui_base->add_child(uid_upgrade_dialog);
7814-
78157762
confirmation = memnew(ConfirmationDialog);
78167763
gui_base->add_child(confirmation);
78177764
confirmation->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_menu_confirm_current));
@@ -8205,8 +8152,7 @@ EditorNode::~EditorNode() {
82058152
memdelete(editor_plugins_force_over);
82068153
memdelete(editor_plugins_force_input_forwarding);
82078154
memdelete(progress_hb);
8208-
memdelete(surface_upgrade_tool);
8209-
memdelete(uid_upgrade_tool);
8155+
memdelete(project_upgrade_tool);
82108156
memdelete(editor_dock_manager);
82118157

82128158
EditorSettings::destroy();

editor/editor_node.h

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ class ProgressDialog;
9797
class ProjectExportDialog;
9898
class ProjectSettingsEditor;
9999
class SceneImportSettingsDialog;
100-
class SurfaceUpgradeTool;
101-
class SurfaceUpgradeDialog;
102-
class UIDUpgradeTool;
103-
class UIDUpgradeDialog;
100+
class ProjectUpgradeTool;
104101

105102
struct EditorProgress {
106103
String task;
@@ -166,8 +163,7 @@ class EditorNode : public Node {
166163

167164
TOOLS_ORPHAN_RESOURCES,
168165
TOOLS_BUILD_PROFILE_MANAGER,
169-
TOOLS_SURFACE_UPGRADE,
170-
TOOLS_UID_UPGRADE,
166+
TOOLS_PROJECT_UPGRADE,
171167
TOOLS_CUSTOM,
172168

173169
VCS_METADATA,
@@ -226,7 +222,6 @@ class EditorNode : public Node {
226222

227223
private:
228224
friend class EditorSceneTabs;
229-
friend class SurfaceUpgradeTool;
230225

231226
enum {
232227
MAX_INIT_CALLBACKS = 128,
@@ -460,16 +455,8 @@ class EditorNode : public Node {
460455

461456
HashMap<String, Ref<Texture2D>> icon_type_cache;
462457

463-
SurfaceUpgradeTool *surface_upgrade_tool = nullptr;
464-
SurfaceUpgradeDialog *surface_upgrade_dialog = nullptr;
465-
466-
bool run_surface_upgrade_tool = false;
467-
468-
UIDUpgradeTool *uid_upgrade_tool = nullptr;
469-
UIDUpgradeDialog *uid_upgrade_dialog = nullptr;
470-
471-
bool run_uid_upgrade_tool = false;
472-
bool should_prompt_uid_upgrade_tool = false;
458+
ProjectUpgradeTool *project_upgrade_tool = nullptr;
459+
bool run_project_upgrade_tool = false;
473460

474461
bool was_window_windowed_last = false;
475462

editor/project_upgrade_tool.cpp

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**************************************************************************/
2+
/* project_upgrade_tool.cpp */
3+
/**************************************************************************/
4+
/* This file is part of: */
5+
/* GODOT ENGINE */
6+
/* https://godotengine.org */
7+
/**************************************************************************/
8+
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9+
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10+
/* */
11+
/* Permission is hereby granted, free of charge, to any person obtaining */
12+
/* a copy of this software and associated documentation files (the */
13+
/* "Software"), to deal in the Software without restriction, including */
14+
/* without limitation the rights to use, copy, modify, merge, publish, */
15+
/* distribute, sublicense, and/or sell copies of the Software, and to */
16+
/* permit persons to whom the Software is furnished to do so, subject to */
17+
/* the following conditions: */
18+
/* */
19+
/* The above copyright notice and this permission notice shall be */
20+
/* included in all copies or substantial portions of the Software. */
21+
/* */
22+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25+
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26+
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27+
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28+
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29+
/**************************************************************************/
30+
31+
#include "project_upgrade_tool.h"
32+
33+
#include "core/io/dir_access.h"
34+
#include "editor/editor_file_system.h"
35+
#include "editor/editor_node.h"
36+
#include "editor/editor_settings.h"
37+
#include "editor/gui/editor_scene_tabs.h"
38+
#include "editor/themes/editor_scale.h"
39+
#include "scene/gui/dialogs.h"
40+
41+
void ProjectUpgradeTool::_add_files(EditorFileSystemDirectory *p_dir, Vector<String> &r_reimport_paths, Vector<String> &r_resave_scenes, Vector<String> &r_resave_resources) {
42+
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
43+
for (int i = 0; i < p_dir->get_file_count(); i++) {
44+
const String path = p_dir->get_file_path(i);
45+
const String ext = path.get_extension();
46+
if (ext == "tscn" || ext == "scn") {
47+
r_resave_scenes.append(path);
48+
} else if (ext == "tres" || ext == "res") {
49+
r_resave_resources.append(path);
50+
} else if (da->file_exists(path + ".import")) {
51+
r_reimport_paths.append(path);
52+
}
53+
}
54+
55+
for (int i = 0; i < p_dir->get_subdir_count(); i++) {
56+
_add_files(p_dir->get_subdir(i), r_reimport_paths, r_resave_scenes, r_resave_resources);
57+
}
58+
}
59+
60+
void ProjectUpgradeTool::_bind_methods() {
61+
ADD_SIGNAL(MethodInfo("upgrade_finished"));
62+
}
63+
64+
void ProjectUpgradeTool::popup_dialog() {
65+
if (!upgrade_dialog) {
66+
upgrade_dialog = memnew(ConfirmationDialog);
67+
upgrade_dialog->set_autowrap(true);
68+
upgrade_dialog->set_text(TTRC("Different engine version may have minor differences in various Resources, like additional fields or removed properties. When upgrading the project to a new version, such changes can cause diffs when saving scenes or resources, or reimporting.\n\nThis tool ensures that such changes are performed all at once. It will:\n- Regenerate UID cache\n- Load and re-save every text/binary Resource\n- Reimport every importable Resource\n\nFull upgrade will take considerable amount of time, but afterwards saving/reimporting any scene/resource should not cause unintended changes."));
69+
upgrade_dialog->get_ok_button()->set_text(TTRC("Restart & Upgrade"));
70+
upgrade_dialog->get_label()->set_custom_minimum_size(Size2(750 * EDSCALE, 0));
71+
EditorNode::get_singleton()->get_gui_base()->add_child(upgrade_dialog);
72+
upgrade_dialog->connect(SceneStringName(confirmed), callable_mp(this, &ProjectUpgradeTool::prepare_upgrade));
73+
}
74+
upgrade_dialog->popup_centered();
75+
}
76+
77+
void ProjectUpgradeTool::prepare_upgrade() {
78+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RUN_ON_RESTART, true);
79+
80+
Vector<String> reimport_paths;
81+
Vector<String> resave_scenes;
82+
Vector<String> resave_resources;
83+
_add_files(EditorFileSystem::get_singleton()->get_filesystem(), reimport_paths, resave_scenes, resave_resources);
84+
85+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_REIMPORT_PATHS, reimport_paths);
86+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, resave_scenes);
87+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_RESOURCES, resave_resources);
88+
89+
// Delay to avoid deadlocks, since this dialog can be triggered by loading a scene.
90+
callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor).call_deferred(false);
91+
}
92+
93+
void ProjectUpgradeTool::begin_upgrade() {
94+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RUN_ON_RESTART, false);
95+
DirAccess::remove_absolute("res://.godot/uid_cache.bin");
96+
}
97+
98+
void ProjectUpgradeTool::finish_upgrade() {
99+
EditorNode::get_singleton()->trigger_menu_option(EditorSceneTabs::SCENE_CLOSE_ALL, true);
100+
101+
Vector<String> paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_REIMPORT_PATHS, Vector<String>());
102+
EditorFileSystem::get_singleton()->reimport_files(paths);
103+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_REIMPORT_PATHS, Variant());
104+
105+
{
106+
paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, Vector<String>());
107+
EditorProgress ep("uid_upgrade_resave", TTR("Updating Project Scenes"), paths.size());
108+
109+
int step = 0;
110+
for (const String &file_path : paths) {
111+
ep.step(TTR("Re-saving scene:") + " " + file_path, step++);
112+
EditorNode::get_singleton()->load_scene(file_path);
113+
EditorNode::get_singleton()->trigger_menu_option(EditorNode::FILE_SAVE_SCENE, true);
114+
EditorNode::get_singleton()->trigger_menu_option(EditorNode::FILE_CLOSE, true);
115+
}
116+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_SCENES, Variant());
117+
}
118+
119+
{
120+
paths = EditorSettings::get_singleton()->get_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_RESOURCES, Vector<String>());
121+
EditorProgress ep("uid_upgrade_resave", TTR("Updating Project Resources"), paths.size());
122+
123+
int step = 0;
124+
for (const String &file_path : paths) {
125+
ep.step(TTR("Re-saving resource:") + " " + file_path, step++);
126+
Ref<Resource> res = ResourceLoader::load(file_path, "", ResourceFormatLoader::CACHE_MODE_REPLACE);
127+
if (res.is_valid()) {
128+
ResourceSaver::save(res);
129+
}
130+
}
131+
EditorSettings::get_singleton()->set_project_metadata(META_PROJECT_UPGRADE_TOOL, META_RESAVE_RESOURCES, Variant());
132+
}
133+
134+
emit_signal(UPGRADE_FINISHED);
135+
}

0 commit comments

Comments
 (0)