0

Hello fellow developers/programmers. Today I come to ask for help with something, and is that I'm making an app that if or if it has to be portable, the problem I'm having is that when writing a zip file the app does not find the directories or generates the zip corruptly.

My code that writes the zip file looks like this:

ipcMain.on("report-file", async (event, data) => {
      let zipFilePath = "report.zip"

      let output = fs.createWriteStream(zipFilePath);
      let archive = archiver("zip")
      archive.pipe(output);

      if (data.saves) {
            archive.directory(`game/saves`, false)
            archive.directory(`game/cache`, false)
      }

      archive.append(fs.createReadStream(`log.txt`), {
            name: `log.txt`,
      })

      archive.append(fs.createReadStream(`traceback.txt`), {
            name: `traceback.txt`,
      })

      archive.finalize()  
});

Electron Version: 21.2.3

SO: Windows 11

electron-builder Version: 23.6.0

Looking a little more in depth, I found that the app is using the address C:\User\User\AppData\Local\Temp\[id]\resources\app.asar and it is trying to compress the files as if they were in that path, however, the files to compress are located where the .exe is. (G:\myapp\dist)

I already tried to fix it by following an old post on the stackoverflow page, however, it didn't solve the problem, so today I decided to ask my question here, do you have any idea how to get the actual path of an electron js portable app?

Neyunse
  • 105
  • 5
  • The portable is not the app, it is just something that extracts itself into the tmp folder. in the tmp is your real electron app. Because of that paths like __dir may direct you there. And when you try to pack something relative to your app, you may get problems, because your app is archived into an app.asar which is no valid path for new files to put into. Had no need for that yet, but did you really try out every approach in the link? some of them will only work after building the .exe so they may not work when you use `electron .` – Welcor Nov 18 '22 at 18:08

1 Answers1

0

I found the solution to this, and it was to create a dialog with electron, and load the folder location. Then use resolve together with the address of the executable, this way it loads correctly the address of the folder where the exe is located.

let dir
dir = await dialog.showOpenDialog(win, {
     properties: ['openDirectory'],
     defaultPath: path.resolve('.', process.env.PORTABLE_EXECUTABLE_DIR)
});
Neyunse
  • 105
  • 5