public ImageDownloadProgress( ImageSourcesConfig imageSource, QualityGroupConfig qualityGroup, ImageDirConfig dir, FileSignature[] imagesOnline) { ImageSource = imageSource; QualityGroup = qualityGroup; Dir = dir; TargetDirectory = QualityGroup.TargetDirectory.ToAppRootedPath(); TargetSubdirectory = Dir.Subdir.Value == null ? TargetDirectory : TargetDirectory.Join(Dir.Subdir); MegaUrl = string.IsNullOrEmpty(Dir.MegaId) ? null : ImageSource.MegaPrefix + Dir.MegaId; var existingSignatures = readExistingSignatures() ?.ToDictionary(_ => _.Path); if (imagesOnline == null) { FilesDownloaded = existingSignatures; return; } FilesOnline = Dir.Subdir.Value == null ? imagesOnline.ToDictionary(_ => _.Path) : imagesOnline.Where(_ => Dir.Subdir.IsParentOf(_.Path)) .Select(_ => new FileSignature { Path = _.Path.RelativeTo(Dir.Subdir).Intern(true), Md5Hash = _.Md5Hash }) .ToDictionary(_ => _.Path); FilesDownloaded = new Dictionary <FsPath, FileSignature>(); FilesCorrupted = new Dictionary <FsPath, FileSignature>(); foreach (var onlineImage in FilesOnline.Values) { var existingSignature = existingSignatures?.TryGet(onlineImage.Path); if (existingSignature == null) { continue; } if (existingSignature.Md5Hash == onlineImage.Md5Hash) { FilesDownloaded.Add(existingSignature.Path, existingSignature); } else { FilesCorrupted.Add(existingSignature.Path, existingSignature); } } }
public ImageDownloadProgress( ImageSourcesConfig imageSource, QualityGroupConfig qualityGroup, ImageDirConfig dir, FileSignature[] imagesOnline) { ImageSource = imageSource; QualityGroup = qualityGroup; Dir = dir; TargetDirectory = QualityGroup.TargetDirectory.ToAppRootedPath(); TargetSubdirectory = TargetDirectory.AddPath(Dir.Subdirectory); MegaUrl = string.IsNullOrEmpty(Dir.MegaId) ? null : ImageSource.MegaPrefix + Dir.MegaId; GdriveUrl = string.IsNullOrEmpty(Dir.GdriveId) ? null: ImageSource.GdrivePrefix + Dir.GdriveId; var existingSignatures = readExistingSignatures() ?.ToDictionary(_ => _.Path, Str.Comparer); if (imagesOnline == null) { FilesDownloaded = existingSignatures; return; } FilesOnline = imagesOnline .Where(_ => _.IsRelativeTo(Dir.Subdirectory)) .Select(_ => _.AsRelativeTo(Dir.Subdirectory)) .ToDictionary(_ => _.Path, Str.Comparer); FilesDownloaded = new Dictionary <string, FileSignature>(Str.Comparer); FilesCorrupted = new Dictionary <string, FileSignature>(Str.Comparer); foreach (var onlineImage in FilesOnline.Values) { var existingSignature = existingSignatures?.TryGet(onlineImage.Path); if (existingSignature == null) { continue; } if (existingSignature.Md5Hash == onlineImage.Md5Hash) { FilesDownloaded.Add(existingSignature.Path, existingSignature); } else { FilesCorrupted.Add(existingSignature.Path, existingSignature); } } }