Skip to content

Commit 33766af

Browse files
committed
- Added workaround for issue where 7zip-bin doesn't work in linux.
- App now more intelligently looks for 7zip binary on system path for all platforms.
1 parent 0b87764 commit 33766af

8 files changed

Lines changed: 98 additions & 16 deletions

File tree

angular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,8 @@
106106
}
107107
}
108108
}
109+
},
110+
"cli": {
111+
"analytics": false
109112
}
110113
}

package-lock.json

Lines changed: 31 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "Mychal Thompson <mychal.r.thompson@gmail.com>",
44
"repository": "https://github.com/lVlyke/starfield-mod-loader",
55
"license": "GPL-3.0",
6-
"version": "0.3.1",
6+
"version": "0.3.2",
77
"main": "electron.js",
88
"scripts": {
99
"app:build-dist": "npm run build:release && npm run package",
@@ -48,6 +48,7 @@
4848
"recursive-readdir": "^2.2.3",
4949
"rxjs": "~7.8.0",
5050
"tslib": "^2.3.0",
51+
"which": "^4.0.0",
5152
"zone.js": "~0.13.0"
5253
},
5354
"devDependencies": {

scripts/build.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ const { execSync } = require("child_process");
33

44
const RELEASE_MODE = process.argv.includes("--release");
55

6+
execSync(
7+
"node ./scripts/fix-7zip-bin-permissions.js",
8+
{ stdio: "inherit" }
9+
);
10+
611
execSync(
712
`npx ng build ${RELEASE_MODE ? "--configuration production" : ""}`,
813
{ stdio: "inherit" }

scripts/copy-electron-deps.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//@ts-check
22
const fs = require("fs-extra");
33
const path = require("path");
4+
const { execSync } = require("child_process");
45

56
const BUILD_DIR = "./dist";
67

@@ -26,9 +27,16 @@ const DEPENDENCIES = [
2627
"minimatch",
2728
"brace-expansion",
2829
"balanced-match",
29-
"concat-map"
30+
"concat-map",
31+
"which",
32+
"isexe"
3033
];
3134

35+
execSync(
36+
"node ./scripts/fix-7zip-bin-permissions.js",
37+
{ stdio: "inherit" }
38+
);
39+
3240
fs.mkdirSync(BUILD_DIR, { recursive: true })
3341

3442
DEPENDENCIES.forEach((dep) => {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @ts-check
2+
const { execSync } = require("child_process");
3+
const sevenBin = require("7zip-bin");
4+
5+
// Workaround for 7zip-bin issue: https://github.com/develar/7zip-bin/issues/19
6+
// TODO - Remove when this issue is fixed
7+
if (process.platform !== "win32") {
8+
execSync(
9+
`chmod +x ${sevenBin.path7za}`,
10+
{ stdio: "inherit" }
11+
);
12+
13+
execSync(
14+
`chmod +x ${sevenBin.path7x}`,
15+
{ stdio: "inherit" }
16+
);
17+
}

scripts/serve.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const spawn = require("child_process").spawn;
66
const BUILD_DIR = "./dist";
77
const RELEASE_MODE = process.argv.includes("--release");
88

9+
execSync(
10+
"node ./scripts/fix-7zip-bin-permissions.js",
11+
{ stdio: "inherit" }
12+
);
13+
914
const buildTask = spawn("npx", [
1015
"ng",
1116
"build",

src/electron.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const fsPromises = require("fs").promises;
1111
const _ = require("lodash");
1212
const Seven = require("node-7z");
1313
const 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+
1617
const 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

Comments
 (0)