コード例 #1
0
ファイル: EditBook.xaml.cs プロジェクト: YangHaoxin/Bookpouch
        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
            };
        }
コード例 #2
0
        /// <summary>
        /// Remove a book from the library
        /// </summary>
        /// <param name="bookFile">Path to the folder which contains the book files</param>
        public static void Discard(string bookFile) //Permanently remove a book from the library
        {
            if (!File.Exists(bookFile))
            {
                return;
            }

            const string sqlDeleteBook       = "DELETE FROM books WHERE Path = @Path";
            const string sqlDeleteCategories = "DELETE FROM categories WHERE Path = @Path";

            var bookFileRelativePath = GetRelativeBookFilePath(bookFile);

            try
            {
                File.Delete(bookFile);

                Db.NonQuery(sqlDeleteBook, new[] { new SQLiteParameter("Path", bookFileRelativePath) });
                Db.NonQuery(sqlDeleteCategories, new[] { new SQLiteParameter("Path", bookFileRelativePath) });

                LibraryStructure.GenerateFileTree();
                MainWindow.MW.BookGridReload();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                MainWindow.Info(String.Format(UiLang.Get("DiscardingBookFailed"), bookFile));
                DebugConsole.WriteLine("Book keeper: I was unable to delete " + bookFile + ": " + e);
            }
        }
コード例 #3
0
        private void Category_OnLoaded(object sender, RoutedEventArgs e)
        {
            var hintList = LibraryStructure.CategoryList();

            hintList.Sort();

            new Whisperer
            {
                TextBox  = (TextBox)sender,
                HintList = hintList
            };
        }
コード例 #4
0
        private static void AddBooksFromList(IEnumerable <string> list)
        {
            Busy(true);

            Task.Factory.StartNew(() =>
            {
                foreach (var file in list)
                {
                    BookKeeper.Add(file);
                }

                MW.Dispatcher.Invoke(() =>
                {
                    LibraryStructure.GenerateFileTree();
                    MW.BookGridReload();
                });

                Busy(false);
            });
        }
コード例 #5
0
 private void DataStructureSync_OnClick(object sender, RoutedEventArgs e)
 {
     Info(UiLang.Get("SyncingDataStructure"));
     LibraryStructure.SyncDbWithFileTree();
 }
コード例 #6
0
ファイル: UsbSync.cs プロジェクト: YangHaoxin/Bookpouch
        /// <summary>
        /// Take all books files marked for sync and copy them onto the reader device, if one is found.
        /// If any book files are found on the reader device, which are not marked for sync in the local library, they will be deleted from the device.
        /// </summary>
        private static void SyncBookFiles()
        {
            var localBookList        = LibraryStructure.List();
            var localBookListForSync = (from bookData in localBookList where bookData.Sync select BookKeeper.GetAbsoluteBookFilePath(bookData.Path)).ToList();
            var bookList             = GetFileList();

            if (bookList == null) //The reader is not connected, or the specified storage folder on it doesn't exist, no point to continue
            {
                MainWindow.Busy(false);
                return;
            }

            var filesToDelete = (from file in bookList
                                 let fileName = Path.GetFileName(file)
                                                where !localBookListForSync.Select(Path.GetFileName).Contains(fileName)
                                                select file).ToArray();

            var filesToCopy = localBookListForSync.Where(
                file => File.Exists(file) && !bookList.Select(Path.GetFileName).Contains(Path.GetFileName(file))).ToArray();

            MainWindow.BusyMax(filesToDelete.Length + filesToCopy.Length);
            var busyCount = 0;

            foreach (var file in filesToDelete)
            //Delete files from the reader which don't exist in the local Sync list
            {
                MainWindow.Busy(busyCount++);
                MainWindow.Busy(file);

                try
                {
                    File.SetAttributes(file, FileAttributes.Normal);
                    File.Delete(file);
                }
                catch (Exception e)
                {
                    DebugConsole.WriteLine("Usb sync: Failed to delete " + file + ": " + e);
                }
            }

            foreach (var file in filesToCopy)
            //Copy files (which don't exist in the reader) into the reader, from the local Sync list
            {
                DebugConsole.WriteLine("Copying " + file);
                MainWindow.Busy(busyCount++);
                MainWindow.Busy(file);

                try
                {
                    if (file != null)
                    {
                        File.Copy(file, Path.Combine(_deviceDir, Path.GetFileName(file)));
                    }
                }
                catch (Exception e)
                {
                    MainWindow.Info(String.Format(UiLang.Get("SyncFileCopyFailed"), file));
                    DebugConsole.WriteLine("Usb sync: Error while copying " + file + ": " + e);
                }
            }

            MainWindow.Info(UiLang.Get("SyncFinished"));
            MainWindow.Busy(false);
        }