Skip to content

Conversation

@chrisgarrity
Copy link
Contributor

@chrisgarrity chrisgarrity commented Feb 1, 2019

Looks for a directory structure in the zip file, and prepends the name when extracting the project json if necessary. Will not currently work with gzipped files. Project seems to load correctly after validating the json.

Fixes #42
Note: do not use OSX compress as it creates additional ‘hidden’ folders, and loading the file fails.

@chrisgarrity
Copy link
Contributor Author

@kchadha pushed an update that fixes the test that was failing and adds tests.

The test was failing because the invalid comments file had been created with MacOS compress, so it had an extra 'hidden' folder. That caused it to fail to load before validating. I created a new _invalid_comments.sb3 that has the invalid project json, but no extra folder and that runs fine.

Also added a test for parsing an sb2 with a nested folder structure, and one that tests that anything with more than one folder is invalid.

Questions:

  • Could there be gzip files with subfolders? they're definitely not handled.
  • Should it be friendlier and accept any number of folders as long as one of them has a project.json?

lib/unzip.js Outdated
.then(function (zip) {
return zip.file(isSprite ? 'sprite.json' : 'project.json').async('string')
const dir = Object.values(zip.files).filter(f => f.dir);
const projectJson = dir.length === 1 ? dir[0].name + 'project.json' : 'project.json';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm... I think I would prefer for the parser to look for the project.json in a dir only if it fails to find a file with the name at the top level. Also, I think we should probably make the same provisions for sprite.json as we do for project.json.

I am not sure if it is possible to find out if zip.file('project.json') actually succeeded or not...

@chrisgarrity chrisgarrity force-pushed the handle-sb2-nested-zip branch from 31a48e4 to 45875e3 Compare February 5, 2019 16:36
lib/unzip.js Outdated
});
let file;
if (isSprite) {
file = zip.file('sprite.json');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to treat sprite files the same way we treat project files. I just confirmed that this was something that worked for .sprite2 files in the 2.0 editor.

@chrisgarrity chrisgarrity force-pushed the handle-sb2-nested-zip branch from 45875e3 to 6335962 Compare February 6, 2019 12:07
Uses a pattern to find the sprite or project json in a zipped folder or flat list of files.

Added tests for
* loading a sprite or project with a nested folder
* loading a file without a json

Fixes scratchfoundation#42
@chrisgarrity
Copy link
Contributor Author

VM PR is also ready: scratchfoundation/scratch-vm#1993

Copy link
Contributor

@kchadha kchadha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for working through the changes. I think this should be pulled into VM via the VM PR (#1993)

@chrisgarrity chrisgarrity merged commit 94c7c51 into scratchfoundation:master Feb 12, 2019
@chrisgarrity chrisgarrity deleted the handle-sb2-nested-zip branch February 12, 2019 11:17
@kchadha
Copy link
Contributor

kchadha commented Feb 12, 2019

🎉 This PR is included in version 4.3.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants