invoke win32app functions from main

This commit is contained in:
orignal 2016-03-09 14:41:14 -05:00
parent 95b2bf3645
commit 74d4b8e0b9
5 changed files with 167 additions and 186 deletions

View file

@ -5,7 +5,7 @@
#ifdef _WIN32
#include "./Win32/Win32Service.h"
#include "Win32/Win32App.h"
namespace i2p
{
@ -16,61 +16,21 @@ namespace i2p
setlocale(LC_CTYPE, "");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
setlocale(LC_ALL, "Russian");
return Daemon_Singleton::init(argc, argv);
}
if (!Daemon_Singleton::init(argc, argv)) return false;
if (I2PService::isService())
isDaemon = 1;
else
isDaemon = 0;
std::string serviceControl; i2p::config::GetOption("svcctl", serviceControl);
if (serviceControl == "install")
{
LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service");
InstallService(
SERVICE_NAME, // Name of service
SERVICE_DISPLAY_NAME, // Name to display
SERVICE_START_TYPE, // Service start type
SERVICE_DEPENDENCIES, // Dependencies
SERVICE_ACCOUNT, // Service running account
SERVICE_PASSWORD // Password of the account
);
exit(0);
}
else if (serviceControl == "remove")
{
LogPrint(eLogInfo, "WinSVC: uninstalling ", SERVICE_NAME, " service");
UninstallService(SERVICE_NAME);
exit(0);
}
if (isDaemon == 1)
{
LogPrint(eLogDebug, "Daemon: running as service");
I2PService service(SERVICE_NAME);
if (!I2PService::Run(service))
{
LogPrint(eLogError, "Daemon: Service failed to run w/err 0x%08lx\n", GetLastError());
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
else
LogPrint(eLogDebug, "Daemon: running as user");
return true;
}
bool DaemonWin32::start()
{
setlocale(LC_CTYPE, "");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
if (!i2p::win32::StartWin32App ()) return false;
bool ret = Daemon_Singleton::start();
if (ret && IsLogToFile ())
{
{
// TODO: find out where this garbage to console comes from
SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
@ -79,9 +39,15 @@ namespace i2p
}
bool DaemonWin32::stop()
{
{
i2p::win32::StopWin32App ();
return Daemon_Singleton::stop();
}
}
void DaemonWin32::run ()
{
i2p::win32::RunWin32App ();
}
}
}