Skip to content

Commit

Permalink
Operate on a buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Oct 15, 2023
1 parent 93b9bce commit facfd4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
9 changes: 5 additions & 4 deletions src/projector/otto/windows.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
Expand Down
25 changes: 4 additions & 21 deletions src/util/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPatcherPatch[]>,
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'
);
Expand Down

0 comments on commit facfd4e

Please sign in to comment.