Skip to content

Commit 31a66d3

Browse files
committed
Merge pull request #103796 from runzh-crypto/validate-custom-directory
Validate custom directory when project is started
2 parents 2fe029d + 9977abd commit 31a66d3

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

core/os/os.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_paths) const
254254
if (p_allow_paths) {
255255
// Dir separators are allowed, but disallow ".." to avoid going up the filesystem
256256
invalid_chars.push_back("..");
257-
safe_dir_name = safe_dir_name.replace("\\", "/").strip_edges();
257+
safe_dir_name = safe_dir_name.replace("\\", "/").replace("//", "/").strip_edges();
258258
} else {
259259
invalid_chars.push_back("/");
260260
invalid_chars.push_back("\\");

editor/editor_node.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5702,6 +5702,30 @@ bool EditorNode::ensure_main_scene(bool p_from_native) {
57025702
return false;
57035703
}
57045704

5705+
if (!EditorNode::validate_custom_directory()) {
5706+
current_menu_option = -1;
5707+
return false;
5708+
}
5709+
5710+
return true;
5711+
}
5712+
5713+
bool EditorNode::validate_custom_directory() {
5714+
bool use_custom_dir = GLOBAL_GET("application/config/use_custom_user_dir");
5715+
5716+
if (use_custom_dir) {
5717+
String data_dir = OS::get_singleton()->get_user_data_dir();
5718+
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_USERDATA);
5719+
if (dir->change_dir(data_dir) != OK) {
5720+
dir->make_dir_recursive(data_dir);
5721+
if (dir->change_dir(data_dir) != OK) {
5722+
open_project_settings->set_text(vformat(TTR("User data dir '%s' is not valid. Change to a valid one?"), data_dir));
5723+
open_project_settings->popup_centered();
5724+
return false;
5725+
}
5726+
}
5727+
}
5728+
57055729
return true;
57065730
}
57075731

@@ -8262,6 +8286,11 @@ EditorNode::EditorNode() {
82628286
select_current_scene_button = pick_main_scene->add_button(TTR("Select Current"), true, "select_current");
82638287
pick_main_scene->connect("custom_action", callable_mp(this, &EditorNode::_pick_main_scene_custom_action));
82648288

8289+
open_project_settings = memnew(ConfirmationDialog);
8290+
gui_base->add_child(open_project_settings);
8291+
open_project_settings->set_ok_button_text(TTRC("Open Project Settings"));
8292+
open_project_settings->connect(SceneStringName(confirmed), callable_mp(this, &EditorNode::_menu_option).bind(PROJECT_OPEN_SETTINGS));
8293+
82658294
for (int i = 0; i < _init_callbacks.size(); i++) {
82668295
_init_callbacks[i]();
82678296
}

editor/editor_node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ class EditorNode : public Node {
356356
ConfirmationDialog *save_confirmation = nullptr;
357357
ConfirmationDialog *import_confirmation = nullptr;
358358
ConfirmationDialog *pick_main_scene = nullptr;
359+
ConfirmationDialog *open_project_settings = nullptr;
359360
Button *select_current_scene_button = nullptr;
360361
AcceptDialog *accept = nullptr;
361362
AcceptDialog *save_accept = nullptr;
@@ -962,6 +963,7 @@ class EditorNode : public Node {
962963
Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
963964

964965
bool ensure_main_scene(bool p_from_native);
966+
bool validate_custom_directory();
965967
};
966968

967969
class EditorPluginList : public Object {

0 commit comments

Comments
 (0)