private static void CompressSingleFile(string path, string outputPath)
        {
            JObject obj = JsonConvert.DeserializeObject <JObject>(File.ReadAllText(path));

            Compress(obj);
            var result = new SaveDataProxy
            {
                m_BaseName       = obj["m_BaseName"],
                m_DisplayName    = obj["m_DisplayName"],
                m_Episode        = obj["m_Episode"],
                m_GameId         = obj["m_GameId"],
                m_GameMode       = obj["m_GameMode"],
                m_IsPS4Compliant = obj["m_IsPS4Compliant"],
                m_Name           = obj["m_Name"],
                m_Timestamp      = obj["m_Timestamp"],
                m_Dict           = new Dictionary <string, byte[]>()
            };

            var dict = (JObject)obj["m_Dict"];

            foreach (var jo in dict)
            {
                var fileJson = JsonConvert.SerializeObject(jo.Value, Formatting.None);
                fileJson = Util.ShittifyJson(fileJson);
                result.m_Dict[jo.Key.ToString()] = CLZF.Compress(Encoding.UTF8.GetBytes(fileJson));
                jo.Value.Replace(null);
            }

            var resultJson = JsonConvert.SerializeObject(result, Formatting.None);

            File.WriteAllBytes(outputPath, CLZF.Compress(Encoding.UTF8.GetBytes(resultJson)));
        }
        private static byte[] ReadJToken(string path)
        {
            JToken token = JToken.Parse(File.ReadAllText(path));

            Compress(token);
            var fileJson = JsonConvert.SerializeObject(token, Formatting.None);
            var json     = Util.ShittifyJson(fileJson);

            return(CLZF.Compress(Encoding.UTF8.GetBytes(json)));
        }
예제 #3
0
        private static JToken ExpandFile(byte[] data)
        {
            string decompressedJson = Encoding.UTF8.GetString(CLZF.Decompress(data));

            if (decompressedJson == null)
            {
                return(null);
            }

            decompressedJson = Util.UnShittifyJson(decompressedJson);
            JToken fileToken = JToken.Parse(decompressedJson);

            decompressedJson = null;

            Expand(fileToken);

            return(fileToken);
        }
        private static void CompressMultipleFiles(string path, string outputPath)
        {
            string scenesPath   = Path.Combine(path, "scenes");
            string slotDataPath = Path.Combine(path, "slotData.json");

            SaveDataProxy slot = JsonConvert.DeserializeObject <SaveDataProxy>(File.ReadAllText(slotDataPath));

            slot.m_Dict["global"]     = ReadJToken(Path.Combine(path, "global.json"));
            slot.m_Dict["boot"]       = ReadJToken(Path.Combine(path, "boot.json"));
            slot.m_Dict["screenshot"] = ReadJToken(Path.Combine(path, "screenshot.json"));

            foreach (var file in Directory.GetFiles(scenesPath))
            {
                slot.m_Dict[Path.GetFileNameWithoutExtension(file)] = ReadJToken(file);
            }

            var resultJson = JsonConvert.SerializeObject(slot, Formatting.None);

            File.WriteAllBytes(outputPath, CLZF.Compress(Encoding.UTF8.GetBytes(resultJson)));
        }
예제 #5
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));
        }
예제 #6
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));
        }