Exemple #1
0
        private static Int32 Convert(ProgramArguments args)
        {
            try
            {
                if (!args.TryGetNext(out var mode))
                {
                    throw new ArgumentException(nameof(args));
                }

                String[] split = mode.Split('2');
                if (split.Length != 2)
                {
                    throw new ArgumentException(mode, nameof(args));
                }

                ConvertSpecPreprocessor spec = new ConvertSpecPreprocessor(split[0], split[1]);

                if (!args.TryGetNext(out var path))
                {
                    throw new ArgumentException(nameof(args));
                }

                if (Directory.Exists(path))
                {
                    spec.SourceDirectory = path;
                    if (args.TryGetNext(out var mask))
                    {
                        spec.Mask = mask;
                    }
                }
                else if (File.Exists(path))
                {
                    spec.SourceFile = path;
                    if (args.TryGetNext(out var outputFile))
                    {
                        spec.OutputFile = outputFile;
                    }
                }
                else
                {
                    throw new FileNotFoundException(path);
                }

                spec.Preprocess();

                ICoroutine coroutine;
                switch (mode)
                {
                case "tx2txt":
                    coroutine = new ConvertTxToTxtCoroutine(spec);
                    break;

                case "am2tiff":
                    coroutine = new ConvertAmToTiffCoroutine(spec);
                    break;

                case "tiff2am":
                    coroutine = new ConvertTiffToAmCoroutine(spec);
                    break;

                case "vssf2mp3":
                    coroutine = new ConvertVssfToMp3Coroutine(spec);
                    break;

                case "mp32vssf":
                    coroutine = new ConvertMp3ToVssfCoroutine(spec);
                    break;

                default:
                    throw new ArgumentException(mode, nameof(args));
                }

                coroutine.Execute();
                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("----------------------------");
                Console.Error.WriteLine("Failed to convert game data.");
                Console.Error.WriteLine("----------------------------");
                Console.Error.WriteLine(ex);
                Console.Error.WriteLine("----------------------------");
                ShowConvertHelp();
                Console.WriteLine();
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                return(255);
            }
        }
Exemple #2
0
        private static Int32 Unpack(ProgramArguments arguments)
        {
            try
            {
                var spec = new UnpackGamePackagesSpecPreprocessor();
                if (arguments.TryGetNext(out String gameDirectoryPath))
                {
                    spec.GameDirectoryPath = gameDirectoryPath;
                }
                else
                {
                    spec.GameDirectory = GameDirectoryProvider.GetDefault();
                }

                if (arguments.TryGetNext(out String outputPath))
                {
                    spec.OutputDirectory = outputPath;
                }
                else
                {
                    spec.OutputDirectory = $".\\Data";
                }

                while (arguments.TryGetNext(out String arg))
                {
                    switch (arg)
                    {
                    case "-convert":
                        spec.Convert = true;
                        break;

                    case "-rename":
                        spec.Rename = true;
                        break;

                    default:
                        throw new ArgumentException(arg, nameof(arguments));
                    }
                }

                spec.Preprocess();

                UnpackGamePackagesCoroutine coroutine = new UnpackGamePackagesCoroutine(spec);
                coroutine.Execute();

                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("----------------------------");
                Console.Error.WriteLine("Failed to unpack game data.");
                Console.Error.WriteLine("----------------------------");
                Console.Error.WriteLine(ex);
                Console.Error.WriteLine("----------------------------");
                ShowUnpackHelp();
                Console.WriteLine();
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                return(255);
            }
        }