コード例 #1
0
ファイル: Unrar.cs プロジェクト: silverkors/inbox2_desktop
 public void Dispose()
 {
     if (this.archiveHandle != IntPtr.Zero)
     {
         Unrar.RARCloseArchive(this.archiveHandle);
         this.archiveHandle = IntPtr.Zero;
     }
 }
コード例 #2
0
ファイル: Unrar.cs プロジェクト: silverkors/inbox2_desktop
        private void Extract(string destinationPath, string destinationName)
        {
            int result = Unrar.RARProcessFile(this.archiveHandle, (int)Operation.Extract, destinationPath, destinationName);

            // Check result
            if (result != 0)
            {
                ProcessFileError(result);
            }
        }
コード例 #3
0
ファイル: Unrar.cs プロジェクト: silverkors/inbox2_desktop
        /// <summary>
        /// Tests the ability to extract the current file without saving extracted data to disk
        /// </summary>
        /// <returns></returns>
        public void Test()
        {
            int result = Unrar.RARProcessFile(this.archiveHandle, (int)Operation.Test, string.Empty, string.Empty);

            // Check result
            if (result != 0)
            {
                ProcessFileError(result);
            }
        }
コード例 #4
0
ファイル: Unrar.cs プロジェクト: silverkors/inbox2_desktop
        /// <summary>
        /// Close the currently open archive
        /// </summary>
        /// <returns></returns>
        public void Close()
        {
            // Exit without exception if no archive is open
            if (this.archiveHandle == IntPtr.Zero)
            {
                return;
            }

            // Close archive
            int result = Unrar.RARCloseArchive(this.archiveHandle);

            // Check result
            if (result != 0)
            {
                ProcessFileError(result);
            }
            else
            {
                this.archiveHandle = IntPtr.Zero;
            }
        }
コード例 #5
0
ファイル: Unrar64.cs プロジェクト: Klaudit/inbox2_desktop
 private static extern int RARReadHeaderEx(IntPtr hArcData, ref Unrar.RARHeaderDataEx headerData);
コード例 #6
0
ファイル: Unrar64.cs プロジェクト: Klaudit/inbox2_desktop
 private static extern IntPtr RAROpenArchiveEx(ref Unrar.RAROpenArchiveDataEx archiveData);
コード例 #7
0
ファイル: Unrar64.cs プロジェクト: Klaudit/inbox2_desktop
        /// <summary>
        /// Opens specified archive using the specified mode.  
        /// </summary>
        /// <param name="archivePathName">Path of archive to open</param>
        /// <param name="openMode">Mode in which to open archive</param>
        public void Open(string archivePathName, Unrar.OpenMode openMode)
        {
            IntPtr handle = IntPtr.Zero;

            // Close any previously open archives
            if (this.archiveHandle != IntPtr.Zero)
                this.Close();

            // Prepare extended open archive struct
            this.ArchivePathName = archivePathName;
            Unrar.RAROpenArchiveDataEx openStruct = new Unrar.RAROpenArchiveDataEx();
            openStruct.Initialize();
            openStruct.ArcName = this.archivePathName + "\0";
            openStruct.ArcNameW = this.archivePathName + "\0";
            openStruct.OpenMode = (uint)openMode;
            if (this.retrieveComment)
            {
                openStruct.CmtBuf = new string((char)0, 65536);
                openStruct.CmtBufSize = 65536;
            }
            else
            {
                openStruct.CmtBuf = null;
                openStruct.CmtBufSize = 0;
            }

            // Open archive
            handle = Unrar64.RAROpenArchiveEx(ref openStruct);

            // Check for success
            if (openStruct.OpenResult != 0)
            {
                switch ((Unrar.RarError)openStruct.OpenResult)
                {
                    case Unrar.RarError.InsufficientMemory:
                        throw new OutOfMemoryException("Insufficient memory to perform operation.");

                    case Unrar.RarError.BadData:
                        throw new IOException("Archive header broken");

                    case Unrar.RarError.BadArchive:
                        throw new IOException("File is not a valid archive.");

                    case Unrar.RarError.OpenError:
                        throw new IOException("File could not be opened.");
                }
            }

            // Save handle and flags
            this.archiveHandle = handle;
            this.archiveFlags = (Unrar.ArchiveFlags)openStruct.Flags;

            // Set callback
            Unrar64.RARSetCallback(this.archiveHandle, this.callback, this.GetHashCode());

            // If comment retrieved, save it
            if (openStruct.CmtState == 1)
                this.comment = openStruct.CmtBuf.ToString();

            // If password supplied, set it
            if (this.password.Length != 0)
                Unrar64.RARSetPassword(this.archiveHandle, this.password);

            // Fire NewVolume event for first volume
            this.OnNewVolume(this.archivePathName);
        }
コード例 #8
0
ファイル: Unrar64.cs プロジェクト: Klaudit/inbox2_desktop
 /// <summary>
 /// Opens archive specified by the ArchivePathName property with a specified mode
 /// </summary>
 /// <param name="openMode">Mode in which archive should be opened</param>
 public void Open(Unrar.OpenMode openMode)
 {
     if (this.ArchivePathName.Length == 0)
         throw new IOException("Archive name has not been set.");
     this.Open(this.ArchivePathName, openMode);
 }
