Skip to content

Commit

Permalink
Merge pull request #74964 from clayjohn/pm-file-safety
Browse files Browse the repository at this point in the history
Disallow creating a project in the Home or Documents folder
  • Loading branch information
akien-mga authored Mar 16, 2023
2 parents 0c30a43 + 45a26ff commit e01b828
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
28 changes: 19 additions & 9 deletions editor/project_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class ProjectDialog : public ConfirmationDialog {
}

} else {
// check if the specified folder is empty, even though this is not an error, it is good to check here
// Check if the specified folder is empty, even though this is not an error, it is good to check here.
d->list_dir_begin();
is_folder_empty = true;
String n = d->get_next();
Expand All @@ -283,6 +283,12 @@ class ProjectDialog : public ConfirmationDialog {
d->list_dir_end();

if (!is_folder_empty) {
if (valid_path == OS::get_singleton()->get_environment("HOME") || valid_path == OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS) || valid_path == OS::get_singleton()->get_executable_path().get_base_dir()) {
set_message(TTR("You cannot save a project in the selected path. Please make a new folder or choose a new path."), MESSAGE_ERROR);
get_ok_button()->set_disabled(true);
return "";
}

set_message(TTR("The selected path is not empty. Choosing an empty folder is highly recommended."), MESSAGE_WARNING);
get_ok_button()->set_disabled(false);
return valid_path;
Expand Down Expand Up @@ -1828,9 +1834,11 @@ void ProjectList::erase_selected_projects(bool p_delete_project_contents) {
if (_selected_project_paths.has(item.path) && item.control->is_visible()) {
_config.erase_section(item.path);

if (p_delete_project_contents) {
OS::get_singleton()->move_to_trash(item.path);
}
// Comment out for now until we have a better warning system to
// ensure users delete their project only.
//if (p_delete_project_contents) {
// OS::get_singleton()->move_to_trash(item.path);
//}

memdelete(item.control);
_projects.remove_at(i);
Expand Down Expand Up @@ -2466,7 +2474,7 @@ void ProjectManager::_rename_project() {
}

void ProjectManager::_erase_project_confirm() {
_project_list->erase_selected_projects(delete_project_contents->is_pressed());
_project_list->erase_selected_projects(false);
_update_project_buttons();
}

Expand All @@ -2490,7 +2498,7 @@ void ProjectManager::_erase_project() {
}

erase_ask_label->set_text(confirm_message);
delete_project_contents->set_pressed(false);
//delete_project_contents->set_pressed(false);
erase_ask->popup_centered();
}

Expand Down Expand Up @@ -2953,9 +2961,11 @@ ProjectManager::ProjectManager() {
erase_ask_label = memnew(Label);
erase_ask_vb->add_child(erase_ask_label);

delete_project_contents = memnew(CheckBox);
delete_project_contents->set_text(TTR("Also delete project contents (no undo!)"));
erase_ask_vb->add_child(delete_project_contents);
// Comment out for now until we have a better warning system to
// ensure users delete their project only.
//delete_project_contents = memnew(CheckBox);
//delete_project_contents->set_text(TTR("Also delete project contents (no undo!)"));
//erase_ask_vb->add_child(delete_project_contents);

multi_open_ask = memnew(ConfirmationDialog);
multi_open_ask->set_ok_button_text(TTR("Edit"));
Expand Down
4 changes: 3 additions & 1 deletion editor/project_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class ProjectManager : public Control {

ConfirmationDialog *erase_ask = nullptr;
Label *erase_ask_label = nullptr;
CheckBox *delete_project_contents = nullptr;
// Comment out for now until we have a better warning system to
// ensure users delete their project only.
//CheckBox *delete_project_contents = nullptr;

ConfirmationDialog *erase_missing_ask = nullptr;
ConfirmationDialog *multi_open_ask = nullptr;
Expand Down

0 comments on commit e01b828

Please sign in to comment.