diff options
author | George Hazan <ghazan@miranda.im> | 2020-09-17 18:14:24 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-09-17 18:14:24 +0300 |
commit | dcd1fc6f6662c6c513f2e15e42473372e6a0240f (patch) | |
tree | ae128e273290576479d0b49c903d45013aeef595 /plugins/PluginUpdater/src/Utils.cpp | |
parent | f513c977a39875aa8a180c2d70567957567f1724 (diff) |
fixes #2554 (PluginUpdater: делать откат в случае неудачи при замене файлов)
Diffstat (limited to 'plugins/PluginUpdater/src/Utils.cpp')
-rw-r--r-- | plugins/PluginUpdater/src/Utils.cpp | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index 5126bc04b8..63c1ede5b4 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -467,17 +467,20 @@ void RemoveBackupFolders() 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));
+ if (!hFind)
+ return;
- // remove all folders with lesser dates if there're more than 10 folders
- if (PrepareEscalation())
+ // 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));
+ FindClose(hFind);
+
+ // remove all folders with lesser dates if there're more than 10 folders
+ if (PrepareEscalation()) {
while (arNames.getCount() > g_plugin.iNumberBackups) {
mir_snwprintf(wszMask, L"%s\\Backups\\%s", g_wszRoot, arNames[0].c_str());
SafeDeleteDirectory(wszMask);
@@ -487,6 +490,44 @@ void RemoveBackupFolders() }
/////////////////////////////////////////////////////////////////////////////////////////
+// moves updated files back to Miranda's folder
+
+static void SafeMoveFolder(const wchar_t *wszSrc, const wchar_t *wszDest)
+{
+ TFileName wszNewSrc, wszNewDest;
+ mir_snwprintf(wszNewSrc, L"%s\\*", wszSrc);
+
+ WIN32_FIND_DATAW fdata;
+ HANDLE hFind = FindFirstFileW(wszNewSrc, &fdata);
+ if (!hFind)
+ return;
+
+ do {
+ if (!mir_wstrcmp(fdata.cFileName, L".") || !mir_wstrcmp(fdata.cFileName, L".."))
+ continue;
+
+ mir_snwprintf(wszNewSrc, L"%s\\%s", wszSrc, fdata.cFileName);
+ mir_snwprintf(wszNewDest, L"%s\\%s", wszDest, fdata.cFileName);
+
+ if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ SafeMoveFolder(wszNewSrc, wszNewDest);
+ else
+ SafeMoveFile(wszNewSrc, wszNewDest);
+ }
+ while (FindNextFileW(hFind, &fdata));
+
+ FindClose(hFind);
+}
+
+void RollbackChanges(TFileName &pwszBackupFolder)
+{
+ VARSW dirname(L"%miranda_path%");
+ SafeMoveFolder(pwszBackupFolder, dirname);
+
+ SafeDeleteDirectory(pwszBackupFolder);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
int TransactPipe(int opcode, const wchar_t *p1, const wchar_t *p2)
{
|