From ae1cd71d3b4dde123d10dabde8f2db8042d9d8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=97=D0=BB=20=D0=93=D1=80=D0=B8?= =?UTF-8?q?=D0=B3=D0=BE=D1=80=27=D1=94=D0=B2?= Date: Wed, 26 Mar 2025 22:46:14 +0200 Subject: [PATCH] Fix file writes to non-existent directories When the game attempts to create the settings file but its directory does not exist yet, an early error occurs. In reality, there is no way for the directory to be created without user intervention. This change makes sure the directory is created before any attempt to write a file is done. Errors related to directory creation and/or file writes are still reported as usual. --- electron/src/fsjob.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/electron/src/fsjob.ts b/electron/src/fsjob.ts index 6672ad8d..0e85ea69 100644 --- a/electron/src/fsjob.ts +++ b/electron/src/fsjob.ts @@ -49,6 +49,10 @@ export class FsJobHandler { } private async write(file: string, contents: string): Promise { + // The target directory might not exist, ensure it does + const parentDir = path.dirname(file); + await fs.mkdir(parentDir, { recursive: true }); + // Backups not implemented yet. await fs.writeFile(file, contents, { encoding: "utf-8",