Skip to content

Commit

Permalink
Replace VFS wtih FileSystemSync
Browse files Browse the repository at this point in the history
Todo: Should probably just use the methods that come with filesystemsync to read json files
  • Loading branch information
ArchangelWTF committed Jan 12, 2025
1 parent 6c2b1c6 commit 39fdbd0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions src/services/cache/FikaFriendRequestsCacheService.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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[] {
Expand All @@ -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));
}
}
14 changes: 7 additions & 7 deletions src/services/cache/FikaPlayerRelationsCacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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() {
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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));
}
}
6 changes: 3 additions & 3 deletions src/utils/FikaConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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 {
Expand Down

0 comments on commit 39fdbd0

Please sign in to comment.