Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566#include "UserData.h"#include <SDL3/SDL.h>#include <filesystem>#include <stdexcept>
std::string UserData::projectsDir;std::string UserData::brushesDir;std::string UserData::thumbnailsDir;
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"; thumbnailsDir = projectsDir + "/.thumbs";
std::filesystem::create_directories(projectsDir); std::filesystem::create_directories(brushesDir); std::filesystem::create_directories(thumbnailsDir);}
std::string UserData::GetProjectsDir() { return projectsDir;}
std::string UserData::GetBrushesDir() { return brushesDir;}
std::string UserData::GetThumbnailsDir() { return thumbnailsDir;}