Skip to content

Commit

Permalink
#1274 fix: restore key maps by using gson instance that uses the dese…
Browse files Browse the repository at this point in the history
…rializers
  • Loading branch information
sds100 committed Nov 14, 2024
1 parent ad1af28 commit 7142f2c
Showing 1 changed file with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import io.github.sds100.keymapper.data.entities.ConstraintEntity
import io.github.sds100.keymapper.data.entities.Extra
import io.github.sds100.keymapper.data.entities.FingerprintMapEntity
import io.github.sds100.keymapper.data.entities.KeyMapEntity
import io.github.sds100.keymapper.data.entities.TriggerEntity
import io.github.sds100.keymapper.data.entities.TriggerKeyEntity
import io.github.sds100.keymapper.data.migration.JsonMigration
import io.github.sds100.keymapper.data.migration.Migration10To11
import io.github.sds100.keymapper.data.migration.Migration11To12
Expand Down Expand Up @@ -110,6 +112,8 @@ class BackupManagerImpl(
GsonBuilder()
.registerTypeAdapter(FingerprintMapEntity.DESERIALIZER)
.registerTypeAdapter(KeyMapEntity.DESERIALIZER)
.registerTypeAdapter(TriggerEntity.DESERIALIZER)
.registerTypeAdapter(TriggerKeyEntity.DESERIALIZER)
.registerTypeAdapter(ActionEntity.DESERIALIZER)
.registerTypeAdapter(Extra.DESERIALIZER)
.registerTypeAdapter(ConstraintEntity.DESERIALIZER).create()
Expand Down Expand Up @@ -262,7 +266,6 @@ class BackupManagerImpl(
private suspend fun restore(inputStream: InputStream, soundFiles: List<IFile>): Result<*> {
try {
val parser = JsonParser()
val gson = Gson()

val rootElement = inputStream.bufferedReader().use {
val element = parser.parse(it)
Expand Down Expand Up @@ -299,10 +302,7 @@ class BackupManagerImpl(
Migration11To12.migrateKeyMap(json, deviceInfoList ?: JsonArray())
},
// do nothing because this added the log table
JsonMigration(
12,
13,
) { json -> json },
JsonMigration(12, 13) { json -> json },
)

keymapListJsonArray?.forEach { keyMap ->
Expand Down Expand Up @@ -330,10 +330,7 @@ class BackupManagerImpl(

// do nothing because this added the log table
val newFingerprintMapMigrations = listOf(
JsonMigration(
12,
13,
) { json -> json },
JsonMigration(12, 13) { json -> json },
)

if (rootElement.contains(NAME_FINGERPRINT_MAP_LIST) && backupDbVersion >= 12) {
Expand Down Expand Up @@ -429,8 +426,9 @@ class BackupManagerImpl(
} catch (e: NoSuchElementException) {
return Error.CorruptJsonFile(e.message ?: "")
} catch (e: Exception) {
e.printStackTrace()

if (throwExceptions) {
e.printStackTrace()
throw e
}

Expand Down

0 comments on commit 7142f2c

Please sign in to comment.