//!wrt $BSPEC:{"icn":"C:/local/border/res/img/icon32.png","cpr":"Copyright (C) Onofficiel 2024.","dsc":"Blugin Installation Program","frn":"Blugin Installer","aut":"Onofficiel","ver":1,"ssy":"gui"} function _defineProperty(e,t,i){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==typeof t?t:String(t)}function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var r=i.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}const{WizardBaseApplication:WizardBaseApplication}=w96.app.templates,{FSView:FSView,GroupBox:GroupBox}=w96.ui.components,{uuid:uuid}=w96.util,{KConsole:KConsole}=w96.ktypes;class SemVer{constructor(e="0.0.0"){const t=e.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/);if(!t)throw new Error("Invalid version string");this.major=Number.parseInt(t[1],10),this.minor=Number.parseInt(t[2],10),this.patch=Number.parseInt(t[3],10),this.preRelease=t[4]?t[4].split("."):[],this.build=t[5]||""}[Symbol.toPrimitive](e){if("string"===e){const e=this.preRelease.length?`-${this.preRelease.join(".")}`:"",t=this.build?`+${this.build}`:"";return`${this.major}.${this.minor}.${this.patch}${e}${t}`}return"number"===e?1e6*this.major+1e3*this.minor+this.patch:null}static compare(e,t){if(!(e instanceof SemVer&&t instanceof SemVer))throw new Error("Invalid version objects");const i=Number(e),r=Number(t);return ir?1:0}static isLowerThan(e,t){return-1===SemVer.compare(e,t)}static isGreaterThan(e,t){return 1===SemVer.compare(e,t)}static isEqual(e,t){return 0===SemVer.compare(e,t)}isLowerThan(e){return-1===this.constructor.compare(this,e)}isGreaterThan(e){return 1===this.constructor.compare(this,e)}isEqual(e){return 0===this.constructor.compare(this,e)}toString(){return String(this)}}const PRODUCT={NAME:"Border",get NAME_SNAKE(){return this.NAME.toLocaleLowerCase().replace(/ /g,"_")},get NAME_KEBAB(){return this.NAME.toLocaleLowerCase().replace(/ /g,"-")},get NAME_CAMEL(){return this.NAME.replace(/(?:^\w|[A-Z]|\b\w)/g,(e=>e.toUpperCase())).replace(/\s+/g,"")},VERSION:new SemVer("2.0.0-dev"),AUTHOR:"Onofficiel",get COPYRIGHT(){return`${this.NAME} (C) ${this.AUTHOR} 2024`}},PATH={APPDATA:`C:/user/appdata/${PRODUCT.NAME_KEBAB}`,LOCAL:`C:/local/${PRODUCT.NAME_KEBAB}`};class BluginInstaller extends WizardBaseApplication{constructor(...e){super(...e),_defineProperty(this,"folderPath",`C:/system/temp/${uuid.generateV4()}`),_defineProperty(this,"zip",null)}async main(e){await super.main(e),this.pages=[],this.pages.push({id:"dropper",type:"page",body:'\n
\n
\n ',graphic:"/system/resource/app/resetwiz/graphic-top.png",titleText:"Drag and drop the blugin package here:",description:"Or click on Cancel to discard.",buttons:[{onclick:()=>this.quit(),enabled:!0,text:"Cancel"}],onopen:async e=>{const t=e.querySelector(".content");Object.assign(t.style,{display:"flex",flexDirection:"column",padding:"10px",gap:"8px",justifyContent:"center",alignItems:"center"});const i=t.querySelector(".info");await FS.mkdir(this.folderPath);const r=new FSView(this.folderPath,!0);await r.init(),r.ondropfinish=async()=>{r.navigate(this.folderPath),this.appWindow.activate();const e=(await FS.readdir(this.folderPath))[0],t=await FS.readbin(e);JSZip.loadAsync(t).then((e=>{this.zip=e,e.files["manifest.yml"]?this.openPage("confirm",e):i.textContent="Invalid blugin package."})).catch((e=>{i.textContent=e}))};const n=r.getElement(),s="210px";r.setSize(s,s),Object.assign(n.style,{margin:0,flex:"none",border:"1px solid var(--3d-obj-color-primary)",outline:"1px dashed purple",boxShadow:"1px 1px purple inset, -1px -1px purple inset"}),r.navigate(this.folderPath),t.querySelector(".fs-view").replaceWith(n)}}),this.pages.push({id:"confirm",type:"page",body:'\n
\n
\n ',graphic:"/system/resource/app/resetwiz/graphic-top.png",titleText:"Are you sure you want to install this blugin?",description:"Check the information below before installing.",buttons:[{onclick:()=>this.openPage("dropper"),enabled:!0,text:"Back"},{class:"install",onclick:()=>this.openPage("install"),enabled:!1,text:"Install"}],onopen:async e=>{setTimeout((()=>{e.querySelector(".install").disabled=!1}),5e3);const t=e.querySelector(".content"),i=w96.yaml.load(await this.zip.files["manifest.yml"].async("text")),{meta:r,permissions:n}=i,s=new GroupBox({title:"Manifest",body:`\n ${r.name} v${r.version} (by ${r.author})
\n ${r.description}`});t.querySelector(".meta-data").replaceWith(s.getElement());const o=new GroupBox({title:"Permissions",body:``});t.querySelector(".permissions").replaceWith(o.getElement())}}),this.pages.push({id:"install",type:"page",graphic:"/system/resource/app/resetwiz/graphic-top.png",titleText:"Installing the blugin...",description:"Please wait",body:'\n
\n
\n
\n
\n
\n ',buttons:[{class:"next",text:"Next",onclick:()=>this.terminate(),enabled:!1}],onopen:async e=>{const t=e.querySelector(".logs");Object.assign(t.style,{overflow:"hidden scroll",padding:"4px",marginTop:"2px",width:"100%",height:"160px",boxSizing:"border-box",resize:"none",color:"lime",lineHeight:"1.1",outline:"0",fontSize:"13px",fontFamily:"fixed_bmp,monospace",background:"#000"});const i=new KConsole(t),r=e.querySelector(".w96-progressbar"),n=(e="Something went wrong")=>{r.replaceWith(new Text(e)),i.error(e)};let s,o;i.println_styled("This console will log all the output of the blugin installation.","color: yellow");do{s=uuid.generateV4(),o=`${PATH.APPDATA}/blugins/${s}`}while(await FS.exists(o));for(const[e,t]of Object.entries(this.zip.files).filter((([e,t])=>!t.dir))){const r=`${o}/${e}`,s=FSUtil.getParentPath(r);i.println(`Installing ${e}...`),await FS.exists(s)||await FS.mkdir(s);const a=await t.async("string").catch(n);await FS.writestr(r,a)}r.replaceWith(new Text("Done! Click Next to quit.")),i.println("Blugin installed successfully."),e.querySelector(".next").disabled=!1}}),this.openPage("dropper")}async ontermination(){await super.ontermination(),await FS.rmdir(this.folderPath)}} return await WApplication.execAsync(new BluginInstaller(), this.boxedEnv.args, this);