コード例 #9
0
ファイル: Unrar.cs プロジェクト: silverkors/inbox2_desktop
        /// <summary>
        /// Reads the next archive header and populates CurrentFile property data
        /// </summary>
        /// <returns></returns>
        public bool ReadHeader()
        {
            // Throw exception if archive not open
            if (this.archiveHandle == IntPtr.Zero)
            {
                throw new IOException("Archive is not open.");
            }

            // Initialize header struct
            this.header = new RARHeaderDataEx();
            header.Initialize();

            // Read next entry
            currentFile = null;
            int result = Unrar.RARReadHeaderEx(this.archiveHandle, ref this.header);

            // Check for error or end of archive
            if ((RarError)result == RarError.EndOfArchive)
            {
                return(false);
            }
            else if ((RarError)result == RarError.BadData)
            {
                throw new IOException("Archive data is corrupt.");
            }

            // Determine if new file
            if (((header.Flags & 0x01) != 0) && currentFile != null)
            {
                currentFile.ContinuedFromPrevious = true;
            }
            else
            {
                // New file, prepare header
                currentFile          = new RARFileInfo();
                currentFile.FileName = header.FileNameW.ToString();
                if ((header.Flags & 0x02) != 0)
                {
                    currentFile.ContinuedOnNext = true;
                }
                if (header.PackSizeHigh != 0)
                {
                    currentFile.PackedSize = (header.PackSizeHigh * 0x100000000) + header.PackSize;
                }
                else
                {
                    currentFile.PackedSize = header.PackSize;
                }
                if (header.UnpSizeHigh != 0)
                {
                    currentFile.UnpackedSize = (header.UnpSizeHigh * 0x100000000) + header.UnpSize;
                }
                else
                {
                    currentFile.UnpackedSize = header.UnpSize;
                }
                currentFile.HostOS          = (int)header.HostOS;
                currentFile.FileCRC         = header.FileCRC;
                currentFile.FileTime        = FromMSDOSTime(header.FileTime);
                currentFile.VersionToUnpack = (int)header.UnpVer;
                currentFile.Method          = (int)header.Method;
                currentFile.FileAttributes  = (int)header.FileAttr;
                currentFile.BytesExtracted  = 0;
                if ((header.Flags & 0xE0) == 0xE0)
                {
                    currentFile.IsDirectory = true;
                }
                this.OnNewFile();
            }

            // Return success
            return(true);
        }
コード例 #10
0
ファイル: Unrar.cs プロジェクト: silverkors/inbox2_desktop
        /// <summary>
        /// Opens specified archive using the specified mode.
        /// </summary>
        /// <param name="archivePathName">Path of archive to open</param>
        /// <param name="openMode">Mode in which to open archive</param>
        public void Open(string archivePathName, OpenMode openMode)
        {
            IntPtr handle = IntPtr.Zero;

            // Close any previously open archives
            if (this.archiveHandle != IntPtr.Zero)
            {
                this.Close();
            }

            // Prepare extended open archive struct
            this.ArchivePathName = archivePathName;
            RAROpenArchiveDataEx openStruct = new RAROpenArchiveDataEx();

            openStruct.Initialize();
            openStruct.ArcName  = this.archivePathName + "\0";
            openStruct.ArcNameW = this.archivePathName + "\0";
            openStruct.OpenMode = (uint)openMode;
            if (this.retrieveComment)
            {
                openStruct.CmtBuf     = new string((char)0, 65536);
                openStruct.CmtBufSize = 65536;
            }
            else
            {
                openStruct.CmtBuf     = null;
                openStruct.CmtBufSize = 0;
            }

            // Open archive
            handle = Unrar.RAROpenArchiveEx(ref openStruct);

            // Check for success
            if (openStruct.OpenResult != 0)
            {
                switch ((RarError)openStruct.OpenResult)
                {
                case RarError.InsufficientMemory:
                    throw new OutOfMemoryException("Insufficient memory to perform operation.");

                case RarError.BadData:
                    throw new IOException("Archive header broken");

                case RarError.BadArchive:
                    throw new IOException("File is not a valid archive.");

                case RarError.OpenError:
                    throw new IOException("File could not be opened.");
                }
            }

            // Save handle and flags
            this.archiveHandle = handle;
            this.archiveFlags  = (ArchiveFlags)openStruct.Flags;

            // Set callback
            Unrar.RARSetCallback(this.archiveHandle, this.callback, this.GetHashCode());

            // If comment retrieved, save it
            if (openStruct.CmtState == 1)
            {
                this.comment = openStruct.CmtBuf.ToString();
            }

            // If password supplied, set it
            if (this.password.Length != 0)
            {
                Unrar.RARSetPassword(this.archiveHandle, this.password);
            }

            // Fire NewVolume event for first volume
            this.OnNewVolume(this.archivePathName);
        }