Skip to content

Commit 2a1f664

Browse files
committed
added wine support
1 parent 2d6850c commit 2a1f664

4 files changed

Lines changed: 70 additions & 19 deletions

File tree

formats/wii/dol.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = async ({ format, game, gameId, region, version, inputFile, isFr
7575
process.exit(1);
7676
};
7777

78-
console.debug("Following strings will be replaced:", STRINGS_USED);
78+
logger.debug("Following strings will be replaced: " + JSON.stringify(STRINGS_USED));
7979

8080
if (game.isLyN) {
8181
logger.info("Detected a LyN game, patching NAS and Shop only...");

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ if (!existsSync(appDataPath)) {
3030

3131
// Call CLI
3232
const cliArgs = await cli();
33-
console.debug(cliArgs)
33+
logger.debug(cliArgs);
3434

3535
const platform = cliArgs.platform;
3636
const game = cliArgs.selectedGame;
@@ -47,8 +47,6 @@ if (!existsSync(appDataPath)) {
4747
global.isDebug = debug || false;
4848
global.logLevel = global.isDebug ? "debug" : "info";
4949

50-
console.log("jfsmdf", inputPath)
51-
5250
if (!existsSync(inputPath) || !statSync(inputPath).isFile()) {
5351
logger.error(`Provided path does not exist or it's not a file, please provide an ISO, WBFS, DOL or BIN file.`);
5452
process.exit(1);

lib/child-process.js

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,93 @@ const fse = require('fs-extra');
33
const path = require("path");
44
const utils = require('util');
55
const os = require("node:os");
6-
76
const child_exec = utils.promisify(require('child_process').exec);
87
const chmod = utils.promisify(fs.chmod);
98

109
class ChildProcess {
1110
constructor() {};
1211

12+
async findWine() {
13+
const possiblePaths = [
14+
'wine64',
15+
'wine',
16+
'/usr/local/bin/wine64',
17+
'/usr/local/bin/wine',
18+
'/opt/homebrew/bin/wine64',
19+
'/opt/homebrew/bin/wine',
20+
'/usr/bin/wine64',
21+
'/usr/bin/wine'
22+
];
23+
24+
for (const winePath of possiblePaths) {
25+
try {
26+
await child_exec(`which ${winePath}`);
27+
return winePath;
28+
} catch (error) {
29+
// Continue to next path
30+
}
31+
}
32+
33+
// Try using 'which' command as fallback
34+
try {
35+
const { stdout } = await child_exec('which wine64 || which wine');
36+
return stdout.trim();
37+
} catch (error) {
38+
return null;
39+
}
40+
}
41+
1342
async exec(execPath, command) {
1443
let execName = path.basename(execPath);
1544
let execFolder = path.dirname(execPath);
45+
const isMac = process.platform === 'darwin';
46+
const isWindows = process.platform === 'win32';
47+
let wineCommand = '';
48+
49+
// Check if we need Wine (macOS running .exe files)
50+
if (isMac && (execName.endsWith('.exe') || execName.endsWith('.EXE'))) {
51+
logger.warn('You are on macOS - Wine will be used to run Windows executables!');
52+
53+
const winePath = await this.findWine();
54+
if (!winePath) {
55+
throw new Error('Wine is not installed. Please install Wine to run Windows executables on macOS.\nInstall via Homebrew: brew install --cask wine-stable');
56+
}
57+
58+
logger.debug(`Found Wine at: ${winePath}`);
59+
wineCommand = `${winePath} `;
60+
}
1661

17-
// avoid the workaround if the parent process in not pkg-ed version.
62+
// avoid the workaround if the parent process is not pkg-ed version.
1863
if (process.pkg) {
1964
// creating a temporary folder for our executable file
2065
const tmp = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
21-
2266
const tmpFolder = path.join(tmp, path.relative(global.root, execFolder));
2367
const tmpExecPath = path.join(tmpFolder, execName);
24-
2568
logger.debug(`exec path copying... tmp folder: ${tmpFolder}`);
26-
2769
fse.copySync(execFolder, tmpFolder, { force: true, recursive: true });
28-
2970
execPath = tmpExecPath;
3071
execFolder = tmpFolder;
31-
32-
await chmod(tmpExecPath, 0o765); // grant permission just in case
33-
};
72+
73+
if (!isWindows) {
74+
await chmod(tmpExecPath, 0o765); // grant permission just in case
75+
}
76+
}
3477

3578
// using {detached: true}, execute the command independently of its parent process
3679
// to avoid the main parent process' failing if the child process failed as well.
80+
const fullCommand = `${wineCommand}${execPath} ${command}`;
81+
3782
return {
3883
isPkg: process.pkg,
3984
execPath,
4085
execFolder,
4186
execName,
42-
exec: await child_exec(`${execPath} ${command}`)
87+
isMac,
88+
isWindows,
89+
usingWine: !!wineCommand,
90+
exec: await child_exec(fullCommand)
4391
};
44-
};
45-
46-
};
92+
}
93+
}
4794

4895
module.exports = new ChildProcess();

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@
2525
"node": "^17 || ^16 || ^14 || ^12 || ^22"
2626
},
2727
"pkg": {
28+
"compress": "Brotli",
2829
"targets": [
29-
"node16-win-x64"
30+
"node16-win-x64",
31+
"node16-macos-x64",
32+
"node16-macos-arm64",
33+
"node16-linux-x64",
34+
"node16-linux-arm64"
3035
],
3136
"outputPath": "dist",
3237
"assets": [
33-
"./bin/wit/**"
38+
"./bin/wit/**",
39+
"./bin/self-resigner/**"
3440
]
3541
}
3642
}

0 commit comments

Comments
 (0)