mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
#2152: XDG support
This commit is contained in:
parent
35d73695f8
commit
71585b7daa
@ -64,7 +64,7 @@ std::string PathImpl::homeImpl()
|
|||||||
pwd = getpwuid(geteuid());
|
pwd = getpwuid(geteuid());
|
||||||
if (pwd)
|
if (pwd)
|
||||||
path = pwd->pw_dir;
|
path = pwd->pw_dir;
|
||||||
else
|
else if (EnvironmentImpl::hasImpl("HOME"))
|
||||||
path = EnvironmentImpl::getImpl("HOME");
|
path = EnvironmentImpl::getImpl("HOME");
|
||||||
}
|
}
|
||||||
std::string::size_type n = path.size();
|
std::string::size_type n = path.size();
|
||||||
@ -78,15 +78,23 @@ std::string PathImpl::configHomeImpl()
|
|||||||
{
|
{
|
||||||
#if defined(POCO_VXWORKS)
|
#if defined(POCO_VXWORKS)
|
||||||
return PathImpl::homeImpl();
|
return PathImpl::homeImpl();
|
||||||
#else
|
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||||
std::string path = PathImpl::homeImpl();
|
std::string path = PathImpl::homeImpl();
|
||||||
std::string::size_type n = path.size();
|
std::string::size_type n = path.size();
|
||||||
if (n > 0 && path[n - 1] == '/')
|
if (n > 0 && path[n - 1] == '/')
|
||||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
path.append("Library/Preferences/");
|
||||||
path.append("Library/Preferences/");
|
return path;
|
||||||
#else
|
#else
|
||||||
path.append(".config/");
|
std::string path;
|
||||||
#endif
|
if (EnvironmentImpl::hasImpl("XDG_CONFIG_HOME"))
|
||||||
|
path = EnvironmentImpl::getImpl("XDG_CONFIG_HOME");
|
||||||
|
if (!path.empty())
|
||||||
|
return path;
|
||||||
|
|
||||||
|
path = PathImpl::homeImpl();
|
||||||
|
std::string::size_type n = path.size();
|
||||||
|
if (n > 0 && path[n - 1] == '/')
|
||||||
|
path.append(".config/");
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
#endif
|
#endif
|
||||||
@ -97,15 +105,23 @@ std::string PathImpl::dataHomeImpl()
|
|||||||
{
|
{
|
||||||
#if defined(POCO_VXWORKS)
|
#if defined(POCO_VXWORKS)
|
||||||
return PathImpl::homeImpl();
|
return PathImpl::homeImpl();
|
||||||
#else
|
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||||
std::string path = PathImpl::homeImpl();
|
std::string path = PathImpl::homeImpl();
|
||||||
std::string::size_type n = path.size();
|
std::string::size_type n = path.size();
|
||||||
if (n > 0 && path[n - 1] == '/')
|
if (n > 0 && path[n - 1] == '/')
|
||||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
path.append("Library/Application Support/");
|
||||||
path.append("Library/Application Support/");
|
return path;
|
||||||
#else
|
#else
|
||||||
path.append(".local/share/");
|
std::string path;
|
||||||
#endif
|
if (EnvironmentImpl::hasImpl("XDG_DATA_HOME"))
|
||||||
|
path = EnvironmentImpl::getImpl("XDG_DATA_HOME");
|
||||||
|
if (!path.empty())
|
||||||
|
return path;
|
||||||
|
|
||||||
|
path = PathImpl::homeImpl();
|
||||||
|
std::string::size_type n = path.size();
|
||||||
|
if (n > 0 && path[n - 1] == '/')
|
||||||
|
path.append(".local/share/");
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
#endif
|
#endif
|
||||||
@ -116,15 +132,23 @@ std::string PathImpl::cacheHomeImpl()
|
|||||||
{
|
{
|
||||||
#if defined(POCO_VXWORKS)
|
#if defined(POCO_VXWORKS)
|
||||||
return PathImpl::tempImpl();
|
return PathImpl::tempImpl();
|
||||||
#else
|
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||||
std::string path = PathImpl::homeImpl();
|
std::string path = PathImpl::homeImpl();
|
||||||
std::string::size_type n = path.size();
|
std::string::size_type n = path.size();
|
||||||
if (n > 0 && path[n - 1] == '/')
|
if (n > 0 && path[n - 1] == '/')
|
||||||
#if POCO_OS == POCO_OS_MAC_OS_X
|
path.append("Library/Caches/");
|
||||||
path.append("Library/Caches/");
|
return path;
|
||||||
#else
|
#else
|
||||||
path.append(".cache/");
|
std::string path;
|
||||||
#endif
|
if (EnvironmentImpl::hasImpl("XDG_CACHE_HOME"))
|
||||||
|
path = EnvironmentImpl::getImpl("XDG_CACHE_HOME");
|
||||||
|
if (!path.empty())
|
||||||
|
return path;
|
||||||
|
|
||||||
|
path = PathImpl::homeImpl();
|
||||||
|
std::string::size_type n = path.size();
|
||||||
|
if (n > 0 && path[n - 1] == '/')
|
||||||
|
path.append(".cache/");
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
#endif
|
#endif
|
||||||
@ -219,7 +243,15 @@ std::string PathImpl::expandImpl(const std::string& path)
|
|||||||
}
|
}
|
||||||
while (it != end)
|
while (it != end)
|
||||||
{
|
{
|
||||||
if (*it == '$')
|
if (*it == '\\')
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
if (*it == '$')
|
||||||
|
{
|
||||||
|
result += *it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (*it == '$')
|
||||||
{
|
{
|
||||||
std::string var;
|
std::string var;
|
||||||
++it;
|
++it;
|
||||||
@ -238,6 +270,12 @@ std::string PathImpl::expandImpl(const std::string& path)
|
|||||||
}
|
}
|
||||||
else result += *it++;
|
else result += *it++;
|
||||||
}
|
}
|
||||||
|
std::string::size_type found = result.find("//");
|
||||||
|
while (found != std::string::npos)
|
||||||
|
{
|
||||||
|
result.replace(found, 2, "/");
|
||||||
|
found = result.find("//", found+1);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,6 @@ bool SystemConfiguration::getRaw(const std::string& key, std::string& value) con
|
|||||||
{
|
{
|
||||||
value = Path::dataHome();
|
value = Path::dataHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (key == TEMPHOMEDIR)
|
else if (key == TEMPHOMEDIR)
|
||||||
{
|
{
|
||||||
value = Path::tempHome();
|
value = Path::tempHome();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user