2011-10-02 10:05:45 +00:00
|
|
|
#ifdef NALL_STRING_INTERNAL_HPP
|
2010-10-14 10:07:38 +00:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
2012-06-18 10:13:51 +00:00
|
|
|
string activepath() {
|
|
|
|
string result;
|
|
|
|
#ifdef _WIN32
|
|
|
|
wchar_t path[PATH_MAX] = L"";
|
2012-11-02 10:37:38 +00:00
|
|
|
auto unused = _wgetcwd(path, PATH_MAX);
|
2012-06-18 10:13:51 +00:00
|
|
|
result = (const char*)utf8_t(path);
|
|
|
|
result.transform("\\", "/");
|
|
|
|
#else
|
|
|
|
char path[PATH_MAX] = "";
|
2012-11-02 10:37:38 +00:00
|
|
|
auto unused = getcwd(path, PATH_MAX);
|
2012-06-18 10:13:51 +00:00
|
|
|
result = path;
|
|
|
|
#endif
|
|
|
|
if(result.empty()) result = ".";
|
|
|
|
if(result.endswith("/") == false) result.append("/");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string realpath(const string &name) {
|
|
|
|
string result;
|
|
|
|
#ifdef _WIN32
|
|
|
|
wchar_t path[PATH_MAX] = L"";
|
|
|
|
if(_wfullpath(path, utf16_t(name), PATH_MAX)) result = (const char*)utf8_t(path);
|
|
|
|
result.transform("\\", "/");
|
|
|
|
#else
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
if(::realpath(name, path)) result = path;
|
|
|
|
#endif
|
2012-08-16 10:30:47 +00:00
|
|
|
if(result.empty()) result = {activepath(), name};
|
2012-06-18 10:13:51 +00:00
|
|
|
return result;
|
2010-10-14 10:07:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:27:15 +00:00
|
|
|
// /home/username/
|
|
|
|
// c:/users/username/
|
2010-10-14 10:07:38 +00:00
|
|
|
string userpath() {
|
2012-06-18 10:13:51 +00:00
|
|
|
string result;
|
|
|
|
#ifdef _WIN32
|
|
|
|
wchar_t path[PATH_MAX] = L"";
|
2013-01-21 12:27:15 +00:00
|
|
|
SHGetFolderPathW(0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, 0, 0, path);
|
2012-06-18 10:13:51 +00:00
|
|
|
result = (const char*)utf8_t(path);
|
|
|
|
result.transform("\\", "/");
|
|
|
|
#else
|
|
|
|
char path[PATH_MAX] = "";
|
|
|
|
struct passwd *userinfo = getpwuid(getuid());
|
|
|
|
if(userinfo) strcpy(path, userinfo->pw_dir);
|
|
|
|
result = path;
|
|
|
|
#endif
|
|
|
|
if(result.empty()) result = ".";
|
|
|
|
if(result.endswith("/") == false) result.append("/");
|
|
|
|
return result;
|
2010-10-14 10:07:38 +00:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:27:15 +00:00
|
|
|
// /home/username/.config/
|
|
|
|
// c:/users/username/appdata/roaming/
|
2012-06-18 10:13:51 +00:00
|
|
|
string configpath() {
|
2013-01-21 12:27:15 +00:00
|
|
|
string result;
|
2012-06-18 10:13:51 +00:00
|
|
|
#ifdef _WIN32
|
2013-01-21 12:27:15 +00:00
|
|
|
wchar_t path[PATH_MAX] = L"";
|
|
|
|
SHGetFolderPathW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 0, 0, path);
|
|
|
|
result = (const char*)utf8_t(path);
|
|
|
|
result.transform("\\", "/");
|
2012-06-18 10:13:51 +00:00
|
|
|
#else
|
2013-01-21 12:27:15 +00:00
|
|
|
result = {userpath(), ".config/"};
|
2012-06-18 10:13:51 +00:00
|
|
|
#endif
|
2013-01-21 12:27:15 +00:00
|
|
|
if(result.empty()) result = ".";
|
|
|
|
if(result.endswith("/") == false) result.append("/");
|
|
|
|
return result;
|
2010-10-14 10:07:38 +00:00
|
|
|
}
|
|
|
|
|
2012-08-16 10:30:47 +00:00
|
|
|
string temppath() {
|
|
|
|
#ifdef _WIN32
|
|
|
|
wchar_t path[PATH_MAX] = L"";
|
|
|
|
GetTempPathW(PATH_MAX, path);
|
2013-01-21 12:27:15 +00:00
|
|
|
string result = (const char*)utf8_t(path);
|
|
|
|
result.transform("\\", "/");
|
|
|
|
return result;
|
2012-08-16 10:30:47 +00:00
|
|
|
#else
|
|
|
|
return "/tmp/";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-10-14 10:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|