예제 #1
0
파일: LzmaAlone.cs 프로젝트: ChewSo/omaha
		static int Main2(string[] args)
		{
			System.Console.WriteLine("\nLZMA# 4.61  2008-11-23\n");

			if (args.Length == 0)
			{
				PrintHelp();
				return 0;
			}

			SwitchForm[] kSwitchForms = new SwitchForm[13];
			int sw = 0;
			kSwitchForms[sw++] = new SwitchForm("?", SwitchType.Simple, false);
			kSwitchForms[sw++] = new SwitchForm("H", SwitchType.Simple, false);
			kSwitchForms[sw++] = new SwitchForm("A", SwitchType.UnLimitedPostString, false, 1);
			kSwitchForms[sw++] = new SwitchForm("D", SwitchType.UnLimitedPostString, false, 1);
			kSwitchForms[sw++] = new SwitchForm("FB", SwitchType.UnLimitedPostString, false, 1);
			kSwitchForms[sw++] = new SwitchForm("LC", SwitchType.UnLimitedPostString, false, 1);
			kSwitchForms[sw++] = new SwitchForm("LP", SwitchType.UnLimitedPostString, false, 1);
			kSwitchForms[sw++] = new SwitchForm("PB", SwitchType.UnLimitedPostString, false, 1);
			kSwitchForms[sw++] = new SwitchForm("MF", SwitchType.UnLimitedPostString, false, 1);
			kSwitchForms[sw++] = new SwitchForm("EOS", SwitchType.Simple, false);
			kSwitchForms[sw++] = new SwitchForm("SI", SwitchType.Simple, false);
			kSwitchForms[sw++] = new SwitchForm("SO", SwitchType.Simple, false);
			kSwitchForms[sw++] = new SwitchForm("T", SwitchType.UnLimitedPostString, false, 1);


			Parser parser = new Parser(sw);
			try
			{
				parser.ParseStrings(kSwitchForms, args);
			}
			catch
			{
				return IncorrectCommand();
			}

			if (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)
			{
				PrintHelp();
				return 0;
			}

			System.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;

			int paramIndex = 0;
			if (paramIndex >= nonSwitchStrings.Count)
				return IncorrectCommand();
			string command = (string)nonSwitchStrings[paramIndex++];
			command = command.ToLower();

			bool dictionaryIsDefined = false;
			Int32 dictionary = 1 << 21;
			if (parser[(int)Key.Dictionary].ThereIs)
			{
				Int32 dicLog;
				if (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))
					IncorrectCommand();
				dictionary = (Int32)1 << dicLog;
				dictionaryIsDefined = true;
			}
			string mf = "bt4";
			if (parser[(int)Key.MatchFinder].ThereIs)
				mf = (string)parser[(int)Key.MatchFinder].PostStrings[0];
			mf = mf.ToLower();

			if (command == "b")
			{
				const Int32 kNumDefaultItereations = 10;
				Int32 numIterations = kNumDefaultItereations;
				if (paramIndex < nonSwitchStrings.Count)
					if (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))
						numIterations = kNumDefaultItereations;
				return LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary);
			}

			string train = "";
			if (parser[(int)Key.Train].ThereIs)
				train = (string)parser[(int)Key.Train].PostStrings[0];

			bool encodeMode = false;
			if (command == "e")
				encodeMode = true;
			else if (command == "d")
				encodeMode = false;
			else
				IncorrectCommand();

			bool stdInMode = parser[(int)Key.StdIn].ThereIs;
			bool stdOutMode = parser[(int)Key.StdOut].ThereIs;

			Stream inStream = null;
			if (stdInMode)
			{
				throw (new Exception("Not implemeted"));
			}
			else
			{
				if (paramIndex >= nonSwitchStrings.Count)
					IncorrectCommand();
				string inputName = (string)nonSwitchStrings[paramIndex++];
				inStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);
			}

			FileStream outStream = null;
			if (stdOutMode)
			{
				throw (new Exception("Not implemeted"));
			}
			else
			{
				if (paramIndex >= nonSwitchStrings.Count)
					IncorrectCommand();
				string outputName = (string)nonSwitchStrings[paramIndex++];
				outStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);
			}

			FileStream trainStream = null;
			if (train.Length != 0)
				trainStream = new FileStream(train, FileMode.Open, FileAccess.Read);

			if (encodeMode)
			{
				if (!dictionaryIsDefined)
					dictionary = 1 << 23;

				Int32 posStateBits = 2;
				Int32 litContextBits = 3; // for normal files
				// UInt32 litContextBits = 0; // for 32-bit data
				Int32 litPosBits = 0;
				// UInt32 litPosBits = 2; // for 32-bit data
				Int32 algorithm = 2;
				Int32 numFastBytes = 128;

				bool eos = parser[(int)Key.EOS].ThereIs || stdInMode;

				if (parser[(int)Key.Mode].ThereIs)
					if (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))
						IncorrectCommand();

				if (parser[(int)Key.FastBytes].ThereIs)
					if (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))
						IncorrectCommand();
				if (parser[(int)Key.LitContext].ThereIs)
					if (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))
						IncorrectCommand();
				if (parser[(int)Key.LitPos].ThereIs)
					if (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))
						IncorrectCommand();
				if (parser[(int)Key.PosBits].ThereIs)
					if (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))
						IncorrectCommand();

				CoderPropID[] propIDs = 
				{
					CoderPropID.DictionarySize,
					CoderPropID.PosStateBits,
					CoderPropID.LitContextBits,
					CoderPropID.LitPosBits,
					CoderPropID.Algorithm,
					CoderPropID.NumFastBytes,
					CoderPropID.MatchFinder,
					CoderPropID.EndMarker
				};
				object[] properties = 
				{
					(Int32)(dictionary),
					(Int32)(posStateBits),
					(Int32)(litContextBits),
					(Int32)(litPosBits),
					(Int32)(algorithm),
					(Int32)(numFastBytes),
					mf,
					eos
				};

				Compression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();
				encoder.SetCoderProperties(propIDs, properties);
				encoder.WriteCoderProperties(outStream);
				Int64 fileSize;
				if (eos || stdInMode)
					fileSize = -1;
				else
					fileSize = inStream.Length;
				for (int i = 0; i < 8; i++)
					outStream.WriteByte((Byte)(fileSize >> (8 * i)));
				if (trainStream != null)
				{
					CDoubleStream doubleStream = new CDoubleStream();
					doubleStream.s1 = trainStream;
					doubleStream.s2 = inStream;
					doubleStream.fileIndex = 0;
					inStream = doubleStream;
					long trainFileSize = trainStream.Length;
					doubleStream.skipSize = 0;
					if (trainFileSize > dictionary)
						doubleStream.skipSize = trainFileSize - dictionary;
					trainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);
					encoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));
				}
				encoder.Code(inStream, outStream, -1, -1, null);
			}
			else if (command == "d")
			{
				byte[] properties = new byte[5];
				if (inStream.Read(properties, 0, 5) != 5)
					throw (new Exception("input .lzma is too short"));
				Compression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();
				decoder.SetDecoderProperties(properties);
				if (trainStream != null)
				{
					if (!decoder.Train(trainStream))
						throw (new Exception("can't train"));
				}
				long outSize = 0;
				for (int i = 0; i < 8; i++)
				{
					int v = inStream.ReadByte();
					if (v < 0)
						throw (new Exception("Can't Read 1"));
					outSize |= ((long)(byte)v) << (8 * i);
				}
				long compressedSize = inStream.Length - inStream.Position;
				decoder.Code(inStream, outStream, compressedSize, outSize, null);
			}
			else
				throw (new Exception("Command Error"));
			return 0;
		}
