mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:54:01 +01:00
supoort win32 console application
This commit is contained in:
parent
3c55c2d777
commit
355c7437ed
189
DaemonWin32.cpp
189
DaemonWin32.cpp
|
@ -1,98 +1,113 @@
|
||||||
#include "Config.h"
|
#include <thread>
|
||||||
#include "Daemon.h"
|
#include "Config.h"
|
||||||
#include "util.h"
|
#include "Daemon.h"
|
||||||
#include "Log.h"
|
#include "util.h"
|
||||||
|
#include "Log.h"
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
#include "Win32/Win32Service.h"
|
|
||||||
#include "Win32/Win32App.h"
|
|
||||||
|
|
||||||
namespace i2p
|
|
||||||
{
|
|
||||||
namespace util
|
|
||||||
{
|
|
||||||
bool DaemonWin32::init(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
setlocale(LC_CTYPE, "");
|
|
||||||
SetConsoleCP(1251);
|
|
||||||
SetConsoleOutputCP(1251);
|
|
||||||
|
|
||||||
if (!Daemon_Singleton::init(argc, argv))
|
#ifdef _WIN32
|
||||||
return false;
|
|
||||||
|
#include "Win32/Win32Service.h"
|
||||||
std::string serviceControl; i2p::config::GetOption("svcctl", serviceControl);
|
#ifdef WIN32_APP
|
||||||
if (serviceControl == "install")
|
#include "Win32/Win32App.h"
|
||||||
{
|
#endif
|
||||||
LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service");
|
|
||||||
InstallService(
|
namespace i2p
|
||||||
SERVICE_NAME, // Name of service
|
{
|
||||||
SERVICE_DISPLAY_NAME, // Name to display
|
namespace util
|
||||||
SERVICE_START_TYPE, // Service start type
|
{
|
||||||
SERVICE_DEPENDENCIES, // Dependencies
|
bool DaemonWin32::init(int argc, char* argv[])
|
||||||
SERVICE_ACCOUNT, // Service running account
|
{
|
||||||
SERVICE_PASSWORD // Password of the account
|
setlocale(LC_CTYPE, "");
|
||||||
);
|
SetConsoleCP(1251);
|
||||||
return false;
|
SetConsoleOutputCP(1251);
|
||||||
}
|
|
||||||
else if (serviceControl == "remove")
|
if (!Daemon_Singleton::init(argc, argv))
|
||||||
{
|
return false;
|
||||||
LogPrint(eLogInfo, "WinSVC: uninstalling ", SERVICE_NAME, " service");
|
|
||||||
UninstallService(SERVICE_NAME);
|
std::string serviceControl; i2p::config::GetOption("svcctl", serviceControl);
|
||||||
return false;
|
if (serviceControl == "install")
|
||||||
}
|
{
|
||||||
|
LogPrint(eLogInfo, "WinSVC: installing ", SERVICE_NAME, " as service");
|
||||||
if (isDaemon == 1)
|
InstallService(
|
||||||
{
|
SERVICE_NAME, // Name of service
|
||||||
LogPrint(eLogDebug, "Daemon: running as service");
|
SERVICE_DISPLAY_NAME, // Name to display
|
||||||
I2PService service(SERVICE_NAME);
|
SERVICE_START_TYPE, // Service start type
|
||||||
if (!I2PService::Run(service))
|
SERVICE_DEPENDENCIES, // Dependencies
|
||||||
{
|
SERVICE_ACCOUNT, // Service running account
|
||||||
LogPrint(eLogError, "Daemon: Service failed to run w/err 0x%08lx\n", GetLastError());
|
SERVICE_PASSWORD // Password of the account
|
||||||
return false;
|
);
|
||||||
}
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
else if (serviceControl == "remove")
|
||||||
else
|
{
|
||||||
LogPrint(eLogDebug, "Daemon: running as user");
|
LogPrint(eLogInfo, "WinSVC: uninstalling ", SERVICE_NAME, " service");
|
||||||
|
UninstallService(SERVICE_NAME);
|
||||||
return true;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint(eLogDebug, "Daemon: running as user");
|
||||||
|
|
||||||
|
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
|
||||||
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"));
|
||||||
bool ret = Daemon_Singleton::start();
|
#endif
|
||||||
if (ret && IsLogToFile ())
|
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);
|
// TODO: find out where this garbage to console comes from
|
||||||
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
|
SetStdHandle(STD_OUTPUT_HANDLE, INVALID_HANDLE_VALUE);
|
||||||
}
|
SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE);
|
||||||
bool insomnia; i2p::config::GetOption("insomnia", insomnia);
|
}
|
||||||
if (insomnia)
|
bool insomnia; i2p::config::GetOption("insomnia", insomnia);
|
||||||
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
if (insomnia)
|
||||||
return ret;
|
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
|
||||||
}
|
return ret;
|
||||||
|
}
|
||||||
bool DaemonWin32::stop()
|
|
||||||
|
bool DaemonWin32::stop()
|
||||||
{
|
{
|
||||||
i2p::win32::StopWin32App ();
|
#ifdef WIN32_APP
|
||||||
return Daemon_Singleton::stop();
|
i2p::win32::StopWin32App ();
|
||||||
|
#endif
|
||||||
|
return Daemon_Singleton::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonWin32::run ()
|
void DaemonWin32::run ()
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32_APP
|
||||||
i2p::win32::RunWin32App ();
|
i2p::win32::RunWin32App ();
|
||||||
}
|
#else
|
||||||
}
|
while (running)
|
||||||
}
|
{
|
||||||
|
std::this_thread::sleep_for (std::chrono::seconds(1));
|
||||||
#endif
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
USE_WIN32_APP=yes
|
||||||
CXX = g++
|
CXX = g++
|
||||||
WINDRES = windres
|
WINDRES = windres
|
||||||
CXXFLAGS = -Os -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN
|
CXXFLAGS = -Os -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN
|
||||||
NEEDED_CXXFLAGS = -std=c++11
|
NEEDED_CXXFLAGS = -std=c++11
|
||||||
BOOST_SUFFIX = -mt
|
BOOST_SUFFIX = -mt
|
||||||
INCFLAGS = -I/usr/include/ -I/usr/local/include/
|
INCFLAGS = -I/usr/include/ -I/usr/local/include/
|
||||||
LDFLAGS = -mwindows -s -Wl,-rpath,/usr/local/lib \
|
LDFLAGS = -Wl,-rpath,/usr/local/lib \
|
||||||
-L/usr/local/lib \
|
-L/usr/local/lib \
|
||||||
-L/c/dev/openssl \
|
-L/c/dev/openssl \
|
||||||
-L/c/dev/boost/lib
|
-L/c/dev/boost/lib
|
||||||
|
@ -24,8 +25,13 @@ LDLIBS = \
|
||||||
-static-libgcc -static-libstdc++ \
|
-static-libgcc -static-libstdc++ \
|
||||||
-Wl,-Bstatic -lstdc++ \
|
-Wl,-Bstatic -lstdc++ \
|
||||||
-Wl,-Bstatic -lpthread
|
-Wl,-Bstatic -lpthread
|
||||||
DAEMON_RC += Win32/Resource.rc
|
|
||||||
DAEMON_OBJS += $(patsubst %.rc,obj/%.o,$(DAEMON_RC))
|
ifeq ($(USE_WIN32_APP), yes)
|
||||||
|
CXXFLAGS += -DWIN32_APP
|
||||||
|
LDFLAGS += -mwindows -s
|
||||||
|
DAEMON_RC += Win32/Resource.rc
|
||||||
|
DAEMON_OBJS += $(patsubst %.rc,obj/%.o,$(DAEMON_RC))
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(USE_AESNI),1)
|
ifeq ($(USE_AESNI),1)
|
||||||
CPU_FLAGS = -maes -DAESNI
|
CPU_FLAGS = -maes -DAESNI
|
||||||
|
|
Loading…
Reference in a new issue