summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-09-08 19:43:23 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-09-08 19:43:23 +0300
commit88fc41f67e3114e06deba123ce972052f17e0f3e (patch)
tree0a9de5a1b50e9c194efc258a76b82ed5b33f21b8 /plugins/PluginUpdater
parent5d0dff54982b174d382aca8da00393273bc7b3e5 (diff)
Plugin Updater to store backups in the separate folders
Diffstat (limited to 'plugins/PluginUpdater')
-rw-r--r--plugins/PluginUpdater/src/DlgUpdate.cpp4
-rw-r--r--plugins/PluginUpdater/src/Events.cpp12
-rw-r--r--plugins/PluginUpdater/src/Utils.cpp38
-rw-r--r--plugins/PluginUpdater/src/checksum.cpp2
-rw-r--r--plugins/PluginUpdater/src/stdafx.h2
5 files changed, 44 insertions, 14 deletions
diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp
index 3d0b272284..f5da0bbfe2 100644
--- a/plugins/PluginUpdater/src/DlgUpdate.cpp
+++ b/plugins/PluginUpdater/src/DlgUpdate.cpp
@@ -119,8 +119,6 @@ LBL_Error:
}
Skin_PlaySound("updatecompleted");
- g_plugin.setByte(DB_SETTING_RESTART_COUNT, 5);
-
if (g_plugin.bBackup)
CallService(MS_AB_BACKUP, 0, 0);
@@ -474,8 +472,6 @@ LBL_Error:
g_plugin.bForceRedownload = false;
g_plugin.bChangePlatform = false;
g_plugin.delSetting(DB_SETTING_CHANGEPLATFORM);
-
- g_plugin.setByte(DB_SETTING_RESTART_COUNT, 5);
g_plugin.setByte(DB_SETTING_NEED_RESTART, 1);
if (g_plugin.bBackup)
diff --git a/plugins/PluginUpdater/src/Events.cpp b/plugins/PluginUpdater/src/Events.cpp
index 55a28341bd..d87904ddb4 100644
--- a/plugins/PluginUpdater/src/Events.cpp
+++ b/plugins/PluginUpdater/src/Events.cpp
@@ -41,16 +41,14 @@ int ModulesLoaded(WPARAM, LPARAM)
if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE))
AssocMgr_AddNewUrlTypeW("mirpu:", TranslateT("Plugin updater URI scheme"), g_plugin.getInst(), IDI_PLGLIST, MODULENAME "/ParseUri", 0);
- int iRestartCount = g_plugin.getByte(DB_SETTING_RESTART_COUNT, 2);
- if (iRestartCount > 0)
- g_plugin.setByte(DB_SETTING_RESTART_COUNT, iRestartCount - 1);
- else
- DeleteDirectoryTreeW(g_wszRoot);
+ int iCompatLevel = db_get_b(0, "Compatibility", MODULENAME);
+ if (iCompatLevel == 0) {
+ db_set_b(0, "Compatibility", MODULENAME, 1);
+ DeleteDirectoryTreeW(CMStringW(g_wszRoot) + L"\\Backups");
+ }
CheckUpdateOnStartup();
-
CreateTimer();
-
return 0;
}
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp
index 5108c2fbd4..8634b156e1 100644
--- a/plugins/PluginUpdater/src/Utils.cpp
+++ b/plugins/PluginUpdater/src/Utils.cpp
@@ -437,10 +437,38 @@ bool PrepareEscalation()
/////////////////////////////////////////////////////////////////////////////////////////
// Folder creation
+static int __cdecl CompareDirs(const CMStringW *s1, const CMStringW *s2)
+{
+ return mir_wstrcmp(s1->c_str(), s2->c_str());
+}
+
void CreateWorkFolders(TFileName &wszTempFolder, TFileName &wszBackupFolder)
{
- mir_snwprintf(wszBackupFolder, L"%s\\Backups", g_wszRoot);
+ TFileName wszMask;
+ mir_snwprintf(wszMask, L"%s\\Backups\\BKP*", g_wszRoot);
+
+ WIN32_FIND_DATAW fdata;
+ HANDLE hFind = FindFirstFileW(wszMask, &fdata);
+ if (hFind) {
+ // sort folder names alphabetically
+ OBJLIST<CMStringW> arNames(1, CompareDirs);
+ do {
+ if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ arNames.insert(new CMStringW(fdata.cFileName));
+ } while (FindNextFileW(hFind, &fdata));
+
+ // remove all folders with lesser dates if there're more than 10 folders
+ while (arNames.getCount() > 9) {
+ SafeDeleteDirectory(arNames[0]);
+ arNames.remove(00);
+ }
+ }
+
+ SYSTEMTIME st;
+ GetLocalTime(&st);
+ mir_snwprintf(wszBackupFolder, L"%s\\Backups\\BKP%04d-%02d-%02d %02d-%02d-%02d-%03d", g_wszRoot, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
SafeCreateDirectory(wszBackupFolder);
+
mir_snwprintf(wszTempFolder, L"%s\\Temp", g_wszRoot);
SafeCreateDirectory(wszTempFolder);
}
@@ -539,6 +567,14 @@ int SafeCreateDirectory(const wchar_t *pwszFolder)
return TransactPipe(4, pwszFolder, nullptr);
}
+int SafeDeleteDirectory(const wchar_t *pwszDirName)
+{
+ if (hPipe == nullptr)
+ return DeleteDirectoryTreeW(pwszDirName);
+
+ return TransactPipe(6, pwszDirName, nullptr);
+}
+
int SafeCreateFilePath(const wchar_t *pwszFolder)
{
if (hPipe == nullptr) {
diff --git a/plugins/PluginUpdater/src/checksum.cpp b/plugins/PluginUpdater/src/checksum.cpp
index 77b138fde3..67b4d8e633 100644
--- a/plugins/PluginUpdater/src/checksum.cpp
+++ b/plugins/PluginUpdater/src/checksum.cpp
@@ -25,7 +25,7 @@ struct MFileMapping
PBYTE ptr;
HANDLE hMap, hFile;
- MFileMapping(const wchar_t* pwszFileName)
+ MFileMapping(const wchar_t *pwszFileName)
{
ptr = nullptr;
hMap = nullptr;
diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h
index a9628fb7ca..ed46c7c286 100644
--- a/plugins/PluginUpdater/src/stdafx.h
+++ b/plugins/PluginUpdater/src/stdafx.h
@@ -136,7 +136,6 @@ enum
#define DB_SETTING_UPDATE_MODE "UpdateMode"
#define DB_SETTING_UPDATE_URL "UpdateURL"
#define DB_SETTING_NEED_RESTART "NeedRestart"
-#define DB_SETTING_RESTART_COUNT "RestartCount"
#define DB_SETTING_LAST_UPDATE "LastUpdate"
#define DB_SETTING_DONT_SWITCH_TO_STABLE "DontSwitchToStable"
#define DB_SETTING_CHANGEPLATFORM "ChangePlatform"
@@ -276,6 +275,7 @@ bool PrepareEscalation();
void CreateWorkFolders(TFileName &wszTempFolder, TFileName &wszBackupFolder);
int SafeCreateDirectory(const wchar_t *pwszDirName);
+int SafeDeleteDirectory(const wchar_t *pwszDirName);
int SafeCopyFile(const wchar_t *pwszSrc, const wchar_t *pwszDst);
int SafeMoveFile(const wchar_t *pwszSrc, const wchar_t *pwszDst);
int SafeDeleteFile(const wchar_t *pwszSrc);