1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #103796 from runzh-crypto/validate-custom-directory

Validate custom directory when project is started
This commit is contained in:
Thaddeus Crews
2025-04-04 09:29:37 -05:00
3 changed files with 32 additions and 1 deletions

View File

@@ -254,7 +254,7 @@ String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_paths) const
if (p_allow_paths) {
// Dir separators are allowed, but disallow ".." to avoid going up the filesystem
invalid_chars.push_back("..");
safe_dir_name = safe_dir_name.replace("\\", "/").strip_edges();
safe_dir_name = safe_dir_name.replace("\\", "/").replace("//", "/").strip_edges();
} else {
invalid_chars.push_back("/");
invalid_chars.push_back("\\");

View File

@@ -5702,6 +5702,30 @@ bool EditorNode::ensure_main_scene(bool p_from_native) {
return false;
}
if (!EditorNode::validate_custom_directory()) {
current_menu_option = -1;
return false;
}
return true;
}
bool EditorNode::validate_custom_directory() {
bool use_custom_dir = GLOBAL_GET("application/config/use_custom_user_dir");
if (use_custom_dir) {
String data_dir = OS::get_singleton()->get_user_data_dir();
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_USERDATA);
if (dir->change_dir(data_dir) != OK) {
dir->make_dir_recursive(data_dir);
if (dir->change_dir(data_dir) != OK) {
open_project_settings->set_text(vformat(TTR("User data dir '%s' is not valid. Change to a valid one?"), data_dir));
open_project_settings->popup_centered();
return false;
}
}
}
return true;
}
@@ -8262,6 +8286,11 @@ EditorNode::EditorNode() {
select_current_scene_button = pick_main_scene->add_button(TTR("Select Current"), true, "select_current");
pick_main_scene->connect("custom_action", callable_mp(this, &EditorNode::_pick_main_scene_custom_action));
open_project_settings = memnew(ConfirmationDialog);
gui_base->add_child(open_project_settings);
open_project_settings->set_ok_button_text(TTRC("Open Project Settings"));
open_project_settings->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_menu_option).bind(PROJECT_OPEN_SETTINGS));
for (int i = 0; i < _init_callbacks.size(); i++) {
_init_callbacks[i]();
}

View File

@@ -356,6 +356,7 @@ private:
ConfirmationDialog *save_confirmation = nullptr;
ConfirmationDialog *import_confirmation = nullptr;
ConfirmationDialog *pick_main_scene = nullptr;
ConfirmationDialog *open_project_settings = nullptr;
Button *select_current_scene_button = nullptr;
AcceptDialog *accept = nullptr;
AcceptDialog *save_accept = nullptr;
@@ -962,6 +963,7 @@ public:
Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
bool ensure_main_scene(bool p_from_native);
bool validate_custom_directory();
};
class EditorPluginList : public Object {