mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.4 KiB
84 lines
2.4 KiB
11 years ago
|
#include "Daemon.h"
|
||
9 years ago
|
#include "util/util.h"
|
||
9 years ago
|
#include "util/Log.h"
|
||
11 years ago
|
|
||
|
#ifdef _WIN32
|
||
|
|
||
|
#include "./Win32/Win32Service.h"
|
||
|
|
||
|
namespace i2p
|
||
|
{
|
||
9 years ago
|
namespace util
|
||
|
{
|
||
|
bool DaemonWin32::init(int argc, char* argv[])
|
||
|
{
|
||
|
setlocale(LC_CTYPE, "");
|
||
|
SetConsoleCP(1251);
|
||
|
SetConsoleOutputCP(1251);
|
||
|
setlocale(LC_ALL, "Russian");
|
||
11 years ago
|
|
||
9 years ago
|
if (!Daemon_Singleton::init(argc, argv)) return false;
|
||
|
if (I2PService::isService())
|
||
|
isDaemon = 1;
|
||
|
else
|
||
|
isDaemon = 0;
|
||
11 years ago
|
|
||
9 years ago
|
std::string serviceControl = i2p::util::config::GetArg("-service", "none");
|
||
|
if (serviceControl == "install")
|
||
|
{
|
||
|
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")
|
||
|
{
|
||
|
UninstallService(SERVICE_NAME);
|
||
|
exit(0);
|
||
|
}
|
||
|
else if (serviceControl != "none")
|
||
|
{
|
||
|
printf(" --service=install to install the service.\n");
|
||
|
printf(" --service=remove to remove the service.\n");
|
||
|
}
|
||
|
|
||
|
if (isDaemon == 1)
|
||
|
{
|
||
|
LogPrint("Service session");
|
||
|
I2PService service(SERVICE_NAME);
|
||
|
if (!I2PService::Run(service))
|
||
|
{
|
||
|
LogPrint("Service failed to run w/err 0x%08lx\n", GetLastError());
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
exit(EXIT_SUCCESS);
|
||
|
}
|
||
|
else
|
||
|
LogPrint("User session");
|
||
11 years ago
|
|
||
9 years ago
|
return true;
|
||
|
}
|
||
|
bool DaemonWin32::start()
|
||
|
{
|
||
|
setlocale(LC_CTYPE, "");
|
||
|
SetConsoleCP(1251);
|
||
|
SetConsoleOutputCP(1251);
|
||
|
setlocale(LC_ALL, "Russian");
|
||
11 years ago
|
|
||
9 years ago
|
return Daemon_Singleton::start();
|
||
|
}
|
||
11 years ago
|
|
||
9 years ago
|
bool DaemonWin32::stop()
|
||
|
{
|
||
|
return Daemon_Singleton::stop();
|
||
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
9 years ago
|
#endif
|