예제 #2
0
        public static int Main2(string[] args)
        {
            System.Console.WriteLine("\nLZMA# 4.61  2008-11-23\n");

            if (args.Length == 0)
            {
                PrintHelp();
                return(0);
            }

            SwitchForm[] kSwitchForms = new SwitchForm[13];
            int          sw           = 0;

            kSwitchForms[sw++] = new SwitchForm("?", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("H", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("A", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("D", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("FB", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("LC", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("LP", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("PB", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("MF", SwitchType.UnLimitedPostString, false, 1);
            kSwitchForms[sw++] = new SwitchForm("EOS", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("SI", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("SO", SwitchType.Simple, false);
            kSwitchForms[sw++] = new SwitchForm("T", SwitchType.UnLimitedPostString, false, 1);


            Parser parser = new Parser(sw);

            try
            {
                parser.ParseStrings(kSwitchForms, args);
            }
            catch
            {
                return(IncorrectCommand());
            }

            if (parser[(int)Key.Help1].ThereIs || parser[(int)Key.Help2].ThereIs)
            {
                PrintHelp();
                return(0);
            }

            System.Collections.ArrayList nonSwitchStrings = parser.NonSwitchStrings;

            int paramIndex = 0;

            if (paramIndex >= nonSwitchStrings.Count)
            {
                return(IncorrectCommand());
            }
            string command = (string)nonSwitchStrings[paramIndex++];

            command = command.ToLower();

            bool  dictionaryIsDefined = false;
            Int32 dictionary          = 1 << 21;

            if (parser[(int)Key.Dictionary].ThereIs)
            {
                Int32 dicLog;
                if (!GetNumber((string)parser[(int)Key.Dictionary].PostStrings[0], out dicLog))
                {
                    IncorrectCommand();
                }
                dictionary          = (Int32)1 << dicLog;
                dictionaryIsDefined = true;
            }
            string mf = "bt4";

            if (parser[(int)Key.MatchFinder].ThereIs)
            {
                mf = (string)parser[(int)Key.MatchFinder].PostStrings[0];
            }
            mf = mf.ToLower();

            if (command == "b")
            {
                const Int32 kNumDefaultItereations = 10;
                Int32       numIterations          = kNumDefaultItereations;
                if (paramIndex < nonSwitchStrings.Count)
                {
                    if (!GetNumber((string)nonSwitchStrings[paramIndex++], out numIterations))
                    {
                        numIterations = kNumDefaultItereations;
                    }
                }
                return(LzmaBench.LzmaBenchmark(numIterations, (UInt32)dictionary));
            }

            string train = "";

            if (parser[(int)Key.Train].ThereIs)
            {
                train = (string)parser[(int)Key.Train].PostStrings[0];
            }

            bool encodeMode = false;

            if (command == "e")
            {
                encodeMode = true;
            }
            else if (command == "d")
            {
                encodeMode = false;
            }
            else
            {
                IncorrectCommand();
            }

            bool stdInMode  = parser[(int)Key.StdIn].ThereIs;
            bool stdOutMode = parser[(int)Key.StdOut].ThereIs;

            Stream inStream = null;

            if (stdInMode)
            {
                throw (new Exception("Not implemeted"));
            }
            else
            {
                if (paramIndex >= nonSwitchStrings.Count)
                {
                    IncorrectCommand();
                }
                string inputName = (string)nonSwitchStrings[paramIndex++];
                inStream = new FileStream(inputName, FileMode.Open, FileAccess.Read);
            }

            FileStream outStream = null;

            if (stdOutMode)
            {
                throw (new Exception("Not implemeted"));
            }
            else
            {
                if (paramIndex >= nonSwitchStrings.Count)
                {
                    IncorrectCommand();
                }
                string outputName = (string)nonSwitchStrings[paramIndex++];
                outStream = new FileStream(outputName, FileMode.Create, FileAccess.Write);
            }

            FileStream trainStream = null;

            if (train.Length != 0)
            {
                trainStream = new FileStream(train, FileMode.Open, FileAccess.Read);
            }

            if (encodeMode)
            {
                if (!dictionaryIsDefined)
                {
                    dictionary = 1 << 23;
                }

                Int32 posStateBits   = 2;
                Int32 litContextBits = 3;                 // for normal files
                // UInt32 litContextBits = 0; // for 32-bit data
                Int32 litPosBits = 0;
                // UInt32 litPosBits = 2; // for 32-bit data
                Int32 algorithm    = 2;
                Int32 numFastBytes = 128;

                bool eos = parser[(int)Key.EOS].ThereIs || stdInMode;

                if (parser[(int)Key.Mode].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.Mode].PostStrings[0], out algorithm))
                    {
                        IncorrectCommand();
                    }
                }

                if (parser[(int)Key.FastBytes].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.FastBytes].PostStrings[0], out numFastBytes))
                    {
                        IncorrectCommand();
                    }
                }
                if (parser[(int)Key.LitContext].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.LitContext].PostStrings[0], out litContextBits))
                    {
                        IncorrectCommand();
                    }
                }
                if (parser[(int)Key.LitPos].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.LitPos].PostStrings[0], out litPosBits))
                    {
                        IncorrectCommand();
                    }
                }
                if (parser[(int)Key.PosBits].ThereIs)
                {
                    if (!GetNumber((string)parser[(int)Key.PosBits].PostStrings[0], out posStateBits))
                    {
                        IncorrectCommand();
                    }
                }

                CoderPropID[] propIDs =
                {
                    CoderPropID.DictionarySize,
                    CoderPropID.PosStateBits,
                    CoderPropID.LitContextBits,
                    CoderPropID.LitPosBits,
                    CoderPropID.Algorithm,
                    CoderPropID.NumFastBytes,
                    CoderPropID.MatchFinder,
                    CoderPropID.EndMarker
                };
                object[] properties =
                {
                    (Int32)(dictionary),
                    (Int32)(posStateBits),
                    (Int32)(litContextBits),
                    (Int32)(litPosBits),
                    (Int32)(algorithm),
                    (Int32)(numFastBytes),
                    mf,
                    eos
                };

                Compression.LZMA.Encoder encoder = new Compression.LZMA.Encoder();
                encoder.SetCoderProperties(propIDs, properties);
                encoder.WriteCoderProperties(outStream);
                Int64 fileSize;
                if (eos || stdInMode)
                {
                    fileSize = -1;
                }
                else
                {
                    fileSize = inStream.Length;
                }
                for (int i = 0; i < 8; i++)
                {
                    outStream.WriteByte((Byte)(fileSize >> (8 * i)));
                }
                if (trainStream != null)
                {
                    CDoubleStream doubleStream = new CDoubleStream();
                    doubleStream.s1        = trainStream;
                    doubleStream.s2        = inStream;
                    doubleStream.fileIndex = 0;
                    inStream = doubleStream;
                    long trainFileSize = trainStream.Length;
                    doubleStream.skipSize = 0;
                    if (trainFileSize > dictionary)
                    {
                        doubleStream.skipSize = trainFileSize - dictionary;
                    }
                    trainStream.Seek(doubleStream.skipSize, SeekOrigin.Begin);
                    encoder.SetTrainSize((uint)(trainFileSize - doubleStream.skipSize));
                }
                encoder.Code(inStream, outStream, -1, -1, null);
            }
            else if (command == "d")
            {
                byte[] properties = new byte[5];
                if (inStream.Read(properties, 0, 5) != 5)
                {
                    throw (new Exception("input .lzma is too short"));
                }
                Compression.LZMA.Decoder decoder = new Compression.LZMA.Decoder();
                decoder.SetDecoderProperties(properties);
                if (trainStream != null)
                {
                    if (!decoder.Train(trainStream))
                    {
                        throw (new Exception("can't train"));
                    }
                }
                long outSize = 0;
                for (int i = 0; i < 8; i++)
                {
                    int v = inStream.ReadByte();
                    if (v < 0)
                    {
                        throw (new Exception("Can't Read 1"));
                    }
                    outSize |= ((long)(byte)v) << (8 * i);
                }
                long compressedSize = inStream.Length - inStream.Position;
                decoder.Code(inStream, outStream, compressedSize, outSize, null);
            }
            else
            {
                throw (new Exception("Command Error"));
            }
            return(0);
        }
