mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Merge pull request #613 from Danielv123/Fix-patch-with-missing-file
Correctly handle module files missing from a previously patched save
This commit is contained in:
1 file changed
+15
-5
@@ -77,9 +77,16 @@ export class SaveModule {
|
|||||||
|
|
||||||
static async fromSave(json: Static<typeof SaveModule.jsonSchema>, root: JSZip) {
|
static async fromSave(json: Static<typeof SaveModule.jsonSchema>, root: JSZip) {
|
||||||
const module = new this(lib.ModuleInfo.fromJSON(json));
|
const module = new this(lib.ModuleInfo.fromJSON(json));
|
||||||
module.files = new Map(
|
module.files = new Map(await Promise.all(json.files
|
||||||
await Promise.all(json.files.map(async f => [f, await root.file(f)!.async("nodebuffer")] as const))
|
.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;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,8 +402,11 @@ export async function patch(savePath: string, modules: SaveModule[]) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (let module of patchInfo.modules) {
|
for (let module of patchInfo.modules) {
|
||||||
for (let file of module.files.keys()) {
|
for (let filepath of module.files.keys()) {
|
||||||
zip.remove(root.file(file)!.name);
|
const file = root.file(filepath);
|
||||||
|
if (file !== null) {
|
||||||
|
zip.remove(file.name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
patchInfo.modules = [];
|
patchInfo.modules = [];
|
||||||
|
|||||||
Reference in new issue
Block a user