Browse Source

Merge pull request #409 from PurpleI2P/openssl

recent changes
pull/436/head
orignal 9 years ago
parent
commit
f24618e8df
  1. 2
      Config.h
  2. 7
      Daemon.h
  3. 54
      DaemonWin32.cpp
  4. 4
      FS.cpp
  5. 2
      Makefile
  6. 2
      Makefile.mingw
  7. 39
      Win32/Win32App.cpp
  8. 9
      Win32/Win32App.h
  9. 2
      version.h

2
Config.h

@ -90,7 +90,7 @@ namespace config {
bool SetOption(const char *name, const T& value) { bool SetOption(const char *name, const T& value) {
if (!m_Options.count(name)) if (!m_Options.count(name))
return false; return false;
m_Options[name] = value; m_Options.at(name).value() = value;
notify(m_Options); notify(m_Options);
return true; return true;
} }

7
Daemon.h

@ -48,9 +48,10 @@ namespace i2p
return instance; return instance;
} }
virtual bool init(int argc, char* argv[]); bool init(int argc, char* argv[]);
virtual bool start(); bool start();
virtual bool stop(); bool stop();
void run ();
}; };
#else #else
class DaemonLinux : public Daemon_Singleton class DaemonLinux : public Daemon_Singleton

54
DaemonWin32.cpp

