Skip to content
This repository was archived by the owner on Nov 26, 2019. It is now read-only.

Commit 5d96167

Browse files
committed
add path retrieval for documents in wine prefix
1 parent 7211f78 commit 5d96167

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/main/kotlin/com/msc/serverbrowser/constants/PathConstants.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.msc.serverbrowser.constants
22

3+
import com.msc.serverbrowser.util.unix.WineUtility
4+
import com.msc.serverbrowser.util.windows.OSUtility
35
import java.io.File
46
import javax.swing.filechooser.FileSystemView
57

@@ -28,11 +30,14 @@ object PathConstants {
2830
val TEMP_INSTALLER_EXE = SAMPEX_PATH + File.separator + "tempInstaller.exe"
2931

3032
// GTA / SAMP specific Paths
31-
private val GTA_USER_FILES = (FileSystemView.getFileSystemView().defaultDirectory.path + File.separator
32-
+ "GTA San Andreas User Files")
33+
private val GTA_USER_FILES: String = if (OSUtility.isWindows) {
34+
FileSystemView.getFileSystemView().defaultDirectory.path
35+
} else {
36+
WineUtility.documentsPath
37+
} + File.separator + "GTA San Andreas User Files"
3338
val SAMP_PATH = GTA_USER_FILES + File.separator + "SAMP"
3439
val SAMP_SCREENS = SAMP_PATH + File.separator + "//screens"
3540
val SAMP_CFG = SAMP_PATH + File.separator + "sa-mp.cfg"
36-
val SAMP_CHATLOG = "$SAMP_PATH\\chatlog.txt"
37-
val SAMP_USERDATA = "$SAMP_PATH\\USERDATA.DAT"
41+
val SAMP_CHATLOG = "$SAMP_PATH${File.separator}chatlog.txt"
42+
val SAMP_USERDATA = "$SAMP_PATH${File.separator}USERDATA.DAT"
3843
}

src/main/kotlin/com/msc/serverbrowser/util/samp/SAMPLauncher.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ object SAMPLauncher {
3131
/**
3232
* Tries connecting to a SA-MP server.
3333
*
34-
*
3534
* Also does:
3635
*
3736
* * kill GTA process
3837
* * Check if GTA can be found and display an error otherwise
3938
* * use multiple methods for connecting, in case the best one doesn't work
4039
*
41-
*
42-
*
4340
* @param address the IP-address / domain for the server
4441
* @param port the port for the server
4542
* @param serverPassword password to be used for connect to the server

src/main/kotlin/com/msc/serverbrowser/util/unix/WineUtility.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
package com.msc.serverbrowser.util.unix
22

3+
import com.msc.serverbrowser.util.windows.Registry
4+
35
object WineUtility {
4-
fun convertPath(windowsPath: String) = ProcessBuilder("winepath", windowsPath)
6+
7+
val documentsPath: String
8+
get() {
9+
val pathAfterExpandedPath = Registry
10+
.readString("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", "Personal")
11+
12+
val expandedPath = ProcessBuilder(listOf("wine", "cmd", "/c", "echo", pathAfterExpandedPath))
13+
.start()
14+
.inputStream
15+
.bufferedReader()
16+
.readLine()
17+
.replace("\"", "")
18+
19+
return convertPath(expandedPath)
20+
}
21+
22+
fun convertPath(windowsPath: String): String = ProcessBuilder("winepath", windowsPath)
523
.start()
624
.inputStream
725
.bufferedReader()

src/main/kotlin/com/msc/serverbrowser/util/windows/Registry.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ object Registry {
1414
.bufferedReader()
1515
.use { it.readLines() }
1616
.lastOrNull { it.isNotBlank() }
17-
?.substringAfter("REG_SZ")
17+
?.substringAfter("SZ")
1818
?.trim()
1919
}
2020

0 commit comments

Comments
 (0)