예제 #3
0
        private static int Main2(string[] args)
        {
            Console.WriteLine("\nLZMA# 4.61  2008-11-23\n");
            if (args.Length == 0)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            SwitchForm[] switchForms = new SwitchForm[13];
            int          num1        = 0;

            SwitchForm[] switchFormArray1 = switchForms;
            int          index1           = num1;
            int          num2             = index1 + 1;
            SwitchForm   switchForm1      = new SwitchForm("?", SwitchType.Simple, false);

            switchFormArray1[index1] = switchForm1;
            SwitchForm[] switchFormArray2 = switchForms;
            int          index2           = num2;
            int          num3             = index2 + 1;
            SwitchForm   switchForm2      = new SwitchForm("H", SwitchType.Simple, false);

            switchFormArray2[index2] = switchForm2;
            SwitchForm[] switchFormArray3 = switchForms;
            int          index3           = num3;
            int          num4             = index3 + 1;
            SwitchForm   switchForm3      = new SwitchForm("A", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray3[index3] = switchForm3;
            SwitchForm[] switchFormArray4 = switchForms;
            int          index4           = num4;
            int          num5             = index4 + 1;
            SwitchForm   switchForm4      = new SwitchForm("D", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray4[index4] = switchForm4;
            SwitchForm[] switchFormArray5 = switchForms;
            int          index5           = num5;
            int          num6             = index5 + 1;
            SwitchForm   switchForm5      = new SwitchForm("FB", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray5[index5] = switchForm5;
            SwitchForm[] switchFormArray6 = switchForms;
            int          index6           = num6;
            int          num7             = index6 + 1;
            SwitchForm   switchForm6      = new SwitchForm("LC", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray6[index6] = switchForm6;
            SwitchForm[] switchFormArray7 = switchForms;
            int          index7           = num7;
            int          num8             = index7 + 1;
            SwitchForm   switchForm7      = new SwitchForm("LP", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray7[index7] = switchForm7;
            SwitchForm[] switchFormArray8 = switchForms;
            int          index8           = num8;
            int          num9             = index8 + 1;
            SwitchForm   switchForm8      = new SwitchForm("PB", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray8[index8] = switchForm8;
            SwitchForm[] switchFormArray9 = switchForms;
            int          index9           = num9;
            int          num10            = index9 + 1;
            SwitchForm   switchForm9      = new SwitchForm("MF", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray9[index9] = switchForm9;
            SwitchForm[] switchFormArray10 = switchForms;
            int          index10           = num10;
            int          num11             = index10 + 1;
            SwitchForm   switchForm10      = new SwitchForm("EOS", SwitchType.Simple, false);

            switchFormArray10[index10] = switchForm10;
            SwitchForm[] switchFormArray11 = switchForms;
            int          index11           = num11;
            int          num12             = index11 + 1;
            SwitchForm   switchForm11      = new SwitchForm("SI", SwitchType.Simple, false);

            switchFormArray11[index11] = switchForm11;
            SwitchForm[] switchFormArray12 = switchForms;
            int          index12           = num12;
            int          num13             = index12 + 1;
            SwitchForm   switchForm12      = new SwitchForm("SO", SwitchType.Simple, false);

            switchFormArray12[index12] = switchForm12;
            SwitchForm[] switchFormArray13 = switchForms;
            int          index13           = num13;
            int          numSwitches       = index13 + 1;
            SwitchForm   switchForm13      = new SwitchForm("T", SwitchType.UnLimitedPostString, false, 1);

            switchFormArray13[index13] = switchForm13;
            Parser parser = new Parser(numSwitches);

            try
            {
                parser.ParseStrings(switchForms, args);
            }
            catch
            {
                return(LzmaAlone.IncorrectCommand());
            }
            if (parser[0].ThereIs || parser[1].ThereIs)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            ArrayList nonSwitchStrings = parser.NonSwitchStrings;
            int       num14            = 0;

            if (num14 >= nonSwitchStrings.Count)
            {
                return(LzmaAlone.IncorrectCommand());
            }
            ArrayList arrayList1 = nonSwitchStrings;
            int       index14    = num14;
            int       num15      = index14 + 1;
            string    lower1     = ((string)arrayList1[index14]).ToLower();
            bool      flag1      = false;
            int       num16      = 2097152;

            if (parser[3].ThereIs)
            {
                int v;
                if (!LzmaAlone.GetNumber((string)parser[3].PostStrings[0], out v))
                {
                    LzmaAlone.IncorrectCommand();
                }
                num16 = 1 << v;
                flag1 = true;
            }
            string str = "bt4";

            if (parser[8].ThereIs)
            {
                str = (string)parser[8].PostStrings[0];
            }
            string lower2 = str.ToLower();
            int    num17;

            if (lower1 == "b")
            {
                int v = 10;
                if (num15 < nonSwitchStrings.Count)
                {
                    ArrayList arrayList2 = nonSwitchStrings;
                    int       index15    = num15;
                    num17 = index15 + 1;
                    if (!LzmaAlone.GetNumber((string)arrayList2[index15], out v))
                    {
                        v = 10;
                    }
                }
                return(LzmaBench.LzmaBenchmark(v, (uint)num16));
            }
            string path = "";

            if (parser[12].ThereIs)
            {
                path = (string)parser[12].PostStrings[0];
            }
            bool flag2 = false;

            if (lower1 == "e")
            {
                flag2 = true;
            }
            else if (lower1 == "d")
            {
                flag2 = false;
            }
            else
            {
                LzmaAlone.IncorrectCommand();
            }
            bool thereIs = parser[10].ThereIs;
            int  num18   = parser[11].ThereIs ? 1 : 0;

            if (thereIs)
            {
                throw new Exception("Not implemeted");
            }
            if (num15 >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            ArrayList arrayList3 = nonSwitchStrings;
            int       index16    = num15;
            int       num19      = index16 + 1;
            Stream    inStream   = (Stream) new FileStream((string)arrayList3[index16], FileMode.Open, FileAccess.Read);

            if (num18 != 0)
            {
                throw new Exception("Not implemeted");
            }
            if (num19 >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            ArrayList arrayList4 = nonSwitchStrings;
            int       index17    = num19;

            num17 = index17 + 1;
            FileStream fileStream1 = new FileStream((string)arrayList4[index17], FileMode.Create, FileAccess.Write);
            FileStream fileStream2 = (FileStream)null;

            if (path.Length != 0)
            {
                fileStream2 = new FileStream(path, FileMode.Open, FileAccess.Read);
            }
            if (flag2)
            {
                if (!flag1)
                {
                    num16 = 8388608;
                }
                int  v1    = 2;
                int  v2    = 3;
                int  v3    = 0;
                int  v4    = 2;
                int  v5    = 128;
                bool flag3 = parser[9].ThereIs | thereIs;
                if (parser[2].ThereIs && !LzmaAlone.GetNumber((string)parser[2].PostStrings[0], out v4))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[4].ThereIs && !LzmaAlone.GetNumber((string)parser[4].PostStrings[0], out v5))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[5].ThereIs && !LzmaAlone.GetNumber((string)parser[5].PostStrings[0], out v2))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[6].ThereIs && !LzmaAlone.GetNumber((string)parser[6].PostStrings[0], out v3))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[7].ThereIs && !LzmaAlone.GetNumber((string)parser[7].PostStrings[0], out v1))
                {
                    LzmaAlone.IncorrectCommand();
                }
                CoderPropID[] propIDs = new CoderPropID[8]
                {
                    CoderPropID.DictionarySize,
                    CoderPropID.PosStateBits,
                    CoderPropID.LitContextBits,
                    CoderPropID.LitPosBits,
                    CoderPropID.Algorithm,
                    CoderPropID.NumFastBytes,
                    CoderPropID.MatchFinder,
                    CoderPropID.EndMarker
                };
                object[] properties = new object[8]
                {
                    (object)num16,
                    (object)v1,
                    (object)v2,
                    (object)v3,
                    (object)v4,
                    (object)v5,
                    (object)lower2,
                    (object)flag3
                };
                Encoder encoder = new Encoder();
                encoder.SetCoderProperties(propIDs, properties);
                encoder.WriteCoderProperties((Stream)fileStream1);
                long num20 = !(flag3 | thereIs) ? inStream.Length : -1L;
                for (int index15 = 0; index15 < 8; ++index15)
                {
                    fileStream1.WriteByte((byte)(num20 >> 8 * index15));
                }
                if (fileStream2 != null)
                {
                    CDoubleStream cdoubleStream = new CDoubleStream();
                    cdoubleStream.s1        = (Stream)fileStream2;
                    cdoubleStream.s2        = inStream;
                    cdoubleStream.fileIndex = 0;
                    inStream = (Stream)cdoubleStream;
                    long length = fileStream2.Length;
                    cdoubleStream.skipSize = 0L;
                    if (length > (long)num16)
                    {
                        cdoubleStream.skipSize = length - (long)num16;
                    }
                    fileStream2.Seek(cdoubleStream.skipSize, SeekOrigin.Begin);
                    encoder.SetTrainSize((uint)(length - cdoubleStream.skipSize));
                }
                encoder.Code(inStream, (Stream)fileStream1, -1L, -1L, (ICodeProgress)null);
            }
            else
            {
                if (!(lower1 == "d"))
                {
                    throw new Exception("Command Error");
                }
                byte[] numArray = new byte[5];
                if (inStream.Read(numArray, 0, 5) != 5)
                {
                    throw new Exception("input .lzma is too short");
                }
                Decoder decoder = new Decoder();
                decoder.SetDecoderProperties(numArray);
                if (fileStream2 != null && !decoder.Train((Stream)fileStream2))
                {
                    throw new Exception("can't train");
                }
                long outSize = 0;
                for (int index15 = 0; index15 < 8; ++index15)
                {
                    int num20 = inStream.ReadByte();
                    if (num20 < 0)
                    {
                        throw new Exception("Can't Read 1");
                    }
                    outSize |= (long)(byte)num20 << 8 * index15;
                }
                long inSize = inStream.Length - inStream.Position;
                decoder.Code(inStream, (Stream)fileStream1, inSize, outSize, (ICodeProgress)null);
            }
            return(0);
        }
예제 #4
0
        private static int Main2(string[] args)
        {
            Console.WriteLine("\nLZMA# 4.61  2008-11-23\n");
            if (args.Length == 0)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            SwitchForm[] array       = new SwitchForm[13];
            int          numSwitches = 0;

            array[numSwitches++] = new SwitchForm("?", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("H", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("A", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("D", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("FB", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("LC", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("LP", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("PB", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("MF", SwitchType.UnLimitedPostString, false, 1);
            array[numSwitches++] = new SwitchForm("EOS", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("SI", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("SO", SwitchType.Simple, false);
            array[numSwitches++] = new SwitchForm("T", SwitchType.UnLimitedPostString, false, 1);
            Parser parser = new Parser(numSwitches);

            try
            {
                parser.ParseStrings(array, args);
            }
            catch
            {
                int result = LzmaAlone.IncorrectCommand();
                return(result);
            }
            if (parser[0].ThereIs || parser[1].ThereIs)
            {
                LzmaAlone.PrintHelp();
                return(0);
            }
            ArrayList nonSwitchStrings = parser.NonSwitchStrings;
            int       num = 0;

            if (num >= nonSwitchStrings.Count)
            {
                return(LzmaAlone.IncorrectCommand());
            }
            string text = (string)nonSwitchStrings[num++];

            text = text.ToLower();
            bool flag = false;
            int  num2 = 2097152;

            if (parser[3].ThereIs)
            {
                int num3;
                if (!LzmaAlone.GetNumber((string)parser[3].PostStrings[0], out num3))
                {
                    LzmaAlone.IncorrectCommand();
                }
                num2 = 1 << num3;
                flag = true;
            }
            string text2 = "bt4";

            if (parser[8].ThereIs)
            {
                text2 = (string)parser[8].PostStrings[0];
            }
            text2 = text2.ToLower();
            if (text == "b")
            {
                int numIterations = 10;
                if (num < nonSwitchStrings.Count && !LzmaAlone.GetNumber((string)nonSwitchStrings[num++], out numIterations))
                {
                    numIterations = 10;
                }
                return(LzmaBench.LzmaBenchmark(numIterations, (uint)num2));
            }
            string text3 = string.Empty;

            if (parser[12].ThereIs)
            {
                text3 = (string)parser[12].PostStrings[0];
            }
            bool flag2 = false;

            if (text == "e")
            {
                flag2 = true;
            }
            else if (text == "d")
            {
                flag2 = false;
            }
            else
            {
                LzmaAlone.IncorrectCommand();
            }
            bool thereIs  = parser[10].ThereIs;
            bool thereIs2 = parser[11].ThereIs;

            if (thereIs)
            {
                throw new Exception("Not implemeted");
            }
            if (num >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            string path   = (string)nonSwitchStrings[num++];
            Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read);

            if (thereIs2)
            {
                throw new Exception("Not implemeted");
            }
            if (num >= nonSwitchStrings.Count)
            {
                LzmaAlone.IncorrectCommand();
            }
            string     path2       = (string)nonSwitchStrings[num++];
            FileStream fileStream  = new FileStream(path2, FileMode.Create, FileAccess.Write);
            FileStream fileStream2 = null;

            if (text3.Length != 0)
            {
                fileStream2 = new FileStream(text3, FileMode.Open, FileAccess.Read);
            }
            if (flag2)
            {
                if (!flag)
                {
                    num2 = 8388608;
                }
                int  num4  = 2;
                int  num5  = 3;
                int  num6  = 0;
                int  num7  = 2;
                int  num8  = 128;
                bool flag3 = parser[9].ThereIs || thereIs;
                if (parser[2].ThereIs && !LzmaAlone.GetNumber((string)parser[2].PostStrings[0], out num7))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[4].ThereIs && !LzmaAlone.GetNumber((string)parser[4].PostStrings[0], out num8))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[5].ThereIs && !LzmaAlone.GetNumber((string)parser[5].PostStrings[0], out num5))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[6].ThereIs && !LzmaAlone.GetNumber((string)parser[6].PostStrings[0], out num6))
                {
                    LzmaAlone.IncorrectCommand();
                }
                if (parser[7].ThereIs && !LzmaAlone.GetNumber((string)parser[7].PostStrings[0], out num4))
                {
                    LzmaAlone.IncorrectCommand();
                }
                CoderPropID[] propIDs = new CoderPropID[]
                {
                    CoderPropID.DictionarySize,
                    CoderPropID.PosStateBits,
                    CoderPropID.LitContextBits,
                    CoderPropID.LitPosBits,
                    CoderPropID.Algorithm,
                    CoderPropID.NumFastBytes,
                    CoderPropID.MatchFinder,
                    CoderPropID.EndMarker
                };
                object[] properties = new object[]
                {
                    num2,
                    num4,
                    num5,
                    num6,
                    num7,
                    num8,
                    text2,
                    flag3
                };
                Encoder encoder = new Encoder();
                encoder.SetCoderProperties(propIDs, properties);
                encoder.WriteCoderProperties(fileStream);
                long num9;
                if (flag3 || thereIs)
                {
                    num9 = -1L;
                }
                else
                {
                    num9 = stream.Length;
                }
                for (int i = 0; i < 8; i++)
                {
                    fileStream.WriteByte((byte)(num9 >> 8 * i));
                }
                if (fileStream2 != null)
                {
                    CDoubleStream cDoubleStream = new CDoubleStream();
                    cDoubleStream.s1        = fileStream2;
                    cDoubleStream.s2        = stream;
                    cDoubleStream.fileIndex = 0;
                    stream = cDoubleStream;
                    long length = fileStream2.Length;
                    cDoubleStream.skipSize = 0L;
                    if (length > (long)num2)
                    {
                        cDoubleStream.skipSize = length - (long)num2;
                    }
                    fileStream2.Seek(cDoubleStream.skipSize, SeekOrigin.Begin);
                    encoder.SetTrainSize((uint)(length - cDoubleStream.skipSize));
                }
                encoder.Code(stream, fileStream, -1L, -1L, null);
            }
            else
            {
                if (!(text == "d"))
                {
                    throw new Exception("Command Error");
                }
                byte[] array2 = new byte[5];
                if (stream.Read(array2, 0, 5) != 5)
                {
                    throw new Exception("input .lzma is too short");
                }
                Decoder decoder = new Decoder();
                decoder.SetDecoderProperties(array2);
                if (fileStream2 != null && !decoder.Train(fileStream2))
                {
                    throw new Exception("can't train");
                }
                long num10 = 0L;
                for (int j = 0; j < 8; j++)
                {
                    int num11 = stream.ReadByte();
                    if (num11 < 0)
                    {
                        throw new Exception("Can't Read 1");
                    }
                    num10 |= (long)((byte)num11) << 8 * j;
                }
                long inSize = stream.Length - stream.Position;
                decoder.Code(stream, fileStream, inSize, num10, null);
            }
            return(0);
        }