Skip to content

Commit 5261308

Browse files
Merge pull request #146 from KitsuneDev/linux-macos-paths
Add Preliminary Support for Linux and MacOS Paths
2 parents d9af883 + e9ab40e commit 5261308

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/main/kotlin/icu/windea/pls/lang/PlsDataProvider.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.util.concurrent.*
1212
*/
1313
@Service
1414
class PlsDataProvider {
15+
val OS: String = System.getProperty("os.name", "Windows")
1516
fun init() {
1617
//preload cached values
1718
initForPaths()
@@ -57,6 +58,7 @@ class PlsDataProvider {
5758
}
5859

5960
private fun doGetSteamPath(): String {
61+
if(!OS.contains("Windows")) return ""
6062
val command = """Get-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Valve\Steam' | Select-Object InstallPath | Format-Table -HideTableHeaders"""
6163
return runCatchingCancelable { executeCommand(command, CommandType.POWER_SHELL) }.getOrDefault("")
6264
}
@@ -72,14 +74,17 @@ class PlsDataProvider {
7274
}
7375

7476
private fun doGetSteamGamePath(steamId: String): String {
77+
if(!OS.contains("Windows")) return "";
7578
val command = """Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App ${steamId}' | Select-Object InstallLocation | Format-Table -HideTableHeaders"""
7679
return runCatchingCancelable { executeCommand(command, CommandType.POWER_SHELL) }.getOrDefault("")
7780
}
7881

7982
private fun doGetFallbackSteamGamePath(gameName: String): String? {
8083
//不准确,可以放在不同库目录下
8184
val steamPath = getSteamPath() ?: return null
82-
return """$steamPath\steamapps\common\$gameName"""
85+
var path = """$steamPath\steamapps\common\$gameName"""
86+
if(!OS.contains("Windows")) path = path.replace("\\", "/");
87+
return path
8388
}
8489

8590
/**
@@ -88,7 +93,9 @@ class PlsDataProvider {
8893
fun getSteamWorkshopPath(steamId: String): String? {
8994
//不准确,可以放在不同库目录下
9095
val steamPath = getSteamPath() ?: return null
91-
return """$steamPath\steamapps\workshop\content\$steamId"""
96+
var path = """$steamPath\steamapps\workshop\content\$steamId"""
97+
if(!OS.contains("Windows")) path = path.replace("\\", "/");
98+
return path
9299
}
93100

94101
/**
@@ -97,7 +104,10 @@ class PlsDataProvider {
97104
fun getGameDataPath(gameName: String): String? {
98105
//实际上应当基于launcher-settings.json中的gameDataPath
99106
val userHome = System.getProperty("user.home") ?: return null
100-
return """$userHome\Documents\Paradox Interactive\$gameName"""
107+
// Note: needs to be symlinked to install path.
108+
var path = """$userHome\Documents\Paradox Interactive\$gameName"""
109+
if(!OS.contains("Windows")) path = path.replace("\\", "/");
110+
return path
101111
}
102112

103113
//endregion

0 commit comments

Comments
 (0)