Skip to content

Commit

Permalink
Cache isGameFile calculation per file
Browse files Browse the repository at this point in the history
  • Loading branch information
olegbl committed Jun 15, 2024
1 parent 4604bcc commit 62e66da
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/FileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type FileStatus = {
exists: boolean;
extracted: boolean;
filePath: string;
gameFile: boolean | null;
modified: boolean;
operations: FileOperation[];
};
Expand All @@ -33,6 +34,7 @@ export class FileManager {
exists: false,
extracted: false,
filePath: normalizedFilePath,
gameFile: null,
modified: false,
operations: [],
});
Expand All @@ -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' });
Expand Down Expand Up @@ -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.`
Expand Down

0 comments on commit 62e66da

Please sign in to comment.