diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/GroupVersioned.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/GroupVersioned.kt index 607cfd930..3673e9cfb 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/GroupVersioned.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/GroupVersioned.kt @@ -292,11 +292,11 @@ class GroupVersioned : NodeVersioned, PwGroupInterface, PwNodeV4Interface { var notes = "" var isExpanded = true var defaultAutoTypeSequence = "" - var enableAutoType: Boolean = true - var enableSearching: Boolean = true + var enableAutoType: Boolean? = null + var enableSearching: Boolean? = null var lastTopVisibleEntry: UUID = PwDatabase.UUID_ZERO override val type: Type @@ -70,8 +70,10 @@ class PwGroupV4 : PwGroup, PwNodeV4Interface { notes = parcel.readString() ?: notes isExpanded = parcel.readByte().toInt() != 0 defaultAutoTypeSequence = parcel.readString() ?: defaultAutoTypeSequence - enableAutoType = parcel.readByte().toInt() != 0 - enableSearching = parcel.readByte().toInt() != 0 + val isAutoTypeEnabled = parcel.readInt() + enableAutoType = if (isAutoTypeEnabled == -1) null else isAutoTypeEnabled == 1 + val isSearchingEnabled = parcel.readInt() + enableSearching = if (isSearchingEnabled == -1) null else isSearchingEnabled == 1 lastTopVisibleEntry = parcel.readSerializable() as UUID } @@ -92,8 +94,8 @@ class PwGroupV4 : PwGroup, PwNodeV4Interface { dest.writeString(notes) dest.writeByte((if (isExpanded) 1 else 0).toByte()) dest.writeString(defaultAutoTypeSequence) - dest.writeByte((if (enableAutoType) 1 else 0).toByte()) - dest.writeByte((if (enableSearching) 1 else 0).toByte()) + dest.writeInt(if (enableAutoType == null) -1 else if (enableAutoType!!) 1 else 0) + dest.writeInt(if (enableSearching == null) -1 else if (enableSearching!!) 1 else 0) dest.writeSerializable(lastTopVisibleEntry) } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/file/load/Importer.kt b/app/src/main/java/com/kunzisoft/keepass/database/file/load/Importer.kt index ccd24df4c..1eec9700e 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/file/load/Importer.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/file/load/Importer.kt @@ -39,6 +39,9 @@ abstract class Importer> { * @throws InvalidDBException on database error. */ @Throws(IOException::class, InvalidDBException::class) - abstract fun openDatabase(databaseInputStream: InputStream, password: String?, keyInputStream: InputStream?, progressTaskUpdater: ProgressTaskUpdater?): PwDb + abstract fun openDatabase(databaseInputStream: InputStream, + password: String?, + keyInputStream: InputStream?, + progressTaskUpdater: ProgressTaskUpdater?): PwDb } diff --git a/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt b/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt index 71b5c4205..d3f242dc5 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt @@ -490,9 +490,9 @@ class ImporterV4(private val streamDir: File) : Importer() { } else if (name.equals(PwDatabaseV4XML.ElemGroupDefaultAutoTypeSeq, ignoreCase = true)) { ctxGroup?.defaultAutoTypeSequence = readString(xpp) } else if (name.equals(PwDatabaseV4XML.ElemEnableAutoType, ignoreCase = true)) { - ctxGroup?.enableAutoType = stringToBoolean(readString(xpp)) + ctxGroup?.enableAutoType = readOptionalBool(xpp) } else if (name.equals(PwDatabaseV4XML.ElemEnableSearching, ignoreCase = true)) { - ctxGroup?.enableSearching = stringToBoolean(readString(xpp)) + ctxGroup?.enableSearching = readOptionalBool(xpp) } else if (name.equals(PwDatabaseV4XML.ElemLastTopVisibleEntry, ignoreCase = true)) { ctxGroup?.lastTopVisibleEntry = readUuid(xpp) } else if (name.equals(PwDatabaseV4XML.ElemCustomData, ignoreCase = true)) { @@ -847,7 +847,23 @@ class ImporterV4(private val streamDir: File) : Importer() { private fun readBool(xpp: XmlPullParser, bDefault: Boolean): Boolean { val str = readString(xpp) - return str.equals("true", ignoreCase = true) || !str.equals("false", ignoreCase = true) && bDefault + return when { + str.equals(PwDatabaseV4XML.ValTrue, ignoreCase = true) -> true + str.equals(PwDatabaseV4XML.ValFalse, ignoreCase = true) -> false + else -> bDefault + } + } + + @Throws(IOException::class, XmlPullParserException::class) + private fun readOptionalBool(xpp: XmlPullParser, bDefault: Boolean? = null): Boolean? { + val str = readString(xpp) + + return when { + str.equals(PwDatabaseV4XML.ValTrue, ignoreCase = true) -> true + str.equals(PwDatabaseV4XML.ValFalse, ignoreCase = true) -> false + str.equals(PwDatabaseV4XML.ValNull, ignoreCase = true) -> null + else -> bDefault + } } @Throws(IOException::class, XmlPullParserException::class) @@ -1032,22 +1048,6 @@ class ImporterV4(private val streamDir: File) : Importer() { return ctxNew } - - private fun stringToBoolean(str: String?): Boolean { - if (str == null || str.isEmpty()) { - return false - } - - val trimmed = str.trim { it <= ' ' } - if (trimmed.equals("true", ignoreCase = true)) { - return true - } else if (trimmed.equals("false", ignoreCase = true)) { - return false - } - - return false - } - companion object { private const val DEFAULT_HISTORY_DAYS: Long = 365 diff --git a/app/src/main/java/com/kunzisoft/keepass/database/file/save/PwDbV4Output.kt b/app/src/main/java/com/kunzisoft/keepass/database/file/save/PwDbV4Output.kt index 4c4977b60..5ec421bce 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/file/save/PwDbV4Output.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/file/save/PwDbV4Output.kt @@ -496,7 +496,7 @@ class PwDbV4Output(private val mDatabaseV4: PwDatabaseV4, outputStream: OutputSt @Throws(IllegalArgumentException::class, IllegalStateException::class, IOException::class) private fun writeObject(name: String, value: Boolean?) { val text: String = when { - value == null -> "null" + value == null -> PwDatabaseV4XML.ValNull value -> PwDatabaseV4XML.ValTrue else -> PwDatabaseV4XML.ValFalse }