From e6d070c5c9ca18332f11645466da5aaf3c873415 Mon Sep 17 00:00:00 2001 From: Chomp Date: Fri, 13 Dec 2024 10:57:59 +0000 Subject: [PATCH] Adjusted backup folder to be inside profiles folder Adjusted writer code to save profiles into subfolder --- project/assets/configs/backup.json | 2 +- project/src/services/BackupService.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/project/assets/configs/backup.json b/project/assets/configs/backup.json index d1634a8f0..20e862bfe 100644 --- a/project/assets/configs/backup.json +++ b/project/assets/configs/backup.json @@ -1,7 +1,7 @@ { "enabled": true, "maxBackups": 10, - "directory": "./user/backups/profiles", + "directory": "./user/profiles/backups", "dateFormat": "YYYY-MM-DD_HH-MM-SS", "backupInterval": { "enabled": true, diff --git a/project/src/services/BackupService.ts b/project/src/services/BackupService.ts index 8f768ba56..75f8cdfa3 100644 --- a/project/src/services/BackupService.ts +++ b/project/src/services/BackupService.ts @@ -31,9 +31,10 @@ export class BackupService { let currentProfiles: string[] = []; try { - currentProfiles = await fs.readdir(this.profileDir); - // Ensure only JSON files are being backed up - currentProfiles = currentProfiles.filter((profileName: string) => profileName.endsWith(".json")); + // Get profiles that end in .json + currentProfiles = (await fs.readdir(this.profileDir)).filter((profileName: string) => + profileName.endsWith(".json"), + ); } catch (error) { this.logger.error(`Unable to read profiles directory: ${error.message}`); return; @@ -45,7 +46,11 @@ export class BackupService { } try { - await fs.copy(this.profileDir, targetDir); + // iterate over each profile found and save it into backup folder + for (const profileToCopy of currentProfiles) { + await fs.copy(path.join(this.profileDir, profileToCopy), path.join(targetDir, profileToCopy)); + } + // TODO - write json with list of active mods to same folder as profile } catch (error) { this.logger.error(`Unable to write to backup profile directory: ${error.message}`); return;