@@ -11,6 +11,7 @@ const fsPromises = require("fs").promises;
1111const _ = require ( "lodash" ) ;
1212const Seven = require ( "node-7z" ) ;
1313const sevenBin = require ( "7zip-bin" ) ;
14+ const which = require ( "which" ) ;
1415
1516// TODO - Replace this with fs.readdir(..., { recursive: true }) when electron uses Node v18.17.0+
1617const recursiveReaddir = require ( "recursive-readdir" ) ;
@@ -224,17 +225,36 @@ class ElectronLoader {
224225 case ".rar" : {
225226 decompressOperation = new Promise ( ( resolve , _reject ) => {
226227 // Look for 7-Zip installed on system
228+ const _7zBinaries = [
229+ "7zzs" ,
230+ "7zz" ,
231+ "7z.exe"
232+ ] ;
233+
227234 const _7zBinaryLocations = [
228- "7z" ,
229- "7z.exe" ,
230235 "C:\\Program Files\\7-Zip\\7z.exe" ,
231236 "C:\\Program Files (x86)\\7-Zip\\7z.exe"
232237 ] ;
233- const decompressStream = Seven . extractFull ( filePath , modDirStagingPath , {
234- // Fall back to bundled 7-Zip binary if not found on system
238+
239+ let _7zBinaryPath = _7zBinaryLocations . find ( _7zPath => fs . existsSync ( _7zPath ) ) ;
240+
241+ if ( ! _7zBinaryPath ) {
242+ _7zBinaryPath = _7zBinaries . reduce ( ( _7zBinaryPath , _7zBinaryPathGuess ) => {
243+ try {
244+ _7zBinaryPath = which . sync ( _7zBinaryPathGuess ) ;
245+ } catch ( _err ) { }
246+
247+ return _7zBinaryPath ;
248+ } , _7zBinaryPath ) ;
249+ }
250+
251+ if ( ! _7zBinaryPath ) {
252+ // Fall back to bundled 7-Zip binary if it's not found on system
235253 // TODO - Warn user about opening RARs if 7-Zip not installed on machine
236- $bin : _7zBinaryLocations . find ( _7zPath => fs . existsSync ( _7zPath ) ) ?? sevenBin . path7za
237- } ) ;
254+ _7zBinaryPath = sevenBin . path7za ;
255+ }
256+
257+ const decompressStream = Seven . extractFull ( filePath , modDirStagingPath , { $bin : _7zBinaryPath } ) ;
238258
239259 decompressStream . on ( "data" , ( { file } ) => {
240260 modFilePaths . push ( file ) ;
0 commit comments