Advertisement
InnovativeStudios

main.js

May 4th, 2023
1,002
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const host = {
  2.     protocol: "http://",
  3.     domain: "mod.a3sog.org",
  4.     port: 80,
  5.     path: "/SOG.zip",
  6.     gameIP: "127.0.0.1",
  7.     gamePORT: "2302"
  8. }
  9.  
  10. ipcMain.on('download', (event, info) => {  
  11.     settingsData.arma3path = info.arma3path
  12.     settings = JSON.stringify(settingsData)
  13.  
  14.     sfs.writeFile(sPath, settings, (e) => { if (e) throw e })
  15.    
  16.     let req = http.request({method: 'HEAD', host: host.domain, port: host.port, path: host.path}, (res) => {
  17.         if (res.headers["last-modified"] != settingsData["last-modified"] || settingsData.version == "-1") {
  18.             log.log("Mismatch: " + res.headers["last-modified"] + " != " + settingsData["last-modified"])
  19.             settingsData["last-modified"] = res.headers["last-modified"]
  20.            
  21.             if (fs.existsSync(`${info.arma3path}\\SOG`)) {
  22.                 rimraf(`${info.arma3path}\\SOG`, (e) => { if (e) throw e })
  23.             }
  24.            
  25.             download(BrowserWindow.getFocusedWindow(), host.protocol + host.domain + host.path, {
  26.                 directory: `${app.getPath("userData")}\\mods`, onProgress: (state) => win.webContents.send('dlProgress', state)
  27.             }).then(dl => {
  28.                 let file = dl.getSavePath()
  29.  
  30.                 extract(file, {dir: info.arma3path}, (e) => {
  31.                     if (e) throw e
  32.                 }).then(function unlinkFile() {
  33.                     fs.unlink(file, (e) => { if (e) throw e })
  34.                 }).then(function readWriteVersion() {
  35.                     version = vfs.readFileSync(info.arma3path + "\\SOG\\Version")
  36.                     settingsData.version = version.toString()
  37.                     settings = JSON.stringify(settingsData)
  38.                     vfs.writeFile(sPath, settings, (e) => { if (e) throw e })
  39.                 }).then(function sendComplete() {
  40.                     win.webContents.send('dlComplete', {version: settingsData.version, ip: host.gameIP, port: host.gamePORT, join: info.join})
  41.                 })
  42.             }).catch((e) => {
  43.                 if (e) log.log(e)
  44.                 dlServerUp = false
  45.                 win.webContents.send('serverDown', {download: true})
  46.             })
  47.         } else {
  48.             log.log("No Mismatch Found")
  49.             win.webContents.send('dlComplete', {version: settingsData.version, ip: host.gameIP, port: host.gamePORT, join: info.join})
  50.         }
  51.     })
  52.  
  53.     req.on('abort', (e) => {
  54.         if (e) log.log(e)
  55.         dlServerUp = false
  56.         win.webContents.send('serverDown', {download: true})
  57.     })
  58.  
  59.     req.on('error', (e) => {
  60.         if (e) log.log(e)
  61.         dlServerUp = false
  62.         win.webContents.send('serverDown', {download: true})
  63.     })
  64.  
  65.     req.end()
  66. })
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement