summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater/src/Utils.cpp
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/src/Utils.cpp
parent5d0dff54982b174d382aca8da00393273bc7b3e5 (diff)
Plugin Updater to store backups in the separate folders
Diffstat (limited to 'plugins/PluginUpdater/src/Utils.cpp')
-rw-r--r--plugins/PluginUpdater/src/Utils.cpp38
1 files changed, 37 insertions, 1 deletions
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) {