示例#1
0
        private static void Run(string[] args)
        {
            switch (args[0])
            {
            case "d":
                var encSave = File.ReadAllBytes(args[1]);
                File.WriteAllBytes(args[2], Encryption.DecryptSave(encSave));
                break;

            case "e":
                var decSave = File.ReadAllBytes(args[1]);
                File.WriteAllBytes(args[2], Encryption.EncryptSave(decSave));
                break;

            case "x":
                var savex  = new SaveManager(File.ReadAllBytes(args[1]));
                var output = Json.Serialize(savex);
                File.WriteAllText(args[2], output);
                break;

            case "i":
                string      import = File.ReadAllText(args[1]);
                SaveManager savei  = Json.DeSerialize(import);
                File.WriteAllBytes(args[2], savei.Export());
                break;

            case "s":
                var save = new SaveManager(File.ReadAllBytes(args[1]));

                for (int i = 3; i < args.Length; i++)
                {
                    Scripting.RunScript(save.SerializeData, args[i]);
                }

                File.WriteAllBytes(args[2], save.Export());
                break;

            default:
                PrintUsage();
                return;
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                PrintUsage();
                return;
            }

            switch (args[0])
            {
            case "d":
                var encSave = File.ReadAllBytes(args[1]);
                File.WriteAllBytes(args[2], Encryption.DecryptSave(encSave));
                break;

            case "e":
                var decSave = File.ReadAllBytes(args[1]);
                File.WriteAllBytes(args[2], Encryption.EncryptSave(decSave));
                break;

            case "s":
                var save = new SaveManager(File.ReadAllBytes(args[1]));

                for (int i = 3; i < args.Length; i++)
                {
                    Scripting.RunScript(save.SerializeData, args[i]);
                }

                File.WriteAllBytes(args[2], save.Export());
                break;

            default:
                PrintUsage();
                return;
            }
        }
示例#3
0
文件: Program.cs 项目: pmsmall/PqSave
        private static void Run(string[] args)
        {
            char   mode       = '\0';
            string key        = null;
            string keyfile    = null;
            string inputPath  = null;
            string outputPath = null;

            string[] scripts     = new string[args.Length];
            int      fileCount   = 0;
            int      scriptCount = 0;

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];
                switch (arg)
                {
                case "d":
                case "e":
                case "x":
                case "i":
                case "s":
                    mode = arg[0];
                    break;

                case "-k":
                case "--key":
                    i++;
                    key = args[i];
                    break;

                case "--keyfile":
                    i++;
                    keyfile = args[i];
                    break;

                default:
                    if (fileCount == 0)
                    {
                        inputPath = arg;
                        fileCount++;
                    }
                    else if (fileCount == 1)
                    {
                        outputPath = arg;
                        fileCount++;
                    }
                    else
                    {
                        scripts[scriptCount++] = arg;
                    }
                    break;
                }
            }

            if (keyfile != null)
            {
                foreach (var line in File.ReadLines(keyfile))
                {
                    if (line.Length == 16)
                    {
                        key = line;
                    }
                }
            }
            if (inputPath == null || outputPath == null)
            {
                PrintUsage();
                return;
            }

            switch (mode)
            {
            case 'd':
                var encSave = File.ReadAllBytes(inputPath);
                if (key != null)
                {
                    Encryption.key = key;
                }
                File.WriteAllBytes(outputPath, Encryption.DecryptSave(encSave));
                break;

            case 'e':
                var decSave = File.ReadAllBytes(inputPath);
                File.WriteAllBytes(outputPath, Encryption.EncryptSave(decSave));
                break;

            case 'x':
                var savex  = new SaveManager(File.ReadAllBytes(inputPath));
                var output = Json.Serialize(savex);
                File.WriteAllText(outputPath, output);
                break;

            case 'i':
                string      import = File.ReadAllText(inputPath);
                SaveManager savei  = Json.DeSerialize(import);
                File.WriteAllBytes(outputPath, savei.Export());
                break;

            case 's':
                var save = new SaveManager(File.ReadAllBytes(inputPath));

                for (int i = 0; i < scriptCount; i++)
                {
                    Scripting.RunScript(save.SerializeData, scripts[i]);
                }

                File.WriteAllBytes(outputPath, save.Export());
                break;

            default:
                PrintUsage();
                return;
            }
        }