mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-13 19:37:51 +00:00
commit
10f3690ede
226
DaemonWin32.cpp
226
DaemonWin32.cpp
@ -1,113 +1,115 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include "Config.h"
|
#include <clocale>
|
||||||
#include "Daemon.h"
|
#include "Config.h"
|
||||||
#include "util.h"
|
#include "Daemon.h"
|
||||||
#include "Log.h"
|
#include "util.h"
|
||||||
|
#include "Log.h"
|
||||||
#ifdef _WIN32
|
|
||||||
|
#ifdef _WIN32
|
||||||
#include "Win32/Win32Service.h"
|
|
||||||
#ifdef WIN32_APP
|
#include "Win32/Win32Service.h"
|
||||||
#include "Win32/Win32App.h"
|
#ifdef WIN32_APP
|
||||||
#endif
|
#include "Win32/Win32App.h"
|
||||||
|
#endif
|
||||||
namespace i2p
|
|
||||||
{
|
namespace i2p
|
||||||
namespace util
|
{
|
||||||
{
|
namespace util
|
||||||
bool DaemonWin32::init(int argc, char* argv[])
|
{
|
||||||
{
|
bool DaemonWin32::init(int argc, char* argv[])
|
||||||
setlocale(LC_CTYPE, "");
|
{
|
||||||
SetConsoleCP(1251);
|
setlocale(LC_CTYPE, "");
|
||||||
SetConsoleOutputCP(1251);
|
SetConsoleCP(1251);
|
||||||
|
SetConsoleOutputCP(1251);
|
||||||
if (!Daemon_Singleton::init(argc, argv))
|
setlocale(LC_ALL, "Russian");
|
||||||
return false;
|
|
||||||
|
if (!Daemon_Singleton::init(argc, argv))
|
||||||
std::string serviceControl; i2p::config::GetOption("svcctl", serviceControl);
|
return false;
|
||||||
if (serviceControl == "install")
|
|
||||||
{
|
std::string serviceControl; i2p::config::GetOption("svcctl", serviceControl);
|
||||||
LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service");
|
if (serviceControl == "install")
|
||||||
InstallService(
|
{
|
||||||
SERVICE_NAME, // Name of service
|
LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service");
|
||||||
SERVICE_DISPLAY_NAME, // Name to display
|
InstallService(
|
||||||
SERVICE_START_TYPE, // Service start type
|
SERVICE_NAME, // Name of service
|
||||||
SERVICE_DEPENDENCIES, // Dependencies
|
SERVICE_DISPLAY_NAME, // Name to display
|
||||||
SERVICE_ACCOUNT, // Service running account
|
SERVICE_START_TYPE, // Service start type
|
||||||
SERVICE_PASSWORD // Password of the account
|
SERVICE_DEPENDENCIES, // Dependencies
|
||||||
);
|
SERVICE_ACCOUNT, // Service running account
|
||||||
return false;
|
SERVICE_PASSWORD // Password of the account
|
||||||
}
|
);
|
||||||
else if (serviceControl == "remove")
|
return false;
|
||||||
{
|
}
|
||||||
LogPrint(eLogInfo, "WinSVC: uninstalling ", SERVICE_NAME, " service");
|
else if (serviceControl == "remove")
|
||||||
UninstallService(SERVICE_NAME);
|
{
|
||||||
return false;
|
LogPrint(eLogInfo, "WinSVC: uninstalling ", SERVICE_NAME, " service");
|
||||||
}
|
UninstallService(SERVICE_NAME);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isDaemon)
|
if (isDaemon)
|
||||||
{
|
{
|
||||||
LogPrint(eLogDebug, "Daemon: running as service");
|
LogPrint(eLogDebug, "Daemon: running as service");
|
||||||
I2PService service(SERVICE_NAME);
|
I2PService service(SERVICE_NAME);
|
||||||
if (!I2PService::Run(service))
|
if (!I2PService::Run(service))
|
||||||
{
|
{
|
||||||
LogPrint(eLogError, "Daemon: Service failed to run w/err 0x%08lx\n", GetLastError());
|
LogPrint(eLogError, "Daemon: Service failed to run w/err 0x%08lx\n", GetLastError());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
LogPrint(eLogDebug, "Daemon: running as user");
|
LogPrint(eLogDebug, "Daemon: running as user");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonWin32::start()
|
bool DaemonWin32::start()
|
||||||
{
|
{
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
SetConsoleCP(1251);
|
SetConsoleCP(1251);
|
||||||
SetConsoleOutputCP(1251);
|
SetConsoleOutputCP(1251);
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
#ifdef WIN32_APP
|
#ifdef WIN32_APP
|
||||||
if (!i2p::win32::StartWin32App ()) return false;
|
if (!i2p::win32::StartWin32App ()) return false;
|
||||||
|
|
||||||
// override log
|
// override log
|
||||||
i2p::config::SetOption("log", std::string ("file"));
|
i2p::config::SetOption("log", std::string ("file"));
|
||||||
#endif
|
#endif
|
||||||
bool ret = Daemon_Singleton::start();
|
bool ret = Daemon_Singleton::start();
|
||||||
if (ret && i2p::log::Logger().GetLogType() == eLogFile)
|
if (ret && i2p::log::Logger().GetLogType() == eLogFile)
|
||||||
{
|
{
|
||||||
// TODO: find out where this garbage to console comes from
|
// TODO: find out where this garbage to console comes from
|
||||||
SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
|
SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
|
||||||
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
|
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
|
||||||
}
|
}
|
||||||
bool insomnia; i2p::config::GetOption("insomnia", insomnia);
|
bool insomnia; i2p::config::GetOption("insomnia", insomnia);
|
||||||
if (insomnia)
|
if (insomnia)
|
||||||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaemonWin32::stop()
|
bool DaemonWin32::stop()
|
||||||
{
|
{
|
||||||
#ifdef WIN32_APP
|
#ifdef WIN32_APP
|
||||||
i2p::win32::StopWin32App ();
|
i2p::win32::StopWin32App ();
|
||||||
#endif
|
#endif
|
||||||
return Daemon_Singleton::stop();
|
return Daemon_Singleton::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonWin32::run ()
|
void DaemonWin32::run ()
|
||||||
{
|
{
|
||||||
#ifdef WIN32_APP
|
#ifdef WIN32_APP
|
||||||
i2p::win32::RunWin32App ();
|
i2p::win32::RunWin32App ();
|
||||||
#else
|
#else
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(1));
|
std::this_thread::sleep_for (std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -126,8 +126,12 @@ namespace http {
|
|||||||
s <<
|
s <<
|
||||||
"<!DOCTYPE html>\r\n"
|
"<!DOCTYPE html>\r\n"
|
||||||
"<html lang=\"en\">\r\n" /* TODO: Add support for locale */
|
"<html lang=\"en\">\r\n" /* TODO: Add support for locale */
|
||||||
" <head>\r\n"
|
" <head>\r\n" /* TODO: Find something to parse html/template system. This is horrible. */
|
||||||
" <meta charset=\"UTF-8\">\r\n" /* TODO: Find something to parse html/template system. This is horrible. */
|
#if (!defined(WIN32))
|
||||||
|
" <meta charset=\"UTF-8\">\r\n"
|
||||||
|
#else
|
||||||
|
" <meta charset=\"windows-1251\">\r\n"
|
||||||
|
#endif
|
||||||
" <link rel=\"shortcut icon\" href=\"" << itoopieFavicon << "\">\r\n"
|
" <link rel=\"shortcut icon\" href=\"" << itoopieFavicon << "\">\r\n"
|
||||||
" <title>Purple I2P " VERSION " Webconsole</title>\r\n"
|
" <title>Purple I2P " VERSION " Webconsole</title>\r\n"
|
||||||
<< cssStyles <<
|
<< cssStyles <<
|
||||||
|
Loading…
Reference in New Issue
Block a user