extremely buggy json implementation

This commit is contained in:
Bitl 2024-01-25 09:52:59 -07:00
parent 4b70bf44c3
commit f4c5110d0b
16 changed files with 176 additions and 30 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@ -13,7 +13,7 @@ namespace Novetus.Bootstrapper
#region File Names
public static readonly string LauncherName = "Novetus.exe";
public static readonly string URIName = "NovetusURI.exe";
public static readonly string DependencyLauncherName = "Novetus_dependency_installer.bat";
public static readonly string DependencyLauncherName = "Novetus_Dependency_Installer.exe";
#endregion
#region File Paths

View File

@ -47,6 +47,9 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Configuration" />
@ -92,6 +95,7 @@
</Compile>
<None Include="app.config" />
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net451" />
</packages>

View File

@ -32,11 +32,7 @@ namespace Novetus.Core
if (createNewFile)
{
if (File.Exists(path))
{
IOSafe.File.Delete(path);
}
IOSafe.File.Delete(path);
File.Create(path).Close();
}
}

View File

@ -0,0 +1,140 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Novetus.Core
{
public class JSONFile
{
public string path;
public Dictionary<string, string> defContents = null;
public JObject obj;
public JSONFile(string JSONPath, string section, bool createNewFile = true, Dictionary<string, string> contents = null)
{
path = JSONPath;
obj = new JObject();
if (contents != null)
{
defContents = contents;
}
if (createNewFile)
{
if (contents != null)
{
JsonCreateFile(section, defContents);
}
else
{
JsonCreateFile(section, new Dictionary<string, string>() { });
}
}
else
{
JsonReload();
}
}
public void JsonReload()
{
using (StreamReader file = File.OpenText(path))
{
obj = (JObject)JToken.ReadFrom(new JsonTextReader(file));
file.Close();
}
}
public void JsonSave()
{
IOSafe.File.Delete(path);
File.WriteAllText(path, obj.ToString());
JsonReload();
}
public void JsonCreateFile(string Section, Dictionary<string, string> contents)
{
obj = new JObject(
new JProperty(Section,
new JArray(from key in contents.Keys
select new JObject(
new JProperty(key, contents[key])))));
JsonSave();
}
public void JsonWriteValue(string Section, string Key, string Value)
{
JsonReload();
var node = obj.SelectToken(Section + "[0]") as JObject;
if (node != null)
{
bool found = false;
foreach (var o in node.Descendants())
{
JProperty p = o as JProperty;
if (p != null)
{
string keyName = p.Name;
if (keyName.Equals(Key))
{
p.Value = Value;
found = true;
break;
}
}
}
if (!found)
{
node.Add(new JProperty(Key, Value));
}
}
else
{
return;
}
JsonSave();
}
public string JsonReadValue(string Section, string Key, string Value = "")
{
JsonReload();
bool found = false;
foreach (var o in obj.Descendants())
{
JProperty p = o as JProperty;
if (p != null)
{
string keyName = p.Name;
if (keyName.Equals(Key))
{
found = true;
return p.Value.ToString();
}
}
}
if (!found && !string.IsNullOrWhiteSpace(Value))
{
JsonWriteValue(Section, Key, Value);
return JsonReadValue(Section, Key, Value);
}
return "";
}
}
}

View File

@ -9,6 +9,7 @@
<Import_RootNamespace>NovetusCore</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Classes\JSONFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)NETEnhancements\ConvertSafe.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\INIFile.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Script.cs" />

View File

