Example #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);
        }
Example #2
0
        /// <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
            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.");
            }

            // New file, prepare header
            currentFile          = new RARFileInfo();
            currentFile.FileName = header.FileNameW.ToString();

            if ((header.Flags & 0xE0) == 0xE0)
            {
                currentFile.IsDirectory = true;
            }

            // Return success
            return(true);
        }
Example #3
0
        /// <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;
        }
Example #4
0
        /// <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);
        }
Example #5
0
        public bool ReadHeader()
        {
            if (!(archiveHandle == IntPtr.Zero))
            {
                header = default(RARHeaderDataEx);
                header.Initialize();
                currentFile = null;
                switch (RARReadHeaderEx(archiveHandle, ref header))
                {
                case 10:
                    return(false);

                case 12:
                    throw new IOException("Archive data is corrupt.");

                default:
                    if ((header.Flags & 1) != 0 && currentFile != null)
                    {
                        currentFile.ContinuedFromPrevious = true;
                    }
                    else
                    {
                        currentFile          = new RARFileInfo();
                        currentFile.FileName = header.FileNameW.ToString();
                        if ((header.Flags & 2) != 0)
                        {
                            currentFile.ContinuedOnNext = true;
                        }
                        if (header.PackSizeHigh != 0)
                        {
                            currentFile.PackedSize = header.PackSizeHigh * 4294967296L + header.PackSize;
                        }
                        else
                        {
                            currentFile.PackedSize = header.PackSize;
                        }
                        if (header.UnpSizeHigh != 0)
                        {
                            currentFile.UnpackedSize = header.UnpSizeHigh * 4294967296L + 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  = 0L;
                        if ((header.Flags & 0xE0) == 224)
                        {
                            currentFile.IsDirectory = true;
                        }
                        OnNewFile();
                    }
                    return(true);
                }
            }
            throw new IOException("Archive is not open.");
        }
        /// <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
            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.");

            // New file, prepare header
            currentFile = new RARFileInfo();
            currentFile.FileName = header.FileNameW.ToString();

            if ((header.Flags & 0xE0) == 0xE0)
                currentFile.IsDirectory = true;

            // Return success
            return true;
        }
Example #7
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;
        }