SevenZip/SevenZipExtractor.cs
/// <summary>
///   Unpacks files by their indices to the specified directory.
/// </summary>
/// <param name = "indexes">indexes of the files in the archive file table.</param>
/// <param name = "directory">Directory where the files are to be unpacked.</param>
Unpacks files by their indices to the specified directory.
Unpacks files by their indices to the specified directory .
public void ExtractFiles(string directory, params int[] indexes)
        {
            DisposedCheck();
            ClearExceptions();
            if (!CheckIndexes(indexes))
            {
                if (
                    !ThrowException(null, new ArgumentException("The indexes must be more or equal to zero.", "indexes")))
                {
                    return;
                }
            }
            InitArchiveFileData(false);
            #region Indexes stuff
            var uindexes = new uint[indexes.Length];
            for (int i = 0; i < indexes.Length; i++)
            {
                uindexes[i] = (uint) indexes[i];
            }
#if CS4
            if (uindexes.Where(i => i >= _filesCount).Any(
                i => !ThrowException(null, 
                                     new ArgumentOutOfRangeException("indexes", 
                                                                    "Index must be less than " + 
                                                                        _filesCount.Value.ToString(
                                                                            CultureInfo.InvariantCulture) + "!"))))
            {
                return;
            }
#else
            foreach (uint i in uindexes)
            {
                if (i >= _filesCount)
                {
                    if (!ThrowException(null,
                                        new ArgumentOutOfRangeException("indexes",
                                                                        "Index must be less than " +
                                                                        _filesCount.Value.ToString(
                                                                            CultureInfo.InvariantCulture) + "!")))
                    {
                        return;
                    }
                }
            }
#endif
            var origIndexes = new List<uint>(uindexes);
            origIndexes.Sort();
            uindexes = origIndexes.ToArray();
            if (_isSolid.Value)
            {
                uindexes = SolidIndexes(uindexes);
            }
            #endregion
            try
            {
                IInStream archiveStream;
                using ((archiveStream = GetArchiveStream(origIndexes.Count != 1)) as IDisposable)
                {
                    ArchiveOpenCallback openCallback = GetArchiveOpenCallback();
                    if (!OpenArchive(archiveStream, openCallback))
                    {
                        return;
                    }
                    try
                    {
                        using (
                            ArchiveExtractCallback aec = GetArchiveExtractCallback(directory, (int) _filesCount,
                                                                                   origIndexes))
                        {
                            try
                            {
                                CheckedExecute(
                                    _archive.Extract(uindexes, (uint) uindexes.Length, 0, aec),
                                    SevenZipExtractionFailedException.DEFAULT_MESSAGE, aec);
                            }
                            finally
                            {
                                FreeArchiveExtractCallback(aec);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        if (openCallback.ThrowException())
                        {
                            throw;
                        }
                    }
                }
                OnEvent(ExtractionFinished, EventArgs.Empty, false);
            }
            finally
            {
                if (origIndexes.Count > 1)
                {
                    if (_archive != null)
                    {
                        _archive.Close();
                    }
                    _archiveStream = null;
                    _opened = false;
                }
            }
            ThrowUserException();
        }
public void ExtractFiles ( string directory , params int [ ] indexes ) { DisposedCheck ( ) ; ClearExceptions ( ) ; if ( ! CheckIndexes ( indexes ) ) { if ( ! ThrowException ( null , new ArgumentException ( " " , " " ) ) ) { return ; } } InitArchiveFileData ( false ) ; region  Indexes stuff var uindexes = new uint [ indexes . Length ] ; for ( int i = 0 ; i < indexes . Length ; i ++ ) { uindexes [ i ] = ( uint ) indexes [ i ] ; } if CS4 if ( uindexes . Where ( i => i >= _filesCount ) . Any ( i => ! ThrowException ( null , new ArgumentOutOfRangeException ( " " , " " + _filesCount . Value . ToString ( CultureInfo . InvariantCulture ) + " " ) ) ) ) { return ; } else foreach ( uint i in uindexes ) { if ( i >= _filesCount ) { if ( ! ThrowException ( null , new ArgumentOutOfRangeException ( " " , " " + _filesCount . Value . ToString ( CultureInfo . InvariantCulture ) + " " ) ) ) { return ; } } } endif var origIndexes = new List < uint > ( uindexes ) ; origIndexes . Sort ( ) ; uindexes = origIndexes . ToArray ( ) ; if ( _isSolid . Value ) { uindexes = SolidIndexes ( uindexes ) ; } endregion try { IInStream archiveStream ; using ( ( archiveStream = GetArchiveStream ( origIndexes . Count != 1 ) ) as IDisposable ) { ArchiveOpenCallback openCallback = GetArchiveOpenCallback ( ) ; if ( ! OpenArchive ( archiveStream , openCallback ) ) { return ; } try { using ( ArchiveExtractCallback aec = GetArchiveExtractCallback ( directory , ( int ) _filesCount , origIndexes ) ) { try { CheckedExecute ( _archive . Extract ( uindexes , ( uint ) uindexes . Length , 0 , aec ) , SevenZipExtractionFailedException . DEFAULT_MESSAGE , aec ) ; } finally { FreeArchiveExtractCallback ( aec ) ; } } } catch ( Exception ) { if ( openCallback . ThrowException ( ) ) { throw ; } } } OnEvent ( ExtractionFinished , EventArgs . Empty , false ) ; } finally { if ( origIndexes . Count > 1 ) { if ( _archive != null ) { _archive . Close ( ) ; } _archiveStream = null ; _opened = false ; } } ThrowUserException ( ) ; }
Unpacks files by their indices to the specified directory.
Unpacks files by their indices to the specified directory .
directory
string
Directory where the files are to be unpacked.
Directory where the files are to be unpacked .
indexes
indexes of the files in the archive file table.
indexes of the files in the archive file table .