From 7c07d4e6578b0eab6de015ab7c1126e2f8fa4a13 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 21 May 2025 11:35:33 +0300 Subject: more logs for Plugin Updater --- plugins/PluginUpdater/src/DlgUpdate.cpp | 55 +++++++++++++++++---------------- plugins/PluginUpdater/src/Utils.cpp | 6 +++- plugins/PluginUpdater/src/unzipfile.cpp | 14 ++++++--- 3 files changed, 43 insertions(+), 32 deletions(-) (limited to 'plugins/PluginUpdater/src') diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index 6340cd8540..dc823ad35d 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -85,37 +85,38 @@ class CUpdateDLg : public CDlgBase uint32_t dwErrorCode; for (auto &it : todo) { - if (it->bEnabled) { - if (it->bDeleteOnly) { - // we need only to backup the old file - TFileName wszBackFile; - mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszNewName + wcslen(g_mirandaPath) + 1); - if (dwErrorCode = BackupFile(it->wszNewName, wszBackFile)) { + if (!it->bEnabled) + continue; + + if (it->bDeleteOnly) { + // we need only to backup the old file + TFileName wszBackFile; + mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszNewName + wcslen(g_mirandaPath) + 1); + if (dwErrorCode = BackupFile(it->wszNewName, wszBackFile)) { LBL_Error: - RollbackChanges(wszBackupFolder); - Skin_PlaySound("updatefailed"); - CMStringW wszError(FORMAT, TranslateT("Unpack operation failed with error code=%d, update terminated"), dwErrorCode); - MessageBox(pDlg->GetHwnd(), wszError, TranslateT("Plugin Updater"), MB_OK | MB_ICONERROR); - pDlg->Close(); - return; - } + RollbackChanges(wszBackupFolder); + Skin_PlaySound("updatefailed"); + CMStringW wszError(FORMAT, TranslateT("Unpack operation failed with error code=%d, update terminated"), dwErrorCode); + MessageBox(pDlg->GetHwnd(), wszError, TranslateT("Plugin Updater"), MB_OK | MB_ICONERROR); + pDlg->Close(); + return; } - else { - // if file name differs, we also need to backup the old file here - // otherwise it would be replaced by unzip - if (_wcsicmp(it->wszOldName, it->wszNewName)) { - TFileName wszSrcPath, wszBackFile; - mir_snwprintf(wszSrcPath, L"%s\\%s", g_mirandaPath.get(), it->wszOldName); - mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszOldName); - if (dwErrorCode = BackupFile(wszSrcPath, wszBackFile)) - goto LBL_Error; - } - - if (dwErrorCode = unzip(it->File.wszDiskPath, g_mirandaPath, wszBackupFolder, true)) + } + else { + // if file name differs, we also need to backup the old file here + // otherwise it would be replaced by unzip + if (_wcsicmp(it->wszOldName, it->wszNewName)) { + TFileName wszSrcPath, wszBackFile; + mir_snwprintf(wszSrcPath, L"%s\\%s", g_mirandaPath.get(), it->wszOldName); + mir_snwprintf(wszBackFile, L"%s\\%s", wszBackupFolder, it->wszOldName); + if (dwErrorCode = BackupFile(wszSrcPath, wszBackFile)) goto LBL_Error; - - PU::SafeDeleteFile(it->File.wszDiskPath); // remove .zip after successful update } + + if (dwErrorCode = unzip(it->File.wszDiskPath, g_mirandaPath, wszBackupFolder, true)) + goto LBL_Error; + + PU::SafeDeleteFile(it->File.wszDiskPath); // remove .zip after successful update } } diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index bfc68c97df..5fbf66192d 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -304,7 +304,11 @@ int BackupFile(wchar_t *pwszSrcFileName, wchar_t *pwszBackFileName) PU::SafeCreateFilePath(pwszBackFileName); - return PU::SafeMoveFile(pwszSrcFileName, pwszBackFileName); + if (int err = PU::SafeMoveFile(pwszSrcFileName, pwszBackFileName)) { + Netlib_LogfW(g_hNetlibUser, L"Error moving file %s to %s: %d", pwszSrcFileName, pwszBackFileName, err); + return err; + } + return 0; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp index 56457b07ee..2252f2ae9b 100644 --- a/plugins/PluginUpdater/src/unzipfile.cpp +++ b/plugins/PluginUpdater/src/unzipfile.cpp @@ -70,8 +70,10 @@ int extractCurrentFile(unzFile uf, wchar_t *pwszDestPath, wchar_t *pwszBackPath, mir_ptr buf((char *)mir_alloc(DATA_BUF_SIZE+1)); int err = unzGetCurrentFileInfo64(uf, &file_info, filename, sizeof(filename), buf, DATA_BUF_SIZE, nullptr, 0); - if (err != UNZ_OK) + if (err != UNZ_OK) { + Netlib_LogfW(g_hNetlibUser, L"Error retrieving file info %S: %d", filename, err); return err; + } for (char *p = strchr(filename, '/'); p; p = strchr(p + 1, '/')) *p = '\\'; @@ -111,9 +113,12 @@ int extractCurrentFile(unzFile uf, wchar_t *pwszDestPath, wchar_t *pwszBackPath, pwszFile2unzip = wszBackFile; } - HANDLE hFile = CreateFile(pwszFile2unzip, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, file_info.external_fa, nullptr); - if (hFile == INVALID_HANDLE_VALUE) - return GetLastError(); + HANDLE hFile = CreateFileW(pwszFile2unzip, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, file_info.external_fa, nullptr); + if (hFile == INVALID_HANDLE_VALUE) { + err = GetLastError(); + Netlib_LogfW(g_hNetlibUser, L"Error creating file %s: %d", pwszFile2unzip, err); + return err; + } while (true) { err = unzReadCurrentFile(uf, buf, DATA_BUF_SIZE); @@ -123,6 +128,7 @@ int extractCurrentFile(unzFile uf, wchar_t *pwszDestPath, wchar_t *pwszBackPath, DWORD bytes; if (!WriteFile(hFile, buf, err, &bytes, FALSE)) { err = GetLastError(); + Netlib_LogfW(g_hNetlibUser, L"Error writing file %s: %d", pwszFile2unzip, err); break; } } -- cgit v1.2.3