Skip to content

Commit beca4f9

Browse files
authored
Merge pull request #3 from LunyaaDev/fix/linux-custom-install-location
Fix/linux custom install location
2 parents 05a333f + d54ee60 commit beca4f9

File tree

6 files changed

+99
-19
lines changed

6 files changed

+99
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"dependencies": {
3434
"tail": "^2.2.6",
35+
"vdf-parser": "^1.2.1",
3536
"vrchat-location-parser": "^0.2.0"
3637
}
3738
}

pnpm-lock.yaml

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

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ export class VrchatLogWatcher extends EventEmitter {
8181

8282
constructor() {
8383
super()
84-
this.vrchatLogDir = getVrchatLogDir()
84+
85+
const logdir = getVrchatLogDir()
86+
// throw error when log dir is missing
87+
if (!logdir) {
88+
throw Error('VRChat log dir missing')
89+
}
90+
this.vrchatLogDir = logdir
8591
// start logging on init
8692
this.currentLogFile = getLatestLogfile(this.vrchatLogDir)
8793
this.watchFile()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface SteamLibraryFolders {
2+
libraryfolders: { [key: string]: LibraryFolder }
3+
}
4+
5+
export interface LibraryFolder {
6+
path: string
7+
label: string
8+
contentid: number
9+
totalsize: number
10+
update_clean_bytes_tally: number
11+
time_last_update_verified: number
12+
apps: { [key: string]: number }
13+
}

src/utils/getVrchatLogDir.ts

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,75 @@
11
import * as path from 'path'
22
import * as os from 'os'
3+
import * as VDF from 'vdf-parser'
4+
import * as fs from 'fs'
5+
import { SteamLibraryFolders } from '../interfaces/SteamLibraryFolders'
6+
7+
// https://steamdb.info/app/438100
8+
const VRCHAT_APP_ID = '438100'
9+
10+
const returnPathIfExists = (path2Check: string) =>
11+
fs.existsSync(path2Check) ? path2Check : null
312

413
export const getVrchatLogDir = () => {
514
// windows
6-
if (process.platform == 'win32')
7-
return path.join(os.homedir(), 'Appdata', 'LocalLow', 'VRChat', 'VRChat')
8-
return path.join(
9-
os.homedir(),
10-
'.steam',
11-
'steam',
12-
'steamapps',
13-
'compatdata',
14-
'438100',
15-
'pfx',
16-
'drive_c',
17-
'users',
18-
'steamuser',
19-
'AppData',
20-
'LocalLow',
21-
'VRChat',
22-
'VRChat',
23-
)
15+
if (process.platform == 'win32') {
16+
return returnPathIfExists(
17+
path.join(os.homedir(), 'Appdata', 'LocalLow', 'VRChat', 'VRChat'),
18+
)
19+
}
20+
21+
// linux
22+
if (process.platform == 'linux') {
23+
// path of libraryfolders.vdf
24+
const libraryFoldersPath = path.join(
25+
os.homedir(),
26+
'.steam',
27+
'steam',
28+
'steamapps',
29+
'libraryfolders.vdf',
30+
)
31+
32+
// return if file is non existant
33+
if (!fs.existsSync(libraryFoldersPath)) {
34+
return null
35+
}
36+
37+
// read and parse file
38+
const libraryFoldersText = fs.readFileSync(libraryFoldersPath).toString()
39+
const libraryFoldersConfig =
40+
VDF.parse<SteamLibraryFolders>(libraryFoldersText)
41+
42+
console.log(libraryFoldersConfig.libraryfolders)
43+
44+
// find library with vrchat
45+
const library = Object.values(libraryFoldersConfig.libraryfolders).findLast(
46+
(library) =>
47+
// returns app id or undefined
48+
Object.keys(library.apps).findLast((appId) => appId == VRCHAT_APP_ID),
49+
)
50+
51+
// check if library with VRChat is existent
52+
if (!library?.path) {
53+
return null
54+
}
55+
56+
return returnPathIfExists(
57+
path.join(
58+
library.path,
59+
'steamapps',
60+
'compatdata',
61+
'438100',
62+
'pfx',
63+
'drive_c',
64+
'users',
65+
'steamuser',
66+
'AppData',
67+
'LocalLow',
68+
'VRChat',
69+
'VRChat',
70+
),
71+
)
72+
}
73+
74+
return null
2475
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"declaration": true,
66
"module": "nodenext",
77
"moduleResolution": "nodenext",
8+
"types": ["node"],
89
"target": "ESNext",
910
"strict": true
1011
},

0 commit comments

Comments
 (0)