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 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)); }
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)); }