From 39fdbd0edece9c1c9a281bfefbd3840d033213c7 Mon Sep 17 00:00:00 2001 From: Archangel Date: Sun, 12 Jan 2025 16:24:08 +0100 Subject: [PATCH] Replace VFS wtih FileSystemSync Todo: Should probably just use the methods that come with filesystemsync to read json files --- .../cache/FikaFriendRequestsCacheService.ts | 14 +++++++------- .../cache/FikaPlayerRelationsCacheService.ts | 14 +++++++------- src/utils/FikaConfig.ts | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/services/cache/FikaFriendRequestsCacheService.ts b/src/services/cache/FikaFriendRequestsCacheService.ts index 0927bd97..932f34fc 100644 --- a/src/services/cache/FikaFriendRequestsCacheService.ts +++ b/src/services/cache/FikaFriendRequestsCacheService.ts @@ -1,7 +1,7 @@ import { inject, injectable } from "tsyringe"; +import { FileSystemSync } from "@spt/utils/FileSystemSync"; import { JsonUtil } from "@spt/utils/JsonUtil"; -import { VFS } from "@spt/utils/VFS"; import { IFikaFriendRequests } from "../../models/fika/IFikaFriendRequests"; import { FikaConfig } from "../../utils/FikaConfig"; @@ -14,16 +14,16 @@ export class FikaFriendRequestsCacheService { constructor( @inject("JsonUtil") protected jsonUtil: JsonUtil, - @inject("VFS") protected vfs: VFS, + @inject("FileSystemSync") protected fileSystemSync: FileSystemSync, @inject("FikaConfig") protected fikaConfig: FikaConfig, ) { this.friendRequestsFullPath = `./${this.fikaConfig.getModPath()}${this.friendRequestsPath}`; - if (!this.vfs.exists(this.friendRequestsFullPath)) { - this.vfs.writeFile(this.friendRequestsFullPath, "[]"); + if (!this.fileSystemSync.exists(this.friendRequestsFullPath)) { + this.fileSystemSync.write(this.friendRequestsFullPath, "[]"); } - this.friendRequests = this.jsonUtil.deserialize(this.vfs.readFile(this.friendRequestsFullPath), this.friendRequestsFullPath); + this.friendRequests = this.jsonUtil.deserialize(this.fileSystemSync.read(this.friendRequestsFullPath), this.friendRequestsFullPath); } public getAllFriendRequests(): IFikaFriendRequests[] { @@ -50,12 +50,12 @@ export class FikaFriendRequestsCacheService { this.friendRequests.splice(index, 1); - this.vfs.writeFile(this.friendRequestsFullPath, this.jsonUtil.serialize(this.friendRequests)); + this.fileSystemSync.write(this.friendRequestsFullPath, this.jsonUtil.serialize(this.friendRequests)); } public storeFriendRequest(value: IFikaFriendRequests): void { this.friendRequests.push(value); - this.vfs.writeFile(this.friendRequestsFullPath, this.jsonUtil.serialize(this.friendRequests)); + this.fileSystemSync.write(this.friendRequestsFullPath, this.jsonUtil.serialize(this.friendRequests)); } } diff --git a/src/services/cache/FikaPlayerRelationsCacheService.ts b/src/services/cache/FikaPlayerRelationsCacheService.ts index cd4699eb..82f527f5 100644 --- a/src/services/cache/FikaPlayerRelationsCacheService.ts +++ b/src/services/cache/FikaPlayerRelationsCacheService.ts @@ -2,8 +2,8 @@ import { inject, injectable } from "tsyringe"; import { ProfileHelper } from "@spt/helpers/ProfileHelper"; import { ILogger } from "@spt/models/spt/utils/ILogger"; +import { FileSystemSync } from "@spt/utils/FileSystemSync"; import { JsonUtil } from "@spt/utils/JsonUtil"; -import { VFS } from "@spt/utils/VFS"; import { IFikaPlayerRelations } from "../../models/fika/IFikaPlayerRelations"; import { FikaConfig } from "../../utils/FikaConfig"; @@ -18,16 +18,16 @@ export class FikaPlayerRelationsCacheService { @inject("WinstonLogger") protected logger: ILogger, @inject("ProfileHelper") protected profileHelper: ProfileHelper, @inject("JsonUtil") protected jsonUtil: JsonUtil, - @inject("VFS") protected vfs: VFS, + @inject("FileSystemSync") protected fileSystemSync: FileSystemSync, @inject("FikaConfig") protected fikaConfig: FikaConfig, ) { this.playerRelationsFullPath = `./${this.fikaConfig.getModPath()}${this.playerRelationsPath}`; - if (!this.vfs.exists(this.playerRelationsFullPath)) { - this.vfs.writeFile(this.playerRelationsFullPath, "{}"); + if (!this.fileSystemSync.exists(this.playerRelationsFullPath)) { + this.fileSystemSync.write(this.playerRelationsFullPath, "{}"); } - this.playerRelations = this.jsonUtil.deserialize(this.vfs.readFile(this.playerRelationsFullPath), this.playerRelationsFullPath); + this.playerRelations = this.jsonUtil.deserialize(this.fileSystemSync.read(this.playerRelationsFullPath), this.playerRelationsFullPath); } public postInit() { @@ -73,7 +73,7 @@ export class FikaPlayerRelationsCacheService { } if (shouldSave) { - this.vfs.writeFile(this.playerRelationsFullPath, this.jsonUtil.serialize(this.playerRelations)); + this.fileSystemSync.write(this.playerRelationsFullPath, this.jsonUtil.serialize(this.playerRelations)); } } @@ -95,6 +95,6 @@ export class FikaPlayerRelationsCacheService { public storeValue(key: string, value: IFikaPlayerRelations): void { this.playerRelations[key] = value; - this.vfs.writeFile(this.playerRelationsFullPath, this.jsonUtil.serialize(this.playerRelations)); + this.fileSystemSync.write(this.playerRelationsFullPath, this.jsonUtil.serialize(this.playerRelations)); } } diff --git a/src/utils/FikaConfig.ts b/src/utils/FikaConfig.ts index f7890b3b..97e9c700 100644 --- a/src/utils/FikaConfig.ts +++ b/src/utils/FikaConfig.ts @@ -2,8 +2,8 @@ import path from "node:path"; import { inject, injectable } from "tsyringe"; import { PreSptModLoader } from "@spt/loaders/PreSptModLoader"; +import { FileSystemSync } from "@spt/utils/FileSystemSync"; import { JsonUtil } from "@spt/utils/JsonUtil"; -import { VFS } from "@spt/utils/VFS"; import { IFikaConfig } from "../models/fika/config/IFikaConfig"; @@ -18,14 +18,14 @@ export class FikaConfig { constructor( @inject("PreSptModLoader") protected preSptModLoader: PreSptModLoader, - @inject("VFS") protected vfs: VFS, + @inject("FileSystemSync") protected fileSystemSync: FileSystemSync, @inject("JsonUtil") protected jsonUtil: JsonUtil, ) { this.modAuthor = packageJson.author.replace(/\W/g, "").toLowerCase(); this.modName = packageJson.name.replace(/\W/g, "").toLowerCase(); this.modPath = this.preSptModLoader.getModPath(this.getModFolderName()); - this.fikaConfig = this.jsonUtil.deserializeJsonC(this.vfs.readFile(path.join(this.modPath, "assets/configs/fika.jsonc"))); + this.fikaConfig = this.jsonUtil.deserializeJsonC(this.fileSystemSync.read(path.join(this.modPath, "assets/configs/fika.jsonc"))); } public getConfig(): IFikaConfig {