Skip to content

Commit

Permalink
fix project dialog removing home dir (+style fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
DubiousDuck committed Jan 15, 2025
1 parent 4ce466d commit 6c276c7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
37 changes: 26 additions & 11 deletions editor/project_manager/project_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,7 @@ void ProjectDialog::_validate_path() {
return;
}

// TODO: The following 5 lines could be simplified if OS.get_user_home_dir() or SYSTEM_DIR_HOME is implemented. See: https://github.com/godotengine/godot-proposals/issues/4851.
#ifdef WINDOWS_ENABLED
String home_dir = OS::get_singleton()->get_environment("USERPROFILE");
#else
String home_dir = OS::get_singleton()->get_environment("HOME");
#endif
String documents_dir = OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS);
if (target_path == home_dir || target_path == documents_dir) {
if (_is_path_home_or_doc_dir(target_path)) {
_set_message(TTR("You cannot save a project at the selected path. Please create a subfolder or choose a new path."), MESSAGE_ERROR, target_path_input_type);
return;
}
Expand Down Expand Up @@ -324,13 +317,18 @@ void ProjectDialog::_create_dir_toggled(bool p_pressed) {
} else {
// Strip any trailing slash.
target_path = target_path.rstrip("/\\");

// Save and remove target dir name.
if (target_path.get_file() == auto_dir) {
if (_is_path_home_or_doc_dir(target_path)) {
last_custom_target_dir = "";
} else {
last_custom_target_dir = target_path.get_file();
if (target_path.get_file() == auto_dir) {
last_custom_target_dir = "";
} else {
last_custom_target_dir = target_path.get_file();
}
target_path = target_path.get_base_dir();
}
target_path = target_path.get_base_dir();
}

_set_target_path(target_path);
Expand Down Expand Up @@ -731,6 +729,23 @@ void ProjectDialog::ok_pressed() {
}
}

bool ProjectDialog::_is_path_home_or_doc_dir(const String &p_path) {
String target_path = p_path;

// TODO: The following 5 lines could be simplified if OS.get_user_home_dir() or SYSTEM_DIR_HOME is implemented. See: https://github.com/godotengine/godot-proposals/issues/4851.
#ifdef WINDOWS_ENABLED
String home_dir = OS::get_singleton()->get_environment("USERPROFILE");
#else
String home_dir = OS::get_singleton()->get_environment("HOME");
#endif
String documents_dir = OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS);

if (target_path == home_dir || target_path == documents_dir) {
return true;
}
return false;
}

void ProjectDialog::set_zip_path(const String &p_path) {
zip_path = p_path;
}
Expand Down
2 changes: 2 additions & 0 deletions editor/project_manager/project_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class ProjectDialog : public ConfirmationDialog {

void ok_pressed() override;

bool _is_path_home_or_doc_dir(const String &p_path);

protected:
static void _bind_methods();
void _notification(int p_what);
Expand Down

0 comments on commit 6c276c7

Please sign in to comment.