/// <summary>
        /// Extract to specific directory, retaining filename
        /// </summary>
        public static void WriteToDirectory(this RarArchiveEntry entry, string destinationDirectory, CancellationToken cancellation,
                                            IRarExtractionListener listener,
                                            ExtractOptions options = ExtractOptions.Overwrite)
        {
            string destinationFileName = string.Empty;
            string file = Path.GetFileName(entry.FilePath);


            if (options.HasFlag(ExtractOptions.ExtractFullPath))
            {
                string folder = Path.GetDirectoryName(entry.FilePath);
                destinationDirectory = Path.Combine(destinationDirectory, folder);
                destinationFileName  = Path.Combine(destinationDirectory, file);
            }
            else
            {
                destinationFileName = Path.Combine(destinationDirectory, file);
            }
            if (!Directory.Exists(destinationDirectory))
            {
                Directory.CreateDirectory(destinationDirectory);
            }

            entry.WriteToFile(destinationFileName, cancellation, listener, options);
        }
Beispiel #2
0
 /// <summary>
 /// Constructor with a FileInfo object to an existing file.
 /// </summary>
 /// <param name="fileInfo"></param>
 /// <param name="options"></param>
 internal RarArchive(FileInfo fileInfo, RarOptions options)
 {
     if (!fileInfo.Exists)
     {
         throw new ArgumentException("File does not exist: " + fileInfo.FullName);
     }
     lazyVolumes = new LazyReadOnlyCollection <RarArchiveVolume>(RarArchiveVolumeFactory.GetParts(fileInfo, options));
     lazyEntries = new LazyReadOnlyCollection <RarArchiveEntry>(RarArchiveEntry.GetEntries(this, Volumes));
 }
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this RarArchiveEntry entry, string destinationFileName, CancellationToken cancellation,
                                       IRarExtractionListener listener,
                                       ExtractOptions options = ExtractOptions.Overwrite)
        {
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs, cancellation, listener);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Takes multiple seekable Streams for a multi-part archive
 /// </summary>
 /// <param name="streams"></param>
 /// <param name="options"></param>
 internal RarArchive(IEnumerable <Stream> streams, RarOptions options)
 {
     lazyVolumes = new LazyReadOnlyCollection <RarArchiveVolume>(RarArchiveVolumeFactory.GetParts(streams, options));
     lazyEntries = new LazyReadOnlyCollection <RarArchiveEntry>(RarArchiveEntry.GetEntries(this, Volumes));
 }
 public static void WriteTo(this RarArchiveEntry entry, Stream stream, CancellationToken cancellation)
 {
     entry.WriteTo(stream, cancellation, new NullRarExtractionListener());
 }
 /// <summary>
 /// Extract to specific file
 /// </summary>
 public static void WriteToFile(this RarArchiveEntry entry, string destinationFileName, CancellationToken cancellation,
                                ExtractOptions options = ExtractOptions.Overwrite)
 {
     entry.WriteToFile(destinationFileName, cancellation, new NullRarExtractionListener(), options);
 }
 /// <summary>
 /// Extract to specific directory, retaining filename
 /// </summary>
 public static void WriteToDirectory(this RarArchiveEntry entry, string destinationPath, CancellationToken cancellation,
                                     ExtractOptions options = ExtractOptions.Overwrite)
 {
     entry.WriteToDirectory(destinationPath, cancellation, new NullRarExtractionListener(), options);
 }