Пример #1
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             if (zipArchive != null)
             {
                 zipArchive.Dispose();
             }
             if (rarArchive != null)
             {
                 rarArchive.Dispose();
             }
             if (gZipArchive != null)
             {
                 gZipArchive.Dispose();
             }
             if (sevenZipArchive != null)
             {
                 sevenZipArchive.Dispose();
             }
             streamReader.Dispose();
         }
         disposed = true;
     }
 }
        private bool ExtractArchive(RarArchive archive, string destinationDirectory)
        {
            var timer       = Stopwatch.StartNew();
            var archiveName = Path.GetFileName(Path.GetDirectoryName(destinationDirectory));

            logger.LogInformation("sharpcompress ARCHIVE.EXTRACTION.STARTED [" + archiveName + "]");

            try
            {
                archive.Entries.Where(entry => !entry.IsDirectory).ToList().ForEach(
                    entry =>
                {
                    var t = Stopwatch.StartNew();
                    logger.LogInformation("sharpcompress DECOMPRESSING [" + entry.Key + "]");
                    entry.WriteToDirectory(
                        destinationDirectory,
                        new ExtractionOptions {
                        ExtractFullPath = true, Overwrite = true
                    });
                    t.Stop();
                    logger.LogInformation(
                        "sharpcompress DECOMPRESSED [" + entry.Key + "] in "
                        + TimeSpan.FromMilliseconds(t.ElapsedMilliseconds).TotalSeconds + "s");
                });
            }
            catch (Exception e)
            {
                logger.LogError("sharpcompress ARCHIVE.EXTRACTION.FAILED [" + archiveName + "]");
                logger.LogError(e.Message);
                return(false);
            }
            finally
            {
                archive.Dispose();
            }

            timer.Stop();
            logger.LogInformation("sharpcompress ARCHIVE.EXTRACTION.SUCCEEDED [" + archiveName + $"] {TimeSpan.FromMilliseconds(timer.ElapsedMilliseconds).TotalSeconds}s");
            new DirectoryInfo(destinationDirectory).GetFiles("*.rar").ToList().ForEach(f => f.Delete());
            return(true);
        }
Пример #3
0
        private IEnumerable <Page> ExtractPageInCBR(String filepath)
        {
            RarArchive rarArchive = RarArchive.Open(filepath);

            try
            {
                List <Page> result = new List <Page>();

                foreach (var entry in rarArchive.Entries.Where(entry => !entry.IsDirectory))
                {
                    entry.WriteToDirectory(Path.GetDirectoryName(filepath), new ExtractionOptions()
                    {
                        Overwrite = true
                    });
                }
                Messenger.Default.Send(new ExtractFileNotificationMessage($"Extraction dans {filepath}", null));
                var files = Directory.GetFiles(Path.GetDirectoryName(filepath)).ToList();
                int ind   = 1;
                foreach (string file in files)
                {
                    if (Path.GetExtension(file) == ".jpg"
                        ||
                        Path.GetExtension(file) == ".jpeg"
                        ||
                        Path.GetExtension(file) == ".png")
                    {
                        Page page = new Page();
                        page.Ordre   = ind++;
                        page.Element = ResizeFileImage(file, ind);
                        yield return(page);
                    }
                }
            }
            finally
            {
                rarArchive.Dispose();
            }
        }