@ -13,10 +13,6 @@ using System.Windows.Forms;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Linq;
using static System.Windows.Forms.LinkLabel;
#if !BASICLAUNCHER
using Newtonsoft.Json;
#endif
#endregion
namespace Novetus.Core
@ -65,7 +61,7 @@ namespace Novetus.Core
#region ConfigBase
public class ConfigBase
{
public INIFile INI;
public JSONFile JSON;
private string Section { get; set; }
private string Path { get; set; }
private string FileName { get; set; }
@ -90,13 +86,23 @@ namespace Novetus.Core
}
else
{
INI = new INIFile(FullPath, false);
JSON = new JSONFile(FullPath, Section, false);
}
}
public void CreateFile()
{
INI = new INIFile(FullPath);
DefineDefaults();
if (ValueDefaults.Count == 0)
{
ValueDefaults = new Dictionary<string, string>()
{
{"Error", "There are no default values in your ConfigBase class!"}
};
}
JSON = new JSONFile(FullPath, Section, true, ValueDefaults);
GenerateDefaults();
}
@ -112,16 +118,6 @@ namespace Novetus.Core
public void GenerateDefaults()
{
DefineDefaults();
if (ValueDefaults.Count == 0)
{
ValueDefaults = new Dictionary<string, string>()
{
{"Error", "There are no default values in your ConfigBase class!"}
};
}
foreach (string key in ValueDefaults.Keys)
{
var value = ValueDefaults[key];
@ -152,7 +148,7 @@ namespace Novetus.Core
public void SaveSetting(string section, string name, string value)
{
SaveSettingEvent();
INI.IniWriteValue(section, name, value);
JSON.JsonWriteValue(section, name, value);
}
public void SaveSettingInt(string name, int value)
@ -182,12 +178,12 @@ namespace Novetus.Core
public string ReadSetting(string section, string name)
{
string value = INI.IniReadValue(section, name);
string value = JSON.JsonReadValue(section, name);
if (!string.IsNullOrWhiteSpace(value))
{
ReadSettingEvent();
return INI.IniReadValue(section, name);
return JSON.JsonReadValue(section, name);
}
else
{
@ -204,7 +200,7 @@ namespace Novetus.Core
SaveSetting(section, name, defaultval);
ReadSettingEvent();
return INI.IniReadValue(section, name);
return JSON.JsonReadValue(section, name);
}
}

View File

@ -286,9 +286,10 @@ CREDITS AND LICENSES:
ROBLOX and the ROBLOX Clients were made by the ROBLOX Corporation.
The ROBLOX Corporation does not support or endorse the creation of Novetus.
Bitl is not affiliated with the ROBLOX Corporation or its subsidiaries.
Bitl does not own the majority of the places or items included with Novetus.
Bitl Development Studio is not affiliated with the ROBLOX Corporation or its subsidiaries.
Bitl Development Studio does not own the majority of the places or items included with Novetus.
Novetus is not associated with Novetus Engineering LLC.
This item is not authorized for posting on Steam, except under Bitl Development Studio or the ROBLOX Corporation.
Novetus uses the majority of the Whimsee's Map Pack in the "full" version. Credits go to Whimsee and many other people for making that pack possible.
Thank you to everyone who has contributed a map, item, or client including cole and many other people.
LUA scripts were used to build a client that can connect to LAN and the Internet.

View File

@ -1,3 +1,7 @@
EDGE Snapshot v24.8788.21050.1
Fixes:
- Fixed a bug where selecting an Extra item in the Extras panel would be slightly broken when "Show Hats" is enabled.
---------------------------------------------------------------------------
EDGE Snapshot v24.8786.38141.3
Fixes:
- Fixed ROBLOXian 2.0 being affected by.....the issue from the previous update. This is what happens if you use existing items as test items and never update them...

View File

@ -9,6 +9,6 @@ ExtendedVersionNumber=True
//ExtendedVersionTemplate=%version% vX.24.%extended-revision% (%version-name%)
//ExtendedVersionTemplate=%version% Snapshot v24.%build%.%revision%.%extended-revision%
ExtendedVersionTemplate=EDGE Snapshot v24.%build%.%revision%.%extended-revision%
ExtendedVersionRevision=3
ExtendedVersionRevision=1
InitialBootup=False
IsLite=False