コード例 #1
0
        public static void ReorderEntriesAsInDatabase(PwObjectList <PwEntry> v,
                                                      PwDatabase pd)
        {
            if ((v == null) || (pd == null))
            {
                Debug.Assert(false); return;
            }

            PwObjectList <PwEntry> vRem = v.CloneShallow();

            v.Clear();

            EntryHandler eh = delegate(PwEntry pe)
            {
                int p = vRem.IndexOf(pe);
                if (p >= 0)
                {
                    v.Add(pe);
                    vRem.RemoveAt((uint)p);
                }

                return(true);
            };

            pd.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);

            foreach (PwEntry peRem in vRem)
            {
                v.Add(peRem);                                        // Entries not found
            }
        }
コード例 #2
0
        /// <summary>
        /// Get a list of subgroups (not including this one).
        /// </summary>
        /// <param name="bRecursive">If <c>true</c>, subgroups are added
        /// recursively, i.e. all child groups are returned, too.</param>
        /// <returns>List of subgroups.</returns>
        public PwObjectList <PwGroup> GetGroups(bool bRecursive)
        {
            if (bRecursive == false)
            {
                return(m_listGroups);
            }

            PwObjectList <PwGroup> list = m_listGroups.CloneShallow();

            foreach (PwGroup pgSub in m_listGroups)
            {
                list.Add(pgSub.GetGroups(true));
            }

            return(list);
        }
コード例 #3
0
        public PwObjectList <PwEntry> GetEntries(bool bIncludeSubGroupEntries)
        {
            if (bIncludeSubGroupEntries == false)
            {
                return(m_listEntries);
            }

            PwObjectList <PwEntry> list = m_listEntries.CloneShallow();

            foreach (PwGroup pgSub in m_listGroups)
            {
                list.Add(pgSub.GetEntries(true));
            }

            return(list);
        }
コード例 #4
0
ファイル: EntryUtil.cs プロジェクト: rdealexb/keepass
        public static void ReorderEntriesAsInDatabase(PwObjectList<PwEntry> v,
            PwDatabase pd)
        {
            if((v == null) || (pd == null)) { Debug.Assert(false); return; }
            if(pd.RootGroup == null) { Debug.Assert(false); return; } // DB must be open

            PwObjectList<PwEntry> vRem = v.CloneShallow();
            v.Clear();

            EntryHandler eh = delegate(PwEntry pe)
            {
                int p = vRem.IndexOf(pe);
                if(p >= 0)
                {
                    v.Add(pe);
                    vRem.RemoveAt((uint)p);
                }

                return true;
            };

            pd.RootGroup.TraverseTree(TraversalMethod.PreOrder, null, eh);

            foreach(PwEntry peRem in vRem) v.Add(peRem); // Entries not found
        }
コード例 #5
0
		internal void ReorderObjectList<T>(PwObjectList<T> vItems,
			PwObjectPool ppOrgStructure, PwObjectPool ppSrcStructure, bool bEntries)
			where T : class, IStructureItem, IDeepClonable<T>
		{
			if(!ObjectListRequiresReorder<T>(vItems, ppOrgStructure, ppSrcStructure,
				bEntries)) return;

#if DEBUG
			PwObjectList<T> vOrgListItems = vItems.CloneShallow();
#endif

			Queue<KeyValuePair<uint, uint>> qToDo = new Queue<KeyValuePair<uint, uint>>();
			qToDo.Enqueue(new KeyValuePair<uint, uint>(0, vItems.UCount - 1));

			while(qToDo.Count > 0)
			{
				if((m_slStatus != null) && !m_slStatus.ContinueWork()) break;

				KeyValuePair<uint, uint> kvp = qToDo.Dequeue();
				if(kvp.Value <= kvp.Key) { Debug.Assert(false); continue; }

				Queue<PwUuid> qRelBefore = new Queue<PwUuid>();
				Queue<PwUuid> qRelAfter = new Queue<PwUuid>();
				uint uPivot = FindLocationChangedPivot<T>(vItems, kvp, ppOrgStructure,
					ppSrcStructure, qRelBefore, qRelAfter, bEntries);
				T ptPivot = vItems.GetAt(uPivot);

				List<T> vToSort = vItems.GetRange(kvp.Key, kvp.Value);
				Queue<T> qBefore = new Queue<T>();
				Queue<T> qAfter = new Queue<T>();
				bool bBefore = true;

				foreach(T pt in vToSort)
				{
					if(pt == ptPivot) { bBefore = false; continue; }

					bool bAdded = false;
					foreach(PwUuid puBefore in qRelBefore)
					{
						if(puBefore.EqualsValue(pt.Uuid))
						{
							qBefore.Enqueue(pt);
							bAdded = true;
							break;
						}
					}
					if(bAdded) continue;

					foreach(PwUuid puAfter in qRelAfter)
					{
						if(puAfter.EqualsValue(pt.Uuid))
						{
							qAfter.Enqueue(pt);
							bAdded = true;
							break;
						}
					}
					if(bAdded) continue;

					if(bBefore) qBefore.Enqueue(pt);
					else qAfter.Enqueue(pt);
				}
				Debug.Assert(bBefore == false);

				uint uPos = kvp.Key;
				while(qBefore.Count > 0) vItems.SetAt(uPos++, qBefore.Dequeue());
				vItems.SetAt(uPos++, ptPivot);
				while(qAfter.Count > 0) vItems.SetAt(uPos++, qAfter.Dequeue());
				Debug.Assert(uPos == (kvp.Value + 1));

				int iNewPivot = vItems.IndexOf(ptPivot);
				if((iNewPivot < (int)kvp.Key) || (iNewPivot > (int)kvp.Value))
				{
					Debug.Assert(false);
					continue;
				}

				if((iNewPivot - 1) > (int)kvp.Key)
					qToDo.Enqueue(new KeyValuePair<uint, uint>(kvp.Key,
						(uint)(iNewPivot - 1)));

				if((iNewPivot + 1) < (int)kvp.Value)
					qToDo.Enqueue(new KeyValuePair<uint, uint>((uint)(iNewPivot + 1),
						kvp.Value));
			}

#if DEBUG
			foreach(T ptItem in vOrgListItems)
			{
				Debug.Assert(vItems.IndexOf(ptItem) >= 0);
			}
#endif
		}