Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project Manager: Fix hacky code for project rename #69338

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@ ProjectSettings::ProjectSettings() {
// Initialization of engine variables should be done in the setup() method,
// so that the values can be overridden from project.godot or project.binary.

CRASH_COND_MSG(singleton != nullptr, "Instantiating a new ProjectSettings singleton is not supported.");
singleton = this;

GLOBAL_DEF_BASIC("application/config/name", "");
Expand Down
35 changes: 18 additions & 17 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,17 +436,17 @@ class ProjectDialog : public ConfirmationDialog {
return;
}

ProjectSettings *current = memnew(ProjectSettings);

int err = current->setup(dir2, "");
// Load project.godot as ConfigFile to set the new name.
ConfigFile cfg;
String project_godot = dir2.path_join("project.godot");
Error err = cfg.load(project_godot);
if (err != OK) {
set_message(vformat(TTR("Couldn't load project.godot in project path (error %d). It may be missing or corrupted."), err), MESSAGE_ERROR);
set_message(vformat(TTR("Couldn't load project at '%s' (error %d). It may be missing or corrupted."), project_godot, err), MESSAGE_ERROR);
} else {
ProjectSettings::CustomMap edited_settings;
edited_settings["application/config/name"] = project_name->get_text().strip_edges();

if (current->save_custom(dir2.path_join("project.godot"), edited_settings, Vector<String>(), true) != OK) {
set_message(TTR("Couldn't edit project.godot in project path."), MESSAGE_ERROR);
cfg.set_value("application", "config/name", project_name->get_text().strip_edges());
err = cfg.save(project_godot);
if (err != OK) {
set_message(vformat(TTR("Couldn't save project at '%s' (error %d)."), project_godot, err), MESSAGE_ERROR);
}
}

Expand Down Expand Up @@ -694,18 +694,19 @@ class ProjectDialog : public ConfirmationDialog {
default_files_container->hide();
get_ok_button()->set_disabled(false);

ProjectSettings *current = memnew(ProjectSettings);

int err = current->setup(project_path->get_text(), "");
// Fetch current name from project.godot to prefill the text input.
ConfigFile cfg;
String project_godot = project_path->get_text().path_join("project.godot");
Error err = cfg.load(project_godot);
if (err != OK) {
set_message(vformat(TTR("Couldn't load project.godot in project path (error %d). It may be missing or corrupted."), err), MESSAGE_ERROR);
set_message(vformat(TTR("Couldn't load project at '%s' (error %d). It may be missing or corrupted."), project_godot, err), MESSAGE_ERROR);
status_rect->show();
msg->show();
get_ok_button()->set_disabled(true);
} else if (current->has_setting("application/config/name")) {
String proj = current->get("application/config/name");
project_name->set_text(proj);
_text_changed(proj);
} else {
String cur_name = cfg.get_value("application", "config/name", "");
project_name->set_text(cur_name);
_text_changed(cur_name);
}

project_name->call_deferred(SNAME("grab_focus"));
Expand Down