backup management, part 3
Windows
This commit is contained in:
parent
f2b81ed4cb
commit
57185c6da9
|
@ -35,6 +35,9 @@
|
||||||
#include <fmt/printf.h>
|
#include <fmt/printf.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#include <shlobj.h>
|
||||||
|
#include <shlwapi.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
@ -433,7 +436,35 @@ bool FurnaceGUI::splitBackupName(const char* input, String& backupName, struct t
|
||||||
|
|
||||||
void FurnaceGUI::purgeBackups(int year, int month, int day) {
|
void FurnaceGUI::purgeBackups(int year, int month, int day) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// I will do it later...
|
String findPath=backupPath+String(DIR_SEPARATOR_STR)+String("*.fur");
|
||||||
|
WString findPathW=utf8To16(findPath.c_str());
|
||||||
|
WIN32_FIND_DATAW next;
|
||||||
|
HANDLE backDir=FindFirstFileW(findPathW.c_str(),&next);
|
||||||
|
if (backDir!=INVALID_HANDLE_VALUE) {
|
||||||
|
do {
|
||||||
|
String backupName;
|
||||||
|
struct tm backupTime;
|
||||||
|
String cFileNameU=utf16To8(next.cFileName);
|
||||||
|
bool deleteBackup=false;
|
||||||
|
if (!splitBackupName(cFileNameU.c_str(),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_mday<day) {
|
||||||
|
deleteBackup=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deleteBackup) {
|
||||||
|
String nextPath=backupPath+DIR_SEPARATOR_STR+cFileNameU;
|
||||||
|
deleteFile(nextPath.c_str());
|
||||||
|
}
|
||||||
|
} while (FindNextFileW(backDir,&next)!=0);
|
||||||
|
FindClose(backDir);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
DIR* backDir=opendir(backupPath.c_str());
|
DIR* backDir=opendir(backupPath.c_str());
|
||||||
if (backDir==NULL) {
|
if (backDir==NULL) {
|
||||||
|
@ -441,7 +472,6 @@ void FurnaceGUI::purgeBackups(int year, int month, int day) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
FurnaceGUIBackupEntry nextEntry;
|
|
||||||
String backupName;
|
String backupName;
|
||||||
struct tm backupTime;
|
struct tm backupTime;
|
||||||
struct dirent* next=readdir(backDir);
|
struct dirent* next=readdir(backDir);
|
||||||
|
@ -4322,7 +4352,25 @@ void FurnaceGUI::drawSettings() {
|
||||||
backupEntryLock.unlock();
|
backupEntryLock.unlock();
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// I will do it later...
|
String findPath=backupPath+String(DIR_SEPARATOR_STR)+String("*.fur");
|
||||||
|
WString findPathW=utf8To16(findPath.c_str());
|
||||||
|
WIN32_FIND_DATAW next;
|
||||||
|
HANDLE backDir=FindFirstFileW(findPathW.c_str(),&next);
|
||||||
|
if (backDir!=INVALID_HANDLE_VALUE) {
|
||||||
|
do {
|
||||||
|
FurnaceGUIBackupEntry nextEntry;
|
||||||
|
String cFileNameU=utf16To8(next.cFileName);
|
||||||
|
if (!splitBackupName(cFileNameU.c_str(),nextEntry.name,nextEntry.lastEntryTime)) continue;
|
||||||
|
|
||||||
|
nextEntry.size=(((uint64_t)next.nFileSizeHigh)<<32)|next.nFileSizeLow;
|
||||||
|
|
||||||
|
backupEntryLock.lock();
|
||||||
|
backupEntries.push_back(nextEntry);
|
||||||
|
totalBackupSize+=nextEntry.size;
|
||||||
|
backupEntryLock.unlock();
|
||||||
|
} while (FindNextFileW(backDir,&next)!=0);
|
||||||
|
FindClose(backDir);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
DIR* backDir=opendir(backupPath.c_str());
|
DIR* backDir=opendir(backupPath.c_str());
|
||||||
if (backDir==NULL) {
|
if (backDir==NULL) {
|
||||||
|
|
Loading…
Reference in a new issue