Ejemplo n.º 1
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();
                 // Iterate through each chapter using the chapter and volume filters.
                 foreach (IChapter Chapter in Series.Children.Filter(Options)) {
                     // Initialize the file path.
                     string FilePath = Path.Combine(Title, 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()));
                     // 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();
                                 }
                             }
                         }
                     } else 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 whether repairing has failed.
                             bool HasFailed = 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 repairing has failed.
                                     HasFailed = Publisher.HasFailed = Repair.HasFailed;
                                 }
                             }
                             // Check if there are no broken pages.
                             if (!HasBrokenPages) {
                                 // Delete the error file.
                                 File.Delete(string.Format("{0}.txt", FilePath));
                             }
                             // Check if repairing has failed.
                             if (HasFailed) {
                                 // Run in single processing mode for the unique identifier.
                                 Single(Options, UniqueIdentifier);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Run in single processing mode for the location.
 /// </summary>
 /// <param name="location">The location.</param>
 /// <param name="options">The collection of options.</param>
 public static void Single(string location, Options options) {
     var provider = Providers.FirstOrDefault(x => x.Open(location) != null);
     if (provider == null) return;
     using (var series = provider.Open(location)) {
         using (series.Populate()) {
             var seriesTitle = series.Title.InvalidatePath();
             var persistencePath = Path.Combine(seriesTitle, ".mangarack-persist");
             var persistence = new List<List<string>>();
             if (File.Exists(persistencePath)) {
                 const int persistenceVersion = 2;
                 foreach (var pieces in File.ReadAllLines(persistencePath).Select(line => new List<string>(line.Split('\0')))) {
                     while (pieces.Count < persistenceVersion) pieces.Add(string.Empty);
                     persistence.Add(pieces);
                 }
             }
             foreach (var chapter in series.Children) {
                 var line = persistence.FirstOrDefault(x => string.Equals(x[1], chapter.UniqueIdentifier));
                 if (line == null) continue;
                 var currentFilePath = Path.Combine(seriesTitle, line[0]);
                 var nextFileName = chapter.ToFileName(seriesTitle, options);
                 if (!string.Equals(line[0], nextFileName) && File.Exists(currentFilePath)) {
                     File.Move(currentFilePath, Path.Combine(seriesTitle, nextFileName));
                     line[0] = nextFileName;
                     Persist(persistencePath, persistence);
                     Console.WriteLine("Switched {0}", nextFileName);
                 }
             }
             foreach (var chapter in series.Children.Filter(options)) {
                 var hasFailed = false;
                 var fileName = chapter.ToFileName(seriesTitle, options);
                 var filePath = Path.Combine(seriesTitle, fileName);
                 var persistenceFile = persistence.FirstOrDefault(x => string.Equals(x[0], fileName));
                 if (options.EnablePersistentSynchronization && persistenceFile != null) {
                     continue;
                 }
                 if (persistenceFile != null) {
                     persistenceFile[1] = chapter.UniqueIdentifier ?? string.Empty;
                 } else {
                     persistence.Add(new List<string> {fileName, chapter.UniqueIdentifier ?? string.Empty});
                 }
                 do {
                     if (options.DisableDuplicationPrevention || !File.Exists(filePath)) {
                         using (chapter.Populate()) {
                             using (var publisher = new Publisher(filePath, options, provider)) {
                                 using (var synchronizer = new Synchronize(publisher, series, chapter)) {
                                     synchronizer.Populate();
                                     hasFailed = false;
                                 }
                             }
                         }
                     } else {
                         if (options.EnableOverwriteMetaInformation) {
                             var comicInfo = new ComicInfo();
                             using (var zipFile = new ZipFile(filePath)) {
                                 var zipEntry = zipFile.GetEntry("ComicInfo.xml");
                                 if (zipEntry != null) {
                                     var previousComicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry));
                                     comicInfo.Transcribe(series, chapter, previousComicInfo.Pages);
                                     if (comicInfo.Genre.Any(x => !previousComicInfo.Genre.Contains(x)) ||
                                         previousComicInfo.Genre.Any(x => !comicInfo.Genre.Contains(x)) ||
                                         comicInfo.Manga != previousComicInfo.Manga ||
                                         comicInfo.Number != previousComicInfo.Number ||
                                         comicInfo.PageCount != previousComicInfo.PageCount ||
                                         comicInfo.Penciller.Any(x => !previousComicInfo.Penciller.Contains(x)) ||
                                         previousComicInfo.Penciller.Any(x => !comicInfo.Penciller.Contains(x)) ||
                                         comicInfo.Series != previousComicInfo.Series ||
                                         comicInfo.Summary != previousComicInfo.Summary ||
                                         comicInfo.Title != previousComicInfo.Title ||
                                         comicInfo.Volume != previousComicInfo.Volume ||
                                         comicInfo.Writer.Any(x => !previousComicInfo.Writer.Contains(x)) ||
                                         previousComicInfo.Writer.Any(x => !comicInfo.Writer.Contains(x))) {
                                         using (var memoryStream = new MemoryStream()) {
                                             comicInfo.Save(memoryStream);
                                             memoryStream.Position = 0;
                                             zipFile.BeginUpdate();
                                             zipFile.Add(new DataSource(memoryStream), "ComicInfo.xml");
                                             zipFile.CommitUpdate();
                                             Console.WriteLine("Modified {0}", fileName);
                                         }
                                     }
                                 }
                             }
                         }
                         if (!options.DisableRepairAndErrorTracking && File.Exists(string.Format("{0}.txt", filePath))) {
                             using (chapter.Populate()) {
                                 ComicInfo comicInfo;
                                 var hasBrokenPages = false;
                                 using (var zipFile = new ZipFile(filePath)) {
                                     var zipEntry = zipFile.GetEntry("ComicInfo.xml");
                                     if (zipEntry == null) {
                                         return;
                                     }
                                     comicInfo = ComicInfo.Load(zipFile.GetInputStream(zipEntry));
                                 }
                                 using (var publisher = new Publisher(filePath, options, provider, true)) {
                                     using (var repair = new Repair(publisher, chapter, comicInfo, File.ReadAllLines(string.Format("{0}.txt", filePath)))) {
                                         repair.Populate();
                                         hasBrokenPages = publisher.HasBrokenPages;
                                         hasFailed = publisher.HasFailed = repair.HasFailed;
                                     }
                                 }
                                 if (!hasBrokenPages && File.Exists(string.Format("{0}.txt", filePath))) {
                                     File.Delete(string.Format("{0}.txt", filePath));
                                 }
                             }
                         }
                     }
                 } while (hasFailed);
                 Persist(persistencePath, persistence);
             }
         }
     }
 }
Ejemplo n.º 3
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());
                     }
                 }
             }
         }
     }
 }