From ffc853ecd249bfbd04455e02a76b35414ff40b49 Mon Sep 17 00:00:00 2001 From: wrrrzr Date: Tue, 6 May 2025 22:25:11 +0300 Subject: [PATCH] Fix error --- src/constants.h | 5 +++++ src/main.cpp | 26 +++----------------------- src/porting.cpp | 25 +++++++++++++++++++++++++ src/porting.h | 3 +++ src/porting_android.cpp | 5 +++++ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/src/constants.h b/src/constants.h index e97bd0507..7816eee87 100644 --- a/src/constants.h +++ b/src/constants.h @@ -105,3 +105,8 @@ // The intent is to ensure that the rendering doesn't turn terribly blurry // when filtering is enabled. #define TEXTURE_FILTER_MIN_SIZE 192U + + +// Luanti config filenames +#define CONFIGFILE "luanti.conf" +#define LEGACY_CONFIGFILE "minetest.conf" diff --git a/src/main.cpp b/src/main.cpp index 75ee35f2d..ef6d273bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,8 +60,6 @@ extern "C" { #error ================================== #endif -#define CONFIGFILE "luanti.conf" -#define LEGACY_CONFIGFILE "minetest.conf" #define DEBUGFILE "debug.txt" #define DEFAULT_SERVER_PORT 30000 @@ -743,28 +741,10 @@ static void startup_message() } -#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) -static std::string xdg_get_config_dir() { - const char *const xdg_config_home = getenv("XDG_CONFIG_HOME"); - if (xdg_config_home) - return std::string(xdg_config_home) + DIR_DELIM "luanti"; - - const char *const home = getenv("HOME"); - // In rare cases the HOME environment variable may be unset - FATAL_ERROR_IF(!home, - "Required environment variable HOME is not set"); - return std::string(home) + DIR_DELIM ".config" DIR_DELIM "luanti"; -} -#endif - static bool read_config_file(const Settings &cmd_args) { // Path of configuration file in use sanity_check(g_settings_path.empty()); // Sanity check -#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) - fs::CreateAllDirs(xdg_get_config_dir()); -#endif - if (cmd_args.exists("config")) { bool r = g_settings->readConfigFile(cmd_args.get("config").c_str()); if (!r) { @@ -775,9 +755,9 @@ static bool read_config_file(const Settings &cmd_args) g_settings_path = cmd_args.get("config"); } else { std::vector filenames; -#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) - filenames.push_back(xdg_get_config_dir() + DIR_DELIM CONFIGFILE); -#endif + std::optional platform_specific_filename = porting::getPlatformSpecificConfigFile(); + if (platform_specific_filename != std::nullopt) + filenames.push_back(platform_specific_filename.value()); // Legacy configuration file location filenames.push_back(porting::path_user + DIR_DELIM + LEGACY_CONFIGFILE); // Very legacy configuration file location diff --git a/src/porting.cpp b/src/porting.cpp index fc0f06c4d..8ae0ee192 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -474,6 +474,7 @@ void migrateLegacyDirs() { #elif defined(__ANDROID__) extern bool setSystemPaths(); // defined in porting_android.cpp +extern void migrateLegacyDirs(); // defined in porting_android.cpp //// XDG systems @@ -1015,4 +1016,28 @@ void TriggerMemoryTrim() #endif +#if defined(__ANDROID__) +std::optional getPlatformSpecificConfigFile() { + return std::nullopt; +} +#elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) +static std::string xdg_get_config_dir() { + const char *const xdg_config_home = getenv("XDG_CONFIG_HOME"); + if (xdg_config_home) + return std::string(xdg_config_home) + DIR_DELIM "luanti"; + return std::string(getHomeOrFail()) + DIR_DELIM ".config" DIR_DELIM "luanti"; +} + +std::optional getPlatformSpecificConfigFile() { + std::string config_home = xdg_get_config_dir(); + fs::CreateAllDirs(config_home); + return config_home + DIR_DELIM CONFIGFILE; +} + +#else +std::optional getPlatformSpecificConfigFile() { + return std::nullopt; +} +#endif + } //namespace porting diff --git a/src/porting.h b/src/porting.h index e44dfb79d..520353468 100644 --- a/src/porting.h +++ b/src/porting.h @@ -14,6 +14,7 @@ // Be mindful of what you include here! #include +#include #include "config.h" #include "irrlichttypes.h" // u64 #include "debug.h" @@ -121,6 +122,8 @@ void initializePaths(); void migrateLegacyDirs(); +std::optional getPlatformSpecificConfigFile(); + /* Return system information e.g. "Linux/3.12.7 x86_64" diff --git a/src/porting_android.cpp b/src/porting_android.cpp index bc44a4e32..d885d04ff 100644 --- a/src/porting_android.cpp +++ b/src/porting_android.cpp @@ -40,6 +40,7 @@ namespace porting { void cleanupAndroid(); std::string getLanguageAndroid(); bool setSystemPaths(); // used in porting.cpp + void migrateLegacyDirs(); // used in porting.cpp } extern "C" int SDL_Main(int _argc, char *_argv[]) @@ -99,6 +100,10 @@ static std::string readJavaString(jstring j_str) return str; } +void migrateLegacyDirs() { + // Real migration in android/ +} + bool setSystemPaths() { // Set user and share paths