mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-02 05:46:22 +01:00
Merge pull request #561 from bschramke/develop
Support for XDG Base Directory Specification
This commit is contained in:
@@ -76,7 +76,10 @@ class Util_API Application: public Subsystem
|
||||
/// - application.name: the file name of the application executable
|
||||
/// - application.baseName: the file name (excluding extension) of the application executable
|
||||
/// - application.dir: the path to the directory where the application executable resides
|
||||
/// - application.configDir: the path to the directory where the last configuration file loaded with loadConfiguration() was found.
|
||||
/// - application.configDir: the path to the directory where user specific configuration files of the application should be stored.
|
||||
/// - application.cacheDir: the path to the directory where user specific non-essential data files of the application should be stored.
|
||||
/// - application.dataDir: the path to the directory where user specific data files of the application should be stored.
|
||||
/// - application.tempDir: the path to the directory where user specific temporary files and other file objects of the application should be stored.
|
||||
///
|
||||
/// If loadConfiguration() has never been called, application.configDir will be equal to application.dir.
|
||||
///
|
||||
@@ -371,6 +374,7 @@ private:
|
||||
void getApplicationPath(Poco::Path& path) const;
|
||||
void processOptions();
|
||||
bool findAppConfigFile(const std::string& appName, const std::string& extension, Poco::Path& path) const;
|
||||
bool findAppConfigFile(const Path& basePath, const std::string& appName, const std::string& extension, Poco::Path& path) const;
|
||||
|
||||
typedef Poco::AutoPtr<LayeredConfiguration> ConfigPtr;
|
||||
|
||||
|
||||
@@ -41,7 +41,12 @@ 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.tempHomeDir: the base directory relative to which user-specific temporary files and other file objects should be placed
|
||||
/// - system.tempDir: the system's temporary directory
|
||||
/// - system.configDir: the system's configuration directory
|
||||
/// - system.dateTime: the current UTC date and time, formatted in ISO 8601 format.
|
||||
/// - system.pid: the current process ID.
|
||||
/// - system.env.<NAME>: the environment variable with the given <NAME>.
|
||||
@@ -76,7 +81,12 @@ 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 TEMPHOMEDIR;
|
||||
static const std::string TEMPDIR;
|
||||
static const std::string CONFIGDIR;
|
||||
static const std::string DATETIME;
|
||||
#if !defined(POCO_VXWORKS)
|
||||
static const std::string PID;
|
||||
|
||||
@@ -166,7 +166,10 @@ 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.tempDir", Path::tempHome() + appPath.getBaseName() + Path::separator());
|
||||
_pConfig->setString("application.dataDir", Path::dataHome() + appPath.getBaseName() + Path::separator());
|
||||
processOptions();
|
||||
}
|
||||
|
||||
@@ -506,6 +509,29 @@ bool Application::findAppConfigFile(const std::string& appName, const std::strin
|
||||
}
|
||||
|
||||
|
||||
bool Application::findAppConfigFile(const Path& basePath, const std::string& appName, const std::string& extension, Path& path) const
|
||||
{
|
||||
poco_assert (!appName.empty());
|
||||
|
||||
Path p(basePath,appName);
|
||||
p.setExtension(extension);
|
||||
bool found = findFile(p);
|
||||
if (!found)
|
||||
{
|
||||
#if defined(_DEBUG)
|
||||
if (appName[appName.length() - 1] == 'd')
|
||||
{
|
||||
p.setBaseName(appName.substr(0, appName.length() - 1));
|
||||
found = findFile(p);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (found)
|
||||
path = p;
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
void Application::defineOptions(OptionSet& options)
|
||||
{
|
||||
for (SubsystemVec::iterator it = _subsystems.begin(); it != _subsystems.end(); ++it)
|
||||
|
||||
@@ -43,7 +43,12 @@ 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::TEMPHOMEDIR = "system.tempHomeDir";
|
||||
const std::string SystemConfiguration::TEMPDIR = "system.tempDir";
|
||||
const std::string SystemConfiguration::CONFIGDIR = "system.configDir";
|
||||
const std::string SystemConfiguration::DATETIME = "system.dateTime";
|
||||
#if !defined(POCO_VXWORKS)
|
||||
const std::string SystemConfiguration::PID = "system.pid";
|
||||
@@ -108,10 +113,30 @@ 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 == TEMPHOMEDIR)
|
||||
{
|
||||
value = Path::tempHome();
|
||||
}
|
||||
else if (key == TEMPDIR)
|
||||
{
|
||||
value = Path::temp();
|
||||
}
|
||||
else if (key == CONFIGDIR)
|
||||
{
|
||||
value = Path::config();
|
||||
}
|
||||
else if (key == DATETIME)
|
||||
{
|
||||
value = Poco::DateTimeFormatter::format(Poco::DateTime(), Poco::DateTimeFormat::ISO8601_FORMAT);
|
||||
@@ -153,7 +178,12 @@ 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("tempHomeDir");
|
||||
range.push_back("tempDir");
|
||||
range.push_back("configDir");
|
||||
range.push_back("dateTime");
|
||||
#if !defined(POCO_VXWORKS)
|
||||
range.push_back("pid");
|
||||
|
||||
Reference in New Issue
Block a user