From 1e9a73e8a3661d6c5a51e18d327843e9a05a355d Mon Sep 17 00:00:00 2001 From: Bitl Date: Thu, 25 Jan 2024 10:52:32 -0700 Subject: [PATCH] less buggy JSON implementation --- .../CharCustom/CharacterCustomizationShared.cs | 6 +++--- Novetus/NovetusCore/Classes/JSONFile.cs | 15 +++++++-------- .../NovetusCore/NETEnhancements/NETExtensions.cs | 9 +++++++++ .../StorageAndFunctions/FileManagement.cs | 3 ++- .../StorageAndFunctions/GlobalPaths.cs | 4 ++-- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Novetus/NovetusCore/CharCustom/CharacterCustomizationShared.cs b/Novetus/NovetusCore/CharCustom/CharacterCustomizationShared.cs index 66045ee..11de58d 100644 --- a/Novetus/NovetusCore/CharCustom/CharacterCustomizationShared.cs +++ b/Novetus/NovetusCore/CharCustom/CharacterCustomizationShared.cs @@ -648,10 +648,10 @@ class CharacterCustomizationShared { using (var ofd = new OpenFileDialog()) { - ofd.Filter = "Novetus config_customization files (*.ini)|*.ini"; + ofd.Filter = "Novetus config_customization files (*.json)|*.json"; ofd.FilterIndex = 1; - ofd.FileName = "config_customization.ini"; - ofd.Title = "Load config_customization.ini"; + ofd.FileName = "config_customization.json"; + ofd.Title = "Load config_customization.json"; if (ofd.ShowDialog() == DialogResult.OK) { //FileManagement.Customization(ofd.FileName, false); diff --git a/Novetus/NovetusCore/Classes/JSONFile.cs b/Novetus/NovetusCore/Classes/JSONFile.cs index e9c4099..052ba94 100644 --- a/Novetus/NovetusCore/Classes/JSONFile.cs +++ b/Novetus/NovetusCore/Classes/JSONFile.cs @@ -2,8 +2,10 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; +using System.Drawing; using System.IO; using System.Linq; +using System.Runtime.Remoting; namespace Novetus.Core { @@ -59,20 +61,17 @@ namespace Novetus.Core public void JsonCreateFile(string Section, Dictionary contents) { - obj = new JObject( - new JProperty(Section, - new JArray(from key in contents.Keys - select new JObject( - new JProperty(key, contents[key]))))); + JObject o = new JObject(); + obj.Add(new JProperty(Section, new JObject(o))); + + contents.Keys.ForEach(k => JsonWriteValue(Section, k, contents[k])); JsonSave(); } public void JsonWriteValue(string Section, string Key, string Value) { - JsonReload(); - - var node = obj.SelectToken(Section + "[0]") as JObject; + var node = obj.SelectToken(Section) as JObject; if (node != null) { bool found = false; diff --git a/Novetus/NovetusCore/NETEnhancements/NETExtensions.cs b/Novetus/NovetusCore/NETEnhancements/NETExtensions.cs index ad8841e..a29ae8f 100644 --- a/Novetus/NovetusCore/NETEnhancements/NETExtensions.cs +++ b/Novetus/NovetusCore/NETEnhancements/NETExtensions.cs @@ -227,6 +227,15 @@ namespace Novetus.Core EnableMenuItem(GetSystemMenu(form.Handle, false), 0xF060, 0); } #endregion + + #region IEnumerable Extensions + public static void ForEach(this IEnumerable source, Action action) + { + foreach (T item in source) + action(item); + } + #endregion + #endregion } } diff --git a/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs b/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs index b26710d..3eb75db 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/FileManagement.cs @@ -148,6 +148,7 @@ namespace Novetus.Core public void SaveSetting(string section, string name, string value) { SaveSettingEvent(); + JSON.JsonReload(); JSON.JsonWriteValue(section, name, value); } @@ -869,7 +870,7 @@ namespace Novetus.Core catch (Exception ex) { Util.LogExceptions(ex); - ReadInfoFile(infopath, termspath, exepath); + //ReadInfoFile(infopath, termspath, exepath); } } diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs index 45884aa..5dc6085 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalPaths.cs @@ -111,8 +111,8 @@ namespace Novetus.Core #endregion #region File Names - public static readonly string ConfigName = "config.ini"; - public static string ConfigNameCustomization = "config_customization.ini"; + public static readonly string ConfigName = "config.json"; + public static string ConfigNameCustomization = "config_customization.json"; public static readonly string InfoName = "info.ini"; public static readonly string ScriptName = "CSMPFunctions"; public static readonly string ScriptGenName = "CSMPBoot";