Esempio n. 1
0
        public void Open(string archivePathName, OpenMode openMode)
        {
            IntPtr zero = IntPtr.Zero;

            if (archiveHandle != IntPtr.Zero)
            {
                Close();
            }
            ArchivePathName = archivePathName;
            RAROpenArchiveDataEx archiveData = default(RAROpenArchiveDataEx);

            archiveData.Initialize();
            archiveData.ArcName  = this.archivePathName + "\0";
            archiveData.ArcNameW = this.archivePathName + "\0";
            archiveData.OpenMode = (uint)openMode;
            if (retrieveComment)
            {
                archiveData.CmtBuf     = new string('\0', 65536);
                archiveData.CmtBufSize = 65536u;
            }
            else
            {
                archiveData.CmtBuf     = null;
                archiveData.CmtBufSize = 0u;
            }
            zero = RAROpenArchiveEx(ref archiveData);
            if (archiveData.OpenResult != 0)
            {
                switch (archiveData.OpenResult)
                {
                case 11u:
                    throw new OutOfMemoryException("Insufficient memory to perform operation.");
                    break;

                case 12u:
                    throw new IOException("Archive header broken");
                    break;

                case 13u:
                    throw new IOException("File is not a valid archive.");
                    break;

                case 15u:
                    throw new IOException("File could not be opened.");
                    break;
                }
            }
            archiveHandle = zero;
            archiveFlags  = (ArchiveFlags)archiveData.Flags;
            RARSetCallback(archiveHandle, callback, GetHashCode());
            if (archiveData.CmtState == 1)
            {
                comment = archiveData.CmtBuf.ToString();
            }
            if (password.Length != 0)
            {
                RARSetPassword(archiveHandle, password);
            }
            OnNewVolume(this.archivePathName);
        }
Esempio n. 2
0
        public void Open(string archivePathName, OpenMode openMode)
        {
            IntPtr zero = IntPtr.Zero;

            if (this.archiveHandle != IntPtr.Zero)
            {
                this.Close();
            }
            this.ArchivePathName = archivePathName;
            RAROpenArchiveDataEx archiveData = new RAROpenArchiveDataEx();

            archiveData.Initialize();
            archiveData.ArcName  = this.archivePathName + "\0";
            archiveData.ArcNameW = this.archivePathName + "\0";
            archiveData.OpenMode = (uint)openMode;
            if (this.retrieveComment)
            {
                archiveData.CmtBuf     = new string('\0', 0x10000);
                archiveData.CmtBufSize = 0x10000;
            }
            else
            {
                archiveData.CmtBuf     = null;
                archiveData.CmtBufSize = 0;
            }
            zero = RAROpenArchiveEx(ref archiveData);
            switch (archiveData.OpenResult)
            {
            case 11:
                throw new OutOfMemoryException("Insufficient memory to perform operation.");

            case 12:
                throw new IOException("Archive header broken");

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

            case 15:
                throw new IOException("File could not be opened.");
            }
            this.archiveHandle = zero;
            this.archiveFlags  = (ArchiveFlags)archiveData.Flags;
            RARSetCallback(this.archiveHandle, this.callback, this.GetHashCode());
            if (archiveData.CmtState == 1)
            {
                this.comment = archiveData.CmtBuf.ToString();
            }
            if (this.password.Length != 0)
            {
                RARSetPassword(this.archiveHandle, this.password);
            }
            this.OnNewVolume(this.archivePathName);
        }
Esempio n. 3
0
        /// <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;

            // 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;
        }
Esempio n. 4
0
        /// <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);
        }
Esempio n. 5
0
        /// <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);
        }
        /// <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;

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