2017-10-02 21:24:00 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* godotsharp_dirs.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-03 20:27:34 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-10-02 21:24:00 +00:00
|
|
|
/* */
|
|
|
|
/* 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-04 23:50:27 +00:00
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
#include "godotsharp_dirs.h"
|
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2021-06-11 12:51:48 +00:00
|
|
|
#include "core/io/dir_access.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/os/os.h"
|
2017-10-02 21:24:00 +00:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/version.h"
|
2022-02-14 13:00:03 +00:00
|
|
|
#include "editor/editor_paths.h"
|
2017-10-02 21:24:00 +00:00
|
|
|
#endif
|
|
|
|
|
2019-11-13 19:12:36 +00:00
|
|
|
#ifdef ANDROID_ENABLED
|
2020-04-18 19:28:51 +00:00
|
|
|
#include "mono_gd/support/android_support.h"
|
2019-07-03 15:41:07 +00:00
|
|
|
#endif
|
|
|
|
|
2019-10-10 23:23:35 +00:00
|
|
|
#include "mono_gd/gd_mono.h"
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
namespace GodotSharpDirs {
|
|
|
|
|
|
|
|
String _get_expected_build_config() {
|
|
|
|
#ifdef TOOLS_ENABLED
|
2020-03-18 13:50:49 +00:00
|
|
|
return "Debug";
|
2017-10-02 21:24:00 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
2020-03-18 13:50:49 +00:00
|
|
|
return "ExportDebug";
|
2017-10-02 21:24:00 +00:00
|
|
|
#else
|
2020-03-18 13:50:49 +00:00
|
|
|
return "ExportRelease";
|
2017-10-02 21:24:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
String _get_mono_user_dir() {
|
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-25 00:25:11 +00:00
|
|
|
if (EditorPaths::get_singleton()) {
|
|
|
|
return EditorPaths::get_singleton()->get_data_dir().plus_file("mono");
|
2017-10-02 21:24:00 +00:00
|
|
|
} else {
|
|
|
|
String settings_path;
|
|
|
|
|
2022-01-13 19:17:20 +00:00
|
|
|
// Self-contained mode if a `._sc_` or `_sc_` file is present in executable dir.
|
2017-10-17 09:36:19 +00:00
|
|
|
String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
|
2022-01-13 19:17:20 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2022-03-23 09:08:58 +00:00
|
|
|
Ref<DirAccess> d = DirAccess::create_for_path(exe_dir);
|
2017-10-17 09:36:19 +00:00
|
|
|
|
|
|
|
if (d->file_exists("._sc_") || d->file_exists("_sc_")) {
|
|
|
|
// contain yourself
|
|
|
|
settings_path = exe_dir.plus_file("editor_data");
|
|
|
|
} else {
|
Add initial support for the XDG Base Directory spec
Spec version 0.7 from https://standards.freedesktop.org/basedir-spec/basedir-spec-0.7.html
(latest as of this commit).
Three virtual methods are added to OS for the various XDG paths we will use:
- OS::get_data_path gives XDG_DATA_HOME, or if missing:
~/.local/share on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_config_path gives XDG_CONFIG_HOME, or if missing:
~/.config on X11, ~/Library/Application Support/ on macOS and %APPDATA% on Windows
- OS::get_cache_path gives XDG_CACHE_HOME, or if missing:
~/.cache on X11, ~/Library/Caches on macOS and %APPDATA% on Windows
So for Windows there are no changes, for Linux we follow the full split spec
and for macOS stuff will move from ~/.godot to ~/Library/Application Support/Godot.
Support for system-wide installation of templates on Unix was removed for now,
as it's a bit hackish and I don't think anyone uses it.
user:// will still be OS::get_data_path() + "/godot/app_userdata/$name" by
default, but when using the application/config/use_shared_user_dir option
it will now use XDG_DATA_HOME/$name, e.g. ~/.local/share/MyGame.
For now everything still goes in EditorSettings::get_settings_dir(), but
this will be changed in a later commit to make use of the new splitting
where relevant.
Part of #3513.
2017-11-17 16:11:41 +00:00
|
|
|
settings_path = OS::get_singleton()->get_data_path().plus_file(OS::get_singleton()->get_godot_dir_name());
|
2017-10-02 21:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return settings_path.plus_file("mono");
|
|
|
|
}
|
|
|
|
#else
|
2017-11-17 14:25:22 +00:00
|
|
|
return OS::get_singleton()->get_user_data_dir().plus_file("mono");
|
2017-10-02 21:24:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GodotSharpDirs {
|
|
|
|
public:
|
|
|
|
String res_data_dir;
|
|
|
|
String res_metadata_dir;
|
2019-07-03 07:44:53 +00:00
|
|
|
String res_assemblies_base_dir;
|
2017-10-02 21:24:00 +00:00
|
|
|
String res_assemblies_dir;
|
|
|
|
String res_config_dir;
|
|
|
|
String res_temp_dir;
|
|
|
|
String res_temp_assemblies_base_dir;
|
|
|
|
String res_temp_assemblies_dir;
|
|
|
|
String mono_user_dir;
|
|
|
|
String mono_logs_dir;
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
String mono_solutions_dir;
|
|
|
|
String build_logs_dir;
|
2018-10-03 17:01:57 +00:00
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
String sln_filepath;
|
|
|
|
String csproj_filepath;
|
2018-10-03 17:01:57 +00:00
|
|
|
|
|
|
|
String data_editor_tools_dir;
|
|
|
|
String data_editor_prebuilt_api_dir;
|
2019-11-28 22:42:37 +00:00
|
|
|
#else
|
|
|
|
// Equivalent of res_assemblies_dir, but in the data directory rather than in 'res://'.
|
|
|
|
// Only defined on export templates. Used when exporting assemblies outside of PCKs.
|
|
|
|
String data_game_assemblies_dir;
|
2017-10-02 21:24:00 +00:00
|
|
|
#endif
|
|
|
|
|
2018-10-03 17:01:57 +00:00
|
|
|
String data_mono_etc_dir;
|
|
|
|
String data_mono_lib_dir;
|
|
|
|
|
2019-02-15 17:49:04 +00:00
|
|
|
#ifdef WINDOWS_ENABLED
|
|
|
|
String data_mono_bin_dir;
|
|
|
|
#endif
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
private:
|
|
|
|
_GodotSharpDirs() {
|
2021-09-10 15:32:29 +00:00
|
|
|
res_data_dir = ProjectSettings::get_singleton()->get_project_data_path().plus_file("mono");
|
2017-10-02 21:24:00 +00:00
|
|
|
res_metadata_dir = res_data_dir.plus_file("metadata");
|
2019-07-03 07:44:53 +00:00
|
|
|
res_assemblies_base_dir = res_data_dir.plus_file("assemblies");
|
2019-10-10 23:23:35 +00:00
|
|
|
res_assemblies_dir = res_assemblies_base_dir.plus_file(GDMono::get_expected_api_build_config());
|
2017-10-02 21:24:00 +00:00
|
|
|
res_config_dir = res_data_dir.plus_file("etc").plus_file("mono");
|
|
|
|
|
|
|
|
// TODO use paths from csproj
|
|
|
|
res_temp_dir = res_data_dir.plus_file("temp");
|
|
|
|
res_temp_assemblies_base_dir = res_temp_dir.plus_file("bin");
|
|
|
|
res_temp_assemblies_dir = res_temp_assemblies_base_dir.plus_file(_get_expected_build_config());
|
|
|
|
|
2019-11-10 16:10:38 +00:00
|
|
|
#ifdef JAVASCRIPT_ENABLED
|
|
|
|
mono_user_dir = "user://";
|
|
|
|
#else
|
2017-10-02 21:24:00 +00:00
|
|
|
mono_user_dir = _get_mono_user_dir();
|
2019-11-10 16:10:38 +00:00
|
|
|
#endif
|
2017-10-02 21:24:00 +00:00
|
|
|
mono_logs_dir = mono_user_dir.plus_file("mono_logs");
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
mono_solutions_dir = mono_user_dir.plus_file("solutions");
|
|
|
|
build_logs_dir = mono_user_dir.plus_file("build_logs");
|
2017-10-27 19:22:54 +00:00
|
|
|
|
2019-07-03 15:41:07 +00:00
|
|
|
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
|
|
|
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
2020-12-15 12:04:21 +00:00
|
|
|
if (appname_safe.is_empty()) {
|
2019-07-03 15:41:07 +00:00
|
|
|
appname_safe = "UnnamedProject";
|
2017-10-27 19:22:54 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 17:01:57 +00:00
|
|
|
String base_path = ProjectSettings::get_singleton()->globalize_path("res://");
|
|
|
|
|
2019-07-03 15:41:07 +00:00
|
|
|
sln_filepath = base_path.plus_file(appname_safe + ".sln");
|
|
|
|
csproj_filepath = base_path.plus_file(appname_safe + ".csproj");
|
2018-10-03 17:01:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
String exe_dir = OS::get_singleton()->get_executable_path().get_base_dir();
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
String data_dir_root = exe_dir.plus_file("GodotSharp");
|
|
|
|
data_editor_tools_dir = data_dir_root.plus_file("Tools");
|
|
|
|
data_editor_prebuilt_api_dir = data_dir_root.plus_file("Api");
|
|
|
|
|
|
|
|
String data_mono_root_dir = data_dir_root.plus_file("Mono");
|
|
|
|
data_mono_etc_dir = data_mono_root_dir.plus_file("etc");
|
2019-07-03 15:41:07 +00:00
|
|
|
|
2019-11-13 19:12:36 +00:00
|
|
|
#ifdef ANDROID_ENABLED
|
2020-03-18 16:40:04 +00:00
|
|
|
data_mono_lib_dir = gdmono::android::support::get_app_native_lib_dir();
|
2019-07-03 15:41:07 +00:00
|
|
|
#else
|
2018-10-03 17:01:57 +00:00
|
|
|
data_mono_lib_dir = data_mono_root_dir.plus_file("lib");
|
2019-07-03 15:41:07 +00:00
|
|
|
#endif
|
2018-10-03 17:01:57 +00:00
|
|
|
|
2019-02-15 17:49:04 +00:00
|
|
|
#ifdef WINDOWS_ENABLED
|
|
|
|
data_mono_bin_dir = data_mono_root_dir.plus_file("bin");
|
|
|
|
#endif
|
|
|
|
|
2022-07-20 06:28:22 +00:00
|
|
|
#ifdef MACOS_ENABLED
|
2018-10-03 17:01:57 +00:00
|
|
|
if (!DirAccess::exists(data_editor_tools_dir)) {
|
2020-11-22 06:17:15 +00:00
|
|
|
data_editor_tools_dir = exe_dir.plus_file("../Resources/GodotSharp/Tools");
|
2018-10-03 17:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!DirAccess::exists(data_editor_prebuilt_api_dir)) {
|
2020-11-22 06:17:15 +00:00
|
|
|
data_editor_prebuilt_api_dir = exe_dir.plus_file("../Resources/GodotSharp/Api");
|
2018-10-03 17:01:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!DirAccess::exists(data_mono_root_dir)) {
|
|
|
|
data_mono_etc_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/etc");
|
2020-11-22 06:17:15 +00:00
|
|
|
data_mono_lib_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/lib");
|
2018-10-03 17:01:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2019-07-03 15:41:07 +00:00
|
|
|
String appname = ProjectSettings::get_singleton()->get("application/config/name");
|
|
|
|
String appname_safe = OS::get_singleton()->get_safe_dir_name(appname);
|
|
|
|
String data_dir_root = exe_dir.plus_file("data_" + appname_safe);
|
2018-10-03 17:01:57 +00:00
|
|
|
if (!DirAccess::exists(data_dir_root)) {
|
|
|
|
data_dir_root = exe_dir.plus_file("data_Godot");
|
|
|
|
}
|
|
|
|
|
|
|
|
String data_mono_root_dir = data_dir_root.plus_file("Mono");
|
|
|
|
data_mono_etc_dir = data_mono_root_dir.plus_file("etc");
|
2019-07-03 15:41:07 +00:00
|
|
|
|
2019-11-13 19:12:36 +00:00
|
|
|
#ifdef ANDROID_ENABLED
|
2020-03-18 16:40:04 +00:00
|
|
|
data_mono_lib_dir = gdmono::android::support::get_app_native_lib_dir();
|
2019-07-03 15:41:07 +00:00
|
|
|
#else
|
2018-10-03 17:01:57 +00:00
|
|
|
data_mono_lib_dir = data_mono_root_dir.plus_file("lib");
|
2019-11-28 22:42:37 +00:00
|
|
|
data_game_assemblies_dir = data_dir_root.plus_file("Assemblies");
|
2019-07-03 15:41:07 +00:00
|
|
|
#endif
|
2018-10-03 17:01:57 +00:00
|
|
|
|
2019-02-15 17:49:04 +00:00
|
|
|
#ifdef WINDOWS_ENABLED
|
|
|
|
data_mono_bin_dir = data_mono_root_dir.plus_file("bin");
|
|
|
|
#endif
|
|
|
|
|
2022-07-20 06:28:22 +00:00
|
|
|
#ifdef MACOS_ENABLED
|
2018-10-03 17:01:57 +00:00
|
|
|
if (!DirAccess::exists(data_mono_root_dir)) {
|
|
|
|
data_mono_etc_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/etc");
|
2020-11-22 06:17:15 +00:00
|
|
|
data_mono_lib_dir = exe_dir.plus_file("../Resources/GodotSharp/Mono/lib");
|
2018-10-03 17:01:57 +00:00
|
|
|
}
|
2019-11-28 22:42:37 +00:00
|
|
|
|
|
|
|
if (!DirAccess::exists(data_game_assemblies_dir)) {
|
2020-11-22 06:17:15 +00:00
|
|
|
data_game_assemblies_dir = exe_dir.plus_file("../Resources/GodotSharp/Assemblies");
|
2019-11-28 22:42:37 +00:00
|
|
|
}
|
2018-10-03 17:01:57 +00:00
|
|
|
#endif
|
2017-10-27 19:22:54 +00:00
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static _GodotSharpDirs &get_singleton() {
|
|
|
|
static _GodotSharpDirs singleton;
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
String get_res_data_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_data_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_res_metadata_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_metadata_dir;
|
|
|
|
}
|
|
|
|
|
2019-07-03 07:44:53 +00:00
|
|
|
String get_res_assemblies_base_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_assemblies_base_dir;
|
|
|
|
}
|
|
|
|
|
2017-10-02 21:24:00 +00:00
|
|
|
String get_res_assemblies_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_assemblies_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_res_config_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_config_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_res_temp_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_temp_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_res_temp_assemblies_base_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_temp_assemblies_base_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_res_temp_assemblies_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().res_temp_assemblies_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_mono_user_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().mono_user_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_mono_logs_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().mono_logs_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
String get_mono_solutions_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().mono_solutions_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_build_logs_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().build_logs_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_project_sln_path() {
|
|
|
|
return _GodotSharpDirs::get_singleton().sln_filepath;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_project_csproj_path() {
|
|
|
|
return _GodotSharpDirs::get_singleton().csproj_filepath;
|
|
|
|
}
|
2018-10-03 17:01:57 +00:00
|
|
|
|
|
|
|
String get_data_editor_tools_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().data_editor_tools_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_data_editor_prebuilt_api_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().data_editor_prebuilt_api_dir;
|
|
|
|
}
|
2019-11-28 22:42:37 +00:00
|
|
|
#else
|
|
|
|
String get_data_game_assemblies_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().data_game_assemblies_dir;
|
|
|
|
}
|
2017-10-02 21:24:00 +00:00
|
|
|
#endif
|
2018-10-03 17:01:57 +00:00
|
|
|
|
|
|
|
String get_data_mono_etc_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().data_mono_etc_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get_data_mono_lib_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().data_mono_lib_dir;
|
|
|
|
}
|
|
|
|
|
2019-02-15 17:49:04 +00:00
|
|
|
#ifdef WINDOWS_ENABLED
|
|
|
|
String get_data_mono_bin_dir() {
|
|
|
|
return _GodotSharpDirs::get_singleton().data_mono_bin_dir;
|
|
|
|
}
|
|
|
|
#endif
|
2017-12-06 20:36:34 +00:00
|
|
|
} // namespace GodotSharpDirs
|