Merge pull request #561 from bschramke/develop

Support for XDG Base Directory Specification
This commit is contained in:
Aleksandar Fabijanic
2015-02-09 21:04:28 -06:00
12 changed files with 399 additions and 2 deletions

View File

@@ -291,9 +291,37 @@ 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 tempHome();
/// Returns the user's temp directory.
///
/// On Unix systems, this is the '~/.local/temp/'.
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.
static std::string config();
/// Returns the systemwide config directory.
///
/// On Unix systems, this is the '/etc/'.
static std::string null();
/// Returns the name of the null device.

View File

@@ -32,7 +32,12 @@ class PathImpl
public:
static std::string currentImpl();
static std::string homeImpl();
static std::string configHomeImpl();
static std::string dataHomeImpl();
static std::string tempHomeImpl();
static std::string cacheHomeImpl();
static std::string tempImpl();
static std::string configImpl();
static std::string nullImpl();
static std::string expandImpl(const std::string& path);
static void listRootsImpl(std::vector<std::string>& roots);

View File

@@ -32,7 +32,12 @@ 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 tempHomeImpl();
static std::string tempImpl();
static std::string configImpl();
static std::string nullImpl();
static std::string systemImpl();
static std::string expandImpl(const std::string& path);

View File

@@ -32,7 +32,12 @@ 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 tempHomeImpl();
static std::string tempImpl();
static std::string configImpl();
static std::string nullImpl();
static std::string systemImpl();
static std::string expandImpl(const std::string& path);

View File

@@ -595,11 +595,60 @@ std::string Path::home()
}
std::string Path::configHome()
{
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::configHomeImpl();
#else
return PathImpl::homeImpl();
#endif
}
std::string Path::dataHome()
{
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::dataHomeImpl();
#else
return PathImpl::homeImpl();
#endif
}
std::string Path::tempHome()
{
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::tempHomeImpl();
#else
return PathImpl::tempImpl();
#endif
}
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();
}
std::string Path::config()
{
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::configImpl();
#else
return PathImpl::currentImpl();
#endif
}
std::string Path::null()
{

View File

@@ -76,6 +76,82 @@ std::string PathImpl::homeImpl()
}
std::string PathImpl::configHomeImpl()
{
#if defined(POCO_VXWORKS)
return PathImpl::homeImpl();
#else
std::string path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
#if POCO_OS == POCO_OS_MAC_OS_X
path.append("Library/Preferences/");
#else
path.append(".config/");
#endif
return path;
#endif
}
std::string PathImpl::dataHomeImpl()
{
#if defined(POCO_VXWORKS)
return PathImpl::homeImpl();
#else
std::string path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
#if POCO_OS == POCO_OS_MAC_OS_X
path.append("Library/Application Support/");
#else
path.append(".local/share/");
#endif
return path;
#endif
}
std::string PathImpl::cacheHomeImpl()
{
#if defined(POCO_VXWORKS)
return PathImpl::tempImpl();
#else
std::string path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
#if POCO_OS == POCO_OS_MAC_OS_X
path.append("Library/Caches/");
#else
path.append(".cache/");
#endif
return path;
#endif
}
std::string PathImpl::tempHomeImpl()
{
#if defined(POCO_VXWORKS)
return PathImpl::tempImpl();
#else
std::string path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
#if POCO_OS == POCO_OS_MAC_OS_X
path.append("Library/Caches/");
#else
path.append(".local/tmp/");
#endif
return path;
#endif
}
std::string PathImpl::tempImpl()
{
std::string path;
@@ -94,6 +170,19 @@ std::string PathImpl::tempImpl()
}
std::string PathImpl::configImpl()
{
std::string path;
#if POCO_OS == POCO_OS_MAC_OS_X
path = "/Library/Preferences/";
#else
path = "/etc/";
#endif
return path;
}
std::string PathImpl::nullImpl()
{
#if defined(POCO_VXWORKS)

View File

@@ -76,6 +76,59 @@ 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::tempHomeImpl()
{
return tempImpl();
}
std::string PathImpl::tempImpl()
{
char buffer[MAX_PATH];
@@ -93,6 +146,26 @@ std::string PathImpl::tempImpl()
}
std::string PathImpl::configImpl()
{
std::string result;
// if PROGRAMDATA environment variable not exist, return system directory instead
try
{
result = EnvironmentImpl::getImpl("PROGRAMDATA");
}
catch (NotFoundException&)
{
result = systemImpl();
}
std::string::size_type n = result.size();
if (n > 0 && result[n - 1] != '\\')
result.append("\\");
return result;
}
std::string PathImpl::nullImpl()
{
return "NUL:";

View File

@@ -86,6 +86,59 @@ 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::tempHomeImpl()
{
return tempImpl();
}
std::string PathImpl::tempImpl()
{
Buffer<wchar_t> buffer(MAX_PATH_LEN);
@@ -104,6 +157,26 @@ std::string PathImpl::tempImpl()
}
std::string PathImpl::configImpl()
{
std::string result;
// if PROGRAMDATA environment variable not exist, return system directory instead
try
{
result = EnvironmentImpl::getImpl("PROGRAMDATA");
}
catch (NotFoundException&)
{
result = systemImpl();
}
std::string::size_type n = result.size();
if (n > 0 && result[n - 1] != '\\')
result.append("\\");
return result;
}
std::string PathImpl::nullImpl()
{
return "NUL:";