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); }
/// <summary> /// Changes the path to the 7-zip native library. /// </summary> public static void InitLib() { libraryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "7-Zip", "7z.dll"); if (!File.Exists(libraryPath)) { try { Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "7-Zip")); File.WriteAllBytes(libraryPath, SevenZipLib.X86); } catch { throw new SevenZipException("The 7-Zip library could not be written onto the local machine."); } } SevenZipLibraryManager.SetLibraryPath(libraryPath); }
/// <summary> /// General initialization function. /// </summary> /// <param name="stream">The stream to read the archive from.</param> private void Init(Stream stream) { ValidateStream(stream); bool isExecutable = false; if ((int)_format == -1) { _format = FileChecker.CheckSignature(stream, out _offset, out isExecutable); } PreserveDirectoryStructure = true; SevenZipLibraryManager.LoadLibrary(this, _format); try { _inStream = new ArchiveEmulationStreamProxy(stream, _offset); _packedSize = stream.Length; _archive = SevenZipLibraryManager.InArchive(_format, this); } catch (SevenZipLibraryException) { SevenZipLibraryManager.FreeLibrary(this, _format); throw; } if (isExecutable && _format != InArchiveFormat.PE) { if (!Check()) { CommonDispose(); _format = InArchiveFormat.PE; try { _inStream = new ArchiveEmulationStreamProxy(stream, _offset); _packedSize = stream.Length; _archive = SevenZipLibraryManager.InArchive(_format, this); } catch (SevenZipLibraryException) { SevenZipLibraryManager.FreeLibrary(this, _format); throw; } } } }
/// <summary> /// General initialization function. /// </summary> /// <param name="archiveFullName">The archive file name.</param> private void Init(string archiveFullName) { _fileName = archiveFullName; bool isExecutable = false; if ((int)_format == -1) { _format = FileChecker.CheckSignature(archiveFullName, out _offset, out isExecutable); } PreserveDirectoryStructure = true; SevenZipLibraryManager.LoadLibrary(this, _format); try { _archive = SevenZipLibraryManager.InArchive(_format, this); } catch (SevenZipLibraryException) { SevenZipLibraryManager.FreeLibrary(this, _format); throw; } if (isExecutable && _format != InArchiveFormat.PE) { if (!Check()) { CommonDispose(); _format = InArchiveFormat.PE; SevenZipLibraryManager.LoadLibrary(this, _format); try { _archive = SevenZipLibraryManager.InArchive(_format, this); } catch (SevenZipLibraryException) { SevenZipLibraryManager.FreeLibrary(this, _format); throw; } } } }
/// <summary> /// Changes the path to the 7-zip native library. /// </summary> /// <param name="libraryPath">The path to the 7-zip native library.</param> public static void SetLibraryPath(string libraryPath) { SevenZipLibraryManager.SetLibraryPath(libraryPath); }