Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const host = {
- protocol: "http://",
- domain: "mod.a3sog.org",
- port: 80,
- path: "/SOG.zip",
- gameIP: "127.0.0.1",
- gamePORT: "2302"
- }
- ipcMain.on('download', (event, info) => {
- settingsData.arma3path = info.arma3path
- settings = JSON.stringify(settingsData)
- sfs.writeFile(sPath, settings, (e) => { if (e) throw e })
- let req = http.request({method: 'HEAD', host: host.domain, port: host.port, path: host.path}, (res) => {
- if (res.headers["last-modified"] != settingsData["last-modified"] || settingsData.version == "-1") {
- log.log("Mismatch: " + res.headers["last-modified"] + " != " + settingsData["last-modified"])
- settingsData["last-modified"] = res.headers["last-modified"]
- if (fs.existsSync(`${info.arma3path}\\SOG`)) {
- rimraf(`${info.arma3path}\\SOG`, (e) => { if (e) throw e })
- }
- download(BrowserWindow.getFocusedWindow(), host.protocol + host.domain + host.path, {
- directory: `${app.getPath("userData")}\\mods`, onProgress: (state) => win.webContents.send('dlProgress', state)
- }).then(dl => {
- let file = dl.getSavePath()
- extract(file, {dir: info.arma3path}, (e) => {
- if (e) throw e
- }).then(function unlinkFile() {
- fs.unlink(file, (e) => { if (e) throw e })
- }).then(function readWriteVersion() {
- version = vfs.readFileSync(info.arma3path + "\\SOG\\Version")
- settingsData.version = version.toString()
- settings = JSON.stringify(settingsData)
- vfs.writeFile(sPath, settings, (e) => { if (e) throw e })
- }).then(function sendComplete() {
- win.webContents.send('dlComplete', {version: settingsData.version, ip: host.gameIP, port: host.gamePORT, join: info.join})
- })
- }).catch((e) => {
- if (e) log.log(e)
- dlServerUp = false
- win.webContents.send('serverDown', {download: true})
- })
- } else {
- log.log("No Mismatch Found")
- win.webContents.send('dlComplete', {version: settingsData.version, ip: host.gameIP, port: host.gamePORT, join: info.join})
- }
- })
- req.on('abort', (e) => {
- if (e) log.log(e)
- dlServerUp = false
- win.webContents.send('serverDown', {download: true})
- })
- req.on('error', (e) => {
- if (e) log.log(e)
- dlServerUp = false
- win.webContents.send('serverDown', {download: true})
- })
- req.end()
- })
Advertisement
Advertisement