mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
fix(input): skip a leading byte order mark when parsing Steam KeyValues files
This commit is contained in:
1 parent
e9877e27f7
commit
53fdc2c9ad
2 files changed
+21
-2
No files matched your search
@@ -204,7 +204,7 @@ object SteamTouchConfig {
|
||||
}
|
||||
return try {
|
||||
val text = file.readText()
|
||||
val kv = KeyValues.parse(text.removePrefix(""))
|
||||
val kv = KeyValues.parse(text)
|
||||
val mappings = kv.child("controller_mappings") ?: kv
|
||||
val layouts = mappings.string("touch_layout")?.let { hex -> decodeLayouts(hexToBytes(hex)) }
|
||||
Log.i(TAG, "steam touch: app $appId uses ${file.path} (${layouts?.layouts?.size ?: 0} layouts)")
|
||||
@@ -618,7 +618,7 @@ class KeyValues private constructor() {
|
||||
private fun escape(text: String) = text.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\t", "\\t")
|
||||
|
||||
fun parse(text: String): Node {
|
||||
val tokens = tokenize(text)
|
||||
val tokens = tokenize(text.removePrefix("\uFEFF"))
|
||||
var i = 0
|
||||
fun node(): Node {
|
||||
val n = Node()
|
||||
|
||||
@@ -124,6 +124,25 @@ class SteamTouchConfigFilesTest {
|
||||
assertTrue(text.contains("\"413150\""))
|
||||
}
|
||||
|
||||
private fun withBom(name: String) = File(dir, name).apply { writeText("\uFEFF" + readText()) }
|
||||
|
||||
@Test fun aConfigsetWithAByteOrderMarkKeepsItsOtherEntries() {
|
||||
configset("configset_controller_mobile_touch.vdf", "8400" to "\"workshop\"\t\t\"7\"")
|
||||
withBom("configset_controller_mobile_touch.vdf")
|
||||
val saved = saveDefault(413150)
|
||||
val root = KeyValues.parse(File(dir, "configset_controller_mobile_touch.vdf").readText()).child("controller_config")
|
||||
assertEquals("1", root?.child("413150")?.string("autosave"))
|
||||
assertEquals("7", root?.child("8400")?.string("workshop"))
|
||||
assertSavedA(413150, saved)
|
||||
}
|
||||
|
||||
@Test fun aWorkshopPickInAConfigsetWithAByteOrderMarkIsRead() {
|
||||
val picked = workshop("42", "community")
|
||||
configset("configset_controller_mobile_touch.vdf", "413150" to "\"workshop\"\t\t\"42\"")
|
||||
withBom("configset_controller_mobile_touch.vdf")
|
||||
assertEquals(picked, SteamTouchConfig.load(context, 413150).file)
|
||||
}
|
||||
|
||||
@Test fun aConfigsetMissingItsRootBraceGetsTheEntryAtTheRoot() {
|
||||
File(dir, "configset_controller_mobile_touch.vdf")
|
||||
.writeText("\"controller_config\"\n{\n\t\"8400\"\n\t{\n\t\t\"workshop\"\t\t\"7\"\n\t}\n")
|
||||
|
||||
Reference in new issue
Block a user