コード例 #1
0
        /// <summary>
        /// Extract to specific directory, retaining filename
        /// </summary>
        public static void WriteEntryToDirectory(this IReader reader, string destinationDirectory,
                                                 ExtractOptions options = ExtractOptions.Overwrite)
        {
            string destinationFileName = string.Empty;
            string file = Path.GetFileName(reader.Entry.Key);


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

            if (!reader.Entry.IsDirectory)
            {
                reader.WriteEntryToFile(destinationFileName, options);
            }
            else if (options.HasFlag(ExtractOptions.ExtractFullPath) && !Directory.Exists(destinationFileName))
            {
                Directory.CreateDirectory(destinationFileName);
            }
        }
コード例 #2
0
        /// <summary>
        /// Extract to specific directory, retaining filename
        /// </summary>
        public static void WriteEntryToDirectory(this IReader reader, string destinationDirectory,
                                                 ExtractOptions options = ExtractOptions.Overwrite)
        {
            string destinationFileName = string.Empty;
            string file = Path.GetFileName(reader.Entry.FilePath);


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

            if (!reader.Entry.IsDirectory)
            {
                reader.WriteEntryToFile(destinationFileName, options);
            }
            else if (options.HasFlag(ExtractOptions.ExtractFullPath) && !Directory.Exists(destinationFileName))
            {
                Directory.CreateDirectory(destinationFileName);
            }
        }
コード例 #3
0
        private int RaiseExtractionOrCheckFailedEvent(Exception exception)
        {
            int  result        = HRESULT.S_OK;
            bool abortAndThrow = !_options.HasFlag(ExtractOptions.NoAbortOnFailure);

            if (_extractMode == ExtractMode.ExtractToFile || _extractMode == ExtractMode.ExtractToStream)
            {
                CleanLastFileExtracted();
                FileExtractionFailedEventArgs args = new FileExtractionFailedEventArgs()
                {
                    CurrentEntry     = _entries[_lastEntryIndex],
                    TargetFilePath   = LastExtractedFilePath,
                    EntriesTotal     = _entries.Count,
                    EntriesProcessed = _entriesProcessed,
                    AbortAndThrow    = abortAndThrow,
                    Exception        = exception
                };

                result        = InvokeEventHandler(args, _archive.OnFileExtractionFailed, "SevenZipArchive.FileExtractionFailed");
                abortAndThrow = args.AbortAndThrow;
            }
            else if (_extractMode == ExtractMode.IntegrityCheck)
            {
                FileCheckFailedEventArgs args = new FileCheckFailedEventArgs()
                {
                    CurrentEntry     = _entries[_lastEntryIndex],
                    EntriesTotal     = _entries.Count,
                    EntriesProcessed = _entriesProcessed,
                    Exception        = exception
                };

                result = InvokeEventHandler(args, _archive.OnFileCheckFailed, "SevenZipArchive.FileCheckFailed");
            }
            else
            {
                Debug.Fail("Unexpected exception.");
                return(HRESULT.S_OK);
            }

            if (result != HRESULT.S_OK)
            {
                return(result);
            }
            else
            {
                if (!abortAndThrow)
                {
                    _exception = null;
                    return(HRESULT.S_OK);
                }
                else
                {
                    _exception = exception;
                    return(HRESULT.E_ABORT);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       ExtractOptions options = ExtractOptions.Overwrite)
        {
            if (entry.IsDirectory)
            {
                return;
            }
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs);
            }

            if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
            {
                // update file time to original packed time
                FileInfo nf = new FileInfo(destinationFileName);
                if (nf.Exists)
                {
                    if (options.HasFlag(ExtractOptions.PreserveFileTime))
                    {
                        if (entry.CreatedTime.HasValue)
                        {
                            nf.CreationTime = entry.CreatedTime.Value;
                        }

                        if (entry.LastModifiedTime.HasValue)
                        {
                            nf.LastWriteTime = entry.LastModifiedTime.Value;
                        }

                        if (entry.LastAccessedTime.HasValue)
                        {
                            nf.LastAccessTime = entry.CreatedTime.Value;
                        }
                    }

                    if (options.HasFlag(ExtractOptions.PreserveAttributes))
                    {
                        if (entry.Attrib.HasValue)
                        {
                            nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
                        }
                    }
                }
            }
        }
