mirror of https://github.com/PurpleI2P/i2pd
fix code syle(spaces->tabs, tabulations)
Signed-off-by: R4SAS <r4sas@i2pmail.org>pull/1525/head
parent
9633c247f0
commit
7a5146ea74
@ -1,455 +1,455 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#include "ClientContext.h"
|
#include "ClientContext.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "NetDb.hpp"
|
#include "NetDb.hpp"
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
#include "Transports.h"
|
#include "Transports.h"
|
||||||
#include "Tunnel.h"
|
#include "Tunnel.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "Daemon.h"
|
#include "Daemon.h"
|
||||||
#include "Win32App.h"
|
#include "Win32App.h"
|
||||||
#include "Win32NetState.h"
|
#include "Win32NetState.h"
|
||||||
|
|
||||||
#define ID_ABOUT 2000
|
#define ID_ABOUT 2000
|
||||||
#define ID_EXIT 2001
|
#define ID_EXIT 2001
|
||||||
#define ID_CONSOLE 2002
|
#define ID_CONSOLE 2002
|
||||||
#define ID_APP 2003
|
#define ID_APP 2003
|
||||||
#define ID_GRACEFUL_SHUTDOWN 2004
|
#define ID_GRACEFUL_SHUTDOWN 2004
|
||||||
#define ID_STOP_GRACEFUL_SHUTDOWN 2005
|
#define ID_STOP_GRACEFUL_SHUTDOWN 2005
|
||||||
#define ID_RELOAD 2006
|
#define ID_RELOAD 2006
|
||||||
#define ID_ACCEPT_TRANSIT 2007
|
#define ID_ACCEPT_TRANSIT 2007
|
||||||
#define ID_DECLINE_TRANSIT 2008
|
#define ID_DECLINE_TRANSIT 2008
|
||||||
|
|
||||||
#define ID_TRAY_ICON 2050
|
#define ID_TRAY_ICON 2050
|
||||||
#define WM_TRAYICON (WM_USER + 1)
|
#define WM_TRAYICON (WM_USER + 1)
|
||||||
|
|
||||||
#define IDT_GRACEFUL_SHUTDOWN_TIMER 2100
|
#define IDT_GRACEFUL_SHUTDOWN_TIMER 2100
|
||||||
#define FRAME_UPDATE_TIMER 2101
|
#define FRAME_UPDATE_TIMER 2101
|
||||||
#define IDT_GRACEFUL_TUNNELCHECK_TIMER 2102
|
#define IDT_GRACEFUL_TUNNELCHECK_TIMER 2102
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace win32
|
namespace win32
|
||||||
{
|
{
|
||||||
static DWORD GracefulShutdownEndtime = 0;
|
static DWORD GracefulShutdownEndtime = 0;
|
||||||
|
|
||||||
typedef DWORD (* IPN)();
|
typedef DWORD (* IPN)();
|
||||||
IPN GetTickCountLocal = (IPN)GetProcAddress (GetModuleHandle ("KERNEL32.dll"), "GetTickCount");
|
IPN GetTickCountLocal = (IPN)GetProcAddress (GetModuleHandle ("KERNEL32.dll"), "GetTickCount");
|
||||||
|
|
||||||
static void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem)
|
static void ShowPopupMenu (HWND hWnd, POINT *curpos, int wDefaultItem)
|
||||||
{
|
{
|
||||||
HMENU hPopup = CreatePopupMenu();
|
HMENU hPopup = CreatePopupMenu();
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_CONSOLE, "Open &console");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_CONSOLE, "Open &console");
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_APP, "Show app");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_APP, "Show app");
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_ABOUT, "&About...");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_ABOUT, "&About...");
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
||||||
if(!i2p::context.AcceptsTunnels())
|
if(!i2p::context.AcceptsTunnels())
|
||||||
InsertMenu (hPopup, -1,
|
InsertMenu (hPopup, -1,
|
||||||
i2p::util::DaemonWin32::Instance ().isGraceful ? MF_BYPOSITION | MF_STRING | MF_GRAYED : MF_BYPOSITION | MF_STRING,
|
i2p::util::DaemonWin32::Instance ().isGraceful ? MF_BYPOSITION | MF_STRING | MF_GRAYED : MF_BYPOSITION | MF_STRING,
|
||||||
ID_ACCEPT_TRANSIT, "Accept &transit");
|
ID_ACCEPT_TRANSIT, "Accept &transit");
|
||||||
else
|
else
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_DECLINE_TRANSIT, "Decline &transit");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_DECLINE_TRANSIT, "Decline &transit");
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_RELOAD, "&Reload tunnels config");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_RELOAD, "&Reload tunnels config");
|
||||||
if (!i2p::util::DaemonWin32::Instance ().isGraceful)
|
if (!i2p::util::DaemonWin32::Instance ().isGraceful)
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_GRACEFUL_SHUTDOWN, "&Graceful shutdown");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_GRACEFUL_SHUTDOWN, "&Graceful shutdown");
|
||||||
else
|
else
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_STOP_GRACEFUL_SHUTDOWN, "Stop &graceful shutdown");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_STOP_GRACEFUL_SHUTDOWN, "Stop &graceful shutdown");
|
||||||
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_EXIT, "E&xit");
|
InsertMenu (hPopup, -1, MF_BYPOSITION | MF_STRING, ID_EXIT, "E&xit");
|
||||||
SetMenuDefaultItem (hPopup, ID_CONSOLE, FALSE);
|
SetMenuDefaultItem (hPopup, ID_CONSOLE, FALSE);
|
||||||
SendMessage (hWnd, WM_INITMENUPOPUP, (WPARAM)hPopup, 0);
|
SendMessage (hWnd, WM_INITMENUPOPUP, (WPARAM)hPopup, 0);
|
||||||
|
|
||||||
POINT p;
|
POINT p;
|
||||||
if (!curpos)
|
if (!curpos)
|
||||||
{
|
{
|
||||||
GetCursorPos (&p);
|
GetCursorPos (&p);
|
||||||
curpos = &p;
|
curpos = &p;
|
||||||
}
|
}
|
||||||
|
|
||||||
WORD cmd = TrackPopupMenu (hPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, curpos->x, curpos->y, 0, hWnd, NULL);
|
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);
|
SendMessage (hWnd, WM_COMMAND, cmd, 0);
|
||||||
|
|
||||||
DestroyMenu(hPopup);
|
DestroyMenu(hPopup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddTrayIcon (HWND hWnd)
|
static void AddTrayIcon (HWND hWnd)
|
||||||
{
|
{
|
||||||
NOTIFYICONDATA nid;
|
NOTIFYICONDATA nid;
|
||||||
memset(&nid, 0, sizeof(nid));
|
memset(&nid, 0, sizeof(nid));
|
||||||
nid.cbSize = sizeof(nid);
|
nid.cbSize = sizeof(nid);
|
||||||
nid.hWnd = hWnd;
|
nid.hWnd = hWnd;
|
||||||
nid.uID = ID_TRAY_ICON;
|
nid.uID = ID_TRAY_ICON;
|
||||||
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO;
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP | NIF_INFO;
|
||||||
nid.uCallbackMessage = WM_TRAYICON;
|
nid.uCallbackMessage = WM_TRAYICON;
|
||||||
nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (MAINICON));
|
nid.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE (MAINICON));
|
||||||
strcpy (nid.szTip, "i2pd");
|
strcpy (nid.szTip, "i2pd");
|
||||||
strcpy (nid.szInfo, "i2pd is starting");
|
strcpy (nid.szInfo, "i2pd is starting");
|
||||||
Shell_NotifyIcon(NIM_ADD, &nid );
|
Shell_NotifyIcon(NIM_ADD, &nid );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void RemoveTrayIcon (HWND hWnd)
|
static void RemoveTrayIcon (HWND hWnd)
|
||||||
{
|
{
|
||||||
NOTIFYICONDATA nid;
|
NOTIFYICONDATA nid;
|
||||||
nid.hWnd = hWnd;
|
nid.hWnd = hWnd;
|
||||||
nid.uID = ID_TRAY_ICON;
|
nid.uID = ID_TRAY_ICON;
|
||||||
Shell_NotifyIcon (NIM_DELETE, &nid);
|
Shell_NotifyIcon (NIM_DELETE, &nid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ShowUptime (std::stringstream& s, int seconds)
|
static void ShowUptime (std::stringstream& s, int seconds)
|
||||||
{
|
{
|
||||||
int num;
|
int num;
|
||||||
|
|
||||||
if ((num = seconds / 86400) > 0) {
|
if ((num = seconds / 86400) > 0) {
|
||||||
s << num << " days, ";
|
s << num << " days, ";
|
||||||
seconds -= num * 86400;
|
seconds -= num * 86400;
|
||||||
}
|
}
|
||||||
if ((num = seconds / 3600) > 0) {
|
if ((num = seconds / 3600) > 0) {
|
||||||
s << num << " hours, ";
|
s << num << " hours, ";
|
||||||
seconds -= num * 3600;
|
seconds -= num * 3600;
|
||||||
}
|
}
|
||||||
if ((num = seconds / 60) > 0) {
|
if ((num = seconds / 60) > 0) {
|
||||||
s << num << " min, ";
|
s << num << " min, ";
|
||||||
seconds -= num * 60;
|
seconds -= num * 60;
|
||||||
}
|
}
|
||||||
s << seconds << " seconds\n";
|
s << seconds << " seconds\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename size> static void ShowTransfered (std::stringstream& s, size transfer)
|
template <typename size> static void ShowTransfered (std::stringstream& s, size transfer)
|
||||||
{
|
{
|
||||||
auto bytes = transfer & 0x03ff;
|
auto bytes = transfer & 0x03ff;
|
||||||
transfer >>= 10;
|
transfer >>= 10;
|
||||||
auto kbytes = transfer & 0x03ff;
|
auto kbytes = transfer & 0x03ff;
|
||||||
transfer >>= 10;
|
transfer >>= 10;
|
||||||
auto mbytes = transfer & 0x03ff;
|
auto mbytes = transfer & 0x03ff;
|
||||||
transfer >>= 10;
|
transfer >>= 10;
|
||||||
auto gbytes = transfer & 0x03ff;
|
auto gbytes = transfer & 0x03ff;
|
||||||
|
|
||||||
if (gbytes)
|
if (gbytes)
|
||||||
s << gbytes << " GB, ";
|
s << gbytes << " GB, ";
|
||||||
if (mbytes)
|
if (mbytes)
|
||||||
s << mbytes << " MB, ";
|
s << mbytes << " MB, ";
|
||||||
if (kbytes)
|
if (kbytes)
|
||||||
s << kbytes << " KB, ";
|
s << kbytes << " KB, ";
|
||||||
s << bytes << " Bytes\n";
|
s << bytes << " Bytes\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PrintMainWindowText (std::stringstream& s)
|
static void PrintMainWindowText (std::stringstream& s)
|
||||||
{
|
{
|
||||||
s << "\n";
|
s << "\n";
|
||||||
s << "Status: ";
|
s << "Status: ";
|
||||||
switch (i2p::context.GetStatus())
|
switch (i2p::context.GetStatus())
|
||||||
{
|
{
|
||||||
case eRouterStatusOK: s << "OK"; break;
|
case eRouterStatusOK: s << "OK"; break;
|
||||||
case eRouterStatusTesting: s << "Testing"; break;
|
case eRouterStatusTesting: s << "Testing"; break;
|
||||||
case eRouterStatusFirewalled: s << "Firewalled"; break;
|
case eRouterStatusFirewalled: s << "Firewalled"; break;
|
||||||
case eRouterStatusError:
|
case eRouterStatusError:
|
||||||
{
|
{
|
||||||
switch (i2p::context.GetError())
|
switch (i2p::context.GetError())
|
||||||
{
|
{
|
||||||
case eRouterErrorClockSkew: s << "Clock skew"; break;
|
case eRouterErrorClockSkew: s << "Clock skew"; break;
|
||||||
default: s << "Error";
|
default: s << "Error";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: s << "Unknown";
|
default: s << "Unknown";
|
||||||
}
|
}
|
||||||
s << "; ";
|
s << "; ";
|
||||||
s << "Success Rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate() << "%\n";
|
s << "Success Rate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate() << "%\n";
|
||||||
s << "Uptime: "; ShowUptime(s, i2p::context.GetUptime ());
|
s << "Uptime: "; ShowUptime(s, i2p::context.GetUptime ());
|
||||||
if (GracefulShutdownEndtime != 0)
|
if (GracefulShutdownEndtime != 0)
|
||||||
{
|
{
|
||||||
DWORD GracefulTimeLeft = (GracefulShutdownEndtime - GetTickCountLocal()) / 1000;
|
DWORD GracefulTimeLeft = (GracefulShutdownEndtime - GetTickCountLocal()) / 1000;
|
||||||
s << "Graceful shutdown, time left: "; ShowUptime(s, GracefulTimeLeft);
|
s << "Graceful shutdown, time left: "; ShowUptime(s, GracefulTimeLeft);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
s << "\n";
|
s << "\n";
|
||||||
s << "Inbound: " << i2p::transport::transports.GetInBandwidth() / 1024 << " KiB/s; ";
|
s << "Inbound: " << i2p::transport::transports.GetInBandwidth() / 1024 << " KiB/s; ";
|
||||||
s << "Outbound: " << i2p::transport::transports.GetOutBandwidth() / 1024 << " KiB/s\n";
|
s << "Outbound: " << i2p::transport::transports.GetOutBandwidth() / 1024 << " KiB/s\n";
|
||||||
s << "Received: "; ShowTransfered (s, i2p::transport::transports.GetTotalReceivedBytes());
|
s << "Received: "; ShowTransfered (s, i2p::transport::transports.GetTotalReceivedBytes());
|
||||||
s << "Sent: "; ShowTransfered (s, i2p::transport::transports.GetTotalSentBytes());
|
s << "Sent: "; ShowTransfered (s, i2p::transport::transports.GetTotalSentBytes());
|
||||||
s << "\n";
|
s << "\n";
|
||||||
s << "Routers: " << i2p::data::netdb.GetNumRouters () << "; ";
|
s << "Routers: " << i2p::data::netdb.GetNumRouters () << "; ";
|
||||||
s << "Floodfills: " << i2p::data::netdb.GetNumFloodfills () << "; ";
|
s << "Floodfills: " << i2p::data::netdb.GetNumFloodfills () << "; ";
|
||||||
s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "\n";
|
s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "\n";
|
||||||
s << "Tunnels: ";
|
s << "Tunnels: ";
|
||||||
s << "In: " << i2p::tunnel::tunnels.CountInboundTunnels() << "; ";
|
s << "In: " << i2p::tunnel::tunnels.CountInboundTunnels() << "; ";
|
||||||
s << "Out: " << i2p::tunnel::tunnels.CountOutboundTunnels() << "; ";
|
s << "Out: " << i2p::tunnel::tunnels.CountOutboundTunnels() << "; ";
|
||||||
s << "Transit: " << i2p::tunnel::tunnels.CountTransitTunnels() << "\n";
|
s << "Transit: " << i2p::tunnel::tunnels.CountTransitTunnels() << "\n";
|
||||||
s << "\n";
|
s << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
static LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
static UINT s_uTaskbarRestart;
|
static UINT s_uTaskbarRestart;
|
||||||
|
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
{
|
{
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
{
|
{
|
||||||
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
|
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
|
||||||
AddTrayIcon (hWnd);
|
AddTrayIcon (hWnd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
RemoveTrayIcon (hWnd);
|
RemoveTrayIcon (hWnd);
|
||||||
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
||||||
KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
|
KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
|
||||||
KillTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER);
|
KillTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER);
|
||||||
PostQuitMessage (0);
|
PostQuitMessage (0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
{
|
{
|
||||||
switch (LOWORD(wParam))
|
switch (LOWORD(wParam))
|
||||||
{
|
{
|
||||||
case ID_ABOUT:
|
case ID_ABOUT:
|
||||||
{
|
{
|
||||||
std::stringstream text;
|
std::stringstream text;
|
||||||
text << "Version: " << I2PD_VERSION << " " << CODENAME;
|
text << "Version: " << I2PD_VERSION << " " << CODENAME;
|
||||||
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_EXIT:
|
case ID_EXIT:
|
||||||
{
|
{
|
||||||
PostMessage (hWnd, WM_CLOSE, 0, 0);
|
PostMessage (hWnd, WM_CLOSE, 0, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_ACCEPT_TRANSIT:
|
case ID_ACCEPT_TRANSIT:
|
||||||
{
|
{
|
||||||
i2p::context.SetAcceptsTunnels (true);
|
i2p::context.SetAcceptsTunnels (true);
|
||||||
std::stringstream text;
|
std::stringstream text;
|
||||||
text << "I2Pd now accept transit tunnels";
|
text << "I2Pd now accept transit tunnels";
|
||||||
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_DECLINE_TRANSIT:
|
case ID_DECLINE_TRANSIT:
|
||||||
{
|
{
|
||||||
i2p::context.SetAcceptsTunnels (false);
|
i2p::context.SetAcceptsTunnels (false);
|
||||||
std::stringstream text;
|
std::stringstream text;
|
||||||
text << "I2Pd now decline new transit tunnels";
|
text << "I2Pd now decline new transit tunnels";
|
||||||
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_GRACEFUL_SHUTDOWN:
|
case ID_GRACEFUL_SHUTDOWN:
|
||||||
{
|
{
|
||||||
i2p::context.SetAcceptsTunnels (false);
|
i2p::context.SetAcceptsTunnels (false);
|
||||||
SetTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER, 10*60*1000, nullptr); // 10 minutes
|
SetTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER, 10*60*1000, nullptr); // 10 minutes
|
||||||
SetTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER, 1000, nullptr); // check tunnels every second
|
SetTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER, 1000, nullptr); // check tunnels every second
|
||||||
GracefulShutdownEndtime = GetTickCountLocal() + 10*60*1000;
|
GracefulShutdownEndtime = GetTickCountLocal() + 10*60*1000;
|
||||||
i2p::util::DaemonWin32::Instance ().isGraceful = true;
|
i2p::util::DaemonWin32::Instance ().isGraceful = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_STOP_GRACEFUL_SHUTDOWN:
|
case ID_STOP_GRACEFUL_SHUTDOWN:
|
||||||
{
|
{
|
||||||
i2p::context.SetAcceptsTunnels (true);
|
i2p::context.SetAcceptsTunnels (true);
|
||||||
KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
|
KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
|
||||||
KillTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER);
|
KillTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER);
|
||||||
GracefulShutdownEndtime = 0;
|
GracefulShutdownEndtime = 0;
|
||||||
i2p::util::DaemonWin32::Instance ().isGraceful = false;
|
i2p::util::DaemonWin32::Instance ().isGraceful = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_RELOAD:
|
case ID_RELOAD:
|
||||||
{
|
{
|
||||||
i2p::client::context.ReloadConfig();
|
i2p::client::context.ReloadConfig();
|
||||||
std::stringstream text;
|
std::stringstream text;
|
||||||
text << "I2Pd reloading configs...";
|
text << "I2Pd reloading configs...";
|
||||||
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
MessageBox( hWnd, TEXT(text.str ().c_str ()), TEXT("i2pd"), MB_ICONINFORMATION | MB_OK );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_CONSOLE:
|
case ID_CONSOLE:
|
||||||
{
|
{
|
||||||
char buf[30];
|
char buf[30];
|
||||||
std::string httpAddr; i2p::config::GetOption("http.address", httpAddr);
|
std::string httpAddr; i2p::config::GetOption("http.address", httpAddr);
|
||||||
uint16_t httpPort; i2p::config::GetOption("http.port", httpPort);
|
uint16_t httpPort; i2p::config::GetOption("http.port", httpPort);
|
||||||
snprintf(buf, 30, "http://%s:%d", httpAddr.c_str(), httpPort);
|
snprintf(buf, 30, "http://%s:%d", httpAddr.c_str(), httpPort);
|
||||||
ShellExecute(NULL, "open", buf, NULL, NULL, SW_SHOWNORMAL);
|
ShellExecute(NULL, "open", buf, NULL, NULL, SW_SHOWNORMAL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ID_APP:
|
case ID_APP:
|
||||||
{
|
{
|
||||||
ShowWindow(hWnd, SW_SHOW);
|
ShowWindow(hWnd, SW_SHOW);
|
||||||
SetTimer(hWnd, FRAME_UPDATE_TIMER, 3000, NULL);
|
SetTimer(hWnd, FRAME_UPDATE_TIMER, 3000, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_SYSCOMMAND:
|
case WM_SYSCOMMAND:
|
||||||
{
|
{
|
||||||
switch (wParam)
|
switch (wParam)
|
||||||
{
|
{
|
||||||
case SC_MINIMIZE:
|
case SC_MINIMIZE:
|
||||||
{
|
{
|
||||||
ShowWindow(hWnd, SW_HIDE);
|
ShowWindow(hWnd, SW_HIDE);
|
||||||
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case SC_CLOSE:
|
case SC_CLOSE:
|
||||||
{
|
{
|
||||||
std::string close; i2p::config::GetOption("close", close);
|
std::string close; i2p::config::GetOption("close", close);
|
||||||
if (0 == close.compare("ask"))
|
if (0 == close.compare("ask"))
|
||||||
switch(::MessageBox(hWnd, "Would you like to minimize instead of exiting?"
|
switch(::MessageBox(hWnd, "Would you like to minimize instead of exiting?"
|
||||||
" You can add 'close' configuration option. Valid values are: ask, minimize, exit.",
|
" You can add 'close' configuration option. Valid values are: ask, minimize, exit.",
|
||||||
"Minimize instead of exiting?", MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON1))
|
"Minimize instead of exiting?", MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON1))
|
||||||
{
|
{
|
||||||
case IDYES: close = "minimize"; break;
|
case IDYES: close = "minimize"; break;
|
||||||
case IDNO: close = "exit"; break;
|
case IDNO: close = "exit"; break;
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
if (0 == close.compare("minimize"))
|
if (0 == close.compare("minimize"))
|
||||||
{
|
{
|
||||||
ShowWindow(hWnd, SW_HIDE);
|
ShowWindow(hWnd, SW_HIDE);
|
||||||
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (0 != close.compare("exit"))
|
if (0 != close.compare("exit"))
|
||||||
{
|
{
|
||||||
::MessageBox(hWnd, close.c_str(), "Unknown close action in config", MB_OK | MB_ICONWARNING);
|
::MessageBox(hWnd, close.c_str(), "Unknown close action in config", MB_OK | MB_ICONWARNING);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case WM_TRAYICON:
|
case WM_TRAYICON:
|
||||||
{
|
{
|
||||||
switch (lParam)
|
switch (lParam)
|
||||||
{
|
{
|
||||||
case WM_LBUTTONUP:
|
case WM_LBUTTONUP:
|
||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
{
|
{
|
||||||
SetForegroundWindow (hWnd);
|
SetForegroundWindow (hWnd);
|
||||||
ShowPopupMenu(hWnd, NULL, -1);
|
ShowPopupMenu(hWnd, NULL, -1);
|
||||||
PostMessage (hWnd, WM_APP + 1, 0, 0);
|
PostMessage (hWnd, WM_APP + 1, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_TIMER:
|
case WM_TIMER:
|
||||||
{
|
{
|
||||||
switch(wParam)
|
switch(wParam)
|
||||||
{
|
{
|
||||||
case IDT_GRACEFUL_SHUTDOWN_TIMER:
|
case IDT_GRACEFUL_SHUTDOWN_TIMER:
|
||||||
{
|
{
|
||||||
GracefulShutdownEndtime = 0;
|
GracefulShutdownEndtime = 0;
|
||||||
PostMessage (hWnd, WM_CLOSE, 0, 0); // exit
|
PostMessage (hWnd, WM_CLOSE, 0, 0); // exit
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case IDT_GRACEFUL_TUNNELCHECK_TIMER:
|
case IDT_GRACEFUL_TUNNELCHECK_TIMER:
|
||||||
{
|
{
|
||||||
if (i2p::tunnel::tunnels.CountTransitTunnels() == 0)
|
if (i2p::tunnel::tunnels.CountTransitTunnels() == 0)
|
||||||
PostMessage (hWnd, WM_CLOSE, 0, 0);
|
PostMessage (hWnd, WM_CLOSE, 0, 0);
|
||||||
else
|
else
|
||||||
SetTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER, 1000, nullptr);
|
SetTimer (hWnd, IDT_GRACEFUL_TUNNELCHECK_TIMER, 1000, nullptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case FRAME_UPDATE_TIMER:
|
case FRAME_UPDATE_TIMER:
|
||||||
{
|
{
|
||||||
InvalidateRect(hWnd, NULL, TRUE);
|
InvalidateRect(hWnd, NULL, TRUE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
HDC hDC;
|
HDC hDC;
|
||||||
PAINTSTRUCT ps;
|
PAINTSTRUCT ps;
|
||||||
RECT rp;
|
RECT rp;
|
||||||
HFONT hFont;
|
HFONT hFont;
|
||||||
std::stringstream s; PrintMainWindowText (s);
|
std::stringstream s; PrintMainWindowText (s);
|
||||||
hDC = BeginPaint (hWnd, &ps);
|
hDC = BeginPaint (hWnd, &ps);
|
||||||
GetClientRect(hWnd, &rp);
|
GetClientRect(hWnd, &rp);
|
||||||
SetTextColor(hDC, 0x00D43B69);
|
SetTextColor(hDC, 0x00D43B69);
|
||||||
hFont = CreateFont(18,0,0,0,0,0,0,0,DEFAULT_CHARSET,0,0,0,0,TEXT("Times New Roman"));
|
hFont = CreateFont(18,0,0,0,0,0,0,0,DEFAULT_CHARSET,0,0,0,0,TEXT("Times New Roman"));
|
||||||
SelectObject(hDC,hFont);
|
SelectObject(hDC,hFont);
|
||||||
DrawText(hDC, TEXT(s.str().c_str()), s.str().length(), &rp, DT_CENTER|DT_VCENTER);
|
DrawText(hDC, TEXT(s.str().c_str()), s.str().length(), &rp, DT_CENTER|DT_VCENTER);
|
||||||
DeleteObject(hFont);
|
DeleteObject(hFont);
|
||||||
EndPaint(hWnd, &ps);
|
EndPaint(hWnd, &ps);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if (uMsg == s_uTaskbarRestart)
|
if (uMsg == s_uTaskbarRestart)
|
||||||
AddTrayIcon (hWnd);
|
AddTrayIcon (hWnd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DefWindowProc( hWnd, uMsg, wParam, lParam);
|
return DefWindowProc( hWnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartWin32App ()
|
bool StartWin32App ()
|
||||||
{
|
{
|
||||||
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 false;
|
return false;
|
||||||
}
|
}
|
||||||
// register main window
|
// register main window
|
||||||
auto hInst = GetModuleHandle(NULL);
|
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);
|
||||||
wclx.style = 0;
|
wclx.style = 0;
|
||||||
wclx.lpfnWndProc = WndProc;
|
wclx.lpfnWndProc = WndProc;
|
||||||
//wclx.cbClsExtra = 0;
|
//wclx.cbClsExtra = 0;
|
||||||
//wclx.cbWndExtra = 0;
|
//wclx.cbWndExtra = 0;
|
||||||
wclx.hInstance = hInst;
|
wclx.hInstance = hInst;
|
||||||
wclx.hIcon = LoadIcon (hInst, MAKEINTRESOURCE(MAINICON));
|
wclx.hIcon = LoadIcon (hInst, MAKEINTRESOURCE(MAINICON));
|
||||||
wclx.hCursor = LoadCursor (NULL, IDC_ARROW);
|
wclx.hCursor = LoadCursor (NULL, IDC_ARROW);
|
||||||
//wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
//wclx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
|
||||||
wclx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
wclx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||||
wclx.lpszMenuName = NULL;
|
wclx.lpszMenuName = NULL;
|
||||||
wclx.lpszClassName = I2PD_WIN32_CLASSNAME;
|
wclx.lpszClassName = I2PD_WIN32_CLASSNAME;
|
||||||
RegisterClassEx (&wclx);
|
RegisterClassEx (&wclx);
|
||||||
// create new window
|
// create new window
|
||||||
if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 100, 100, 350, 210, NULL, NULL, hInst, NULL))
|
if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 100, 100, 350, 210, 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 false;
|
return false;
|
||||||
}
|
}
|
||||||
SubscribeToEvents();
|
SubscribeToEvents();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RunWin32App ()
|
int RunWin32App ()
|
||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (GetMessage (&msg, NULL, 0, 0 ))
|
while (GetMessage (&msg, NULL, 0, 0 ))
|
||||||
{
|
{
|
||||||
TranslateMessage (&msg);
|
TranslateMessage (&msg);
|
||||||
DispatchMessage (&msg);
|
DispatchMessage (&msg);
|
||||||
}
|
}
|
||||||
return msg.wParam;
|
return msg.wParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopWin32App ()
|
void StopWin32App ()
|
||||||
{
|
{
|
||||||
HWND hWnd = FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"));
|
HWND hWnd = FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"));
|
||||||
if (hWnd)
|
if (hWnd)
|
||||||
PostMessage (hWnd, WM_COMMAND, MAKEWPARAM(ID_EXIT, 0), 0);
|
PostMessage (hWnd, WM_COMMAND, MAKEWPARAM(ID_EXIT, 0), 0);
|
||||||
// UnSubscribeFromEvents(); // TODO: understand why unsubscribing crashes app
|
// UnSubscribeFromEvents(); // TODO: understand why unsubscribing crashes app
|
||||||
UnregisterClass (I2PD_WIN32_CLASSNAME, GetModuleHandle(NULL));
|
UnregisterClass (I2PD_WIN32_CLASSNAME, GetModuleHandle(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GracefulShutdown ()
|
bool GracefulShutdown ()
|
||||||
{
|
{
|
||||||
HWND hWnd = FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"));
|
HWND hWnd = FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"));
|
||||||
if (hWnd)
|
if (hWnd)
|
||||||
PostMessage (hWnd, WM_COMMAND, MAKEWPARAM(ID_GRACEFUL_SHUTDOWN, 0), 0);
|
PostMessage (hWnd, WM_COMMAND, MAKEWPARAM(ID_GRACEFUL_SHUTDOWN, 0), 0);
|
||||||
return hWnd;
|
return hWnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StopGracefulShutdown ()
|
bool StopGracefulShutdown ()
|
||||||
{
|
{
|
||||||
HWND hWnd = FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"));
|
HWND hWnd = FindWindow (I2PD_WIN32_CLASSNAME, TEXT("i2pd"));
|
||||||
if (hWnd)
|
if (hWnd)
|
||||||
PostMessage (hWnd, WM_COMMAND, MAKEWPARAM(ID_STOP_GRACEFUL_SHUTDOWN, 0), 0);
|
PostMessage (hWnd, WM_COMMAND, MAKEWPARAM(ID_STOP_GRACEFUL_SHUTDOWN, 0), 0);
|
||||||
return hWnd;
|
return hWnd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
#ifndef WIN32APP_H__
|
#ifndef WIN32APP_H__
|
||||||
#define WIN32APP_H__
|
#define WIN32APP_H__
|
||||||
|
|
||||||
#define I2PD_WIN32_CLASSNAME "i2pd main window"
|
#define I2PD_WIN32_CLASSNAME "i2pd main window"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace win32
|
namespace win32
|
||||||
{
|
{
|
||||||
bool StartWin32App ();
|
bool StartWin32App ();
|
||||||
void StopWin32App ();
|
void StopWin32App ();
|
||||||
int RunWin32App ();
|
int RunWin32App ();
|
||||||
bool GracefulShutdown ();
|
bool GracefulShutdown ();
|
||||||
bool StopGracefulShutdown ();
|
bool StopGracefulShutdown ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // WIN32APP_H__
|
#endif // WIN32APP_H__
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
//{{NO_DEPENDENCIES}}
|
//{{NO_DEPENDENCIES}}
|
||||||
#define MAINICON 101
|
#define MAINICON 101
|
||||||
|
|
||||||
#ifdef APSTUDIO_INVOKED
|
#ifdef APSTUDIO_INVOKED
|
||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||||
#define _APS_NEXT_SYMED_VALUE 101
|
#define _APS_NEXT_SYMED_VALUE 101
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue