mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-25 18:22:59 +02:00
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:
@@ -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("\\");
|
||||
|
||||
Reference in New Issue
Block a user