mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-21 01:21:34 -08:00
Better index action implementation
This commit is contained in:
1 parent
3dc988dd08
commit
6f736d6415
6 files changed
+40
-25
No files matched your search
@@ -45,8 +45,8 @@ abstract class PwDatabase<Group : PwGroup<*, Group, Entry>, Entry : PwEntry<Grou
|
||||
var iconFactory = PwIconFactory()
|
||||
protected set
|
||||
|
||||
var groupIndexes = LinkedHashMap<PwNodeId<*>, Group>()
|
||||
var entryIndexes = LinkedHashMap<PwNodeId<*>, Entry>()
|
||||
private var groupIndexes = LinkedHashMap<PwNodeId<*>, Group>()
|
||||
private var entryIndexes = LinkedHashMap<PwNodeId<*>, Entry>()
|
||||
|
||||
abstract val version: String
|
||||
|
||||
@@ -201,6 +201,12 @@ abstract class PwDatabase<Group : PwGroup<*, Group, Entry>, Entry : PwEntry<Grou
|
||||
* -------------------------------------
|
||||
*/
|
||||
|
||||
fun doForEachGroupInIndex(action: (Group) -> Unit) {
|
||||
for (group in groupIndexes) {
|
||||
action.invoke(group.value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an id number is already in use
|
||||
*
|
||||
@@ -239,6 +245,12 @@ abstract class PwDatabase<Group : PwGroup<*, Group, Entry>, Entry : PwEntry<Grou
|
||||
return groupIndexes.size
|
||||
}
|
||||
|
||||
fun doForEachEntryInIndex(action: (Entry) -> Unit) {
|
||||
for (entry in entryIndexes) {
|
||||
action.invoke(entry.value)
|
||||
}
|
||||
}
|
||||
|
||||
fun isEntryIdUsed(id: PwNodeId<*>): Boolean {
|
||||
return entryIndexes.containsKey(id)
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ class PwDatabaseV3 : PwDatabase<PwGroupV3, PwEntryV3>() {
|
||||
val rootGroups: List<PwGroupV3>
|
||||
get() {
|
||||
val kids = ArrayList<PwGroupV3>()
|
||||
for ((_, value) in groupIndexes) {
|
||||
if (value.level == 0)
|
||||
kids.add(value)
|
||||
doForEachGroupInIndex { group ->
|
||||
if (group.level == 0)
|
||||
kids.add(group)
|
||||
}
|
||||
return kids
|
||||
}
|
||||
@@ -61,7 +61,6 @@ class PwDatabaseV3 : PwDatabase<PwGroupV3, PwEntryV3>() {
|
||||
override val passwordEncoding: String
|
||||
get() = "ISO-8859-1"
|
||||
|
||||
|
||||
override var numberKeyEncryptionRounds: Long
|
||||
get() = numKeyEncRounds.toLong()
|
||||
@Throws(NumberFormatException::class)
|
||||
|
||||
@@ -80,10 +80,8 @@ class PwDatabaseV4 : PwDatabase<PwGroupV4, PwEntryV4>() {
|
||||
var entryTemplatesGroupChanged = PwDate()
|
||||
var historyMaxItems = DEFAULT_HISTORY_MAX_ITEMS
|
||||
var historyMaxSize = DEFAULT_HISTORY_MAX_SIZE
|
||||
// TODO last selected group as object
|
||||
var lastSelectedGroup = UUID_ZERO
|
||||
// TODO last top visible group as object
|
||||
var lastTopVisibleGroup = UUID_ZERO
|
||||
var lastSelectedGroupUUID = UUID_ZERO
|
||||
var lastTopVisibleGroupUUID = UUID_ZERO
|
||||
var memoryProtection = MemoryProtectionConfig()
|
||||
val deletedObjects = ArrayList<PwDeletedObject>()
|
||||
val customIcons = ArrayList<PwIconCustom>()
|
||||
@@ -150,13 +148,21 @@ class PwDatabaseV4 : PwDatabase<PwGroupV4, PwEntryV4>() {
|
||||
override val passwordEncoding: String
|
||||
get() = "UTF-8"
|
||||
|
||||
fun getGroupByUUID(groupUUID: UUID): PwGroupV4? {
|
||||
if (groupUUID == UUID_ZERO)
|
||||
return null
|
||||
return getGroupById(PwNodeIdUUID(groupUUID))
|
||||
}
|
||||
|
||||
// Retrieve recycle bin in index
|
||||
val recycleBin: PwGroupV4?
|
||||
get() {
|
||||
if (recycleBinUUID == UUID_ZERO)
|
||||
return null
|
||||
return groupIndexes[PwNodeIdUUID(recycleBinUUID)]
|
||||
}
|
||||
get() = getGroupByUUID(recycleBinUUID)
|
||||
|
||||
val lastSelectedGroup: PwGroupV4?
|
||||
get() = getGroupByUUID(lastSelectedGroupUUID)
|
||||
|
||||
val lastTopVisibleGroup: PwGroupV4?
|
||||
get() = getGroupByUUID(lastTopVisibleGroupUUID)
|
||||
|
||||
fun setDataEngine(dataEngine: CipherEngine) {
|
||||
this.dataEngine = dataEngine
|
||||
|
||||
@@ -385,9 +385,9 @@ class ImporterV4(private val streamDir: File) : Importer<PwDatabaseV4>() {
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemHistoryMaxSize, ignoreCase = true)) {
|
||||
mDatabase.historyMaxSize = readLong(xpp, -1)
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemLastSelectedGroup, ignoreCase = true)) {
|
||||
mDatabase.lastSelectedGroup = readUuid(xpp)
|
||||
mDatabase.lastSelectedGroupUUID = readUuid(xpp)
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemLastTopVisibleGroup, ignoreCase = true)) {
|
||||
mDatabase.lastTopVisibleGroup = readUuid(xpp)
|
||||
mDatabase.lastTopVisibleGroupUUID = readUuid(xpp)
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemBinaries, ignoreCase = true)) {
|
||||
return switchContext(ctx, KdbContext.Binaries, xpp)
|
||||
} else if (name.equals(PwDatabaseV4XML.ElemCustomData, ignoreCase = true)) {
|
||||
|
||||
@@ -204,18 +204,16 @@ class PwDbV3Output(private val mDatabaseV3: PwDatabaseV3, os: OutputStream) : Pw
|
||||
}
|
||||
|
||||
// Groups
|
||||
for (group in mDatabaseV3.groupIndexes) {
|
||||
val pgo = PwGroupOutputV3(group as PwGroupV3, os)
|
||||
mDatabaseV3.doForEachGroupInIndex { group ->
|
||||
val pgo = PwGroupOutputV3(group, os)
|
||||
try {
|
||||
pgo.output()
|
||||
} catch (e: IOException) {
|
||||
throw PwDbOutputException("Failed to output a tree", e)
|
||||
}
|
||||
}
|
||||
|
||||
// Entries
|
||||
for (entry in mDatabaseV3.entryIndexes) {
|
||||
val peo = PwEntryOutputV3(entry as PwEntryV3, os)
|
||||
mDatabaseV3.doForEachEntryInIndex { entry ->
|
||||
val peo = PwEntryOutputV3(entry, os)
|
||||
try {
|
||||
peo.output()
|
||||
} catch (e: IOException) {
|
||||
|
||||
@@ -218,8 +218,8 @@ class PwDbV4Output(private val mDatabaseV4: PwDatabaseV4, outputStream: OutputSt
|
||||
writeObject(PwDatabaseV4XML.ElemEntryTemplatesGroupChanged, mDatabaseV4.entryTemplatesGroupChanged.date)
|
||||
writeObject(PwDatabaseV4XML.ElemHistoryMaxItems, mDatabaseV4.historyMaxItems.toLong())
|
||||
writeObject(PwDatabaseV4XML.ElemHistoryMaxSize, mDatabaseV4.historyMaxSize)
|
||||
writeObject(PwDatabaseV4XML.ElemLastSelectedGroup, mDatabaseV4.lastSelectedGroup)
|
||||
writeObject(PwDatabaseV4XML.ElemLastTopVisibleGroup, mDatabaseV4.lastTopVisibleGroup)
|
||||
writeObject(PwDatabaseV4XML.ElemLastSelectedGroup, mDatabaseV4.lastSelectedGroupUUID)
|
||||
writeObject(PwDatabaseV4XML.ElemLastTopVisibleGroup, mDatabaseV4.lastTopVisibleGroupUUID)
|
||||
|
||||
if (header!!.version < PwDbHeaderV4.FILE_VERSION_32_4) {
|
||||
writeBinPool()
|
||||
|
||||
Reference in new issue
Block a user