private KdbContext EndXmlElement(KdbContext ctx, XmlReader xr)
{
Debug.Assert(xr.NodeType == XmlNodeType.EndElement);
if((ctx == KdbContext.KeePassFile) && (xr.Name == ElemDocNode))
return KdbContext.Null;
else if((ctx == KdbContext.Meta) && (xr.Name == ElemMeta))
return KdbContext.KeePassFile;
else if((ctx == KdbContext.Root) && (xr.Name == ElemRoot))
return KdbContext.KeePassFile;
else if((ctx == KdbContext.MemoryProtection) && (xr.Name == ElemMemoryProt))
return KdbContext.Meta;
else if((ctx == KdbContext.CustomIcons) && (xr.Name == ElemCustomIcons))
return KdbContext.Meta;
else if((ctx == KdbContext.CustomIcon) && (xr.Name == ElemCustomIconItem))
{
if((m_uuidCustomIconID != PwUuid.Zero) && (m_pbCustomIconData != null))
m_pwDatabase.CustomIcons.Add(new PwCustomIcon(
m_uuidCustomIconID, m_pbCustomIconData));
else { Debug.Assert(false); }
m_uuidCustomIconID = PwUuid.Zero;
m_pbCustomIconData = null;
return KdbContext.CustomIcons;
}
else if((ctx == KdbContext.Binaries) && (xr.Name == ElemBinaries))
return KdbContext.Meta;
else if((ctx == KdbContext.CustomData) && (xr.Name == ElemCustomData))
return KdbContext.Meta;
else if((ctx == KdbContext.CustomDataItem) && (xr.Name == ElemStringDictExItem))
{
if((m_strCustomDataKey != null) && (m_strCustomDataValue != null))
m_pwDatabase.CustomData.Set(m_strCustomDataKey, m_strCustomDataValue);
else { Debug.Assert(false); }
m_strCustomDataKey = null;
m_strCustomDataValue = null;
return KdbContext.CustomData;
}
else if((ctx == KdbContext.Group) && (xr.Name == ElemGroup))
{
if(PwUuid.Zero.EqualsValue(m_ctxGroup.Uuid))
m_ctxGroup.Uuid = new PwUuid(true); // No assert (import)
m_ctxGroups.Pop();
if(m_ctxGroups.Count == 0)
{
m_ctxGroup = null;
return KdbContext.Root;
}
else
{
m_ctxGroup = m_ctxGroups.Peek();
return KdbContext.Group;
}
}
else if((ctx == KdbContext.GroupTimes) && (xr.Name == ElemTimes))
return KdbContext.Group;
else if((ctx == KdbContext.Entry) && (xr.Name == ElemEntry))
{
// Create new UUID if absent
if(PwUuid.Zero.EqualsValue(m_ctxEntry.Uuid))
m_ctxEntry.Uuid = new PwUuid(true); // No assert (import)
if(m_bEntryInHistory)
{
m_ctxEntry = m_ctxHistoryBase;
return KdbContext.EntryHistory;
}
return KdbContext.Group;
}
else if((ctx == KdbContext.EntryTimes) && (xr.Name == ElemTimes))
return KdbContext.Entry;
else if((ctx == KdbContext.EntryString) && (xr.Name == ElemString))
{
m_ctxEntry.Strings.Set(m_ctxStringName, m_ctxStringValue);
m_ctxStringName = null;
m_ctxStringValue = null;
return KdbContext.Entry;
}
else if((ctx == KdbContext.EntryBinary) && (xr.Name == ElemBinary))
{
if(string.IsNullOrEmpty(m_strDetachBins))
m_ctxEntry.Binaries.Set(m_ctxBinaryName, m_ctxBinaryValue);
else
{
SaveBinary(m_ctxBinaryName, m_ctxBinaryValue, m_strDetachBins);
m_ctxBinaryValue = null;
GC.Collect();
}
m_ctxBinaryName = null;
m_ctxBinaryValue = null;
return KdbContext.Entry;
}
else if((ctx == KdbContext.EntryAutoType) && (xr.Name == ElemAutoType))
return KdbContext.Entry;
else if((ctx == KdbContext.EntryAutoTypeItem) && (xr.Name == ElemAutoTypeItem))
{
AutoTypeAssociation atAssoc = new AutoTypeAssociation(m_ctxATName,
m_ctxATSeq);
m_ctxEntry.AutoType.Add(atAssoc);
m_ctxATName = null;
m_ctxATSeq = null;
return KdbContext.EntryAutoType;
}
else if((ctx == KdbContext.EntryHistory) && (xr.Name == ElemHistory))
{
m_bEntryInHistory = false;
return KdbContext.Entry;
}
else if((ctx == KdbContext.RootDeletedObjects) && (xr.Name == ElemDeletedObjects))
return KdbContext.Root;
else if((ctx == KdbContext.DeletedObject) && (xr.Name == ElemDeletedObject))
{
m_ctxDeletedObject = null;
return KdbContext.RootDeletedObjects;
}
else
{
Debug.Assert(false);
throw new FormatException();
}
}