/// <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); } }
/// <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); } }
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); } } }
/// <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); } } } } }
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); } }
/// <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); } }
/// <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); }
/// <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); } } } } }
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); } } } }
/// <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); } }
/// <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); } }
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); } } }
/// <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); }
/// <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); } }
/// <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); //} } }
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); }