GH 30:Poco::Path::home() throws

GH #30: Poco::Path::home() throws when called from Windows Service
done for Win32 and Win32U, return root for WinCE
This commit is contained in:
aleks-f
2012-12-14 12:09:23 -06:00
parent dbc847eb62
commit 5d463c3a1c
10 changed files with 103 additions and 36 deletions

View File

@@ -57,10 +57,36 @@ std::string PathImpl::currentImpl()
}
std::string PathImpl::systemImpl()
{
char buffer[MAX_PATH];
DWORD n = GetSystemDirectoryA(buffer, sizeof(buffer));
if (n > 0 && n < sizeof(buffer))
{
std::string result(buffer, n);
if (result[n - 1] != '\\')
result.append("\\");
return result;
}
else throw SystemException("Cannot get system directory");
}
std::string PathImpl::homeImpl()
{
std::string result = EnvironmentImpl::getImpl("HOMEDRIVE");
result.append(EnvironmentImpl::getImpl("HOMEPATH"));
std::string result;
// windows service has no home dir, return system directory instead
try
{
result = EnvironmentImpl::getImpl("HOMEDRIVE");
result.append(EnvironmentImpl::getImpl("HOMEPATH"));
}
catch (NotFoundException&)
{
result = systemImpl();
}
std::string::size_type n = result.size();
if (n > 0 && result[n - 1] != '\\')
result.append("\\");