Only support XDG directory path configuration on Linux
This also harmonizes the server code to be consistent with Linux desktop (with warnings printed for relative XDG paths). Co-authored-by: Rémi Verschelde <rverschelde@gmail.com>
This commit is contained in:
parent
9ef525c3a0
commit
06c266f231
4 changed files with 40 additions and 67 deletions
|
@ -143,7 +143,7 @@
|
|||
<method name="get_cache_dir" qualifiers="const">
|
||||
<return type="String" />
|
||||
<description>
|
||||
Returns the [i]global[/i] cache data directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_CACHE_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_config_dir] and [method get_data_dir].
|
||||
Returns the [i]global[/i] cache data directory according to the operating system's standards. On Linux, this path can be overridden by setting the [code]XDG_CACHE_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_config_dir] and [method get_data_dir].
|
||||
Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path.
|
||||
</description>
|
||||
</method>
|
||||
|
@ -171,7 +171,7 @@
|
|||
<method name="get_config_dir" qualifiers="const">
|
||||
<return type="String" />
|
||||
<description>
|
||||
Returns the [i]global[/i] user configuration directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_CONFIG_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_data_dir].
|
||||
Returns the [i]global[/i] user configuration directory according to the operating system's standards. On Linux, this path can be overridden by setting the [code]XDG_CONFIG_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_data_dir].
|
||||
Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path.
|
||||
</description>
|
||||
</method>
|
||||
|
@ -192,7 +192,7 @@
|
|||
<method name="get_data_dir" qualifiers="const">
|
||||
<return type="String" />
|
||||
<description>
|
||||
Returns the [i]global[/i] user data directory according to the operating system's standards. On desktop platforms, this path can be overridden by setting the [code]XDG_DATA_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_config_dir].
|
||||
Returns the [i]global[/i] user data directory according to the operating system's standards. On Linux, this path can be overridden by setting the [code]XDG_DATA_HOME[/code] environment variable before starting the project. See [url=$DOCS_URL/tutorials/io/data_paths.html]File paths in Godot projects[/url] in the documentation for more information. See also [method get_cache_dir] and [method get_config_dir].
|
||||
Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path.
|
||||
</description>
|
||||
</method>
|
||||
|
|
|
@ -2327,14 +2327,6 @@ MainLoop *OS_OSX::get_main_loop() const {
|
|||
}
|
||||
|
||||
String OS_OSX::get_config_path() const {
|
||||
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on macOS as well.
|
||||
if (has_environment("XDG_CONFIG_HOME")) {
|
||||
if (get_environment("XDG_CONFIG_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_CONFIG_HOME");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `$HOME/Library/Application Support` or `.` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file("Library/Application Support");
|
||||
}
|
||||
|
@ -2342,26 +2334,10 @@ String OS_OSX::get_config_path() const {
|
|||
}
|
||||
|
||||
String OS_OSX::get_data_path() const {
|
||||
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on macOS as well.
|
||||
if (has_environment("XDG_DATA_HOME")) {
|
||||
if (get_environment("XDG_DATA_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_DATA_HOME");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `get_config_path()` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
return get_config_path();
|
||||
}
|
||||
|
||||
String OS_OSX::get_cache_path() const {
|
||||
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on macOS as well.
|
||||
if (has_environment("XDG_CACHE_HOME")) {
|
||||
if (get_environment("XDG_CACHE_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_CACHE_HOME");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `$HOME/Library/Caches` or `get_config_path()` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file("Library/Caches");
|
||||
}
|
||||
|
|
|
@ -207,33 +207,54 @@ void OS_Server::run() {
|
|||
}
|
||||
|
||||
String OS_Server::get_config_path() const {
|
||||
#ifndef __APPLE__
|
||||
if (has_environment("XDG_CONFIG_HOME")) {
|
||||
return get_environment("XDG_CONFIG_HOME");
|
||||
} else if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file(".config");
|
||||
} else {
|
||||
return ".";
|
||||
if (get_environment("XDG_CONFIG_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_CONFIG_HOME");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.config` or `.` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file(".config");
|
||||
}
|
||||
return ".";
|
||||
}
|
||||
|
||||
String OS_Server::get_data_path() const {
|
||||
#ifndef __APPLE__
|
||||
if (has_environment("XDG_DATA_HOME")) {
|
||||
return get_environment("XDG_DATA_HOME");
|
||||
} else if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file(".local/share");
|
||||
} else {
|
||||
return get_config_path();
|
||||
if (get_environment("XDG_DATA_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_DATA_HOME");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.local/share` or `get_config_path()` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file(".local/share");
|
||||
}
|
||||
return get_config_path();
|
||||
}
|
||||
|
||||
String OS_Server::get_cache_path() const {
|
||||
#ifndef __APPLE__
|
||||
if (has_environment("XDG_CACHE_HOME")) {
|
||||
return get_environment("XDG_CACHE_HOME");
|
||||
} else if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file(".cache");
|
||||
} else {
|
||||
return get_config_path();
|
||||
if (get_environment("XDG_CACHE_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_CACHE_HOME");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `$HOME/.cache` or `get_config_path()` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (has_environment("HOME")) {
|
||||
return get_environment("HOME").plus_file(".cache");
|
||||
}
|
||||
return get_config_path();
|
||||
}
|
||||
|
||||
String OS_Server::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
|
||||
|
|
|
@ -3642,14 +3642,6 @@ uint64_t OS_Windows::get_embedded_pck_offset() const {
|
|||
}
|
||||
|
||||
String OS_Windows::get_config_path() const {
|
||||
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well.
|
||||
if (has_environment("XDG_CONFIG_HOME")) {
|
||||
if (get_environment("XDG_CONFIG_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_CONFIG_HOME").replace("\\", "/");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_CONFIG_HOME` is a relative path. Ignoring its value and falling back to `%APPDATA%` or `.` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
if (has_environment("APPDATA")) {
|
||||
return get_environment("APPDATA").replace("\\", "/");
|
||||
}
|
||||
|
@ -3657,29 +3649,13 @@ String OS_Windows::get_config_path() const {
|
|||
}
|
||||
|
||||
String OS_Windows::get_data_path() const {
|
||||
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well.
|
||||
if (has_environment("XDG_DATA_HOME")) {
|
||||
if (get_environment("XDG_DATA_HOME").is_abs_path()) {
|
||||
return get_environment("XDG_DATA_HOME").replace("\\", "/");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_DATA_HOME` is a relative path. Ignoring its value and falling back to `get_config_path()` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
return get_config_path();
|
||||
}
|
||||
|
||||
String OS_Windows::get_cache_path() const {
|
||||
static String cache_path_cache;
|
||||
if (cache_path_cache == String()) {
|
||||
// The XDG Base Directory specification technically only applies on Linux/*BSD, but it doesn't hurt to support it on Windows as well.
|
||||
if (has_environment("XDG_CACHE_HOME")) {
|
||||
if (get_environment("XDG_CACHE_HOME").is_abs_path()) {
|
||||
cache_path_cache = get_environment("XDG_CACHE_HOME").replace("\\", "/");
|
||||
} else {
|
||||
WARN_PRINT_ONCE("`XDG_CACHE_HOME` is a relative path. Ignoring its value and falling back to `%LOCALAPPDATA%\\cache`, `%TEMP%` or `get_config_path()` per the XDG Base Directory specification.");
|
||||
}
|
||||
}
|
||||
if (cache_path_cache == String() && has_environment("LOCALAPPDATA")) {
|
||||
if (has_environment("LOCALAPPDATA")) {
|
||||
cache_path_cache = get_environment("LOCALAPPDATA").replace("\\", "/");
|
||||
}
|
||||
if (cache_path_cache == String() && has_environment("TEMP")) {
|
||||
|
|
Loading…
Reference in a new issue