@@ -11,6 +11,9 @@ const DetectableDB = JSON.parse(fs.readFileSync(join(__dirname, 'detectable.json
1111import * as Natives from './native/index.js' ;
1212const Native = Natives [ process . platform ] ;
1313
14+ function basename ( str ) {
15+ return str . substr ( str . lastIndexOf ( '/' ) + 1 ) ;
16+ }
1417
1518const timestamps = { } , names = { } , pids = { } ;
1619export default class ProcessServer {
@@ -34,11 +37,12 @@ export default class ProcessServer {
3437
3538 // log(`got processed in ${(performance.now() - startTime).toFixed(2)}ms`);
3639
37- for ( const [ pid , _path , args ] of processes ) {
40+ for ( const [ pid , _path , args , _cwdPath = '' ] of processes ) {
3841 const path = _path . toLowerCase ( ) . replaceAll ( '\\' , '/' ) ;
42+ const cwdPath = _cwdPath . toLowerCase ( ) . replaceAll ( '\\' , '/' ) ;
3943 const toCompare = [ ] ;
4044 const splitPath = path . split ( '/' ) ;
41- for ( let i = 1 ; i < splitPath . length ; i ++ ) {
45+ for ( let i = 1 ; i < splitPath . length || i == 1 ; i ++ ) {
4246 toCompare . push ( splitPath . slice ( - i ) . join ( '/' ) ) ;
4347 }
4448
@@ -47,12 +51,27 @@ export default class ProcessServer {
4751 toCompare . push ( p . replace ( '.x64' , '' ) ) ;
4852 toCompare . push ( p . replace ( 'x64' , '' ) ) ;
4953 toCompare . push ( p . replace ( '_64' , '' ) ) ;
54+ toCompare . push ( p . replace ( '.exe' , '' ) ) ;
5055 }
5156
5257 for ( const { executables, id, name } of DetectableDB ) {
5358 if ( executables ?. some ( x => {
5459 if ( x . is_launcher ) return false ;
55- if ( x . name [ 0 ] === '>' ? x . name . substring ( 1 ) !== toCompare [ 0 ] : ! toCompare . some ( y => x . name === y ) ) return false ;
60+ // I can't figure how to not make 'sbin/init' NOT match 'Divinity Original Sin' with a substring match, so this ugly hack have to do for now
61+ for ( const comp of toCompare ) {
62+ const asdf = comp . includes ( '.exe' )
63+ if ( asdf ) {
64+ // TODO: Do the reverse; check if x.name contains game/ or /games and THEN check against game/comp and games/comp
65+ const alternative1 = 'game/' + comp
66+ const alternative2 = 'games/' + comp
67+ const ghjk = x . name . includes ( alternative1 )
68+ const zxc = x . name . includes ( alternative2 )
69+ if ( ghjk || zxc ) {
70+ return true
71+ }
72+ }
73+ }
74+ if ( x . name [ 0 ] === '>' ? x . name . substring ( 1 ) !== toCompare [ 0 ] : ! toCompare . some ( y => x . name === y || `${ cwdPath } /${ y } ` . includes ( `/${ x . name } ` ) ) ) return false ;
5675 if ( args && x . arguments ) return args . join ( " " ) . indexOf ( x . arguments ) > - 1 ;
5776 return true ;
5877 } ) ) {
0 commit comments