/// <summary> /// reread available comics /// </summary> private void lstViewAvailableComics_Refresh() { //reset cache comic books and clear items comicBooks = null; lstViewAvailableComics.Items.Clear(); //update the comic book archives into the view //cache each into comic book records List <Business_Logic.ComicBook> cbList = new List <Business_Logic.ComicBook>(); foreach (var file in Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Resources", "comicbooks"))) { lstViewAvailableComics.Items.Add(Path.GetFileName(file)); string cbFullPath = ""; Business_Logic.ComicBook cb; try { //get full path of comic book archive cbFullPath = Path.GetFullPath(Path.Combine(@"Resources", @"comicbooks", Path.GetFileName(file))); //get comicbook instance cb = comicReader.GetComicBook(cbFullPath); if (cb == null) { throw new InvalidOperationException("Comic book records is empty."); } } catch (InvalidOperationException exc) { Trace.WriteLine("Exception thrown: " + exc.Message); Trace.WriteLine("Comic book selected with archive path: <" + cbFullPath + "> does not exist in the comic book records. Initialized the comic book."); comicReader.InitializeNewComicBook(cbFullPath); cb = comicReader.GetComicBook(cbFullPath); } //add comic book to list cbList.Add(cb); } comicBooks = cbList.ToArray(); }
/// <summary> /// imports a new comic book based on the path to the cbz/cbr comic archive to the application /// </summary> /// <param name="archivePath"> /// path with complete filename to the cbz/cbr comic archive /// </param> /// <returns> /// true if successful, false if invalid archivePath /// </returns> public bool ImportComicBook(string archivePath) { if (File.Exists(archivePath) && ComicArchiveChecker.IsComicArchiveExtension(Path.GetExtension(archivePath))) { //create comic book resource directory if it hasn't been yet string resourceDirectory = Path.Combine(Directory.GetCurrentDirectory(), cbResourceDirectory); Directory.CreateDirectory(resourceDirectory); //copy archive to comic book resource directory string copyCbPath = Path.Combine(resourceDirectory, Path.GetFileName(archivePath)); if (!File.Exists(copyCbPath)) { File.Copy(archivePath, copyCbPath); } comicManager.InitializeNewComicBook(archivePath); return(true); } else { return(false); } }