@ -5,7 +5,7 @@
#ifdef _WIN32 #ifdef _WIN32
#include "./Win32/Win32Service.h" #include "Win32/Win32App.h"
namespace i2p namespace i2p
{ {
@ -17,57 +17,19 @@ namespace i2p
SetConsoleCP(1251); SetConsoleCP(1251);
SetConsoleOutputCP(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() 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");
if (!i2p::win32::StartWin32App ()) return false;
// override log
i2p::config::SetOption("log", std::string ("file"));
bool ret = Daemon_Singleton::start(); bool ret = Daemon_Singleton::start();
if (ret && IsLogToFile ()) if (ret && IsLogToFile ())
{ {
@ -80,8 +42,14 @@ namespace i2p
bool DaemonWin32::stop() bool DaemonWin32::stop()
{ {
i2p::win32::StopWin32App ();
return Daemon_Singleton::stop(); return Daemon_Singleton::stop();
} }
void DaemonWin32::run ()
{
i2p::win32::RunWin32App ();
}
} }
} }

4
FS.cpp

@ -68,10 +68,10 @@ namespace fs {
} }
bool Init() { bool Init() {
if (boost::filesystem::exists(dataDir)) if (!boost::filesystem::exists(dataDir))
boost::filesystem::create_directory(dataDir); boost::filesystem::create_directory(dataDir);
std::string destinations = DataDirPath("destinations"); std::string destinations = DataDirPath("destinations");
if (boost::filesystem::exists(destinations)) if (!boost::filesystem::exists(destinations))
boost::filesystem::create_directory(destinations); boost::filesystem::create_directory(destinations);
return true; return true;

2
Makefile

@ -22,7 +22,7 @@ else ifeq ($(UNAME),Linux)
DAEMON_SRC += DaemonLinux.cpp DAEMON_SRC += DaemonLinux.cpp
include Makefile.linux include Makefile.linux
else # win32 mingw else # win32 mingw
DAEMON_SRC += DaemonWin32.cpp Win32/Win32Service.cpp Win32/Win32App.cpp DAEMON_SRC += DaemonWin32.cpp Win32/Win32App.cpp
include Makefile.mingw include Makefile.mingw
endif endif

2
Makefile.mingw

@ -1,6 +1,6 @@
CXX = g++ CXX = g++
WINDRES = windres WINDRES = windres
CXXFLAGS = -O2 -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN CXXFLAGS = -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/

39
Win32/Win32App.cpp

@ -11,7 +11,11 @@
#define ID_TRAY_ICON 2050 #define ID_TRAY_ICON 2050
#define WM_TRAYICON (WM_USER + 1) #define WM_TRAYICON (WM_USER + 1)
void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem) namespace i2p
{
namespace win32
{
static void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem)
{ {
HMENU hPopup = CreatePopupMenu(); HMENU hPopup = CreatePopupMenu();
InsertMenu (hPopup, 0, MF_BYPOSITION | MF_STRING, ID_ABOUT, "About..."); InsertMenu (hPopup, 0, MF_BYPOSITION | MF_STRING, ID_ABOUT, "About...");
@ -33,7 +37,7 @@ void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem)
DestroyMenu(hPopup); DestroyMenu(hPopup);
} }
void AddTrayIcon (HWND hWnd) static void AddTrayIcon (HWND hWnd)
{ {
NOTIFYICONDATA nid; NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid)); memset(&nid, 0, sizeof(nid));
@ -47,7 +51,7 @@ void AddTrayIcon (HWND hWnd)
Shell_NotifyIcon(NIM_ADD, &nid ); Shell_NotifyIcon(NIM_ADD, &nid );
} }
void RemoveTrayIcon (HWND hWnd) static void RemoveTrayIcon (HWND hWnd)
{ {
NOTIFYICONDATA nid; NOTIFYICONDATA nid;
nid.hWnd = hWnd; nid.hWnd = hWnd;
@ -106,15 +110,15 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
return DefWindowProc( hWnd, uMsg, wParam, lParam); return DefWindowProc( hWnd, uMsg, wParam, lParam);
} }
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE prev, LPSTR cmdline, int show) bool StartWin32App ()
{ {
// check if tunning already
if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"))) if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd")))
{ {
MessageBox(NULL, TEXT("I2Pd is running already"), TEXT("Warning"), MB_OK); MessageBox(NULL, TEXT("I2Pd is running already"), TEXT("Warning"), MB_OK);
return 0; return false;
} }
// register main window // register main window
auto hInst = GetModuleHandle(NULL);
WNDCLASSEX wclx; WNDCLASSEX wclx;
memset (&wclx, 0, sizeof(wclx)); memset (&wclx, 0, sizeof(wclx));
wclx.cbSize = sizeof(wclx); wclx.cbSize = sizeof(wclx);
@ -134,24 +138,25 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa
if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 150, NULL, NULL, hInst, NULL)) if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 250, 150, NULL, NULL, hInst, NULL))
{ {
MessageBox(NULL, "Failed to create main window", TEXT("Warning!"), MB_ICONERROR | MB_OK | MB_TOPMOST); MessageBox(NULL, "Failed to create main window", TEXT("Warning!"), MB_ICONERROR | MB_OK | MB_TOPMOST);
return 1; return false;
}
return true;
} }
/* // init int RunWin32App ()
char * argv[] = { (char *)"i2pd" }; {
Daemon.init(sizeof (argv)/sizeof (argv[0]), argv);
// start
Daemon.start ();*/
// main loop
MSG msg; MSG msg;
while (GetMessage (&msg, NULL, 0, 0 )) while (GetMessage (&msg, NULL, 0, 0 ))
{ {
TranslateMessage (&msg); TranslateMessage (&msg);
DispatchMessage (&msg); DispatchMessage (&msg);
} }
/* // atop
Daemon.stop ();*/
// terminate
UnregisterClass (I2PD_WIN32_CLASSNAME, hInst);
return msg.wParam; return msg.wParam;
} }
void StopWin32App ()
{
UnregisterClass (I2PD_WIN32_CLASSNAME, GetModuleHandle(NULL));
}
}
}

9
Win32/Win32App.h

@ -3,4 +3,13 @@
#define I2PD_WIN32_CLASSNAME "i2pd main window" #define I2PD_WIN32_CLASSNAME "i2pd main window"
namespace i2p
{
namespace win32
{
bool StartWin32App ();
void StopWin32App ();
int RunWin32App ();
}
}
#endif // WIN32APP_H__ #endif // WIN32APP_H__

2
version.h

@ -8,7 +8,7 @@
#define I2PD_VERSION_MAJOR 2 #define I2PD_VERSION_MAJOR 2
#define I2PD_VERSION_MINOR 5 #define I2PD_VERSION_MINOR 5
#define I2PD_VERSION_MICRO 0 #define I2PD_VERSION_MICRO 1
#define I2PD_VERSION_PATCH 0 #define I2PD_VERSION_PATCH 0
#define I2PD_VERSION MAKE_VERSION(I2PD_VERSION_MAJOR, I2PD_VERSION_MINOR, I2PD_VERSION_MICRO) #define I2PD_VERSION MAKE_VERSION(I2PD_VERSION_MAJOR, I2PD_VERSION_MINOR, I2PD_VERSION_MICRO)
#define VERSION I2PD_VERSION #define VERSION I2PD_VERSION

Loading…
Cancel
Save