mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-02 05:46:22 +01:00
trunk: sync from 1.4.3
make & cmake fixes
This commit is contained in:
@@ -299,14 +299,16 @@ void Application::stopOptionsProcessing()
|
||||
|
||||
int Application::run()
|
||||
{
|
||||
int rc = EXIT_SOFTWARE;
|
||||
initialize(*this);
|
||||
try
|
||||
{
|
||||
rc = main(_args);
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
int rc = EXIT_CONFIG;
|
||||
try
|
||||
{
|
||||
initialize(*this);
|
||||
rc = EXIT_SOFTWARE;
|
||||
rc = main(_args);
|
||||
uninitialize();
|
||||
}
|
||||
catch (Poco::Exception& exc)
|
||||
{
|
||||
logger().log(exc);
|
||||
}
|
||||
catch (std::exception& exc)
|
||||
@@ -314,11 +316,10 @@ int Application::run()
|
||||
logger().error(exc.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
logger().fatal("system exception");
|
||||
}
|
||||
uninitialize();
|
||||
return rc;
|
||||
{
|
||||
logger().fatal("system exception");
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -368,13 +369,13 @@ void Application::processOptions()
|
||||
while (it != _args.end() && !_stopOptionsProcessing)
|
||||
{
|
||||
std::string name;
|
||||
std::string value;
|
||||
if (processor.process(*it, name, value))
|
||||
{
|
||||
if (!name.empty()) // "--" option to end options processing or deferred argument
|
||||
{
|
||||
handleOption(name, value);
|
||||
}
|
||||
std::string value;
|
||||
if (processor.process(*it, name, value))
|
||||
{
|
||||
if (!name.empty()) // "--" option to end options processing or deferred argument
|
||||
{
|
||||
handleOption(name, value);
|
||||
}
|
||||
it = _args.erase(it);
|
||||
}
|
||||
else ++it;
|
||||
|
||||
@@ -388,12 +388,12 @@ void ServerApplication::registerService()
|
||||
else
|
||||
service.registerService(path, _displayName);
|
||||
if (_startup == "auto")
|
||||
service.setStartup(WinService::SVC_AUTO_START);
|
||||
else if (_startup == "manual")
|
||||
service.setStartup(WinService::SVC_MANUAL_START);
|
||||
if (!_description.empty())
|
||||
service.setDescription(_description);
|
||||
logger().information("The application has been successfully registered as a service.");
|
||||
service.setStartup(WinService::SVC_AUTO_START);
|
||||
else if (_startup == "manual")
|
||||
service.setStartup(WinService::SVC_MANUAL_START);
|
||||
if (!_description.empty())
|
||||
service.setDescription(_description);
|
||||
logger().information("The application has been successfully registered as a service.");
|
||||
}
|
||||
|
||||
|
||||
@@ -428,19 +428,19 @@ void ServerApplication::defineOptions(OptionSet& options)
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("name")
|
||||
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDisplayName)));
|
||||
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDisplayName)));
|
||||
|
||||
options.addOption(
|
||||
Option("description", "", "Specify a description for the service (only with /registerService).")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("text")
|
||||
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDescription)));
|
||||
options.addOption(
|
||||
Option("description", "", "Specify a description for the service (only with /registerService).")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("text")
|
||||
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleDescription)));
|
||||
|
||||
options.addOption(
|
||||
Option("startup", "", "Specify the startup mode for the service (only with /registerService).")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
options.addOption(
|
||||
Option("startup", "", "Specify the startup mode for the service (only with /registerService).")
|
||||
.required(false)
|
||||
.repeatable(false)
|
||||
.argument("automatic|manual")
|
||||
.callback(OptionCallback<ServerApplication>(this, &ServerApplication::handleStartup)));
|
||||
}
|
||||
@@ -466,13 +466,13 @@ void ServerApplication::handleDisplayName(const std::string& name, const std::st
|
||||
|
||||
void ServerApplication::handleDescription(const std::string& name, const std::string& value)
|
||||
{
|
||||
_description = value;
|
||||
_description = value;
|
||||
}
|
||||
|
||||
|
||||
void ServerApplication::handleStartup(const std::string& name, const std::string& value)
|
||||
{
|
||||
if (Poco::icompare(value, 4, std::string("auto")) == 0)
|
||||
if (Poco::icompare(value, 4, std::string("auto")) == 0)
|
||||
_startup = "auto";
|
||||
else if (Poco::icompare(value, std::string("manual")) == 0)
|
||||
_startup = "manual";
|
||||
@@ -496,20 +496,10 @@ int ServerApplication::run(int argc, char** argv)
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
logger().log(exc);
|
||||
return EXIT_CONFIG;
|
||||
}
|
||||
int rc = run();
|
||||
try
|
||||
{
|
||||
uninitialize();
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
logger().log(exc);
|
||||
rc = EXIT_CONFIG;
|
||||
}
|
||||
return rc;
|
||||
logger().log(exc);
|
||||
return EXIT_CONFIG;
|
||||
}
|
||||
return run();
|
||||
}
|
||||
|
||||
|
||||
@@ -521,20 +511,10 @@ int ServerApplication::run(const std::vector<std::string>& args)
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
logger().log(exc);
|
||||
return EXIT_CONFIG;
|
||||
}
|
||||
int rc = run();
|
||||
try
|
||||
{
|
||||
uninitialize();
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
logger().log(exc);
|
||||
rc = EXIT_CONFIG;
|
||||
}
|
||||
return rc;
|
||||
logger().log(exc);
|
||||
return EXIT_CONFIG;
|
||||
}
|
||||
return run();
|
||||
}
|
||||
|
||||
|
||||
@@ -547,20 +527,10 @@ int ServerApplication::run(int argc, wchar_t** argv)
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
logger().log(exc);
|
||||
return EXIT_CONFIG;
|
||||
}
|
||||
int rc = run();
|
||||
try
|
||||
{
|
||||
uninitialize();
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
logger().log(exc);
|
||||
rc = EXIT_CONFIG;
|
||||
}
|
||||
return rc;
|
||||
logger().log(exc);
|
||||
return EXIT_CONFIG;
|
||||
}
|
||||
return run();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -53,9 +53,35 @@ namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
class AutoHandle
|
||||
{
|
||||
public:
|
||||
AutoHandle(HMODULE h):
|
||||
_h(h)
|
||||
{
|
||||
}
|
||||
|
||||
~AutoHandle()
|
||||
{
|
||||
FreeLibrary(_h);
|
||||
}
|
||||
|
||||
HMODULE handle()
|
||||
{
|
||||
return _h;
|
||||
}
|
||||
|
||||
private:
|
||||
HMODULE _h;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
WinRegistryKey::WinRegistryKey(const std::string& key, bool readOnly, REGSAM extraSam):
|
||||
_hKey(0),
|
||||
_readOnly(readOnly),
|
||||
_hKey(0),
|
||||
_readOnly(readOnly),
|
||||
_extraSam(extraSam)
|
||||
{
|
||||
std::string::size_type pos = key.find('\\');
|
||||
@@ -266,17 +292,53 @@ void WinRegistryKey::deleteKey()
|
||||
std::string subKey(_subKey);
|
||||
subKey += "\\";
|
||||
subKey += *it;
|
||||
WinRegistryKey subRegKey(_hRootKey, subKey);
|
||||
subRegKey.deleteKey();
|
||||
}
|
||||
WinRegistryKey subRegKey(_hRootKey, subKey);
|
||||
subRegKey.deleteKey();
|
||||
}
|
||||
|
||||
// NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later.
|
||||
// We cannot call it directly as this would prevent the code running on Windows XP 32-bit.
|
||||
// Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for
|
||||
// its existence in ADVAPI32.DLL and call it indirectly.
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
std::wstring usubKey;
|
||||
Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
|
||||
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
|
||||
throw NotFoundException(key());
|
||||
std::wstring usubKey;
|
||||
Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
|
||||
|
||||
typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved);
|
||||
if (_extraSam != 0)
|
||||
{
|
||||
AutoHandle advAPI32(LoadLibraryW(L"ADVAPI32.DLL"));
|
||||
if (advAPI32.handle())
|
||||
{
|
||||
RegDeleteKeyExWFunc pRegDeleteKeyExW = reinterpret_cast<RegDeleteKeyExWFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExW"));
|
||||
if (pRegDeleteKeyExW)
|
||||
{
|
||||
if ((*pRegDeleteKeyExW)(_hRootKey, usubKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
|
||||
throw NotFoundException(key());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
|
||||
throw NotFoundException(key());
|
||||
#else
|
||||
if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS)
|
||||
throw NotFoundException(key());
|
||||
typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved);
|
||||
if (_extraSam != 0)
|
||||
{
|
||||
AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL"));
|
||||
if (advAPI32.handle())
|
||||
{
|
||||
RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA"));
|
||||
if (pRegDeleteKeyExA)
|
||||
{
|
||||
if ((*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
|
||||
throw NotFoundException(key());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS)
|
||||
throw NotFoundException(key());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user