コード例 #5
0
 private FileExistsAction ExtractOptionsToFileExistAction(ExtractOptions options)
 {
     if (options.HasFlag(ExtractOptions.OverwriteExistingFiles))
     {
         return(FileExistsAction.Overwrite);
     }
     else if (options.HasFlag(ExtractOptions.SkipExistingFiles))
     {
         return(FileExistsAction.Skip);
     }
     else
     {
         return(FileExistsAction.Throw);
     }
 }
コード例 #6
0
        /// <summary>
        /// Extract to specific directory, retaining filename
        /// </summary>
        public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory,
                                            ExtractOptions options = ExtractOptions.Overwrite)
        {
            string destinationFileName;
            string file = Path.GetFileName(entry.Key);


            if (options.HasFlag(ExtractOptions.ExtractFullPath))
            {
                string folder  = Path.GetDirectoryName(entry.Key);
                string destdir = Path.Combine(destinationDirectory, folder);
                if (!Directory.Exists(destdir))
                {
                    Directory.CreateDirectory(destdir);
                }
                destinationFileName = Path.Combine(destdir, file);
            }
            else
            {
                destinationFileName = Path.Combine(destinationDirectory, file);
            }
            if (!entry.IsDirectory)
            {
                entry.WriteToFile(destinationFileName, options);
            }
        }
コード例 #7
0
        /// <summary>
        /// Extract to specific directory, retaining filename
        /// </summary>
        public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory,
                                            ExtractOptions options = ExtractOptions.Overwrite)
        {
            string destinationFileName;
            string file = Path.GetFileName(entry.Key);

            if (options.HasFlag(ExtractOptions.ExtractFullPath))
            {
                string folder = Path.GetDirectoryName(entry.Key);
                string destdir = Path.Combine(destinationDirectory, folder);
                if (!Directory.Exists(destdir))
                {
                    Directory.CreateDirectory(destdir);
                }
                destinationFileName = Path.Combine(destdir, file);
            }
            else
            {
                destinationFileName = Path.Combine(destinationDirectory, file);
            }
            if (!entry.IsDirectory)
            {
                entry.WriteToFile(destinationFileName, options);
            }
        }
コード例 #8
0
        /// <summary>
        /// Extract to specific directory, retaining filename
        /// </summary>
        public static void WriteToDirectory(this RarArchiveEntry entry, string destinationDirectory,
                                            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, listener, options);
        }
コード例 #9
0
        /// <summary>
        /// Extract to specific directory, retaining filename
        /// </summary>
        public static void WriteToDirectory(this RarArchiveEntry entry, string destinationDirectory,
            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, listener, options);
        }
コード例 #10
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
            ExtractOptions options = ExtractOptions.Overwrite)
        {
            if (entry.IsDirectory)
            {
                return;
            }
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs);
            }

            if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
            {
                // update file time to original packed time
                FileInfo nf = new FileInfo(destinationFileName);
                if (nf.Exists)
                {
                    if (options.HasFlag(ExtractOptions.PreserveAttributes))
                    {
                        if (entry.CreatedTime.HasValue)
                        {
                            nf.CreationTime = entry.CreatedTime.Value;
                        }

                        if (entry.LastModifiedTime.HasValue)
                        {
                            nf.LastWriteTime = entry.LastModifiedTime.Value;
                        }

                        if (entry.LastAccessedTime.HasValue)
                        {
                            nf.LastAccessTime = entry.CreatedTime.Value;
                        }
                    }

                    if (options.HasFlag(ExtractOptions.PreserveAttributes))
                    {
                        if (entry.Attrib.HasValue)
                        {
                            nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
                        }
                    }
                }
            }
        }
コード例 #11
0
        internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName,
                                                        ExtractOptions options)
        {
            if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
            {
                FileInfo nf = new FileInfo(destinationFileName);
                if (!nf.Exists)
                {
                    return;
                }

                // update file time to original packed time
                if (options.HasFlag(ExtractOptions.PreserveFileTime))
                {
                    if (entry.CreatedTime.HasValue)
                    {
                        nf.CreationTime = entry.CreatedTime.Value;
                    }

                    if (entry.LastModifiedTime.HasValue)
                    {
                        nf.LastWriteTime = entry.LastModifiedTime.Value;
                    }

                    if (entry.LastAccessedTime.HasValue)
                    {
                        nf.LastAccessTime = entry.LastAccessedTime.Value;
                    }
                }

                if (options.HasFlag(ExtractOptions.PreserveAttributes))
                {
                    if (entry.Attrib.HasValue)
                    {
                        nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
                    }
                }
            }
        }
