Skip to content

Commit 69ebb2d

Browse files
committed
Improve linux game detection
OpenAsar#92
1 parent 7d02b8b commit 69ebb2d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/process/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ export default class ProcessServer {
6060
}
6161
});
6262

63-
for (const [pid, path, args] of processesToScan) {
63+
for (const [pid, path, args, _cwdPath = ''] of processesToScan) {
6464
const possiblePaths = this._generatePossiblePaths(path);
6565

6666
for (const { e, i, n } of DetectableDB) {
67-
if (this._matchExecutable(e, possiblePaths, args)) {
67+
if (this._matchExecutable(e, possiblePaths, args, _cwdPath)) {
6868
this._handleDetectedGame(i, n, pid, activeIds);
6969
}
7070
}
@@ -95,7 +95,7 @@ export default class ProcessServer {
9595
}
9696

9797
const toCompare = [];
98-
for (let i = 0; i < splitPath.length; i++) {
98+
for (let i = 0; i < splitPath.length || i === 1; i++) {
9999
toCompare.push(splitPath.slice(-i).join('/'));
100100
}
101101

@@ -111,10 +111,10 @@ export default class ProcessServer {
111111
return variations;
112112
}
113113

114-
_matchExecutable(executables, possiblePaths, args) {
114+
_matchExecutable(executables, possiblePaths, args, cwdPath) {
115115
if (!executables) return false;
116116
return executables.n.some(name => {
117-
const pathMatches = name[0] === '>' ? name.substring(1) === possiblePaths[0] : possiblePaths.some(path => name === path);
117+
const pathMatches = name[0] === '>' ? name.substring(1) === possiblePaths[0] : possiblePaths.some(path => name === path || `${cwdPath}/${path}`.includes(`/${name}`));
118118
const argsMatch = !executables.a || (args && args.join(" ").includes(executables.a));
119119
return pathMatches && argsMatch;
120120
});

src/process/native/linux.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readdir, readFile } from "fs/promises";
1+
import { readdir, readFile, readlink } from "fs/promises";
22

33
export const getProcesses = async () => {
44
try {
@@ -27,9 +27,14 @@ export const getProcesses = async () => {
2727
if (status.includes('State:\tT')) return null;
2828
} catch (err) {}
2929

30+
let cwdPath;
31+
try {
32+
cwdPath = await readlink(`/proc/${pid}/cwd`);
33+
} catch (err) {}
34+
3035
const parts = cmdlineContent.split('\0').filter(part => part.trim() !== '');
3136

32-
return parts.length ? [pid, parts[0], parts.slice(1)] : null;
37+
return parts.length ? [pid, parts[0], parts.slice(1), cwdPath] : null;
3338
} catch {
3439
return null;
3540
}

0 commit comments

Comments
 (0)