mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Prevent duplication during database saving
This commit is contained in:
@@ -162,15 +162,29 @@ abstract class BinaryPool<T> {
|
|||||||
/**
|
/**
|
||||||
* Different from doForEach, provide an ordered index to each binary
|
* Different from doForEach, provide an ordered index to each binary
|
||||||
*/
|
*/
|
||||||
fun doForEachOrderedBinary(action: (index: Int, binary: BinaryFile) -> Unit,
|
fun doForEachBinaryWithoutDuplication(action: (keyBinary: KeyBinary<T>) -> Unit,
|
||||||
conditionToAdd: (binary: BinaryFile) -> Boolean) {
|
conditionToAdd: (binary: BinaryFile) -> Boolean) {
|
||||||
|
orderedBinariesWithoutDuplication(conditionToAdd).forEach { keyBinary ->
|
||||||
|
action.invoke(keyBinary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doForEachBinaryWithoutDuplication(action: (keyBinary: KeyBinary<T>) -> Unit) {
|
||||||
|
doForEachBinaryWithoutDuplication(action, { true })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Different from doForEach, provide an ordered index to each binary
|
||||||
|
*/
|
||||||
|
fun doForEachOrderedBinaryWithoutDuplication(action: (index: Int, binary: BinaryFile) -> Unit,
|
||||||
|
conditionToAdd: (binary: BinaryFile) -> Boolean) {
|
||||||
orderedBinariesWithoutDuplication(conditionToAdd).forEachIndexed { index, keyBinary ->
|
orderedBinariesWithoutDuplication(conditionToAdd).forEachIndexed { index, keyBinary ->
|
||||||
action.invoke(index, keyBinary.binary)
|
action.invoke(index, keyBinary.binary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doForEachOrderedBinary(action: (index: Int, binary: BinaryFile) -> Unit) {
|
fun doForEachOrderedBinaryWithoutDuplication(action: (index: Int, binary: BinaryFile) -> Unit) {
|
||||||
doForEachOrderedBinary(action, { true })
|
doForEachOrderedBinaryWithoutDuplication(action, { true })
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isEmpty(): Boolean {
|
fun isEmpty(): Boolean {
|
||||||
|
|||||||
@@ -91,6 +91,14 @@ class IconsManager {
|
|||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun doForEachCustomIconWithoutBinaryDuplication(action: (IconImageCustom) -> Unit) {
|
||||||
|
customCache.doForEachBinaryWithoutDuplication { keyBinary ->
|
||||||
|
keyBinary.keys.forEach { key ->
|
||||||
|
action.invoke(IconImageCustom(key, keyBinary.binary))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear the cache of icons
|
* Clear the cache of icons
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
|
|||||||
|
|
||||||
val binaryCipherKey = database.loadedCipherKey
|
val binaryCipherKey = database.loadedCipherKey
|
||||||
?: throw IOException("Unable to retrieve cipher key to write binaries")
|
?: throw IOException("Unable to retrieve cipher key to write binaries")
|
||||||
database.binaryPool.doForEachOrderedBinary { _, binary ->
|
database.binaryPool.doForEachOrderedBinaryWithoutDuplication { _, binary ->
|
||||||
// Force decompression to add binary in header
|
// Force decompression to add binary in header
|
||||||
binary.decompress(binaryCipherKey)
|
binary.decompress(binaryCipherKey)
|
||||||
// Write type binary
|
// Write type binary
|
||||||
@@ -497,7 +497,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
|
|||||||
xml.startTag(null, DatabaseKDBXXML.ElemBinaries)
|
xml.startTag(null, DatabaseKDBXXML.ElemBinaries)
|
||||||
|
|
||||||
// Use indexes because necessarily (binary header ref is the order)
|
// Use indexes because necessarily (binary header ref is the order)
|
||||||
mDatabaseKDBX.binaryPool.doForEachOrderedBinary { index, binary ->
|
mDatabaseKDBX.binaryPool.doForEachOrderedBinaryWithoutDuplication { index, binary ->
|
||||||
xml.startTag(null, DatabaseKDBXXML.ElemBinary)
|
xml.startTag(null, DatabaseKDBXXML.ElemBinary)
|
||||||
xml.attribute(null, DatabaseKDBXXML.AttrId, index.toString())
|
xml.attribute(null, DatabaseKDBXXML.AttrId, index.toString())
|
||||||
if (binary.length > 0) {
|
if (binary.length > 0) {
|
||||||
@@ -701,7 +701,7 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
|
|||||||
|
|
||||||
xml.startTag(null, DatabaseKDBXXML.ElemCustomIcons)
|
xml.startTag(null, DatabaseKDBXXML.ElemCustomIcons)
|
||||||
|
|
||||||
mDatabaseKDBX.iconsManager.getCustomIconList().forEach { iconCustom ->
|
mDatabaseKDBX.iconsManager.doForEachCustomIconWithoutBinaryDuplication { iconCustom ->
|
||||||
xml.startTag(null, DatabaseKDBXXML.ElemCustomIconItem)
|
xml.startTag(null, DatabaseKDBXXML.ElemCustomIconItem)
|
||||||
|
|
||||||
writeUuid(DatabaseKDBXXML.ElemCustomIconItemID, iconCustom.uuid)
|
writeUuid(DatabaseKDBXXML.ElemCustomIconItemID, iconCustom.uuid)
|
||||||
|
|||||||
Reference in New Issue
Block a user