From 62e66da03db6d5f6ed83d5f7cb904a37e72af79e Mon Sep 17 00:00:00 2001 From: Oleg Lokhvitsky Date: Fri, 14 Jun 2024 22:14:53 -0700 Subject: [PATCH] Cache isGameFile calculation per file --- src/main/FileManager.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/FileManager.ts b/src/main/FileManager.ts index 1ca6c79..ed7e223 100644 --- a/src/main/FileManager.ts +++ b/src/main/FileManager.ts @@ -11,6 +11,7 @@ export type FileStatus = { exists: boolean; extracted: boolean; filePath: string; + gameFile: boolean | null; modified: boolean; operations: FileOperation[]; }; @@ -33,6 +34,7 @@ export class FileManager { exists: false, extracted: false, filePath: normalizedFilePath, + gameFile: null, modified: false, operations: [], }); @@ -52,6 +54,14 @@ export class FileManager { return this.get(filePath).modified; } + public gameFile(filePath: string): boolean { + const fileStatus = this.get(filePath); + return ( + fileStatus.gameFile ?? + falseIfError(this.runtime.BridgeAPI.isGameFile(fileStatus.filePath)) + ); + } + public extract(filePath: string, mod: string): void { const fileStatus = this.get(filePath); fileStatus.operations.push({ mod, type: 'extract' }); @@ -93,7 +103,7 @@ export class FileManager { (fileStatus.filePath.endsWith('.txt') || fileStatus.filePath.endsWith('.json')) && // and it's part of the game - falseIfError(this.runtime.BridgeAPI.isGameFile(fileStatus.filePath)) + this.gameFile(filePath) ) { this.runtime.console.warn( `Mod "${mod}" is modifying file "${fileStatus.filePath}" without reading it first. No other mods have written to this file, but make sure to update this mod whenever Diablo II updates.`