public Database(Group root, IDictionary<string, ImageSource> customIcons) { if (root == null) throw new ArgumentNullException("root"); if (customIcons == null) throw new ArgumentNullException("customIcons"); _root = root; _customIcons = customIcons; Configuration = new DatabaseConfiguration(); _groups = new Dictionary<string, Group>(); _entries = new Dictionary<string, Entry>(); Index(root); }
public Database(Group root, IDictionary<string, ImageSource> customIcons) { if (root == null) throw new ArgumentNullException("root"); if (customIcons == null) throw new ArgumentNullException("customIcons"); _root = root; // RecycleBin = _root.Entries.FirstOrDefault(p=>p.Group.Icon == 43) _customIcons = customIcons; Configuration = new DatabaseConfiguration(); _groups = new Dictionary<string, Group>(); _entries = new Dictionary<string, Entry>(); Index(root); }
public Database Parse() { var settings = new XmlReaderSettings { CloseInput = false, IgnoreComments = true, IgnoreWhitespace = true, IgnoreProcessingInstructions = true, }; using (var reader = XmlReader.Create(_stream, settings)) { if (!reader.ReadToFollowing("KeePassFile")) return null; if (!reader.ReadToDescendant("Meta")) return null; string recycleBinId = null; var recyleBinEnabled = false; var config = new DatabaseConfiguration(); var icons = new Dictionary<string, ImageSource>(); using (var subReader = reader.ReadSubtree()) { subReader.ReadToFollowing("Generator"); string oldRoot = subReader.Name; while (!string.IsNullOrEmpty(subReader.Name)) { if (oldRoot == subReader.Name) subReader.Skip(); oldRoot = subReader.Name; switch (subReader.Name) { case "DefaultUserName": config.DefaultUserName = subReader .ReadElementContentAsString(); break; case "MemoryProtection": using (var configReader = subReader.ReadSubtree()) ParseProtection(configReader, config); break; case "CustomIcons": using (var iconsReader = subReader.ReadSubtree()) ParseIcons(iconsReader, _dispatcher, icons); break; case "RecycleBinEnabled": var value = subReader .ReadElementContentAsString(); recyleBinEnabled = value == "True"; break; case "RecycleBinUUID": recycleBinId = subReader .ReadElementContentAsString(); break; default: #if DEBUG Debug.WriteLine(subReader.Name); #endif break; } } } if (reader.Name != "Root" && !reader.ReadToNextSibling("Root")) { return null; } if (!reader.ReadToDescendant("Group")) return null; using (var subReader = reader.ReadSubtree()) { var root = ParseGroup(subReader); var database = new Database(root, icons) { Configuration = config, RecycleBinEnabled = recyleBinEnabled, }; if (!string.IsNullOrEmpty(recycleBinId)) { database.RecycleBin = database .GetGroup(recycleBinId); } return database; } } }
private static void ParseProtection(XmlReader reader, DatabaseConfiguration config) { if (reader.Name != "MemoryProtection") reader.Read(); reader.Read(); while (reader.NodeType != XmlNodeType.EndElement) { switch (reader.Name) { case "ProtectTitle": config.ProtectTitle = reader .ReadElementContentAsString() == "True"; break; case "ProtectUserName": config.ProtectUserName = reader .ReadElementContentAsString() == "True"; break; case "ProtectPassword": config.ProtectPassword = reader .ReadElementContentAsString() == "True"; break; default: reader.Skip(); break; } } }