示例#1
0
        public void Dispose(bool decompressor)
        {
            if (decompressor)
            {
                if (m_is64Bit)
                {
                    DestroyDecompressLibrary64(m_libHandle);
                }
                else
                {
                    DestroyDecompressLibrary32(m_libHandle);
                }
            }
            else
            {
                if (m_is64Bit)
                {
                    DestroyCompressLibrary64(m_libHandle);
                }
                else
                {
                    DestroyCompressLibrary32(m_libHandle);
                }
            }

            m_fileNameCallback      = null;
            m_progressCallback      = null;
            m_processedSizeCallback = null;
            m_totalSizeCallback     = null;

            m_libHandle = new IntPtr();
            Dispose();
        }
示例#2
0
 private static extern IntPtr InitDecompressLibrary32(string libraryPath, string archiveName,
                                                      [MarshalAs(UnmanagedType.FunctionPtr)] ProgressCallback pCallback,
                                                      [MarshalAs(UnmanagedType.FunctionPtr)] FileNameCallback fnCallback,
                                                      [MarshalAs(UnmanagedType.FunctionPtr)] TotalSizeCallback tsCallback,
                                                      [MarshalAs(UnmanagedType.FunctionPtr)] ProcessedSizeCallback psCallback);
示例#3
0
        public SevenZipWrapper(string archiveName, bool decompressor)
        {
            var rootDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            // check for IntPtr.Size == 8 does not work here, as we are in a 32 bit process, IntPtr.Size is always 4
            var libraryPath = Path.Combine(rootDir, "rsc", m_is64Bit ? "64" : "32", "7z.dll");

            if (decompressor)
            {
                m_fileNameCallback = value =>
                {
                    var fPath = Path.GetFileName(value);
                    if (FileExtractionStarted == null)
                    {
                        return;
                    }

                    var ev = new FileNameEventArgs(fPath, (byte)m_progress);
                    FileExtractionStarted(this, ev);
                    if (ev.Cancel)
                    {
                        Cancel(false);
                    }
                };
                m_progressCallback = value =>
                {
                    m_progress = value;
                    if (Extracting != null)
                    {
                        Extracting(this, new ProgressEventArgs((byte)m_progress, (byte)(100 - m_progress)));
                    }
                };
                m_totalSizeCallback = value =>
                {
                    m_totalSize = value;
                };
                m_processedSizeCallback = value =>
                {
                    m_processedSize = value;
                };

                if (m_is64Bit)
                {
                    m_libHandle = InitDecompressLibrary64(libraryPath, archiveName, m_progressCallback, m_fileNameCallback,
                                                          m_totalSizeCallback, m_processedSizeCallback);
                }
                else
                {
                    m_libHandle = InitDecompressLibrary32(libraryPath, archiveName, m_progressCallback, m_fileNameCallback,
                                                          m_totalSizeCallback, m_processedSizeCallback);
                }
            }
            else
            {
                m_fileNameCallback = value =>
                {
                    var fPath = Path.GetFileName(value);
                    if (FileCompressionStarted == null)
                    {
                        return;
                    }

                    var ev = new FileNameEventArgs(fPath, (byte)m_progress);
                    FileCompressionStarted(this, ev);
                    if (ev.Cancel)
                    {
                        Cancel(false);
                    }
                };
                m_progressCallback = value =>
                {
                    m_progress = value;
                    if (Compressing != null)
                    {
                        Compressing(this, new ProgressEventArgs((byte)m_progress, (byte)(100 - m_progress)));
                    }
                };
                m_totalSizeCallback = value =>
                {
                    m_totalSize = value;
                };
                m_processedSizeCallback = value =>
                {
                    m_processedSize = value;
                };

                if (m_is64Bit)
                {
                    m_libHandle = InitCompressLibrary64(libraryPath, archiveName, m_progressCallback, m_fileNameCallback,
                                                        m_totalSizeCallback, m_processedSizeCallback);
                }
                else
                {
                    m_libHandle = InitCompressLibrary32(libraryPath, archiveName, m_progressCallback, m_fileNameCallback,
                                                        m_totalSizeCallback, m_processedSizeCallback);
                }
            }
        }