@@ -53,11 +53,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5353 } ;
5454
5555 Loader . prototype . _proceedJMS1 = function ( ) {
56- var def = Q . defer ( ) ;
56+ var _this = this ;
5757 this . jpakType = "JMS" ;
58- def . reject ( "TODO: Implement it!" ) ;
59-
60- return def . promise ;
58+ JPAK . Tools . d ( "JMS1 Format" ) ;
59+ return this . _p_getFileSize ( ) . then ( function ( ) { return _this . _p_jms1_loadFileTable ( ) ; } ) ;
6160 } ;
6261
6362 Loader . prototype . checkMagic = function ( magic ) {
@@ -109,7 +108,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
109108 var base = this . fileTable ;
110109 if ( this . tableLoaded ) {
111110 if ( path !== "/" ) {
112- path = path . split ( "/" ) . clean ( "" ) ;
111+ path = JPAK . Tools . cleanArray ( path . split ( "/" ) , "" ) ;
113112 var dir = "" , ok = true ;
114113 for ( var i = 0 ; i < path . length ; i ++ ) {
115114 dir = path [ i ] ;
@@ -132,7 +131,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
132131 * Returns null if not found
133132 */
134133 Loader . prototype . findFileEntry = function ( path ) {
135- var pathblock = path . split ( "/" ) . clean ( "" ) ;
134+ var pathblock = JPAK . Tools . cleanArray ( path . split ( "/" ) , "" ) ;
136135 var filename = pathblock [ pathblock . length - 1 ] ;
137136 path = path . replace ( filename , "" ) ;
138137 var base = this . findDirectoryEntry ( path ) ;
@@ -168,7 +167,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
168167
169168 switch ( this . jpakType ) {
170169 case "JPAK1" : return this . _p_jpak1_getFileBlob ( path , type ) ;
171- case "JMS" : return this . _p_jms_getFileBlob ( path , type ) ;
170+ case "JMS" : return this . _p_jms1_getFileBlob ( path , type ) ;
172171 default : def . reject ( "Not a valid jpak file!" ) ;
173172 }
174173
@@ -193,7 +192,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
193192
194193 switch ( this . jpakType ) {
195194 case "JPAK1" : return this . _p_jpak1_getFile ( path , type ) ;
196- case "JMS" : return this . _p_jms_getFile ( path , type ) ;
195+ case "JMS" : return this . _p_jms1_getFile ( path , type ) ;
197196 default : def . reject ( "Not a valid jpak file!" ) ;
198197 }
199198
@@ -313,6 +312,91 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
313312 return def . promise ;
314313 } ;
315314
315+ Loader . prototype . _p_jms1_loadFileTable = function ( ) {
316+ var _this = this ;
317+ var tableOffsetLoader = new JPAK . Tools . DataLoader ( {
318+ url : this . jpakfile ,
319+ partial : true ,
320+ partialFrom : this . fileSize - 4 ,
321+ partialTo : this . fileSize
322+ } ) ;
323+
324+ return tableOffsetLoader . start ( ) . then ( function ( data ) {
325+ _this . fileTableOffset = new DataView ( data ) . getUint32 ( 0 , true ) ;
326+ var fileTableLoader = new JPAK . Tools . DataLoader ( {
327+ url : _this . jpakfile ,
328+ partial : true ,
329+ partialFrom : _this . fileTableOffset ,
330+ partialTo : _this . fileSize - 16 - 1
331+ } ) ;
332+
333+ return fileTableLoader . start ( ) ;
334+ } ) . then ( function ( data ) {
335+ data = ( new Uint8Array ( data ) ) . asString ( ) ;
336+ _this . fileTable = JSON . parse ( data ) ;
337+ _this . tableLoaded = true ;
338+
339+ var volumeTableLoader = new JPAK . Tools . DataLoader ( {
340+ url : _this . jpakfile ,
341+ partial : true ,
342+ partialFrom : 0xC ,
343+ partialTo : _this . fileTableOffset - 1
344+ } ) ;
345+
346+ return volumeTableLoader . start ( ) ;
347+
348+ } ) . then ( function ( data ) {
349+ var def = Q . defer ( ) ;
350+ data = ( new Uint8Array ( data ) ) . asString ( ) ;
351+ _this . volumeTable = JSON . parse ( data ) ;
352+ _this . volumeTableLoaded = true ;
353+ def . resolve ( _this . fileTable ) ;
354+ return def . promise ;
355+ } ) ;
356+ } ;
357+
358+ Loader . prototype . _p_jms1_getFile = function ( path , type ) {
359+ var def = Q . defer ( ) ;
360+ var file = this . findFileEntry ( path ) ;
361+ type = type || 'application/octet-binary' ;
362+
363+ if ( file . volume in this . volumeTable ) {
364+ var volumePath = this . volumeTable [ file . volume ] . filename ;
365+ var fileLoader = new JPAK . Tools . DataLoader ( {
366+ url : volumePath ,
367+ partial : true ,
368+ partialFrom : file . offset ,
369+ partialTo : file . offset + file . size - 1
370+ } ) ;
371+
372+ fileLoader . start ( ) . then ( function ( data ) {
373+ if ( file . compressed !== undefined && file . compressed )
374+ data = JPAK . Tools . GZ . decompress ( data ) ;
375+ def . resolve ( data ) ;
376+ } ) . fail ( function ( error ) {
377+ def . reject ( error ) ;
378+ } ) ;
379+ } else {
380+ def . reject ( "Volume \"" + file . volume + "\" not found!" ) ;
381+ }
382+
383+ return def . promise ;
384+ } ;
385+
386+ Loader . prototype . _p_jms1_getFileBlob = function ( path , type ) {
387+ var def = Q . defer ( ) ;
388+
389+ this . _p_jms1_getFile ( path , type ) . then ( function ( data ) {
390+ def . resolve ( new Blob ( [ new Uint8Array ( data ) . buffer ] , { "type" :type } ) ) ;
391+ } ) . fail ( function ( error ) {
392+ def . reject ( error ) ;
393+ } ) ;
394+
395+ return def . promise ;
396+ } ;
397+
316398 JPAK . Loader = Loader ;
317399 }
400+
401+
318402} ) ( ) ;
0 commit comments