mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
Added status output to main window
This commit is contained in:
parent
051e642c0c
commit
277d4d9333
|
@ -1,8 +1,12 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
|
#include "../ClientContext.h"
|
||||||
#include "../Config.h"
|
#include "../Config.h"
|
||||||
|
#include "../NetDb.h"
|
||||||
#include "../RouterContext.h"
|
#include "../RouterContext.h"
|
||||||
|
#include "../Transports.h"
|
||||||
|
#include "../Tunnel.h"
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "Win32App.h"
|
#include "Win32App.h"
|
||||||
|
@ -22,6 +26,7 @@
|
||||||
#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
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
|
@ -75,6 +80,43 @@ namespace win32
|
||||||
Shell_NotifyIcon (NIM_DELETE, &nid);
|
Shell_NotifyIcon (NIM_DELETE, &nid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrintMainWindowText (std::stringstream& s)
|
||||||
|
{
|
||||||
|
s << "NetStatus: ";
|
||||||
|
switch (i2p::context.GetStatus())
|
||||||
|
{
|
||||||
|
case eRouterStatusOK: s << "OK"; break;
|
||||||
|
case eRouterStatusTesting: s << "Testing"; break;
|
||||||
|
case eRouterStatusFirewalled: s << "Firewalled"; break;
|
||||||
|
case eRouterStatusError:
|
||||||
|
{
|
||||||
|
switch (i2p::context.GetError())
|
||||||
|
{
|
||||||
|
case eRouterErrorClockSkew: s << "Clock skew"; break;
|
||||||
|
default: s << "Error";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: s << "Unknown";
|
||||||
|
}
|
||||||
|
s << "; ";
|
||||||
|
s << "SuccRate: " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate() << "%\n";
|
||||||
|
s << "Uptime: " << i2p::context.GetUptime() << " seconds\n";
|
||||||
|
s << "\n";
|
||||||
|
s << "InBand: " << i2p::transport::transports.GetInBandwidth() << " Bytes/s; ";
|
||||||
|
s << "OutBand: " << i2p::transport::transports.GetOutBandwidth() << " Bytes/s\n";
|
||||||
|
s << "Recv: " << i2p::transport::transports.GetTotalReceivedBytes() << " Bytes; ";
|
||||||
|
s << "Sent: " << i2p::transport::transports.GetTotalSentBytes() << " Bytes\n";
|
||||||
|
s << "\n";
|
||||||
|
s << "Routers: " << i2p::data::netdb.GetNumRouters () << "; ";
|
||||||
|
s << "Floodfills: " << i2p::data::netdb.GetNumFloodfills () << "; ";
|
||||||
|
s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "\n";
|
||||||
|
s << "Tunnels: ";
|
||||||
|
s << "In: " << i2p::tunnel::tunnels.CountInboundTunnels() << "; ";
|
||||||
|
s << "Out: " << i2p::tunnel::tunnels.CountOutboundTunnels() << "; ";
|
||||||
|
s << "Transit: " << i2p::tunnel::tunnels.CountTransitTunnels() << "\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)
|
||||||
{
|
{
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
|
@ -87,6 +129,7 @@ namespace win32
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
{
|
{
|
||||||
RemoveTrayIcon (hWnd);
|
RemoveTrayIcon (hWnd);
|
||||||
|
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
||||||
KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
|
KillTimer (hWnd, IDT_GRACEFUL_SHUTDOWN_TIMER);
|
||||||
PostQuitMessage (0);
|
PostQuitMessage (0);
|
||||||
break;
|
break;
|
||||||
|
@ -125,6 +168,7 @@ namespace win32
|
||||||
case ID_APP:
|
case ID_APP:
|
||||||
{
|
{
|
||||||
ShowWindow(hWnd, SW_SHOW);
|
ShowWindow(hWnd, SW_SHOW);
|
||||||
|
SetTimer(hWnd, FRAME_UPDATE_TIMER, 3000, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,6 +181,7 @@ namespace win32
|
||||||
case SC_MINIMIZE:
|
case SC_MINIMIZE:
|
||||||
{
|
{
|
||||||
ShowWindow(hWnd, SW_HIDE);
|
ShowWindow(hWnd, SW_HIDE);
|
||||||
|
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case SC_CLOSE:
|
case SC_CLOSE:
|
||||||
|
@ -154,6 +199,7 @@ namespace win32
|
||||||
if (0 == close.compare("minimize"))
|
if (0 == close.compare("minimize"))
|
||||||
{
|
{
|
||||||
ShowWindow(hWnd, SW_HIDE);
|
ShowWindow(hWnd, SW_HIDE);
|
||||||
|
KillTimer (hWnd, FRAME_UPDATE_TIMER);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (0 != close.compare("exit"))
|
if (0 != close.compare("exit"))
|
||||||
|
@ -186,6 +232,26 @@ namespace win32
|
||||||
PostMessage (hWnd, WM_CLOSE, 0, 0); // exit
|
PostMessage (hWnd, WM_CLOSE, 0, 0); // exit
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (wParam == FRAME_UPDATE_TIMER)
|
||||||
|
{
|
||||||
|
InvalidateRect(hWnd, NULL, TRUE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WM_PAINT:
|
||||||
|
{
|
||||||
|
HDC hDC;
|
||||||
|
PAINTSTRUCT ps;
|
||||||
|
RECT rp;
|
||||||
|
HFONT hFont;
|
||||||
|
std::stringstream s; PrintMainWindowText (s);
|
||||||
|
hDC = BeginPaint (hWnd, &ps);
|
||||||
|
GetClientRect(hWnd, &rp);
|
||||||
|
SetTextColor(hDC, 0x00D43B69);
|
||||||
|
hFont = CreateFont(18,0,0,0,0,0,0,0,DEFAULT_CHARSET,0,0,0,0,TEXT("Times New Roman"));
|
||||||
|
SelectObject(hDC,hFont);
|
||||||
|
DrawText(hDC, TEXT(s.str().c_str()), s.str().length(), &rp, DT_CENTER|DT_VCENTER);
|
||||||
|
EndPaint(hWnd, &ps);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,7 +282,7 @@ namespace win32
|
||||||
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_OVERLAPPEDWINDOW, 100, 100, 549, 738, NULL, NULL, hInst, NULL))
|
if (!CreateWindow(I2PD_WIN32_CLASSNAME, TEXT("i2pd"), WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 100, 100, 400, 180, 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;
|
||||||
|
|
Loading…
Reference in a new issue