(function(){vart;(t=classextendsthis.OS.application.BaseApplication{constructor(t){super("Archive",t),this.currfile="Untitled".asFileHandle(),this.args&&this.args.length>0&&this.args[0].path&&(this.currfile=t[0].path.asFileHandle())}main(){returnthis.btadd=this.find("btaradd"),this.btdel=this.find("btardel"),this.btxtract=this.find("btarxtract"),this.filetree=this.find("filetree"),this.zip=void0,this.bindKey("ALT-N",()=>this.fileMenuHandle("new")),this.bindKey("ALT-O",()=>this.fileMenuHandle("open")),this.bindKey("CTRL-S",()=>this.fileMenuHandle("save")),this.bindKey("ALT-S",()=>this.fileMenuHandle("saveas")),this.btxtract.onbtclick=t=>{vare,i;return(e=this.filetree.selectedItem)?(i=e.data,this.openDialog("FileDialog",{title:__("Select a folder"),mimes:["dir"]}).then(t=>this.xtract(i,t.file.path).then(()=>this.notify(__("extract successful: {0}",i.path))).catch(t=>this.error(t.toString(),t))).catch(t=>this.error(t.toString(),t))):this.notify(__("Please select file/folder to extract"))},this.btadd.onbtclick=t=>this.actionAdd(),this.btdel.onbtclick=t=>this.actionDel(),this.filetree.contextmenuHandle=(t,e)=>{vari,r;if(i=this.filetree.selectedItem)returnr=[{text:"__(Delete)",onmenuselect:()=>this.actionDel()},{text:"__(Info)",onmenuselect:()=>this.actionInfo()}],"dir"===i.data.type&&r.unshift({text:"__(Add)",onmenuselect:()=>this.actionAdd()}),e.items=r,e.show(t)},this.openar(this.currfile)}actionAdd(){vart,e;return(t=this.filetree.selectedItem)&&"dir"===t.data.type?(e=t.data,this.openDialog("FileDialog",{title:__("Select a file/folder")}).then(t=>this.addToZip(t.file,`${e.path}/${t.file.path.asFileHandle().basename}`).then(()=>(this.currfile.dirty=!0,this.refreshTreeFile())).catch(t=>this.error(t.toString(),t))).catch(t=>this.error(t.toString(),t))):this.notify(__("Please select a destination folder"))}actionDel(){vart,e;return(t=this.filetree.selectedItem)?(e=t.data).root?this.notify(__("You cannot delete the root node")):this.ask({title:"__(Delete)",text:__("Do you really want to delete: {0}?",e.text)}).then(t=>{if(t)returnthis.zip.remove(e.path.trimBy("/")),this.currfile.dirty=!0,this.refreshTreeFile()}).catch(t=>this.error(t.toString(),t)):this.notify(__("Please select a destination folder"))}actionInfo(){vart,e,i;return(t=this.filetree.selectedItem)?(e=t.data.path.trimBy("/"),"dir"===t.data.type&&(e+="/"),(i=this.zip.files[e])?this.openDialog("InfoDialog",{title:"About: "+i.name,name:i.name,date:i.date,dir:i.dir,dataBinary:i._dataBinary,size:i._data.uncompressedSize}):this.notify(__("Cannot get entry meta data"))):this.notify(__("Please select a file/folder"))}openar(t){returnthis.zip=void0,"Untitled"===t.filename?(this.zip=newJSZip,this.currfile=t,this.refreshTreeFile()):t.read("binary").then(e=>JSZip.loadAsync(e).then(e=>(this.zip=e,this.currfile=t,this.refreshTreeFile())).catch(t=>this.error(__("Wrong zip format: {0}",t.toString()),t))).catch(e=>this.error(__("Unable to read archive: {0}",t.path),e))}refreshTreeFile(){vart,e,i,r,n;if(this.zip){for(tinr={text:this.currfile.filename.trimFromRight(".zip"),type:"dir",path:"",open:!0,root:!0,nodes:[]},i=this.zip.files)n=i[t],e=this.putFileInTree(t.split("/"),r),n.dir||(e.type="file",deletee.nodes);returnthis.filetree.data=r}}putFileInTree(t,e){vari,r,n,a;returni=function(){vart,i,r,n;for(n=[],t=0,i=(r=e.nodes).length;t<i;t++)a=r[t],n.push(a.text);returnn}(),(r=t.shift())?i.includes(r)?this.putFileInTree(t,e.nodes[i.indexOf(r)]):(n={text:r,path:`${e.path}/${r}`,type:"dir",nodes:[]},e.nodes.push(n),this.putFileInTree(t,n)):e}xtract(t,e){returnnewPromise((i,r)=>"file"===t.type?this.zip.file(t.path.trimBy("/")).async("uint8array").then(n=>{vara;return(a=`${e}/${t.text}`.asFileHandle()).cache=newBlob([n],{type:"octet/stream"}),a.write().then((function(){returni()})).catch((function(t){returnr(__e(t))}))}).catch((function(t){returnr(__e(t))})):e.asFileHandle().mk(t.text).then(()=>{varn,a;returnn=function(){vare,i,r,n;for(n=[],e=0,i=(r=t.nodes).length;e<i;e++)a=r[e],n.push(a);returnn}(),this.xtractall(n,`${e}/${t.text}`).then((function(){retu