Пример #1
0
        public override int Run(string[] remainingArguments)
        {
            if (this.OutputPath == null)
            {
                this.OutputPath = this.InputPath + ".txt";
            }
            CryptoProvider cryptoProvider = CryptoFactory.GetCryptoProvider(this.Game);
            CryptoResult   cryptoResult;

            try
            {
                cryptoResult = CryptoFileReader.ReadFile(this.InputPath, cryptoProvider);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't open input file");
                return(1);
            }
            FileStream fileStream;

            try
            {
                fileStream = File.Open(this.OutputPath, FileMode.Create, FileAccess.Write);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't create output file");
                return(1);
            }
            if (!cryptoResult.IsSignatureValid)
            {
                Console.WriteLine("Warning: signature is invalid");
            }
            string str = cryptoResult.Result;

            if (this.Prettify)
            {
                try
                {
                    str = this.GetPrettyString(str);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Warning: data is not valid JSON");
                }
            }
            byte[] bytes = Encoding.UTF8.GetBytes(str);
            fileStream.Write(bytes, 0, bytes.Length);
            fileStream.Close();
            return(0);
        }
Пример #2
0
        public override int Run(string[] remainingArguments)
        {
            if (this.OutputPath == null)
            {
                this.OutputPath = this.InputPath + ".sav";
            }
            FileStream fileStream;

            try
            {
                fileStream = File.OpenRead(this.InputPath);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't open input file");
                return(1);
            }
            byte[] numArray = new byte[fileStream.Length];
            fileStream.Read(numArray, 0, (int)fileStream.Length);
            fileStream.Close();
            string minifiedString = Encoding.UTF8.GetString(numArray, 0, numArray.Length);

            if (this.Minify)
            {
                try
                {
                    minifiedString = this.GetMinifiedString(minifiedString);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Warning: data is not valid JSON");
                }
            }
            CryptoProvider cryptoProvider = CryptoFactory.GetCryptoProvider(this.Game);

            try
            {
                CryptoFileWriter.Write(this.OutputPath, minifiedString, false, cryptoProvider);
            }
            catch (IOException ex)
            {
                Console.WriteLine("Can't create output file");
                return(1);
            }
            return(0);
        }