Example #1
0
        /// <summary>
        /// Add category to the book
        /// </summary>
        private void Category_OnKeyUp(object sender, KeyEventArgs e)
        {
            var textBox = (TextBox)sender;

            if (textBox.Text.Length <= 1 || (textBox.Text.Substring(textBox.Text.Length - 1) != ";" && textBox.Text.Substring(textBox.Text.Length - 1) != ","))
            {
                return;
            }

            var category = textBox.Text.Substring(0, textBox.Text.Length - 1);

            textBox.Text = String.Empty;

            if (_categoryTagList.Any(categoryTag => categoryTag.Name == category))
            {
                return;
            }

            CategoryTagsBorder.Visibility = Visibility.Visible;
            _categoryTagList.Add(new CategoryTag {
                Name = category
            });

            Db.NonQuery("INSERT OR IGNORE INTO categories VALUES(@Path, @Name, 0)", new []
            {
                new SQLiteParameter("Path", BookKeeper.GetRelativeBookFilePath(_bookFile)),
                new SQLiteParameter("Name", category)
            });
        }
Example #2
0
        /// <summary>
        /// Go through all database records along with all book files in the library root folder and remove any database entries which point to non-existing files,
        /// then attempt to generate database entries for all book files, which don't have them.
        /// </summary>
        public static void SyncDbWithFileTree()
        {
            MainWindow.Busy(true);

            Task.Factory.StartNew(() =>
            {
                GenerateFileTree();
                Tools.RemoveEmptyDirectories(Properties.Settings.Default.BooksDir);
                var fileTree           = GetFileTree();
                const string sql       = "SELECT Path FROM books";
                const string sqlDelete = "DELETE FROM books WHERE Path = @Path";
                var query    = Db.Query(sql);
                var pathList = new List <string>();

                MainWindow.Busy(UiLang.Get("BusyCleaningDb"));

                //Delete rows pointing to non-existing files
                while (query.Read())
                {
                    if (File.Exists(BookKeeper.GetAbsoluteBookFilePath(query["Path"].ToString())))
                    {
                        pathList.Add(query["Path"].ToString());
                    }
                    else
                    {
                        Db.NonQuery(sqlDelete, new[] { new SQLiteParameter("Path", query["Path"].ToString()) });
                    }
                }

                MainWindow.BusyMax(fileTree.Count(bookFile => !pathList.Contains(BookKeeper.GetRelativeBookFilePath(bookFile))));

                var i = 0;

                //Generate rows for any books missing them
                foreach (
                    var bookFile in
                    fileTree.Where(bookFile => !pathList.Contains(BookKeeper.GetRelativeBookFilePath(bookFile))))
                {
                    MainWindow.Busy(BookKeeper.GetRelativeBookFilePath(bookFile));
                    MainWindow.Busy(i++);

                    try
                    {
                        BookKeeper.GetData(bookFile);
                    }
                    catch (Exception e)
                    {
                        DebugConsole.WriteLine(
                            "Library structure: I found a book file without any entry in the database (" + bookFile +
                            "), but an error occurred during attempted adding: " + e);
                    }
                }

                MainWindow.MW.Dispatcher.Invoke(() => MainWindow.MW.BookGridReload());

                MainWindow.Busy(false);
            });
        }
Example #3
0
        /// <summary>
        /// Remove category from the book
        /// </summary>
        private void CategoryTag_OnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var categoryTag = (CategoryTag)(((Button)sender).DataContext);

            _categoryTagList.Remove(categoryTag);

            if (_categoryTagList.Count == 0)
            {
                CategoryTagsBorder.Visibility = Visibility.Collapsed;
            }

            Db.NonQuery("DELETE FROM categories WHERE Name = @Name AND Path = @Path", new []
            {
                new SQLiteParameter("Name", categoryTag.Name),
                new SQLiteParameter("Path", BookKeeper.GetRelativeBookFilePath(_bookFile))
            });
        }
Example #4
0
        /// <summary>
        /// Mark automatically added category as user added category
        /// </summary>
        private void CategoryTag_OnPreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            var categoryTag = (CategoryTag)(((Button)sender).DataContext);

            if (_categoryTagList.Count == 0)
            {
                CategoryTagsBorder.Visibility = Visibility.Collapsed;
            }

            Db.NonQuery("UPDATE categories SET FromFile = 0 WHERE Name = @Name AND Path = @Path", new[]
            {
                new SQLiteParameter("Name", categoryTag.Name),
                new SQLiteParameter("Path", BookKeeper.GetRelativeBookFilePath(_bookFile))
            });

            categoryTag.FromFile         = false;
            ((Button)sender).BorderBrush = Brushes.DarkRed;
        }
Example #5
0
        private void Category_OnLoaded(object sender, RoutedEventArgs e)
        {
            var query = Db.Query("SELECT Name, FromFile FROM categories WHERE Path = @Path", new [] { new SQLiteParameter("Path", BookKeeper.GetRelativeBookFilePath(_bookFile)) });

            while (query.Read())
            {
                var category = new CategoryTag
                {
                    Name     = query["Name"].ToString(),
                    FromFile = SQLiteConvert.ToBoolean(query["FromFile"])
                };

                _categoryTagList.Add(category);
            }

            if (_categoryTagList.Count > 0)
            {
                CategoryTagsBorder.Visibility = Visibility.Visible;
            }

            Categories.ItemsSource = _categoryTagList;

            var defaultCategories = Properties.Settings.Default.DefaultCategories.Split(';');
            var hintList          = new List <string>(defaultCategories);

            hintList.AddRange(LibraryStructure.CategoryList());
            hintList.Sort();

            new Whisperer
            {
                TextBox  = (TextBox)sender,
                HintList = hintList
            };
        }