mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-28 21:06:31 -08:00
2 files changed
+92
-16
No files matched your search
@@ -0,0 +1,81 @@
|
||||
package dev.slimevr.desktop.linux
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.BufferedReader
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileReader
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.exists
|
||||
|
||||
internal val STEAM_PATH = System.getenv("HOME")?.let { home ->
|
||||
listOf(
|
||||
Path(home, ".steam", "root"),
|
||||
Path(home, ".steam", "debian-installation"),
|
||||
Path(home, ".var", "app", "com.valvesoftware.Steam", "data", "Steam"),
|
||||
).firstOrNull { it.exists() }
|
||||
}
|
||||
internal val VDF_KEY_VALUES_PATTERN = Regex(""""(\w+)"[ \t]*(?:"(.+)")?""")
|
||||
|
||||
suspend fun findAppLibraryLocation(appId: Int): Path = withContext(Dispatchers.IO) {
|
||||
if (STEAM_PATH == null) throw FileNotFoundException("Unable to find Steam")
|
||||
val libraryFoldersPath = STEAM_PATH.resolve("config/libraryfolders.vdf")
|
||||
if (!libraryFoldersPath.exists()) throw FileNotFoundException("Steam libraryfolders.vdf does not exist")
|
||||
|
||||
BufferedReader(FileReader(STEAM_PATH.resolve("config/libraryfolders.vdf").toFile())).use { reader ->
|
||||
var depth = 0
|
||||
var currentLibraryPath: Path? = null
|
||||
|
||||
while (reader.ready()) {
|
||||
val line = reader.readLine().trim()
|
||||
if (line == "{") {
|
||||
depth += 1
|
||||
continue
|
||||
}
|
||||
if (line == "}") {
|
||||
depth -= 1
|
||||
continue
|
||||
}
|
||||
|
||||
VDF_KEY_VALUES_PATTERN.matchEntire(line)?.let {
|
||||
val key = it.groupValues[1]
|
||||
val value = it.groupValues[2]
|
||||
|
||||
when (depth) {
|
||||
0 -> {
|
||||
require(key == "libraryfolders") { "root key must be libraryfolders" }
|
||||
}
|
||||
|
||||
1 -> {
|
||||
// start of a library node
|
||||
}
|
||||
|
||||
2 -> {
|
||||
// in a library node
|
||||
if (key == "path") {
|
||||
currentLibraryPath = Path(value)
|
||||
} else if (key == "apps") {
|
||||
// start of apps node
|
||||
require(currentLibraryPath != null) { "path must come before apps in node" }
|
||||
}
|
||||
}
|
||||
|
||||
3 -> {
|
||||
// in apps node
|
||||
val curAppId = try {
|
||||
key.toInt()
|
||||
} catch (_: NumberFormatException) {
|
||||
null
|
||||
}
|
||||
if (curAppId != null && curAppId == appId) {
|
||||
check(currentLibraryPath != null) { "path must come before apps in node" }
|
||||
return@withContext currentLibraryPath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw RuntimeException("Couldn't find library folder for appid $appId")
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.slimevr.desktop.vrchat
|
||||
|
||||
import dev.slimevr.AppLogger
|
||||
import dev.slimevr.desktop.linux.findAppLibraryLocation
|
||||
import kotlinx.coroutines.CancellationException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -13,8 +14,7 @@ import java.io.FileReader
|
||||
import java.io.InvalidObjectException
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.exists
|
||||
import java.nio.file.Path
|
||||
|
||||
private const val USER_REG_SUBPATH = "steamapps/compatdata/438100/pfx/user.reg"
|
||||
private val KEY_VALUE_PATTERN = Regex(""""(.+)"=(.+)""")
|
||||
@@ -22,22 +22,15 @@ private val HEX_FORMAT = HexFormat {
|
||||
upperCase = false
|
||||
bytes.byteSeparator = ","
|
||||
}
|
||||
private const val VRCHAT_APPID = 438100
|
||||
|
||||
internal val linuxUserRegPath = System.getenv("HOME")?.let { home ->
|
||||
listOf(
|
||||
Path(home, ".steam", "root", USER_REG_SUBPATH),
|
||||
Path(home, ".steam", "debian-installation", USER_REG_SUBPATH),
|
||||
Path(home, ".var", "app", "com.valvesoftware.Steam", "data", "Steam", USER_REG_SUBPATH),
|
||||
).firstOrNull { it.exists() }
|
||||
}
|
||||
|
||||
internal suspend fun linuxGetVRChatKeys(path: String, registry: MutableMap<String, String>): Map<String, String> {
|
||||
internal suspend fun linuxGetVRChatKeys(regPath: Path, keyPath: String, registry: MutableMap<String, String>): Map<String, String> {
|
||||
val keysMap = mutableMapOf<String, String>()
|
||||
registry.clear()
|
||||
try {
|
||||
withContext(Dispatchers.IO) {
|
||||
BufferedReader(FileReader(linuxUserRegPath?.toFile() ?: return@withContext)).use { reader ->
|
||||
val actualPath = "[${path.replace("\\", """\\""")}]"
|
||||
BufferedReader(FileReader(regPath.toFile() ?: return@withContext)).use { reader ->
|
||||
val actualPath = "[${keyPath.replace("\\", """\\""")}]"
|
||||
while (reader.ready()) {
|
||||
val line = reader.readLine()
|
||||
if (!line.startsWith(actualPath)) continue
|
||||
@@ -86,15 +79,17 @@ internal suspend fun linuxGetDwordValue(registry: Map<String, String>, key: Stri
|
||||
}
|
||||
|
||||
internal fun linuxVRCConfigFlow(): Flow<solarxr_protocol.rpc.VRCConfigValues?> = flow {
|
||||
val regPath = linuxUserRegPath ?: run {
|
||||
AppLogger.vrc.info("[VRChatRegEdit] Couldn't find any VRChat registry file")
|
||||
val regPath = try {
|
||||
findAppLibraryLocation(VRCHAT_APPID).resolve(USER_REG_SUBPATH)
|
||||
} catch (e: Exception) {
|
||||
AppLogger.vrc.warn(e, "[VRChatRegEdit] Couldn't find any VRChat registry file")
|
||||
return@flow
|
||||
}
|
||||
AppLogger.vrc.info("[VRChatRegEdit] Using VRChat registry file: $regPath")
|
||||
|
||||
val registry = mutableMapOf<String, String>()
|
||||
while (true) {
|
||||
val keys = linuxGetVRChatKeys(VRC_REG_PATH, registry)
|
||||
val keys = linuxGetVRChatKeys(regPath, VRC_REG_PATH, registry)
|
||||
if (keys.isEmpty()) {
|
||||
emit(null)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user