mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 15:56:01 +00:00
fix(battlenet): drop the unused runtime drive and list its games under the runtime path (#3188)
* fix(battlenet): drop the unused runtime drive and list its games under the runtime path * fix(battlenet): read product.db paths decoded and keep alias-saved folders * fix(battlenet): keep drives for paths that climb out of the runtime * fix(battlenet): keep a drive referenced with any separator spelling * fix(battlenet): check decoded config values before dropping a drive
This commit is contained in:
1 parent
1b80b506cb
commit
19d8819137
4 files changed
+244
-5
No files matched your search
@@ -207,7 +207,8 @@ object BattleNet {
|
||||
val taken = HashSet<File>()
|
||||
fun options(title: Title, folder: File) = listOfNotNull(folder, title.flavor?.let { File(folder, it) }?.takeIf { it.isDirectory })
|
||||
for ((code, game) in games) {
|
||||
val keep = saved[code]?.let(::File)?.takeIf { it in options(game.first, game.second) && it !in taken } ?: continue
|
||||
val want = saved[code]?.let { runCatching { File(it).canonicalFile }.getOrNull() } ?: continue
|
||||
val keep = options(game.first, game.second).firstOrNull { runCatching { it.canonicalFile }.getOrNull() == want }?.takeIf { it !in taken } ?: continue
|
||||
out[code] = keep
|
||||
taken.add(keep)
|
||||
}
|
||||
@@ -245,9 +246,12 @@ object BattleNet {
|
||||
}
|
||||
}.trimEnd('/')
|
||||
if (mapped?.startsWith("/") == true) {
|
||||
val host = File("$target/$relative")
|
||||
val rootfs = LinuxRuntime.rootDir(context)
|
||||
if (runCatching { host.canonicalFile.startsWith(rootfs.canonicalFile) }.getOrDefault(false)) return host
|
||||
runCatching {
|
||||
val home = rootfs.canonicalFile.toPath()
|
||||
val host = File("$target/$relative").canonicalFile.toPath()
|
||||
if (host.startsWith(home)) File(rootfs, home.relativize(host).toString()) else null
|
||||
}.getOrNull()?.let { return it }
|
||||
}
|
||||
return com.droiddeck.launcher.frontend.AddedGames.hostPath(context, "$target/$relative")
|
||||
}
|
||||
|
||||
@@ -236,6 +236,21 @@ class BattleNetTest {
|
||||
assertNull(BattleNet.hostFolder(context, "D:\\..\\etc"))
|
||||
}
|
||||
|
||||
@Test fun aDriveAtAnAliasOfTheAppDataFolderListsTheGameUnderTheRuntimePath() {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
val data = context.filesDir.parentFile!!
|
||||
val alias = File(data.parentFile, "alias-" + data.name)
|
||||
java.nio.file.Files.createSymbolicLink(alias.toPath(), data.absoluteFile.toPath())
|
||||
try {
|
||||
val devices = File(BattleNet.prefix(context), "pfx/dosdevices").apply { mkdirs() }
|
||||
java.nio.file.Files.createSymbolicLink(File(devices, "d:").toPath(), alias.absoluteFile.toPath())
|
||||
val game = File(root, "root/Games/Stores/Battle.net/StarCraft").apply { mkdirs() }
|
||||
val drive = "D:\\" + data.absoluteFile.toPath().relativize(game.absoluteFile.toPath()).joinToString("\\")
|
||||
assertEquals(game.path, BattleNet.hostFolder(context, drive)?.path)
|
||||
} finally {
|
||||
java.nio.file.Files.delete(alias.toPath())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun wowForeverIsListedBesideRetailInTheSharedWorldOfWarcraftFolder() {
|
||||
val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() }
|
||||
@@ -294,6 +309,21 @@ class BattleNetTest {
|
||||
assertEquals(mapOf("WoWF" to root), BattleNet.ownFolders(mapOf("WoWF" to (forever to root)), mapOf("WoWF" to "/elsewhere")))
|
||||
}
|
||||
|
||||
@Test fun aFolderSavedThroughAnAliasOfTheAppDataFolderIsKept() {
|
||||
val data = context.filesDir.parentFile!!
|
||||
val root = File(context.filesDir, "World of Warcraft").apply { mkdirs() }
|
||||
val foreverDir = File(root, "_forever_").apply { mkdirs() }
|
||||
val forever = BattleNet.title("wow_forever")!!
|
||||
val alias = File(data.parentFile, "alias-" + data.name)
|
||||
java.nio.file.Files.createSymbolicLink(alias.toPath(), data.absoluteFile.toPath())
|
||||
try {
|
||||
val saved = File(alias, data.absoluteFile.toPath().relativize(foreverDir.absoluteFile.toPath()).toString()).path
|
||||
assertEquals(mapOf("WoWF" to foreverDir), BattleNet.ownFolders(mapOf("WoWF" to (forever to root)), mapOf("WoWF" to saved)))
|
||||
} finally {
|
||||
java.nio.file.Files.delete(alias.toPath())
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun theListedFolderIsRememberedAcrossScans() {
|
||||
val pfx = File(BattleNet.prefix(context), "pfx").apply { mkdirs() }
|
||||
val wow = File(pfx, "drive_c/Program Files (x86)/World of Warcraft").apply { mkdirs() }
|
||||
|
||||
Reference in new issue
Block a user