Skip to content

Commit

Permalink
Merge pull request #613 from Danielv123/Fix-patch-with-missing-file
Browse files Browse the repository at this point in the history
Correctly handle module files missing from a previously patched save
  • Loading branch information
Cooldude2606 committed Apr 27, 2024
2 parents 5612457 + 8831b33 commit c37fe0f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/host/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ export class SaveModule {

static async fromSave(json: Static<typeof SaveModule.jsonSchema>, root: JSZip) {
const module = new this(lib.ModuleInfo.fromJSON(json));
module.files = new Map(
await Promise.all(json.files.map(async f => [f, await root.file(f)!.async("nodebuffer")] as const))
);
module.files = new Map(await Promise.all(json.files
.map(filename => ({filename, file: root.file(filename)}))
.filter(({filename, file}) => {
if (file === null) {
lib.logger.warn(`Missing file ${filename} in save`);
}
return file !== null;
})
.map(async ({filename, file}) => [filename, await file!.async("nodebuffer")] as const)
));
return module;
}

Expand Down Expand Up @@ -395,8 +402,11 @@ export async function patch(savePath: string, modules: SaveModule[]) {
}
} else {
for (let module of patchInfo.modules) {
for (let file of module.files.keys()) {
zip.remove(root.file(file)!.name);
for (let filepath of module.files.keys()) {
const file = root.file(filepath);
if (file !== null) {
zip.remove(file.name);
}
}
}
patchInfo.modules = [];
Expand Down

0 comments on commit c37fe0f

Please sign in to comment.