mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e5b32ef13 | ||
|
|
0493a321d2 | ||
|
|
38b6c12153 | ||
|
|
74d4b8e0b9 | ||
|
|
95b2bf3645 | ||
|
|
121ac4f1de | ||
|
|
ec8550d587 | ||
|
|
e403c419e5 | ||
|
|
4b0d587fe1 | ||
|
|
ebd356c7bd | ||
|
|
507093dbad | ||
|
|
4cfdc77015 | ||
|
|
9096cacba8 | ||
|
|
607336d3ce | ||
|
|
6383fc3575 | ||
|
|
a5576ddbf3 | ||
|
|
e2a70873b8 |
2
Config.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;
|
||||||
}
|
}
|
||||||
|
|||||||
14
Daemon.h
14
Daemon.h
@@ -20,6 +20,7 @@ namespace i2p
|
|||||||
virtual bool init(int argc, char* argv[]);
|
virtual bool init(int argc, char* argv[]);
|
||||||
virtual bool start();
|
virtual bool start();
|
||||||
virtual bool stop();
|
virtual bool stop();
|
||||||
|
virtual void run () {};
|
||||||
|
|
||||||
bool isLogging;
|
bool isLogging;
|
||||||
bool isDaemon;
|
bool isDaemon;
|
||||||
@@ -47,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
|
||||||
@@ -61,8 +63,10 @@ namespace i2p
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool start();
|
bool start();
|
||||||
virtual bool stop();
|
bool stop();
|
||||||
|
; void run ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string pidfile;
|
std::string pidfile;
|
||||||
int pidFH;
|
int pidFH;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <thread>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -118,6 +119,14 @@ namespace i2p
|
|||||||
|
|
||||||
return Daemon_Singleton::stop();
|
return Daemon_Singleton::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DaemonLinux::run ()
|
||||||
|
{
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for (std::chrono::seconds(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include "./Win32/Win32Service.h"
|
#include "Win32/Win32App.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
@@ -17,64 +17,39 @@ 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;
|
||||||
|
|
||||||
return Daemon_Singleton::start();
|
// override log
|
||||||
|
i2p::config::SetOption("log", std::string ("file"));
|
||||||
|
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()
|
bool DaemonWin32::stop()
|
||||||
{
|
{
|
||||||
|
i2p::win32::StopWin32App ();
|
||||||
return Daemon_Singleton::stop();
|
return Daemon_Singleton::stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DaemonWin32::run ()
|
||||||
|
{
|
||||||
|
i2p::win32::RunWin32App ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
FS.cpp
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;
|
||||||
|
|||||||
6
Log.h
6
Log.h
@@ -45,6 +45,7 @@ class Log: public i2p::util::MsgQueue<LogMsg>
|
|||||||
std::shared_ptr<std::ostream> GetLogStream () const { return m_LogStream; };
|
std::shared_ptr<std::ostream> GetLogStream () const { return m_LogStream; };
|
||||||
const std::string& GetTimestamp ();
|
const std::string& GetTimestamp ();
|
||||||
LogLevel GetLogLevel () { return m_MinLevel; };
|
LogLevel GetLogLevel () { return m_MinLevel; };
|
||||||
|
const std::string& GetFullFilePath () const { return m_FullFilePath; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -110,6 +111,11 @@ inline void ReopenLogFile ()
|
|||||||
g_Log->ReopenLogFile ();
|
g_Log->ReopenLogFile ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool IsLogToFile ()
|
||||||
|
{
|
||||||
|
return g_Log ? !g_Log->GetFullFilePath ().empty () : false;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename TValue>
|
template<typename TValue>
|
||||||
void LogPrint (std::stringstream& s, TValue arg)
|
void LogPrint (std::stringstream& s, TValue arg)
|
||||||
{
|
{
|
||||||
|
|||||||
28
Makefile
28
Makefile
@@ -22,21 +22,18 @@ 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
|
DAEMON_SRC += DaemonWin32.cpp Win32/Win32App.cpp
|
||||||
WINDIR := True
|
|
||||||
include Makefile.mingw
|
include Makefile.mingw
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: mk_build_dir $(ARLIB) $(ARLIB_CLIENT) $(I2PD)
|
all: mk_obj_dir $(ARLIB) $(ARLIB_CLIENT) $(I2PD)
|
||||||
|
|
||||||
mk_build_dir:
|
mk_obj_dir:
|
||||||
mkdir -p obj
|
@mkdir -p obj
|
||||||
ifeq ($(WINDIR),True)
|
@mkdir -p obj/Win32
|
||||||
mkdir -p obj/Win32
|
|
||||||
endif
|
|
||||||
|
|
||||||
api: mk_build_dir $(SHLIB) $(ARLIB)
|
api: mk_obj_dir $(SHLIB) $(ARLIB)
|
||||||
api_client: mk_build_dir $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT)
|
api_client: mk_obj_dir $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT)
|
||||||
|
|
||||||
## NOTE: The NEEDED_CXXFLAGS are here so that CXXFLAGS can be specified at build time
|
## 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.
|
## **without** overwriting the CXXFLAGS which we need in order to build.
|
||||||
@@ -45,19 +42,18 @@ api_client: mk_build_dir $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT)
|
|||||||
## -std=c++11. If you want to remove this variable please do so in a way that allows setting
|
## -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.
|
## custom FLAGS to work at build-time.
|
||||||
|
|
||||||
deps:
|
deps: mk_obj_dir
|
||||||
@mkdir -p obj
|
|
||||||
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS)
|
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) -MM *.cpp > $(DEPS)
|
||||||
@sed -i -e '/\.o:/ s/^/obj\//' $(DEPS)
|
@sed -i -e '/\.o:/ s/^/obj\//' $(DEPS)
|
||||||
|
|
||||||
obj/%.o : %.cpp
|
obj/%.o: %.cpp
|
||||||
@mkdir -p obj
|
|
||||||
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $<
|
$(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $<
|
||||||
|
|
||||||
# '-' is 'ignore if missing' on first run
|
# '-' is 'ignore if missing' on first run
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
||||||
$(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) $(ARLIB) $(ARLIB_CLIENT)
|
DAEMON_OBJS += $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC))
|
||||||
|
$(I2PD): $(DAEMON_OBJS) $(ARLIB) $(ARLIB_CLIENT)
|
||||||
$(CXX) -o $@ $^ $(LDLIBS) $(LDFLAGS)
|
$(CXX) -o $@ $^ $(LDLIBS) $(LDFLAGS)
|
||||||
|
|
||||||
$(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC))
|
$(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC))
|
||||||
@@ -92,4 +88,4 @@ dist:
|
|||||||
.PHONY: dist
|
.PHONY: dist
|
||||||
.PHONY: api
|
.PHONY: api
|
||||||
.PHONY: api_client
|
.PHONY: api_client
|
||||||
.PHONY: mk_build_dir
|
.PHONY: mk_obj_dir
|
||||||
|
|||||||
@@ -1,13 +1,38 @@
|
|||||||
CXX = g++
|
CXX = g++
|
||||||
CXXFLAGS = -O2 -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN
|
WINDRES = windres
|
||||||
|
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/
|
||||||
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 \
|
||||||
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
|
-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
|
||||||
|
DAEMON_RC += Win32/Resource.rc
|
||||||
|
DAEMON_OBJS += $(patsubst %.rc,obj/%.o,$(DAEMON_RC))
|
||||||
|
|
||||||
ifeq ($(USE_AESNI),1)
|
ifeq ($(USE_AESNI),1)
|
||||||
CPU_FLAGS = -maes -DAESNI
|
CPU_FLAGS = -maes -DAESNI
|
||||||
else
|
else
|
||||||
CPU_FLAGS = -msse
|
CPU_FLAGS = -msse
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
obj/%.o : %.rc
|
||||||
|
$(WINDRES) -i $< -o $@
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ namespace transport
|
|||||||
m_TerminationTimer (m_Server.GetService ()), m_IsEstablished (false), m_IsTerminated (false),
|
m_TerminationTimer (m_Server.GetService ()), m_IsEstablished (false), m_IsTerminated (false),
|
||||||
m_ReceiveBufferOffset (0), m_NextMessage (nullptr), m_IsSending (false)
|
m_ReceiveBufferOffset (0), m_NextMessage (nullptr), m_IsSending (false)
|
||||||
{
|
{
|
||||||
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
|
||||||
m_Establisher = new Establisher;
|
m_Establisher = new Establisher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ END
|
|||||||
// Icon with lowest ID value placed first to ensure application icon
|
// Icon with lowest ID value placed first to ensure application icon
|
||||||
// remains consistent on all systems.
|
// remains consistent on all systems.
|
||||||
MAINICON ICON "ictoopie.ico"
|
MAINICON ICON "ictoopie.ico"
|
||||||
|
IDI_ICON1 ICON "ictoopie_16.ico"
|
||||||
#endif // English (United States) resources
|
#endif // English (United States) resources
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
162
Win32/Win32App.cpp
Normal file
162
Win32/Win32App.cpp
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
#include <string.h>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <shellapi.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)
|
||||||
|
|
||||||
|
namespace i2p
|
||||||
|
{
|
||||||
|
namespace win32
|
||||||
|
{
|
||||||
|
static 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddTrayIcon (HWND hWnd)
|
||||||
|
{
|
||||||
|
NOTIFYICONDATA nid;
|
||||||
|
memset(&nid, 0, sizeof(nid));
|
||||||
|
nid.cbSize = sizeof(nid);
|
||||||
|
nid.hWnd = hWnd;
|
||||||
|
nid.uID = ID_TRAY_ICON;
|
||||||
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
||||||
|
nid.uCallbackMessage = WM_TRAYICON;
|
||||||
|
nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (IDI_ICON1));
|
||||||
|
strcpy (nid.szTip, "i2pd");
|
||||||
|
Shell_NotifyIcon(NIM_ADD, &nid );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RemoveTrayIcon (HWND hWnd)
|
||||||
|
{
|
||||||
|
NOTIFYICONDATA nid;
|
||||||
|
nid.hWnd = hWnd;
|
||||||
|
nid.uID = ID_TRAY_ICON;
|
||||||
|
Shell_NotifyIcon (NIM_DELETE, &nid);
|
||||||
|
}
|
||||||
|
|
||||||
|
static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
|
{
|
||||||
|
switch (uMsg)
|
||||||
|
{
|
||||||
|
case WM_CREATE:
|
||||||
|
{
|
||||||
|
AddTrayIcon (hWnd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WM_CLOSE:
|
||||||
|
{
|
||||||
|
RemoveTrayIcon (hWnd);
|
||||||
|
PostQuitMessage (0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
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_TRAYICON:
|
||||||
|
{
|
||||||
|
SetForegroundWindow (hWnd);
|
||||||
|
switch (lParam)
|
||||||
|
{
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
{
|
||||||
|
SetForegroundWindow (hWnd);
|
||||||
|
ShowPopupMenu(hWnd, NULL, -1);
|
||||||
|
PostMessage (hWnd, WM_APP + 1, 0, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DefWindowProc( hWnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool StartWin32App ()
|
||||||
|
{
|
||||||
|
if (FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd")))
|
||||||
|
{
|
||||||
|
MessageBox(NULL, TEXT("I2Pd is running already"), TEXT("Warning"), MB_OK);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// register main window
|
||||||
|
auto hInst = GetModuleHandle(NULL);
|
||||||
|
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 (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("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 false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RunWin32App ()
|
||||||
|
{
|
||||||
|
MSG msg;
|
||||||
|
while (GetMessage (&msg, NULL, 0, 0 ))
|
||||||
|
{
|
||||||
|
TranslateMessage (&msg);
|
||||||
|
DispatchMessage (&msg);
|
||||||
|
}
|
||||||
|
return msg.wParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StopWin32App ()
|
||||||
|
{
|
||||||
|
UnregisterClass (I2PD_WIN32_CLASSNAME, GetModuleHandle(NULL));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
Win32/Win32App.h
Normal file
15
Win32/Win32App.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef WIN32APP_H__
|
||||||
|
#define WIN32APP_H__
|
||||||
|
|
||||||
|
#define I2PD_WIN32_CLASSNAME "i2pd main window"
|
||||||
|
|
||||||
|
namespace i2p
|
||||||
|
{
|
||||||
|
namespace win32
|
||||||
|
{
|
||||||
|
bool StartWin32App ();
|
||||||
|
void StopWin32App ();
|
||||||
|
int RunWin32App ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // WIN32APP_H__
|
||||||
BIN
Win32/ictoopie_16.ico
Normal file
BIN
Win32/ictoopie_16.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
8
i2pd.cpp
8
i2pd.cpp
@@ -1,4 +1,3 @@
|
|||||||
#include <thread>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
|
|
||||||
@@ -6,12 +5,7 @@ int main( int argc, char* argv[] )
|
|||||||
{
|
{
|
||||||
Daemon.init(argc, argv);
|
Daemon.init(argc, argv);
|
||||||
if (Daemon.start())
|
if (Daemon.start())
|
||||||
{
|
Daemon.run ();
|
||||||
while (Daemon.running)
|
|
||||||
{
|
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Daemon.stop();
|
Daemon.stop();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user