Exemplo n.º 1
0
 private void ReloadImages()
 {
     _images =
         SupportedExtensions.GetFilesWithExtensions(_directoryInfo, SupportedExtensions.GetImages()).ToList();
     if (!_images.Any())
     {
         throw new ArgumentException(
                   $"Directory ({_directoryInfo.Name}) should contain at least one supported image file.");
     }
 }
Exemplo n.º 2
0
        private void LazyExtract()
        {
            var archive = ArchiveFactory.Open(_archiveFileInfo.FullName);

            var currentFolder = new DirectoryInfo(Directory.GetCurrentDirectory());
            var tempDir       = currentFolder.GetDirectories().FirstOrDefault(x => x.Name == TempArchivePath);
            var tempDirInfo   = tempDir ?? currentFolder.CreateSubdirectory(TempArchivePath);

            var archiveTempDir     = tempDirInfo.GetDirectories().FirstOrDefault(x => x.Name == Name);
            var archiveTempDirInfo = archiveTempDir ?? tempDirInfo.CreateSubdirectory(Name);

            foreach (var file in archiveTempDirInfo.GetFiles())
            {
                file.Delete();
            }

            foreach (var entry in archive.Entries)
            {
                if (entry.IsDirectory)
                {
                    continue;
                }

                entry.WriteToDirectory(archiveTempDirInfo.FullName,
                                       new ExtractionOptions {
                    ExtractFullPath = true, Overwrite = true
                });
            }

            _images =
                SupportedExtensions.GetFilesWithExtensions(archiveTempDirInfo, SupportedExtensions.GetImages(), SearchOption.AllDirectories)
                .ToList();

            if (!_images.Any())
            {
                throw new Exception($"Archive {_archiveFileInfo.FullName} doesn't contain any supported images.");
            }
        }