import Installer from './Installer' import Path from 'path' import fs from 'fs' class WinInstall extends Installer{ getLocalConfig(){ var data={}, other data.binarypath= process.env.USERPROFILE other= this.winEnvironment() for(var id in other.local){ data[id]=other.local[id] } return data } getGlobalConfig(){ var data={}, other data.binarypath= process.env.WINDIR other= this.winEnvironment() for(var id in other.global){ data[id]=other.global[id] } return data } $binaryStr(dir, bin){ var str=[] var file= Path.join(dir,bin) str.push("@echo off") str.push("vox \"" + file + "\" %*") str= str.join("\r\n") return str } generateBinaries(config, installConfig){ var file1, file2, file3,conf,text for(var id in config.bin){ conf= config.bin[id] text= this.$binaryStr(installConfig.path, conf.exec) file1= Path.join(installConfig.binarypath, id+".cmd") file2= Path.join(installConfig.binarypath, id+"w.exe") file3= Path.join(installConfig.binarypath, id+"w.exe.config") fs.writeFileSync(file1, text) fs.writeFileSync(file2, fs.readFileSync(__dirname + "/../vox.exe")) fs.writeFileSync(file3, fs.readFileSync(__dirname + "/../vox.exe.config")) conf.executable= file2 while(conf.executable.indexOf("/")>-1){ conf.executable=conf.executable.replace("/","\\") } } } winEnvironment(){ var appdata,appdataglobal, desktop, desktopGlobal; var inappdata; //if(windows){ appdata= process.env.USERPROFILE + "/Start Menu/Programs/"; if(!fs.existsSync(appdata)){ appdata= process.env.APPDATA + "/Microsoft/Windows/Start Menu/Programs/" inappdata= true; } appdataglobal= process.env.ALLUSERSPROFILE; if(inappdata){ appdataglobal= process.env.PROGRAMDATA; if(appdataglobal){ appdataglobal+= "/Microsoft/Windows"; } } if(appdataglobal){ appdataglobal+= "/Start menu/Programs/"; } else{ appdataglobal= appdata; } desktop= process.env.USERPROFILE + "/Desktop/"; desktopGlobal= process.env.PUBLIC; if(!desktopGlobal){ desktopGlobal= process.env.ALLUSERSPROFILE; } if(desktopGlobal){ desktopGlobal+= "/Desktop/"; } else{ desktopGlobal= desktop; } //} return { "global":{ "programs": appdataglobal, "desktop": desktopGlobal }, "local":{ "programs": appdata, "desktop": desktop } } } // Generación de accesos directos .... generateIconAsync(conf, installConfig){ var dir=installConfig.path var task= new core.VW.Task() if(conf.shorcuts===false){ return } if(conf.icon){ if(typeof conf.icon == "string"){ conf.icon= dir + "/" + conf.icon } else{ if(conf.icon.icon){ conf.icon.icon= dir + "/" + conf.icon.icon } if(conf.icon.winicon){ conf.icon.winicon= dir + "\\" + conf.icon.winicon } } } var file= installConfig.programs if(conf.menudir){ file= Path.join(file, conf.menudir) if(!fs.existsSync(file)) fs.mkdirSync(file) } var args={ "target": conf.executable } if(conf.icon && conf.icon.winicon) args.icon= conf.icon.winicon file= Path.join(file, conf.name || conf.id) file+= ".lnk" var ws = require('vw-windows-shortcuts') ws.create(file, args, function(err){ if(err){ task.exception= err task.finish() return } file= installConfig.desktop if(!fs.existsSync(file)) fs.mkdirSync(file) file+= conf.name || conf.id file+= ".lnk" ws.create(file, args, function(err){ if(err){ task.exception= err task.finish() return } task.finish() }) }) return task } async generateAutoStart(conf, installConfig){ await core.Microsoft.Win32.Registry.ready() var key if(installConfig.global) key=core.Microsoft.Win32.Registry.localMachine else key=core.Microsoft.Win32.Registry.currentUser key= await key.openSubKeyAsync("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",true) await key.setValueAsync(conf.id, conf.executable) } } export default WinInstall