File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ class IProjectReader
2727 virtual void setFileName (const std::string &fileName) final { m_fileName = fileName; }
2828
2929 virtual bool load () = 0;
30+ virtual bool loadData (const std::string &data) = 0;
3031 virtual bool isValid () = 0;
3132 virtual void clear () = 0;
3233 virtual std::vector<std::shared_ptr<Target>> targets () = 0;
Original file line number Diff line number Diff line change @@ -235,9 +235,11 @@ bool Scratch3Reader::load()
235235 READER_STEP (step, " target -> costume -> rotationCenterY" );
236236 costume->setRotationCenterY (jsonCostume[" rotationCenterY" ]);
237237
238- void *data;
239- unsigned int size = m_zipReader->readFile (costume->fileName (), &data);
240- costume->setData (size, data);
238+ if (m_zipReader && !costume->data ()) {
239+ void *data;
240+ unsigned int size = m_zipReader->readFile (costume->fileName (), &data);
241+ costume->setData (size, data);
242+ }
241243
242244 target->addCostume (costume);
243245 }
@@ -349,6 +351,18 @@ bool Scratch3Reader::load()
349351 return true ;
350352}
351353
354+ bool Scratch3Reader::loadData (const std::string &data)
355+ {
356+ try {
357+ m_json = json::parse (data);
358+ } catch (std::exception &e) {
359+ printErr (" invalid JSON file" , e.what ());
360+ return false ;
361+ }
362+
363+ return load ();
364+ }
365+
352366bool Scratch3Reader::isValid ()
353367{
354368 if (m_json == " " )
@@ -391,6 +405,9 @@ std::vector<std::string> Scratch3Reader::extensions()
391405
392406void Scratch3Reader::read ()
393407{
408+ if (fileName ().empty ())
409+ return ;
410+
394411 // Read project.json
395412 m_zipReader = std::make_unique<ZipReader>(fileName ());
396413 if (m_zipReader->open ()) {
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ class Scratch3Reader : public IProjectReader
1414{
1515 public:
1616 bool load () override ;
17+ bool loadData (const std::string &data) override ;
1718 bool isValid () override ;
1819 void clear () override ;
1920 std::vector<std::shared_ptr<Target>> targets () override ;
You can’t perform that action at this time.
0 commit comments