mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Better method to put binary
This commit is contained in:
@@ -43,13 +43,10 @@ abstract class BinaryPool<T> {
|
||||
/**
|
||||
* Create and return a new binary file not yet linked to a binary
|
||||
*/
|
||||
fun put(cacheDirectory: File,
|
||||
key: T? = null,
|
||||
compression: Boolean = false,
|
||||
protection: Boolean = false): KeyBinary<T> {
|
||||
val fileInCache = File(cacheDirectory, "$poolId$creationId$binaryFileIncrement")
|
||||
fun put(key: T? = null,
|
||||
builder: (uniqueBinaryId: String) -> BinaryData): KeyBinary<T> {
|
||||
binaryFileIncrement++
|
||||
val newBinaryFile = BinaryFile(fileInCache, compression, protection)
|
||||
val newBinaryFile: BinaryData = builder("$poolId$creationId$binaryFileIncrement")
|
||||
val newKey = put(key, newBinaryFile)
|
||||
return KeyBinary(newBinaryFile, newKey)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class DatabaseKDB : DatabaseVersioned<Int, UUID, GroupKDB, EntryKDB>() {
|
||||
|
||||
private var kdfListV3: MutableList<KdfEngine> = ArrayList()
|
||||
|
||||
private var binaryIncrement = 0
|
||||
private var binaryPool = AttachmentPool()
|
||||
|
||||
override val version: String
|
||||
get() = "KeePass 1"
|
||||
@@ -276,9 +276,10 @@ class DatabaseKDB : DatabaseVersioned<Int, UUID, GroupKDB, EntryKDB>() {
|
||||
|
||||
fun buildNewAttachment(cacheDirectory: File): BinaryData {
|
||||
// Generate an unique new file
|
||||
val fileInCache = File(cacheDirectory, binaryIncrement.toString())
|
||||
binaryIncrement++
|
||||
return BinaryFile(fileInCache)
|
||||
return binaryPool.put { uniqueBinaryId ->
|
||||
val fileInCache = File(cacheDirectory, uniqueBinaryId)
|
||||
BinaryFile(fileInCache)
|
||||
}.binary
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -638,7 +638,10 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
||||
compression: Boolean,
|
||||
protection: Boolean,
|
||||
binaryPoolId: Int? = null): BinaryData {
|
||||
return binaryPool.put(cacheDirectory, binaryPoolId, compression, protection).binary
|
||||
return binaryPool.put(binaryPoolId) { uniqueBinaryId ->
|
||||
val fileInCache = File(cacheDirectory, uniqueBinaryId)
|
||||
BinaryFile(fileInCache, compression, protection)
|
||||
}.binary
|
||||
}
|
||||
|
||||
fun removeUnlinkedAttachment(binary: BinaryData, clear: Boolean) {
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.kunzisoft.keepass.database.element.icon
|
||||
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.database.element.database.BinaryData
|
||||
import com.kunzisoft.keepass.database.element.database.BinaryFile
|
||||
import com.kunzisoft.keepass.database.element.database.CustomIconPool
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard.Companion.KEY_ID
|
||||
import com.kunzisoft.keepass.icons.IconPack.Companion.NB_ICONS
|
||||
@@ -52,7 +53,12 @@ class IconsManager {
|
||||
fun buildNewCustomIcon(cacheDirectory: File,
|
||||
key: UUID? = null,
|
||||
result: (IconImageCustom, BinaryData?) -> Unit) {
|
||||
val keyBinary = customCache.put(cacheDirectory, key)
|
||||
val keyBinary = customCache.put(key) { uniqueBinaryId ->
|
||||
//BinaryByte()
|
||||
// TODO change to BinaryByte to increase performance
|
||||
val fileInCache = File(cacheDirectory, uniqueBinaryId)
|
||||
BinaryFile(fileInCache)
|
||||
}
|
||||
result.invoke(IconImageCustom(keyBinary.keys.first()), keyBinary.binary)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user