pathut: add path_cachedir
This commit is contained in:
parent
0226988817
commit
1a20debf56
@ -684,6 +684,48 @@ string path_home()
|
||||
#endif
|
||||
}
|
||||
|
||||
string path_cachedir()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
string dir;
|
||||
wchar_t *cp;
|
||||
SHGetKnownFolderPath(FOLDERID_InternetCache, 0, nullptr, &cp);
|
||||
if (cp != 0) {
|
||||
wchartoutf8(cp, dir);
|
||||
}
|
||||
if (dir.empty()) {
|
||||
cp = _wgetenv(L"HOMEDRIVE");
|
||||
wchartoutf8(cp, dir);
|
||||
if (cp != 0) {
|
||||
string dir1;
|
||||
const wchar_t *cp1 = _wgetenv(L"HOMEPATH");
|
||||
wchartoutf8(cp1, dir1);
|
||||
if (cp1 != 0) {
|
||||
dir = path_cat(dir, dir1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dir.empty()) {
|
||||
dir = "C:/";
|
||||
}
|
||||
dir = path_canon(dir);
|
||||
path_catslash(dir);
|
||||
return dir;
|
||||
#else
|
||||
static string xdgcache;
|
||||
if (xdgcache.empty()) {
|
||||
const char *cp = getenv("XDG_CACHE_HOME");
|
||||
if (cp == 0) {
|
||||
xdgcache = path_cat(path_home(), ".cache");
|
||||
} else {
|
||||
xdgcache = string(cp);
|
||||
}
|
||||
path_catslash(xdgcache);
|
||||
}
|
||||
return xdgcache;
|
||||
#endif
|
||||
}
|
||||
|
||||
string path_tildexpand(const string& s)
|
||||
{
|
||||
if (s.empty() || s[0] != '~') {
|
||||
|
||||
@ -56,6 +56,9 @@ bool path_samefile(const std::string& p1, const std::string& p2);
|
||||
|
||||
/// Get the current user's home directory
|
||||
extern std::string path_home();
|
||||
/// Get the top location for cached data
|
||||
extern std::string path_cachedir();
|
||||
|
||||
/// Expand ~ at the beginning of std::string
|
||||
extern std::string path_tildexpand(const std::string& s);
|
||||
/// Use getcwd() to make absolute path if needed. Beware: ***this can fail***
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user