diff --git a/include/config.h b/include/config.h index 5ab73ef..341468c 100644 --- a/include/config.h +++ b/include/config.h @@ -25,6 +25,8 @@ class configuration { static std::string get_resource_folder(); + static std::string get_linux_config_folder(); + static void build_logger(); // diff --git a/src/config.cpp b/src/config.cpp index 96b3d1c..ef8f971 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -9,6 +9,7 @@ #endif #ifdef SFML_SYSTEM_LINUX +#include #include #include #endif @@ -18,7 +19,7 @@ toml::value configuration::config; void configuration::build_config() { -#ifdef SFML_SYSTEM_MACOS +#if defined(SFML_SYSTEM_MACOS) std::filesystem::path folder_path = std::filesystem::path(sago::getConfigHome()) / std::filesystem::path("VectorAudio"); // On macOS we cannot be sure the folder exists as we don't use the folder of @@ -28,6 +29,12 @@ void configuration::build_config() } file_path = folder_path / std::filesystem::path(file_path); +#elif defined(SFML_SYSTEM_LINUX) + std::string config_path = get_linux_config_folder(); + if (!std::filesystem::exists(config_path)) { + std::filesystem::create_directory(config_path); + } + file_path = config_path + file_path; #else file_path = get_resource_folder() + file_path; #endif @@ -68,6 +75,18 @@ std::string configuration::get_resource_folder() #endif } +std::string configuration::get_linux_config_folder() +{ + char* xdg_config_home_chars = getenv("XDG_CONFIG_HOME"); + std::string suffix = "/vector_audio/"; + if (xdg_config_home_chars) { + std::string xdg_config_home(xdg_config_home_chars); + return xdg_config_home + suffix; + } + std::string home(getenv("HOME")); + return home + "/.config" + suffix; +} + void configuration::write_config_async() { std::thread([]() {