mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
try handling as a Scratch 1 file after scratch-parser validation fails
This commit is contained in:
parent
a92f33960f
commit
5593b28984
1 changed files with 21 additions and 14 deletions
|
@ -290,26 +290,33 @@ class VirtualMachine extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
const validationPromise = new Promise((resolve, reject) => {
|
const validationPromise = new Promise((resolve, reject) => {
|
||||||
try {
|
|
||||||
const sb1 = new SB1File(input);
|
|
||||||
const json = sb1.json;
|
|
||||||
json.projectVersion = 2;
|
|
||||||
return resolve([json, sb1.zip]);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ValidationError) {
|
|
||||||
// The input does not validate as a Scratch 1 file.
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The second argument of false below indicates to the validator that the
|
// The second argument of false below indicates to the validator that the
|
||||||
// input should be parsed/validated as an entire project (and not a single sprite)
|
// input should be parsed/validated as an entire project (and not a single sprite)
|
||||||
validate(input, false, (error, res) => {
|
validate(input, false, (error, res) => {
|
||||||
if (error) return reject(error);
|
if (error) return reject(error);
|
||||||
resolve(res);
|
resolve(res);
|
||||||
});
|
});
|
||||||
});
|
})
|
||||||
|
.catch(error => {
|
||||||
|
try {
|
||||||
|
const sb1 = new SB1File(input);
|
||||||
|
const json = sb1.json;
|
||||||
|
json.projectVersion = 2;
|
||||||
|
return [json, sb1.zip];
|
||||||
|
} catch (sb1Error) {
|
||||||
|
if (sb1Error instanceof ValidationError) {
|
||||||
|
// The input does not validate as a Scratch 1 file.
|
||||||
|
} else {
|
||||||
|
// The project appears to be a Scratch 1 file but it
|
||||||
|
// could not be successfully translated into a Scratch 2
|
||||||
|
// project.
|
||||||
|
throw sb1Error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Through original error since the input does not appear to be
|
||||||
|
// an SB1File.
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
|
||||||
return validationPromise
|
return validationPromise
|
||||||
.then(validatedInput => this.deserializeProject(validatedInput[0], validatedInput[1]))
|
.then(validatedInput => this.deserializeProject(validatedInput[0], validatedInput[1]))
|
||||||
|
|
Loading…
Reference in a new issue