コード例 #1
0
        /// <summary>
        /// Constructs a new zip instance.
        /// If the file exists and has a non-zero length we read it,
        /// otherwise we create a new archive.
        /// </summary>
        /// <param name="filename">The name of the file to read or write</param>
        /// <param name="options">The options passed on the commandline</param>
        public SevenZipCompression(string filename, Dictionary <string, string> options)
        {
            m_threadCount = DEFAULT_THREAD_COUNT;

            string threadCountSetting;
            int    threadCountValue;

            if (options != null &&
                options.TryGetValue(THREAD_COUNT_OPTION, out threadCountSetting) &&
                Int32.TryParse(threadCountSetting, out threadCountValue) &&
                threadCountValue > 0)
            {
                // arbitrary limit to avoid stupid mistakes
                if (threadCountValue > MAX_THREAD_COUNT)
                {
                    threadCountValue = MAX_THREAD_COUNT;
                }

                m_threadCount = threadCountValue;
            }

            string cplvl;
            int    tmplvl;

            if (options.TryGetValue(COMPRESSION_LEVEL_OPTION, out cplvl) && int.TryParse(cplvl, out tmplvl))
            {
                tmplvl = Math.Max(Math.Min(9, tmplvl), 0);
            }
            else
            {
                tmplvl = DEFAULT_COMPRESSION_LEVEL;
            }

            m_encoderProps = new ManagedLzma.LZMA.Master.LZMA.CLzma2EncProps();
            m_encoderProps.Lzma2EncProps_Init();

            m_encoderProps.mLzmaProps.mLevel = tmplvl;
            m_encoderProps.mLzmaProps.mAlgo  = Library.Utility.Utility.ParseBoolOption(options, COMPRESSION_FASTALGO_OPTION) ? 0 : 1;

            var file = new FileInfo(filename);

            if (file.Exists && file.Length > 0)
            {
                InitializeArchiveReader(filename);
            }
            else
            {
                InitializeArchiveWriter(filename);
            }
        }
コード例 #2
0
        /// <summary>
        /// Constructs a new zip instance.
        /// If the file exists and has a non-zero length we read it,
        /// otherwise we create a new archive.
        /// </summary>
        /// <param name="filename">The name of the file to read or write</param>
        /// <param name="options">The options passed on the commandline</param>
        public SevenZipCompression(string filename, Dictionary<string, string> options)
        {
            m_threadCount = DEFAULT_THREAD_COUNT;

            string threadCountSetting;
            int threadCountValue;
            if(options != null
                && options.TryGetValue(THREAD_COUNT_OPTION, out threadCountSetting)
                && Int32.TryParse(threadCountSetting, out threadCountValue)
                && threadCountValue > 0)
            {
                // arbitrary limit to avoid stupid mistakes
                if(threadCountValue > MAX_THREAD_COUNT)
                    threadCountValue = MAX_THREAD_COUNT;

                m_threadCount = threadCountValue;
            }
                
            string cplvl;
            int tmplvl;
            if (options.TryGetValue(COMPRESSION_LEVEL_OPTION, out cplvl) && int.TryParse(cplvl, out tmplvl))
                tmplvl = Math.Max(Math.Min(9, tmplvl), 0);
            else
                tmplvl = DEFAULT_COMPRESSION_LEVEL;

            m_encoderProps = new ManagedLzma.LZMA.Master.LZMA.CLzma2EncProps();
            m_encoderProps.Lzma2EncProps_Init();

            m_encoderProps.mLzmaProps.mLevel = tmplvl;
            m_encoderProps.mLzmaProps.mAlgo = Library.Utility.Utility.ParseBoolOption(options, COMPRESSION_FASTALGO_OPTION) ? 0 : 1;
                
            var file = new FileInfo(filename);
            if(file.Exists && file.Length > 0)
                InitializeArchiveReader(filename);
            else
                InitializeArchiveWriter(filename);
        }