handle sb2 files zipped in a folder

If the asset can’t be found by name, look for the same asset in a folder within the zipfile.
This commit is contained in:
chrisgarrity 2019-02-08 15:03:27 +01:00
parent d1d5b80d55
commit a4b0550013

View file

@ -26,7 +26,13 @@ const deserializeSound = function (sound, runtime, zip, assetFileName) {
return Promise.resolve(null); return Promise.resolve(null);
} }
const soundFile = zip.file(fileName); let soundFile = zip.file(fileName);
if (!soundFile) {
// look for assetfile in a flat list of files, or in a folder
const fileMatch = new RegExp(`^([^/]*/)?${fileName}$`);
soundFile = zip.file(fileMatch)[0]; // use first matching file
}
if (!soundFile) { if (!soundFile) {
log.error(`Could not find sound file associated with the ${sound.name} sound.`); log.error(`Could not find sound file associated with the ${sound.name} sound.`);
return Promise.resolve(null); return Promise.resolve(null);
@ -100,7 +106,13 @@ const deserializeCostume = function (costume, runtime, zip, assetFileName, textL
return Promise.resolve(null); return Promise.resolve(null);
} }
const costumeFile = zip.file(fileName); let costumeFile = zip.file(fileName);
if (!costumeFile) {
// look for assetfile in a flat list of files, or in a folder
const fileMatch = new RegExp(`^([^/]*/)?${fileName}$`);
costumeFile = zip.file(fileMatch)[0]; // use the first matched file
}
if (!costumeFile) { if (!costumeFile) {
log.error(`Could not find costume file associated with the ${costume.name} costume.`); log.error(`Could not find costume file associated with the ${costume.name} costume.`);
return Promise.resolve(null); return Promise.resolve(null);