Example #1
0
        protected override void OnNavigatedTo(
            bool cancelled, NavigationEventArgs e)
        {
            if (cancelled)
                return;

            _database = Cache.Database;
            if (_database == null)
            {
                this.BackToDBs();
                return;
            }

            string id;
            var queries = NavigationContext.QueryString;

            if (queries.TryGetValue("entry", out id))
                _entry = _database.GetEntry(id);
            else
            {
                id = queries["group"];
                _group = _database.GetGroup(id);
            }

            _target = _database.Root;
            Refresh();
        }
Example #2
0
        public static void CacheDb(DatabaseInfo info,
            string name, Database database)
        {
            _info = info;
            _standards.Clear();
            Database = database;

            _appSettings[KEY_DATABASE] = name;
            _appSettings.Save();
        }
Example #3
0
        private void ListHistory(Database database)
        {
            var dispatcher = Dispatcher;

            var recents = Cache.GetRecents()
                .Select(database.GetEntry)
                .Where(x => x != null)
                .Select(x => new GroupItem(x, dispatcher))
                .ToList();

            lstHistory.SetItems(recents);
        }
Example #4
0
        private Group GetGroup(Database database)
        {
            string groupId;
            var queries = NavigationContext.QueryString;

            if (queries.TryGetValue("id", out groupId))
                return database.GetGroup(groupId);

            //_cmdHome.IsEnabled = false;
            return database.Root;
        }
Example #5
0
        private void txtSearch_TextChanged(
            object sender, TextChangedEventArgs e)
        {
            if (_database == null)
            {
                _database = Cache.Database;

                if (_database == null)
                {
                    this.BackToDBs();
                    return;
                }
            }

            PerformSearch();
            _cmdSearch.IsEnabled = txtSearch.Text.Length > 0;
        }
Example #6
0
        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;
                }
            }
        }