Exemple #1
0
        /// <summary>
        /// Delete all books with specific file path from the library
        /// </summary>
        /// <param name="pathName"></param>
        public bool Delete(string fileName)
        {
            bool result = false;

            lock (_books)
            {
                if (!string.IsNullOrEmpty(fileName) && fileName.Length > LibraryFactory.GetLibrary().LibraryPath.Length + 1)
                {
                    // Extract relative file name
                    fileName = fileName.Substring(LibraryFactory.GetLibrary().LibraryPath.Length + 1);
                    string ext = Path.GetExtension(fileName.ToLower());

                    // Assume it's a single file
                    if (ext.Equals(".epub") || ext.Equals(".fb2") || (ext.Equals(".zip") && fileName.ToLower().Contains(".fb2.zip")))
                    {
                        if (Contains(fileName))
                        {
                            Book book = _books[_paths[fileName]];
                            if (book != null)
                            {
                                _books.Remove(book.ID);
                                _paths.Remove(book.FileName);
                                if (book.BookType == BookType.FB2)
                                {
                                    FB2Count--;
                                }
                                else
                                {
                                    EPUBCount--;
                                }
                                result = IsChanged = true;
                            }
                        }
                    }
                    // removed object should be archive or directory: let's remove all books with that path or zip
                    else
                    {
                        List <Book> booksForRemove = _books.Where(b => b.Value.FileName.Contains(fileName)).Select(b => b.Value).ToList();
                        foreach (Book book in booksForRemove)
                        {
                            _books.Remove(book.ID);
                            _paths.Remove(book.FileName);
                            if (book.BookType == BookType.FB2)
                            {
                                FB2Count--;
                            }
                            else
                            {
                                EPUBCount--;
                            }
                        }
                        if (booksForRemove.Count > 0)
                        {
                            result = IsChanged = true;
                        }
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        public Book(string fileName = "")
        {
            Version  = 1;
            FileName = fileName;
            var lib = LibraryFactory.GetLibrary();

            if (!string.IsNullOrEmpty(FileName) && FileName.IndexOf(lib.LibraryPath) == 0)
            {
                FileName = FileName.Substring(lib.LibraryPath.Length + 1);
            }
            Title            = Sequence = Annotation = Language = string.Empty;
            HasCover         = false;
            BookDate         = DocumentDate = DateTime.MinValue;
            NumberInSequence = 0;
            Authors          = new List <string>();
            Translators      = new List <string>();
            Genres           = new List <string>();
        }