diff options
Diffstat (limited to 'plugins/PluginUpdater/src')
-rw-r--r-- | plugins/PluginUpdater/src/DlgListNew.cpp | 27 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/DlgUpdate.cpp | 174 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/Utils.cpp | 26 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/stdafx.cxx | 2 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/stdafx.h | 30 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/unzipfile.cpp | 27 | ||||
-rw-r--r-- | plugins/PluginUpdater/src/version.h | 4 |
7 files changed, 123 insertions, 167 deletions
diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index 2ac37ce98d..7a15dd5a34 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -294,6 +294,17 @@ public: FillList();
}
+ bool DownloadUpdate(FILEINFO *p, HNETLIBCONN nlc, TFileName wszBackupFolder)
+ {
+ if (DownloadFile(&p->File, nlc) != ERROR_SUCCESS)
+ return false;
+
+ if (!unzip(p->File.wszDiskPath, g_mirandaPath, wszBackupFolder, false))
+ PU::SafeDeleteFile(p->File.wszDiskPath); // remove .zip after successful update
+ db_unset(0, DB_MODULE_NEW_FILES, _T2A(p->wszOldName));
+ return true;
+ }
+
void Unpack()
{
// create needed folders after escalating priviledges. Folders creates when we actually install updates
@@ -303,21 +314,21 @@ public: HNETLIBCONN nlc = nullptr;
int i = 0;
for (auto &p : *todo) {
- if (p->IsFiltered(m_wszFilter))
+ if (p->IsFiltered(m_wszFilter)) {
+ // this update is hidden from screen, so we do not update anything
+ if (p->bEnabled)
+ DownloadUpdate(p, nlc, wszBackupFolder);
continue;
+ }
m_list.EnsureVisible(i, FALSE);
if (p->bEnabled) {
// download update
m_list.SetItemText(i, 1, TranslateT("Downloading..."));
-
- if (DownloadFile(&p->File, nlc) == ERROR_SUCCESS) {
+ if (DownloadUpdate(p, nlc, wszBackupFolder))
m_list.SetItemText(i, 1, TranslateT("Succeeded."));
- if (!unzip(p->File.wszDiskPath, g_mirandaPath, wszBackupFolder, false))
- PU::SafeDeleteFile(p->File.wszDiskPath); // remove .zip after successful update
- db_unset(0, DB_MODULE_NEW_FILES, _T2A(p->wszOldName));
- }
- else m_list.SetItemText(i, 1, TranslateT("Failed!"));
+ else
+ m_list.SetItemText(i, 1, TranslateT("Failed!"));
}
else m_list.SetItemText(i, 1, TranslateT("Skipped."));
i++;
diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index cd3d9a2402..e04c3561e2 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
}
}
@@ -465,112 +466,7 @@ LBL_Error: /////////////////////////////////////////////////////////////////////////////////////////
// building file list in the separate thread
-struct
-{
- wchar_t *oldName, *newName;
-}
-static renameTable[] =
-{
- { L"svc_dbepp.dll", L"Plugins\\dbeditorpp.dll" },
- { L"svc_crshdmp.dll", L"Plugins\\crashdumper.dll" },
- { L"crashdmp.dll", L"Plugins\\crashdumper.dll" },
- { L"crashrpt.dll", L"Plugins\\crashdumper.dll" },
- { L"attache.dll", L"Plugins\\crashdumper.dll" },
- { L"svc_vi.dll", L"Plugins\\crashdumper.dll" },
- { L"crashrpt.dll", L"Plugins\\crashdumper.dll" },
- { L"versioninfo.dll", L"Plugins\\crashdumper.dll" },
- { L"advsplashscreen.dll", L"Plugins\\splashscreen.dll" },
- { L"import_sa.dll", L"Plugins\\import.dll" },
- { L"newnr.dll", L"Plugins\\notesreminders.dll" },
- { L"dbtool.exe", nullptr },
- { L"dbtool_sa.exe", nullptr },
- { L"dbchecker.bat", nullptr },
- { L"fixme.cmd", nullptr },
- { L"mdbx_chk.exe", nullptr },
- { L"mdbx_dump.exe", nullptr },
- { L"mdbx_load.exe", nullptr },
- { L"clist_mw.dll", L"Plugins\\clist_nicer.dll" },
- { L"bclist.dll", L"Plugins\\clist_blind.dll" },
- { L"otr.dll", L"Plugins\\mirotr.dll" },
- { L"ttnotify.dll", L"Plugins\\tooltipnotify.dll" },
- { L"newstatusnotify.dll", L"Plugins\\newxstatusnotify.dll" },
- { L"rss.dll", L"Plugins\\newsaggregator.dll" },
- { L"dbx_3x.dll", L"Plugins\\dbx_mmap.dll" },
- { L"actman30.dll", L"Plugins\\actman.dll" },
- { L"skype.dll", L"Plugins\\skypeweb.dll" },
- { L"skypeclassic.dll", L"Plugins\\skypeweb.dll" },
- { L"historysweeper.dll", L"Plugins\\historysweeperlight.dll" },
- { L"advancedautoaway.dll", L"Plugins\\statusmanager.dll" },
- { L"keepstatus.dll", L"Plugins\\statusmanager.dll" },
- { L"startupstatus.dll", L"Plugins\\statusmanager.dll" },
- { L"dropbox.dll", L"Plugins\\cloudfile.dll" },
- { L"popup.dll", L"Plugins\\popupplus.dll" },
- { L"libaxolotl.mir", L"Libs\\libsignal.mir" },
-
- { L"dbx_mmap_sa.dll", L"Plugins\\dbx_mmap.dll" },
- { L"dbx_tree.dll", L"Plugins\\dbx_mmap.dll" },
- { L"rc4.dll", nullptr },
- { L"athena.dll", nullptr },
- { L"skypekit.exe", nullptr },
- { L"mir_app.dll", nullptr },
- { L"mir_core.dll", nullptr },
- { L"zlib.dll", nullptr },
-
- { L"quotes.dll", L"Plugins\\currencyrates.dll" },
- { L"proto_quotes.dll", L"Icons\\proto_currencyrates.dll" },
-
- { L"proto_newsaggr.dll", L"Icons\\proto_newsaggregator.dll" },
- { L"clienticons_*.dll", L"Icons\\fp_icons.dll" },
- { L"fp_*.dll", L"Icons\\fp_icons.dll" },
- { L"xstatus_icq.dll", nullptr },
-
- { L"langpack_*.txt", L"Languages\\*" },
-
- { L"pcre16.dll", nullptr },
- { L"clist_classic.dll", nullptr },
- { L"chat.dll", nullptr },
- { L"srmm.dll", nullptr },
- { L"stdchat.dll", nullptr },
- { L"stdurl.dll", nullptr },
- { L"stdidle.dll", nullptr },
- { L"stdfile.dll", nullptr },
- { L"stdhelp.dll", nullptr },
- { L"stdauth.dll", nullptr },
- { L"stdssl.dll", nullptr },
-
- { L"advaimg.dll", nullptr },
- { L"aim.dll", nullptr },
- { L"extraicons.dll", nullptr },
- { L"firstrun.dll", nullptr },
- { L"flashavatars.dll", nullptr },
- { L"gender.dll", nullptr },
- { L"gtalkext.dll", nullptr },
- { L"icq.dll", nullptr },
- { L"importtxt.dll", nullptr },
- { L"langman.dll", nullptr },
- { L"libcrypto-1_1.mir", nullptr },
- { L"libssl-1_1.mir", nullptr },
- { L"libtox.dll", nullptr },
- { L"lua53.dll", nullptr },
- { L"metacontacts.dll", nullptr },
- { L"mra.dll", nullptr },
- { L"modernopt.dll", nullptr },
- { L"msn.dll", nullptr },
- { L"msvcp100.dll", nullptr },
- { L"msvcr100.dll", nullptr },
- { L"mtextcontrol.dll", nullptr },
- { L"omegle.dll", nullptr },
- { L"openssl.dll", nullptr },
- { L"rate.dll", nullptr },
- { L"spamotron.dll", nullptr },
- { L"sms.dll", nullptr },
- { L"tlen.dll", nullptr },
- { L"xfire.dll", nullptr },
- { L"yahoo.dll", nullptr },
- { L"yahoogroups.dll", nullptr },
- { L"yapp.dll", nullptr },
- { L"WART-*.exe", nullptr },
-};
+RENAMETABLE g_arRename(50);
// Checks if file needs to be renamed and copies it in pNewName
// Returns true if smth. was copied
@@ -579,13 +475,13 @@ static bool CheckFileRename(const wchar_t *pwszFolder, const wchar_t *pwszOldNam MFilePath fullOldPath;
fullOldPath.Format(L"%s\\%s", pwszFolder, pwszOldName);
- for (auto &it : renameTable) {
- if (wildcmpiw(pwszOldName, it.oldName)) {
- if (it.newName == nullptr)
+ for (auto &it : g_arRename) {
+ if (wildcmpiw(pwszOldName, it->wszSearch)) {
+ if (it->wszReplace == nullptr)
*pNewName = 0;
else {
- wcsncpy_s(pNewName, MAX_PATH, it.newName, _TRUNCATE);
- size_t cbLen = wcslen(it.newName) - 1;
+ wcsncpy_s(pNewName, MAX_PATH, it->wszReplace, _TRUNCATE);
+ size_t cbLen = wcslen(it->wszReplace) - 1;
if (pNewName[cbLen] == '*')
wcsncpy_s(pNewName + cbLen, MAX_PATH - cbLen, pwszOldName, _TRUNCATE);
@@ -786,7 +682,7 @@ static void CheckUpdates(void *) ptrW updateUrl(GetDefaultUrl()), baseUrl;
SERVLIST hashes(50, CompareHashes);
- bool success = ParseHashes(updateUrl, baseUrl, hashes);
+ bool success = ParseHashes(updateUrl, baseUrl, hashes, &g_arRename);
if (success) {
if (hashes.getCount()) {
FILELIST *UpdateFiles = new FILELIST(20);
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index bfc68c97df..ecab59c7a0 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -29,7 +29,7 @@ int CompareHashes(const ServListEntry *p1, const ServListEntry *p2) return _wcsicmp(p1->m_name, p2->m_name);
}
-bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes)
+bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes, RENAMETABLE *arRename)
{
REPLACEVARSARRAY vars[2];
vars[0].key.w = L"platform";
@@ -42,6 +42,9 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) baseUrl = Utils_ReplaceVarsW(pwszUrl, 0, vars);
+ if (arRename)
+ arRename->destroy();
+
// Download version info
FILEURL pFileUrl;
mir_snwprintf(pFileUrl.wszDownloadURL, L"%s/hashes.zip", baseUrl.get());
@@ -113,6 +116,21 @@ bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes) fclose(fp);
DeleteFileW(wszTmpIni);
+ // building table of rules
+ mir_snwprintf(wszTmpIni, L"%s\\rules.txt", g_wszTempPath);
+ if (arRename) {
+ JSONNode root;
+ if (file2json(wszTmpIni, root))
+ for (auto &it : root["rules"]) {
+ Utf2T wszName(it.name());
+ if (it.isnull())
+ arRename->insert(new RenameTableItem(wszName, nullptr));
+ else
+ arRename->insert(new RenameTableItem(wszName, it.as_mstring()));
+ }
+ }
+ DeleteFileW(wszTmpIni);
+
if (bDoNotSwitchToStable) {
g_plugin.setByte(DB_SETTING_DONT_SWITCH_TO_STABLE, 1);
// Reset setting if needed
@@ -304,7 +322,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/stdafx.cxx b/plugins/PluginUpdater/src/stdafx.cxx index 13f28e1314..f111565f38 100644 --- a/plugins/PluginUpdater/src/stdafx.cxx +++ b/plugins/PluginUpdater/src/stdafx.cxx @@ -1,5 +1,5 @@ /*
-Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-25 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h index 7053769c59..ca76ba0763 100644 --- a/plugins/PluginUpdater/src/stdafx.h +++ b/plugins/PluginUpdater/src/stdafx.h @@ -30,17 +30,17 @@ Boston, MA 02111-1307, USA. // Miranda header files
#include <newpluginapi.h>
+#include <m_assocmgr.h>
#include <m_clist.h>
-#include <m_skin.h>
+#include <m_icolib.h>
+#include <m_gui.h>
+#include <m_hotkeys.h>
+#include <m_json.h>
#include <m_langpack.h>
+#include <m_netlib.h>
#include <m_options.h>
-#include <m_system.h>
#include <m_popup.h>
-#include <m_hotkeys.h>
-#include <m_netlib.h>
-#include <m_icolib.h>
-#include <m_assocmgr.h>
-#include <m_gui.h>
+#include <m_skin.h>
#include <m_folders.h>
@@ -233,6 +233,20 @@ typedef OBJLIST<ServListEntry> SERVLIST; ///////////////////////////////////////////////////////////////////////////////
+struct RenameTableItem
+{
+ RenameTableItem(const wchar_t *_1, const wchar_t *_2) :
+ wszSearch(mir_wstrdup(_1)),
+ wszReplace(mir_wstrdup(_2))
+ {}
+
+ ptrW wszSearch, wszReplace;
+};
+
+typedef OBJLIST<RenameTableItem> RENAMETABLE;
+
+///////////////////////////////////////////////////////////////////////////////
+
void InitPopupList();
void InitEvents();
@@ -249,7 +263,7 @@ void CALLBACK CheckUpdateOnStartup(void); int BackupFile(wchar_t *pwszSrcFileName, wchar_t *pwszBackFileName);
-bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes);
+bool ParseHashes(const wchar_t *pwszUrl, ptrW &baseUrl, SERVLIST &arHashes, RENAMETABLE *arRename = nullptr);
int CompareHashes(const ServListEntry *p1, const ServListEntry *p2);
wchar_t* GetDefaultUrl();
diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp index 56457b07ee..2c661758fb 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<char> 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 = '\\';
@@ -88,8 +90,10 @@ int extractCurrentFile(unzFile uf, wchar_t *pwszDestPath, wchar_t *pwszBackPath, if (!(file_info.external_fa & FILE_ATTRIBUTE_DIRECTORY)) {
err = unzOpenCurrentFile(uf);
- if (err != UNZ_OK)
+ if (err != UNZ_OK) {
+ Netlib_LogfW(g_hNetlibUser, L"Error opening file %s: %d", pwszNewName.get(), err);
return err;
+ }
if (pwszBackPath != nullptr) {
PrepareFileName(wszDestFile, _countof(wszDestFile), pwszDestPath, pwszNewName);
@@ -111,18 +115,25 @@ 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);
- if (err <= 0)
+ if (err <= 0) {
+ if (err)
+ Netlib_LogfW(g_hNetlibUser, L"Error reading zipped file %s: %d", pwszFile2unzip, err);
break;
+ }
DWORD bytes;
if (!WriteFile(hFile, buf, err, &bytes, FALSE)) {
err = GetLastError();
+ Netlib_LogfW(g_hNetlibUser, L"Error writing file %s: %d", pwszFile2unzip, err);
break;
}
}
@@ -152,8 +163,10 @@ int unzip(const wchar_t *pwszZipFile, wchar_t *pwszDestPath, wchar_t *pwszBackPa unzFile uf = unzOpen2_64(pwszZipFile, &ffunc);
if (uf) {
do {
- if (int err = extractCurrentFile(uf, pwszDestPath, pwszBackPath, ch))
+ if (int err = extractCurrentFile(uf, pwszDestPath, pwszBackPath, ch)) {
+ Netlib_LogfW(g_hNetlibUser, L"Error unzipping file %s: %d", pwszZipFile, err);
iErrorCode = err;
+ }
}
while (unzGoToNextFile(uf) == UNZ_OK);
unzClose(uf);
diff --git a/plugins/PluginUpdater/src/version.h b/plugins/PluginUpdater/src/version.h index dfb62e414c..dde05d4a1f 100644 --- a/plugins/PluginUpdater/src/version.h +++ b/plugins/PluginUpdater/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 1
-#define __BUILD_NUM 7
+#define __BUILD_NUM 8
#include <stdver.h>
@@ -10,4 +10,4 @@ #define __DESCRIPTION "Installs and updates plugins and other Miranda NG components."
#define __AUTHOR "Mataes, George Hazan"
#define __AUTHORWEB "https://miranda-ng.org/p/PluginUpdater"
-#define __COPYRIGHT "© 2012-24 Mataes, George Hazan"
+#define __COPYRIGHT "© 2012-25 Mataes, George Hazan"
|