From e2a70873b826085ac8db2fc751a2d41389b49392 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 5 Mar 2016 21:46:01 -0500 Subject: [PATCH 1/9] fixed garbage in console for windows --- DaemonWin32.cpp | 9 ++++++++- Log.h | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/DaemonWin32.cpp b/DaemonWin32.cpp index 4ab65040..bf5f938c 100644 --- a/DaemonWin32.cpp +++ b/DaemonWin32.cpp @@ -68,7 +68,14 @@ namespace i2p SetConsoleOutputCP(1251); setlocale(LC_ALL, "Russian"); - return Daemon_Singleton::start(); + 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); + SetStdHandle(STD_ERROR_HANDLE, INVALID_HANDLE_VALUE); + } + return ret; } bool DaemonWin32::stop() diff --git a/Log.h b/Log.h index 5b07e2c9..363a23b5 100644 --- a/Log.h +++ b/Log.h @@ -45,6 +45,7 @@ class Log: public i2p::util::MsgQueue std::shared_ptr GetLogStream () const { return m_LogStream; }; const std::string& GetTimestamp (); LogLevel GetLogLevel () { return m_MinLevel; }; + const std::string& GetFullFilePath () const { return m_FullFilePath; }; private: @@ -110,6 +111,11 @@ inline void ReopenLogFile () g_Log->ReopenLogFile (); } +inline bool IsLogToFile () +{ + return g_Log ? !g_Log->GetFullFilePath ().empty () : false; +} + template void LogPrint (std::stringstream& s, TValue arg) { From a5576ddbf3e2b8948dd2fdada7c8799abb724f08 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 6 Mar 2016 09:57:38 -0500 Subject: [PATCH 2/9] don't acquire DH keys pair until connection is established --- NTCPSession.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 0ac2e74b..2584f584 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -25,7 +25,6 @@ namespace transport m_TerminationTimer (m_Server.GetService ()), m_IsEstablished (false), m_IsTerminated (false), m_ReceiveBufferOffset (0), m_NextMessage (nullptr), m_IsSending (false) { - m_DHKeysPair = transports.GetNextDHKeysPair (); m_Establisher = new Establisher; } From 6383fc357556b83e3b94d45cce541ed84a352398 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 7 Mar 2016 14:54:57 -0500 Subject: [PATCH 3/9] initial commit of Win32App --- Makefile | 2 +- Win32/Win32App.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++ Win32/Win32App.h | 8 +++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Win32/Win32App.cpp create mode 100644 Win32/Win32App.h diff --git a/Makefile b/Makefile index 09cf2ace..9bfae351 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ else ifeq ($(UNAME),Linux) DAEMON_SRC += DaemonLinux.cpp include Makefile.linux else # win32 mingw - DAEMON_SRC += DaemonWin32.cpp Win32/Win32Service.cpp + DAEMON_SRC += DaemonWin32.cpp Win32/Win32Service.cpp Win32/Win32App.cpp WINDIR := True include Makefile.mingw endif diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp new file mode 100644 index 00000000..42d7bef8 --- /dev/null +++ b/Win32/Win32App.cpp @@ -0,0 +1,56 @@ +#include +#include "Win32App.h" + + +static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + } + return DefWindowProc( hWnd, uMsg, wParam, lParam); +} + + int WINAPI WinMain (HINSTANCE hInst, HINSTANCE prev, LPSTR cmdline, int show) + { + // check if tunning already + if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("Title"))) + { + MessageBox(NULL, TEXT("I2Pd is running already"), TEXT("Warning"), MB_OK); + return 0; + } + // register main window + WNDCLASSEX wclx; + memset (&wclx, 0, sizeof(wclx)); + wclx.cbSize = sizeof(wclx); + wclx.style = 0; + wclx.lpfnWndProc = &WndProc; + wclx.cbClsExtra = 0; + wclx.cbWndExtra = 0; + wclx.hInstance = hInst; + //wclx.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_TRAYICON ) ); + //wclx.hIconSm = LoadSmallIcon( hInstance, IDI_TRAYICON ); + wclx.hCursor = LoadCursor (NULL, IDC_ARROW); + wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); + wclx.lpszMenuName = NULL; + wclx.lpszClassName = I2PD_WIN32_CLASSNAME; + RegisterClassEx (&wclx); + // create new window + if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("Title"), 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); + return 1; + } + + // start + // main loop + MSG msg; + while (GetMessage (&msg, NULL, 0, 0 )) + { + TranslateMessage (&msg); + DispatchMessage (&msg); + } + // atop + // terminate + UnregisterClass (I2PD_WIN32_CLASSNAME, hInst); + return msg.wParam; + } diff --git a/Win32/Win32App.h b/Win32/Win32App.h new file mode 100644 index 00000000..e7c384a9 --- /dev/null +++ b/Win32/Win32App.h @@ -0,0 +1,8 @@ +#ifndef WIN32APP_H__ +#define WIN32APP_H__ + +#include + +#define I2PD_WIN32_CLASSNAME "i2pd main window" + +#endif // WIN32APP_H__ From 607336d3ce5994e8fc51eba7424b81e7d3536ccc Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 7 Mar 2016 15:57:32 -0500 Subject: [PATCH 4/9] tray icon added --- Win32/Win32App.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++-- Win32/Win32App.h | 2 - 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index 42d7bef8..a7bda173 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -1,11 +1,99 @@ #include +#include +#include #include "Win32App.h" +#define ID_ABOUT 2000 +#define ID_EXIT 2001 + +void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem) +{ + HMENU hPopup = CreatePopupMenu(); + InsertMenu (hPopup, 0, MF_BYPOSITION | MF_STRING, ID_ABOUT, "About..."); + InsertMenu (hPopup, 1, MF_BYPOSITION | MF_STRING, ID_EXIT , "Exit"); + SetMenuDefaultItem (hPopup, ID_ABOUT, FALSE); + SetFocus (hWnd); + SendMessage (hWnd, WM_INITMENUPOPUP, (WPARAM)hPopup, 0); + + POINT p; + if (!curpos) + { + GetCursorPos (&p); + curpos = &p; + } + + WORD cmd = TrackPopupMenu (hPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, curpos->x, curpos->y, 0, hWnd, NULL); + SendMessage (hWnd, WM_COMMAND, cmd, 0); + + DestroyMenu(hPopup); +} + +void AddTrayIcon (HWND hWnd, UINT uID, UINT uCallbackMsg, UINT uIcon) +{ + NOTIFYICONDATA nid; + nid.hWnd = hWnd; + nid.uID = uID; + nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + nid.uCallbackMessage = uCallbackMsg; + nid.hIcon = LoadIcon (GetModuleHandle(NULL), IDI_APPLICATION); + strcpy (nid.szTip, "i2pd"); + Shell_NotifyIcon(NIM_ADD, &nid ); +} + +void RemoveTrayIcon (HWND hWnd, UINT uID) +{ + NOTIFYICONDATA nid; + nid.hWnd = hWnd; + nid.uID = uID; + Shell_NotifyIcon (NIM_DELETE, &nid); +} static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { + case WM_CREATE: + { + AddTrayIcon (hWnd, 1, WM_APP, 0); + return 0; + } + case WM_CLOSE: + { + RemoveTrayIcon (hWnd, 1); + PostQuitMessage (0); + return DefWindowProc (hWnd, uMsg, wParam, lParam); + } + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case ID_ABOUT: + { + MessageBox( hWnd, TEXT("i2pd"), TEXT("About"), MB_ICONINFORMATION | MB_OK ); + return 0; + } + case ID_EXIT: + { + PostMessage (hWnd, WM_CLOSE, 0, 0); + return 0; + } + } + break; + } + case WM_APP: + { + switch (lParam) + { + case WM_RBUTTONUP: + { + SetForegroundWindow (hWnd); + ShowPopupMenu(hWnd, NULL, -1); + PostMessage (hWnd, WM_APP + 1, 0, 0); + return 0; + } + } + break; + } } return DefWindowProc( hWnd, uMsg, wParam, lParam); } @@ -13,7 +101,7 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa int WINAPI WinMain (HINSTANCE hInst, HINSTANCE prev, LPSTR cmdline, int show) { // check if tunning already - if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("Title"))) + if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"))) { MessageBox(NULL, TEXT("I2Pd is running already"), TEXT("Warning"), MB_OK); return 0; @@ -27,15 +115,15 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa wclx.cbClsExtra = 0; wclx.cbWndExtra = 0; wclx.hInstance = hInst; - //wclx.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_TRAYICON ) ); - //wclx.hIconSm = LoadSmallIcon( hInstance, IDI_TRAYICON ); + wclx.hIcon = LoadIcon (hInst, IDI_APPLICATION); + wclx.hIconSm = LoadIcon (hInst, IDI_APPLICATION); wclx.hCursor = LoadCursor (NULL, IDC_ARROW); wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wclx.lpszMenuName = NULL; wclx.lpszClassName = I2PD_WIN32_CLASSNAME; RegisterClassEx (&wclx); // create new window - if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("Title"), 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); return 1; diff --git a/Win32/Win32App.h b/Win32/Win32App.h index e7c384a9..8b14ae1b 100644 --- a/Win32/Win32App.h +++ b/Win32/Win32App.h @@ -1,8 +1,6 @@ #ifndef WIN32APP_H__ #define WIN32APP_H__ -#include - #define I2PD_WIN32_CLASSNAME "i2pd main window" #endif // WIN32APP_H__ From 9096cacba8b48f747344b2f580bcda1eca9363f8 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 7 Mar 2016 16:06:34 -0500 Subject: [PATCH 5/9] tray icon added --- Win32/Win32App.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index a7bda173..f69045d9 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -129,7 +129,13 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa return 1; } + // init + int argc; + auto argv = CommandLineToArgvW (cmdline, &argc) + Daemon.init(argc, argv); + LocalFree (argv); // start + Daemon.start (); // main loop MSG msg; while (GetMessage (&msg, NULL, 0, 0 )) @@ -138,6 +144,7 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa DispatchMessage (&msg); } // atop + Daemon.stop (); // terminate UnregisterClass (I2PD_WIN32_CLASSNAME, hInst); return msg.wParam; From 4cfdc770158cf8f45106ee538abd444109b9ded2 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 7 Mar 2016 16:17:06 -0500 Subject: [PATCH 6/9] invoke daemon --- Win32/Win32App.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index f69045d9..ca97fe59 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "../Daemon.h" #include "Win32App.h" #define ID_ABOUT 2000 @@ -130,10 +131,8 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa } // init - int argc; - auto argv = CommandLineToArgvW (cmdline, &argc) - Daemon.init(argc, argv); - LocalFree (argv); + char * argv[] = { (char *)"i2pd" }; + Daemon.init(sizeof (argv)/sizeof (argv[0]), argv); // start Daemon.start (); // main loop From 507093dbad65f748611606b7f65913b2a7a24c81 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 7 Mar 2016 21:36:11 -0500 Subject: [PATCH 7/9] compile with resources --- Makefile | 196 +++++++++++++++++++++++++------------------------ Makefile.mingw | 3 +- 2 files changed, 103 insertions(+), 96 deletions(-) diff --git a/Makefile b/Makefile index 9bfae351..ef0dec46 100644 --- a/Makefile +++ b/Makefile @@ -1,95 +1,101 @@ -UNAME := $(shell uname -s) -SHLIB := libi2pd.so -ARLIB := libi2pd.a -SHLIB_CLIENT := libi2pdclient.so -ARLIB_CLIENT := libi2pdclient.a -I2PD := i2pd -GREP := fgrep -DEPS := obj/make.dep - -include filelist.mk - -USE_AESNI := yes -USE_STATIC := no - -ifeq ($(UNAME),Darwin) - DAEMON_SRC += DaemonLinux.cpp - include Makefile.osx -else ifeq ($(shell echo $(UNAME) | $(GREP) -c FreeBSD),1) - DAEMON_SRC += DaemonLinux.cpp - include Makefile.bsd -else ifeq ($(UNAME),Linux) - DAEMON_SRC += DaemonLinux.cpp - include Makefile.linux -else # win32 mingw - DAEMON_SRC += DaemonWin32.cpp Win32/Win32Service.cpp Win32/Win32App.cpp - WINDIR := True - include Makefile.mingw -endif - -all: mk_build_dir $(ARLIB) $(ARLIB_CLIENT) $(I2PD) - -mk_build_dir: - mkdir -p obj - ifeq ($(WINDIR),True) - mkdir -p obj/Win32 - endif - -api: mk_build_dir $(SHLIB) $(ARLIB) -api_client: mk_build_dir $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT) - -## NOTE: The NEEDED_CXXFLAGS are here so that CXXFLAGS can be specified at build time -## **without** overwriting the CXXFLAGS which we need in order to build. -## For example, when adding 'hardening flags' to the build -## (e.g. -fstack-protector-strong -Wformat -Werror=format-security), we do not want to remove -## -std=c++11. If you want to remove this variable please do so in a way that allows setting -## custom FLAGS to work at build-time. - -deps: - @mkdir -p obj - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS) - @sed -i -e '/\.o:/ s/^/obj\//' $(DEPS) - -obj/%.o : %.cpp - @mkdir -p obj - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $< - -# '-' is 'ignore if missing' on first run --include $(DEPS) - -$(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) $(ARLIB) $(ARLIB_CLIENT) - $(CXX) -o $@ $^ $(LDLIBS) $(LDFLAGS) - -$(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) -ifneq ($(USE_STATIC),yes) - $(CXX) $(LDFLAGS) $(LDLIBS) -shared -o $@ $^ -endif - -$(SHLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC)) - $(CXX) $(LDFLAGS) $(LDLIBS) -shared -o $@ $^ - -$(ARLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) - ar -r $@ $^ - -$(ARLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC)) - ar -r $@ $^ - -clean: - rm -rf obj - $(RM) $(I2PD) $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT) - -strip: $(I2PD) $(SHLIB_CLIENT) $(SHLIB) - strip $^ - -LATEST_TAG=$(shell git describe --tags --abbrev=0 master) -dist: - git archive --format=tar.gz -9 --worktree-attributes \ - --prefix=i2pd_$(LATEST_TAG)/ $(LATEST_TAG) -o i2pd_$(LATEST_TAG).tar.gz - -.PHONY: all -.PHONY: clean -.PHONY: deps -.PHONY: dist -.PHONY: api -.PHONY: api_client -.PHONY: mk_build_dir +UNAME := $(shell uname -s) +SHLIB := libi2pd.so +ARLIB := libi2pd.a +SHLIB_CLIENT := libi2pdclient.so +ARLIB_CLIENT := libi2pdclient.a +I2PD := i2pd +GREP := fgrep +DEPS := obj/make.dep + +include filelist.mk + +USE_AESNI := yes +USE_STATIC := no + +ifeq ($(UNAME),Darwin) + DAEMON_SRC += DaemonLinux.cpp + include Makefile.osx +else ifeq ($(shell echo $(UNAME) | $(GREP) -c FreeBSD),1) + DAEMON_SRC += DaemonLinux.cpp + include Makefile.bsd +else ifeq ($(UNAME),Linux) + DAEMON_SRC += DaemonLinux.cpp + include Makefile.linux +else # win32 mingw + DAEMON_SRC += DaemonWin32.cpp Win32/Win32Service.cpp Win32/Win32App.cpp + DAEMON_RC += Win32/Resource.rc + WINDIR := True + include Makefile.mingw +endif + +all: mk_build_dir $(ARLIB) $(ARLIB_CLIENT) $(I2PD) + +mk_build_dir: + mkdir -p obj + ifeq ($(WINDIR),True) + mkdir -p obj/Win32 + endif + +api: mk_build_dir $(SHLIB) $(ARLIB) +api_client: mk_build_dir $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT) + +## NOTE: The NEEDED_CXXFLAGS are here so that CXXFLAGS can be specified at build time +## **without** overwriting the CXXFLAGS which we need in order to build. +## For example, when adding 'hardening flags' to the build +## (e.g. -fstack-protector-strong -Wformat -Werror=format-security), we do not want to remove +## -std=c++11. If you want to remove this variable please do so in a way that allows setting +## custom FLAGS to work at build-time. + +deps: + @mkdir -p obj + $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS) + @sed -i -e '/\.o:/ s/^/obj\//' $(DEPS) + +obj/%.o : %.cpp + @mkdir -p obj + $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $< + +obj/%.o : %.rc + $(WINDRES) -i $< -o $@ + +# '-' is 'ignore if missing' on first run +-include $(DEPS) + +DAEMON_OBJS = $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) +DAEMON_RES_OBJS = $(patsubst %.rc,obj/%.o,$(DAEMON_RC)) +$(I2PD): $(DAEMON_OBJS) $(DAEMON_RES_OBJS) $(ARLIB) $(ARLIB_CLIENT) + $(CXX) -o $@ $^ $(LDLIBS) $(LDFLAGS) + +$(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) +ifneq ($(USE_STATIC),yes) + $(CXX) $(LDFLAGS) $(LDLIBS) -shared -o $@ $^ +endif + +$(SHLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC)) + $(CXX) $(LDFLAGS) $(LDLIBS) -shared -o $@ $^ + +$(ARLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) + ar -r $@ $^ + +$(ARLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC)) + ar -r $@ $^ + +clean: + rm -rf obj + $(RM) $(I2PD) $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT) + +strip: $(I2PD) $(SHLIB_CLIENT) $(SHLIB) + strip $^ + +LATEST_TAG=$(shell git describe --tags --abbrev=0 master) +dist: + git archive --format=tar.gz -9 --worktree-attributes \ + --prefix=i2pd_$(LATEST_TAG)/ $(LATEST_TAG) -o i2pd_$(LATEST_TAG).tar.gz + +.PHONY: all +.PHONY: clean +.PHONY: deps +.PHONY: dist +.PHONY: api +.PHONY: api_client +.PHONY: mk_build_dir diff --git a/Makefile.mingw b/Makefile.mingw index 24f33a11..632eca0c 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,9 +1,10 @@ CXX = g++ +WINDRES = windres CXXFLAGS = -O2 -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN NEEDED_CXXFLAGS = -std=c++11 BOOST_SUFFIX = -mt INCFLAGS = -I/usr/include/ -I/usr/local/include/ -LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib -L/c/dev/openssl -L/c/dev/boost/lib +LDFLAGS = -mwindows -Wl,-rpath,/usr/local/lib -L/usr/local/lib -L/c/dev/openssl -L/c/dev/boost/lib LDLIBS = -Wl,-Bstatic -lboost_system$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_date_time$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_filesystem$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_regex$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_program_options$(BOOST_SUFFIX) -Wl,-Bstatic -lssl -Wl,-Bstatic -lcrypto -Wl,-Bstatic -lz -Wl,-Bstatic -lwsock32 -Wl,-Bstatic -lws2_32 -Wl,-Bstatic -lgdi32 -Wl,-Bstatic -liphlpapi -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -Wl,-Bstatic -lpthread ifeq ($(USE_AESNI),1) From ebd356c7bdca430daba1d728ffcf766211d22b00 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 8 Mar 2016 11:24:29 -0500 Subject: [PATCH 8/9] set correct icons --- Win32/Win32App.cpp | 58 ++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/Win32/Win32App.cpp b/Win32/Win32App.cpp index ca97fe59..b039c9b3 100644 --- a/Win32/Win32App.cpp +++ b/Win32/Win32App.cpp @@ -1,12 +1,16 @@ #include #include #include -#include "../Daemon.h" +//#include "../Daemon.h" +#include "resource.h" #include "Win32App.h" #define ID_ABOUT 2000 #define ID_EXIT 2001 +#define ID_TRAY_ICON 2050 +#define WM_TRAYICON (WM_USER + 1) + void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem) { HMENU hPopup = CreatePopupMenu(); @@ -29,23 +33,36 @@ void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem) DestroyMenu(hPopup); } -void AddTrayIcon (HWND hWnd, UINT uID, UINT uCallbackMsg, UINT uIcon) +void AddTrayIcon (HWND hWnd) { NOTIFYICONDATA nid; + memset(&nid, 0, sizeof(nid)); + nid.cbSize = sizeof(nid); nid.hWnd = hWnd; - nid.uID = uID; + nid.uID = ID_TRAY_ICON; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; - nid.uCallbackMessage = uCallbackMsg; - nid.hIcon = LoadIcon (GetModuleHandle(NULL), IDI_APPLICATION); + nid.uCallbackMessage = WM_TRAYICON; + // TODO: must set correct icon + // nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (IDI_ICON1)); + { + char szIconFile[512]; + + GetSystemDirectory( szIconFile, sizeof( szIconFile ) ); + if ( szIconFile[ strlen( szIconFile ) - 1 ] != '\\' ) + strcat( szIconFile, "\\" ); + strcat( szIconFile, "shell32.dll" ); + // Icon #23 (0-indexed) in shell32.dll is a "help" icon. + ExtractIconEx( szIconFile, 23, NULL, &(nid.hIcon), 1 ); + } strcpy (nid.szTip, "i2pd"); Shell_NotifyIcon(NIM_ADD, &nid ); } -void RemoveTrayIcon (HWND hWnd, UINT uID) +void RemoveTrayIcon (HWND hWnd) { NOTIFYICONDATA nid; nid.hWnd = hWnd; - nid.uID = uID; + nid.uID = ID_TRAY_ICON; Shell_NotifyIcon (NIM_DELETE, &nid); } @@ -55,14 +72,14 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa { case WM_CREATE: { - AddTrayIcon (hWnd, 1, WM_APP, 0); - return 0; + AddTrayIcon (hWnd); + break; } case WM_CLOSE: { - RemoveTrayIcon (hWnd, 1); + RemoveTrayIcon (hWnd); PostQuitMessage (0); - return DefWindowProc (hWnd, uMsg, wParam, lParam); + break; } case WM_COMMAND: { @@ -81,8 +98,9 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa } break; } - case WM_APP: + case WM_TRAYICON: { + SetForegroundWindow (hWnd); switch (lParam) { case WM_RBUTTONUP: @@ -90,7 +108,7 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa SetForegroundWindow (hWnd); ShowPopupMenu(hWnd, NULL, -1); PostMessage (hWnd, WM_APP + 1, 0, 0); - return 0; + break; } } break; @@ -112,12 +130,12 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa memset (&wclx, 0, sizeof(wclx)); wclx.cbSize = sizeof(wclx); wclx.style = 0; - wclx.lpfnWndProc = &WndProc; + wclx.lpfnWndProc = WndProc; wclx.cbClsExtra = 0; wclx.cbWndExtra = 0; wclx.hInstance = hInst; - wclx.hIcon = LoadIcon (hInst, IDI_APPLICATION); - wclx.hIconSm = LoadIcon (hInst, IDI_APPLICATION); + wclx.hIcon = LoadIcon (hInst, MAKEINTRESOURCE (IDI_ICON1)); + wclx.hIconSm = LoadIcon (hInst, MAKEINTRESOURCE (IDI_ICON1)); wclx.hCursor = LoadCursor (NULL, IDC_ARROW); wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); wclx.lpszMenuName = NULL; @@ -130,11 +148,11 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa return 1; } - // init + /* // init char * argv[] = { (char *)"i2pd" }; Daemon.init(sizeof (argv)/sizeof (argv[0]), argv); // start - Daemon.start (); + Daemon.start ();*/ // main loop MSG msg; while (GetMessage (&msg, NULL, 0, 0 )) @@ -142,8 +160,8 @@ static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa TranslateMessage (&msg); DispatchMessage (&msg); } - // atop - Daemon.stop (); + /* // atop + Daemon.stop ();*/ // terminate UnregisterClass (I2PD_WIN32_CLASSNAME, hInst); return msg.wParam; From 4b0d587fe108be85b2d3d37b45d5a53f0e51fb1a Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 8 Mar 2016 15:02:32 -0500 Subject: [PATCH 9/9] Daemon::run --- Daemon.h | 7 +++++-- DaemonLinux.cpp | 9 +++++++++ i2pd.cpp | 8 +------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Daemon.h b/Daemon.h index e755e3e9..4f31b2dc 100644 --- a/Daemon.h +++ b/Daemon.h @@ -20,6 +20,7 @@ namespace i2p virtual bool init(int argc, char* argv[]); virtual bool start(); virtual bool stop(); + virtual void run () {}; bool isLogging; bool isDaemon; @@ -61,8 +62,10 @@ namespace i2p return instance; } - virtual bool start(); - virtual bool stop(); + bool start(); + bool stop(); +; void run (); + private: std::string pidfile; int pidFH; diff --git a/DaemonLinux.cpp b/DaemonLinux.cpp index 2ccbfe38..53d9f61e 100644 --- a/DaemonLinux.cpp +++ b/DaemonLinux.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -118,6 +119,14 @@ namespace i2p return Daemon_Singleton::stop(); } + + void DaemonLinux::run () + { + while (running) + { + std::this_thread::sleep_for (std::chrono::seconds(1)); + } + } } } diff --git a/i2pd.cpp b/i2pd.cpp index 32749d16..6167f10e 100644 --- a/i2pd.cpp +++ b/i2pd.cpp @@ -1,4 +1,3 @@ -#include #include #include "Daemon.h" @@ -6,12 +5,7 @@ int main( int argc, char* argv[] ) { Daemon.init(argc, argv); if (Daemon.start()) - { - while (Daemon.running) - { - std::this_thread::sleep_for (std::chrono::seconds(1)); - } - } + Daemon.run (); Daemon.stop(); return EXIT_SUCCESS; }