Exemplo n.º 1
0
        public bool ReadHeader()
        {
            if (this.archiveHandle == IntPtr.Zero)
            {
                throw new IOException("Archive is not open.");
            }
            this.header = new RARHeaderDataEx();
            this.header.Initialize();
            this.currentFile = null;
            switch (RARReadHeaderEx(this.archiveHandle, ref this.header))
            {
            case 10:
                return(false);

            case 12:
                throw new IOException("Archive data is corrupt.");
            }
            if (((this.header.Flags & 1) != 0) && (this.currentFile != null))
            {
                this.currentFile.ContinuedFromPrevious = true;
            }
            else
            {
                this.currentFile          = new RARFileInfo();
                this.currentFile.FileName = this.header.FileNameW.ToString();
                if ((this.header.Flags & 2) != 0)
                {
                    this.currentFile.ContinuedOnNext = true;
                }
                if (this.header.PackSizeHigh != 0)
                {
                    this.currentFile.PackedSize = (this.header.PackSizeHigh * 0x100000000L) + this.header.PackSize;
                }
                else
                {
                    this.currentFile.PackedSize = this.header.PackSize;
                }
                if (this.header.UnpSizeHigh != 0)
                {
                    this.currentFile.UnpackedSize = (this.header.UnpSizeHigh * 0x100000000L) + this.header.UnpSize;
                }
                else
                {
                    this.currentFile.UnpackedSize = this.header.UnpSize;
                }
                this.currentFile.HostOS          = (int)this.header.HostOS;
                this.currentFile.FileCRC         = this.header.FileCRC;
                this.currentFile.FileTime        = this.FromMSDOSTime(this.header.FileTime);
                this.currentFile.VersionToUnpack = (int)this.header.UnpVer;
                this.currentFile.Method          = (int)this.header.Method;
                this.currentFile.FileAttributes  = (int)this.header.FileAttr;
                this.currentFile.BytesExtracted  = 0L;
                if ((this.header.Flags & 0xe0) == 0xe0)
                {
                    this.currentFile.IsDirectory = true;
                }
                this.OnNewFile();
            }
            return(true);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public Unrar()
 {
     this.archivePathName = string.Empty;
     this.archiveHandle   = new IntPtr(0);
     this.retrieveComment = true;
     this.password        = string.Empty;
     this.comment         = string.Empty;
     this.header          = new RARHeaderDataEx();
     this.destinationPath = string.Empty;
     this.callback        = new UNRARCallback(this.RARCallback);
 }
Exemplo n.º 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
            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);
        }
Exemplo n.º 5
0
 private static extern int RARReadHeaderEx(IntPtr hArcData, ref RARHeaderDataEx headerData);
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 private static extern int RARReadHeaderEx(IntPtr hArcData, ref RARHeaderDataEx headerData);
Exemplo n.º 9
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;
        }
Exemplo n.º 11
0
 public static extern RarError RARReadHeaderEx(IntPtr hArcData, ref RARHeaderDataEx headerData);
Exemplo n.º 12
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;
        }