From 27b6fd54990d07079501748d9c75cf21e7c1afee Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 23 May 2018 13:21:08 +0300 Subject: TrafficCounter: - fixes #1376 (Traffic counter: crash with empty statistic); - massive code cleaning; - version bump --- plugins/TrafficCounter/src/TrafficCounter.cpp | 167 +++++++++++--------------- plugins/TrafficCounter/src/misc.cpp | 14 +-- plugins/TrafficCounter/src/statistics.cpp | 88 +++++++------- plugins/TrafficCounter/src/statistics.h | 6 +- plugins/TrafficCounter/src/stdafx.h | 27 +++-- plugins/TrafficCounter/src/version.h | 14 +-- 6 files changed, 143 insertions(+), 173 deletions(-) (limited to 'plugins/TrafficCounter/src') diff --git a/plugins/TrafficCounter/src/TrafficCounter.cpp b/plugins/TrafficCounter/src/TrafficCounter.cpp index a270682bfd..1c116c4071 100644 --- a/plugins/TrafficCounter/src/TrafficCounter.cpp +++ b/plugins/TrafficCounter/src/TrafficCounter.cpp @@ -609,9 +609,6 @@ 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) @@ -637,16 +634,20 @@ LRESULT CALLBACK TrafficCounterWndProc_MW(HWND hwnd, UINT msg, WPARAM wParam, LP case WM_LBUTTONDOWN: if (db_get_b(NULL, "CLUI", "ClientAreaDrag", SETTING_CLIENTDRAG_DEFAULT)) { + POINT p; 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, nullptr); + { + POINT p; + 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, nullptr); + } break; case WM_COMMAND: @@ -656,12 +657,11 @@ LRESULT CALLBACK TrafficCounterWndProc_MW(HWND hwnd, UINT msg, WPARAM wParam, LP 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(); + for (int i = 0; i < NumberOfAccounts; i++) { + auto &p = ProtoList[i]; + p.StartIncoming = p.AllStatistics[p.NumberOfRecords - 1].Incoming; + p.StartOutgoing = p.AllStatistics[p.NumberOfRecords - 1].Outgoing; + p.Session.TimeAtStart = GetTickCount(); } OverallInfo.CurrentRecvTraffic = OverallInfo.CurrentSentTraffic = 0; } @@ -707,44 +707,45 @@ LRESULT CALLBACK TrafficCounterWndProc_MW(HWND hwnd, UINT msg, WPARAM wParam, LP 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; + for (int i = 0; i < NumberOfAccounts; i++) { + auto &p = ProtoList[i]; + if (p.State) { + p.AllStatistics[p.NumberOfRecords - 1].Time = + (CurrentTimeMs - p.Total.TimeAtStart) / 1000; + p.Session.Timer = + (CurrentTimeMs - p.Session.TimeAtStart) / 1000; } - Stat_CheckStatistics(i); - - { // Здесь на основании статистики вычисляются значения всех трафиков и времени. + Stat_CheckStatistics(p); + { + // Здесь на основании статистики вычисляются значения всех трафиков и времени. 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; + for (Sum1 = Sum2 = 0, j = p.StartIndex; j < p.NumberOfRecords; j++) { + Sum1 += p.AllStatistics[j].Incoming; + Sum2 += p.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; + p.CurrentRecvTraffic = Sum1 - p.StartIncoming; + p.CurrentSentTraffic = Sum2 - p.StartOutgoing; + OverallInfo.CurrentRecvTraffic += p.CurrentRecvTraffic; + OverallInfo.CurrentSentTraffic += p.CurrentSentTraffic; // Значения для выбранного периода. - ProtoList[i].TotalRecvTraffic = + p.TotalRecvTraffic = Stat_GetItemValue(1 << i, unOptions.PeriodForShow + 1, Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1, 1); - ProtoList[i].TotalSentTraffic = + p.TotalSentTraffic = Stat_GetItemValue(1 << i, unOptions.PeriodForShow + 1, Stat_GetRecordsNumber(i, unOptions.PeriodForShow + 1) - 1, 2); - ProtoList[i].Total.Timer = + p.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; + OverallInfo.TotalRecvTraffic += p.TotalRecvTraffic; + OverallInfo.TotalSentTraffic += p.TotalSentTraffic; } } // Не пора ли уведомить? @@ -762,33 +763,15 @@ LRESULT CALLBACK TrafficCounterWndProc_MW(HWND hwnd, UINT msg, WPARAM wParam, LP 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)) + 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; + 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); @@ -796,40 +779,35 @@ LRESULT CALLBACK TrafficCounterWndProc_MW(HWND hwnd, UINT msg, WPARAM wParam, LP break; case TIMER_TOOLTIP: - { - wchar_t *TooltipText; - CLCINFOTIP ti = { 0 }; - RECT rt; + GetCursorPos(&TooltipPosition); + if (!TooltipShowing && unOptions.ShowTooltip) { + KillTimer(TrafficHwnd, TIMER_TOOLTIP); + ScreenToClient(TrafficHwnd, &TooltipPosition); - 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, nullptr, NULL); - - CallService(MS_TIPPER_SHOWTIPW, (WPARAM)TooltipText, (LPARAM)&ti); - - TooltipShowing = TRUE; - mir_free(TooltipText); - } + RECT rt; + GetClientRect(TrafficHwnd, &rt); + if (PtInRect(&rt, TooltipPosition)) { + GetCursorPos(&ptMouse); + + CLCINFOTIP ti = { 0 }; + 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); + + wchar_t *TooltipText = variables_parsedup(Traffic_TooltipFormat, nullptr, NULL); + CallService(MS_TIPPER_SHOWTIPW, (WPARAM)TooltipText, (LPARAM)&ti); + mir_free(TooltipText); + + TooltipShowing = TRUE; } } break; } break; - - default: - return DefWindowProc(hwnd, msg, wParam, lParam); } - // + return DefWindowProc(hwnd, msg, wParam, lParam); } @@ -948,21 +926,17 @@ void CreateProtocolList(void) auto &accs = Accounts(); NumberOfAccounts = accs.getCount(); - ProtoList = (PROTOLIST*)mir_alloc(sizeof(PROTOLIST)*NumberOfAccounts); + ProtoList = (PROTOLIST*)mir_calloc(sizeof(PROTOLIST)*NumberOfAccounts); int i = 0; for (auto &pa : accs) { auto &p = ProtoList[i++]; p.name = mir_strdup(pa->szModuleName); p.tszAccountName = mir_wstrdup(pa->tszAccountName); - p.Flags = db_get_b(NULL, p.name, SETTINGS_PROTO_FLAGS, 3); - p.CurrentRecvTraffic = p.CurrentSentTraffic = p.Session.Timer = 0; - p.Enabled = pa->IsEnabled(); - p.State = 0; - Stat_ReadFile(i); + Stat_ReadFile(p); p.StartIndex = p.NumberOfRecords - 1; p.StartIncoming = p.AllStatistics[p.StartIndex].Incoming; p.StartOutgoing = p.AllStatistics[p.StartIndex].Outgoing; @@ -975,11 +949,12 @@ void CreateProtocolList(void) void DestroyProtocolList(void) { for (int i = 0; i < NumberOfAccounts; i++) { - Stat_CheckStatistics(i); - CloseHandle(ProtoList[i].hFile); - mir_free(ProtoList[i].tszAccountName); - mir_free(ProtoList[i].name); - mir_free(ProtoList[i].AllStatistics); + auto &p = ProtoList[i]; + Stat_CheckStatistics(p); + CloseHandle(p.hFile); + mir_free(p.tszAccountName); + mir_free(p.name); + mir_free(p.AllStatistics); } mir_free(ProtoList); diff --git a/plugins/TrafficCounter/src/misc.cpp b/plugins/TrafficCounter/src/misc.cpp index 3e8b231e07..2ea49fbf10 100644 --- a/plugins/TrafficCounter/src/misc.cpp +++ b/plugins/TrafficCounter/src/misc.cpp @@ -177,19 +177,15 @@ Size - размер буфера. */ size_t GetDurationFormatM(DWORD Duration, wchar_t *Format, wchar_t *Buffer, size_t Size) { size_t Length; - DWORD q; - WORD TokenIndex, FormatIndex; - wchar_t Token[256], // Аккумулятор. - *Res; // Промежуточный результат. + wchar_t Token[256]; // Аккумулятор. - Res = (wchar_t*)malloc(sizeof(wchar_t)); // Выделяем чуть-чуть памяти под результат, но это только начало. - //SecureZeroMemory(Res, sizeof(wchar_t)); + wchar_t *Res = (wchar_t*)malloc(sizeof(wchar_t)); // Выделяем чуть-чуть памяти под результат, но это только начало. Res[0] = 0; - for (FormatIndex = 0; Format[FormatIndex];) { + for (int FormatIndex = 0; Format[FormatIndex];) { // Ищем токены. Считается, что токен - только буквы. - TokenIndex = 0; - q = iswalpha(Format[FormatIndex]); + int TokenIndex = 0; + int q = iswalpha(Format[FormatIndex]); // Копируем символы в аккумулятор до смены флага. do { Token[TokenIndex++] = Format[FormatIndex++]; diff --git a/plugins/TrafficCounter/src/statistics.cpp b/plugins/TrafficCounter/src/statistics.cpp index 5451e7158e..a0872b769e 100644 --- a/plugins/TrafficCounter/src/statistics.cpp +++ b/plugins/TrafficCounter/src/statistics.cpp @@ -29,8 +29,6 @@ HWND hListAccs; INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - WORD i; - switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); @@ -41,12 +39,12 @@ INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPA 2, 20, 246, 112, hwndDlg, nullptr, nullptr, nullptr); SendMessage(hListAccs, WM_SETFONT, (WPARAM)(HFONT)GetStockObject(DEFAULT_GUI_FONT), 0); - for (i = 0; i < NumberOfAccounts; i++) { + for (int i = 0; i < NumberOfAccounts; i++) { // Готовим список аккаунтов if (ProtoList[i].tszAccountName) SendMessage(hListAccs, LB_ADDSTRING, 0, (LPARAM)ProtoList[i].tszAccountName); } - for (i = NumberOfAccounts; i--;) + for (int 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")); @@ -112,7 +110,8 @@ INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPA LB_GETSELITEMS, SelItemsCount, (LPARAM)SelItems); - for (Stat_SelAcc = i = 0; i < SelItemsCount; i++) + Stat_SelAcc = 0; + for (int i = 0; i < SelItemsCount; i++) Stat_SelAcc |= 1 << SelItems[i]; Stat_Show(hwndDlg); } @@ -133,7 +132,7 @@ INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPA MB_OKCANCEL | MB_ICONWARNING)) break; GetLocalTime(&stNow); - for (i = NumberOfAccounts; i--;) + for (int i = NumberOfAccounts; i--;) if (0x01 & (Stat_SelAcc >> i)) { SetFilePointer(ProtoList[i].hFile, sizeof(HOURLYSTATS), nullptr, FILE_BEGIN); SetEndOfFile(ProtoList[i].hFile); // Усекаем файл до одной записи. @@ -149,7 +148,7 @@ INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPA ProtoList[i].StartOutgoing = 0; ProtoList[i].AllStatistics[0].Time = 0; ProtoList[i].Total.TimeAtStart = GetTickCount(); - Stat_CheckStatistics(i); + Stat_CheckStatistics(ProtoList[i]); } Stat_Show(hwndDlg); } @@ -242,7 +241,7 @@ INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPA { DWORD j = -1, dwTotalIncoming = 0, dwTotalOutgoing = 0; - i = SendDlgItemMessage(hwndDlg, IDC_LIST_DATA, LVM_GETSELECTEDCOUNT, 0, 0); + int 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); @@ -293,7 +292,7 @@ INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPA /* Функция читает статистику из файла для аккаунта с номером n. */ -void Stat_ReadFile(BYTE n) +void Stat_ReadFile(PROTOLIST &p) { LARGE_INTEGER Size; DWORD BytesRead; @@ -302,18 +301,18 @@ void Stat_ReadFile(BYTE n) pszPath = Utils_ReplaceVarsW(L"%miranda_userdata%\\statistics"); CreateDirectoryTreeW(pszPath); - mir_snwprintf(FileName, L"%s\\%S.stat", pszPath, ProtoList[n].name); + mir_snwprintf(FileName, L"%s\\%S.stat", pszPath, p.name); mir_free(pszPath); GetLocalTime(&stNow); - ProtoList[n].hFile = CreateFile(FileName, GENERIC_READ | GENERIC_WRITE, + p.hFile = CreateFile(FileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - GetFileSizeEx(ProtoList[n].hFile, &Size); + GetFileSizeEx(p.hFile, &Size); if (Size.QuadPart != 0) // Если файл со статистикой существует и имеет ненулевой размер... { // ...то читаем статистику из файла - 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, nullptr); + p.NumberOfRecords = DWORD(Size.QuadPart / sizeof(HOURLYSTATS)); + p.AllStatistics = (HOURLYSTATS*)mir_alloc(sizeof(HOURLYSTATS)*p.NumberOfRecords); + ReadFile(p.hFile, &p.AllStatistics[0], sizeof(HOURLYSTATS)*p.NumberOfRecords, &BytesRead, nullptr); if (!BytesRead) { MessageBox(TrafficHwnd, TranslateT("Couldn't read statistics file"), TranslateT("Traffic Counter"), MB_OK); return; @@ -321,17 +320,15 @@ void Stat_ReadFile(BYTE n) } else { // Необходимо создать новый файл. - ProtoList[n].NumberOfRecords = 1; - ProtoList[n].AllStatistics = (HOURLYSTATS*)mir_alloc(sizeof(HOURLYSTATS)); - ProtoList[n].AllStatistics[0].Hour = stNow.wHour; - ProtoList[n].AllStatistics[0].Day = stNow.wDay; - 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; + p.NumberOfRecords = 1; + p.AllStatistics = (HOURLYSTATS*)mir_alloc(sizeof(HOURLYSTATS)); + p.AllStatistics[0].Hour = stNow.wHour; + p.AllStatistics[0].Day = stNow.wDay; + p.AllStatistics[0].Month = stNow.wMonth; + p.AllStatistics[0].Year = stNow.wYear; + p.AllStatistics[0].Incoming = p.AllStatistics[0].Outgoing = p.AllStatistics[0].Time = 0; } - Stat_CheckStatistics(n); + Stat_CheckStatistics(p); } /* Функция готовит вывод в ListView статистики. @@ -367,25 +364,25 @@ void Stat_UpdateTotalTraffic(HWND hwndDialog, DWORD Incoming, DWORD Outgoing) количество записей уменьшается на соответствующее количество часов. Если текущее время больше, в статистику включается необходимое количество пустых записей. */ -void Stat_CheckStatistics(BYTE n) +void Stat_CheckStatistics(PROTOLIST &p) { 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 = p.AllStatistics[p.NumberOfRecords - 1].Hour; + stLast.wDay = p.AllStatistics[p.NumberOfRecords - 1].Day; + stLast.wMonth = p.AllStatistics[p.NumberOfRecords - 1].Month; + stLast.wYear = p.AllStatistics[p.NumberOfRecords - 1].Year; GetLocalTime(&stNow); d = TimeCompare(stNow, stLast); // Если текущее время совпадает со временем последней записи... if (!d) { // ...сохраняем запись в файл и уходим. - SetFilePointer(ProtoList[n].hFile, -LONG(sizeof(HOURLYSTATS)), nullptr, FILE_END); - WriteFile(ProtoList[n].hFile, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1], sizeof(HOURLYSTATS), &q, nullptr); + SetFilePointer(p.hFile, -LONG(sizeof(HOURLYSTATS)), nullptr, FILE_END); + WriteFile(p.hFile, &p.AllStatistics[p.NumberOfRecords - 1], sizeof(HOURLYSTATS), &q, nullptr); return; } @@ -405,25 +402,25 @@ void Stat_CheckStatistics(BYTE n) } } - ProtoList[n].NumberOfRecords--; + p.NumberOfRecords--; } while (TimeCompare(stNow, stLast)); return; } if (d > 0) { // Сохраняем. - SetFilePointer(ProtoList[n].hFile, -LONG(sizeof(HOURLYSTATS)), nullptr, FILE_END); - WriteFile(ProtoList[n].hFile, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1], sizeof(HOURLYSTATS), &q, nullptr); + SetFilePointer(p.hFile, -LONG(sizeof(HOURLYSTATS)), nullptr, FILE_END); + WriteFile(p.hFile, &p.AllStatistics[p.NumberOfRecords - 1], sizeof(HOURLYSTATS), &q, nullptr); // Последняя запись из статистики понадобится для вычисления новых записей, поэтому копируем её (кроме трафика и времени). - memcpy(&htTmp, &ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1], + memcpy(&htTmp, &p.AllStatistics[p.NumberOfRecords - 1], sizeof(HOURLYSTATS) - 2 * sizeof(DWORD) - sizeof(WORD)); // Счётчик времени каждый час должен начинать считать с нуля. - ProtoList[n].Total.TimeAtStart = GetTickCount() - stNow.wMilliseconds; + p.Total.TimeAtStart = GetTickCount() - stNow.wMilliseconds; do { - ProtoList[n].AllStatistics = - (HOURLYSTATS*)mir_realloc(ProtoList[n].AllStatistics, sizeof(HOURLYSTATS) * ++ProtoList[n].NumberOfRecords); + p.AllStatistics = + (HOURLYSTATS*)mir_realloc(p.AllStatistics, sizeof(HOURLYSTATS) * ++p.NumberOfRecords); htTmp.Hour++; if (htTmp.Hour > 23) { @@ -442,8 +439,8 @@ void Stat_CheckStatistics(BYTE n) stLast.wYear = htTmp.Year; // Добавляем записи одновременно в ОЗУ и в файл. - WriteFile(ProtoList[n].hFile, &htTmp, sizeof(HOURLYSTATS), &q, nullptr); - memcpy(&ProtoList[n].AllStatistics[ProtoList[n].NumberOfRecords - 1], &htTmp, sizeof(HOURLYSTATS)); + WriteFile(p.hFile, &htTmp, sizeof(HOURLYSTATS), &q, nullptr); + memcpy(&p.AllStatistics[p.NumberOfRecords - 1], &htTmp, sizeof(HOURLYSTATS)); } while (TimeCompare(stNow, stLast)); } @@ -455,9 +452,9 @@ void Stat_CheckStatistics(BYTE n) ItemNumber - номер строки в ListView (номер периода). stReq - дата, соответствующая вычисленному индексу. */ -DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, DWORD ItemNumber, SYSTEMTIME *stReq) +DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, int ItemNumber, SYSTEMTIME *stReq) { - DWORD Left, Right, Probe; // Границы интервала для поиска (индексы статистики). + int Left, Right, Probe; // Границы интервала для поиска (индексы статистики). SYSTEMTIME stProbe = { 0 }; // Время тыка. signed short int d = 1; @@ -499,7 +496,8 @@ DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, DWORD ItemNumber, SYSTEMTIM Probe++; break; } - if (Probe == ItemNumber) break; + if (Probe == ItemNumber) + break; } stReq->wHour = ProtoList[AccNum].AllStatistics[Left].Hour; @@ -576,7 +574,7 @@ DWORD Stat_GetItemValue(WORD SelectedAccs, BYTE Interval, DWORD ItemNum, BYTE Su { DWORD Result = 0; SYSTEMTIME st = { 0 }; - DWORD Index, IndexP, i; + int Index, IndexP, i; signed long int IndexM; BYTE a, EldestAcc; diff --git a/plugins/TrafficCounter/src/statistics.h b/plugins/TrafficCounter/src/statistics.h index ebe368e27d..7c034779c1 100644 --- a/plugins/TrafficCounter/src/statistics.h +++ b/plugins/TrafficCounter/src/statistics.h @@ -32,11 +32,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define STAT_UNITS_ADAPTIVE 3 INT_PTR CALLBACK DlgProcOptStatistics(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -void Stat_ReadFile(BYTE); +void Stat_ReadFile(PROTOLIST &p); void Stat_Show(HWND); void Stat_UpdateTotalTraffic(HWND, DWORD, DWORD); -void Stat_CheckStatistics(BYTE); -DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, DWORD ItemNumber, SYSTEMTIME *st); +void Stat_CheckStatistics(PROTOLIST &p); +DWORD Stat_GetStartIndex(BYTE AccNum, BYTE Interval, int ItemNumber, SYSTEMTIME *st); void Stat_SetAccShift(BYTE AccNum, BYTE EldestAccount); DWORD Stat_GetItemValue(WORD SelectedAccs, BYTE Interval, DWORD ItemNum, BYTE SubitemNum); DWORD Stat_GetRecordsNumber(BYTE AccNum, BYTE Interval); diff --git a/plugins/TrafficCounter/src/stdafx.h b/plugins/TrafficCounter/src/stdafx.h index a26ac69639..9878720fbc 100644 --- a/plugins/TrafficCounter/src/stdafx.h +++ b/plugins/TrafficCounter/src/stdafx.h @@ -44,19 +44,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +struct CMPlugin : public PLUGIN +{ + CMPlugin(); +}; + #include "resource.h" #include "version.h" #include "misc.h" #include "opttree.h" #include "vars.h" -#include "statistics.h" #include "TrafficCounter.h" -struct CMPlugin : public PLUGIN -{ - CMPlugin(); -}; - #pragma pack(push) #pragma pack(1) typedef struct @@ -74,7 +73,7 @@ typedef struct tagTimer DWORD Timer; // Количество секунд со времени запуска таймера. } TIMER; -typedef struct +struct PROTOLIST { char *name; // Имя аккаунта. @@ -99,21 +98,23 @@ typedef struct }; // Добавлено в версии 0.1.1.0. - DWORD NumberOfRecords; // Количество часов в общей статистике. + int NumberOfRecords; // Количество часов в общей статистике. HOURLYSTATS *AllStatistics; // Полная статистика вместе со статистикой онлайна. HANDLE hFile; // Файл с сохранённой статистикой данного протокола. - DWORD StartIndex; // Номер записи в статистике, бывший актуальным на момент запуска. - DWORD StartIncoming; // Значение входящего трафика на момент запуска. - DWORD StartOutgoing; // Значение исходящего трафика на момент запуска. + int StartIndex; // Номер записи в статистике, бывший актуальным на момент запуска. + int StartIncoming; // Значение входящего трафика на момент запуска. + int StartOutgoing; // Значение исходящего трафика на момент запуска. // 0.1.1.5. - DWORD Shift; // Номер записи в статистике старейшего выбранного аккаунта, + int Shift; // Номер записи в статистике старейшего выбранного аккаунта, // дата которой соответствует началу статистики данного аккаунта. // 0.1.1.6 wchar_t *tszAccountName; // Человеческое имя аккаунта для использования в графическом интерфейсе. -} PROTOLIST; +}; + +#include "statistics.h" //--------------------------------------------------------------------------------------------- // Различные флаги diff --git a/plugins/TrafficCounter/src/version.h b/plugins/TrafficCounter/src/version.h index 6acb2ae8ac..f465ad5020 100644 --- a/plugins/TrafficCounter/src/version.h +++ b/plugins/TrafficCounter/src/version.h @@ -1,13 +1,13 @@ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 1 +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 1 #define __RELEASE_NUM 1 -#define __BUILD_NUM 8 +#define __BUILD_NUM 9 #include #define __PLUGIN_NAME "Traffic counter" #define __FILENAME "TrafficCounter.dll" -#define __DESCRIPTION "Adding traffic and time counters." -#define __AUTHOR "Ghost, Mironych" -#define __AUTHORWEB "https://miranda-ng.org/p/TrafficCounter/" -#define __COPYRIGHT "© 2002-2006 Ghost, 2007-2012 Mironych" +#define __DESCRIPTION "Adding traffic and time counters." +#define __AUTHOR "Ghost, Mironych" +#define __AUTHORWEB "https://miranda-ng.org/p/TrafficCounter/" +#define __COPYRIGHT "© 2002-2006 Ghost, 2007-2012 Mironych" -- cgit v1.2.3