mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
fix(input): close a truncated touch configset before adding the autosave entry
This commit is contained in:
1 parent
439d9afe5e
commit
02e7eff284
2 files changed
+17
-1
No files matched your search
@@ -438,7 +438,7 @@ object SteamTouchConfig {
|
||||
|
||||
private fun selectAutosave(dir: File, key: String) {
|
||||
val file = File(dir, CONFIGSET)
|
||||
val text = file.takeIf { it.isFile }?.readText()?.takeIf { it.contains('}') } ?: "\"controller_config\"\n{\n}\n"
|
||||
val text = file.takeIf { it.isFile }?.readText()?.takeIf { it.contains('{') }?.let(::closeBraces) ?: "\"controller_config\"\n{\n}\n"
|
||||
val entry = "\t\"$key\"\n\t{\n\t\t\"autosave\"\t\t\"1\"\n\t}"
|
||||
val block = Regex("""\n\s*"${Regex.escape(key)}"\s*\{[^}]*\}""", RegexOption.IGNORE_CASE)
|
||||
val next = if (block.containsMatchIn(text)) text.replace(block) { "\n$entry" }
|
||||
@@ -446,6 +446,11 @@ object SteamTouchConfig {
|
||||
File(file.path + ".tmp").apply { writeText(next) }.renameTo(file)
|
||||
}
|
||||
|
||||
private fun closeBraces(text: String): String {
|
||||
val open = text.count { it == '{' } - text.count { it == '}' }
|
||||
return if (open <= 0) text else text.trimEnd() + "\n}".repeat(open) + "\n"
|
||||
}
|
||||
|
||||
|
||||
fun decodeLayouts(bytes: ByteArray): Layouts {
|
||||
val layouts = mutableListOf<Layout>()
|
||||
|
||||
Reference in new issue
Block a user