Пример #1
0
 /// <summary>
 /// Publish comic information.
 /// </summary>
 /// <param name="ComicInfo">The comic information.</param>
 public void Publish(ComicInfo ComicInfo)
 {
     // Check if meta-information is not disabled or check if repairing.
     if (_IsRepairing || !_Options.DisableMetaInformation) {
         // Initialize a new instance of the MemoryStream class.
         using (MemoryStream MemoryStream = new MemoryStream()) {
             // Save the comic information.
             ComicInfo.Save(MemoryStream);
             // Rewind the stream.
             MemoryStream.Position = 0;
             // Begin updating the compressed file.
             _ZipFile.BeginUpdate();
             // Add the file.
             _ZipFile.Add(new DataSource(MemoryStream), "ComicInfo.xml");
             // End updating the compressed file.
             _ZipFile.CommitUpdate();
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Run in single processing mode for the unique identifier.
 /// </summary>
 /// <param name="Options">The collection of options.</param>
 /// <param name="UniqueIdentifier">The unique identifier.</param>
 public static void Single(Options Options, string UniqueIdentifier)
 {
     // Select the provider.
     IProvider Provider = _Providers.FirstOrDefault(x => x.Open(UniqueIdentifier) != null);
     // Check if the provider is valid.
     if (Provider != null) {
         // Initialize the series.
         using (ISeries Series = Provider.Open(UniqueIdentifier)) {
             // Populate the series.
             using (Series.Populate()) {
                 // Initialize the series title.
                 string Title = Series.Title.InvalidatePath();
                 // Initialize the persistence.
                 List<string> Persistence = new List<string>();
                 // Initialize the persistence file path.
                 string PersistencePath = Path.Combine(Title, ".mangarack-persist");
                 // Check if persistent synchronization tracking is enabled and a tracking file is available.
                 if (File.Exists(PersistencePath)) {
                     // Iterate through each line in the persistence file.
                     foreach (string Line in File.ReadAllLines(PersistencePath)) {
                         // Add the line to the persistence file names.
                         Persistence.Add(Line);
                     }
                 }
                 // Iterate through each chapter using the chapter and volume filters.
                 foreach (IChapter Chapter in Series.Children.Filter(Options)) {
                     // Initialize whether sychronization has failed.
                     bool HasFailed = false;
                     // Initialize the file name.
                     string FileName = string.Format(Chapter.Volume == -1 ? "{0} #{2}.{3}" : "{0} V{1} #{2}.{3}", Title, Chapter.Volume.ToString("00"), Chapter.Number.ToString("000.####"), Options.FileExtension.InvalidatePath());
                     // Initialize the file path.
                     string FilePath = Path.Combine(Title, FileName);
                     // Check if persistent synchronization tracking is enabled and the file name is persisted.
                     if (Persistence.Contains(FileName)) {
                         // Continue to the next chapter.
                         continue;
                     } else {
                         // Add the file name to the persistence file names.
                         Persistence.Add(FileName);
                     }
                     // Do the following code.
                     do {
                         // Check if the file should be synchronized.
                         if (Options.DisableDuplicationPrevention || !File.Exists(FilePath)) {
                             // Populate the chapter.
                             using (Chapter.Populate()) {
                                 // Initialize a new instance of the Publisher class.
                                 using (Publisher Publisher = new Publisher(FilePath, Options, Provider)) {
                                     // Initialize a new instance of the Synchronizer class.
                                     using (Synchronize Synchronizer = new Synchronize(Publisher, Series, Chapter)) {
                                         // Populate synchronously.
                                         Synchronizer.Populate();
                                         // Set whether synchronization has failed.
                                         HasFailed = false;
                                     }
                                 }
                             }
                         } else {
                             // Check if a meta-information overwrite should be performed.
                             if (Options.EnableOverwriteMetaInformation) {
                                 // Initialize the comic information.
                                 ComicInfo ComicInfo = new ComicInfo(), PreviousComicInfo = null;
                                 // Initialize a new instance of the ZipFile class.
                                 using (ZipFile ZipFile = new ZipFile(FilePath)) {
                                     // Find the comic information.
                                     ZipEntry ZipEntry = ZipFile.GetEntry("ComicInfo.xml");
                                     // Check if comic information is available.
                                     if (ZipEntry != null) {
                                         // Load the comic information.
                                         PreviousComicInfo = ComicInfo.Load(ZipFile.GetInputStream(ZipEntry));
                                         // Transcribe the series, chapter and pages information.
                                         ComicInfo.Transcribe(Series, Chapter, PreviousComicInfo.Pages);
                                         // Check if a current genre differs ...
                                         if (ComicInfo.Genre.Any(x => !PreviousComicInfo.Genre.Contains(x)) ||
                                             // ... or if a previous genre differs ...
                                             PreviousComicInfo.Genre.Any(x => !ComicInfo.Genre.Contains(x)) ||
                                             // ... or the manga specification differs ...
                                             ComicInfo.Manga != PreviousComicInfo.Manga ||
                                             // ... or the number differs ...
                                             ComicInfo.Number != PreviousComicInfo.Number ||
                                             // ... or if the page count differs ...
                                             ComicInfo.PageCount != PreviousComicInfo.PageCount ||
                                             // ... or if a current penciller difffers ...
                                             ComicInfo.Penciller.Any(x => !PreviousComicInfo.Penciller.Contains(x)) ||
                                             // ... or if a previous penciller difffers ...
                                             PreviousComicInfo.Penciller.Any(x => !ComicInfo.Penciller.Contains(x)) ||
                                             // ... or if the series differs ...
                                             ComicInfo.Series != PreviousComicInfo.Series ||
                                             // ... or if the summary differs ...
                                             ComicInfo.Summary != PreviousComicInfo.Summary ||
                                             // ... or if the title differs ...
                                             ComicInfo.Title != PreviousComicInfo.Title ||
                                             // ... or if the volume differs ...
                                             ComicInfo.Volume != PreviousComicInfo.Volume ||
                                             // ... or if a current writer differs.
                                             ComicInfo.Writer.Any(x => !PreviousComicInfo.Writer.Contains(x)) ||
                                             // ... or if a previous writer differs.
                                             PreviousComicInfo.Writer.Any(x => !ComicInfo.Writer.Contains(x))) {
                                             // Initialize a new instance of the MemoryStream class.
                                             using (MemoryStream MemoryStream = new MemoryStream()) {
                                                 // Save the comic information.
                                                 ComicInfo.Save(MemoryStream);
                                                 // Rewind the stream.
                                                 MemoryStream.Position = 0;
                                                 // Begin updating the compressed file.
                                                 ZipFile.BeginUpdate();
                                                 // Add the file.
                                                 ZipFile.Add(new DataSource(MemoryStream), "ComicInfo.xml");
                                                 // End updating the compressed file.
                                                 ZipFile.CommitUpdate();
                                                 // Write a message.
                                                 Console.WriteLine("Modified {0}", FileName);
                                             }
                                         }
                                     }
                                 }
                             }
                             // Check if a repair should be performed.
                             if (!Options.DisableRepairAndErrorTracking && File.Exists(string.Format("{0}.txt", FilePath))) {
                                 // Populate the chapter.
                                 using (Chapter.Populate()) {
                                     // Initialize the comic information.
                                     ComicInfo ComicInfo = null;
                                     // Initialize whether there are broken pages.
                                     bool HasBrokenPages = false;
                                     // Initialize a new instance of the ZipFile class.
                                     using (ZipFile ZipFile = new ZipFile(FilePath)) {
                                         // Find the comic information.
                                         ZipEntry ZipEntry = ZipFile.GetEntry("ComicInfo.xml");
                                         // Check if comic information is available.
                                         if (ZipEntry == null) {
                                             // Stop the function.
                                             return;
                                         } else {
                                             // Load the comic information.
                                             ComicInfo = ComicInfo.Load(ZipFile.GetInputStream(ZipEntry));
                                         }
                                     }
                                     // Initialize a new instance of the Publisher class.
                                     using (Publisher Publisher = new Publisher(FilePath, Options, Provider, true)) {
                                         // Initialize a new instance of the Repair class.
                                         using (Repair Repair = new Repair(Publisher, Series, Chapter, ComicInfo, File.ReadAllLines(string.Format("{0}.txt", FilePath)))) {
                                             // Populate synchronously.
                                             Repair.Populate();
                                             // Set whether there are broken pages.
                                             HasBrokenPages = Publisher.HasBrokenPages;
                                             // Set whether synchronization has failed.
                                             HasFailed = Publisher.HasFailed = Repair.HasFailed;
                                         }
                                     }
                                     // Check if there are no broken pages.
                                     if (!HasBrokenPages && File.Exists(string.Format("{0}.txt", FilePath))) {
                                         // Delete the error file.
                                         File.Delete(string.Format("{0}.txt", FilePath));
                                     }
                                 }
                             }
                         }
                     } while (HasFailed);
                     // Check if persistent synchronization tracking is enabled.
                     if (Options.EnablePersistentSynchronization) {
                         // Write each line to the persistence file path.
                         File.WriteAllLines(PersistencePath, Persistence.ToArray());
                     }
                 }
             }
         }
     }
 }