Skip to content

Commit

Permalink
Added system to find active server mods and write them to the backup …
Browse files Browse the repository at this point in the history
…folder next to the profiles
  • Loading branch information
Chomp committed Dec 13, 2024
1 parent e6d070c commit 753ee6d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion project/src/services/BackupService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path";
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
Expand All @@ -9,14 +10,17 @@ import { inject, injectable } from "tsyringe";
@injectable()
export class BackupService {
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[] = [];
protected readonly profileDir = "./user/profiles";

constructor(
@inject("PrimaryLogger") protected logger: ILogger,
@inject("PreSptModLoader") protected preSptModLoader: PreSptModLoader,
@inject("ConfigServer") protected configServer: ConfigServer,
) {
this.backupConfig = this.configServer.getConfig(ConfigTypes.BACKUP);
this.startBackupInterval();
this.activeServerMods = this.getActiveServerMods();
}

/**
Expand Down Expand Up @@ -50,7 +54,8 @@ export class BackupService {
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

await fs.writeJson(path.join(targetDir, "activeMods.json"), this.activeServerMods);
} catch (error) {
this.logger.error(`Unable to write to backup profile directory: ${error.message}`);
return;
Expand Down Expand Up @@ -159,4 +164,20 @@ export class BackupService {
this.init().catch((error) => this.logger.error(`Profile backup failed: ${error.message}`));
}, minutes);
}

/**
* Get an array of active server mod details
* @returns array of mod names
*/
protected getActiveServerMods(): string[] {
const result = [];

const activeMods = this.preSptModLoader.getImportedModDetails();
for (const activeModKey in activeMods) {
result.push(
`${activeModKey}-${activeMods[activeModKey].author ?? "unknown"}-${activeMods[activeModKey].version ?? ""}`,
);
}
return result;
}
}

0 comments on commit 753ee6d

Please sign in to comment.