From d6fecf7686c5ea9309051c5238637a29488c280c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Fri, 8 Jan 2021 10:24:41 +0100 Subject: [PATCH 1/2] Main: Create user data dir in `setup()` Custom backport of #39563 with preliminary change to make `OS::ensure_user_data_dir()` public as done in f8a79a9. Fixes #32488. --- core/os/os.cpp | 3 +-- core/os/os.h | 3 ++- main/main.cpp | 3 +++ platform/osx/os_osx.mm | 2 -- platform/server/os_server.cpp | 2 -- platform/uwp/os_uwp.cpp | 2 -- platform/windows/os_windows.cpp | 2 -- platform/x11/os_x11.cpp | 1 - 8 files changed, 6 insertions(+), 12 deletions(-) diff --git a/core/os/os.cpp b/core/os/os.cpp index 1ffa5c449721..041858fd0e10 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -460,8 +460,7 @@ OS::ScreenOrientation OS::get_screen_orientation() const { return (OS::ScreenOrientation)_orientation; } -void OS::_ensure_user_data_dir() { - +void OS::ensure_user_data_dir() { String dd = get_user_data_dir(); DirAccess *da = DirAccess::open(dd); if (da) { diff --git a/core/os/os.h b/core/os/os.h index 5714e101d98b..ffd2a14b0df0 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -140,7 +140,6 @@ class OS { virtual void set_cmdline(const char *p_execpath, const List &p_args); - void _ensure_user_data_dir(); virtual bool _check_internal_feature_support(const String &p_feature) = 0; public: @@ -305,6 +304,8 @@ class OS { virtual List get_cmdline_args() const { return _cmdline; } virtual String get_model_name() const; + void ensure_user_data_dir(); + virtual MainLoop *get_main_loop() const = 0; virtual void yield(); diff --git a/main/main.cpp b/main/main.cpp index 4f3f4523cef9..d02f75b30b19 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -899,6 +899,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph #endif } + // Initialize user data dir. + OS::get_singleton()->ensure_user_data_dir(); + GLOBAL_DEF("memory/limits/multithreaded_server/rid_pool_prealloc", 60); ProjectSettings::get_singleton()->set_custom_property_info("memory/limits/multithreaded_server/rid_pool_prealloc", PropertyInfo(Variant::INT, "memory/limits/multithreaded_server/rid_pool_prealloc", PROPERTY_HINT_RANGE, "0,500,1")); // No negative and limit to 500 due to crashes GLOBAL_DEF("network/limits/debugger_stdout/max_chars_per_second", 2048); diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 63d98673af37..48d0ea115b13 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1774,8 +1774,6 @@ static void displays_arrangement_changed(CGDirectDisplayID display_id, CGDisplay power_manager = memnew(PowerOSX); - _ensure_user_data_dir(); - restore_rect = Rect2(get_window_position(), get_window_size()); if (p_desired.layered) { diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index 87cc33d39b2a..9ee0a6ae8cf2 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -97,8 +97,6 @@ Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int power_manager = memnew(PowerX11); #endif - _ensure_user_data_dir(); - resource_loader_dummy.instance(); ResourceLoader::add_resource_format_loader(resource_loader_dummy); diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 20be1dd0d3bf..5ce3429e359e 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -340,8 +340,6 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a ref new TypedEventHandler(managed_object, &ManagedType::on_gyroscope_reading_changed); } - _ensure_user_data_dir(); - if (is_keep_screen_on()) display_request->RequestActive(); diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 46c9198f33f5..08c4c9bf0c4a 100755 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1687,8 +1687,6 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int RegisterTouchWindow(hWnd, 0); - _ensure_user_data_dir(); - DragAcceptFiles(hWnd, true); move_timer_id = 1; diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index e59cf65351b0..fc6d2e2be029 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -605,7 +605,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a #ifdef JOYDEV_ENABLED joypad = memnew(JoypadLinux(input)); #endif - _ensure_user_data_dir(); power_manager = memnew(PowerX11); From 5bda8fae38d633a939dbff46b1a6dcf7c893de19 Mon Sep 17 00:00:00 2001 From: Leleat Date: Sun, 13 Sep 2020 14:49:53 +0200 Subject: [PATCH 2/2] creater user-dir, if non-existant and pressing 'Open Project Data Folder' (cherry picked from commit 8cf9d09d6169f114bb78d93ede904a60ea74ddaf) --- editor/editor_node.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 0c1dcee9ebeb..7ba40caf688c 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -2594,6 +2594,8 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } } break; case RUN_PROJECT_DATA_FOLDER: { + // ensure_user_data_dir() to prevent the edge case: "Open Project Data Folder" won't work after the project was renamed in ProjectSettingsEditor unless the project is saved + OS::get_singleton()->ensure_user_data_dir(); OS::get_singleton()->shell_open(String("file://") + OS::get_singleton()->get_user_data_dir()); } break; case FILE_EXPLORE_ANDROID_BUILD_TEMPLATES: {