Problems using JSON parser on Morph Asset .dsf files

Richard HaseltineRichard Haseltine Posts: 100,939

I seem to be running into two problems trying to load .dsf morph asset files as objects - first, I can't even when they are uncompressed and secondly, I can't open them at all if they are compressed. The function is being passed the absolute path to a file:

function process( name ) {
 
 // open file
 var file = new DzFile( name );
 if ( file.open( DzFile.ReadOnly ) ) {
  // try and if the file won't parse plain go onto try it as a zip file
  try {
   // Load as DSON object
   var ourObject = JSON.parse( file.read() );
  }
  catch ( e ) {
   // close the file
   file.close();
   // Now open as a DzZipFile
   file = new DzZipFile( name );
   if ( file.open( DzZipFile.ReadOnly ) ) {
    try {
     // Load as DSON object
     var ourObject = JSON.parse( file.read() );
    }
    catch ( e ) {
     // and if that didn't work either close and give up
     file.close();
     return;
    }
   }
  }
  file.close();
  if ( ourObject.modifier_library ) {
   // Do stuff
  }
 }
 return;
}

If I send it to an encrypted morph asset it can't even open the file - the file = new DzZipFile( name ); line doesn't return a valid object. I tried making a new variable, var zFile = new DzZipFile( name );, in case it didn't like reusing the file variable but that didn't help. It is getting to the DzZipFile section, just not creating the file object.

If I send it to a plain text Morph Asset it does open the file OK, apparently, but it still doesn't create a valid object with the JSON command.

Comments

  • Richard HaseltineRichard Haseltine Posts: 100,939
    edited December 1969

    Oddly, I just tried again stripping out all the Try stuff and it did work on the plain text morph assets in a folder it had been failing on before. However, I still can't handle compressed assets - and the DSON parser doesn't fail gracefully if asked to, so I think I need some form of the try...catch code.

  • Richard HaseltineRichard Haseltine Posts: 100,939
    edited December 1969

    And on a third look I see there's no read() for DzZipFile, which is a good reason for it to fail anyway (though I seemed to be getting an error before the read function, it wouldn't even create a valid object) - so how, if at all, do we read the contents of a compressed .dsf to pass it to the JSON parser? It certainly doesn't seem to take them directly.

  • millighostmillighost Posts: 261
    edited December 1969

    And on a third look I see there's no read() for DzZipFile, which is a good reason for it to fail anyway (though I seemed to be getting an error before the read function, it wouldn't even create a valid object) - so how, if at all, do we read the contents of a compressed .dsf to pass it to the JSON parser? It certainly doesn't seem to take them directly.

    Use DzGZFile. DzZipFile is for zip-files (the ones with multiple files in it, like the installer files).

  • Richard HaseltineRichard Haseltine Posts: 100,939
    edited December 1969

    Ah, I'd missed that. I thought Zip was the wrong compression method. Thanks.

Sign In or Register to comment.