mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Prevent uploading icon in error
This commit is contained in:
@@ -92,6 +92,7 @@ class Database {
|
|||||||
return mDatabaseKDB?.loadedCipherKey ?: mDatabaseKDBX?.loadedCipherKey
|
return mDatabaseKDB?.loadedCipherKey ?: mDatabaseKDBX?.loadedCipherKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO private
|
||||||
val iconsManager: IconsManager
|
val iconsManager: IconsManager
|
||||||
get() {
|
get() {
|
||||||
return mDatabaseKDB?.iconsManager ?: mDatabaseKDBX?.iconsManager ?: IconsManager()
|
return mDatabaseKDB?.iconsManager ?: mDatabaseKDBX?.iconsManager ?: IconsManager()
|
||||||
@@ -102,6 +103,10 @@ class Database {
|
|||||||
?: mDatabaseKDBX?.buildNewCustomIcon(cacheDirectory)
|
?: mDatabaseKDBX?.buildNewCustomIcon(cacheDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeCustomIcon(iconUUID: UUID) {
|
||||||
|
iconsManager.removeCustomIcon(iconUUID)
|
||||||
|
}
|
||||||
|
|
||||||
val allowName: Boolean
|
val allowName: Boolean
|
||||||
get() = mDatabaseKDBX != null
|
get() = mDatabaseKDBX != null
|
||||||
|
|
||||||
|
|||||||
@@ -78,6 +78,15 @@ abstract class BinaryPool<T> {
|
|||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a binary from the pool with its [key], the file is not deleted
|
||||||
|
*/
|
||||||
|
@Throws(IOException::class)
|
||||||
|
fun remove(key: T) {
|
||||||
|
pool.remove(key)
|
||||||
|
// Don't clear attachment here because a file can be used in many BinaryAttachment
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a binary from the pool, the file is not deleted
|
* Remove a binary from the pool, the file is not deleted
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -319,7 +319,7 @@ class DatabaseKDBX : DatabaseVersioned<UUID, UUID, GroupKDBX, EntryKDBX> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun containsCustomIcons(): Boolean {
|
fun containsCustomIcons(): Boolean {
|
||||||
return this.iconsManager.containsCustomIcons()
|
return this.iconsManager.containsAnyCustomIcon()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun putCustomData(label: String, value: String) {
|
fun putCustomData(label: String, value: String) {
|
||||||
|
|||||||
@@ -60,10 +60,20 @@ class IconsManager {
|
|||||||
return IconImageCustom(iconUuid)
|
return IconImageCustom(iconUuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun containsCustomIcons(): Boolean {
|
fun containsAnyCustomIcon(): Boolean {
|
||||||
return !customCache.isEmpty()
|
return !customCache.isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun removeCustomIcon(iconUuid: UUID) {
|
||||||
|
val binary = customCache[iconUuid]
|
||||||
|
customCache.remove(iconUuid)
|
||||||
|
try {
|
||||||
|
binary?.clear()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Unable to remove custom icon binary", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getCustomIconList(): List<IconImage> {
|
fun getCustomIconList(): List<IconImage> {
|
||||||
val list = ArrayList<IconImage>()
|
val list = ArrayList<IconImage>()
|
||||||
customCache.doForEachBinary { key, binary ->
|
customCache.doForEachBinary { key, binary ->
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ class IconPickerViewModel: ViewModel() {
|
|||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
asyncResult.await()?.let { customIcon ->
|
asyncResult.await()?.let { customIcon ->
|
||||||
iconCustomAdded.value = customIcon
|
iconCustomAdded.value = customIcon
|
||||||
|
// Remove icon if data cannot be saved
|
||||||
|
if (customIcon.binaryFile.length <= 0) {
|
||||||
|
database.removeCustomIcon(customIcon.uuid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user