From b2f33c6f47d37635d28b0d754a0b6e499078dd09 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 29 Feb 2024 12:24:22 +0300 Subject: fixes #4254 (CrashDumper to use Windows local date & time format) --- plugins/CrashDumper/src/dumper.cpp | 47 ++++++++++++-------------------------- plugins/CrashDumper/src/stdafx.h | 10 ++++---- plugins/CrashDumper/src/utils.cpp | 26 +++++++++++++-------- plugins/CrashDumper/src/version.h | 2 +- 4 files changed, 35 insertions(+), 50 deletions(-) (limited to 'plugins/CrashDumper/src') diff --git a/plugins/CrashDumper/src/dumper.cpp b/plugins/CrashDumper/src/dumper.cpp index afd2fc566c..66c74b337d 100644 --- a/plugins/CrashDumper/src/dumper.cpp +++ b/plugins/CrashDumper/src/dumper.cpp @@ -59,11 +59,7 @@ BOOL CALLBACK LoadedModules64(LPCSTR, DWORD64 ModuleBase, ULONG ModuleSize, PVOI buffer.AppendFormat(L"%s %p - %p", path, (void*)ModuleBase, (void*)(ModuleBase + ModuleSize)); GetVersionInfo(hModule, buffer); - - wchar_t timebuf[30] = L""; - GetLastWriteTime(path, timebuf, 30); - - buffer.AppendFormat(L" [%s]\r\n", timebuf); + buffer.AppendFormat(L" [%s]\r\n", GetLastWriteTime(path).c_str()); return TRUE; } @@ -175,14 +171,11 @@ static void GetPluginsString(CMStringW &buffer, unsigned &flags) if (hModule == nullptr) { if ((flags & VI_FLAG_PRNVAR) && IsPluginOnWhiteList(_T2A(FindFileData.cFileName))) { - wchar_t timebuf[30] = L""; - GetLastWriteTime(&FindFileData.ftLastWriteTime, timebuf, 30); - ubuffer.AppendFormat(L"\xa4 %s v.%s%d.%d.%d.%d%s [%s] - %S %s\r\n", FindFileData.cFileName, (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", 0, 0, 0, 0, (flags & VI_FLAG_FORMAT) ? L"[/b]" : L"", - timebuf, "", L""); + GetLastWriteTime(&FindFileData.ftLastWriteTime).c_str(), "", L""); GetLinkedModulesInfo(path, ubuffer); ubuffer.Append(L"\r\n"); @@ -194,9 +187,6 @@ static void GetPluginsString(CMStringW &buffer, unsigned &flags) const PLUGININFOEX *pi = GetMirInfo(hModule); if (pi != nullptr) { - wchar_t timebuf[30] = L""; - GetLastWriteTime(&FindFileData.ftLastWriteTime, timebuf, 30); - const wchar_t *unica = !(((PLUGININFOEX*)pi)->flags & UNICODE_AWARE) ? L"|ANSI|" : L""; int v1, v2, v3, v4; @@ -219,7 +209,7 @@ static void GetPluginsString(CMStringW &buffer, unsigned &flags) (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", v1, v2, v3, v4, (flags & VI_FLAG_FORMAT) ? L"[/b]" : L"", - timebuf, pi->shortName ? pi->shortName : "", unica); + GetLastWriteTime(&FindFileData.ftLastWriteTime).c_str(), pi->shortName ? pi->shortName : "", unica); arDlls.insert(tmp.Detach()); if (mir_wstrcmpi(FindFileData.cFileName, L"weather.dll") == 0) @@ -233,7 +223,7 @@ static void GetPluginsString(CMStringW &buffer, unsigned &flags) while (FindNextFile(hFind, &FindFileData)); FindClose(hFind); - buffer.AppendFormat(L"\r\n%sActive Plugins (%u):%s\r\n", (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", count, (flags & VI_FLAG_FORMAT) ? L"[/b]" : L""); + buffer.AppendFormat(L"\r\n%sActive Plugins (%u):%s\r\n", (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", (int)count, (flags & VI_FLAG_FORMAT) ? L"[/b]" : L""); for (auto &str : arDlls) { buffer.Append(str); @@ -241,7 +231,7 @@ static void GetPluginsString(CMStringW &buffer, unsigned &flags) } if (ucount) { - buffer.AppendFormat(L"\r\n%sUnloadable Plugins (%u):%s\r\n", (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", ucount, (flags & VI_FLAG_FORMAT) ? L"[/b]" : L""); + buffer.AppendFormat(L"\r\n%sUnloadable Plugins (%u):%s\r\n", (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", (int)ucount, (flags & VI_FLAG_FORMAT) ? L"[/b]" : L""); buffer.Append(ubuffer); } } @@ -349,14 +339,11 @@ static void GetWeatherStrings(CMStringW &buffer, unsigned flags) id += 5; } - wchar_t timebuf[30] = L""; - GetLastWriteTime(&FindFileData.ftLastWriteTime, timebuf, 30); - buffer.AppendFormat(L" %s v.%s%S%s [%s] - %S\r\n", FindFileData.cFileName, (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", ver, (flags & VI_FLAG_FORMAT) ? L"[/b]" : L"", - timebuf, id); + GetLastWriteTime(&FindFileData.ftLastWriteTime).c_str(), id); CloseHandle(hDumpFile); } } @@ -378,12 +365,10 @@ static void GetIconStrings(CMStringW& buffer) if (hFind == INVALID_HANDLE_VALUE) return; do { - if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue; - - wchar_t timebuf[30] = L""; - GetLastWriteTime(&FindFileData.ftLastWriteTime, timebuf, 30); + if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + continue; - buffer.AppendFormat(L" %s [%s]\r\n", FindFileData.cFileName, timebuf); + buffer.AppendFormat(L" %s [%s]\r\n", FindFileData.cFileName, GetLastWriteTime(&FindFileData.ftLastWriteTime).c_str()); } while (FindNextFile(hFind, &FindFileData)); FindClose(hFind); } @@ -420,10 +405,9 @@ void PrintVersionInfo(CMStringW& buffer, unsigned flags) GetWow64String(buffer); buffer.Append(L"\r\n"); - wchar_t path[MAX_PATH], mirtime[30]; + wchar_t path[MAX_PATH]; GetModuleFileName(nullptr, path, MAX_PATH); - GetLastWriteTime(path, mirtime, 30); - buffer.AppendFormat(L"Build time: %s\r\n", mirtime); + buffer.AppendFormat(L"Build time: %s\r\n", GetLastWriteTime(path).c_str()); wchar_t profpn[MAX_PATH]; mir_snwprintf(profpn, L"%s\\%s", profpathfull, profname); @@ -440,8 +424,8 @@ void PrintVersionInfo(CMStringW& buffer, unsigned flags) FindClose(hFind); unsigned __int64 fsize = (unsigned __int64)FindFileData.nFileSizeHigh << 32 | FindFileData.nFileSizeLow; - buffer.AppendFormat(L"Profile size: %I64u Bytes\r\n", fsize), GetLastWriteTime(&FindFileData.ftCreationTime, mirtime, 30); - buffer.AppendFormat(L"Profile creation date: %s\r\n", mirtime); + buffer.AppendFormat(L"Profile size: %I64u Bytes\r\n", fsize); + buffer.AppendFormat(L"Profile creation date: %s\r\n", GetLastWriteTime(&FindFileData.ftCreationTime).c_str()); } } mir_free(profpathfull); @@ -550,14 +534,11 @@ void CreateCrashReport(HANDLE hDumpFile, PEXCEPTION_POINTERS exc_ptr, const wcha frame.AddrFrame.Mode = AddrModeFlat; frame.AddrStack.Mode = AddrModeFlat; - wchar_t curtime[30]; - GetISO8061Time(nullptr, curtime, 30); - CMStringW buffer; PrintSymbolsInfo(buffer); buffer.AppendFormat(L"Miranda Crash Report from %s. Crash Dumper v.%d.%d.%d.%d\r\n", - curtime, __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM); + GetISO8061Time(nullptr).c_str(), __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM); int crashpos = buffer.GetLength(); diff --git a/plugins/CrashDumper/src/stdafx.h b/plugins/CrashDumper/src/stdafx.h index 72c153afed..ac8546816b 100644 --- a/plugins/CrashDumper/src/stdafx.h +++ b/plugins/CrashDumper/src/stdafx.h @@ -123,12 +123,12 @@ void GetLanguagePackString(CMStringW& buffer); void GetWow64String(CMStringW& buffer); void GetVersionInfo(HMODULE hLib, CMStringW& buffer); -void GetISO8061Time(SYSTEMTIME* stLocal, LPTSTR lpszString, uint32_t dwSize); - void ReadableExceptionInfo(PEXCEPTION_RECORD excrec, CMStringW& buffer); -void GetLastWriteTime(LPCTSTR fileName, LPTSTR lpszString, uint32_t dwSize); -void GetLastWriteTime(FILETIME* ftime, LPTSTR lpszString, uint32_t dwSize); +CMStringW GetISO8061Time(SYSTEMTIME *stLocal); +CMStringW GetLastWriteTime(LPCTSTR fileName); +CMStringW GetLastWriteTime(FILETIME* ftime); + void ShowMessage(int type, const wchar_t* format, ...); const PLUGININFOEX* GetMirInfo(HMODULE hModule); @@ -144,8 +144,6 @@ void RemoveExceptionHandler(void); extern CDlgBase *pViewDialog; -void OpenAuthUrl(const char* url); - void InitIcons(void); int OptionsInit(WPARAM wParam, LPARAM); diff --git a/plugins/CrashDumper/src/utils.cpp b/plugins/CrashDumper/src/utils.cpp index 54b4e2a2d2..3c35fa86dd 100644 --- a/plugins/CrashDumper/src/utils.cpp +++ b/plugins/CrashDumper/src/utils.cpp @@ -42,7 +42,7 @@ int GetTZOffset(void) return offset; } -void GetISO8061Time(SYSTEMTIME *stLocal, LPTSTR lpszString, uint32_t dwSize) +CMStringW GetISO8061Time(SYSTEMTIME *stLocal) { SYSTEMTIME loctime; if (stLocal == nullptr) { @@ -50,23 +50,28 @@ void GetISO8061Time(SYSTEMTIME *stLocal, LPTSTR lpszString, uint32_t dwSize) GetLocalTime(stLocal); } + CMStringW ret; if (g_plugin.bClassicDates) { - GetDateFormat(LOCALE_INVARIANT, 0, stLocal, L"d MMM yyyy", lpszString, dwSize); - int dlen = (int)mir_wstrlen(lpszString); - GetTimeFormat(LOCALE_INVARIANT, 0, stLocal, L" H:mm:ss", lpszString + dlen, dwSize - dlen); + wchar_t buf[100]; + GetDateFormatW(LOCALE_CUSTOM_DEFAULT, DATE_LONGDATE, stLocal, 0, buf, _countof(buf)); + ret.AppendFormat(L"%s ", buf); + + GetTimeFormatW(LOCALE_CUSTOM_DEFAULT, 0, stLocal, 0, buf, _countof(buf)); + ret.Append(buf); } else { int offset = GetTZOffset(); // Build a string showing the date and time. - mir_snwprintf(lpszString, dwSize, L"%d-%02d-%02d %02d:%02d:%02d%+03d%02d", + ret.Format(L"%d-%02d-%02d %02d:%02d:%02d%+03d%02d", stLocal->wYear, stLocal->wMonth, stLocal->wDay, stLocal->wHour, stLocal->wMinute, stLocal->wSecond, offset / 60, offset % 60); } + return ret; } -void GetLastWriteTime(FILETIME *ftime, LPTSTR lpszString, uint32_t dwSize) +CMStringW GetLastWriteTime(FILETIME *ftime) { FILETIME ftLocal; SYSTEMTIME stLocal; @@ -75,18 +80,19 @@ void GetLastWriteTime(FILETIME *ftime, LPTSTR lpszString, uint32_t dwSize) FileTimeToLocalFileTime(ftime, &ftLocal); FileTimeToSystemTime(&ftLocal, &stLocal); - GetISO8061Time(&stLocal, lpszString, dwSize); + return GetISO8061Time(&stLocal); } -void GetLastWriteTime(LPCTSTR fileName, LPTSTR lpszString, uint32_t dwSize) +CMStringW GetLastWriteTime(LPCTSTR fileName) { WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(fileName, &FindFileData); - if (hFind == INVALID_HANDLE_VALUE) return; + if (hFind == INVALID_HANDLE_VALUE) + return L""; FindClose(hFind); - GetLastWriteTime(&FindFileData.ftLastWriteTime, lpszString, dwSize); + return GetLastWriteTime(&FindFileData.ftLastWriteTime); } const PLUGININFOEX* GetMirInfo(HMODULE hModule) diff --git a/plugins/CrashDumper/src/version.h b/plugins/CrashDumper/src/version.h index 8d9b49e245..45ef0aabb7 100644 --- a/plugins/CrashDumper/src/version.h +++ b/plugins/CrashDumper/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 2 #define __RELEASE_NUM 0 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3