mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 11:31:53 +01:00
committed by
Alex Fabijanic
parent
2632f34e85
commit
275275baa9
@@ -289,6 +289,24 @@ public:
|
||||
static std::string home();
|
||||
/// Returns the user's home directory.
|
||||
|
||||
static std::string configHome();
|
||||
/// Returns the user's config directory.
|
||||
///
|
||||
/// On Unix systems, this is the '~/.config/'. On Windows systems,
|
||||
/// this is '%APPDATA%'.
|
||||
|
||||
static std::string dataHome();
|
||||
/// Returns the user's data directory.
|
||||
///
|
||||
/// On Unix systems, this is the '~/.local/share/'. On Windows systems,
|
||||
/// this is '%APPDATA%'.
|
||||
|
||||
static std::string cacheHome();
|
||||
/// Returns the user's cache directory.
|
||||
///
|
||||
/// On Unix systems, this is the '~/.cache/'. On Windows systems,
|
||||
/// this is '%APPDATA%'.
|
||||
|
||||
static std::string temp();
|
||||
/// Returns the temporary directory.
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ class PathImpl
|
||||
public:
|
||||
static std::string currentImpl();
|
||||
static std::string homeImpl();
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string expandImpl(const std::string& path);
|
||||
|
||||
@@ -30,6 +30,9 @@ class Foundation_API PathImpl
|
||||
public:
|
||||
static std::string currentImpl();
|
||||
static std::string homeImpl();
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string systemImpl();
|
||||
|
||||
@@ -30,6 +30,9 @@ class Foundation_API PathImpl
|
||||
public:
|
||||
static std::string currentImpl();
|
||||
static std::string homeImpl();
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string systemImpl();
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
static std::string configHomeImpl();
|
||||
static std::string dataHomeImpl();
|
||||
static std::string cacheHomeImpl();
|
||||
static std::string tempHomeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string configImpl();
|
||||
static std::string nullImpl();
|
||||
|
||||
@@ -569,6 +569,16 @@ std::string Path::home()
|
||||
}
|
||||
|
||||
|
||||
std::string Path::cacheHome()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
|
||||
return PathImpl::cacheHomeImpl();
|
||||
#else
|
||||
return PathImpl::homeImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string Path::temp()
|
||||
{
|
||||
return PathImpl::tempImpl();
|
||||
|
||||
@@ -74,6 +74,87 @@ std::string PathImpl::homeImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configHomeImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
return PathImpl::homeImpl();
|
||||
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||
std::string path = PathImpl::homeImpl();
|
||||
std::string::size_type n = path.size();
|
||||
if (n > 0 && path[n - 1] == '/')
|
||||
path.append("Library/Preferences/");
|
||||
return path;
|
||||
#else
|
||||
std::string path;
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::dataHomeImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
return PathImpl::homeImpl();
|
||||
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||
std::string path = PathImpl::homeImpl();
|
||||
std::string::size_type n = path.size();
|
||||
if (n > 0 && path[n - 1] == '/')
|
||||
path.append("Library/Application Support/");
|
||||
return path;
|
||||
#else
|
||||
std::string path;
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::cacheHomeImpl()
|
||||
{
|
||||
#if defined(POCO_VXWORKS)
|
||||
return PathImpl::tempImpl();
|
||||
#elif POCO_OS == POCO_OS_MAC_OS_X
|
||||
std::string path = PathImpl::homeImpl();
|
||||
std::string::size_type n = path.size();
|
||||
if (n > 0 && path[n - 1] == '/')
|
||||
path.append("Library/Caches/");
|
||||
return path;
|
||||
#else
|
||||
std::string path;
|
||||
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;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempImpl()
|
||||
{
|
||||
std::string path;
|
||||
|
||||
@@ -74,6 +74,54 @@ std::string PathImpl::homeImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if APPDATA environment variable not exist, return home directory instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("APPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = homeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::dataHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if LOCALAPPDATA environment variable not exist, return config home instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("LOCALAPPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = configHomeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::cacheHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempImpl()
|
||||
{
|
||||
char buffer[MAX_PATH];
|
||||
|
||||
@@ -84,6 +84,54 @@ std::string PathImpl::homeImpl()
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if APPDATA environment variable no exist, return home directory instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("APPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = homeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::dataHomeImpl()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
// if LOCALAPPDATA environment variable no exist, return config home instead
|
||||
try
|
||||
{
|
||||
result = EnvironmentImpl::getImpl("LOCALAPPDATA");
|
||||
}
|
||||
catch (NotFoundException&)
|
||||
{
|
||||
result = configHomeImpl();
|
||||
}
|
||||
|
||||
std::string::size_type n = result.size();
|
||||
if (n > 0 && result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::cacheHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempImpl()
|
||||
{
|
||||
Buffer<wchar_t> buffer(MAX_PATH_LEN);
|
||||
|
||||
@@ -49,11 +49,13 @@ std::string PathImpl::cacheHomeImpl()
|
||||
return homeImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempHomeImpl()
|
||||
{
|
||||
return tempImpl();
|
||||
}
|
||||
|
||||
|
||||
std::string PathImpl::configImpl()
|
||||
{
|
||||
return("\\");
|
||||
|
||||
@@ -39,6 +39,9 @@ class Util_API SystemConfiguration: public AbstractConfiguration
|
||||
/// of the first Ethernet adapter found on the system.
|
||||
/// - system.currentDir: the current working directory
|
||||
/// - system.homeDir: the user's home directory
|
||||
/// - system.configHomeDir: the base directory relative to which user specific configuration files should be stored
|
||||
/// - system.cacheHomeDir: the base directory relative to which user specific non-essential data files should be stored
|
||||
/// - system.dataHomeDir: the base directory relative to which user specific data files should be stored
|
||||
/// - system.tempDir: the system's temporary directory
|
||||
/// - system.dateTime: the current UTC date and time, formatted in ISO 8601 format.
|
||||
/// - system.pid: the current process ID.
|
||||
@@ -74,6 +77,9 @@ private:
|
||||
static const std::string NODEID;
|
||||
static const std::string CURRENTDIR;
|
||||
static const std::string HOMEDIR;
|
||||
static const std::string CONFIGHOMEDIR;
|
||||
static const std::string CACHEHOMEDIR;
|
||||
static const std::string DATAHOMEDIR;
|
||||
static const std::string TEMPDIR;
|
||||
static const std::string DATETIME;
|
||||
#if !defined(POCO_VXWORKS)
|
||||
|
||||
@@ -164,7 +164,9 @@ void Application::init()
|
||||
_pConfig->setString("application.name", appPath.getFileName());
|
||||
_pConfig->setString("application.baseName", appPath.getBaseName());
|
||||
_pConfig->setString("application.dir", appPath.parent().toString());
|
||||
_pConfig->setString("application.configDir", appPath.parent().toString());
|
||||
_pConfig->setString("application.configDir", Path::configHome() + appPath.getBaseName() + Path::separator());
|
||||
_pConfig->setString("application.cacheDir", Path::cacheHome() + appPath.getBaseName() + Path::separator());
|
||||
_pConfig->setString("application.dataDir", Path::dataHome() + appPath.getBaseName() + Path::separator());
|
||||
processOptions();
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,9 @@ const std::string SystemConfiguration::NODENAME = "system.nodeName";
|
||||
const std::string SystemConfiguration::NODEID = "system.nodeId";
|
||||
const std::string SystemConfiguration::CURRENTDIR = "system.currentDir";
|
||||
const std::string SystemConfiguration::HOMEDIR = "system.homeDir";
|
||||
const std::string SystemConfiguration::CONFIGHOMEDIR = "system.configHomeDir";
|
||||
const std::string SystemConfiguration::CACHEHOMEDIR = "system.cacheHomeDir";
|
||||
const std::string SystemConfiguration::DATAHOMEDIR = "system.dataHomeDir";
|
||||
const std::string SystemConfiguration::TEMPDIR = "system.tempDir";
|
||||
const std::string SystemConfiguration::DATETIME = "system.dateTime";
|
||||
#if !defined(POCO_VXWORKS)
|
||||
@@ -106,6 +109,18 @@ bool SystemConfiguration::getRaw(const std::string& key, std::string& value) con
|
||||
{
|
||||
value = Path::home();
|
||||
}
|
||||
else if (key == CONFIGHOMEDIR)
|
||||
{
|
||||
value = Path::configHome();
|
||||
}
|
||||
else if (key == CACHEHOMEDIR)
|
||||
{
|
||||
value = Path::cacheHome();
|
||||
}
|
||||
else if (key == DATAHOMEDIR)
|
||||
{
|
||||
value = Path::dataHome();
|
||||
}
|
||||
else if (key == TEMPDIR)
|
||||
{
|
||||
value = Path::temp();
|
||||
@@ -151,6 +166,9 @@ void SystemConfiguration::enumerate(const std::string& key, Keys& range) const
|
||||
range.push_back("nodeId");
|
||||
range.push_back("currentDir");
|
||||
range.push_back("homeDir");
|
||||
range.push_back("configHomeDir");
|
||||
range.push_back("cacheHomeDir");
|
||||
range.push_back("dataHomeDir");
|
||||
range.push_back("tempDir");
|
||||
range.push_back("dateTime");
|
||||
#if !defined(POCO_VXWORKS)
|
||||
|
||||
@@ -93,6 +93,9 @@ void SystemConfigurationTest::testKeys()
|
||||
assert (std::find(keys.begin(), keys.end(), "nodeId") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "currentDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "homeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "configHomeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "cacheHomeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "dataHomeDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "tempDir") != keys.end());
|
||||
assert (std::find(keys.begin(), keys.end(), "dateTime") != keys.end());
|
||||
#if !defined(POCO_VXWORKS)
|
||||
|
||||
Reference in New Issue
Block a user