Ejemplo n.º 1
0
        private static void ProcesssBlueprint(FileProcessingSubOptions options)
        {
            if (options == null) throw new ArgumentNullException(nameof(options));

            AssertFileOfType(options.Input, ".png", options.IsRaw);

            try
            {
                using (var bitmap = options.IsRaw
                        ? new Bitmap(new MemoryStream(Convert.FromBase64String(options.Input)))
                        : (Bitmap)Image.FromFile(options.Input))
                {
                    var blueprint = BlueprintConverter.Deserialize(bitmap);

                    Console.WriteLine(JsonConvert.SerializeObject(new BlueprintDump(blueprint),
                        new JsonSerializerSettings
                        {
                            ContractResolver = new DumpDataResolver(
                                "Type",
                                "Data",
                                "IsEmpty",
                                "Id",
                                "ContentTypes",
                                "Position",
                                "Rotation",
                                "CarColors",
                                "TrackColors",
                                "TrackId",
                                "StationControllers"
                                )
                        }));
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("invalid input");
                Environment.Exit(1);
            }
            catch (InvalidBlueprintException)
            {
                Console.WriteLine("invalid blueprint");
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.WriteLine("error: " + e.GetType() + ": " + e.Message + "\n" + e.StackTrace);
                Environment.Exit(1);
            }
        }
Ejemplo n.º 2
0
        private static void ProcessSavegame(FileProcessingSubOptions options)
        {
            if (options == null) throw new ArgumentNullException(nameof(options));

            AssertFileOfType(options.Input, ".txt", options.IsRaw);

            try
            {
                using (
                    var stream = options.IsRaw
                        ? new MemoryStream(Encoding.UTF8.GetBytes(options.Input))
                        : (Stream) File.OpenRead(options.Input))
                {
                    var savegame = SavegameConverter.Deserialize(stream);

                    Console.WriteLine(JsonConvert.SerializeObject(new SavegameDump(savegame),
                        new JsonSerializerSettings
                        {
                            ContractResolver = new DumpDataResolver(
                                "Type",
                                "Data",
                                "IsEmpty",
                                "Id",
                                "JobAgency",
                                "Patches",
                                "Zones",
                                "Transactions"
                                )
                        }));
                }
            }
            catch (FormatException)
            {
                Console.WriteLine("invalid input");
                Environment.Exit(1);
            }
            catch (InvalidSavegameException e)
            {
                Console.WriteLine("invalid savegame: " + e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.WriteLine("error: " + e.GetType() + ": " + e.Message + "\n" + e.StackTrace);
                Environment.Exit(1);
            }
        }