@@ -221,63 +221,122 @@ PrivateCollectionManager.installCollectionFromFile = function (file) {
221221 var targetDir = path . join ( tempDir . name , fileName ) ;
222222 console . log ( "targetPath:" , targetDir ) ;
223223
224- var extractor = unzip . Extract ( { path : targetDir } ) ;
225- extractor . on ( "close" , function ( ) {
224+ var admZip = require ( 'adm-zip' ) ;
226225
227- //try loading the collection
228- try {
229- var definitionFile = path . join ( targetDir , "Definition.xml" ) ;
230- if ( ! fs . existsSync ( definitionFile ) ) throw Util . getMessage ( "collection.specification.is.not.found.in.the.archive" ) ;
226+ var zip = new admZip ( filePath ) ;
227+ zip . extractAllToAsync ( targetDir , true , function ( err ) {
228+ if ( err ) {
229+ ApplicationPane . _instance . unbusy ( ) ;
230+ Dialog . error ( "Error installing collection." ) ;
231+ tempDir . removeCallback ( ) ;
232+ } else {
233+ //try loading the collection
234+ try {
235+ var definitionFile = path . join ( targetDir , "Definition.xml" ) ;
236+ if ( ! fs . existsSync ( definitionFile ) ) throw Util . getMessage ( "collection.specification.is.not.found.in.the.archive" ) ;
231237
232- var fileContents = fs . readFileSync ( definitionFile , ShapeDefCollectionParser . CHARSET ) ;
238+ var fileContents = fs . readFileSync ( definitionFile , ShapeDefCollectionParser . CHARSET ) ;
233239
234- var domParser = new DOMParser ( ) ;
240+ var domParser = new DOMParser ( ) ;
235241
236- var collection = null ;
237- var dom = domParser . parseFromString ( fileContents , "text/xml" ) ;
238- if ( dom != null ) {
239- var dom = dom . documentElement ;
240- var parser = new PrivateShapeDefParser ( ) ;
241- Dom . workOn ( "./p:Collection" , dom , function ( node ) {
242- collection = parser . parseNode ( node ) ;
243- } ) ;
244- } ;
245-
246- if ( collection && collection . id ) {
247- //check for duplicate of name
248- for ( i in PrivateCollectionManager . privateShapeDef . collections ) {
249- var existingCollection = PrivateCollectionManager . privateShapeDef . collections [ i ] ;
250- if ( existingCollection . id == collection . id ) {
251- throw Util . getMessage ( "collection.named.already.installed" , collection . id ) ;
252- }
253- }
242+ var collection = null ;
243+ var dom = domParser . parseFromString ( fileContents , "text/xml" ) ;
244+ if ( dom != null ) {
245+ var dom = dom . documentElement ;
246+ var parser = new PrivateShapeDefParser ( ) ;
247+ Dom . workOn ( "./p:Collection" , dom , function ( node ) {
248+ collection = parser . parseNode ( node ) ;
249+ } ) ;
250+ } ;
254251
255- Dialog . confirm ( "Are you sure you want to install the unsigned collection: " + collection . displayName + "?" ,
256- "Since a collection may contain execution code that could harm your machine. It is hightly recommanded that you should only install collections from authors whom you trust." ,
257- "Install" , function ( ) {
258- // CollectionManager.setCollectionCollapsed(collection, false);
259- PrivateCollectionManager . addShapeCollection ( collection ) ;
260- tempDir . removeCallback ( ) ;
261- } , "Cancel" , function ( ) {
262- tempDir . removeCallback ( ) ;
252+ if ( collection && collection . id ) {
253+ //check for duplicate of name
254+ for ( i in PrivateCollectionManager . privateShapeDef . collections ) {
255+ var existingCollection = PrivateCollectionManager . privateShapeDef . collections [ i ] ;
256+ if ( existingCollection . id == collection . id ) {
257+ throw Util . getMessage ( "collection.named.already.installed" , collection . id ) ;
258+ }
263259 }
264- ) ;
265- } else {
266- throw Util . getMessage ( "collection.specification.is.not.found.in.the.archive" ) ;
260+
261+ Dialog . confirm ( "Are you sure you want to install the unsigned collection: " + collection . displayName + "?" ,
262+ "Since a collection may contain execution code that could harm your machine. It is hightly recommanded that you should only install collections from authors whom you trust." ,
263+ "Install" , function ( ) {
264+ // CollectionManager.setCollectionCollapsed(collection, false);
265+ PrivateCollectionManager . addShapeCollection ( collection ) ;
266+ tempDir . removeCallback ( ) ;
267+ } , "Cancel" , function ( ) {
268+ tempDir . removeCallback ( ) ;
269+ }
270+ ) ;
271+ } else {
272+ throw Util . getMessage ( "collection.specification.is.not.found.in.the.archive" ) ;
273+ }
274+ } catch ( e ) {
275+ Dialog . error ( "Error installing collection." ) ;
276+ } finally {
277+ ApplicationPane . _instance . unbusy ( ) ;
278+ tempDir . removeCallback ( ) ;
267279 }
268- } catch ( e ) {
269- Dialog . error ( "Error installing collection." ) ;
270- } finally {
271- ApplicationPane . _instance . unbusy ( ) ;
272- tempDir . removeCallback ( ) ;
273280 }
274- } ) . on ( "error" , function ( error ) {
275- ApplicationPane . _instance . unbusy ( ) ;
276- Dialog . error ( "Error installing collection." ) ;
277- tempDir . removeCallback ( ) ;
278281 } ) ;
279282
280- fs . createReadStream ( filePath ) . pipe ( extractor ) ;
283+ // var extractor = unzip.Extract({ path: targetDir });
284+ // extractor.on("close", function () {
285+
286+ // //try loading the collection
287+ // try {
288+ // var definitionFile = path.join(targetDir, "Definition.xml");
289+ // if (!fs.existsSync(definitionFile)) throw Util.getMessage("collection.specification.is.not.found.in.the.archive");
290+
291+ // var fileContents = fs.readFileSync(definitionFile, ShapeDefCollectionParser.CHARSET);
292+
293+ // var domParser = new DOMParser();
294+
295+ // var collection = null;
296+ // var dom = domParser.parseFromString(fileContents, "text/xml");
297+ // if (dom != null) {
298+ // var dom = dom.documentElement;
299+ // var parser = new PrivateShapeDefParser();
300+ // Dom.workOn("./p:Collection", dom, function (node) {
301+ // collection = parser.parseNode(node);
302+ // });
303+ // };
304+
305+ // if (collection && collection.id) {
306+ // //check for duplicate of name
307+ // for (i in PrivateCollectionManager.privateShapeDef.collections) {
308+ // var existingCollection = PrivateCollectionManager.privateShapeDef.collections[i];
309+ // if (existingCollection.id == collection.id) {
310+ // throw Util.getMessage("collection.named.already.installed", collection.id);
311+ // }
312+ // }
313+
314+ // Dialog.confirm("Are you sure you want to install the unsigned collection: " + collection.displayName + "?",
315+ // "Since a collection may contain execution code that could harm your machine. It is hightly recommanded that you should only install collections from authors whom you trust.",
316+ // "Install", function () {
317+ // // CollectionManager.setCollectionCollapsed(collection, false);
318+ // PrivateCollectionManager.addShapeCollection(collection);
319+ // tempDir.removeCallback();
320+ // }, "Cancel", function () {
321+ // tempDir.removeCallback();
322+ // }
323+ // );
324+ // } else {
325+ // throw Util.getMessage("collection.specification.is.not.found.in.the.archive");
326+ // }
327+ // } catch (e) {
328+ // Dialog.error("Error installing collection.");
329+ // } finally {
330+ // ApplicationPane._instance.unbusy();
331+ // tempDir.removeCallback();
332+ // }
333+ // }).on("error", function (error) {
334+ // ApplicationPane._instance.unbusy();
335+ // Dialog.error("Error installing collection.");
336+ // tempDir.removeCallback();
337+ // });
338+
339+ // fs.createReadStream(filePath).pipe(extractor);
281340} ;
282341PrivateCollectionManager . setLastUsedCollection = function ( collection ) {
283342 Config . set ( "PrivateCollection.lastUsedCollection.id" , collection . id ) ;
0 commit comments