mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Add name to custom icons #956
This commit is contained in:
@@ -316,9 +316,10 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun addCustomIcon(customIconId: UUID? = null,
|
fun addCustomIcon(customIconId: UUID? = null,
|
||||||
|
name: String,
|
||||||
smallSize: Boolean,
|
smallSize: Boolean,
|
||||||
result: (IconImageCustom, BinaryData?) -> Unit) {
|
result: (IconImageCustom, BinaryData?) -> Unit) {
|
||||||
iconsManager.addCustomIcon(customIconId, smallSize, result)
|
iconsManager.addCustomIcon(customIconId, name, smallSize, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isCustomIconBinaryDuplicate(binary: BinaryData): Boolean {
|
fun isCustomIconBinaryDuplicate(binary: BinaryData): Boolean {
|
||||||
|
|||||||
@@ -327,6 +327,10 @@ class EntryKDBX : EntryVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
|
|||||||
return customData.isNotEmpty()
|
return customData.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun containsCustomIconWithName(): Boolean {
|
||||||
|
return icon.custom.name.isNotEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
fun addEntryToHistory(entry: EntryKDBX) {
|
fun addEntryToHistory(entry: EntryKDBX) {
|
||||||
history.add(entry)
|
history.add(entry)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,6 +125,10 @@ class GroupKDBX : GroupVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInte
|
|||||||
return customData.isNotEmpty()
|
return customData.isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun containsCustomIconWithName(): Boolean {
|
||||||
|
return icon.custom.name.isNotEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
|
|||||||
@@ -27,22 +27,27 @@ import java.util.*
|
|||||||
|
|
||||||
class IconImageCustom : IconImageDraw {
|
class IconImageCustom : IconImageDraw {
|
||||||
|
|
||||||
var uuid: UUID
|
val uuid: UUID
|
||||||
|
var name: String = ""
|
||||||
|
|
||||||
constructor() {
|
constructor(name: String = "") {
|
||||||
uuid = DatabaseVersioned.UUID_ZERO
|
this.uuid = DatabaseVersioned.UUID_ZERO
|
||||||
|
this.name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(uuid: UUID) {
|
constructor(uuid: UUID, name: String = "") {
|
||||||
this.uuid = uuid
|
this.uuid = uuid
|
||||||
|
this.name = name
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(parcel: Parcel) {
|
constructor(parcel: Parcel) {
|
||||||
uuid = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: DatabaseVersioned.UUID_ZERO
|
uuid = parcel.readParcelable<ParcelUuid>(ParcelUuid::class.java.classLoader)?.uuid ?: DatabaseVersioned.UUID_ZERO
|
||||||
|
name = parcel.readString() ?: name
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||||
dest.writeParcelable(ParcelUuid(uuid), flags)
|
dest.writeParcelable(ParcelUuid(uuid), flags)
|
||||||
|
dest.writeString(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun describeContents(): Int {
|
override fun describeContents(): Int {
|
||||||
|
|||||||
@@ -52,17 +52,18 @@ class IconsManager(private val binaryCache: BinaryCache) {
|
|||||||
fun buildNewCustomIcon(key: UUID? = null,
|
fun buildNewCustomIcon(key: UUID? = null,
|
||||||
result: (IconImageCustom, BinaryData?) -> Unit) {
|
result: (IconImageCustom, BinaryData?) -> Unit) {
|
||||||
// Create a binary file for a brand new custom icon
|
// Create a binary file for a brand new custom icon
|
||||||
addCustomIcon(key, false, result)
|
addCustomIcon(key, "", false, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addCustomIcon(key: UUID? = null,
|
fun addCustomIcon(key: UUID? = null,
|
||||||
|
name: String,
|
||||||
smallSize: Boolean,
|
smallSize: Boolean,
|
||||||
result: (IconImageCustom, BinaryData?) -> Unit) {
|
result: (IconImageCustom, BinaryData?) -> Unit) {
|
||||||
val keyBinary = customCache.put(key) { uniqueBinaryId ->
|
val keyBinary = customCache.put(key) { uniqueBinaryId ->
|
||||||
// Create a byte array for better performance with small data
|
// Create a byte array for better performance with small data
|
||||||
binaryCache.getBinaryData(uniqueBinaryId, smallSize)
|
binaryCache.getBinaryData(uniqueBinaryId, smallSize)
|
||||||
}
|
}
|
||||||
result.invoke(IconImageCustom(keyBinary.keys.first()), keyBinary.binary)
|
result.invoke(IconImageCustom(keyBinary.keys.first(), name), keyBinary.binary)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getIcon(iconUuid: UUID): IconImageCustom {
|
fun getIcon(iconUuid: UUID): IconImageCustom {
|
||||||
|
|||||||
@@ -32,4 +32,6 @@ interface NodeKDBXInterface : NodeTimeInterface {
|
|||||||
|
|
||||||
fun containsCustomData(): Boolean
|
fun containsCustomData(): Boolean
|
||||||
|
|
||||||
|
fun containsCustomIconWithName() : Boolean
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,10 +97,12 @@ class DatabaseHeaderKDBX(private val databaseV4: DatabaseKDBX) : DatabaseHeader(
|
|||||||
var containsCustomData = false
|
var containsCustomData = false
|
||||||
var containsCustomDataWithLastModificationTime = false
|
var containsCustomDataWithLastModificationTime = false
|
||||||
override fun operate(node: T): Boolean {
|
override fun operate(node: T): Boolean {
|
||||||
|
if (node.containsCustomIconWithName()) {
|
||||||
|
containsCustomIconWithName = true
|
||||||
|
}
|
||||||
if (node.containsCustomData()) {
|
if (node.containsCustomData()) {
|
||||||
containsCustomData = true
|
containsCustomData = true
|
||||||
}
|
}
|
||||||
// TODO Custom Icon name
|
|
||||||
// TODO Custom Icon modification time
|
// TODO Custom Icon modification time
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ object DatabaseKDBXXML {
|
|||||||
const val ElemCustomIconItem = "Icon"
|
const val ElemCustomIconItem = "Icon"
|
||||||
const val ElemCustomIconItemID = "UUID"
|
const val ElemCustomIconItemID = "UUID"
|
||||||
const val ElemCustomIconItemData = "Data"
|
const val ElemCustomIconItemData = "Data"
|
||||||
|
const val ElemCustomIconName = "Name"
|
||||||
|
|
||||||
const val ElemAutoType = "AutoType"
|
const val ElemAutoType = "AutoType"
|
||||||
const val ElemHistory = "History"
|
const val ElemHistory = "History"
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ class DatabaseInputKDBX(cacheDirectory: File,
|
|||||||
private var ctxHistoryBase: EntryKDBX? = null
|
private var ctxHistoryBase: EntryKDBX? = null
|
||||||
private var ctxDeletedObject: DeletedObject? = null
|
private var ctxDeletedObject: DeletedObject? = null
|
||||||
private var customIconID = DatabaseVersioned.UUID_ZERO
|
private var customIconID = DatabaseVersioned.UUID_ZERO
|
||||||
|
private var customIconName: String = ""
|
||||||
private var customIconData: ByteArray? = null
|
private var customIconData: ByteArray? = null
|
||||||
private var customDataKey: String? = null
|
private var customDataKey: String? = null
|
||||||
private var customDataValue: String? = null
|
private var customDataValue: String? = null
|
||||||
@@ -469,6 +470,8 @@ class DatabaseInputKDBX(cacheDirectory: File,
|
|||||||
if (strData.isNotEmpty()) {
|
if (strData.isNotEmpty()) {
|
||||||
customIconData = Base64.decode(strData, BASE_64_FLAG)
|
customIconData = Base64.decode(strData, BASE_64_FLAG)
|
||||||
}
|
}
|
||||||
|
} else if (name.equals(DatabaseKDBXXML.ElemCustomIconName, ignoreCase = true)) {
|
||||||
|
customIconName = readString(xpp)
|
||||||
} else {
|
} else {
|
||||||
readUnknown(xpp)
|
readUnknown(xpp)
|
||||||
}
|
}
|
||||||
@@ -719,7 +722,9 @@ class DatabaseInputKDBX(cacheDirectory: File,
|
|||||||
} else if (ctx == KdbContext.CustomIcon && name.equals(DatabaseKDBXXML.ElemCustomIconItem, ignoreCase = true)) {
|
} else if (ctx == KdbContext.CustomIcon && name.equals(DatabaseKDBXXML.ElemCustomIconItem, ignoreCase = true)) {
|
||||||
val iconData = customIconData
|
val iconData = customIconData
|
||||||
if (customIconID != DatabaseVersioned.UUID_ZERO && iconData != null) {
|
if (customIconID != DatabaseVersioned.UUID_ZERO && iconData != null) {
|
||||||
mDatabase.addCustomIcon(customIconID, isRAMSufficient.invoke(iconData.size.toLong())) { _, binary ->
|
mDatabase.addCustomIcon(customIconID,
|
||||||
|
customIconName,
|
||||||
|
isRAMSufficient.invoke(iconData.size.toLong())) { _, binary ->
|
||||||
binary?.getOutputDataStream(mDatabase.binaryCache)?.use { outputStream ->
|
binary?.getOutputDataStream(mDatabase.binaryCache)?.use { outputStream ->
|
||||||
outputStream.write(iconData)
|
outputStream.write(iconData)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -724,6 +724,9 @@ class DatabaseOutputKDBX(private val mDatabaseKDBX: DatabaseKDBX,
|
|||||||
writeObject(DatabaseKDBXXML.ElemCustomIconItemData,
|
writeObject(DatabaseKDBXXML.ElemCustomIconItemData,
|
||||||
String(Base64.encode(customImageData, BASE_64_FLAG)))
|
String(Base64.encode(customImageData, BASE_64_FLAG)))
|
||||||
}
|
}
|
||||||
|
if (iconCustom.name.isNotEmpty()) {
|
||||||
|
writeObject(DatabaseKDBXXML.ElemCustomIconName, iconCustom.name)
|
||||||
|
}
|
||||||
|
|
||||||
xml.endTag(null, DatabaseKDBXXML.ElemCustomIconItem)
|
xml.endTag(null, DatabaseKDBXXML.ElemCustomIconItem)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user