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

@@ -65,10 +65,38 @@ std::string PathImpl::currentImpl()
}
std::string PathImpl::systemImpl()
{
Buffer<wchar_t> buffer(MAX_PATH_LEN);
DWORD n = GetSystemDirectoryW(buffer.begin(), static_cast<DWORD>(buffer.size()));
if (n > 0)
{
n = GetLongPathNameW(buffer.begin(), buffer.begin(), static_cast<DWORD>(buffer.size()));
if (n <= 0) throw SystemException("Cannot get system directory long path name");
std::string result;
UnicodeConverter::toUTF8(buffer.begin(), result);
if (result[result.size() - 1] != '\\') result.append("\\");
return result;
}
throw SystemException("Cannot get temporary directory path");
}
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("\\");