private void CommonDispose() { if (_opened) { try { if (_archive != null) { _archive.Close(); } } catch (Exception) { } } _archive = null; _archiveFileData = null; _archiveProperties = null; _archiveFileInfoCollection = null; if (_inStream != null) { _inStream.Dispose(); _inStream = null; } if (_openCallback != null) { try { _openCallback.Dispose(); } catch (ObjectDisposedException) { } _openCallback = null; } if (_archiveStream != null) { if (_archiveStream is IDisposable) { try { if (_archiveStream is DisposeVariableWrapper) { (_archiveStream as DisposeVariableWrapper).DisposeStream = true; } (_archiveStream as IDisposable).Dispose(); } catch (ObjectDisposedException) { } _archiveStream = null; } } SevenZipLibraryManager.FreeLibrary(this, _format); }
private static void ListOrExtract(string archiveName, uint level) { using (SevenZipFormat Format = new SevenZipFormat(SevenZipDllPath)) { IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(KnownSevenZipFormat.Zip)); if (Archive == null) return; try { using (InStreamWrapper ArchiveStream = new InStreamWrapper(File.OpenRead(archiveName))) { IArchiveOpenCallback OpenCallback = new ArchiveOpenCallback(); // 32k CheckPos is not enough for some 7z archive formats ulong CheckPos = 128 * 1024; if (Archive.Open(ArchiveStream, ref CheckPos, OpenCallback) != 0) //ShowHelp(); if (!Directory.Exists(@"tmp_dir")) Directory.CreateDirectory(@"tmp_dir"); //Console.WriteLine(archiveName); uint Count = Archive.GetNumberOfItems(); for (uint I = 0; I < Count; I++) { PropVariant Name = new PropVariant(); Archive.GetProperty(I, ItemPropId.kpidPath, ref Name); string FileName = (string)Name.GetObject(); Program.f1.label1.Text = FileName; Application.DoEvents(); for(int i = 0; i < level; i++) Console.Write("\t"); Console.Write(FileName + "\n"); FileName += level; Archive.Extract(new uint[] { I }, 1, 0, new ArchiveExtractCallback(I, FileName)); Program.Determine_Parser(new System.IO.FileInfo("tmp_dir//" + FileName), level); } } } finally { Marshal.ReleaseComObject(Archive); Directory.Delete(@"tmp_dir", true); } } }
/// <summary> /// Opens the archive and throws exceptions or returns OperationResult.DataError if any error occurs. /// </summary> /// <param name="archiveStream">The IInStream compliant class instance, that is, the input stream.</param> /// <param name="openCallback">The ArchiveOpenCallback instance.</param> /// <returns>True if Open() succeeds; otherwise, false.</returns> private bool OpenArchive(IInStream archiveStream, ArchiveOpenCallback openCallback) { if (!_opened) { if (OpenArchiveInner(archiveStream, openCallback) != OperationResult.Ok) { if (!ThrowException(null, new SevenZipArchiveException())) { return(false); } } _volumeFileNames = new ReadOnlyCollection <string>(openCallback.VolumeFileNames); _opened = true; } return(true); }
private void CommonDispose() { if (_opened) { try { if (_archive != null) { _archive.Close(); } } catch (Exception) { } } _archive = null; _archiveFileData = null; _archiveProperties = null; _archiveFileInfoCollection = null; _inStream = null; if (_openCallback != null) { try { _openCallback.Dispose(); } catch (ObjectDisposedException) { } _openCallback = null; } if (_archiveStream != null) { if (_archiveStream is IDisposable) { try { if (_archiveStream is DisposeVariableWrapper) { (_archiveStream as DisposeVariableWrapper).DisposeStream = true; } (_archiveStream as IDisposable).Dispose(); } catch (ObjectDisposedException) { } _archiveStream = null; } } SevenZipLibraryManager.FreeLibrary(this, _format); }
/// <summary> /// Opens the archive and throws exceptions or returns OperationResult.DataError if any error occurs. /// </summary> /// <param name="archiveStream">The IInStream compliant class instance, that is, the input stream.</param> /// <param name="openCallback">The ArchiveOpenCallback instance.</param> /// <returns>True if Open() succeeds; otherwise, false.</returns> private bool OpenArchive(IInStream archiveStream, ArchiveOpenCallback openCallback) { if (!_opened) { if (OpenArchiveInner(archiveStream, openCallback) != OperationResult.Ok) { if (!ThrowException(null, new SevenZipArchiveException())) { return false; } } _volumeFileNames = new ReadOnlyCollection<string>(openCallback.VolumeFileNames); _opened = true; } return true; }
private ArchiveOpenCallback GetArchiveOpenCallback() { return _openCallback ?? (_openCallback = String.IsNullOrEmpty(Password) ? new ArchiveOpenCallback(_fileName) : new ArchiveOpenCallback(_fileName, Password)); }
private ArchiveOpenCallback GetArchiveOpenCallback() { return(_openCallback ?? (_openCallback = String.IsNullOrEmpty(Password) ? new ArchiveOpenCallback(_fileName) : new ArchiveOpenCallback(_fileName, Password))); }