Esempio n. 1
0
        private void BtnExtract_Click(object sender, RoutedEventArgs e)
        {
            RAROpenArchiveDataEx openArchiveDataEx = new RAROpenArchiveDataEx()
            {
                ArcName  = TxtArchiveDir.Text,
                ArcNameW = TxtArchiveDir.Text,
                OpenMode = OpenMode.Extract,
                Callback = UNRARCallback
            };

            openArchiveDataEx.Initializ();

            var             rarHandle    = Unrar.RAROpenArchiveEx(ref openArchiveDataEx);
            RARHeaderDataEx headerDataEx = new RARHeaderDataEx();

            headerDataEx.Initialize();

            while (true)
            {
                Unrar.RARReadHeaderEx(rarHandle, ref headerDataEx);
                Unrar.RARProcessFileW(rarHandle, Operation.Extract, TxtExtractDir.Text, null);
                if (headerDataEx.FileNameW == " ")
                {
                    break;
                }
            }
            Unrar.RARCloseArchive(rarHandle);
        }
Esempio n. 2
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. 3
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. 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;

            // 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. 5
0
 private static extern IntPtr RAROpenArchiveEx(ref RAROpenArchiveDataEx archiveData);
Esempio n. 6
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. 7
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. 8
0
 private static extern IntPtr RAROpenArchiveEx(ref RAROpenArchiveDataEx archiveData);
        /// <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. 10
0
 public static extern IntPtr RAROpenArchiveEx(ref RAROpenArchiveDataEx archiveData);
Esempio n. 11
0
        private void BtnSelectArchive_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog
            {
                CheckFileExists = true
            };
            var result = fileDialog.ShowDialog();

            if (result == true)
            {
                TxtArchiveDir.Text = fileDialog.FileName;
            }

            RAROpenArchiveDataEx openArchiveDataEx = new RAROpenArchiveDataEx()
            {
                ArcName  = TxtArchiveDir.Text,
                ArcNameW = TxtArchiveDir.Text,
                OpenMode = OpenMode.List,
            };

            openArchiveDataEx.Initializ();

            var             rarHandle    = Unrar.RAROpenArchiveEx(ref openArchiveDataEx);
            RARHeaderDataEx headerDataEx = new RARHeaderDataEx();

            headerDataEx.Initialize();

            string preFile  = null;
            var    entities = new List <string>();

            while (true)
            {
                Unrar.RARReadHeaderEx(rarHandle, ref headerDataEx);
                if (headerDataEx.FileNameW == "" || headerDataEx.FileNameW == " ")
                {
                    if (preFile == headerDataEx.FileName)
                    {
                        break;
                    }
                    preFile = headerDataEx.FileName;
                }
                else
                {
                    if (preFile == headerDataEx.FileNameW)
                    {
                        break;
                    }
                    preFile = headerDataEx.FileNameW;
                }
                entities.Add(preFile);
                Unrar.RARProcessFileW(rarHandle, Operation.Skip, null, null);
            }
            Unrar.RARCloseArchive(rarHandle);

            var entityTree = new List <TreeViewItem>();

            entities.Sort();

            foreach (var entity in entities)
            {
                if (!entity.Contains("\\"))
                {
                    entityTree.Add(new TreeViewItem()
                    {
                        Header = entity
                    });
                    continue;
                }
                var parent = entityTree.First(en => (entity.StartsWith((string)en.Header)));
                parent.Items.Add(entity);
            }

            tre.ItemsSource = entityTree;
        }