From 6982fc882137e680c99002fa75de9b12017f053c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 28 Feb 2025 15:49:16 +0300 Subject: fixes #4895 (Error message when closing Miranda profile password prompt window) --- src/mir_app/mir_app.vcxproj | 8 +++-- src/mir_app/src/MDatabaseCommonCrypt.cpp | 2 +- src/mir_app/src/database.cpp | 54 ++++++++++++++++++-------------- 3 files changed, 37 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/mir_app/mir_app.vcxproj b/src/mir_app/mir_app.vcxproj index 50cfd59262..b2b3925bb9 100644 --- a/src/mir_app/mir_app.vcxproj +++ b/src/mir_app/mir_app.vcxproj @@ -64,7 +64,9 @@ - + + false + @@ -196,8 +198,8 @@ - MIR_APP_EXPORTS;DEBUG;%(PreprocessorDefinitions) - MIR_APP_EXPORTS;NDEBUG;%(PreprocessorDefinitions) + MIR_APP_EXPORTS;%(PreprocessorDefinitions) + Sync src/mir_app.def diff --git a/src/mir_app/src/MDatabaseCommonCrypt.cpp b/src/mir_app/src/MDatabaseCommonCrypt.cpp index 47a75a8cba..a3b9efdbeb 100644 --- a/src/mir_app/src/MDatabaseCommonCrypt.cpp +++ b/src/mir_app/src/MDatabaseCommonCrypt.cpp @@ -457,7 +457,7 @@ int MDatabaseCommon::InitCrypt() CEnterPasswordDialog dlg(this); while (true) { if (!dlg.DoModal()) - return 4; + throw -2; pass_ptrA szPassword(mir_utf8encodeW(dlg.m_newPass)); if (m_crypto->setKey(szPassword, (const uint8_t*)key.data(), key.length())) { diff --git a/src/mir_app/src/database.cpp b/src/mir_app/src/database.cpp index 5b1c0f882d..40bc14ccb9 100644 --- a/src/mir_app/src/database.cpp +++ b/src/mir_app/src/database.cpp @@ -527,39 +527,47 @@ int LoadDatabaseModule(void) } // find a driver to support the given profile - bool retry; +LBL_Restart: int rc; - do { - retry = false; + try { if (!szProfile.isExist() && shouldAutoCreate(szProfile)) rc = tryCreateDatabase(szProfile); else rc = tryOpenDatabase(szProfile); + } + catch (int errorCode) { + rc = errorCode; + } + + switch (rc) { + case 0: + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + g_plugin.registerIcon(LPGEN("Database"), iconList, "database"); + break; + + // there were no suitable driver installed + case -1: + MessageBoxW(nullptr, + CMStringW(FORMAT, TranslateW(tszNoSuitableDriver), ptszFileName), + TranslateT("Miranda can't open that profile"), MB_OK | MB_ICONERROR); + break; - // there were no suitable driver installed - if (rc == -1) { + default: + if (rc < 0) // smth strange happened, exit silently + break; + + if (fileExist(szProfile)) { + // file isn't locked, just no driver could open it. MessageBoxW(nullptr, - CMStringW(FORMAT, TranslateW(tszNoSuitableDriver), ptszFileName), - TranslateT("Miranda can't open that profile"), MB_OK | MB_ICONERROR); + CMStringW(FORMAT, TranslateW(tszUnknownFormat), ptszFileName), + TranslateT("Miranda can't understand that profile"), MB_OK | MB_ICONERROR); } - else if (rc > 0) { - if (fileExist(szProfile)) { - // file isn't locked, just no driver could open it. - MessageBoxW(nullptr, - CMStringW(FORMAT, TranslateW(tszUnknownFormat), ptszFileName), - TranslateT("Miranda can't understand that profile"), MB_OK | MB_ICONERROR); - } - else - retry = IDRETRY == MessageBoxW(nullptr, - CMStringW(FORMAT, TranslateW(tszProfileLocked), ptszFileName), - TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR); + else { + CMStringW wszTitle(FORMAT, TranslateW(tszProfileLocked), ptszFileName); + if (IDRETRY == MessageBoxW(nullptr, wszTitle, TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR)) + goto LBL_Restart; } } - while (retry); - - if (rc == 0) - HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); - g_plugin.registerIcon(LPGEN("Database"), iconList, "database"); return rc; } -- cgit v1.2.3