コード例 #12
0
        internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName,
                                                       ExtractOptions options)
        {
            if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
            {
                FileInfo nf = new FileInfo(destinationFileName);
                if (!nf.Exists)
                {
                    return;
                }

                // update file time to original packed time
                if (options.HasFlag(ExtractOptions.PreserveFileTime))
                {
                    if (entry.CreatedTime.HasValue)
                    {
                        nf.CreationTime = entry.CreatedTime.Value;
                    }

                    if (entry.LastModifiedTime.HasValue)
                    {
                        nf.LastWriteTime = entry.LastModifiedTime.Value;
                    }

                    if (entry.LastAccessedTime.HasValue)
                    {
                        nf.LastAccessTime = entry.LastAccessedTime.Value;
                    }
                }

                if (options.HasFlag(ExtractOptions.PreserveAttributes))
                {
                    if (entry.Attrib.HasValue)
                    {
                        nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
                    }
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteEntryToFile(this RarReader reader, string destinationFileName,
            ExtractOptions options = ExtractOptions.Overwrite)
        {
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                reader.WriteEntryTo(fs);
            }
        }
コード例 #14
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteEntryToFile(this RarReader reader, string destinationFileName,
                                            ExtractOptions options = ExtractOptions.Overwrite)
        {
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                reader.WriteEntryTo(fs);
            }
        }
コード例 #15
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this RarArchiveEntry entry, string destinationFileName,
                                       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, listener);
            }
        }
コード例 #16
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this RarArchiveEntry entry, string destinationFileName,
                        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, listener);
            }
        }
コード例 #17
0
 public static void WriteToFile(this IArchiveEntry entry, string destinationFileName, ExtractOptions options = 1)
 {
     if (!entry.IsDirectory)
     {
         FileMode create = FileMode.Create;
         if (!options.HasFlag(ExtractOptions.Overwrite))
         {
             create = FileMode.CreateNew;
         }
         using (FileStream stream = File.Open(destinationFileName, create))
         {
             entry.WriteTo(stream);
         }
     }
 }
コード例 #18
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       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);
            }

            entry.PreserveExtractionOptions(destinationFileName, options);
        }
コード例 #19
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       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);
            }

            entry.PreserveExtractionOptions(destinationFileName, options);
        }
コード例 #20
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
            ExtractOptions options = ExtractOptions.Overwrite)
        {
            if (entry.IsDirectory)
            {
                return;
            }
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs);
            }
        }
コード例 #21
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
                                       ExtractOptions options = ExtractOptions.Overwrite)
        {
            if (entry.IsDirectory)
            {
                return;
            }
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                entry.WriteTo(fs);
            }
        }
コード例 #22
0
ファイル: IReader.Extensions.cs プロジェクト: nlhepler/mono
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteEntryToFile(this IReader reader, string destinationFileName,
                                            ExtractOptions options = ExtractOptions.Overwrite)
        {
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                reader.WriteEntryTo(fs);
                //using (Stream s = reader.OpenEntryStream())
                //{
                //    s.TransferTo(fs);
                //}
            }
        }
コード例 #23
0
        /// <summary>
        /// Extract to specific file
        /// </summary>
        public static void WriteEntryToFile(this IReader reader, string destinationFileName,
                                            ExtractOptions options = ExtractOptions.Overwrite)
        {
            FileMode fm = FileMode.Create;

            if (!options.HasFlag(ExtractOptions.Overwrite))
            {
                fm = FileMode.CreateNew;
            }
            using (FileStream fs = File.Open(destinationFileName, fm))
            {
                reader.WriteEntryTo(fs);
                //using (Stream s = reader.OpenEntryStream())
                //{
                //    s.TransferTo(fs);
                //}
            }
        }
コード例 #24
0
        public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory, ExtractOptions options = 1)
        {
            string destinationFileName = string.Empty;
            string fileName            = Path.GetFileName(entry.FilePath);

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