コード例 #1
0
        private static bool ExtractionBenchmark(string archiveFileName, Stream outStream,
                                                ref LibraryFeature?features, LibraryFeature testedFeature)
        {
            var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                GetResourceString(archiveFileName));

            try
            {
                using (var extr = new SevenZipExtractor(stream))
                {
                    extr.ExtractFile(0, outStream);
                }
            }
            catch (Exception)
            {
                return(false);
            }
            features |= testedFeature;
            return(true);
        }
コード例 #2
0
ファイル: LzmaDecodeStream.cs プロジェクト: EnergonV/BestCS
        private void ReadChunk()
        {
            long size;

            byte[] properties;
            try
            {
                properties = SevenZipExtractor.GetLzmaProperties(_input, out size);
            }
            catch (LzmaException)
            {
                _error = true;
                return;
            }
            if (!_firstChunkRead)
            {
                _commonProperties = properties;
            }
            if (_commonProperties[0] != properties[0] ||
                _commonProperties[1] != properties[1] ||
                _commonProperties[2] != properties[2] ||
                _commonProperties[3] != properties[3] ||
                _commonProperties[4] != properties[4])
            {
                _error = true;
                return;
            }
            if (_buffer.Capacity < (int)size)
            {
                _buffer.Capacity = (int)size;
            }
            _buffer.SetLength(size);
            _decoder.SetDecoderProperties(properties);
            _buffer.Position = 0;
            _decoder.Code(
                _input, _buffer, 0, size, null);
            _buffer.Position = 0;
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the ArchiveExtractCallback class
 /// </summary>
 /// <param name="archive">IInArchive interface for the archive</param>
 /// <param name="directory">Directory where files are to be unpacked to</param>
 /// <param name="filesCount">The archive files count</param>
 /// <param name="password">Password for the archive</param>
 /// <param name="extractor">The owner of the callback</param>
 /// <param name="actualIndexes">The list of actual indexes (solid archives support)</param>
 /// <param name="directoryStructure">The value indicating whether to preserve directory structure of extracted files.</param>
 public ArchiveExtractCallback(IInArchive archive, string directory, int filesCount, bool directoryStructure,
                               List <uint> actualIndexes, string password, SevenZipExtractor extractor)
     : base(password)
 {
     Init(archive, directory, filesCount, directoryStructure, actualIndexes, extractor);
 }
コード例 #4
0
 private void Init(IInArchive archive, Stream stream, int filesCount, uint fileIndex, SevenZipExtractor extractor)
 {
     CommonInit(archive, filesCount, extractor);
     _fileStream = new OutStreamWrapper(stream, false);
     _fileStream.BytesWritten += IntEventArgsHandler;
     _fileIndex = fileIndex;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the ArchiveExtractCallback class
 /// </summary>
 /// <param name="archive">IInArchive interface for the archive</param>
 /// <param name="stream">The stream where files are to be unpacked to</param>
 /// <param name="filesCount">The archive files count</param>
 /// <param name="fileIndex">The file index for the stream</param>
 /// <param name="password">Password for the archive</param>
 /// <param name="extractor">The owner of the callback</param>
 public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex, string password,
                               SevenZipExtractor extractor)
     : base(password)
 {
     Init(archive, stream, filesCount, fileIndex, extractor);
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the ArchiveExtractCallback class
 /// </summary>
 /// <param name="archive">IInArchive interface for the archive</param>
 /// <param name="stream">The stream where files are to be unpacked to</param>
 /// <param name="filesCount">The archive files count</param>
 /// <param name="fileIndex">The file index for the stream</param>
 /// <param name="extractor">The owner of the callback</param>
 public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex,
                               SevenZipExtractor extractor)
 {
     Init(archive, stream, filesCount, fileIndex, extractor);
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the ArchiveExtractCallback class
 /// </summary>
 /// <param name="archive">IInArchive interface for the archive</param>
 /// <param name="directory">Directory where files are to be unpacked to</param>
 /// <param name="filesCount">The archive files count</param>
 /// <param name="password">Password for the archive</param>
 /// <param name="extractor">The owner of the callback</param>
 /// <param name="actualIndexes">The list of actual indexes (solid archives support)</param>
 /// <param name="directoryStructure">The value indicating whether to preserve directory structure of extracted files.</param>
 public ArchiveExtractCallback(IInArchive archive, string directory, int filesCount, bool directoryStructure,
     List<uint> actualIndexes, string password, SevenZipExtractor extractor)
     : base(password)
 {
     Init(archive, directory, filesCount, directoryStructure, actualIndexes, extractor);
 }
コード例 #8
0
 private void Init(IInArchive archive, Stream stream, int filesCount, uint fileIndex, SevenZipExtractor extractor)
 {
     CommonInit(archive, filesCount, extractor);
     _fileStream = new OutStreamWrapper(stream, false);
     _fileStream.BytesWritten += IntEventArgsHandler;
     _fileIndex = fileIndex;
 }
コード例 #9
0
        private void CommonInit(IInArchive archive, int filesCount, SevenZipExtractor extractor)
        {
            _archive = archive;
            _filesCount = filesCount;
            _fakeStream = new FakeOutStreamWrapper();
            _fakeStream.BytesWritten += IntEventArgsHandler;
            _extractor = extractor;
#if !WINCE
            GC.AddMemoryPressure(MEMORY_PRESSURE);
#endif
        }
コード例 #10
0
 private void Init(IInArchive archive, string directory, int filesCount, bool directoryStructure,
     List<uint> actualIndexes, SevenZipExtractor extractor)
 {
     CommonInit(archive, filesCount, extractor);
     _directory = directory;
     _actualIndexes = actualIndexes;
     _directoryStructure = directoryStructure;
     if (!directory.EndsWith("" + Path.DirectorySeparatorChar, StringComparison.CurrentCulture))
     {
         _directory += Path.DirectorySeparatorChar;
     }
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the ArchiveExtractCallback class
 /// </summary>
 /// <param name="archive">IInArchive interface for the archive</param>
 /// <param name="stream">The stream where files are to be unpacked to</param>
 /// <param name="filesCount">The archive files count</param>
 /// <param name="fileIndex">The file index for the stream</param>
 /// <param name="password">Password for the archive</param>
 /// <param name="extractor">The owner of the callback</param>
 public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex, string password,
                               SevenZipExtractor extractor)
     : base(password)
 {
     Init(archive, stream, filesCount, fileIndex, extractor);
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the ArchiveExtractCallback class
 /// </summary>
 /// <param name="archive">IInArchive interface for the archive</param>
 /// <param name="stream">The stream where files are to be unpacked to</param>
 /// <param name="filesCount">The archive files count</param>
 /// <param name="fileIndex">The file index for the stream</param>
 /// <param name="extractor">The owner of the callback</param>
 public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex,
                               SevenZipExtractor extractor)
 {
     Init(archive, stream, filesCount, fileIndex, extractor);
 }
コード例 #13
0
ファイル: LibraryManager.cs プロジェクト: EnergonV/BestCS
 private static bool ExtractionBenchmark(string archiveFileName, Stream outStream,
     ref LibraryFeature? features, LibraryFeature testedFeature)
 {			
     var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
             GetResourceString(archiveFileName));
     try
     {
         using (var extr = new SevenZipExtractor(stream))
         {
             extr.ExtractFile(0, outStream);
         }
     }
     catch(Exception)
     {
         return false;
     }
     features |= testedFeature;
     return true;
 }
コード例 #14
0
ファイル: SevenZipCompressor.cs プロジェクト: EnergonV/BestCS
        /// <summary>
        /// Modifies the existing archive (renames files or deletes them).
        /// </summary>
        /// <param name="archiveName">The archive file name.</param>
        /// <param name="newFileNames">New file names. Null value to delete the corresponding index.</param>
        /// <param name="password">The archive password.</param>
        public void ModifyArchive(string archiveName, Dictionary<int, string> newFileNames, string password 
#if CS4 
            = ""
#endif
        )
        {
            ClearExceptions();
            if (!SevenZipLibraryManager.ModifyCapable)
            {
                throw new SevenZipLibraryException("The specified 7zip native library does not support this method.");
            }
            if (!File.Exists(archiveName))
            {
                if (!ThrowException(null, new ArgumentException("The specified archive does not exist.", "archiveName")))
                {
                    return;
                }
            }
            if (newFileNames == null || newFileNames.Count == 0)
            {
                if (!ThrowException(null, new ArgumentException("Invalid new file names.", "newFileNames")))
                {
                    return;
                }
            }
            try
            {
                using (var extr = new SevenZipExtractor(archiveName))
                {
                    _updateData = new UpdateData();
                    var archiveData = new ArchiveFileInfo[extr.ArchiveFileData.Count];
                    extr.ArchiveFileData.CopyTo(archiveData, 0);
                    _updateData.ArchiveFileData = new List<ArchiveFileInfo>(archiveData);
                }
                _updateData.FileNamesToModify = newFileNames;
                _updateData.Mode = InternalCompressionMode.Modify;
            }
            catch (SevenZipException e)
            {
                if (!ThrowException(null, e))
                {
                    return;
                }
            }
            try
            {
                ISequentialOutStream sequentialArchiveStream;
                _compressingFilesOnDisk = true;
                using ((sequentialArchiveStream = GetOutStream(GetArchiveFileStream(archiveName))) as IDisposable)
                {
                    IInStream inArchiveStream;
                    _archiveName = archiveName;
                    using ((inArchiveStream = GetInStream()) as IDisposable)
                    {
                        IOutArchive outArchive;
                        // Create IInArchive, read it and convert to IOutArchive
                        SevenZipLibraryManager.LoadLibrary(
                            this, Formats.InForOutFormats[_archiveFormat]);
                        if ((outArchive = MakeOutArchive(inArchiveStream)) == null)
                        {
                            return;
                        }
                        using (ArchiveUpdateCallback auc = GetArchiveUpdateCallback(null, 0, password))
                        {
                            UInt32 deleteCount = 0;
                            if (_updateData.FileNamesToModify != null)
                            {
#if CS4 // System.Linq of C# 4 is great
                                deleteCount = (UInt32)_updateData.FileNamesToModify.Sum(
                                    pairDeleted => pairDeleted.Value == null ? 1 : 0);
#else
                                foreach(var pairDeleted in _updateData.FileNamesToModify)
                                {
                                    if (pairDeleted.Value == null)
                                    {
                                        deleteCount++;
                                    }
                                }
#endif
                            }
                            try
                            {
                                CheckedExecute(
                                    outArchive.UpdateItems(
                                        sequentialArchiveStream, _oldFilesCount - deleteCount, auc),
                                    SevenZipCompressionFailedException.DEFAULT_MESSAGE, auc);
                            }
                            finally
                            {
                                FreeCompressionCallback(auc);
                            }
                        } 
                    }
                }
            }
            finally
            {
                SevenZipLibraryManager.FreeLibrary(this, Formats.InForOutFormats[_archiveFormat]);
                File.Delete(archiveName);
                FinalizeUpdate();
                _compressingFilesOnDisk = false;
                _updateData.FileNamesToModify = null;
                _updateData.ArchiveFileData = null;
                OnEvent(CompressionFinished, EventArgs.Empty, false);
            }
            ThrowUserException();
        }