Browse Source

fixup! invoke win32app functions from main

pull/406/head
Mikhail Titov 9 years ago
parent
commit
daad975f5d
  1. 43
      DaemonWin32.cpp
  2. 6
      build/CMakeLists.txt
  3. 17
      i2pd.cpp

43
DaemonWin32.cpp

@ -5,6 +5,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include "Win32/Win32Service.h"
#include "Win32/Win32App.h" #include "Win32/Win32App.h"
namespace i2p namespace i2p
@ -16,8 +17,46 @@ namespace i2p
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
SetConsoleCP(1251); SetConsoleCP(1251);
SetConsoleOutputCP(1251); SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
return Daemon_Singleton::init(argc, argv); if (!Daemon_Singleton::init(argc, argv))
return false;
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
);
return false;
}
else if (serviceControl == "remove")
{
LogPrint(eLogInfo, "WinSVC: uninstalling ", SERVICE_NAME, " service");
UninstallService(SERVICE_NAME);
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()

6
build/CMakeLists.txt

@ -157,6 +157,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR MSYS) elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR MSYS)
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32App.cpp")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32Service.cpp") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Win32Service.cpp")
list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Resource.rc") list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/Win32/Resource.rc")
endif () endif ()
@ -309,7 +310,10 @@ include(GNUInstallDirs)
if (WITH_BINARY) if (WITH_BINARY)
add_executable ( "${PROJECT_NAME}" ${DAEMON_SRC} ) add_executable ( "${PROJECT_NAME}" ${DAEMON_SRC} )
if(NOT MSVC) # FIXME: incremental linker file name (.ilk) collision for dll & exe if (WIN32)
set_target_properties("${PROJECT_NAME}" PROPERTIES WIN32_EXECUTABLE TRUE )
endif()
if(NOT MSVC)
if (WITH_STATIC) if (WITH_STATIC)
set_target_properties("${PROJECT_NAME}" PROPERTIES LINK_FLAGS "-static" ) set_target_properties("${PROJECT_NAME}" PROPERTIES LINK_FLAGS "-static" )
endif () endif ()

17
i2pd.cpp

@ -3,10 +3,25 @@
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
{ {
Daemon.init(argc, argv); if (Daemon.init(argc, argv))
{
if (Daemon.start()) if (Daemon.start())
Daemon.run (); Daemon.run ();
Daemon.stop(); Daemon.stop();
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
#ifdef _WIN32
#include <windows.h>
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
{
return main(__argc, __argv);
}
#endif

Loading…
Cancel
Save