#include "UserData.h" #include #include #include std::string UserData::projectsDir; std::string UserData::brushesDir; void UserData::Init() { std::string writablePath; #ifdef __ANDROID__ // try public readable const char* prefPath = SDL_GetAndroidExternalStoragePath(); if (prefPath) { writablePath = prefPath; } else { // try /data/data by android api const char* internalPath = SDL_GetAndroidInternalStoragePath(); if (internalPath) { writablePath = internalPath; } else { // android fucked up, lets try anyway writablePath = "/data/data/io.tngl.hatlink.gradien/files"; } } if (!writablePath.empty() && (writablePath.back() == '/' || writablePath.back() == '\\')) { writablePath.pop_back(); } #else const char* xdgDataHome = std::getenv("XDG_DATA_HOME"); if (xdgDataHome != nullptr) { writablePath = xdgDataHome; } else { const char* homeEnv = std::getenv("HOME"); if (homeEnv != nullptr) { writablePath = homeEnv; writablePath += "/.local/share"; } else { throw std::runtime_error("Failed to find suitable location for user data"); } } writablePath += "/Gradien"; #endif projectsDir = writablePath + "/Projects"; brushesDir = writablePath + "/Brushes"; std::filesystem::create_directories(projectsDir); std::filesystem::create_directories(brushesDir); } std::string UserData::GetProjectsDir() { return projectsDir; } std::string UserData::GetBrushesDir() { return brushesDir; }