From facfd4e5e8f2f1877990708f8b78a17ceede8b31 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Sun, 15 Oct 2023 01:52:12 -0400 Subject: [PATCH] Operate on a buffer --- src/projector/otto/windows.ts | 9 +++++---- src/util/windows.ts | 25 ++++--------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/projector/otto/windows.ts b/src/projector/otto/windows.ts index 720408c..33c8b00 100644 --- a/src/projector/otto/windows.ts +++ b/src/projector/otto/windows.ts @@ -1,4 +1,4 @@ -import {readFile} from 'node:fs/promises'; +import {readFile, writeFile} from 'node:fs/promises'; import {join as pathJoin, dirname, basename} from 'node:path'; import { @@ -277,9 +277,10 @@ export class ProjectorOttoWindows extends ProjectorOtto { } found = true; - await windowsPatch3dDisplayDriversSize( - pathJoin(xtrasDir, path) - ); + const f = pathJoin(xtrasDir, path); + const d = await readFile(f); + windowsPatch3dDisplayDriversSize(d); + await writeFile(f, d); }, { ignoreUnreadableDirectories: true diff --git a/src/util/windows.ts b/src/util/windows.ts index 5069e33..2acab38 100644 --- a/src/util/windows.ts +++ b/src/util/windows.ts @@ -603,31 +603,14 @@ function patchDataOnce( } } -/** - * Patch a file once. - * - * @param file File path. - * @param candidates Patch candidates. - * @param name Patch name. - */ -async function patchFileOnce( - file: string, - candidates: Readonly, - name: string -) { - const data = await readFile(file); - patchDataOnce(data, candidates, name); - await writeFile(file, data); -} - /** * Patch Windows Shockwave 3D InstalledDisplayDrivers size. * - * @param file File path. + * @param data File data. */ -export async function windowsPatch3dDisplayDriversSize(file: string) { - await patchFileOnce( - file, +export function windowsPatch3dDisplayDriversSize(data: Uint8Array) { + patchDataOnce( + data, patch3dDisplayDriversSizePatches, 'Windows Shockwave 3D InstalledDisplayDrivers Size' );