Sapphire committed 2026-06-19 03:54:43 -05:00
1 parent d7bdeaa48a
commit dd198d2205
4 files changed
+76 -30

No files matched your search

@@ -61,7 +61,7 @@ fun main(args: Array<String>) = runBlocking<Unit> {
} else {
arrayOf("udevadm", "cat")
}
featureFlags.udevRulesInstalled = executeShellCommand(*command)?.contains("slime")
featureFlags.udevRulesInstalled = executeShellCommand(*command)?.second?.contains("slime")
}
val configFolder = resolveConfigDirectory() ?: error("Unable to resolve config folder")
@@ -16,16 +16,34 @@ suspend fun runInstaller() {
}
}
suspend fun executeShellCommand(vararg command: String): String? = try {
val process = withContext(Dispatchers.IO) {
ProcessBuilder(*command)
suspend fun executeShellCommand(vararg command: String): Pair<Int, String>? = try {
withContext(Dispatchers.IO) {
val process = ProcessBuilder(*command)
.redirectErrorStream(true)
.start()
}
process.inputStream.bufferedReader().readText().also {
val output = process.inputStream.bufferedReader().readText()
process.waitFor()
Pair(process.exitValue(), output)
}
} catch (e: IOException) {
AppLogger.install.warn("Error executing shell command: ${e.message}")
null
}
// vrpathreg returns 1 if the driver is not present
fun shouldInstallDriver(exitCode: Int): Boolean = exitCode == 1
// get a descriptive reason why we're skipping driver installation
// Exit codes from vrpathreg output:
// 0 : Success
// 1 : ( finddriver only ) Driver not present
// 2 : ( finddriver only ) Error, driver installed more than once
// -1 : Configuration or permission problem
// -2 : Argument problem
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)"
}
@@ -2,7 +2,9 @@ package dev.slimevr.desktop.install
import dev.slimevr.AppLogger
import dev.slimevr.FeatureFlags
import dev.slimevr.desktop.linux.findAppLibraryLocation
private const val STEAMVR_APPID = 250820
private const val LINUX_STEAM_DRIVER_DIRECTORY = "slimevr-openvr-driver-x64-linux"
suspend fun installLinux() {
@@ -10,21 +12,32 @@ suspend fun installLinux() {
}
private suspend fun installLinuxSteamVRDriver() {
val path = System.getProperty("user.dir")
val vrPathReg = "${System.getProperty("user.home")}/.steam/steam/steamapps/common/SteamVR/bin/vrpathreg.sh"
val existing = executeShellCommand(vrPathReg)
if (existing == null) {
AppLogger.install.warn("SteamVR driver installation failed")
val workingDir = System.getProperty("user.dir")
val steamVRLocation = try {
findAppLibraryLocation(STEAMVR_APPID).resolve("steamapps/common/SteamVR")
} catch (e: Exception) {
AppLogger.install.warn(e, "SteamVR driver installation failed (couldn't find SteamVR install location)")
return
}
if (existing.contains("slimevr")) {
AppLogger.install.info("SteamVR driver is already installed")
val pathRegPath = steamVRLocation.resolve("bin/vrpathreg.sh").toString()
val (findExitCode, _) = executeShellCommand(pathRegPath, "finddriver", "slimevr") ?: run {
AppLogger.install.warn("SteamVR driver installation failed (failed to run vrpathreg finddriver)")
return
}
executeShellCommand(vrPathReg, "adddriver", "$path/$LINUX_STEAM_DRIVER_DIRECTORY")
if (executeShellCommand(vrPathReg)?.contains("slimevr") != true) {
AppLogger.install.warn("Failed to install SteamVR driver")
if (!shouldInstallDriver(findExitCode)) {
AppLogger.install.info("Skipping SteamVR driver installation (${getDriverInstallSkipReason(findExitCode)})")
return
}
val (addExitCode, _) = executeShellCommand(pathRegPath, "adddriver", "$workingDir/$LINUX_STEAM_DRIVER_DIRECTORY") ?: run {
AppLogger.install.warn("SteamVR driver installation failed (failed to run vrpathreg adddriver)")
return
}
if (addExitCode != 0) {
AppLogger.install.warn("SteamVR driver installation failed (vrpathreg adddriver exited with code $addExitCode)")
return
}
AppLogger.install.info("SteamVR driver successfully installed")
}
@@ -3,6 +3,8 @@ package dev.slimevr.desktop.install
import com.sun.jna.platform.win32.Advapi32Util
import com.sun.jna.platform.win32.WinReg
import dev.slimevr.AppLogger
import kotlin.io.path.Path
import kotlin.io.path.exists
private const val WINDOWS_STEAMVR_DRIVER_DIRECTORY = "slimevr-openvr-driver-win64"
@@ -23,27 +25,40 @@ private suspend fun getKeyByPath(hkey: WinReg.HKEY, path: String): Map<String, S
}
private suspend fun installWindowsSteamVRDriver() {
val path = System.getProperty("user.dir")
val regQuery = getKeyByPath(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 250820")
val steamVRLocation = regQuery["InstallLocation"]
if (steamVRLocation == null || !steamVRLocation.contains("SteamVR")) {
AppLogger.install.warn("Can't find SteamVR, unable to install SteamVR driver")
val workingDir = System.getProperty("user.dir")
val steamVRLocation = getKeyByPath(WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Steam App 250820")["InstallLocation"]
if (steamVRLocation == null || !steamVRLocation.endsWith("SteamVR")) {
AppLogger.install.warn("SteamVR driver installation failed (couldn't find SteamVR install location)")
return
}
val vrPathReg = "${steamVRLocation}\\bin\\win64\\vrpathreg.exe"
val existing = executeShellCommand(vrPathReg, "finddriver", "slimevr")
if (existing == null) {
AppLogger.install.warn("Error installing SteamVR driver")
run {
val standaloneDriverLocation = Path(steamVRLocation, "drivers", "slimevr")
if (standaloneDriverLocation.exists()) {
AppLogger.install.warn("Skipping SteamVR driver installation as the non-Steam installer has already placed it in the SteamVR drivers folder")
AppLogger.install.warn("If you would like the Steam version to manage the SteamVR driver (recommended), uninstall the non-Steam version of SlimeVR, or delete the '$standaloneDriverLocation' folder")
return
}
}
val pathRegPath = "$steamVRLocation\\bin\\win64\\vrpathreg.exe"
val (findExitCode, _) = executeShellCommand(pathRegPath, "finddriver", "slimevr") ?: run {
AppLogger.install.warn("SteamVR driver installation failed (failed to run vrpathreg finddriver)")
return
}
if (existing.contains("slimevr")) {
AppLogger.install.info("SteamVR driver is already installed")
if (!shouldInstallDriver(findExitCode)) {
AppLogger.install.info("Skipping SteamVR driver installation (${getDriverInstallSkipReason(findExitCode)})")
return
}
executeShellCommand(vrPathReg, "adddriver", "${path}\\${WINDOWS_STEAMVR_DRIVER_DIRECTORY}")
if (executeShellCommand(vrPathReg, "finddriver", "slimevr")?.contains("slimevr") != true) {
AppLogger.install.warn("Failed to install SlimeVR driver")
val (addExitCode, _) = executeShellCommand(pathRegPath, "adddriver", "$workingDir\\$WINDOWS_STEAMVR_DRIVER_DIRECTORY") ?: run {
AppLogger.install.warn("SteamVR driver installation failed (failed to run vrpathreg adddriver)")
return
}
if (addExitCode != 0) {
AppLogger.install.warn("SteamVR driver installation failed (vrpathreg adddriver exited with code $addExitCode)")
return
}
AppLogger.install.info("SteamVR driver successfully installed")
}