#include #include #include #include #ifdef _WIN32 #define READABLE(p) _access(p.c_str(),R_OK)==0 #else #define READABLE(p) access(p.c_str(),R_OK)==0 #endif std::string prefixCustom; std::string prefixDefault; void initPrefixes() { #if defined (__gnu_linux__) prefixCustom = getenv("HOME") + std::string("/.local/share/facecam2d/"); prefixDefault = "/usr/share/facecam2d/"; #elif defined (__APPLE__) prefixCustom = getenv("HOME") + std::string("/Library/Facecam2D/"); prefixDefault = "/Applications/Facecam2D.app/"; #elif defined (_WIN32) prefixCustom = getenv("AppData") + std::string("\\Facecam2D\\"); prefixDefault = getenv("ProgramFiles") + std::string("\\Facecam2D\\"); #endif } std::string resolvePath(const char* path) { std::string customString = prefixCustom + path; std::string defaultString = prefixDefault + path; std::string result; if (READABLE(customString)) { result = customString; } else if (READABLE(defaultString)) { result = defaultString; } else { result = path; if(!(READABLE(std::string(path)))) { std::cerr << path << " not found!" << std::endl; } } return result; }