add Windows compliant implementation of XDG Base Directory Specification

This commit is contained in:
Björn Schramke 2014-11-11 17:05:48 +01:00 committed by Alex Fabijanic
parent eaaf2296f0
commit 43c44aacbb
5 changed files with 63 additions and 5 deletions

View File

@ -33,7 +33,9 @@ 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();
static std::string systemImpl();
static std::string expandImpl(const std::string& path);

View File

@ -33,7 +33,9 @@ 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();
static std::string systemImpl();
static std::string expandImpl(const std::string& path);

View File

@ -571,7 +571,7 @@ std::string Path::home()
std::string Path::configHome()
{
#if defined(POCO_OS_FAMILY_UNIX)
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::configHomeImpl();
#else
return PathImpl::homeImpl();
@ -581,7 +581,7 @@ std::string Path::configHome()
std::string Path::dataHome()
{
#if defined(POCO_OS_FAMILY_UNIX)
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::dataHomeImpl();
#else
return PathImpl::homeImpl();
@ -591,7 +591,7 @@ std::string Path::dataHome()
std::string Path::tempHome()
{
#if defined(POCO_OS_FAMILY_UNIX)
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::tempHomeImpl();
#else
return PathImpl::tempImpl();
@ -601,7 +601,7 @@ std::string Path::tempHome()
std::string Path::cacheHome()
{
#if defined(POCO_OS_FAMILY_UNIX)
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::cacheHomeImpl();
#else
return PathImpl::homeImpl();
@ -617,7 +617,7 @@ std::string Path::temp()
std::string Path::config()
{
#if defined(POCO_OS_FAMILY_UNIX)
#if defined(POCO_OS_FAMILY_UNIX) || defined(POCO_OS_FAMILY_WINDOWS)
return PathImpl::configImpl();
#else
return PathImpl::currentImpl();

View File

@ -122,6 +122,12 @@ std::string PathImpl::cacheHomeImpl()
}
std::string PathImpl::tempHomeImpl()
{
return tempImpl();
}
std::string PathImpl::tempImpl()
{
char buffer[MAX_PATH];
@ -139,6 +145,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

@ -132,6 +132,14 @@ std::string PathImpl::cacheHomeImpl()
}
<<<<<<< HEAD
=======
std::string PathImpl::tempHomeImpl()
{
return tempImpl();
}
>>>>>>> 06e59cb... add Windows compliant implementation of XDG Base Directory Specification
std::string PathImpl::tempImpl()
{
Buffer<wchar_t> buffer(MAX_PATH_LEN);
@ -150,6 +158,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:";