From e80684d7a2ad3afff40ec1c211fba92bb457ea4f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 4 Sep 2019 19:21:26 +0300 Subject: CrashDumper: - fixes #2043 (CrashDumper: add option to disable VI popup); - massive cleaning of options-related code; - version bump --- plugins/CrashDumper/src/crshdmp.cpp | 32 +++++++++++++------------- plugins/CrashDumper/src/dumper.cpp | 6 ++--- plugins/CrashDumper/src/exhndlr.cpp | 4 ++-- plugins/CrashDumper/src/resource.h | 5 ++-- plugins/CrashDumper/src/stdafx.h | 5 +++- plugins/CrashDumper/src/ui.cpp | 46 ++++++++++++++++--------------------- plugins/CrashDumper/src/upload.cpp | 2 +- plugins/CrashDumper/src/utils.cpp | 2 +- plugins/CrashDumper/src/version.h | 2 +- 9 files changed, 51 insertions(+), 53 deletions(-) (limited to 'plugins/CrashDumper/src') diff --git a/plugins/CrashDumper/src/crshdmp.cpp b/plugins/CrashDumper/src/crshdmp.cpp index ebad56ebaf..e5372288a5 100644 --- a/plugins/CrashDumper/src/crshdmp.cpp +++ b/plugins/CrashDumper/src/crshdmp.cpp @@ -30,8 +30,6 @@ wchar_t* profpath; wchar_t CrashLogFolder[MAX_PATH], VersionInfoFolder[MAX_PATH]; -bool servicemode, clsdates, dtsubfldr, catchcrashes, needrestart = 0; - CDlgBase *pViewDialog = nullptr; ///////////////////////////////////////////////////////////////////////////////////////// @@ -50,8 +48,14 @@ PLUGININFOEX pluginInfoEx = { }; CMPlugin::CMPlugin() : - PLUGIN(MODULENAME, pluginInfoEx) -{} + PLUGIN(MODULENAME, pluginInfoEx), + bCatchCrashes(MODULENAME, "CatchCrashes", 1), + bClassicDates(MODULENAME, "ClassicDates", 1), + bUseSubFolder(MODULENAME, "SubFolders", 1), + bSuccessPopups(MODULENAME, "SuccessPopups", 1), + bUploadChanged(MODULENAME, "UploadChanged", 0) +{ +} ///////////////////////////////////////////////////////////////////////////////////////// // MirandaInterfaces - returns the protocol interface to the core @@ -160,7 +164,7 @@ INT_PTR CopyLinkToClipboard(WPARAM, LPARAM) INT_PTR ServiceModeLaunch(WPARAM, LPARAM) { - servicemode = true; + g_plugin.bServiceMode = true; ViewVersionInfo(1, 0); return SERVICE_ONLYDB; } @@ -261,7 +265,7 @@ static int ModulesLoaded(WPARAM, LPARAM) mi.pszService = MS_CRASHDUMPER_URLTOCLIP; Menu_AddMainMenuItem(&mi); - if (catchcrashes && !needrestart) { + if (g_plugin.bCatchCrashes && !g_plugin.bNeedRestart) { SET_UID(mi, 0xecae52f2, 0xd601, 0x4f85, 0x87, 0x9, 0xec, 0x8e, 0x84, 0xfe, 0x1b, 0x3c); mi.position = 2000099990; mi.name.a = LPGEN("Open crash report directory"); @@ -292,14 +296,14 @@ static int ModulesLoaded(WPARAM, LPARAM) UploadInit(); - if (catchcrashes && !needrestart) + if (g_plugin.bCatchCrashes && !g_plugin.bNeedRestart) SetExceptionHandler(); HookEvent(ME_TTB_MODULELOADED, ToolbarModulesLoaded); - if (servicemode) + if (g_plugin.bServiceMode) ViewVersionInfo(0, 0); - else if (g_plugin.getByte("UploadChanged", 0) && !ProcessVIHash(false)) + else if (g_plugin.bUploadChanged && !ProcessVIHash(false)) UploadVersionInfo(0, 0xa1); return 0; @@ -317,13 +321,9 @@ int CMPlugin::Load() if (hMsftedit == nullptr) return 1; - clsdates = g_plugin.getByte("ClassicDates", 1) != 0; - dtsubfldr = g_plugin.getByte("SubFolders", 1) != 0; - catchcrashes = g_plugin.getByte("CatchCrashes", 1) != 0; - profname = Utils_ReplaceVarsW(L"%miranda_profilename%.dat"); profpath = Utils_ReplaceVarsW(L"%miranda_userdata%"); - if (catchcrashes && !needrestart) + if (g_plugin.bCatchCrashes && !g_plugin.bNeedRestart) mir_snwprintf(CrashLogFolder, L"%s\\CrashLog", profpath); wcsncpy_s(VersionInfoFolder, profpath, _TRUNCATE); @@ -335,7 +335,7 @@ int CMPlugin::Load() InitIcons(); - if (catchcrashes && !needrestart) + if (g_plugin.bCatchCrashes && !g_plugin.bNeedRestart) InitExceptionHandler(); CreateServiceFunction(MS_CRASHDUMPER_STORETOFILE, StoreVersionInfoToFile); @@ -353,7 +353,7 @@ int CMPlugin::Load() int CMPlugin::Unload() { - if ((catchcrashes && !needrestart) || (!catchcrashes && needrestart)) + if ((g_plugin.bCatchCrashes && !g_plugin.bNeedRestart) || (!g_plugin.bCatchCrashes && g_plugin.bNeedRestart)) DestroyExceptionHandler(); mir_free(profpath); diff --git a/plugins/CrashDumper/src/dumper.cpp b/plugins/CrashDumper/src/dumper.cpp index 8e89470c5b..99f4c801cb 100644 --- a/plugins/CrashDumper/src/dumper.cpp +++ b/plugins/CrashDumper/src/dumper.cpp @@ -140,7 +140,7 @@ static int CompareDlls(const wchar_t *p1, const wchar_t *p2) static void GetPluginsString(CMStringW &buffer, unsigned &flags) { - buffer.AppendFormat(L"Service Mode: %s\r\n", servicemode ? L"Yes" : L"No"); + buffer.AppendFormat(L"Service Mode: %s\r\n", g_plugin.bServiceMode ? L"Yes" : L"No"); wchar_t path[MAX_PATH]; GetModuleFileName(nullptr, path, MAX_PATH); @@ -163,7 +163,7 @@ static void GetPluginsString(CMStringW &buffer, unsigned &flags) bool loaded = false; mir_snwprintf(fname, MAX_PATH - (fname - path), L"\\plugins\\%s", FindFileData.cFileName); HMODULE hModule = GetModuleHandle(path); - if (hModule == nullptr && servicemode) { + if (hModule == nullptr && g_plugin.bServiceMode) { hModule = LoadLibrary(path); loaded = true; } @@ -449,7 +449,7 @@ void PrintVersionInfo(CMStringW& buffer, unsigned flags) GetWeatherStrings(buffer, flags); } - if (flags & VI_FLAG_PRNVAR && !servicemode) { + if (flags & VI_FLAG_PRNVAR && !g_plugin.bServiceMode) { buffer.AppendFormat(L"\r\n%sProtocols and Accounts:%s\r\n-------------------------------------------------------------------------------\r\n", (flags & VI_FLAG_FORMAT) ? L"[b]" : L"", (flags & VI_FLAG_FORMAT) ? L"[/b]" : L""); diff --git a/plugins/CrashDumper/src/exhndlr.cpp b/plugins/CrashDumper/src/exhndlr.cpp index 32b4b224d1..652adcbf9f 100644 --- a/plugins/CrashDumper/src/exhndlr.cpp +++ b/plugins/CrashDumper/src/exhndlr.cpp @@ -54,7 +54,7 @@ void myfilterWorker(PEXCEPTION_POINTERS exc_ptr, bool notify) CreateDirectoryTreeW(CrashLogFolder); __try { - if (dtsubfldr) { + if (g_plugin.bUseSubFolder) { mir_snwprintf(path, L"%s\\%02d.%02d.%02d", CrashLogFolder, st.wYear, st.wMonth, st.wDay); CreateDirectory(path, nullptr); mir_snwprintf(path, L"%s\\%02d.%02d.%02d\\crash%02d%02d%02d%02d%02d%02d.mdmp", CrashLogFolder, @@ -80,7 +80,7 @@ void myfilterWorker(PEXCEPTION_POINTERS exc_ptr, bool notify) DeleteFile(path); __try { - if (dtsubfldr) { + if (g_plugin.bUseSubFolder) { mir_snwprintf(path, L"%s\\%02d.%02d.%02d", CrashLogFolder, st.wYear, st.wMonth, st.wDay); CreateDirectory(path, nullptr); mir_snwprintf(path, L"%s\\%02d.%02d.%02d\\crash%02d%02d%02d%02d%02d%02d.txt", CrashLogFolder, diff --git a/plugins/CrashDumper/src/resource.h b/plugins/CrashDumper/src/resource.h index 8172d99a51..8a09ec32d6 100644 --- a/plugins/CrashDumper/src/resource.h +++ b/plugins/CrashDumper/src/resource.h @@ -21,6 +21,7 @@ #define IDC_DATESUBFOLDER 1010 #define IDC_CATCHCRASHES 1011 #define IDC_RESTARTNOTE 1012 +#define IDC_SUCCESSPOPUPS 1013 #define IDM_COPY 40002 #define IDM_COPYALL 40003 #define IDM_SELECTALL 40004 @@ -29,9 +30,9 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 110 +#define _APS_NEXT_RESOURCE_VALUE 111 #define _APS_NEXT_COMMAND_VALUE 40005 -#define _APS_NEXT_CONTROL_VALUE 1013 +#define _APS_NEXT_CONTROL_VALUE 1014 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/plugins/CrashDumper/src/stdafx.h b/plugins/CrashDumper/src/stdafx.h index 588c8ce737..6270d4c932 100644 --- a/plugins/CrashDumper/src/stdafx.h +++ b/plugins/CrashDumper/src/stdafx.h @@ -80,6 +80,10 @@ along with this program. If not, see . struct CMPlugin : public PLUGIN { + CMOption bCatchCrashes, bClassicDates, bUploadChanged, bUseSubFolder, bSuccessPopups; + + bool bNeedRestart = false, bServiceMode = false; + CMPlugin(); int Load() override; @@ -98,7 +102,6 @@ struct VerTrnsfr }; extern LCID packlcid; -extern bool servicemode, clsdates, dtsubfldr, catchcrashes, needrestart; extern wchar_t CrashLogFolder[MAX_PATH]; extern wchar_t VersionInfoFolder[MAX_PATH]; diff --git a/plugins/CrashDumper/src/ui.cpp b/plugins/CrashDumper/src/ui.cpp index cde5a7bf2f..52141270fe 100644 --- a/plugins/CrashDumper/src/ui.cpp +++ b/plugins/CrashDumper/src/ui.cpp @@ -73,7 +73,7 @@ public: Utils_SaveWindowPosition(m_hwnd, NULL, MODULENAME, "ViewInfo_"); if (pViewDialog == this) pViewDialog = nullptr; - if (servicemode) + if (g_plugin.bServiceMode) PostQuitMessage(0); return true; } @@ -171,14 +171,14 @@ INT_PTR ViewVersionInfo(WPARAM wParam, LPARAM) class COptDialog : public CDlgBase { CCtrlEdit m_edtUserName, m_edtPass; - CCtrlCheck m_chkAutoUpload, m_chkClassicDates, m_chkRepSubfolder, m_chkCatchCrashes; + CCtrlCheck m_chkAutoUpload, m_chkClassicDates, m_chkRepSubfolder, m_chkCatchCrashes, m_chkSuccessPopups; CCtrlLabel m_lblRestart; void COptDialog::OnCatchCrashesChange(CCtrlCheck*) { m_chkRepSubfolder.Enable(m_chkCatchCrashes.GetState()); m_lblRestart.Show(); - needrestart = 1; + g_plugin.bNeedRestart = true; } public: @@ -190,15 +190,21 @@ public: m_chkClassicDates(this, IDC_CLASSICDATES), m_chkRepSubfolder(this, IDC_DATESUBFOLDER), m_chkCatchCrashes(this, IDC_CATCHCRASHES), + m_chkSuccessPopups(this, IDC_SUCCESSPOPUPS), m_lblRestart(this, IDC_RESTARTNOTE) { - CreateLink(m_chkAutoUpload, "UploadChanged", DBVT_BYTE, 0); + CreateLink(m_chkAutoUpload, g_plugin.bUploadChanged); + CreateLink(m_chkClassicDates, g_plugin.bClassicDates); + CreateLink(m_chkRepSubfolder, g_plugin.bUseSubFolder); + CreateLink(m_chkSuccessPopups, g_plugin.bSuccessPopups); + m_chkCatchCrashes.OnChange = Callback(this, &COptDialog::OnCatchCrashesChange); } bool COptDialog::OnInitDialog() { CDlgBase::OnInitDialog(); + DBVARIANT dbv; if (g_plugin.getString("Username", &dbv) == 0) { m_edtUserName.SetTextA(dbv.pszVal); @@ -208,12 +214,10 @@ public: m_edtPass.SetTextA(dbv.pszVal); db_free(&dbv); } - m_chkClassicDates.SetState(clsdates); - m_chkRepSubfolder.SetState(dtsubfldr); - m_chkCatchCrashes.SetState(catchcrashes); - if (!catchcrashes) + + if (!g_plugin.bCatchCrashes) m_chkRepSubfolder.Disable(); - if (needrestart) + if (g_plugin.bNeedRestart) m_lblRestart.Show(); return true; } @@ -226,23 +230,6 @@ public: m_edtPass.GetTextA(szSetting, _countof(szSetting)); g_plugin.setString("Password", szSetting); - - clsdates = m_chkClassicDates.GetState(); - if (clsdates) - g_plugin.setByte("ClassicDates", 1); - else - g_plugin.setByte("ClassicDates", 0); - dtsubfldr = m_chkRepSubfolder.GetState(); - if (dtsubfldr) - g_plugin.setByte("SubFolders", 1); - else - g_plugin.setByte("SubFolders", 0); - catchcrashes = m_chkCatchCrashes.GetState(); - if (catchcrashes) - g_plugin.setByte("CatchCrashes", 1); - else - g_plugin.setByte("CatchCrashes", 0); - return true; } }; @@ -298,6 +285,13 @@ LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) void ShowMessage(int type, const wchar_t *format, ...) { + switch(type) { + case 1: + case 3: + if (!g_plugin.bSuccessPopups) + return; + } + POPUPDATAW ppd; va_list va; diff --git a/plugins/CrashDumper/src/upload.cpp b/plugins/CrashDumper/src/upload.cpp index 1e212aa391..09cf4199e0 100644 --- a/plugins/CrashDumper/src/upload.cpp +++ b/plugins/CrashDumper/src/upload.cpp @@ -127,7 +127,7 @@ bool InternetDownloadFile(const char *szUrl, VerTrnsfr* szReq) // if the recieved code is 200 OK switch (nlhrReply->resultCode) { case 200: - if (g_plugin.getByte("UploadChanged", 0)) + if (g_plugin.bUploadChanged) ProcessVIHash(true); ShowMessage(1, TranslateT("Version Info upload successful.")); diff --git a/plugins/CrashDumper/src/utils.cpp b/plugins/CrashDumper/src/utils.cpp index c2908ff458..8b59693f01 100644 --- a/plugins/CrashDumper/src/utils.cpp +++ b/plugins/CrashDumper/src/utils.cpp @@ -50,7 +50,7 @@ void GetISO8061Time(SYSTEMTIME *stLocal, LPTSTR lpszString, DWORD dwSize) GetLocalTime(stLocal); } - if (clsdates) { + 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); diff --git a/plugins/CrashDumper/src/version.h b/plugins/CrashDumper/src/version.h index 323a32cc67..213bb305f1 100644 --- a/plugins/CrashDumper/src/version.h +++ b/plugins/CrashDumper/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include -- cgit v1.2.3