Esempio n. 1
0
 public static void ExpandSave(string path, string outputPath, ConvertSettings settings)
 {
     if (settings.singleFile)
     {
         ExpandSaveSingleFile(path, outputPath ?? path + ".json", settings);
     }
     else
     {
         ExpandSaveMultipleFiles(path, outputPath ?? path + "_json", settings);
     }
 }
Esempio n. 2
0
        private static void ExpandSaveSingleFile(string path, string outputPath, ConvertSettings settings)
        {
            string        decompressedJson = Encoding.UTF8.GetString(CLZF.Decompress(File.ReadAllBytes(path)));
            SaveDataProxy save             = JsonConvert.DeserializeObject <SaveDataProxy>(decompressedJson);

            decompressedJson = null;

            // TODO JObject.FromObject
            var result = new ExpandedSaveDataProxy
            {
                m_BaseName       = save.m_BaseName,
                m_DisplayName    = save.m_DisplayName,
                m_Episode        = save.m_Episode,
                m_GameId         = save.m_GameId,
                m_GameMode       = save.m_GameMode,
                m_IsPS4Compliant = save.m_IsPS4Compliant,
                m_Name           = save.m_Name,
                m_Timestamp      = save.m_Timestamp,
                m_Dict           = new Dictionary <string, dynamic>()
            };

            while (save.m_Dict.Keys.Count != 0)
            {
                string key = save.m_Dict.Keys.First();
                var    val = ExpandFile(save.m_Dict[key]);
                if (settings.omitNull || settings.omitFalse || settings.omitZero)
                {
                    Util.RemoveDefault(val, settings.omitNull, settings.omitFalse, settings.omitZero);
                }
                result.m_Dict[key] = val;
                save.m_Dict.Remove(key);
            }

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                FloatFormatHandling = FloatFormatHandling.Symbol,
                Formatting          = Formatting.Indented
            };

            File.WriteAllText(outputPath, JsonConvert.SerializeObject(result));
        }
Esempio n. 3
0
        private static void ExpandSaveMultipleFiles(string path, string outputPath, ConvertSettings settings)
        {
            string scenesPath = Path.Combine(outputPath, "scenes");

            string        decompressedJson = Encoding.UTF8.GetString(CLZF.Decompress(File.ReadAllBytes(path)));
            SaveDataProxy save             = JsonConvert.DeserializeObject <SaveDataProxy>(decompressedJson);

            decompressedJson = null;

            if (Directory.Exists(outputPath))
            {
                Directory.Delete(outputPath, true);
            }
            Directory.CreateDirectory(outputPath);
            Directory.CreateDirectory(scenesPath);

            while (save.m_Dict.Keys.Count != 0)
            {
                string key = save.m_Dict.Keys.First();
                var    val = ExpandFile(save.m_Dict[key]);
                if (settings.omitNull || settings.omitFalse || settings.omitZero)
                {
                    Util.RemoveDefault(val, settings.omitNull, settings.omitFalse, settings.omitZero);
                }
                string filePath;
                if (key == "global" || key == "boot" || key == "screenshot")
                {
                    filePath = Path.Combine(outputPath, key + ".json");
                }
                else
                {
                    filePath = Path.Combine(scenesPath, key + ".json");
                }

                File.WriteAllText(filePath, JsonConvert.SerializeObject(val, settings.minify ? Formatting.None : Formatting.Indented));
                save.m_Dict.Remove(key);
            }

            File.WriteAllText(Path.Combine(outputPath, "slotData.json"), JsonConvert.SerializeObject(save, settings.minify ? Formatting.None : Formatting.Indented));
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            var settings = new ConvertSettings()
            {
                omitNull   = true,
                omitFalse  = false,
                omitZero   = false,
                minify     = false,
                singleFile = false
            };
            string outputPath = null;

            var p = new OptionSet()
            {
                { "file=", v => outputPath = v },
                { "singleFile", v => settings.singleFile = true },
                { "minify", v => settings.minify = true },
                { "omitDefault", v => { settings.omitFalse = true; settings.omitNull = true; settings.omitZero = true; } },
                { "omitNull=", v => settings.omitNull = v == "1" },
                { "omitZero=", v => settings.omitZero = v == "1" },
                { "omitFalse=", v => settings.omitFalse = v == "1" },
            };
            List <string> extras = p.Parse(args);

            if (extras.Count < 1)
            {
                Console.WriteLine("File to convert missing");
                Environment.Exit(-1);
            }

            string file = extras[0];

            bool compress = false;

            if (file.EndsWith(".json"))
            {
                compress = true;
            }
            if (Directory.Exists(file))
            {
                compress            = true;
                settings.singleFile = false;
            }

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                FloatFormatHandling = FloatFormatHandling.Symbol
            };

            if (compress)
            {
                if (outputPath == null)
                {
                    if (file.EndsWith("_json"))
                    {
                        outputPath = file.Substring(0, file.Length - 5);
                    }
                    else if (file.EndsWith(".json"))
                    {
                        outputPath = file.Substring(0, file.Length - 5);
                    }
                    else
                    {
                        throw new Exception("Can't guess output path");
                    }
                }
                SaveCompressor.CompressSave(file, outputPath);
            }
            else
            {
                SaveExpander.ExpandSave(file, outputPath, settings);
            }
        }