diff --git a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt index 8e5f9a29e3..b71e0b0623 100644 --- a/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt +++ b/app/src/main/java/com/droiddeck/launcher/input/SteamTouchConfig.kt @@ -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() diff --git a/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt b/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt index bcb2131711..22f9650bf1 100644 --- a/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/input/SteamTouchConfigFilesTest.kt @@ -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")