From f2b81ed4cbf9aad209e284c7bd57a3a22c7aaab8 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Tue, 21 May 2024 03:16:42 -0500 Subject: [PATCH] backup management, part 2 backup purging! --- src/gui/settings.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index adacd7730..2739c2011 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -432,6 +432,42 @@ bool FurnaceGUI::splitBackupName(const char* input, String& backupName, struct t } void FurnaceGUI::purgeBackups(int year, int month, int day) { +#ifdef _WIN32 + // I will do it later... +#else + DIR* backDir=opendir(backupPath.c_str()); + if (backDir==NULL) { + logW("could not open backups dir!"); + return; + } + while (true) { + FurnaceGUIBackupEntry nextEntry; + String backupName; + struct tm backupTime; + struct dirent* next=readdir(backDir); + bool deleteBackup=false; + if (next==NULL) break; + if (strcmp(next->d_name,".")==0) continue; + if (strcmp(next->d_name,"..")==0) continue; + if (!splitBackupName(next->d_name,backupName,backupTime)) continue; + + if (year==0) { + deleteBackup=true; + } else if (backupTime.tm_year<(year-1900)) { + deleteBackup=true; + } else if (backupTime.tm_year==(year-1900) && backupTime.tm_mon<(month-1)) { + deleteBackup=true; + } else if (backupTime.tm_year==(year-1900) && backupTime.tm_mon==(month-1) && backupTime.tm_mdayd_name; + deleteFile(nextPath.c_str()); + } + } + closedir(backDir); +#endif refreshBackups=true; }