Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"dependencies": {
"tail": "^2.2.6",
"vdf-parser": "^1.2.1",
"vrchat-location-parser": "^0.2.0"
}
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ export class VrchatLogWatcher extends EventEmitter {

constructor() {
super()
this.vrchatLogDir = getVrchatLogDir()

const logdir = getVrchatLogDir()
// throw error when log dir is missing
if (!logdir) {
throw Error('VRChat log dir missing')
}
this.vrchatLogDir = logdir
// start logging on init
this.currentLogFile = getLatestLogfile(this.vrchatLogDir)
this.watchFile()
Expand Down
13 changes: 13 additions & 0 deletions src/interfaces/SteamLibraryFolders.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface SteamLibraryFolders {
libraryfolders: { [key: string]: LibraryFolder }
}

export interface LibraryFolder {
path: string
label: string
contentid: number
totalsize: number
update_clean_bytes_tally: number
time_last_update_verified: number
apps: { [key: string]: number }
}
87 changes: 69 additions & 18 deletions src/utils/getVrchatLogDir.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,75 @@
import * as path from 'path'
import * as os from 'os'
import * as VDF from 'vdf-parser'
import * as fs from 'fs'
import { SteamLibraryFolders } from '../interfaces/SteamLibraryFolders'

// https://steamdb.info/app/438100
const VRCHAT_APP_ID = '438100'

const returnPathIfExists = (path2Check: string) =>
fs.existsSync(path2Check) ? path2Check : null

export const getVrchatLogDir = () => {
// windows
if (process.platform == 'win32')
return path.join(os.homedir(), 'Appdata', 'LocalLow', 'VRChat', 'VRChat')
return path.join(
os.homedir(),
'.steam',
'steam',
'steamapps',
'compatdata',
'438100',
'pfx',
'drive_c',
'users',
'steamuser',
'AppData',
'LocalLow',
'VRChat',
'VRChat',
)
if (process.platform == 'win32') {
return returnPathIfExists(
path.join(os.homedir(), 'Appdata', 'LocalLow', 'VRChat', 'VRChat'),
)
}

// linux
if (process.platform == 'linux') {
// path of libraryfolders.vdf
const libraryFoldersPath = path.join(
os.homedir(),
'.steam',
'steam',
'steamapps',
'libraryfolders.vdf',
)

// return if file is non existant
if (!fs.existsSync(libraryFoldersPath)) {
return null
}

// read and parse file
const libraryFoldersText = fs.readFileSync(libraryFoldersPath).toString()
const libraryFoldersConfig =
VDF.parse<SteamLibraryFolders>(libraryFoldersText)

console.log(libraryFoldersConfig.libraryfolders)

// find library with vrchat
const library = Object.values(libraryFoldersConfig.libraryfolders).findLast(
(library) =>
// returns app id or undefined
Object.keys(library.apps).findLast((appId) => appId == VRCHAT_APP_ID),
)

// check if library with VRChat is existent
if (!library?.path) {
return null
}

return returnPathIfExists(
path.join(
library.path,
'steamapps',
'compatdata',
'438100',
'pfx',
'drive_c',
'users',
'steamuser',
'AppData',
'LocalLow',
'VRChat',
'VRChat',
),
)
}

return null
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"declaration": true,
"module": "nodenext",
"moduleResolution": "nodenext",
"types": ["node"],
"target": "ESNext",
"strict": true
},
Expand Down