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:
Родитель
dbc847eb62
Коммит
5d463c3a1c
39
CONTRIBUTORS
39
CONTRIBUTORS
|
@ -1,23 +1,23 @@
|
|||
Guenter Obiltschnig <guenter.obiltschnig@appinf.com>
|
||||
Alex Fabijanic <alex@pocoproject.org>
|
||||
Peter Schojer <peter.schojer@appinf.com>
|
||||
Ferdinand Beyer <fbeyer@users.sourceforge.net>
|
||||
Krzysztof Burghardt <burghardt@users.sourceforge.net>
|
||||
Claus Dabringer <claus.dabringer@appinf.com>
|
||||
Caleb Epstein <caleb.epstein@gmail.com>
|
||||
Eran Hammer-Lahav <therazorblade@users.sourceforge.net>
|
||||
Chris Johnson <devcjohnson@gmail.com>
|
||||
Sergey Kholodilov <serghol@gmail.com>
|
||||
Ryan Kraay <rkraay@users.sourceforge.net>
|
||||
Larry Lewis <lewislp@users.sourceforge.net>
|
||||
Andrew J. P. Maclean <a.maclean@optusnet.com.au>
|
||||
Andrew Marlow <public@marlowa.plus.com>
|
||||
Paschal Mushubi <mushubi@sympatico.ca>
|
||||
Jiang Shan <pasorobo@users.sourceforge.net>
|
||||
David Shawley <boredc0der@users.sourceforge.net>
|
||||
Sergey Skorokhodov <ryppka@users.sourceforge.net>
|
||||
Guenter Obiltschnig
|
||||
Alex Fabijanic
|
||||
Peter Schojer
|
||||
Ferdinand Beyer
|
||||
Krzysztof Burghardt
|
||||
Claus Dabringer
|
||||
Caleb Epstein
|
||||
Eran Hammer-Lahav
|
||||
Chris Johnson
|
||||
Sergey Kholodilov
|
||||
Ryan Kraay
|
||||
Larry Lewis
|
||||
Andrew J. P. Maclean
|
||||
Andrew Marlow
|
||||
Paschal Mushubi
|
||||
Jiang Shan
|
||||
David Shawley
|
||||
Sergey Skorokhodov
|
||||
Tom Tan
|
||||
Sergey N. Yatskevich <snc@begun.ru>
|
||||
Sergey N. Yatskevich
|
||||
Marc Chevrier
|
||||
Philippe Cuvillier
|
||||
Marian Krivos
|
||||
|
@ -28,6 +28,7 @@ Rangel Reale
|
|||
Fabrizio Duhem
|
||||
Patrick White
|
||||
Mike Naquin
|
||||
Roger Meier
|
||||
|
||||
--
|
||||
$Id$
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
static std::string homeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string systemImpl();
|
||||
static std::string expandImpl(const std::string& path);
|
||||
static void listRootsImpl(std::vector<std::string>& roots);
|
||||
};
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
static std::string homeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string systemImpl();
|
||||
static std::string expandImpl(const std::string& path);
|
||||
static void listRootsImpl(std::vector<std::string>& roots);
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ public:
|
|||
static std::string homeImpl();
|
||||
static std::string tempImpl();
|
||||
static std::string nullImpl();
|
||||
static std::string systemImpl();
|
||||
static std::string expandImpl(const std::string& path);
|
||||
static void listRootsImpl(std::vector<std::string>& roots);
|
||||
|
||||
|
|
|
@ -599,7 +599,7 @@ Path& Path::clear()
|
|||
_dirs.clear();
|
||||
_version.clear();
|
||||
_absolute = false;
|
||||
return *this;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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("\\");
|
||||
|
|
|
@ -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("\\");
|
||||
|
|
|
@ -58,19 +58,9 @@ std::string PathImpl::homeImpl()
|
|||
}
|
||||
|
||||
|
||||
std::string PathImpl::tempImpl()
|
||||
std::string PathImpl::systemImpl()
|
||||
{
|
||||
Buffer<wchar_t> buffer(MAX_PATH_LEN);
|
||||
DWORD n = GetTempPathW(static_cast<DWORD>(buffer.size()), buffer.begin());
|
||||
if (n > 0)
|
||||
{
|
||||
std::string result;
|
||||
UnicodeConverter::toUTF8(buffer.begin(), result);
|
||||
if (result[n - 1] != '\\')
|
||||
result.append("\\");
|
||||
return result;
|
||||
}
|
||||
throw SystemException("Cannot get current directory");
|
||||
return("\\");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,15 @@
|
|||
#include "Poco/Environment.h"
|
||||
#include <iostream>
|
||||
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && defined(POCO_WIN32_UTF8)
|
||||
#if defined(_WIN32_WCE)
|
||||
#include "Poco/Path_WINCE.h"
|
||||
#else
|
||||
#include "Poco/Path_WIN32U.h"
|
||||
#endif
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "Poco/Path_WIN32.h"
|
||||
#endif
|
||||
|
||||
using Poco::Path;
|
||||
using Poco::PathSyntaxException;
|
||||
|
@ -1625,6 +1634,14 @@ void PathTest::testPushPop()
|
|||
}
|
||||
|
||||
|
||||
void PathTest::testWindowsSystem()
|
||||
{
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
std::cout << Poco::PathImpl::systemImpl() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void PathTest::setUp()
|
||||
{
|
||||
}
|
||||
|
@ -1666,6 +1683,7 @@ CppUnit::Test* PathTest::suite()
|
|||
CppUnit_addTest(pSuite, PathTest, testSwap);
|
||||
CppUnit_addTest(pSuite, PathTest, testResolve);
|
||||
CppUnit_addTest(pSuite, PathTest, testPushPop);
|
||||
CppUnit_addTest(pSuite, PathTest, testWindowsSystem);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
void testSwap();
|
||||
void testResolve();
|
||||
void testPushPop();
|
||||
void testWindowsSystem();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
|
Загрузка…
Ссылка в новой задаче