From fff3c38af92382d138426c2772257d8620071624 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 13 Jan 2022 21:17:20 +0200 Subject: [PATCH] [macOS] Fix self-contained mode, by looking for `._sc_` and writing data to the bundle directory instead of executable directory. --- editor/editor_paths.cpp | 5 +++++ modules/mono/godotsharp_dirs.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/editor/editor_paths.cpp b/editor/editor_paths.cpp index a4481cd1eb5..d4e40db406d 100644 --- a/editor/editor_paths.cpp +++ b/editor/editor_paths.cpp @@ -91,6 +91,11 @@ EditorPaths::EditorPaths() { // Self-contained mode if a `._sc_` or `_sc_` file is present in executable dir. String exe_path = OS::get_singleton()->get_executable_path().get_base_dir(); + + // On macOS, look outside .app bundle, since .app bundle is read-only. + if (OS::get_singleton()->has_feature("macos") && exe_path.ends_with("MacOS") && exe_path.plus_file("..").simplify_path().ends_with("Contents")) { + exe_path = exe_path.plus_file("../../..").simplify_path(); + } { DirAccessRef d = DirAccess::create_for_path(exe_path); diff --git a/modules/mono/godotsharp_dirs.cpp b/modules/mono/godotsharp_dirs.cpp index 02739f0480c..c0cd18e29da 100644 --- a/modules/mono/godotsharp_dirs.cpp +++ b/modules/mono/godotsharp_dirs.cpp @@ -68,7 +68,14 @@ String _get_mono_user_dir() { } else { String settings_path; + // Self-contained mode if a `._sc_` or `_sc_` file is present in executable dir. String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir(); + + // On macOS, look outside .app bundle, since .app bundle is read-only. + if (OS::get_singleton()->has_feature("macos") && exe_dir.ends_with("MacOS") && exe_dir.plus_file("..").simplify_path().ends_with("Contents")) { + exe_dir = exe_dir.plus_file("../../..").simplify_path(); + } + DirAccessRef d = DirAccess::create_for_path(exe_dir); if (d->file_exists("._sc_") || d->file_exists("_sc_")) {