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

Fix Project Dialog Removing Home Dir. from Project Path #101609

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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