Update SteamVR driver installation logic to follow the steam release. Added direct Registry reading instead of using shell command.

This commit is contained in:
HannahPadd committed 2026-06-01 12:38:53 +02:00
1 parent 6b86dfca2c
commit 0fb45aebcc
9 files changed
+183 -189

No files matched your search

@@ -68,8 +68,8 @@ class RPCUpdaterHandler(var rpcHandler: RPCHandler, var api: ProtocolAPI) {
val outboundOffset = this.rpcHandler.createRPCMessage(
fbb,
RpcMessage.UpdatesResponse,
responseOffset
RpcMessage.UpdatesResponse,
responseOffset,
)
fbb.finish(outboundOffset)
@@ -12,7 +12,6 @@ class Windows {
steamVRDriver()
}
fun steamVRDriver() {
val regEdit = RegEditWindows()
val regQuery = regEdit.getKeyByPath(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 250820")
+3
View File
@@ -75,6 +75,9 @@ dependencies {
implementation("org.jetbrains.compose.components:components-animatedimage:1.10.3")
implementation("com.github.HannahPadd:manifestUtils:fc4f0fb769")
implementation("net.java.dev.jna:jna:5.14.0")
implementation("net.java.dev.jna:jna-platform:5.14.0")
implementation("com.github.ajalt.mordant:mordant:3.0.2")
implementation("com.github.ajalt.mordant:mordant-markdown:3.0.2")
@@ -25,44 +25,13 @@ class Linux(
private val path = Paths.get("").toAbsolutePath().toString()
suspend fun updateLinux(currentVersionTag: String, versionTag: String, configDir: String, vrConfig: String, serverUrl: String, serverChecksum: String, openVRDriverUrl: String) {
backupConfig(currentVersionTag, configDir, vrConfig)
restoreConfig(versionTag, configDir, vrConfig)
io.backupConfig(currentVersionTag, configDir, vrConfig)
io.restoreConfig(versionTag, configDir, vrConfig)
updateServer(serverUrl, serverChecksum)
updateLinuxSteamVRDriver(openVRDriverUrl)
}
fun backupConfig(versionTag: String, configDir: String, vrConfig: String) {
TerminalUtil.info("Backing up Config")
try {
val targetDir =
File(Paths.get(configDir, versionTag).toAbsolutePath().toString())
targetDir.mkdirs()
val config = File(vrConfig)
val destination = "$targetDir/vrconfig.yml"
config.copyTo(File(destination), true)
TerminalUtil.success("Config backed up to $destination")
} catch (e: IOException) {
state.hasError = true
state.errorText = "Error backing up config"
TerminalUtil.error("Error backing up config")
}
}
fun restoreConfig(versionTag: String, configDir: String, vrConfig: String) {
try {
val sourceDir =
File(Paths.get(configDir, versionTag).toAbsolutePath().toString())
if (!sourceDir.exists()) return
val config = File("$sourceDir/vrconfig.yml")
val destination = "$configDir/vrconfig.yml"
config.copyTo(File(destination), true)
TerminalUtil.success("Config restored up to $destination")
} catch (e: IOException) {
state.hasError = true
state.errorText = "Error restoring config"
TerminalUtil.error("Error restoring config")
}
}
suspend fun updateLinuxSteamVRDriver(openVRDriverUrl: String) {
TerminalUtil.info("Updating SteamVR Driver")
@@ -74,7 +43,10 @@ class Linux(
val steamVRPath =
"${System.getProperty("user.home")}/.steam/steam/steamapps/common/SteamVR/bin/vrpathreg.sh"
val vrPathRegContents = io.executeShellCommand(steamVRPath)
val (_, vrPathRegContents) = io.executeShellCommand(steamVRPath) ?: run {
TerminalUtil.warn("Failed to check SteamVR path configuration.")
return
}
val isDriverRegistered = vrPathRegContents.contains("slimevr")
if (isDriverRegistered) {
@@ -116,7 +88,10 @@ class Linux(
val steamVRPath =
"${System.getProperty("user.home")}/.steam/steam/steamapps/common/SteamVR/bin/vrpathreg.sh"
val vrPathRegContents = io.executeShellCommand(steamVRPath)
val (_, vrPathRegContents) = io.executeShellCommand(steamVRPath) ?: run {
state.update { statusText = "Failed to run vrpathreg script" }
return
}
val isDriverRegistered = vrPathRegContents.contains("slimevr")
if (isDriverRegistered) {
@@ -159,43 +134,10 @@ class Linux(
val command = listOf("chmod", "+x", LINUXSERVERNAME)
//TerminalUtil.info(io.executeShellCommand("chmod +x ${LINUXSERVERNAME}"))
io.unzip("slimevr-openvr-driver-x64-linux.zip")
}
// Legacy
suspend fun feeder() {
state.update {
statusText = "Downloading Feeder App"
}
//TerminalUtil.info(io.executeShellCommand("chmod +x ${LINUXSERVERNAME}"))
io.downloadFile(LINUXFEEDERURL, LINUXFEEDERNAME, "")
state.update {
statusText = "Unzipping Feeder App"
}
io.unzip(LINUXFEEDERNAME)
state.update {
statusText = "Installing Feeder App"
}
io.executeShellCommand(
"chmod",
"+x",
"$path/$LINUXFEEDERDIRECTORY/SlimeVR-Feeder-App",
)
io.executeShellCommand(
"$path/$LINUXFEEDERDIRECTORY/SlimeVR-Feeder-App",
"--install",
)
state.update {
mainProgress = 1f
statusText = "Feeder App Done"
}
}
suspend fun updateUdev() {
@@ -217,16 +159,22 @@ class Linux(
statusText = "Requesting privileges"
}
val res = io.executeShellCommand(
val (_, res) = io.executeShellCommand(
"pkexec",
"cp",
"$path/69-slimevr-devices.rules",
"/etc/udev/rules.d/69-slimevr-devices.rules",
)
) ?: run {
state.update {
statusText = "Error executing privilege command"
mainProgress = 0.66f
}
return
}
state.update {
statusText =
if (res.contains("Error")) {
if (res.contains("Error", ignoreCase = true)) {
"Error installing udev rules"
} else {
"Udev rules installed"
@@ -235,6 +183,4 @@ class Linux(
mainProgress = 0.66f
}
}
}
@@ -0,0 +1,28 @@
package dev.slimevr.updater.platform
import com.sun.jna.Memory
import com.sun.jna.platform.win32.Advapi32
import com.sun.jna.platform.win32.Advapi32Util
import com.sun.jna.platform.win32.WinNT
import com.sun.jna.platform.win32.WinReg
import com.sun.jna.ptr.IntByReference
import dev.slimevr.updater.utils.TerminalUtil
abstract class AbstractRegEdit {
abstract fun getKeyByPath(hkey: WinReg.HKEY, path: String): Map<String, String>
}
class RegEdit : AbstractRegEdit() {
override fun getKeyByPath(hkey: WinReg.HKEY, path: String): Map<String, String> {
val keysMap = mutableMapOf<String, String>()
try {
Advapi32Util.registryGetValues(hkey, path).forEach {
keysMap[it.key.replace("""_h\d+$""".toRegex(), "")] = it.value.toString()
}
} catch (e: Exception) {
TerminalUtil.error("[RegEdit] Error reading values from registry $e")
}
return keysMap
}
}
@@ -1,19 +1,17 @@
package dev.slimevr.updater.platform
import com.sun.jna.platform.win32.WinReg
import dev.slimevr.updater.utils.TerminalUtil
import dev.slimevr.updater.updater.UpdaterIO
import dev.slimevr.updater.gui.UpdaterState
import dev.slimevr.updater.gui.update
import dev.slimevr.updater.updater.Constants.Companion.WINDOWSFEEDERDIRECTORY
import dev.slimevr.updater.updater.Constants.Companion.WINDOWSFEEDERNAME
import dev.slimevr.updater.updater.Constants.Companion.WINDOWSFEEDERURL
import dev.slimevr.updater.updater.Constants.Companion.WINDOWSSERVERNAME
import dev.slimevr.updater.updater.Constants.Companion.WINDOWSSTEAMVRDRIVERDIRECTORY
import dev.slimevr.updater.updater.Constants.Companion.WINDOWSSTEAMVRDRIVERNAME
import dev.slimevr.updater.updater.Constants.Companion.WINDOWSSTEAMVRDRIVERURL
import kotlinx.io.IOException
import java.io.File
import java.nio.file.Paths
import kotlin.io.path.Path
import kotlin.io.path.exists
class Windows(
private val state: UpdaterState,
@@ -31,46 +29,13 @@ class Windows(
serverChecksum: String,
openVRDriverUrl: String
) {
backupConfig(currentVersionTag, configDir, vrConfig)
restoreConfig(versionTag, configDir, vrConfig)
io.backupConfig(currentVersionTag, configDir, vrConfig)
io.restoreConfig(versionTag, configDir, vrConfig)
updateServer(serverUrl, serverChecksum)
usbDrivers()
steamVRDriver()
}
fun backupConfig(versionTag: String, configDir: String, vrConfig: String) {
TerminalUtil.info("Backing up Config")
try {
val targetDir =
File(Paths.get(configDir, versionTag).toAbsolutePath().toString())
targetDir.mkdirs()
val config = File(vrConfig)
val destination = "$targetDir/vrconfig.yml"
config.copyTo(File(destination), true)
TerminalUtil.success("Config backed up to $destination")
} catch (e: IOException) {
state.hasError = true
state.errorText = "Error backing up config"
TerminalUtil.error("Error backing up config")
}
}
fun restoreConfig(versionTag: String, configDir: String, vrConfig: String) {
try {
val sourceDir =
File(Paths.get(configDir, versionTag).toAbsolutePath().toString())
if (!sourceDir.exists()) return
val config = File("$sourceDir/vrconfig.yml")
val destination = "$configDir/vrconfig.yml"
config.copyTo(File(destination), true)
TerminalUtil.success("Config restored up to $destination")
} catch (e: IOException) {
state.hasError = true
state.errorText = "Error restoring config"
TerminalUtil.error("Error restoring config")
}
}
suspend fun updateServer(serverUrl: String, serverChecksum: String) {
println("downloading server")
state.update {
@@ -95,8 +60,11 @@ class Windows(
fun usbDrivers() {
state.statusText = "Checking Windows USB Drivers"
val installedDriversList =
io.executeShellCommand("powershell.exe", "pnputil /enum-drivers")
val (_, installedDriversList) = io.executeShellCommand("powershell.exe", "pnputil /enum-drivers")
?: run {
state.statusText = "Failed to check USB drivers"
return
}
val ch341ser = installedDriversList.contains("ch341ser.inf")
val ch343ser = installedDriversList.contains("ch343ser.inf")
@@ -110,8 +78,11 @@ class Windows(
state.statusText = "Installing USB drivers"
val driverInstallOutput =
io.executeShellCommand("$path\\installusbdrivers.bat")
val (_, driverInstallOutput) = io.executeShellCommand("$path\\installusbdrivers.bat")
?: run {
state.statusText = "Driver install script failed to execute"
return
}
state.statusText =
if (driverInstallOutput.contains("error", ignoreCase = true)) {
@@ -123,57 +94,42 @@ class Windows(
state.mainProgress = 0.33f
}
suspend fun feeder() {
state.statusText = "Downloading Feeder App"
io.downloadFile(
WINDOWSFEEDERURL,
WINDOWSFEEDERNAME,
""
)
state.statusText = "Unzipping Feeder App"
io.unzip(
WINDOWSFEEDERNAME,
)
state.statusText = "Installing Feeder App"
io.executeShellCommand(
"${path}\\${WINDOWSFEEDERDIRECTORY}\\SlimeVR-Feeder-App.exe",
"--install",
)
state.mainProgress = 1f
state.statusText = "Feeder App Done"
}
suspend fun steamVRDriver() {
state.statusText = "Checking SteamVR"
val steamVRLocation = io.executeShellCommand(
"powershell.exe",
"-Command",
"(Get-ItemProperty 'HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 250820').InstallLocation",
).trim()
if (!steamVRLocation.contains("SteamVR")) {
state.statusText = "SteamVR not installed"
val regEdit = RegEdit()
val steamVRLocation = regEdit.getKeyByPath(
WinReg.HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 250820"
)["InstallLocation"]
if (steamVRLocation == null || !steamVRLocation.endsWith("SteamVR")) {
TerminalUtil.warn("SteamVR driver installation failed: couldn't find SteamVR")
return
}
val vrPathRegContents = io.executeShellCommand(
"${steamVRLocation}\\bin\\win64\\vrpathreg.exe",
if (Path(steamVRLocation, "drivers", "slimevr").exists()) {
TerminalUtil.warn("Skipping SteamVR driver installation: driver is in SteamVR drivers folder")
TerminalUtil.warn("If you would like the SteamVR driver to automatically update, please uninstall the other version of SlimeVR")
return
}
val pathRegPath = "$steamVRLocation\\bin\\win64\\vrpathreg.exe"
val (findExitCode, _) = io.executeShellCommand(
pathRegPath,
"finddriver",
"slimevr",
)
"slimevr"
) ?: run {
TerminalUtil.warn("SteamVR driver installation failed: couldn't run vrpathreg finddriver")
return
}
val isDriverRegistered =
vrPathRegContents.contains(WINDOWSSTEAMVRDRIVERDIRECTORY)
if (isDriverRegistered) {
state.statusText = "SteamVR driver already registered"
if (!io.shouldInstallDriver(findExitCode)) {
TerminalUtil.info(
"Skipping SteamVR driver installation: ${
io.getDriverInstallSkipReason(
findExitCode
)
}"
)
return
}
@@ -193,13 +149,23 @@ class Windows(
state.statusText = "Registering SteamVR Driver"
io.executeShellCommand(
"${steamVRLocation}\\bin\\win64\\vrpathreg.exe",
val (addExitCode, _) = io.executeShellCommand(
pathRegPath,
"adddriver",
"$path\\$WINDOWSSTEAMVRDRIVERDIRECTORY\\slimevr",
)
"$path\\$WINDOWSSTEAMVRDRIVERDIRECTORY"
) ?: run {
TerminalUtil.warn("SteamVR driver installation failed: couldn't run vrpathreg adddriver")
return
}
if (addExitCode != 0) {
TerminalUtil.warn("SteamVR driver installation failed: vrpathreg exited with code $addExitCode")
return
}
state.mainProgress = 0.66f
state.statusText = "SteamVR Driver done"
TerminalUtil.info("SteamVR driver successfully installed")
}
}
@@ -0,0 +1,4 @@
package dev.slimevr.updater.updater
class Integrity {
}
@@ -26,6 +26,7 @@ import kotlinx.io.IOException
import kotlinx.serialization.json.Json
import java.io.File
import java.io.FileOutputStream
import java.nio.file.Paths
import java.security.MessageDigest
import java.util.concurrent.atomic.AtomicInteger
import java.util.zip.ZipEntry
@@ -37,36 +38,82 @@ class UpdaterIO(
) {
private val client = HttpClient(CIO)
fun executeShellCommand(vararg command: String): String = try {
fun executeShellCommand(vararg command: String): Pair<Int, String>? = try {
val process = ProcessBuilder(*command)
.redirectErrorStream(true)
.start()
process.inputStream.bufferedReader().readText().also {
process.waitFor()
}
process.waitFor()
Pair(process.exitValue(), process.inputStream.bufferedReader().readText())
} catch (e: IOException) {
state.hasError = true
"Error executing shell command: ${e.message}"
TerminalUtil.warn("Error executing shell command $e")
null
}
fun shouldInstallDriver(exitCode: Int): Boolean = exitCode == 1
fun getDriverInstallSkipReason(exitCode: Int): String = when (exitCode) {
0 -> "driver already installed"
2 -> "driver installed more than once"
-1 -> "SteamVR is misconfigured"
else -> "unknown reason ($exitCode)"
}
fun backupConfig(versionTag: String, configDir: String, vrConfig: String) {
TerminalUtil.info("Backing up Config")
try {
val targetDir =
File(Paths.get(configDir, versionTag).toAbsolutePath().toString())
targetDir.mkdirs()
val config = File(vrConfig)
val destination = "$targetDir/vrconfig.yml"
config.copyTo(File(destination), true)
TerminalUtil.success("Config backed up to $destination")
} catch (e: IOException) {
state.hasError = true
state.errorText = "Error backing up config"
TerminalUtil.error("Error backing up config")
}
}
fun restoreConfig(versionTag: String, configDir: String, vrConfig: String) {
try {
val sourceDir =
File(Paths.get(configDir, versionTag).toAbsolutePath().toString())
if (!sourceDir.exists()) return
val config = File("$sourceDir/vrconfig.yml")
val destination = "$configDir/vrconfig.yml"
config.copyTo(File(destination), true)
TerminalUtil.success("Config restored up to $destination")
} catch (e: IOException) {
state.hasError = true
state.errorText = "Error restoring config"
TerminalUtil.error("Error restoring config")
}
}
suspend fun getReleaseFromApi(): List<Release> {
val client = HttpClient(CIO) {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
try {
val client = HttpClient(CIO) {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
TerminalUtil.info(CDN_RELEASES)
val releases: List<Release> = client.get(CDN_RELEASES).body()
return releases
} catch (e: IOException) {
state.hasError = true
TerminalUtil.error("Error retrieving releases")
return emptyList()
}
TerminalUtil.info(CDN_RELEASES)
val releases: List<Release> = client.get(CDN_RELEASES).body()
return releases
}
suspend fun downloadFile(fileUrl: String, fileName: String, checksum: String) {
state.subProgress = 0f
val targetFile = File(fileName)
@@ -156,7 +203,7 @@ class UpdaterIO(
}
}
private suspend fun unzipWorker(zipFile: ZipFile, zipEntry: ZipEntry, destDir: String) {
private fun unzipWorker(zipFile: ZipFile, zipEntry: ZipEntry, destDir: String) {
val destFolder = File(destDir)
val targetFile = File(destFolder, zipEntry.name)
@@ -227,6 +274,7 @@ class UpdaterIO(
return matches
}
fun restartApplication() {
try {
val javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"