diff --git a/src/config/settings.cpp b/src/config/settings.cpp index 28a2ca1..e5834dd 100644 --- a/src/config/settings.cpp +++ b/src/config/settings.cpp @@ -110,33 +110,11 @@ void loadClamped(const json& j, const char* key, T& field, T lo, T hi) std::string Settings::getDefaultPath() { -#ifdef _WIN32 - char path[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, path))) { - std::string dir = std::string(path) + "\\" DRAGONX_APP_NAME; - fs::create_directories(dir); - return dir + "\\settings.json"; - } - return "settings.json"; -#elif defined(__APPLE__) - const char* home = getenv("HOME"); - if (!home) { - struct passwd* pw = getpwuid(getuid()); - home = pw->pw_dir; - } - std::string dir = std::string(home) + "/Library/Application Support/" DRAGONX_APP_NAME; + // Single per-platform, per-variant config dir (util::Platform::getConfigDir handles the + // _WIN32 / __APPLE__ / XDG split and the DRAGONX_APP_NAME variant suffix in one place). + const std::string dir = util::Platform::getConfigDir(); fs::create_directories(dir); - return dir + "/settings.json"; -#else - const char* home = getenv("HOME"); - if (!home) { - struct passwd* pw = getpwuid(getuid()); - home = pw->pw_dir; - } - std::string dir = std::string(home) + "/.config/" DRAGONX_APP_NAME; - fs::create_directories(dir); - return dir + "/settings.json"; -#endif + return (fs::path(dir) / "settings.json").string(); } bool Settings::load() diff --git a/src/data/address_book.cpp b/src/data/address_book.cpp index dd1a56b..1b06a20 100644 --- a/src/data/address_book.cpp +++ b/src/data/address_book.cpp @@ -10,14 +10,6 @@ #include "../util/logger.h" #include "../util/platform.h" -#include "../config/version.h" // DRAGONX_APP_NAME (per-variant: ObsidianDragon / ObsidianDragonLite) - -#ifdef _WIN32 -#include -#else -#include -#include -#endif namespace fs = std::filesystem; using json = nlohmann::json; @@ -30,36 +22,11 @@ AddressBook::~AddressBook() = default; std::string AddressBook::getDefaultPath() { - // Co-locate with settings.json in the per-variant config dir. Use DRAGONX_APP_NAME - // (not a hardcoded "ObsidianDragon") so the Lite build writes to ObsidianDragonLite/ - // rather than polluting the full-node app's directory — matching Settings::getDefaultPath(). -#ifdef _WIN32 - char path[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, path))) { - std::string dir = std::string(path) + "\\" DRAGONX_APP_NAME; - fs::create_directories(dir); - return dir + "\\addressbook.json"; - } - return "addressbook.json"; -#elif defined(__APPLE__) - const char* home = getenv("HOME"); - if (!home) { - struct passwd* pw = getpwuid(getuid()); - home = pw->pw_dir; - } - std::string dir = std::string(home) + "/Library/Application Support/" DRAGONX_APP_NAME; + // Co-locate with settings.json in the per-variant config dir (Lite -> ObsidianDragonLite/). + // util::Platform::getConfigDir() owns the per-platform + per-variant path in one place. + const std::string dir = util::Platform::getConfigDir(); fs::create_directories(dir); - return dir + "/addressbook.json"; -#else - const char* home = getenv("HOME"); - if (!home) { - struct passwd* pw = getpwuid(getuid()); - home = pw->pw_dir; - } - std::string dir = std::string(home) + "/.config/" DRAGONX_APP_NAME; - fs::create_directories(dir); - return dir + "/addressbook.json"; -#endif + return (fs::path(dir) / "addressbook.json").string(); } bool AddressBook::load() diff --git a/src/util/platform.cpp b/src/util/platform.cpp index 8b2e55b..6ebe8bd 100644 --- a/src/util/platform.cpp +++ b/src/util/platform.cpp @@ -245,6 +245,9 @@ std::string Platform::getConfigDir() return std::string(path) + "\\" DRAGONX_APP_NAME "\\"; } return getHomeDir() + "\\AppData\\Roaming\\" DRAGONX_APP_NAME "\\"; +#elif defined(__APPLE__) + // macOS-native config location (matches what settings.json / addressbook.json use). + return getHomeDir() + "/Library/Application Support/" DRAGONX_APP_NAME "/"; #else return getHomeDir() + "/.config/" DRAGONX_APP_NAME "/"; #endif