2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* godotsharp_dirs.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
#include "godotsharp_dirs.h"
|
|
|
|
|
2023-06-13 16:56:21 +02:00
|
|
|
#include "mono_gd/gd_mono.h"
|
|
|
|
#include "utils/path_utils.h"
|
|
|
|
|
|
|
|
#ifdef ANDROID_ENABLED
|
|
|
|
#include "mono_gd/support/android_support.h"
|
|
|
|
#endif
|
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/config/project_settings.h"
|
2021-06-11 14:51:48 +02:00
|
|
|
#include "core/io/dir_access.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/os.h"
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/version.h"
|
2022-02-14 14:00:03 +01:00
|
|
|
#include "editor/editor_paths.h"
|
2017-10-02 23:24:00 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace GodotSharpDirs {
|
|
|
|
|
|
|
|
String _get_expected_build_config() {
|
|
|
|
#ifdef TOOLS_ENABLED
|
2020-03-18 14:50:49 +01:00
|
|
|
return "Debug";
|
2017-10-02 23:24:00 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
2020-03-18 14:50:49 +01:00
|
|
|
return "ExportDebug";
|
2017-10-02 23:24:00 +02:00
|
|
|
#else
|
2020-03-18 14:50:49 +01:00
|
|
|
return "ExportRelease";
|
2017-10-02 23:24:00 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
String _get_mono_user_dir() {
|
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-25 02:25:11 +02:00
|
|
|
if (EditorPaths::get_singleton()) {
|
2022-08-30 02:34:01 +02:00
|
|
|
return EditorPaths::get_singleton()->get_data_dir().path_join("mono");
|
2017-10-02 23:24:00 +02:00
|
|
|
} else {
|
2023-02-16 12:43:32 +01:00
|
|
|
String settings_path = OS::get_singleton()->get_data_path().path_join(OS::get_singleton()->get_godot_dir_name());
|
2017-10-02 23:24:00 +02:00
|
|
|
|
2022-01-13 20:17:20 +01:00
|
|
|
// Self-contained mode if a `._sc_` or `_sc_` file is present in executable dir.
|
2017-10-17 11:36:19 +02:00
|
|
|
String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
|
2022-03-23 10:08:58 +01:00
|
|
|
Ref<DirAccess> d = DirAccess::create_for_path(exe_dir);
|
2017-10-17 11:36:19 +02:00
|
|
|
if (d->file_exists("._sc_") || d->file_exists("_sc_")) {
|
|
|
|
// contain yourself
|
2022-08-30 02:34:01 +02:00
|
|
|
settings_path = exe_dir.path_join("editor_data");
|
2023-02-16 12:43:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// On macOS, look outside .app bundle, since .app bundle is read-only.
|
|
|
|
// Note: This will not work if Gatekeeper path randomization is active.
|
|
|
|
if (OS::get_singleton()->has_feature("macos") && exe_dir.ends_with("MacOS") && exe_dir.path_join("..").simplify_path().ends_with("Contents")) {
|
|
|
|
exe_dir = exe_dir.path_join("../../..").simplify_path();
|
|
|
|
d = DirAccess::create_for_path(exe_dir);
|
|
|
|
if (d->file_exists("._sc_") || d->file_exists("_sc_")) {
|
|
|
|
// contain yourself
|
|
|
|
settings_path = exe_dir.path_join("editor_data");
|
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
2022-08-30 02:34:01 +02:00
|
|
|
return settings_path.path_join("mono");
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
#else
|
2022-08-30 02:34:01 +02:00
|
|
|
return OS::get_singleton()->get_user_data_dir().path_join("mono");
|
2017-10-02 23:24:00 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GodotSharpDirs {
|
|
|
|
public:
|
|
|
|
String res_metadata_dir;
|
|
|
|
String res_temp_assemblies_dir;
|
|
|
|
String mono_user_dir;
|
2021-09-12 20:21:15 +02:00
|
|
|
String api_assemblies_dir;
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
String build_logs_dir;
|
2018-10-03 19:01:57 +02:00
|
|
|
String data_editor_tools_dir;
|
2019-02-15 18:49:04 +01:00
|
|
|
#endif
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
private:
|
|
|
|
_GodotSharpDirs() {
|
2022-10-05 19:31:07 +02:00
|
|
|
String res_data_dir = ProjectSettings::get_singleton()->get_project_data_path().path_join("mono");
|
2022-08-30 02:34:01 +02:00
|
|
|
res_metadata_dir = res_data_dir.path_join("metadata");
|
2017-10-02 23:24:00 +02:00
|
|
|
|
|
|
|
// TODO use paths from csproj
|
2022-10-05 19:31:07 +02:00
|
|
|
res_temp_assemblies_dir = res_data_dir.path_join("temp").path_join("bin").path_join(_get_expected_build_config());
|
2021-09-12 20:21:15 +02:00
|
|
|
|
2022-08-28 20:27:45 +02:00
|
|
|
#ifdef WEB_ENABLED
|
2019-11-10 17:10:38 +01:00
|
|
|
mono_user_dir = "user://";
|
|
|
|
#else
|
2017-10-02 23:24:00 +02:00
|
|
|
mono_user_dir = _get_mono_user_dir();
|
2019-11-10 17:10:38 +01:00
|
|
|
#endif
|
2018-10-03 19:01:57 +02:00
|
|
|
|
|
|
|
String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
|
2022-10-05 19:31:07 +02:00
|
|
|
String res_dir = OS::get_singleton()->get_bundle_resource_dir();
|
2018-10-03 19:01:57 +02:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
2022-08-30 02:34:01 +02:00
|
|
|
String data_dir_root = exe_dir.path_join("GodotSharp");
|
|
|
|
data_editor_tools_dir = data_dir_root.path_join("Tools");
|
2022-10-05 19:31:07 +02:00
|
|
|
String api_assemblies_base_dir = data_dir_root.path_join("Api");
|
|
|
|
build_logs_dir = mono_user_dir.path_join("build_logs");
|
2022-07-20 08:28:22 +02:00
|
|
|
#ifdef MACOS_ENABLED
|
2018-10-03 19:01:57 +02:00
|
|
|
if (!DirAccess::exists(data_editor_tools_dir)) {
|
2022-10-05 19:31:07 +02:00
|
|
|
data_editor_tools_dir = res_dir.path_join("GodotSharp").path_join("Tools");
|
2018-10-03 19:01:57 +02:00
|
|
|
}
|
2021-09-12 20:21:15 +02:00
|
|
|
if (!DirAccess::exists(api_assemblies_base_dir)) {
|
2022-10-05 19:31:07 +02:00
|
|
|
api_assemblies_base_dir = res_dir.path_join("GodotSharp").path_join("Api");
|
2018-10-03 19:01:57 +02:00
|
|
|
}
|
|
|
|
#endif
|
2022-10-05 19:31:07 +02:00
|
|
|
api_assemblies_dir = api_assemblies_base_dir.path_join(GDMono::get_expected_api_build_config());
|
|
|
|
#else // TOOLS_ENABLED
|
|
|
|
String arch = Engine::get_singleton()->get_architecture_name();
|
2023-03-06 21:39:24 +01:00
|
|
|
String appname_safe = path::get_csharp_project_name();
|
2023-04-20 22:25:21 +02:00
|
|
|
String packed_path = "res://.godot/mono/publish/" + arch;
|
|
|
|
if (DirAccess::exists(packed_path)) {
|
|
|
|
// The dotnet publish data is packed in the pck/zip.
|
|
|
|
String data_dir_root = OS::get_singleton()->get_cache_path().path_join("data_" + appname_safe + "_" + arch);
|
|
|
|
bool has_data = false;
|
|
|
|
if (!has_data) {
|
|
|
|
// 1. Try to access the data directly.
|
|
|
|
String global_packed = ProjectSettings::get_singleton()->globalize_path(packed_path);
|
|
|
|
if (global_packed.is_absolute_path() && FileAccess::exists(global_packed.path_join(".dotnet-publish-manifest"))) {
|
|
|
|
data_dir_root = global_packed;
|
|
|
|
has_data = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!has_data) {
|
|
|
|
// 2. Check if the data was extracted before and is up-to-date.
|
|
|
|
String packed_manifest = packed_path.path_join(".dotnet-publish-manifest");
|
|
|
|
String extracted_manifest = data_dir_root.path_join(".dotnet-publish-manifest");
|
|
|
|
if (FileAccess::exists(packed_manifest) && FileAccess::exists(extracted_manifest)) {
|
|
|
|
if (FileAccess::get_file_as_bytes(packed_manifest) == FileAccess::get_file_as_bytes(extracted_manifest)) {
|
|
|
|
has_data = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!has_data) {
|
|
|
|
// 3. Extract the data to a temporary location to load from there.
|
|
|
|
Ref<DirAccess> da = DirAccess::create_for_path(packed_path);
|
|
|
|
ERR_FAIL_NULL(da);
|
|
|
|
ERR_FAIL_COND(da->copy_dir(packed_path, data_dir_root) != OK);
|
|
|
|
}
|
|
|
|
api_assemblies_dir = data_dir_root;
|
|
|
|
} else {
|
|
|
|
// The dotnet publish data is in a directory next to the executable.
|
|
|
|
String data_dir_root = exe_dir.path_join("data_" + appname_safe + "_" + arch);
|
|
|
|
if (!DirAccess::exists(data_dir_root)) {
|
|
|
|
data_dir_root = exe_dir.path_join("data_Godot_" + arch);
|
|
|
|
}
|
2022-07-20 08:28:22 +02:00
|
|
|
#ifdef MACOS_ENABLED
|
2023-04-20 22:25:21 +02:00
|
|
|
if (!DirAccess::exists(data_dir_root)) {
|
|
|
|
data_dir_root = res_dir.path_join("data_" + appname_safe + "_" + arch);
|
|
|
|
}
|
|
|
|
if (!DirAccess::exists(data_dir_root)) {
|
|
|
|
data_dir_root = res_dir.path_join("data_Godot_" + arch);
|
|
|
|
}
|
2018-10-03 19:01:57 +02:00
|
|
|
#endif
|
2023-04-20 22:25:21 +02:00
|
|
|
api_assemblies_dir = data_dir_root;
|
|
|
|
}
|
2021-12-28 23:25:16 +01:00
|
|
|
#endif
|
2017-10-02 23:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static _GodotSharpDirs &get_singleton() {
|
|
|
|
static _GodotSharpDirs singleton;
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
String get_res_metadata_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_metadata_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_res_temp_assemblies_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_temp_assemblies_dir;
|
|
|
|
}
|
|
|
|
|
2021-09-12 20:21:15 +02:00
|
|
|
String get_api_assemblies_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().api_assemblies_dir;
|
|
|
|
}
|
|
|
|
|
2017-10-02 23:24:00 +02:00
|
|
|
String get_mono_user_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().mono_user_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
String get_build_logs_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().build_logs_dir;
|
|
|
|
}
|
|
|
|
|
2018-10-03 19:01:57 +02:00
|
|
|
String get_data_editor_tools_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().data_editor_tools_dir;
|
|
|
|
}
|
2017-10-02 23:24:00 +02:00
|
|
|
#endif
|
2018-10-03 19:01:57 +02:00
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
} // namespace GodotSharpDirs
|