From 5fe511b135c47c839889853c86afa2da985a56a6 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 29 Aug 2018 22:29:11 +0300 Subject: senseless errors removed --- plugins/Msg_Export/src/FileViewer.cpp | 26 +++------- plugins/Msg_Export/src/options.cpp | 9 +--- plugins/Msg_Export/src/utils.cpp | 91 ++++++++--------------------------- 3 files changed, 28 insertions(+), 98 deletions(-) (limited to 'plugins/Msg_Export/src') diff --git a/plugins/Msg_Export/src/FileViewer.cpp b/plugins/Msg_Export/src/FileViewer.cpp index 6a50585603..1d8f310d1a 100755 --- a/plugins/Msg_Export/src/FileViewer.cpp +++ b/plugins/Msg_Export/src/FileViewer.cpp @@ -190,10 +190,8 @@ int CLStreamRTFInfo::nWriteHeader(char *pszTarget, int nLen) GetRValue(cMyText), GetGValue(cMyText), GetBValue(cMyText), GetRValue(cYourText), GetGValue(cYourText), GetBValue(cYourText)); - if (nSrcLen > nLen) { - MessageBox(nullptr, TranslateT("Failed to write to the Rich Edit the buffer was to small."), MSG_BOX_TITEL, MB_OK); + if (nSrcLen > nLen) return 0; // target buffer to small - } memcpy(pszTarget, szRtfHeader, nSrcLen); bHeaderWriten = true; @@ -215,10 +213,8 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) if (bTailWriten) return 0; - if (nOptimalReadLen < 500) { - MessageBox(nullptr, TranslateT("Error: Optimal buffer size decreased to a too low size!"), MSG_BOX_TITEL, MB_OK); + if (nOptimalReadLen < 500) return 0; - } DWORD dwRead; DWORD dwToRead = nOptimalReadLen; @@ -467,27 +463,19 @@ DWORD CALLBACK RichEditStreamSaveFile(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb // hContact - ? // Returns : Returns true if -bool bLoadFile(HWND hwndDlg, CLHistoryDlg * pclDlg) +bool bLoadFile(HWND hwndDlg, CLHistoryDlg *pclDlg) { DWORD dwStart = GetTickCount(); HWND hRichEdit = GetDlgItem(hwndDlg, IDC_RICHEDIT); - if (!hRichEdit) { - MessageBox(hwndDlg, TranslateT("Failed to get handle to Rich Edit!"), MSG_BOX_TITEL, MB_OK); + if (!hRichEdit) return false; - } - HANDLE hFile = CreateFile(pclDlg->sPath.c_str(), GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE hFile = CreateFile(pclDlg->sPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) { - int nDBCount = db_event_count(pclDlg->hContact); wchar_t szTmp[1500]; - - if (nDBCount == -1) - mir_snwprintf(szTmp, TranslateT("Failed to open file\r\n%s\r\n\r\nContact handle is invalid"), pclDlg->sPath.c_str()); - else - mir_snwprintf(szTmp, TranslateT("Failed to open file\r\n%s\r\n\r\nMiranda database contains %d events"), pclDlg->sPath.c_str(), nDBCount); + CMStringW wszMsg(FORMAT, TranslateT("Miranda database contains %d events"), db_event_count(pclDlg->hContact)); + mir_snwprintf(szTmp, L"%s\r\n%s\r\n\r\n%s", pclDlg->sPath.c_str(), wszMsg.c_str()); SETTEXTEX stText = { 0 }; stText.codepage = 1200; diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp index 370a409c65..66ed3b661d 100755 --- a/plugins/Msg_Export/src/options.cpp +++ b/plugins/Msg_Export/src/options.cpp @@ -362,16 +362,13 @@ public: { // Get the shells allocator LPMALLOC pMalloc; - if (FAILED(SHGetMalloc(&pMalloc))) { // we need to use this to support old Windows versions - MessageBox(m_hwnd, TranslateT("Failed to get the shells allocator!"), MSG_BOX_TITEL, MB_OK); + if (FAILED(SHGetMalloc(&pMalloc))) return; - } // Allocate the Dest Dir buffer to receive browse info wchar_t *lpDestDir = (wchar_t *)pMalloc->Alloc(MAX_PATH + 100); if (!lpDestDir) { pMalloc->Release(); - MessageBox(m_hwnd, TranslateT("Failed to Allocate buffer space"), MSG_BOX_TITEL, MB_OK); return; } @@ -576,10 +573,8 @@ public: continue; sItem.iItem = nCur; - if (!listUsers.GetItem(&sItem)) { - MessageBox(m_hwnd, TranslateT("Failed to export at least one contact"), MSG_BOX_TITEL, MB_OK); + if (!listUsers.GetItem(&sItem)) continue; - } MCONTACT hContact = (MCONTACT)sItem.lParam; data->contacts.push_back(hContact); diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 76472650fa..34f7d7c4a3 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -693,12 +693,8 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath bWriteUTF8Format = bIsUtf8Header(ucByteOrder); DWORD dwPtr = SetFilePointer(hFile, g_bUseJson ? -3 : 0, nullptr, FILE_END); - if (dwPtr == INVALID_SET_FILE_POINTER) { - // we need to aborte mission here because if we continue we risk - // overwriting old log. - DisplayErrorDialog(LPGENW("Failed to move to the end of the file:\n"), sFilePath, nullptr); + if (dwPtr == INVALID_SET_FILE_POINTER) return false; - } if (g_bUseJson) bWriteToFile(hFile, ",", 1); @@ -735,21 +731,16 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath pRoot.push_back(pHist); std::string output = pRoot.write_formatted(); - if (!bWriteTextToFile(hFile, output.c_str(), false, (int)output.size())) { - DisplayErrorDialog(LPGENW("Failed to write user details to file:\n"), sFilePath, nullptr); + if (!bWriteTextToFile(hFile, output.c_str(), false, (int)output.size())) return false; - } SetFilePointer(hFile, -3, nullptr, FILE_CURRENT); } else { bWriteUTF8Format = g_bUseUtf8InNewFiles; - if (bWriteUTF8Format) { - if (!bWriteToFile(hFile, szUtf8ByteOrderHeader, sizeof(szUtf8ByteOrderHeader) - 1)) { - DisplayErrorDialog(LPGENW("Failed to UTF8 byte order code to file:\n"), sFilePath, nullptr); + if (bWriteUTF8Format) + if (!bWriteToFile(hFile, szUtf8ByteOrderHeader, sizeof(szUtf8ByteOrderHeader) - 1)) return false; - } - } CMStringW output = L"------------------------------------------------\r\n"; output.AppendFormat(L"%s\r\n", TranslateT(" History for")); @@ -783,10 +774,8 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath output += L"------------------------------------------------\r\n"; - if (!bWriteTextToFile(hFile, output, bWriteUTF8Format, output.GetLength())) { - DisplayErrorDialog(LPGENW("Failed to write user details to file:\n"), sFilePath, nullptr); + if (!bWriteTextToFile(hFile, output, bWriteUTF8Format, output.GetLength())) return false; - } } } } @@ -814,10 +803,9 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath std::string output = pRoot.write_formatted(); output += "\n]}"; - if (!bWriteTextToFile(hFile, output.c_str(), false, (int)output.size())) { - DisplayErrorDialog(LPGENW("Failed to write message to the file:\n"), sFilePath, &dbei); + if (!bWriteTextToFile(hFile, output.c_str(), false, (int)output.size())) return false; - } + return true; } @@ -830,23 +818,15 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath szTemp[nIndent++] = ' '; // Write first part of line with name and timestamp - if (!bWriteTextToFile(hFile, szTemp, bWriteUTF8Format, nIndent)) { - DisplayErrorDialog(LPGENW("Failed to write timestamp and username to file:\n"), sFilePath, &dbei); + if (!bWriteTextToFile(hFile, szTemp, bWriteUTF8Format, nIndent)) return false; - } if (dbei.pBlob != nullptr && dbei.cbBlob >= 2) { dbei.pBlob[dbei.cbBlob] = 0; switch (dbei.eventType) { case EVENTTYPE_MESSAGE: - { - wchar_t *msg = DbEvent_GetTextW(&dbei, CP_ACP); - if (!bWriteIndentedToFile(hFile, nIndent, msg, bWriteUTF8Format)) { - DisplayErrorDialog(LPGENW("Failed to write message to the file:\n"), sFilePath, &dbei); - } - mir_free(msg); - } + bWriteIndentedToFile(hFile, nIndent, ptrW(DbEvent_GetTextW(&dbei, CP_ACP)), bWriteUTF8Format); break; case EVENTTYPE_URL: @@ -864,31 +844,22 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath pszData = (char *)(dbei.pBlob + sizeof(DWORD)); } - bool bWriteOk = false; - int nLen = (int)mir_strlen(pszData); if ((pszData - (char *)dbei.pBlob) + nLen < (int)dbei.cbBlob) { if (bWriteTextToFile(hFile, pszType, bWriteUTF8Format) && bWriteIndentedToFile(hFile, nIndent, _A2T(pszData), bWriteUTF8Format)) { pszData += nLen + 1; - if ((pszData - (char *)dbei.pBlob) >= (int)dbei.cbBlob) { - bWriteOk = true; - } - else { + if ((pszData - (char *)dbei.pBlob) < (int)dbei.cbBlob) { nLen = (int)mir_strlen(pszData); if ((pszData - (char *)dbei.pBlob) + nLen < (int)dbei.cbBlob) { if (bWriteNewLine(hFile, nIndent) && bWriteTextToFile(hFile, LPGENW("Description: "), bWriteUTF8Format) && bWriteIndentedToFile(hFile, nIndent, _A2T(pszData), bWriteUTF8Format)) { - bWriteOk = true; } } } } } - - if (!bWriteOk) - DisplayErrorDialog(LPGENW("Failed to write URL/File to the file:\n"), sFilePath, &dbei); } break; @@ -904,13 +875,10 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath if (dbei.cbBlob < 8 || dbei.cbBlob > 5000) { int n = mir_snwprintf(szTemp, TranslateT("Invalid Database event received. Type %d, size %d"), dbei.eventType, dbei.cbBlob); - if (!bWriteTextToFile(hFile, szTemp, bWriteUTF8Format, n)) - DisplayErrorDialog(LPGENW("Failed to write Invalid Database event the file:\n"), sFilePath, &dbei); + bWriteTextToFile(hFile, szTemp, bWriteUTF8Format, n); break; } - bool bWriteOk = false; - int nStringCount; const wchar_t *pszTitle; char *pszCurBlobPos; @@ -945,12 +913,8 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath } pszCurBlobPos++; } - bWriteOk = true; } } - - if (!bWriteOk) - DisplayErrorDialog(LPGENW("Failed to write AUTHREQUEST or ADDED to the file:\n"), sFilePath, &dbei); } break; @@ -993,22 +957,18 @@ static bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath } else bWriteTextToFile(hFile, LPGENW("No from address"), bWriteUTF8Format); - if (!bWriteNewLine(hFile, nIndent) || - !bWriteIndentedToFile(hFile, nIndent, _A2T(pszStr), bWriteUTF8Format)) { - DisplayErrorDialog(LPGENW("Failed to write EmailExpress to the file:\n"), sFilePath, &dbei); - } + bWriteNewLine(hFile, nIndent); + bWriteIndentedToFile(hFile, nIndent, _A2T(pszStr), bWriteUTF8Format); } break; case ICQEVENTTYPE_SMS: - if (!bWriteIndentedToFile(hFile, nIndent, _A2T((const char*)dbei.pBlob), bWriteUTF8Format)) - DisplayErrorDialog(LPGENW("Failed to write SMS to the file:\n"), sFilePath, &dbei); + bWriteIndentedToFile(hFile, nIndent, _A2T((const char*)dbei.pBlob), bWriteUTF8Format); break; default: int n = mir_snwprintf(szTemp, TranslateT("Unknown event type %d, size %d"), dbei.eventType, dbei.cbBlob); - if (!bWriteTextToFile(hFile, szTemp, bWriteUTF8Format, n)) - DisplayErrorDialog(LPGENW("Failed to write Unknown event to the file:\n"), sFilePath, &dbei); + bWriteTextToFile(hFile, szTemp, bWriteUTF8Format, n); break; } } @@ -1214,29 +1174,16 @@ int nContactDeleted(WPARAM hContact, LPARAM) return 0; // we found another contact abort mission :-) // Test to see if there is a file to delete - HANDLE hPrevFile = CreateFile(sFilePath.c_str(), - GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, - nullptr, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - nullptr); - + HANDLE hPrevFile = CreateFile(sFilePath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hPrevFile != INVALID_HANDLE_VALUE) { CloseHandle(hPrevFile); wchar_t szTemp[500]; - mir_snwprintf(szTemp, L"%s\r\n%s", - TranslateT("User has been deleted. Do you want to delete the file?"), sFilePath.c_str()); + mir_snwprintf(szTemp, L"%s\r\n%s", TranslateT("User has been deleted. Do you want to delete the file?"), sFilePath.c_str()); - if (g_enDeleteAction == eDAAutomatic || - MessageBox(nullptr, szTemp, MSG_BOX_TITEL, MB_YESNO) == IDYES) { + if (g_enDeleteAction == eDAAutomatic || MessageBox(nullptr, szTemp, MSG_BOX_TITEL, MB_YESNO) == IDYES) { if (!DeleteFile(sFilePath.c_str())) { - mir_snwprintf(szTemp, - L"%s\r\n%s", - TranslateT("Failed to delete the file"), - sFilePath.c_str()); - + mir_snwprintf(szTemp, L"%s\r\n%s", TranslateT("Failed to delete the file"), sFilePath.c_str()); LogLastError(szTemp); } } -- cgit v1.2.3