1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Move minetest.conf to .config/luanti/luanti.conf

This commit is contained in:
wrrrzr 2025-04-27 22:37:53 +03:00
parent d86c0a4313
commit 78eb7ba86e

View file

@ -60,8 +60,8 @@ extern "C" {
#error ================================== #error ==================================
#endif #endif
// TODO: luanti.conf with migration #define CONFIGFILE "luanti.conf"
#define CONFIGFILE "minetest.conf" #define LEGACY_CONFIGFILE "minetest.conf"
#define DEBUGFILE "debug.txt" #define DEBUGFILE "debug.txt"
#define DEFAULT_SERVER_PORT 30000 #define DEFAULT_SERVER_PORT 30000
@ -742,10 +742,28 @@ static void startup_message()
<< std::endl; << std::endl;
} }
#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) static bool read_config_file(const Settings &cmd_args)
{ {
// Path of configuration file in use // Path of configuration file in use
sanity_check(g_settings_path.empty()); // Sanity check 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")) { if (cmd_args.exists("config")) {
bool r = g_settings->readConfigFile(cmd_args.get("config").c_str()); bool r = g_settings->readConfigFile(cmd_args.get("config").c_str());
@ -757,10 +775,14 @@ static bool read_config_file(const Settings &cmd_args)
g_settings_path = cmd_args.get("config"); g_settings_path = cmd_args.get("config");
} else { } else {
std::vector<std::string> filenames; std::vector<std::string> filenames;
filenames.push_back(porting::path_user + DIR_DELIM + CONFIGFILE); #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
filenames.push_back(xdg_get_config_dir() + DIR_DELIM CONFIGFILE);
#endif
// Legacy configuration file location // Legacy configuration file location
filenames.push_back(porting::path_user + DIR_DELIM + LEGACY_CONFIGFILE);
// Very legacy configuration file location
filenames.push_back(porting::path_user + filenames.push_back(porting::path_user +
DIR_DELIM + ".." + DIR_DELIM + CONFIGFILE); DIR_DELIM + ".." + DIR_DELIM + LEGACY_CONFIGFILE);
#if RUN_IN_PLACE #if RUN_IN_PLACE
// Try also from a lower level (to aid having the same configuration // Try also from a lower level (to aid having the same configuration