diff options
author | George Hazan <george.hazan@gmail.com> | 2015-06-25 14:04:38 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-06-25 14:04:38 +0000 |
commit | 8501b9e4faa15257535e71b766f06f16b7971e39 (patch) | |
tree | c15a6c2ab1417b322cfb758c8a7d39477f0cd754 /plugins/TrafficCounter | |
parent | 362a084bb51caf3da238020637a478499781eea4 (diff) |
- warning fix
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@14381 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/TrafficCounter')
-rw-r--r-- | plugins/TrafficCounter/src/TrafficCounter.cpp | 843 | ||||
-rw-r--r-- | plugins/TrafficCounter/src/misc.cpp | 154 | ||||
-rw-r--r-- | plugins/TrafficCounter/src/misc.h | 2 | ||||
-rw-r--r-- | plugins/TrafficCounter/src/statistics.cpp | 812 |
4 files changed, 833 insertions, 978 deletions
diff --git a/plugins/TrafficCounter/src/TrafficCounter.cpp b/plugins/TrafficCounter/src/TrafficCounter.cpp index e464d888c2..03c63386d2 100644 --- a/plugins/TrafficCounter/src/TrafficCounter.cpp +++ b/plugins/TrafficCounter/src/TrafficCounter.cpp @@ -33,6 +33,13 @@ HINSTANCE hInst; int hLangpack = 0; // Поддержка плагинозависимого перевода.
BOOL bPopupExists = FALSE, bVariablesExists = FALSE, bTooltipExists = FALSE;
+static TCHAR tszFormat[] =
+_T("{I4}\x0D\x0A\x0A\
+{R65}?tc_GetTraffic(%extratext%,now,sent,d)\x0D\x0A\x0A\
+{R115}?tc_GetTraffic(%extratext%,now,received,d)\x0D\x0A\x0A\
+{R165}?tc_GetTraffic(%extratext%,total,both,d)\x0D\x0A\x0A\
+{L180}?if3(?tc_GetTime(%extratext%,now,hh:mm:ss),)\x0D\x0A\x0A\
+{L230}?if3(?tc_GetTime(%extratext%,total,d hh:mm),)");
TCHAR* TRAFFIC_COUNTER_WINDOW_CLASS = _T("TrafficCounterWnd");
@@ -123,15 +130,15 @@ extern "C" int __declspec(dllexport) Load(void) {
// Получаем дескриптор языкового пакета.
mir_getLP(&pluginInfoEx);
-
- HookEvent(ME_OPT_INITIALISE,TrafficCounterOptInitialise);
- HookEvent(ME_SYSTEM_MODULESLOADED,TrafficCounterModulesLoaded);
- HookEvent(ME_PROTO_ACK,ProtocolAckHook);
+
+ HookEvent(ME_OPT_INITIALISE, TrafficCounterOptInitialise);
+ HookEvent(ME_SYSTEM_MODULESLOADED, TrafficCounterModulesLoaded);
+ HookEvent(ME_PROTO_ACK, ProtocolAckHook);
HookEvent(ME_PROTO_ACCLISTCHANGED, OnAccountsListChange);
HookEvent(ME_SYSTEM_PRESHUTDOWN, TrafficCounterShutdown);
HookEvent(ME_SYSTEM_MODULELOAD, ModuleLoad);
HookEvent(ME_SYSTEM_MODULEUNLOAD, ModuleLoad);
-
+
return 0;
}
@@ -156,14 +163,12 @@ int TrafficCounterShutdown(WPARAM wParam, LPARAM lParam) SaveSettings(0);
// Удаляем пункт главного меню.
- if (hTrafficMainMenuItem)
- {
+ if (hTrafficMainMenuItem) {
Menu_RemoveItem(hTrafficMainMenuItem);
hTrafficMainMenuItem = NULL;
}
// Удаляем контекстное меню.
- if (TrafficPopupMenu)
- {
+ if (TrafficPopupMenu) {
DestroyMenu(TrafficPopupMenu);
TrafficPopupMenu = NULL;
}
@@ -171,8 +176,7 @@ int TrafficCounterShutdown(WPARAM wParam, LPARAM lParam) CallService(MS_SKINENG_REGISTERPAINTSUB, (WPARAM)TrafficHwnd, (LPARAM)NULL);
// Удаляем фрейм.
- if( (ServiceExists(MS_CLIST_FRAMES_REMOVEFRAME)) && Traffic_FrameID )
- {
+ if ((ServiceExists(MS_CLIST_FRAMES_REMOVEFRAME)) && Traffic_FrameID) {
CallService(MS_CLIST_FRAMES_REMOVEFRAME, (WPARAM)Traffic_FrameID, 0);
Traffic_FrameID = NULL;
}
@@ -198,40 +202,31 @@ int TrafficCounterModulesLoaded(WPARAM wParam, LPARAM lParam) unOptions.Flags = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_WHAT_DRAW, 0x0882);
Stat_SelAcc = db_get_w(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_STAT_ACC_OPT, 0x01);
- //settings for notification
- Traffic_PopupBkColor = db_get_dw(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_BKCOLOR,RGB(200,255,200));
- Traffic_PopupFontColor = db_get_dw(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_FONTCOLOR,RGB(0,0,0));
- //
- Traffic_Notify_time_value = db_get_b(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_NOTIFY_TIME_VALUE,10);
- //
- Traffic_Notify_size_value = db_get_w(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_NOTIFY_SIZE_VALUE,100);
- //
- //popup timeout
- Traffic_PopupTimeoutDefault = db_get_b(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_TIMEOUT_DEFAULT,1);
- Traffic_PopupTimeoutValue = db_get_b(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_TIMEOUT_VALUE,5);
-
+ // settings for notification
+ Traffic_PopupBkColor = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_BKCOLOR, RGB(200, 255, 200));
+ Traffic_PopupFontColor = db_get_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_FONTCOLOR, RGB(0, 0, 0));
+ Traffic_Notify_time_value = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_TIME_VALUE, 10);
+ Traffic_Notify_size_value = db_get_w(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_SIZE_VALUE, 100);
+
+ // popup timeout
+ Traffic_PopupTimeoutDefault = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_DEFAULT, 1);
+ Traffic_PopupTimeoutValue = db_get_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_VALUE, 5);
+
// Формат счётчика для каждого активного протокола
- if (db_get_ts(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_COUNTER_FORMAT, &dbv) == 0)
- {
- if(mir_tstrlen(dbv.ptszVal) > 0)
+ if (db_get_ts(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_COUNTER_FORMAT, &dbv) == 0) {
+ if (mir_tstrlen(dbv.ptszVal) > 0)
mir_tstrncpy(Traffic_CounterFormat, dbv.ptszVal, _countof(Traffic_CounterFormat));
//
db_free(&dbv);
}
else //defaults here
{
- mir_tstrcpy(Traffic_CounterFormat, _T("{I4}\x0D\x0A\x0A\
-{R65}?tc_GetTraffic(%extratext%,now,sent,d)\x0D\x0A\x0A\
-{R115}?tc_GetTraffic(%extratext%,now,received,d)\x0D\x0A\x0A\
-{R165}?tc_GetTraffic(%extratext%,total,both,d)\x0D\x0A\x0A\
-{L180}?if3(?tc_GetTime(%extratext%,now,hh:mm:ss),)\x0D\x0A\x0A\
-{L230}?if3(?tc_GetTime(%extratext%,total,d hh:mm),)"));
+ mir_tstrcpy(Traffic_CounterFormat, tszFormat);
}
// Формат всплывающих подсказок
- if (db_get_ts(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_TOOLTIP_FORMAT, &dbv) == 0)
- {
- if(mir_tstrlen(dbv.ptszVal) > 0)
+ if (db_get_ts(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_TOOLTIP_FORMAT, &dbv) == 0) {
+ if (mir_tstrlen(dbv.ptszVal) > 0)
mir_tstrncpy(Traffic_TooltipFormat, dbv.ptszVal, _countof(Traffic_TooltipFormat));
//
db_free(&dbv);
@@ -278,25 +273,24 @@ int TrafficCounterModulesLoaded(WPARAM wParam, LPARAM lParam) CreateServiceFunction("TrafficCounter/ShowHide", MenuCommand_TrafficShowHide);
// Регистрируем горячую клавишу для показа/скрытия фрейма
{
- HOTKEYDESC hkd = {0};
+ HOTKEYDESC hkd = { 0 };
hkd.cbSize = sizeof(hkd);
- hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT,'T');
+ hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL | HOTKEYF_SHIFT, 'T');
hkd.pszSection = "Traffic Counter";
hkd.pszDescription = LPGEN("Show/Hide frame");
hkd.pszName = "TC_Show_Hide";
hkd.pszService = "TrafficCounter/ShowHide";
Hotkey_Register(&hkd);
}
-
+
// Добавляем пункт в главное меню.
if (unOptions.ShowMainMenuItem)
Traffic_AddMainMenuItem();
// Создаём контекстное меню.
- if (TrafficPopupMenu = CreatePopupMenu())
- {
- AppendMenu(TrafficPopupMenu,MF_STRING,POPUPMENU_HIDE,TranslateT("Hide traffic window"));
- AppendMenu(TrafficPopupMenu,MF_STRING,POPUPMENU_CLEAR_NOW,TranslateT("Clear the current (Now:) value"));
+ if (TrafficPopupMenu = CreatePopupMenu()) {
+ AppendMenu(TrafficPopupMenu, MF_STRING, POPUPMENU_HIDE, TranslateT("Hide traffic window"));
+ AppendMenu(TrafficPopupMenu, MF_STRING, POPUPMENU_CLEAR_NOW, TranslateT("Clear the current (Now:) value"));
}
// Регистрируем обработчики событий Netlib
@@ -319,23 +313,22 @@ void SaveSettings(BYTE OnlyCnt) if (OnlyCnt) return;
// Для каждого протокола сохраняем флаги
- for (i = 0; i < NumberOfAccounts; i++)
- {
+ for (i = 0; i < NumberOfAccounts; i++) {
if (!ProtoList[i].name) continue;
db_set_b(NULL, ProtoList[i].name, SETTINGS_PROTO_FLAGS, ProtoList[i].Flags);
}
//settings for notification
- db_set_dw(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_BKCOLOR,Traffic_PopupBkColor);
- db_set_dw(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_FONTCOLOR,Traffic_PopupFontColor);
+ db_set_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_BKCOLOR, Traffic_PopupBkColor);
+ db_set_dw(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_FONTCOLOR, Traffic_PopupFontColor);
//
- db_set_b(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_NOTIFY_TIME_VALUE,Traffic_Notify_time_value);
+ db_set_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_TIME_VALUE, Traffic_Notify_time_value);
//
- db_set_w(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_NOTIFY_SIZE_VALUE,Traffic_Notify_size_value);
+ db_set_w(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_NOTIFY_SIZE_VALUE, Traffic_Notify_size_value);
//
//popup timeout
- db_set_b(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_TIMEOUT_DEFAULT,Traffic_PopupTimeoutDefault);
- db_set_b(NULL,TRAFFIC_SETTINGS_GROUP,SETTINGS_POPUP_TIMEOUT_VALUE,Traffic_PopupTimeoutValue);
+ db_set_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_DEFAULT, Traffic_PopupTimeoutDefault);
+ db_set_b(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_POPUP_TIMEOUT_VALUE, Traffic_PopupTimeoutValue);
//
// Формат счётчиков
db_set_ts(NULL, TRAFFIC_SETTINGS_GROUP, SETTINGS_COUNTER_FORMAT, Traffic_CounterFormat);
@@ -349,63 +342,63 @@ void SaveSettings(BYTE OnlyCnt) }
/*--------------------------------------------------------------------------------------------*/
-int TrafficRecv(WPARAM wParam,LPARAM lParam)
-{
+int TrafficRecv(WPARAM wParam, LPARAM lParam)
+{
NETLIBNOTIFY *nln = (NETLIBNOTIFY*)wParam;
NETLIBUSER *nlu = (NETLIBUSER*)lParam;
int i;
-
+
if (nln->result > 0)
for (i = 0; i < NumberOfAccounts; i++)
- if (!mir_strcmp(ProtoList[i].name, nlu->szSettingsModule))
- InterlockedExchangeAdd(&ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords-1].Incoming, nln->result);
+ if (!mir_strcmp(ProtoList[i].name, nlu->szSettingsModule))
+ InterlockedExchangeAdd(&ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords - 1].Incoming, nln->result);
return 0;
}
-int TrafficSend(WPARAM wParam,LPARAM lParam)
-{
+int TrafficSend(WPARAM wParam, LPARAM lParam)
+{
NETLIBNOTIFY *nln = (NETLIBNOTIFY*)wParam;
NETLIBUSER *nlu = (NETLIBUSER*)lParam;
int i;
-
+
if (nln->result > 0)
for (i = 0; i < NumberOfAccounts; i++)
if (!mir_strcmp(ProtoList[i].name, nlu->szSettingsModule))
- InterlockedExchangeAdd(&ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords-1].Outgoing, nln->result);
+ InterlockedExchangeAdd(&ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords - 1].Outgoing, nln->result);
return 0;
}
int TrafficCounter_PaintCallbackProc(HWND hWnd, HDC hDC, RECT * rcPaint, HRGN rgn, DWORD dFlags, void * CallBackData)
{
- return TrafficCounter_Draw(hWnd,hDC);
+ return TrafficCounter_Draw(hWnd, hDC);
}
int TrafficCounter_Draw(HWND hwnd, HDC hDC)
{
- if (hwnd==(HWND)-1) return 0;
- if (GetParent(hwnd) == (HWND)CallService(MS_CLUI_GETHWND, 0, 0))
- return PaintTrafficCounterWindow(hwnd, hDC);
- else
- InvalidateRect(hwnd,NULL,FALSE);
- return 0;
+ if (hwnd == (HWND)-1) return 0;
+ if (GetParent(hwnd) == (HWND)CallService(MS_CLUI_GETHWND, 0, 0))
+ return PaintTrafficCounterWindow(hwnd, hDC);
+ else
+ InvalidateRect(hwnd, NULL, FALSE);
+ return 0;
}
static void TC_AlphaText(HDC hDC, LPCTSTR lpString, RECT* lpRect, UINT format, BYTE ClistModernPresent)
{
- int nCount = (int)mir_tstrlen( lpString );
+ int nCount = (int)mir_tstrlen(lpString);
if (ClistModernPresent)
AlphaText(hDC, lpString, nCount, lpRect, format, Traffic_FontColor);
- else
- DrawText( hDC, lpString, nCount, lpRect, format );
+ else
+ DrawText(hDC, lpString, nCount, lpRect, format);
}
-static void TC_DrawIconEx( HDC hdc,int xLeft,int yTop,HICON hIcon, HBRUSH hbrFlickerFreeDraw, BYTE ClistModernPresent)
+static void TC_DrawIconEx(HDC hdc, int xLeft, int yTop, HICON hIcon, HBRUSH hbrFlickerFreeDraw, BYTE ClistModernPresent)
{
if (ClistModernPresent)
- mod_DrawIconEx_helper( hdc, xLeft, yTop, hIcon, 16, 16, 0, hbrFlickerFreeDraw, DI_NORMAL );
- else
- DrawIconEx( hdc, xLeft, yTop, hIcon, 16, 16, 0, hbrFlickerFreeDraw, DI_NORMAL );
+ mod_DrawIconEx_helper(hdc, xLeft, yTop, hIcon, 16, 16, 0, hbrFlickerFreeDraw, DI_NORMAL);
+ else
+ DrawIconEx(hdc, xLeft, yTop, hIcon, 16, 16, 0, hbrFlickerFreeDraw, DI_NORMAL);
}
int PaintTrafficCounterWindow(HWND hwnd, HDC hDC)
@@ -416,15 +409,15 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) HBRUSH b, t;
HDC hdc;
HBITMAP hbmp, oldbmp;
- BITMAPINFO RGB32BitsBITMAPINFO = {0};
- BLENDFUNCTION aga = {AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA};
+ BITMAPINFO RGB32BitsBITMAPINFO = { 0 };
+ BLENDFUNCTION aga = { AC_SRC_OVER, 0, 0xFF, AC_SRC_ALPHA };
DWORD SummarySession, SummaryTotal;
BYTE ClistModernPresent = (GetModuleHandleA("clist_modern.dll") || GetModuleHandleA("clist_modern_dora.dll"))
- && !db_get_b(NULL, "ModernData", "DisableEngine", 0)
- && db_get_b(NULL, "ModernData", "EnableLayering", 1);
+ && !db_get_b(NULL, "ModernData", "DisableEngine", 0)
+ && db_get_b(NULL, "ModernData", "EnableLayering", 1);
- GetClientRect (hwnd, &rect);
+ GetClientRect(hwnd, &rect);
height = rect.bottom - rect.top;
width = rect.right - rect.left;
@@ -437,8 +430,8 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;
RGB32BitsBITMAPINFO.bmiHeader.biCompression = BI_RGB;
- hbmp = CreateDIBSection(NULL,
- &RGB32BitsBITMAPINFO,
+ hbmp = CreateDIBSection(NULL,
+ &RGB32BitsBITMAPINFO,
DIB_RGB_COLORS,
NULL,
NULL, 0);
@@ -446,24 +439,21 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) b = CreateSolidBrush(Traffic_BkColor);
t = CreateSolidBrush(KeyColor);
-
- if ( ClistModernPresent
- && unOptions.DrawFrmAsSkin)
- {
+
+ if (ClistModernPresent
+ && unOptions.DrawFrmAsSkin) {
SKINDRAWREQUEST rq;
rq.hDC = hdc;
rq.rcDestRect = rect;
- rq.rcClipRect = rect;
+ rq.rcClipRect = rect;
strncpy(rq.szObjectID, "Main,ID=EventArea", sizeof(rq.szObjectID));
- if (CallService(MS_SKIN_DRAWGLYPH, (WPARAM)&rq, 0))
- {
+ if (CallService(MS_SKIN_DRAWGLYPH, (WPARAM)&rq, 0)) {
strncpy(rq.szObjectID, "Main,ID=StatusBar", sizeof(rq.szObjectID));
CallService(MS_SKIN_DRAWGLYPH, (WPARAM)&rq, 0);
}
}
- else
- {
+ else {
SetTextColor(hdc, Traffic_FontColor);
SetBkColor(hdc, Traffic_BkColor);
FillRect(hdc, &rect, b);
@@ -478,45 +468,38 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) rect.bottom -= 2;
rect.right -= 3;
-//-------------------
-// Если нет плагина Variables, рисуем упрощённо.
-//-------------------
- if (!bVariablesExists)
- {
+ //-------------------
+ // Если нет плагина Variables, рисуем упрощённо.
+ //-------------------
+ if (!bVariablesExists) {
SummarySession = SummaryTotal = 0;
// Для каждого аккаунта
- for (i = 0; i < NumberOfAccounts; i++)
- {
+ for (i = 0; i < NumberOfAccounts; i++) {
// Только если разрешено его отображение.
- if (ProtoList[i].Visible && ProtoList[i].Enabled)
- {
+ if (ProtoList[i].Visible && ProtoList[i].Enabled) {
dx = 0;
// Изображаем иконку аккаунта.
- if (unOptions.DrawProtoIcon)
- {
+ if (unOptions.DrawProtoIcon) {
TC_DrawIconEx(hdc, rect.left, rect.top,
- Skin_LoadProtoIcon(ProtoList[i].name, CallProtoService(ProtoList[i].name,PS_GETSTATUS,0,0)), b, ClistModernPresent);
+ Skin_LoadProtoIcon(ProtoList[i].name, CallProtoService(ProtoList[i].name, PS_GETSTATUS, 0, 0)), b, ClistModernPresent);
dx = 19;
}
// Изображаем имя аккаунта
- if (unOptions.DrawProtoName)
- {
+ if (unOptions.DrawProtoName) {
rect.left += dx;
TC_AlphaText(hdc, ProtoList[i].tszAccountName, &rect, DT_SINGLELINE | DT_LEFT | DT_TOP, ClistModernPresent);
rect.left -= dx;
}
// Следующие позиции строятся от правого края.
// Общее время.
- if (unOptions.DrawTotalTimeCounter)
- {
+ if (unOptions.DrawTotalTimeCounter) {
TCHAR bu[32];
-
+
GetDurationFormatM(ProtoList[i].Total.Timer, _T("h:mm:ss"), bu, 32);
TC_AlphaText(hdc, bu, &rect, DT_SINGLELINE | DT_RIGHT | DT_TOP, ClistModernPresent);
}
// Текущее время.
- if (unOptions.DrawCurrentTimeCounter)
- {
+ if (unOptions.DrawCurrentTimeCounter) {
TCHAR bu[32];
GetDurationFormatM(ProtoList[i].Session.Timer, _T("h:mm:ss"), bu, 32);
@@ -525,8 +508,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) rect.right += 50;
}
// Изображаем общий трафик.
- if (unOptions.DrawTotalTraffic)
- {
+ if (unOptions.DrawTotalTraffic) {
TCHAR bu[32];
GetFormattedTraffic(ProtoList[i].TotalSentTraffic + ProtoList[i].TotalRecvTraffic, 3, bu, 32);
@@ -538,8 +520,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) SummaryTotal += ProtoList[i].TotalRecvTraffic + ProtoList[i].TotalSentTraffic;
}
// Изображаем текущий трафик.
- if (unOptions.DrawCurrentTraffic)
- {
+ if (unOptions.DrawCurrentTraffic) {
TCHAR bu[32];
GetFormattedTraffic(ProtoList[i].CurrentRecvTraffic + ProtoList[i].CurrentSentTraffic, 3, bu, 32);
@@ -555,20 +536,17 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) }
}
// Рисуем суммарный трафик выбранных аккаунтов.
- if (unOptions.ShowSummary)
- {
+ if (unOptions.ShowSummary) {
// Изображаем иконку.
dx = 0;
- if (unOptions.DrawProtoIcon)
- {
+ if (unOptions.DrawProtoIcon) {
TC_DrawIconEx(hdc, rect.left, rect.top,
Skin_LoadIcon(SKINICON_OTHER_MIRANDA), b, ClistModernPresent);
dx = 19;
}
// Выводим текст
// Изображаем имя
- if (unOptions.DrawProtoName)
- {
+ if (unOptions.DrawProtoName) {
TCHAR *bu = mir_a2t("Summary");
rect.left += dx;
@@ -577,16 +555,14 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) mir_free(bu);
}
// Общее время.
- if (unOptions.DrawTotalTimeCounter)
- {
+ if (unOptions.DrawTotalTimeCounter) {
TCHAR bu[32];
-
+
GetDurationFormatM(OverallInfo.Total.Timer, _T("h:mm:ss"), bu, 32);
TC_AlphaText(hdc, bu, &rect, DT_SINGLELINE | DT_RIGHT | DT_TOP, ClistModernPresent);
}
// Текущее время.
- if (unOptions.DrawCurrentTimeCounter)
- {
+ if (unOptions.DrawCurrentTimeCounter) {
TCHAR bu[32];
GetDurationFormatM(OverallInfo.Session.Timer, _T("h:mm:ss"), bu, 32);
@@ -595,8 +571,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) rect.right += 50;
}
// Изображаем общий трафик.
- if (unOptions.DrawTotalTraffic)
- {
+ if (unOptions.DrawTotalTraffic) {
TCHAR bu[32];
GetFormattedTraffic(SummaryTotal, 3, bu, 32);
@@ -605,8 +580,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) rect.right += 100;
}
// Изображаем текущий трафик.
- if (unOptions.DrawCurrentTraffic)
- {
+ if (unOptions.DrawCurrentTraffic) {
TCHAR bu[32];
GetFormattedTraffic(SummarySession, 3, bu, 32);
@@ -617,20 +591,17 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) }
rect.top += Traffic_LineHeight + Traffic_AdditionSpace;
// Рисуем всеобщий трафик.
- if (unOptions.ShowOverall)
- {
+ if (unOptions.ShowOverall) {
// Изображаем иконку.
dx = 0;
- if (unOptions.DrawProtoIcon)
- {
+ if (unOptions.DrawProtoIcon) {
TC_DrawIconEx(hdc, rect.left, rect.top,
Skin_LoadIcon(SKINICON_OTHER_MIRANDA), b, ClistModernPresent);
dx = 19;
}
// Выводим текст
// Изображаем имя
- if (unOptions.DrawProtoName)
- {
+ if (unOptions.DrawProtoName) {
TCHAR *bu = mir_a2t("Overall");
rect.left += dx;
@@ -640,8 +611,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) }
// Следующие позиции строятся от правого края.
// Изображаем общий трафик.
- if (unOptions.DrawTotalTraffic)
- {
+ if (unOptions.DrawTotalTraffic) {
TCHAR bu[32];
GetFormattedTraffic(OverallInfo.TotalSentTraffic + OverallInfo.TotalRecvTraffic, 3, bu, 32);
@@ -650,8 +620,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) rect.right += 100;
}
// Изображаем текущий трафик.
- if (unOptions.DrawCurrentTraffic)
- {
+ if (unOptions.DrawCurrentTraffic) {
TCHAR bu[32];
GetFormattedTraffic(OverallInfo.CurrentRecvTraffic + OverallInfo.CurrentSentTraffic, 3, bu, 32);
@@ -662,9 +631,9 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) }
}
else
-//-------------
-// Если есть Variables - рисуем по-новому
-//-------------
+ //-------------
+ // Если есть Variables - рисуем по-новому
+ //-------------
{
RowItemInfo *ItemsList;
WORD ItemsNumber, RowsNumber;
@@ -674,10 +643,8 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) HICON *ahIcon = (HICON*)mir_alloc(sizeof(HICON));
RowsNumber = 0;
// Цикл по аккаунтам.
- for (i = 0; i < NumberOfAccounts; i++)
- {
- if (ProtoList[i].Visible && ProtoList[i].Enabled)
- {
+ for (i = 0; i < NumberOfAccounts; i++) {
+ if (ProtoList[i].Visible && ProtoList[i].Enabled) {
ExtraText = (TCHAR**)mir_realloc(ExtraText, sizeof(TCHAR*) * (RowsNumber + 1));
ahIcon = (HICON*)mir_realloc(ahIcon, sizeof(HICON) * (RowsNumber + 1));
@@ -686,16 +653,14 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) }
}
// Ещё 2 особых элемента.
- if (unOptions.ShowSummary)
- {
+ if (unOptions.ShowSummary) {
ExtraText = (TCHAR**)mir_realloc(ExtraText, sizeof(TCHAR*) * (RowsNumber + 1));
ahIcon = (HICON*)mir_realloc(ahIcon, sizeof(HICON) * (RowsNumber + 1));
ExtraText[RowsNumber] = mir_a2t("summary");
ahIcon[RowsNumber++] = Skin_LoadIcon(SKINICON_OTHER_MIRANDA);
}
- if (unOptions.ShowOverall)
- {
+ if (unOptions.ShowOverall) {
ExtraText = (TCHAR**)mir_realloc(ExtraText, sizeof(TCHAR*) * (RowsNumber + 1));
ahIcon = (HICON*)mir_realloc(ahIcon, sizeof(HICON) * (RowsNumber + 1));
@@ -704,45 +669,39 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) }
// Рисуем свой счётчик для каждого из выбранных протоколов
- for (i = 0; i < RowsNumber; i++)
- {
+ for (i = 0; i < RowsNumber; i++) {
TCHAR *buf = variables_parse(Traffic_CounterFormat, ExtraText[i], NULL);
- if (ItemsNumber = GetRowItems(buf, &ItemsList))
- {
+ if (ItemsNumber = GetRowItems(buf, &ItemsList)) {
// Рисуем текст.
- for (dx = 0; dx < ItemsNumber; dx++)
- {
+ for (dx = 0; dx < ItemsNumber; dx++) {
// Делаем копию прямоугольника для рисования.
memcpy(&rect2, &rect, sizeof(RECT));
rect2.bottom = rect2.top + Traffic_LineHeight;
// Что за тег?
- switch (ItemsList[dx].Alignment)
- {
- case 'I':
- TC_DrawIconEx(hdc, ItemsList[dx].Interval, rect2.top, ahIcon[i], b, ClistModernPresent);
- break;
- case 'i':
- TC_DrawIconEx(hdc, width - 16 - ItemsList[dx].Interval, rect2.top, ahIcon[i], b, ClistModernPresent);
- break;
- case 'L':
- rect2.left = ItemsList[dx].Interval;
- TC_AlphaText(hdc, ItemsList[dx].String, &rect2, DT_SINGLELINE | DT_LEFT | DT_VCENTER, ClistModernPresent);
- break;
- case 'R':
- rect2.right = width - ItemsList[dx].Interval;
- TC_AlphaText(hdc, ItemsList[dx].String, &rect2, DT_SINGLELINE | DT_RIGHT | DT_VCENTER, ClistModernPresent);
- break;
- default:
- continue;
+ switch (ItemsList[dx].Alignment) {
+ case 'I':
+ TC_DrawIconEx(hdc, ItemsList[dx].Interval, rect2.top, ahIcon[i], b, ClistModernPresent);
+ break;
+ case 'i':
+ TC_DrawIconEx(hdc, width - 16 - ItemsList[dx].Interval, rect2.top, ahIcon[i], b, ClistModernPresent);
+ break;
+ case 'L':
+ rect2.left = ItemsList[dx].Interval;
+ TC_AlphaText(hdc, ItemsList[dx].String, &rect2, DT_SINGLELINE | DT_LEFT | DT_VCENTER, ClistModernPresent);
+ break;
+ case 'R':
+ rect2.right = width - ItemsList[dx].Interval;
+ TC_AlphaText(hdc, ItemsList[dx].String, &rect2, DT_SINGLELINE | DT_RIGHT | DT_VCENTER, ClistModernPresent);
+ break;
+ default:
+ continue;
}
-
}
// Нужно освободить память.
- for (; ItemsNumber--; )
- {
+ for (; ItemsNumber--;)
mir_free(ItemsList[ItemsNumber].String);
- }
+
mir_free(ItemsList);
}
mir_free(buf);
@@ -750,7 +709,7 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) }
// Удаляем список строк.
- for (; RowsNumber--; )
+ for (; RowsNumber--;)
mir_free(ExtraText[RowsNumber]);
mir_free(ExtraText);
}
@@ -760,13 +719,9 @@ int PaintTrafficCounterWindow(HWND hwnd, HDC hDC) SelectObject(hdc, old_font);
if (ClistModernPresent)
- {
AlphaBlend(hDC, 0, 0, width, height, hdc, 0, 0, width, height, aga);
- }
else
- {
BitBlt(hDC, 0, 0, width, height, hdc, 0, 0, SRCCOPY);
- }
SelectObject(hdc, oldbmp);
DeleteObject(hbmp);
@@ -805,288 +760,270 @@ void ProtocolIsOffLine(int num) ProtoList[num].State = 0;
}
-static POINT ptMouse = {0};
+static POINT ptMouse = { 0 };
LRESULT CALLBACK TrafficCounterWndProc_MW(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
POINT p;
int i;
//
- switch (msg)
- {
- case (WM_USER+697):
- if (lParam == 666)
- DestroyWindow(hwnd);
- break;
+ switch (msg) {
+ case (WM_USER + 697) :
+ if (lParam == 666)
+ DestroyWindow(hwnd);
+ break;
- case WM_PAINT:
- {
- if ( !db_get_b(NULL, "ModernData", "DisableEngine", 0)
- && db_get_b(NULL, "ModernData", "EnableLayering", 1)
- && ServiceExists(MS_SKINENG_INVALIDATEFRAMEIMAGE))
- CallService(MS_SKINENG_INVALIDATEFRAMEIMAGE, (WPARAM)TrafficHwnd, 0);
- else
- {
- HDC hdc = GetDC(hwnd);
- PaintTrafficCounterWindow(hwnd, hdc);
- ReleaseDC(hwnd, hdc);
- }
+ case WM_PAINT:
+ {
+ if (!db_get_b(NULL, "ModernData", "DisableEngine", 0)
+ && db_get_b(NULL, "ModernData", "EnableLayering", 1)
+ && ServiceExists(MS_SKINENG_INVALIDATEFRAMEIMAGE))
+ CallService(MS_SKINENG_INVALIDATEFRAMEIMAGE, (WPARAM)TrafficHwnd, 0);
+ else {
+ HDC hdc = GetDC(hwnd);
+ PaintTrafficCounterWindow(hwnd, hdc);
+ ReleaseDC(hwnd, hdc);
}
+ }
+ break;
+
+ case WM_ERASEBKGND:
+ return 1;
+
+ case WM_LBUTTONDOWN:
+ if (db_get_b(NULL, "CLUI", "ClientAreaDrag", SETTING_CLIENTDRAG_DEFAULT)) {
+ ClientToScreen(GetParent(hwnd), &p);
+ return SendMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_MOVE | HTCAPTION, MAKELPARAM(p.x, p.y));
+ }
+ break;
+
+ case WM_RBUTTONDOWN:
+ p.x = GET_X_LPARAM(lParam);
+ p.y = GET_Y_LPARAM(lParam);
+ ClientToScreen(hwnd, &p);
+ TrackPopupMenu(TrafficPopupMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL, p.x, p.y, 0, hwnd, NULL);
+ break;
+
+ case WM_COMMAND:
+ switch (wParam) {
+ case POPUPMENU_HIDE:
+ MenuCommand_TrafficShowHide(0, 0);
break;
- case WM_ERASEBKGND:
- return 1;
+ case POPUPMENU_CLEAR_NOW:
+ for (i = 0; i < NumberOfAccounts; i++) {
+ ProtoList[i].StartIncoming =
+ ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords - 1].Incoming;
+ ProtoList[i].StartOutgoing =
+ ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords - 1].Outgoing;
+ ProtoList[i].Session.TimeAtStart = GetTickCount();
+ }
+ OverallInfo.CurrentRecvTraffic = OverallInfo.CurrentSentTraffic = 0;
+ }
+ break;
- case WM_LBUTTONDOWN :
- if (db_get_b(NULL,"CLUI","ClientAreaDrag",SETTING_CLIENTDRAG_DEFAULT))
- {
- ClientToScreen(GetParent(hwnd),&p);
- return SendMessage(GetParent(hwnd), WM_SYSCOMMAND, SC_MOVE|HTCAPTION,MAKELPARAM(p.x,p.y));
+ case WM_SETCURSOR:
+ {
+ POINT pt;
+
+ GetCursorPos(&pt);
+ if ((abs(pt.x - ptMouse.x) < 20)
+ && (abs(pt.y - ptMouse.y) < 20))
+ return 1;
+
+ if (TooltipShowing) {
+ KillTimer(TrafficHwnd, TIMER_TOOLTIP);
+ CallService("mToolTip/HideTip", 0, 0);
+ TooltipShowing = FALSE;
}
+ KillTimer(TrafficHwnd, TIMER_TOOLTIP);
+ SetTimer(TrafficHwnd, TIMER_TOOLTIP, CallService(MS_CLC_GETINFOTIPHOVERTIME, 0, 0), 0);
break;
+ }
- case WM_RBUTTONDOWN :
- p.x = GET_X_LPARAM(lParam);
- p.y = GET_Y_LPARAM(lParam);
- ClientToScreen(hwnd,&p);
- TrackPopupMenu(TrafficPopupMenu,TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,p.x,p.y,0,hwnd,NULL);
+ case WM_TIMER:
+ switch (wParam) {
+ case TIMER_NOTIFY_TICK:
+ NotifyOnRecv();
+ NotifyOnSend();
break;
- case WM_COMMAND :
- switch (wParam)
+ case TIMER_REDRAW: // Перерисовка раз в полсекунды.
{
- case POPUPMENU_HIDE:
- MenuCommand_TrafficShowHide(0, 0);
- break;
-
- case POPUPMENU_CLEAR_NOW:
- for (i = 0; i < NumberOfAccounts; i++)
- {
- ProtoList[i].StartIncoming =
- ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords - 1].Incoming;
- ProtoList[i].StartOutgoing =
- ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords - 1].Outgoing;
- ProtoList[i].Session.TimeAtStart = GetTickCount();
+ DWORD CurrentTimeMs;
+ SYSTEMTIME stNow;
+
+ SaveSettings(1);
+ // Перед подсчётом суммарного трафика обнуляем счётчики.
+ OverallInfo.CurrentRecvTraffic =
+ OverallInfo.CurrentSentTraffic =
+ OverallInfo.TotalRecvTraffic =
+ OverallInfo.TotalSentTraffic = 0;
+
+ CurrentTimeMs = GetTickCount();
+
+ for (i = 0; i < NumberOfAccounts; i++) {
+ if (ProtoList[i].State) {
+ ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords - 1].Time =
+ (CurrentTimeMs - ProtoList[i].Total.TimeAtStart) / 1000;
+ ProtoList[i].Session.Timer =
+ (CurrentTimeMs - ProtoList[i].Session.TimeAtStart) / 1000;
}
- OverallInfo.CurrentRecvTraffic = OverallInfo.CurrentSentTraffic = 0;
- }
- break;
- case WM_SETCURSOR:
- {
- POINT pt;
+ Stat_CheckStatistics(i);
- GetCursorPos(&pt);
- if ( (abs(pt.x - ptMouse.x) < 20)
- && (abs(pt.y - ptMouse.y) < 20) )
- return 1;
+ { // Здесь на основании статистики вычисляются значения всех трафиков и времени.
+ DWORD Sum1, Sum2;
+ unsigned long int j;
- if (TooltipShowing)
- {
- KillTimer(TrafficHwnd, TIMER_TOOLTIP);
- CallService("mToolTip/HideTip", 0, 0);
- TooltipShowing = FALSE;
+ // Значения для текущей сессии.
+ for (Sum1 = Sum2 = 0, j = ProtoList[i].StartIndex; j < ProtoList[i].NumberOfRecords; j++) {
+ Sum1 += ProtoList[i].AllStatistics[j].Incoming;
+ Sum2 += ProtoList[i].AllStatistics[j].Outgoing;
+ }
+ ProtoList[i].CurrentRecvTraffic = Sum1 - ProtoList[i].StartIncoming;
+ ProtoList[i].CurrentSentTraffic = Sum2 - ProtoList[i].StartOutgoing;
+ OverallInfo.CurrentRecvTraffic += ProtoList[i].CurrentRecvTraffic;
+ OverallInfo.CurrentSentTraffic += ProtoList[i].CurrentSentTraffic;
+ // Значения для выбранного периода.
+ ProtoList[i].TotalRecvTraffic =
+ Stat_GetItemValue(1 << i,
+ unOptions.PeriodForShow + 1,
+ Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1, 1);
+ ProtoList[i].TotalSentTraffic =
+ Stat_GetItemValue(1 << i,
+ unOptions.PeriodForShow + 1,
+ Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1, 2);
+ ProtoList[i].Total.Timer =
+ Stat_GetItemValue(1 << i,
+ unOptions.PeriodForShow + 1,
+ Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1, 4);
+ OverallInfo.TotalRecvTraffic += ProtoList[i].TotalRecvTraffic;
+ OverallInfo.TotalSentTraffic += ProtoList[i].TotalSentTraffic;
+ }
+ }
+ // Не пора ли уведомить?
+ if (unOptions.NotifyBySize && Traffic_Notify_size_value) {
+ if (!((OverallInfo.CurrentRecvTraffic >> 10) % Traffic_Notify_size_value)
+ && notify_recv_size != OverallInfo.CurrentRecvTraffic >> 10)
+ NotifyOnRecv();
+
+ if (!((OverallInfo.CurrentSentTraffic >> 10) % Traffic_Notify_size_value)
+ && notify_send_size != OverallInfo.CurrentSentTraffic >> 10)
+ NotifyOnSend();
}
- KillTimer(TrafficHwnd, TIMER_TOOLTIP);
- SetTimer(TrafficHwnd, TIMER_TOOLTIP, CallService(MS_CLC_GETINFOTIPHOVERTIME, 0, 0), 0);
- break;
- }
-
- case WM_TIMER :
- switch(wParam)
- {
- case TIMER_NOTIFY_TICK:
- NotifyOnRecv();
- NotifyOnSend();
- break;
- case TIMER_REDRAW: // Перерисовка раз в полсекунды.
- {
- DWORD CurrentTimeMs;
- SYSTEMTIME stNow;
-
- SaveSettings(1);
- // Перед подсчётом суммарного трафика обнуляем счётчики.
- OverallInfo.CurrentRecvTraffic =
- OverallInfo.CurrentSentTraffic =
- OverallInfo.TotalRecvTraffic =
- OverallInfo.TotalSentTraffic = 0;
-
- CurrentTimeMs = GetTickCount();
-
- for (i = 0; i < NumberOfAccounts; i++)
- {
- if (ProtoList[i].State)
- {
- ProtoList[i].AllStatistics[ProtoList[i].NumberOfRecords-1].Time =
- (CurrentTimeMs - ProtoList[i].Total.TimeAtStart) / 1000;
- ProtoList[i].Session.Timer =
- (CurrentTimeMs - ProtoList[i].Session.TimeAtStart) / 1000;
- }
-
- Stat_CheckStatistics(i);
-
- { // Здесь на основании статистики вычисляются значения всех трафиков и времени.
- DWORD Sum1, Sum2;
- unsigned long int j;
-
- // Значения для текущей сессии.
- for (Sum1 = Sum2 = 0, j = ProtoList[i].StartIndex; j < ProtoList[i].NumberOfRecords; j++)
- {
- Sum1 += ProtoList[i].AllStatistics[j].Incoming;
- Sum2 += ProtoList[i].AllStatistics[j].Outgoing;
- }
- ProtoList[i].CurrentRecvTraffic = Sum1 - ProtoList[i].StartIncoming;
- ProtoList[i].CurrentSentTraffic = Sum2 - ProtoList[i].StartOutgoing;
- OverallInfo.CurrentRecvTraffic += ProtoList[i].CurrentRecvTraffic;
- OverallInfo.CurrentSentTraffic += ProtoList[i].CurrentSentTraffic;
- // Значения для выбранного периода.
- ProtoList[i].TotalRecvTraffic =
- Stat_GetItemValue(1 << i,
- unOptions.PeriodForShow + 1,
- Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1,
- 1);
- ProtoList[i].TotalSentTraffic =
- Stat_GetItemValue(1 << i,
- unOptions.PeriodForShow + 1,
- Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1,
- 2);
- ProtoList[i].Total.Timer =
- Stat_GetItemValue(1 << i,
- unOptions.PeriodForShow + 1,
- Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1,
- 4);
- OverallInfo.TotalRecvTraffic += ProtoList[i].TotalRecvTraffic;
- OverallInfo.TotalSentTraffic += ProtoList[i].TotalSentTraffic;
- }
- }
- // Не пора ли уведомить?
- if (unOptions.NotifyBySize && Traffic_Notify_size_value)
- {
- if (!((OverallInfo.CurrentRecvTraffic >> 10) % Traffic_Notify_size_value)
- && notify_recv_size != OverallInfo.CurrentRecvTraffic >> 10 )
- NotifyOnRecv();
-
- if (!((OverallInfo.CurrentSentTraffic >> 10) % Traffic_Notify_size_value)
- && notify_send_size != OverallInfo.CurrentSentTraffic >> 10)
- NotifyOnSend();
- }
+ // Счётчики суммарного времени.
+ GetLocalTime(&stNow);
+
+ // Не пора ли сбросить общий счётчик?
+ if ((unOptions.PeriodForShow == 0
+ && stNow.wHour == 0
+ && stNow.wMinute == 0
+ && stNow.wSecond == 0)
+ || (unOptions.PeriodForShow == 1
+ && DayOfWeek(stNow.wDay, stNow.wMonth, stNow.wYear) == 1
+ && stNow.wHour == 0
+ && stNow.wMinute == 0
+ && stNow.wSecond == 0)
+ || (unOptions.PeriodForShow == 2
+ && stNow.wDay == 1
+ && stNow.wHour == 0
+ && stNow.wMinute == 0
+ && stNow.wSecond == 0)
+ || (unOptions.PeriodForShow == 3
+ && stNow.wMonth == 1
+ && stNow.wDay == 1
+ && stNow.wHour == 0
+ && stNow.wMinute == 0
+ && stNow.wSecond == 0))
+ OverallInfo.Total.TimeAtStart = CurrentTimeMs;
+
+ if (online_count > 0) {
+ OverallInfo.Session.Timer =
+ (CurrentTimeMs - OverallInfo.Session.TimeAtStart) / 1000;
+ OverallInfo.Total.Timer =
+ (CurrentTimeMs - OverallInfo.Total.TimeAtStart) / 1000;
+ }
- // Счётчики суммарного времени.
- GetLocalTime(&stNow);
-
- // Не пора ли сбросить общий счётчик?
- if ( (unOptions.PeriodForShow == 0
- && stNow.wHour == 0
- && stNow.wMinute == 0
- && stNow.wSecond == 0)
- || (unOptions.PeriodForShow == 1
- && DayOfWeek(stNow.wDay, stNow.wMonth, stNow.wYear) == 1
- && stNow.wHour == 0
- && stNow.wMinute == 0
- && stNow.wSecond == 0)
- || (unOptions.PeriodForShow == 2
- && stNow.wDay == 1
- && stNow.wHour == 0
- && stNow.wMinute == 0
- && stNow.wSecond == 0)
- || (unOptions.PeriodForShow == 3
- && stNow.wMonth == 1
- && stNow.wDay == 1
- && stNow.wHour == 0
- && stNow.wMinute == 0
- && stNow.wSecond == 0) )
- OverallInfo.Total.TimeAtStart = CurrentTimeMs;
-
- if (online_count > 0)
- {
- OverallInfo.Session.Timer =
- (CurrentTimeMs - OverallInfo.Session.TimeAtStart) / 1000;
- OverallInfo.Total.Timer =
- (CurrentTimeMs - OverallInfo.Total.TimeAtStart) / 1000;
- }
+ CallService(MS_CLIST_FRAMES_UPDATEFRAME, (WPARAM)Traffic_FrameID, FU_FMREDRAW);
+ }
+ break;
- CallService(MS_CLIST_FRAMES_UPDATEFRAME, (WPARAM)Traffic_FrameID, FU_FMREDRAW);
- }
- break;
+ case TIMER_TOOLTIP:
+ {
+ TCHAR *TooltipText;
+ CLCINFOTIP ti = { 0 };
+ RECT rt;
- case TIMER_TOOLTIP:
- {
- TCHAR *TooltipText;
- CLCINFOTIP ti = {0};
- RECT rt;
-
- GetCursorPos(&TooltipPosition);
- if (!TooltipShowing && unOptions.ShowTooltip )
- {
- KillTimer(TrafficHwnd, TIMER_TOOLTIP);
- ScreenToClient(TrafficHwnd, &TooltipPosition);
- GetClientRect(TrafficHwnd, &rt);
- if (PtInRect(&rt, TooltipPosition))
- {
- GetCursorPos(&ptMouse);
- ti.rcItem.left = TooltipPosition.x - 10;
- ti.rcItem.right = TooltipPosition.x + 10;
- ti.rcItem.top = TooltipPosition.y - 10;
- ti.rcItem.bottom = TooltipPosition.y + 10;
- ti.cbSize = sizeof( ti );
- TooltipText = variables_parsedup(Traffic_TooltipFormat, NULL, NULL);
-
- CallService(MS_TIPPER_SHOWTIPW, (WPARAM)TooltipText, (LPARAM)&ti);
-
- TooltipShowing = TRUE;
- mir_free(TooltipText);
- }
- }
+ GetCursorPos(&TooltipPosition);
+ if (!TooltipShowing && unOptions.ShowTooltip) {
+ KillTimer(TrafficHwnd, TIMER_TOOLTIP);
+ ScreenToClient(TrafficHwnd, &TooltipPosition);
+ GetClientRect(TrafficHwnd, &rt);
+ if (PtInRect(&rt, TooltipPosition)) {
+ GetCursorPos(&ptMouse);
+ ti.rcItem.left = TooltipPosition.x - 10;
+ ti.rcItem.right = TooltipPosition.x + 10;
+ ti.rcItem.top = TooltipPosition.y - 10;
+ ti.rcItem.bottom = TooltipPosition.y + 10;
+ ti.cbSize = sizeof(ti);
+ TooltipText = variables_parsedup(Traffic_TooltipFormat, NULL, NULL);
+
+ CallService(MS_TIPPER_SHOWTIPW, (WPARAM)TooltipText, (LPARAM)&ti);
+
+ TooltipShowing = TRUE;
+ mir_free(TooltipText);
}
- break;
+ }
}
break;
+ }
+ break;
- default:
- return DefWindowProc(hwnd,msg,wParam,lParam);
+ default:
+ return DefWindowProc(hwnd, msg, wParam, lParam);
}
//
- return DefWindowProc(hwnd,msg,wParam,lParam);
+ return DefWindowProc(hwnd, msg, wParam, lParam);
}
void CreateTrafficWindow(HWND hCluiWnd)
{
- WNDCLASSEX wcx = {0};
+ WNDCLASSEX wcx = { 0 };
CLISTFrame f;
- wcx.cbSize = sizeof( WNDCLASSEX );
- wcx.style = 0;
- wcx.lpfnWndProc = TrafficCounterWndProc_MW;
- wcx.cbClsExtra = 0;
- wcx.cbWndExtra = 0;
- wcx.hInstance = hInst;
- wcx.hIcon = NULL;
- wcx.hCursor = LoadCursor(hInst,IDC_ARROW);
- wcx.hbrBackground = 0;
- wcx.lpszMenuName = NULL;
- wcx.lpszClassName = TRAFFIC_COUNTER_WINDOW_CLASS;
- wcx.hIconSm = NULL;
- RegisterClassEx( &wcx );
+ wcx.cbSize = sizeof(WNDCLASSEX);
+ wcx.style = 0;
+ wcx.lpfnWndProc = TrafficCounterWndProc_MW;
+ wcx.cbClsExtra = 0;
+ wcx.cbWndExtra = 0;
+ wcx.hInstance = hInst;
+ wcx.hIcon = NULL;
+ wcx.hCursor = LoadCursor(hInst, IDC_ARROW);
+ wcx.hbrBackground = 0;
+ wcx.lpszMenuName = NULL;
+ wcx.lpszClassName = TRAFFIC_COUNTER_WINDOW_CLASS;
+ wcx.hIconSm = NULL;
+ RegisterClassEx(&wcx);
TrafficHwnd = CreateWindowEx(WS_EX_TOOLWINDOW, TRAFFIC_COUNTER_WINDOW_CLASS,
- TRAFFIC_COUNTER_WINDOW_CLASS,
- WS_CHILDWINDOW | WS_CLIPCHILDREN,
- 0, 0, 0, 0, hCluiWnd, NULL, hInst, NULL);
+ TRAFFIC_COUNTER_WINDOW_CLASS,
+ WS_CHILDWINDOW | WS_CLIPCHILDREN,
+ 0, 0, 0, 0, hCluiWnd, NULL, hInst, NULL);
- if ( ServiceExists(MS_CLIST_FRAMES_ADDFRAME) )
- {
+ if (ServiceExists(MS_CLIST_FRAMES_ADDFRAME)) {
// Готовимся создавать фрейм
memset(&f, 0, sizeof(CLISTFrame));
f.align = alBottom;
f.cbSize = sizeof(CLISTFrame);
f.height = TrafficWindowHeight();
- f.Flags= unOptions.FrameIsVisible | F_LOCKED | F_NOBORDER | F_NO_SUBCONTAINER;
+ f.Flags = unOptions.FrameIsVisible | F_LOCKED | F_NOBORDER | F_NO_SUBCONTAINER;
f.hWnd = TrafficHwnd;
f.TBname = ("Traffic counter");
f.name = ("Traffic counter");
// Создаём фрейм
- Traffic_FrameID = (HANDLE)CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&f,0);
- CallService(MS_SKINENG_REGISTERPAINTSUB,(WPARAM)f.hWnd,(LPARAM)TrafficCounter_PaintCallbackProc);
+ Traffic_FrameID = (HANDLE)CallService(MS_CLIST_FRAMES_ADDFRAME, (WPARAM)&f, 0);
+ CallService(MS_SKINENG_REGISTERPAINTSUB, (WPARAM)f.hWnd, (LPARAM)TrafficCounter_PaintCallbackProc);
}
// Создаём таймеры.
@@ -1094,7 +1031,7 @@ void CreateTrafficWindow(HWND hCluiWnd) UpdateNotifyTimer();
}
-INT_PTR MenuCommand_TrafficShowHide(WPARAM wParam,LPARAM lParam)
+INT_PTR MenuCommand_TrafficShowHide(WPARAM wParam, LPARAM lParam)
{
unOptions.FrameIsVisible = !unOptions.FrameIsVisible;
if (Traffic_FrameID == NULL)
@@ -1113,7 +1050,7 @@ void Traffic_AddMainMenuItem(void) mi.flags = 0;
mi.hIcon = NULL;
mi.pszName = LPGEN("Toggle traffic counter");
- mi.pszService="TrafficCounter/ShowHide";
+ mi.pszService = "TrafficCounter/ShowHide";
hTrafficMainMenuItem = Menu_AddMainMenuItem(&mi);
}
@@ -1155,7 +1092,7 @@ void NotifyOnRecv(void) memset(&ppd, 0, sizeof(ppd));
ppd.lchContact = NULL;
ppd.lchIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE);
- _tcsncpy(ppd.lptzContactName, TranslateT("Traffic counter notification"),MAX_CONTACTNAME);
+ _tcsncpy(ppd.lptzContactName, TranslateT("Traffic counter notification"), MAX_CONTACTNAME);
//
mir_sntprintf(ppd.lptzText, _countof(ppd.lptzText), TranslateT("%d kilobytes received"),
notify_recv_size = OverallInfo.CurrentRecvTraffic >> 10);
@@ -1164,7 +1101,7 @@ void NotifyOnRecv(void) ppd.colorText = Traffic_PopupFontColor;
ppd.PluginWindowProc = NULL;
ppd.iSeconds = (Traffic_PopupTimeoutDefault ? 0 : Traffic_PopupTimeoutValue);
- PUAddPopupT(&ppd);
+ PUAddPopupT(&ppd);
}
void CreateProtocolList(void)
@@ -1172,20 +1109,19 @@ void CreateProtocolList(void) int i;
PROTOACCOUNT **acc;
//
- Proto_EnumAccounts(&NumberOfAccounts,&acc);
+ Proto_EnumAccounts(&NumberOfAccounts, &acc);
//
ProtoList = (PROTOLIST*)mir_alloc(sizeof(PROTOLIST)*(NumberOfAccounts));
//
- for (i = 0; i < NumberOfAccounts; i++)
- {
+ for (i = 0; i < NumberOfAccounts; i++) {
ProtoList[i].name = (char*)mir_alloc(mir_strlen(acc[i]->szModuleName) + 1);
mir_strcpy(ProtoList[i].name, acc[i]->szModuleName);
ProtoList[i].tszAccountName = (TCHAR*)mir_alloc(sizeof(TCHAR) * (1 + mir_tstrlen(acc[i]->tszAccountName)));
mir_tstrcpy(ProtoList[i].tszAccountName, acc[i]->tszAccountName);
//
ProtoList[i].Flags = db_get_b(NULL, ProtoList[i].name, SETTINGS_PROTO_FLAGS, 3);
- ProtoList[i].CurrentRecvTraffic =
- ProtoList[i].CurrentSentTraffic =
+ ProtoList[i].CurrentRecvTraffic =
+ ProtoList[i].CurrentSentTraffic =
ProtoList[i].Session.Timer = 0;
//
ProtoList[i].Enabled = acc[i]->bIsEnabled;
@@ -1197,7 +1133,7 @@ void CreateProtocolList(void) ProtoList[i].StartOutgoing = ProtoList[i].AllStatistics[ProtoList[i].StartIndex].Outgoing;
} // цикл по аккаунтам
// Начальные значения для суммарной информации.
- OverallInfo.Session.Timer = OverallInfo.Total.Timer = 0;
+ OverallInfo.Session.Timer = OverallInfo.Total.Timer = 0;
}
void DestroyProtocolList(void)
@@ -1213,32 +1149,25 @@ void DestroyProtocolList(void) mir_free(ProtoList);
}
-int ProtocolAckHook(WPARAM wParam,LPARAM lParam)
+int ProtocolAckHook(WPARAM wParam, LPARAM lParam)
{
- ACKDATA* pAck=(ACKDATA*)lParam;
+ ACKDATA* pAck = (ACKDATA*)lParam;
WORD i;
- if (ACKTYPE_STATUS == pAck->type)
- {
- if(ID_STATUS_OFFLINE == pAck->lParam)
- {
- for (i = 0; i < NumberOfAccounts; i++)
- {
+ if (ACKTYPE_STATUS == pAck->type) {
+ if (ID_STATUS_OFFLINE == pAck->lParam) {
+ for (i = 0; i < NumberOfAccounts; i++) {
if (!ProtoList[i].name) continue;
- if (!mir_strcmp(ProtoList[i].name, pAck->szModule))
- {
+ if (!mir_strcmp(ProtoList[i].name, pAck->szModule)) {
ProtocolIsOffLine(i);
break;
}
}
}
- else
- {
- if ((pAck->lParam >= ID_STATUS_ONLINE) && (pAck->lParam <= ID_STATUS_OUTTOLUNCH))
- {
+ else {
+ if ((pAck->lParam >= ID_STATUS_ONLINE) && (pAck->lParam <= ID_STATUS_OUTTOLUNCH)) {
for (i = 0; i < NumberOfAccounts; i++)
- if (!mir_strcmp(ProtoList[i].name, pAck->szModule))
- {
+ if (!mir_strcmp(ProtoList[i].name, pAck->szModule)) {
ProtocolIsOnLine(i);
break;
}
@@ -1271,8 +1200,7 @@ int UpdateFonts(WPARAM wParam, LPARAM lParam) void UpdateTrafficWindowSize(void)
{
- if (Traffic_FrameID != NULL)
- {
+ if (Traffic_FrameID != NULL) {
CallService(MS_CLIST_FRAMES_SETFRAMEOPTIONS, MAKEWPARAM(FO_HEIGHT, Traffic_FrameID), TrafficWindowHeight());
}
}
@@ -1280,14 +1208,14 @@ void UpdateTrafficWindowSize(void) unsigned short int TrafficWindowHeight(void)
{
BYTE HeightLineTime = (unOptions.DrawProtoIcon) ? 16 : TrafficFontHeight,
- i, ActProto;
+ i, ActProto;
WORD MaxWndHeight;
for (i = 0, ActProto = unOptions.ShowOverall + unOptions.ShowSummary; i < NumberOfAccounts; i++)
ActProto += ProtoList[i].Visible && ProtoList[i].Enabled;
// Высота строки минимум 16 пикселей (для иконки).
- Traffic_LineHeight = TrafficFontHeight > 16 ? TrafficFontHeight: 16;
+ Traffic_LineHeight = TrafficFontHeight > 16 ? TrafficFontHeight : 16;
// Высота фрейма равна количеству строк.
MaxWndHeight = ActProto * Traffic_LineHeight
@@ -1302,20 +1230,19 @@ int OnAccountsListChange(WPARAM wParam, LPARAM lParam) {
BYTE i;
PROTOACCOUNT *acc = (PROTOACCOUNT*)lParam;
-
- switch (wParam)
- {
- case PRAC_ADDED:
- case PRAC_REMOVED:
- DestroyProtocolList();
- CreateProtocolList();
- break;
- case PRAC_CHANGED:
- case PRAC_CHECKED:
- for (i = 0; i < NumberOfAccounts; i++)
- if (!mir_strcmp(acc->szModuleName, ProtoList[i].name))
- ProtoList[i].Enabled = acc->bIsEnabled;
- break;
+
+ switch (wParam) {
+ case PRAC_ADDED:
+ case PRAC_REMOVED:
+ DestroyProtocolList();
+ CreateProtocolList();
+ break;
+ case PRAC_CHANGED:
+ case PRAC_CHECKED:
+ for (i = 0; i < NumberOfAccounts; i++)
+ if (!mir_strcmp(acc->szModuleName, ProtoList[i].name))
+ ProtoList[i].Enabled = acc->bIsEnabled;
+ break;
}
UpdateTrafficWindowSize();
return 0;
diff --git a/plugins/TrafficCounter/src/misc.cpp b/plugins/TrafficCounter/src/misc.cpp index 2febe16560..ebc9c515f6 100644 --- a/plugins/TrafficCounter/src/misc.cpp +++ b/plugins/TrafficCounter/src/misc.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. InputString - строка для разбора;
RowItemsList - список найденных элементов.
Возвращаемое значение - количество элементов в списках. */
+
WORD GetRowItems(TCHAR *InputString, RowItemInfo **RowItemsList)
{
TCHAR *begin, *end;
@@ -32,15 +33,13 @@ WORD GetRowItems(TCHAR *InputString, RowItemInfo **RowItemsList) // Ищем слева открывающую скобку.
begin = _tcschr(InputString, '{');
// Если скобка найдена...
- if (begin)
- {
+ if (begin) {
// Выделяем память под указатели
*RowItemsList = (RowItemInfo*)mir_alloc(sizeof(RowItemInfo));
}
else return 0;
- do
- {
+ do {
// Сразу вслед за ней ищем закрывающую.
end = _tcschr(begin, '}');
@@ -49,22 +48,20 @@ WORD GetRowItems(TCHAR *InputString, RowItemInfo **RowItemsList) // Разбираем тег.
_stscanf(begin + 1, _T("%c%d"),
- &((*RowItemsList)[c].Alignment),
- &((*RowItemsList)[c].Interval));
+ &((*RowItemsList)[c].Alignment),
+ &((*RowItemsList)[c].Interval));
// Ищем далее открывающую скобку - это конец строки, соответствующей тегу.
begin = _tcschr(end, '{');
- if (begin)
- {
+ if (begin) {
// Выделяем память под строку.
(*RowItemsList)[c].String = (TCHAR*)mir_alloc(sizeof(TCHAR) * (begin - end));
// Копируем строку.
_tcsncpy((*RowItemsList)[c].String, end + 1, begin - end - 1);
(*RowItemsList)[c].String[begin - end - 1] = 0;
}
- else
- {
+ else {
// Выделяем память под строку.
(*RowItemsList)[c].String = (TCHAR*)mir_alloc(sizeof(TCHAR) * mir_tstrlen(end));
// Копируем строку.
@@ -80,20 +77,19 @@ WORD GetRowItems(TCHAR *InputString, RowItemInfo **RowItemsList) /* Функция возвращает количество дней в указанном месяце указанного года. */
BYTE DaysInMonth(BYTE Month, WORD Year)
{
- switch (Month)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12: return 31;
- case 4:
- case 6:
- case 9:
- case 11: return 30;
- case 2: return 28 + (BYTE)!((Year % 4) && ( (Year % 100) || !(Year % 400) ));
+ switch (Month) {
+ case 1:
+ case 3:
+ case 5:
+ case 7:
+ case 8:
+ case 10:
+ case 12: return 31;
+ case 4:
+ case 6:
+ case 9:
+ case 11: return 30;
+ case 2: return 28 + (BYTE)!((Year % 4) && ((Year % 100) || !(Year % 400)));
}
return 0;
}
@@ -116,41 +112,40 @@ BYTE DayOfWeek(BYTE Day, BYTE Month, WORD Year) /*
Аргументы:
- Value - количество байт;
- Unit - единицы измерения (0 - байты, 1 - килобайты, 2 - мегабайты, 3 - автоматически);
- Buffer - адрес строки для записи результата;
- Size - размер буфера.
+Value - количество байт;
+Unit - единицы измерения (0 - байты, 1 - килобайты, 2 - мегабайты, 3 - автоматически);
+Buffer - адрес строки для записи результата;
+Size - размер буфера.
Возвращаемое значение: требуемый размер буфера.
*/
size_t GetFormattedTraffic(DWORD Value, BYTE Unit, TCHAR *Buffer, size_t Size)
{
- TCHAR Str1[32], szUnit[4] = {' ', 0};
+ TCHAR Str1[32], szUnit[4] = { ' ', 0 };
DWORD Divider;
- NUMBERFMT nf = {0, 1, 3, _T(","), _T(" "), 0};
+ NUMBERFMT nf = { 0, 1, 3, _T(","), _T(" "), 0 };
TCHAR *Res; // Промежуточный результат.
- switch (Unit)
- {
- case 0: //bytes
- Divider = 1;
- nf.NumDigits = 0;
- szUnit[0] = 0;
- break;
- case 1: // KB
- Divider = 0x400;
- nf.NumDigits = 2;
- break;
- case 2: // MB
- Divider = 0x100000;
- nf.NumDigits = 2;
- break;
- case 3: // Adaptive
- nf.NumDigits = 2;
- if (Value < 0x100000) { Divider = 0x400; szUnit[1] = 'K'; szUnit[2] = 'B'; }
- else { Divider = 0x100000; szUnit[1] = 'M'; szUnit[2] = 'B'; }
- break;
- default:
- return 0;
+ switch (Unit) {
+ case 0: //bytes
+ Divider = 1;
+ nf.NumDigits = 0;
+ szUnit[0] = 0;
+ break;
+ case 1: // KB
+ Divider = 0x400;
+ nf.NumDigits = 2;
+ break;
+ case 2: // MB
+ Divider = 0x100000;
+ nf.NumDigits = 2;
+ break;
+ case 3: // Adaptive
+ nf.NumDigits = 2;
+ if (Value < 0x100000) { Divider = 0x400; szUnit[1] = 'K'; szUnit[2] = 'B'; }
+ else { Divider = 0x100000; szUnit[1] = 'M'; szUnit[2] = 'B'; }
+ break;
+ default:
+ return 0;
}
mir_sntprintf(Str1, _countof(Str1), _T("%d.%d"), Value / Divider, Value % Divider);
@@ -162,15 +157,11 @@ size_t GetFormattedTraffic(DWORD Value, BYTE Unit, TCHAR *Buffer, size_t Size) GetNumberFormat(LOCALE_USER_DEFAULT, 0, Str1, &nf, Res, (int)l);
mir_tstrcat(Res, szUnit);
- if (Size && Buffer)
- {
+ if (Size && Buffer) {
mir_tstrcpy(Buffer, Res);
l = mir_tstrlen(Buffer);
}
- else
- {
- l = mir_tstrlen(Res) + 1;
- }
+ else l = mir_tstrlen(Res) + 1;
free(Res);
return l;
@@ -182,7 +173,8 @@ Duration: интервал времени в секундах; Format: строка формата;
Buffer: адрес буфера, куда функция помещает результат.
Size - размер буфера. */
-size_t GetDurationFormatM(DWORD Duration, TCHAR *Format, TCHAR *Buffer, WORD Size)
+
+size_t GetDurationFormatM(DWORD Duration, TCHAR *Format, TCHAR *Buffer, size_t Size)
{
size_t Length;
DWORD q;
@@ -194,63 +186,48 @@ size_t GetDurationFormatM(DWORD Duration, TCHAR *Format, TCHAR *Buffer, WORD Siz //SecureZeroMemory(Res, sizeof(TCHAR));
Res[0] = 0;
- for (FormatIndex = 0; Format[FormatIndex];)
- {
+ for (FormatIndex = 0; Format[FormatIndex];) {
// Ищем токены. Считается, что токен - только буквы.
TokenIndex = 0;
q = _istalpha(Format[FormatIndex]);
// Копируем символы в аккумулятор до смены флага.
- do
- {
+ do {
Token[TokenIndex++] = Format[FormatIndex++];
} while (q == _istalpha(Format[FormatIndex]));
Token[TokenIndex] = 0;
// Что получили в аккумуляторе?
- if (!mir_tstrcmp(Token, _T("d")))
- {
+ if (!mir_tstrcmp(Token, _T("d"))) {
q = Duration / (60 * 60 * 24);
mir_sntprintf(Token, _countof(Token), _T("%d"), q);
Duration -= q * 60 * 60 * 24;
}
- else
- if (!mir_tstrcmp(Token, _T("h")))
- {
+ else if (!mir_tstrcmp(Token, _T("h"))) {
q = Duration / (60 * 60);
mir_sntprintf(Token, _countof(Token), _T("%d"), q);
Duration -= q * 60 * 60;
}
- else
- if (!mir_tstrcmp(Token, _T("hh")))
- {
+ else if (!mir_tstrcmp(Token, _T("hh"))) {
q = Duration / (60 * 60);
mir_sntprintf(Token, _countof(Token), _T("%02d"), q);
Duration -= q * 60 * 60;
}
- else
- if (!mir_tstrcmp(Token, _T("m")))
- {
+ else if (!mir_tstrcmp(Token, _T("m"))) {
q = Duration / 60;
mir_sntprintf(Token, _countof(Token), _T("%d"), q);
Duration -= q * 60;
}
- else
- if (!mir_tstrcmp(Token, _T("mm")))
- {
+ else if (!mir_tstrcmp(Token, _T("mm"))) {
q = Duration / 60;
mir_sntprintf(Token, _countof(Token), _T("%02d"), q);
Duration -= q * 60;
}
- else
- if (!mir_tstrcmp(Token, _T("s")))
- {
+ else if (!mir_tstrcmp(Token, _T("s"))) {
q = Duration;
mir_sntprintf(Token, _countof(Token), _T("%d"), q);
Duration -= q;
}
- else
- if (!mir_tstrcmp(Token, _T("ss")))
- {
+ else if (!mir_tstrcmp(Token, _T("ss"))) {
q = Duration;
mir_sntprintf(Token, _countof(Token), _T("%02d"), q);
Duration -= q;
@@ -262,15 +239,11 @@ size_t GetDurationFormatM(DWORD Duration, TCHAR *Format, TCHAR *Buffer, WORD Siz mir_tstrcat(Res, Token);
}
- if (Size && Buffer)
- {
+ if (Size && Buffer) {
_tcsncpy(Buffer, Res, Size);
Length = mir_tstrlen(Buffer);
}
- else
- {
- Length = mir_tstrlen(Res) + 1;
- }
+ else Length = mir_tstrlen(Res) + 1;
free(Res);
return Length;
@@ -278,7 +251,7 @@ size_t GetDurationFormatM(DWORD Duration, TCHAR *Format, TCHAR *Buffer, WORD Siz /* Результат:
-1 - st1 < st2
- 0 - st1 = st2
+0 - st1 = st2
+1 - st1 > st2
*/
signed short int TimeCompare(SYSTEMTIME st1, SYSTEMTIME st2)
@@ -301,6 +274,5 @@ signed short int TimeCompare(SYSTEMTIME st1, SYSTEMTIME st2) if (d < 0) return -1;
if (d > 0) return +1;
-
return 0;
}
diff --git a/plugins/TrafficCounter/src/misc.h b/plugins/TrafficCounter/src/misc.h index 0a6aa9131c..0f4b418bdc 100644 --- a/plugins/TrafficCounter/src/misc.h +++ b/plugins/TrafficCounter/src/misc.h @@ -27,6 +27,6 @@ BYTE DayOfWeek(BYTE Day, BYTE Month, WORD Year); Возвращаемое значение: требуемый размер буфера. */
size_t GetFormattedTraffic(DWORD Value, BYTE Unit, TCHAR *Buffer, size_t Size);
-size_t GetDurationFormatM(DWORD Duration, TCHAR *Format, TCHAR *Buffer, WORD Size);
+size_t GetDurationFormatM(DWORD Duration, TCHAR *Format, TCHAR *Buffer, size_t Size);
signed short int TimeCompare(SYSTEMTIME st1, SYSTEMTIME st2);
\ No newline at end of file diff --git a/plugins/TrafficCounter/src/statistics.cpp b/plugins/TrafficCounter/src/statistics.cpp index bd5a5ff6d2..511560baa3 100644 --- a/plugins/TrafficCounter/src/statistics.cpp +++ b/plugins/TrafficCounter/src/statistics.cpp @@ -30,279 +30,262 @@ HWND hListAccs; INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
WORD i;
-
- switch (msg)
- {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwndDlg);
- // Создаём ListBox c перечнем аккаунтов.
- hListAccs = CreateWindowEx(WS_EX_CLIENTEDGE,
- _T("ListBox"),
- NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | LBS_NOTIFY,
- 2, 20, 246, 112,
- hwndDlg, NULL, NULL, NULL);
- SendMessage(hListAccs, WM_SETFONT, (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT), 0);
- for (i = 0 ; i < NumberOfAccounts; i++)
- {
- // Готовим список аккаунтов
- if (ProtoList[i].tszAccountName)
- SendMessage(hListAccs, LB_ADDSTRING, 0, (LPARAM)ProtoList[i].tszAccountName);
- }
- for (i = NumberOfAccounts; i--; )
- SendMessage(hListAccs, LB_SETSEL, (WPARAM)0x01&(Stat_SelAcc>>i), (LPARAM)i);
- // Готовим список единиц измерения
- SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Bytes"));
- SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("KB"));
- SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("MB"));
- SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Adaptive"));
- SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_SETCURSEL, unOptions.Stat_Units, 0);
- // Готовим закладки
- {
- TCITEM tci;
- tci.mask = TCIF_TEXT;
- tci.pszText = TranslateT("Hourly");
- SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 0, (LPARAM)&tci);
- tci.pszText = TranslateT("Daily");
- SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 1, (LPARAM)&tci);
- tci.pszText = TranslateT("Weekly");
- SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 2, (LPARAM)&tci);
- tci.pszText = TranslateT("Monthly");
- SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 3, (LPARAM)&tci);
- tci.pszText = TranslateT("Yearly");
- SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 4, (LPARAM)&tci);
- SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_SETCURSEL, unOptions.Stat_Tab, 0);
- }
- // Готовим ListView - колонки и стили
- {
- LVCOLUMN lvc ={0};
-
- SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
-
- SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_SETUNICODEFORMAT, 1, 0);
-
-
- lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
- lvc.fmt = LVCFMT_LEFT;
- lvc.pszText = TranslateT("Period");
- lvc.cx = 135;
- lvc.iSubItem = 0;
- SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc);
- lvc.fmt = LVCFMT_RIGHT;
- lvc.pszText = TranslateT("Incoming");
- lvc.iSubItem = 1;
- lvc.cx = 72;
- SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc);
- lvc.pszText = TranslateT("Outgoing");
- lvc.iSubItem = 2;
- lvc.cx = 72;
- SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);
- lvc.pszText = TranslateT("Sum");
- lvc.iSubItem = 3;
- lvc.cx = 72;
- SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 3, (LPARAM)&lvc);
- lvc.pszText = TranslateT("Online");
- lvc.iSubItem = 4;
- lvc.cx = 72;
- SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 4, (LPARAM)&lvc);
+
+ switch (msg) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwndDlg);
+ // Создаём ListBox c перечнем аккаунтов.
+ hListAccs = CreateWindowEx(WS_EX_CLIENTEDGE,
+ _T("ListBox"),
+ NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP | LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | LBS_NOTIFY,
+ 2, 20, 246, 112,
+ hwndDlg, NULL, NULL, NULL);
+ SendMessage(hListAccs, WM_SETFONT, (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT), 0);
+ for (i = 0; i < NumberOfAccounts; i++) {
+ // Готовим список аккаунтов
+ if (ProtoList[i].tszAccountName)
+ SendMessage(hListAccs, LB_ADDSTRING, 0, (LPARAM)ProtoList[i].tszAccountName);
+ }
+ for (i = NumberOfAccounts; i--;)
+ SendMessage(hListAccs, LB_SETSEL, (WPARAM)0x01 & (Stat_SelAcc >> i), (LPARAM)i);
+ // Готовим список единиц измерения
+ SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Bytes"));
+ SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("KB"));
+ SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("MB"));
+ SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_INSERTSTRING, -1, (LPARAM)TranslateT("Adaptive"));
+ SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_SETCURSEL, unOptions.Stat_Units, 0);
+ // Готовим закладки
+ {
+ TCITEM tci;
+ tci.mask = TCIF_TEXT;
+ tci.pszText = TranslateT("Hourly");
+ SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 0, (LPARAM)&tci);
+ tci.pszText = TranslateT("Daily");
+ SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 1, (LPARAM)&tci);
+ tci.pszText = TranslateT("Weekly");
+ SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 2, (LPARAM)&tci);
+ tci.pszText = TranslateT("Monthly");
+ SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 3, (LPARAM)&tci);
+ tci.pszText = TranslateT("Yearly");
+ SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_INSERTITEM, 4, (LPARAM)&tci);
+ SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_SETCURSEL, unOptions.Stat_Tab, 0);
+ }
+ // Готовим ListView - колонки и стили
+ {
+ SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
+ SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_SETUNICODEFORMAT, 1, 0);
+
+ LVCOLUMN lvc = { 0 };
+ lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
+ lvc.fmt = LVCFMT_LEFT;
+ lvc.pszText = TranslateT("Period");
+ lvc.cx = 135;
+ lvc.iSubItem = 0;
+ SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc);
+ lvc.fmt = LVCFMT_RIGHT;
+ lvc.pszText = TranslateT("Incoming");
+ lvc.iSubItem = 1;
+ lvc.cx = 72;
+ SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc);
+ lvc.pszText = TranslateT("Outgoing");
+ lvc.iSubItem = 2;
+ lvc.cx = 72;
+ SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);
+ lvc.pszText = TranslateT("Sum");
+ lvc.iSubItem = 3;
+ lvc.cx = 72;
+ SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 3, (LPARAM)&lvc);
+ lvc.pszText = TranslateT("Online");
+ lvc.iSubItem = 4;
+ lvc.cx = 72;
+ SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_INSERTCOLUMN, 4, (LPARAM)&lvc);
+ }
+ Stat_Show(hwndDlg);
+ break; // WM_INITDIALOG
+ case WM_COMMAND:
+ if ((HWND)lParam == hListAccs) {
+ DWORD SelItems[16];
+ BYTE SelItemsCount;
+ if (HIWORD(wParam) == LBN_SELCHANGE) {
+ SelItemsCount = SendMessage(hListAccs, LB_GETSELCOUNT, 0, 0);
+ SendMessage(hListAccs,
+ LB_GETSELITEMS,
+ SelItemsCount,
+ (LPARAM)SelItems);
+ for (Stat_SelAcc = i = 0; i < SelItemsCount; i++)
+ Stat_SelAcc |= 1 << SelItems[i];
+ Stat_Show(hwndDlg);
}
+ }
+ switch (LOWORD(wParam)) {
+ case IDC_COMBO_UNITS:
+ if (HIWORD(wParam) != CBN_SELCHANGE) break;
+ unOptions.Stat_Units = SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_GETCURSEL, 0, 0);
Stat_Show(hwndDlg);
- break; // WM_INITDIALOG
- case WM_COMMAND:
- if ((HWND)lParam == hListAccs)
- {
- DWORD SelItems[16];
- BYTE SelItemsCount;
- if (HIWORD(wParam) == LBN_SELCHANGE)
- {
- SelItemsCount = SendMessage(hListAccs, LB_GETSELCOUNT, 0, 0);
- SendMessage(hListAccs,
- LB_GETSELITEMS,
- SelItemsCount,
- (LPARAM)SelItems);
- for (Stat_SelAcc = i = 0; i < SelItemsCount; i++)
- Stat_SelAcc |= 1 << SelItems[i];
- Stat_Show(hwndDlg);
- }
- }
- switch (LOWORD(wParam))
+ break;
+ case IDC_BUTTON_CLEAR:
{
- case IDC_COMBO_UNITS:
- if (HIWORD(wParam) != CBN_SELCHANGE) break;
- unOptions.Stat_Units = SendDlgItemMessage(hwndDlg, IDC_COMBO_UNITS, CB_GETCURSEL, 0, 0);
- Stat_Show(hwndDlg);
+ SYSTEMTIME stNow;
+
+ if (IDOK != MessageBox(hwndDlg,
+ TranslateT("Now traffic statistics for selected accounts will be cleared.\nContinue?"),
+ TranslateT("Traffic counter"),
+ MB_OKCANCEL | MB_ICONWARNING))
break;
- case IDC_BUTTON_CLEAR:
+ GetLocalTime(&stNow);
+ for (i = NumberOfAccounts; i--;)
+ if (0x01 & (Stat_SelAcc >> i)) {
+ SetFilePointer(ProtoList[i].hFile, sizeof(HOURLYSTATS), NULL, FILE_BEGIN);
+ SetEndOfFile(ProtoList[i].hFile); // Усекаем файл до одной записи.
+ ProtoList[i].NumberOfRecords = 1;
+ ProtoList[i].AllStatistics = (HOURLYSTATS*)mir_realloc(ProtoList[i].AllStatistics, sizeof(HOURLYSTATS));
+ ProtoList[i].AllStatistics[0].Hour = stNow.wHour;
+ ProtoList[i].AllStatistics[0].Day = stNow.wDay;
+ ProtoList[i].AllStatistics[0].Month = stNow.wMonth;
+ ProtoList[i].AllStatistics[0].Year = stNow.wYear;
+ ProtoList[i].AllStatistics[0].Incoming = 0;
+ ProtoList[i].AllStatistics[0].Outgoing = 0;
+ ProtoList[i].StartIncoming = 0;
+ ProtoList[i].StartOutgoing = 0;
+ ProtoList[i].AllStatistics[0].Time = 0;
+ ProtoList[i].Total.TimeAtStart = GetTickCount();
+ Stat_CheckStatistics(i);
+ }
+ Stat_Show(hwndDlg);
+ }
+ break;
+ }
+ break; // WM_COMMAND
+ case WM_NOTIFY:
+ {
+ LPNMHDR lpnmhdr = (LPNMHDR)lParam;
+
+ switch (lpnmhdr->idFrom) {
+ case IDC_TAB_STATS:
+ if (lpnmhdr->code != TCN_SELCHANGE) break;
+ unOptions.Stat_Tab = SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_GETCURSEL, 0, 0);
+ Stat_Show(hwndDlg);
+ break;
+ case IDC_LIST_DATA:
+ switch (lpnmhdr->code) {
+ case LVN_GETDISPINFO:
{
- SYSTEMTIME stNow;
+ NMLVDISPINFO* pdi = (NMLVDISPINFO*)lParam;
+ SYSTEMTIME st = { 0 };
+ DWORD Index, Value;
+ double vartime;
+ TCHAR szBufW[64];
+ BYTE EldestAcc;
+
+ if (!(pdi->item.mask & LVIF_TEXT)) return 0;
+
+ // Если нужна надпись.
+ if (!pdi->item.iSubItem) {
+ EldestAcc = Stat_GetEldestAcc(Stat_SelAcc);
+ // Индекс применим только для самого старого аккаунта!
+ Index = Stat_GetStartIndex(EldestAcc, unOptions.Stat_Tab, pdi->item.iItem, &st);
+ switch (unOptions.Stat_Tab) {
+ case 0: // Hourly
+ GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szBufW, 32);
+ mir_sntprintf(pdi->item.pszText, 32, _T("%s %02d:00 - %02d:59"),
+ szBufW,
+ ProtoList[EldestAcc].AllStatistics[Index].Hour,
+ ProtoList[EldestAcc].AllStatistics[Index].Hour);
+ break;
+ case 1: // Dayly
+ GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, pdi->item.pszText, 32);
+ break;
+ case 2: // Weekly
+ // Уходим к первому понедельнику слева.
+ SystemTimeToVariantTime(&st, &vartime);
+ vartime -= DayOfWeek(st.wDay, st.wMonth, st.wYear) - 1;
+ VariantTimeToSystemTime(vartime, &st);
+ GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, pdi->item.pszText, 32);
+ // Теперь к воскресенью.
+ SystemTimeToVariantTime(&st, &vartime);
+ vartime += 6;
+ VariantTimeToSystemTime(vartime, &st);
+ GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szBufW, 32);
+ mir_sntprintf(pdi->item.pszText, 32, _T("%s - %s"), pdi->item.pszText, szBufW);
+ break;
+ case 3: // Monthly
+ GetDateFormat(LOCALE_USER_DEFAULT, DATE_YEARMONTH, &st, NULL, pdi->item.pszText, 32);
+ break;
+ case 4: // Yearly
+ mir_sntprintf(pdi->item.pszText, 32, _T("%d"), st.wYear);
+ break;
+ }
+ return 0;
+ }
+
+ Value = Stat_GetItemValue(Stat_SelAcc, unOptions.Stat_Tab, pdi->item.iItem, pdi->item.iSubItem);
- if (IDOK != MessageBox(hwndDlg,
- TranslateT("Now traffic statistics for selected accounts will be cleared.\nContinue?"),
- TranslateT("Traffic counter"),
- MB_OKCANCEL | MB_ICONWARNING))
+ // Теперь можно записать в ListView циферки.
+ switch (pdi->item.iSubItem) {
+ case 1: // Входящий
+ case 2: // Исходящий
+ case 3: // Сумма
+ GetFormattedTraffic(Value, unOptions.Stat_Units, pdi->item.pszText, 32);
break;
- GetLocalTime(&stNow);
- for (i = NumberOfAccounts; i--;)
- if (0x01&(Stat_SelAcc>>i))
+ case 4: // Время
{
- SetFilePointer(ProtoList[i].hFile, sizeof(HOURLYSTATS), NULL, FILE_BEGIN);
- SetEndOfFile(ProtoList[i].hFile); // Усекаем файл до одной записи.
- ProtoList[i].NumberOfRecords = 1;
- ProtoList[i].AllStatistics = (HOURLYSTATS*)mir_realloc(ProtoList[i].AllStatistics, sizeof(HOURLYSTATS));
- ProtoList[i].AllStatistics[0].Hour = stNow.wHour;
- ProtoList[i].AllStatistics[0].Day = stNow.wDay;
- ProtoList[i].AllStatistics[0].Month = stNow.wMonth;
- ProtoList[i].AllStatistics[0].Year = stNow.wYear;
- ProtoList[i].AllStatistics[0].Incoming = 0;
- ProtoList[i].AllStatistics[0].Outgoing = 0;
- ProtoList[i].StartIncoming = 0;
- ProtoList[i].StartOutgoing = 0;
- ProtoList[i].AllStatistics[0].Time = 0;
- ProtoList[i].Total.TimeAtStart = GetTickCount();
- Stat_CheckStatistics(i);
+ TCHAR *Fmt[5] = { _T("m:ss"), _T("h:mm:ss"), _T("h:mm:ss"), _T("d hh:mm:ss"), _T("d hh:mm:ss") };
+ GetDurationFormatM(Value, Fmt[unOptions.Stat_Tab], pdi->item.pszText, 32);
}
- Stat_Show(hwndDlg);
+ break;
+ }
}
break;
- }
- break; // WM_COMMAND
- case WM_NOTIFY:
- {
- LPNMHDR lpnmhdr = (LPNMHDR)lParam;
-
- switch(lpnmhdr->idFrom)
- {
- case IDC_TAB_STATS:
- if (lpnmhdr->code != TCN_SELCHANGE) break;
- unOptions.Stat_Tab = SendDlgItemMessage(hwndDlg, IDC_TAB_STATS, TCM_GETCURSEL, 0, 0);
- Stat_Show(hwndDlg);
- break;
- case IDC_LIST_DATA:
- switch (lpnmhdr->code)
- {
- case LVN_GETDISPINFO:
- {
- NMLVDISPINFO* pdi = (NMLVDISPINFO*)lParam;
- SYSTEMTIME st = {0};
- DWORD Index, Value;
- double vartime;
- TCHAR szBufW[64];
- BYTE EldestAcc;
-
- if (!(pdi->item.mask & LVIF_TEXT)) return 0;
-
- // Если нужна надпись.
- if (!pdi->item.iSubItem)
- {
- EldestAcc = Stat_GetEldestAcc(Stat_SelAcc);
- // Индекс применим только для самого старого аккаунта!
- Index = Stat_GetStartIndex(EldestAcc, unOptions.Stat_Tab, pdi->item.iItem, &st);
- switch (unOptions.Stat_Tab)
- {
- case 0: // Hourly
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szBufW, 32);
- mir_sntprintf(pdi->item.pszText, 32, _T("%s %02d:00 - %02d:59"),
- szBufW,
- ProtoList[EldestAcc].AllStatistics[Index].Hour,
- ProtoList[EldestAcc].AllStatistics[Index].Hour);
- break;
- case 1: // Dayly
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, pdi->item.pszText, 32);
- break;
- case 2: // Weekly
- // Уходим к первому понедельнику слева.
- SystemTimeToVariantTime(&st, &vartime);
- vartime -= DayOfWeek(st.wDay, st.wMonth, st.wYear) - 1;
- VariantTimeToSystemTime(vartime, &st);
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, pdi->item.pszText, 32);
- // Теперь к воскресенью.
- SystemTimeToVariantTime(&st, &vartime);
- vartime += 6;
- VariantTimeToSystemTime(vartime, &st);
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szBufW, 32);
- mir_sntprintf(pdi->item.pszText, 32, _T("%s - %s"), pdi->item.pszText, szBufW);
- break;
- case 3: // Monthly
- GetDateFormat(LOCALE_USER_DEFAULT, DATE_YEARMONTH, &st, NULL, pdi->item.pszText, 32);
- break;
- case 4: // Yearly
- mir_sntprintf(pdi->item.pszText, 32, _T("%d"), st.wYear);
- break;
- }
- return 0;
- }
-
- Value = Stat_GetItemValue(Stat_SelAcc, unOptions.Stat_Tab, pdi->item.iItem, pdi->item.iSubItem);
-
- // Теперь можно записать в ListView циферки.
- switch (pdi->item.iSubItem)
- {
- case 1: // Входящий
- case 2: // Исходящий
- case 3: // Сумма
- GetFormattedTraffic(Value, unOptions.Stat_Units, pdi->item.pszText, 32);
- break;
- case 4: // Время
- {
- TCHAR *Fmt[5] = {_T("m:ss"), _T("h:mm:ss"), _T("h:mm:ss"), _T("d hh:mm:ss"), _T("d hh:mm:ss")};
- GetDurationFormatM(Value, Fmt[unOptions.Stat_Tab], pdi->item.pszText, 32);
- }
- break;
- }
- }
- break;
-
- case NM_CLICK:
- case LVN_ITEMCHANGED:
- {
- DWORD i, j = -1, dwTotalIncoming = 0, dwTotalOutgoing = 0;
-
- i = SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_GETSELECTEDCOUNT, 0, 0);
- for ( ; i--;)
- {
- j = SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_GETNEXTITEM, j, LVNI_SELECTED);
- dwTotalIncoming += Stat_GetItemValue(Stat_SelAcc, unOptions.Stat_Tab, j, 1);
- dwTotalOutgoing += Stat_GetItemValue(Stat_SelAcc, unOptions.Stat_Tab, j, 2);
- }
- Stat_UpdateTotalTraffic(hwndDlg, dwTotalIncoming, dwTotalOutgoing);
- }
- break;
- case NM_CUSTOMDRAW:
- {
- LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
-
- switch (lplvcd->nmcd.dwDrawStage)
- {
- case CDDS_PREPAINT: // Перед началом рисования всего ListView.
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
- return TRUE;
- case CDDS_ITEMPREPAINT: // Перед началом рисования строки.
- {
- COLORREF Color;
- BYTE r, g, b;
-
- if (lplvcd->nmcd.dwItemSpec & 0x01)
- {
- Color = SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_GETBKCOLOR, 0, 0);
- r = GetRValue(Color);
- g = GetGValue(Color);
- b = GetBValue(Color);
- r += r > 0x80 ? -40 : 40;
- g += g > 0x80 ? -40 : 40;
- b += b > 0x80 ? -40 : 40;
- lplvcd->clrTextBk = RGB(r, g, b);
- }
- SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
- return TRUE;
- }
- }
+ case NM_CLICK:
+ case LVN_ITEMCHANGED:
+ {
+ DWORD i, j = -1, dwTotalIncoming = 0, dwTotalOutgoing = 0;
+
+ i = SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_GETSELECTEDCOUNT, 0, 0);
+ for (; i--;) {
+ j = SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_GETNEXTITEM, j, LVNI_SELECTED);
+ dwTotalIncoming += Stat_GetItemValue(Stat_SelAcc, unOptions.Stat_Tab, j, 1);
+ dwTotalOutgoing += Stat_GetItemValue(Stat_SelAcc, unOptions.Stat_Tab, j, 2);
+ }
+ Stat_UpdateTotalTraffic(hwndDlg, dwTotalIncoming, dwTotalOutgoing);
+ }
+ break;
+
+ case NM_CUSTOMDRAW:
+ {
+ LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
+
+ switch (lplvcd->nmcd.dwDrawStage) {
+ case CDDS_PREPAINT: // Перед началом рисования всего ListView.
+ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYITEMDRAW);
+ return TRUE;
+ case CDDS_ITEMPREPAINT: // Перед началом рисования строки.
+ {
+ COLORREF Color;
+ BYTE r, g, b;
+
+ if (lplvcd->nmcd.dwItemSpec & 0x01) {
+ Color = SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_GETBKCOLOR, 0, 0);
+ r = GetRValue(Color);
+ g = GetGValue(Color);
+ b = GetBValue(Color);
+ r += r > 0x80 ? -40 : 40;
+ g += g > 0x80 ? -40 : 40;
+ b += b > 0x80 ? -40 : 40;
+ lplvcd->clrTextBk = RGB(r, g, b);
}
- break;
+ SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, CDRF_NEWFONT);
+ return TRUE;
+ }
}
- break;
+ }
+ break;
}
+ break;
}
- break; // WM_NOTIFY
+ }
+ break; // WM_NOTIFY
}
return 0;
}
@@ -315,8 +298,8 @@ void Stat_ReadFile(BYTE n) LARGE_INTEGER Size;
DWORD BytesRead;
TCHAR FileName[MAX_PATH], *pszPath;
- SYSTEMTIME stNow, stLast = {0};
-
+ SYSTEMTIME stNow, stLast = { 0 };
+
pszPath = Utils_ReplaceVarsT(_T("%miranda_userdata%\\statistics"));
CreateDirectoryTreeT(pszPath);
mir_sntprintf(FileName, _countof(FileName), _T("%s\\%S.stat"), pszPath, ProtoList[n].name);
@@ -328,17 +311,15 @@ void Stat_ReadFile(BYTE n) if (Size.QuadPart != 0) // Если файл со статистикой существует и имеет ненулевой размер...
{
// ...то читаем статистику из файла
- ProtoList[n].NumberOfRecords = DWORD(Size.QuadPart/sizeof(HOURLYSTATS));
+ ProtoList[n].NumberOfRecords = DWORD(Size.QuadPart / sizeof(HOURLYSTATS));
ProtoList[n].AllStatistics = (HOURLYSTATS*)mir_alloc(sizeof(HOURLYSTATS)*ProtoList[n].NumberOfRecords);
ReadFile(ProtoList[n].hFile, &ProtoList[n].AllStatistics[0], sizeof(HOURLYSTATS)*ProtoList[n].NumberOfRecords, &BytesRead, NULL);
- if (!BytesRead)
- {
+ if (!BytesRead) {
MessageBox(TrafficHwnd, TranslateT("Couldn't read statistics file"), TranslateT("Traffic Counter"), MB_OK);
return;
}
}
- else
- {
+ else {
// Необходимо создать новый файл.
ProtoList[n].NumberOfRecords = 1;
ProtoList[n].AllStatistics = (HOURLYSTATS*)mir_alloc(sizeof(HOURLYSTATS));
@@ -347,8 +328,8 @@ void Stat_ReadFile(BYTE n) ProtoList[n].AllStatistics[0].Month = stNow.wMonth;
ProtoList[n].AllStatistics[0].Year = stNow.wYear;
ProtoList[n].AllStatistics[0].Incoming =
- ProtoList[n].AllStatistics[0].Outgoing =
- ProtoList[n].AllStatistics[0].Time = 0;
+ ProtoList[n].AllStatistics[0].Outgoing =
+ ProtoList[n].AllStatistics[0].Time = 0;
}
Stat_CheckStatistics(n);
}
@@ -382,47 +363,41 @@ void Stat_UpdateTotalTraffic(HWND hwndDialog, DWORD Incoming, DWORD Outgoing) /*
Функция сравнивает с текущим время последней записи в статистике для аккаунта с номером n.
Если они совпадают, ничего не происходит.
-Если текущее время меньше времени последней записи (часы перевели назад),
- количество записей уменьшается на соответствующее количество часов.
+Если текущее время меньше времени последней записи (часы перевели назад),
+количество записей уменьшается на соответствующее количество часов.
Если текущее время больше, в статистику включается необходимое количество пустых записей.
*/
void Stat_CheckStatistics(BYTE n)
{
- SYSTEMTIME stNow, stLast = {0};
- HOURLYSTATS htTmp = {0};
+ SYSTEMTIME stNow, stLast = { 0 };
+ HOURLYSTATS htTmp = { 0 };
signed short int d;//, i;
DWORD q;
- stLast.wHour = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords-1].Hour;
- stLast.wDay = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords-1].Day;
- stLast.wMonth = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords-1].Month;
- stLast.wYear = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords-1].Year;
-
+ stLast.wHour = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1].Hour;
+ stLast.wDay = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1].Day;
+ stLast.wMonth = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1].Month;
+ stLast.wYear = ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1].Year;
+
GetLocalTime(&stNow);
d = TimeCompare(stNow, stLast);
// Если текущее время совпадает со временем последней записи...
- if (!d)
- {
+ if (!d) {
// ...сохраняем запись в файл и уходим.
- SetFilePointer(ProtoList[n].hFile, 0-sizeof(HOURLYSTATS), NULL, FILE_END);
- WriteFile(ProtoList[n].hFile, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords-1], sizeof(HOURLYSTATS), &q, NULL);
- return;
+ SetFilePointer(ProtoList[n].hFile, -LONG(sizeof(HOURLYSTATS)), NULL, FILE_END);
+ WriteFile(ProtoList[n].hFile, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1], sizeof(HOURLYSTATS), &q, NULL);
+ return;
}
// Если часы перевели назад.
- if (d < 0)
- {
- do
- {
+ if (d < 0) {
+ do {
stLast.wHour--;
- if (stLast.wHour == 0xFFFF)
- {
+ if (stLast.wHour == 0xFFFF) {
stLast.wDay--;
- if (!stLast.wDay)
- {
+ if (!stLast.wDay) {
stLast.wMonth--;
- if (!stLast.wMonth)
- {
+ if (!stLast.wMonth) {
stLast.wMonth = 12;
stLast.wYear--;
}
@@ -432,35 +407,30 @@ void Stat_CheckStatistics(BYTE n) ProtoList[n].NumberOfRecords--;
} while (TimeCompare(stNow, stLast));
- return;
+ return;
}
- if (d > 0)
- {
+ if (d > 0) {
// Сохраняем.
- SetFilePointer(ProtoList[n].hFile, 0-sizeof(HOURLYSTATS), NULL, FILE_END);
- WriteFile(ProtoList[n].hFile, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords-1], sizeof(HOURLYSTATS), &q, NULL);
+ SetFilePointer(ProtoList[n].hFile, -LONG(sizeof(HOURLYSTATS)), NULL, FILE_END);
+ WriteFile(ProtoList[n].hFile, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1], sizeof(HOURLYSTATS), &q, NULL);
// Последняя запись из статистики понадобится для вычисления новых записей, поэтому копируем её (кроме трафика и времени).
memcpy(&htTmp, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1],
- sizeof(HOURLYSTATS) - 2 * sizeof(DWORD) - sizeof(WORD));
+ sizeof(HOURLYSTATS) - 2 * sizeof(DWORD) - sizeof(WORD));
// Счётчик времени каждый час должен начинать считать с нуля.
ProtoList[n].Total.TimeAtStart = GetTickCount() - stNow.wMilliseconds;
- do
- {
+ do {
ProtoList[n].AllStatistics =
(HOURLYSTATS*)mir_realloc(ProtoList[n].AllStatistics, sizeof(HOURLYSTATS) * ++ProtoList[n].NumberOfRecords);
htTmp.Hour++;
- if (htTmp.Hour > 23)
- {
+ if (htTmp.Hour > 23) {
htTmp.Hour = 0; htTmp.Day++;
- if (htTmp.Day > DaysInMonth(htTmp.Month, htTmp.Year))
- {
+ if (htTmp.Day > DaysInMonth(htTmp.Month, htTmp.Year)) {
htTmp.Day = 1; htTmp.Month++;
- if (htTmp.Month > 12)
- {
+ if (htTmp.Month > 12) {
htTmp.Month = 1; htTmp.Year++;
}
}
@@ -488,11 +458,10 @@ stReq - дата, соответствующая вычисленному индексу. DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, DWORD ItemNumber, SYSTEMTIME *stReq)
{
DWORD Left, Right, Probe; // Границы интервала для поиска (индексы статистики).
- SYSTEMTIME stProbe = {0}; // Время тыка.
+ SYSTEMTIME stProbe = { 0 }; // Время тыка.
signed short int d = 1;
- if (!ItemNumber)
- {
+ if (!ItemNumber) {
stReq->wHour = ProtoList[AccNum].AllStatistics[0].Hour;
stReq->wDay = ProtoList[AccNum].AllStatistics[0].Day;
stReq->wMonth = ProtoList[AccNum].AllStatistics[0].Month;
@@ -501,36 +470,34 @@ DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, DWORD ItemNumber, SYSTEMTIM }
// Вычисляем время, соответствующее началу интервала.
- for (Probe = 0, Left = 1; Left < ProtoList[AccNum].NumberOfRecords; Left++)
- {
- switch(Interval)
- {
- case STAT_INTERVAL_HOUR:
- stReq->wHour = ProtoList[AccNum].AllStatistics[ItemNumber].Hour;
- stReq->wDay = ProtoList[AccNum].AllStatistics[ItemNumber].Day;
- stReq->wMonth = ProtoList[AccNum].AllStatistics[ItemNumber].Month;
- stReq->wYear = ProtoList[AccNum].AllStatistics[ItemNumber].Year;
- return ItemNumber;
- break;
- case STAT_INTERVAL_DAY:
- if (ProtoList[AccNum].AllStatistics[Left].Day != ProtoList[AccNum].AllStatistics[Left - 1].Day)
- Probe++;
- break;
- case STAT_INTERVAL_WEEK:
- if ( !ProtoList[AccNum].AllStatistics[Left].Hour
- && DayOfWeek(ProtoList[AccNum].AllStatistics[Left].Day,
- ProtoList[AccNum].AllStatistics[Left].Month,
- ProtoList[AccNum].AllStatistics[Left].Year) == 1)
- Probe++;
- break;
- case STAT_INTERVAL_MONTH:
- if (ProtoList[AccNum].AllStatistics[Left].Month != ProtoList[AccNum].AllStatistics[Left - 1].Month)
- Probe++;
- break;
- case STAT_INTERVAL_YEAR:
- if (ProtoList[AccNum].AllStatistics[Left].Year != ProtoList[AccNum].AllStatistics[Left - 1].Year)
- Probe++;
- break;
+ for (Probe = 0, Left = 1; Left < ProtoList[AccNum].NumberOfRecords; Left++) {
+ switch (Interval) {
+ case STAT_INTERVAL_HOUR:
+ stReq->wHour = ProtoList[AccNum].AllStatistics[ItemNumber].Hour;
+ stReq->wDay = ProtoList[AccNum].AllStatistics[ItemNumber].Day;
+ stReq->wMonth = ProtoList[AccNum].AllStatistics[ItemNumber].Month;
+ stReq->wYear = ProtoList[AccNum].AllStatistics[ItemNumber].Year;
+ return ItemNumber;
+ break;
+ case STAT_INTERVAL_DAY:
+ if (ProtoList[AccNum].AllStatistics[Left].Day != ProtoList[AccNum].AllStatistics[Left - 1].Day)
+ Probe++;
+ break;
+ case STAT_INTERVAL_WEEK:
+ if (!ProtoList[AccNum].AllStatistics[Left].Hour
+ && DayOfWeek(ProtoList[AccNum].AllStatistics[Left].Day,
+ ProtoList[AccNum].AllStatistics[Left].Month,
+ ProtoList[AccNum].AllStatistics[Left].Year) == 1)
+ Probe++;
+ break;
+ case STAT_INTERVAL_MONTH:
+ if (ProtoList[AccNum].AllStatistics[Left].Month != ProtoList[AccNum].AllStatistics[Left - 1].Month)
+ Probe++;
+ break;
+ case STAT_INTERVAL_YEAR:
+ if (ProtoList[AccNum].AllStatistics[Left].Year != ProtoList[AccNum].AllStatistics[Left - 1].Year)
+ Probe++;
+ break;
}
if (Probe == ItemNumber) break;
}
@@ -543,8 +510,7 @@ DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, DWORD ItemNumber, SYSTEMTIM Left = 0; Right = ProtoList[AccNum].NumberOfRecords - 1;
// Вычисляем индекс начала интервала.
- while (TRUE)
- {
+ while (TRUE) {
if (Right - Left == 1) return Right;
Probe = (Left + Right) >> 1;
stProbe.wYear = ProtoList[AccNum].AllStatistics[Probe].Year;
@@ -565,11 +531,10 @@ DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, DWORD ItemNumber, SYSTEMTIM void Stat_SetAccShift(BYTE AccNum, BYTE EldestAccount)
{
DWORD Left, Right, Probe = 0; // Границы интервала для поиска (индексы статистики).
- SYSTEMTIME stReq = {0}, stProbe;
+ SYSTEMTIME stReq = { 0 }, stProbe;
signed short int d = 1;
- if (AccNum == EldestAccount)
- {
+ if (AccNum == EldestAccount) {
ProtoList[AccNum].Shift = 0;
return;
}
@@ -581,10 +546,8 @@ void Stat_SetAccShift(BYTE AccNum, BYTE EldestAccount) // Вычисляем индекс начала интервала.
Left = 0; Right = ProtoList[EldestAccount].NumberOfRecords - 1;
- while (TRUE)
- {
- if (Right - Left == 1)
- {
+ while (TRUE) {
+ if (Right - Left == 1) {
ProtoList[AccNum].Shift = Probe + d;
return;
}
@@ -608,10 +571,11 @@ SelectedAccs - слово, в котором единичные биты соответствуют выбранным аккаунтам Interval - выбранный интервал;
ItemNum - номер строки в ListVew;
SubitemNum - номер колонки, определяет вид информации. */
+
DWORD Stat_GetItemValue(WORD SelectedAccs, BYTE Interval, DWORD ItemNum, BYTE SubItemNum)
{
DWORD Result = 0;
- SYSTEMTIME st = {0};
+ SYSTEMTIME st = { 0 };
DWORD Index, IndexP, i;
signed long int IndexM;
BYTE a, EldestAcc;
@@ -619,62 +583,58 @@ DWORD Stat_GetItemValue(WORD SelectedAccs, BYTE Interval, DWORD ItemNum, BYTE Su EldestAcc = Stat_GetEldestAcc(SelectedAccs);
Index = Stat_GetStartIndex(EldestAcc, Interval, ItemNum, &st);
- for (a = NumberOfAccounts; a--; )
- {
+ for (a = NumberOfAccounts; a--;) {
if (!((1 << a) & SelectedAccs)) continue;
Stat_SetAccShift(a, EldestAcc);
IndexM = Index - ProtoList[a].Shift;
IndexP = Index;
- for (i = 0; ; )
- {
+ for (i = 0;;) {
if (IndexM >= 0)
- switch (SubItemNum)
- {
- case 1: // Входящий
- Result += ProtoList[a].AllStatistics[IndexM].Incoming;
- break;
- case 2: // Исходящий
- Result += ProtoList[a].AllStatistics[IndexM].Outgoing;
- break;
- case 3: // Сумма
- Result += ProtoList[a].AllStatistics[IndexM].Incoming
- + ProtoList[a].AllStatistics[IndexM].Outgoing;
- break;
- case 4: // Время
- Result += ProtoList[a].AllStatistics[IndexM].Time;
- break;
- }
-
- IndexM++; IndexP++; // Переходим к следующей записи.
- if (IndexM == ProtoList[a].NumberOfRecords) break;
-
- // Когда остановиться?
- switch (Interval)
- {
- case STAT_INTERVAL_HOUR:
- i = 1; // Новый час начинается каждый час.
+ switch (SubItemNum) {
+ case 1: // Входящий
+ Result += ProtoList[a].AllStatistics[IndexM].Incoming;
break;
- case STAT_INTERVAL_DAY:
- i = (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
+ case 2: // Исходящий
+ Result += ProtoList[a].AllStatistics[IndexM].Outgoing;
break;
- case STAT_INTERVAL_WEEK:
- i = (1 == DayOfWeek(ProtoList[EldestAcc].AllStatistics[IndexP].Day,
- ProtoList[EldestAcc].AllStatistics[IndexP].Month,
- ProtoList[EldestAcc].AllStatistics[IndexP].Year))
- && (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
+ case 3: // Сумма
+ Result += ProtoList[a].AllStatistics[IndexM].Incoming
+ + ProtoList[a].AllStatistics[IndexM].Outgoing;
break;
- case STAT_INTERVAL_MONTH:
- i = (1 == ProtoList[EldestAcc].AllStatistics[IndexP].Day)
- && (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
- break;
- case STAT_INTERVAL_YEAR:
- i = (1 == ProtoList[EldestAcc].AllStatistics[IndexP].Month)
- && (1 == ProtoList[EldestAcc].AllStatistics[IndexP].Day)
- && (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
+ case 4: // Время
+ Result += ProtoList[a].AllStatistics[IndexM].Time;
break;
}
+ IndexM++; IndexP++; // Переходим к следующей записи.
+ if (IndexM == ProtoList[a].NumberOfRecords) break;
+
+ // Когда остановиться?
+ switch (Interval) {
+ case STAT_INTERVAL_HOUR:
+ i = 1; // Новый час начинается каждый час.
+ break;
+ case STAT_INTERVAL_DAY:
+ i = (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
+ break;
+ case STAT_INTERVAL_WEEK:
+ i = (1 == DayOfWeek(ProtoList[EldestAcc].AllStatistics[IndexP].Day,
+ ProtoList[EldestAcc].AllStatistics[IndexP].Month,
+ ProtoList[EldestAcc].AllStatistics[IndexP].Year))
+ && (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
+ break;
+ case STAT_INTERVAL_MONTH:
+ i = (1 == ProtoList[EldestAcc].AllStatistics[IndexP].Day)
+ && (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
+ break;
+ case STAT_INTERVAL_YEAR:
+ i = (1 == ProtoList[EldestAcc].AllStatistics[IndexP].Month)
+ && (1 == ProtoList[EldestAcc].AllStatistics[IndexP].Day)
+ && (0 == ProtoList[EldestAcc].AllStatistics[IndexP].Hour);
+ break;
+ }
+
if (i) break;
}
}
@@ -689,36 +649,35 @@ DWORD Stat_GetRecordsNumber(BYTE AccNum, BYTE Interval) DWORD Result, i;
// Нужно узнать количество записей.
- switch (Interval)
- {
- case STAT_INTERVAL_HOUR:
- Result = ProtoList[AccNum].NumberOfRecords; // Для почасовой статистики совпадает.
- break;
- case STAT_INTERVAL_DAY:
- for (Result = 1, i = ProtoList[AccNum].NumberOfRecords - 1; i--; )
- if (ProtoList[AccNum].AllStatistics[i].Day != ProtoList[AccNum].AllStatistics[i+1].Day)
- Result++;
- break;
- case STAT_INTERVAL_WEEK:
- for (Result = 1, i = ProtoList[AccNum].NumberOfRecords; i--; )
- if ( ProtoList[AccNum].AllStatistics[i].Hour == 23
- && DayOfWeek(ProtoList[AccNum].AllStatistics[i].Day,
- ProtoList[AccNum].AllStatistics[i].Month,
- ProtoList[AccNum].AllStatistics[i].Year) == 7)
- Result++;
- break;
- case STAT_INTERVAL_MONTH:
- for (Result = 1, i = ProtoList[AccNum].NumberOfRecords - 1; i--; )
- if (ProtoList[AccNum].AllStatistics[i].Month != ProtoList[AccNum].AllStatistics[i+1].Month)
- Result++;
- break;
- case STAT_INTERVAL_YEAR:
- for (Result = 1, i = ProtoList[AccNum].NumberOfRecords - 1; i--; )
- if (ProtoList[AccNum].AllStatistics[i].Year != ProtoList[AccNum].AllStatistics[i+1].Year)
- Result++;
- break;
- default:
- return 0;
+ switch (Interval) {
+ case STAT_INTERVAL_HOUR:
+ Result = ProtoList[AccNum].NumberOfRecords; // Для почасовой статистики совпадает.
+ break;
+ case STAT_INTERVAL_DAY:
+ for (Result = 1, i = ProtoList[AccNum].NumberOfRecords - 1; i--;)
+ if (ProtoList[AccNum].AllStatistics[i].Day != ProtoList[AccNum].AllStatistics[i + 1].Day)
+ Result++;
+ break;
+ case STAT_INTERVAL_WEEK:
+ for (Result = 1, i = ProtoList[AccNum].NumberOfRecords; i--;)
+ if (ProtoList[AccNum].AllStatistics[i].Hour == 23
+ && DayOfWeek(ProtoList[AccNum].AllStatistics[i].Day,
+ ProtoList[AccNum].AllStatistics[i].Month,
+ ProtoList[AccNum].AllStatistics[i].Year) == 7)
+ Result++;
+ break;
+ case STAT_INTERVAL_MONTH:
+ for (Result = 1, i = ProtoList[AccNum].NumberOfRecords - 1; i--;)
+ if (ProtoList[AccNum].AllStatistics[i].Month != ProtoList[AccNum].AllStatistics[i + 1].Month)
+ Result++;
+ break;
+ case STAT_INTERVAL_YEAR:
+ for (Result = 1, i = ProtoList[AccNum].NumberOfRecords - 1; i--;)
+ if (ProtoList[AccNum].AllStatistics[i].Year != ProtoList[AccNum].AllStatistics[i + 1].Year)
+ Result++;
+ break;
+ default:
+ return 0;
}
return Result;
@@ -730,19 +689,16 @@ BYTE Stat_GetEldestAcc(WORD SelectedAccs) // Узнаём номер аккаунта из числа выбранных, имеющего самую старую первую запись.
// (Это аккаунт с максимальным количеством записей.)
- for (Result = i = 0; i < NumberOfAccounts; i++)
- {
+ for (Result = i = 0; i < NumberOfAccounts; i++) {
// Надо с чего-то начать поиск.
- if ( 0x01 & (SelectedAccs >> i))
- {
+ if (0x01 & (SelectedAccs >> i)) {
Result = i;
break;
}
}
// Продолжаем поиск.
- for (; ++i < NumberOfAccounts; )
- {
- if ( 0x01 & (SelectedAccs >> i) && (ProtoList[i].NumberOfRecords > ProtoList[Result].NumberOfRecords) )
+ for (; ++i < NumberOfAccounts;) {
+ if (0x01 & (SelectedAccs >> i) && (ProtoList[i].NumberOfRecords > ProtoList[Result].NumberOfRecords))
Result = i;
}
|