Better XML writing for custom icons

This commit is contained in:
J-Jamet
2021-03-08 13:35:57 +01:00
parent 81ba7f0721
commit f8f423b5c1
3 changed files with 11 additions and 13 deletions

View File

@@ -322,10 +322,6 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
return this.iconsManager.getIcon(iconUuid)
}
fun containsCustomIcons(): Boolean {
return this.iconsManager.containsAnyCustomIcon()
}
fun putCustomData(label: String, value: String) {
this.customData[label] = value
}

View File

@@ -69,10 +69,6 @@ class IconsManager {
return listIcons
}
fun containsAnyCustomIcon(): Boolean {
return !customCache.isEmpty()
}
fun removeCustomIcon(iconUuid: UUID) {
val binary = customCache[iconUuid]
customCache.remove(iconUuid)

View File

@@ -697,11 +697,14 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
@Throws(IllegalArgumentException::class, IllegalStateException::class, IOException::class)
private fun writeCustomIconList() {
if (!mDatabaseKDBX.containsCustomIcons()) return
xml.startTag(null, DatabaseKDBXXML.ElemCustomIcons)
var firstElement = true
mDatabaseKDBX.iconsManager.doForEachCustomIconWithoutBinaryDuplication { iconCustom ->
// Write the parent tag
if (firstElement) {
xml.startTag(null, DatabaseKDBXXML.ElemCustomIcons)
firstElement = false
}
xml.startTag(null, DatabaseKDBXXML.ElemCustomIconItem)
writeUuid(DatabaseKDBXXML.ElemCustomIconItemID, iconCustom.uuid)
@@ -716,8 +719,11 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
xml.endTag(null, DatabaseKDBXXML.ElemCustomIconItem)
}
// Close the parent tag
if (!firstElement) {
xml.endTag(null, DatabaseKDBXXML.ElemCustomIcons)
}
}
private fun safeXmlString(text: String): String {
if (text.isEmpty()) {