Skip to content

Commit

Permalink
Throw an exception if registry key could not be found
Browse files Browse the repository at this point in the history
  • Loading branch information
shatyuka committed Oct 27, 2023
1 parent 07ec823 commit 9251b92
Showing 1 changed file with 17 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,36 +320,29 @@ public static GeneralData Load()
{
try
{
if (RegistryRoot == null) throw new NullReferenceException($"Cannot load {_ValueName} RegistryKey is unexpectedly not initialized!");
object? value = RegistryRoot.GetValue(_ValueName, null);
if (RegistryRoot == null) throw new NullReferenceException($"Cannot load {_ValueName} since RegistryKey is unexpectedly not initialized!");
object value = RegistryRoot.GetValue(_ValueName) ?? throw new ArgumentNullException($"Cannot find registry key {_ValueName}");

if (value != null)
{
ReadOnlySpan<byte> byteStr = (byte[])value;
ReadOnlySpan<byte> byteStr = (byte[])value;
#if DUMPGIJSON
// Dump GeneralData as raw string
LogWriteLine($"RAW Genshin Settings: {_ValueName}\r\n" +
$"{Encoding.UTF8.GetString(byteStr.TrimEnd((byte)0))}", LogType.Debug, true);

// Dump GeneralData as indented JSON output using GeneralData properties
LogWriteLine($"Deserialized Genshin Settings: {_ValueName}\r\n{byteStr
.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default)
.Serialize(GenshinSettingsJSONContext.Default, false, true)}", LogType.Debug, true);
// Dump GeneralData as raw string
LogWriteLine($"RAW Genshin Settings: {_ValueName}\r\n" +
$"{Encoding.UTF8.GetString(byteStr.TrimEnd((byte)0))}", LogType.Debug, true);

// Dump GeneralData as indented JSON output using GeneralData properties
LogWriteLine($"Deserialized Genshin Settings: {_ValueName}\r\n{byteStr
.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default)
.Serialize(GenshinSettingsJSONContext.Default, false, true)}", LogType.Debug, true);
#endif
#if DEBUG
LogWriteLine($"Loaded Genshin Settings: {_ValueName}", LogType.Debug, true);
LogWriteLine($"Loaded Genshin Settings: {_ValueName}", LogType.Debug, true);
#else
LogWriteLine($"Loaded Genshin Settings", LogType.Default, true);
LogWriteLine($"Loaded Genshin Settings", LogType.Default, true);
#endif
GeneralData data = byteStr.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default) ?? new GeneralData();
data.graphicsData = GraphicsData.Load(data._graphicsData);
data.globalPerfData = GlobalPerfData.Load(data._globalPerfData, data.graphicsData);
return data;
}
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
GlobalPerfData.Load(null, null);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
return new GeneralData();
GeneralData data = byteStr.Deserialize<GeneralData>(GenshinSettingsJSONContext.Default) ?? new GeneralData();
data.graphicsData = GraphicsData.Load(data._graphicsData);
data.globalPerfData = GlobalPerfData.Load(data._globalPerfData, data.graphicsData);
return data;
}
catch (Exception ex)
{
Expand Down

0 comments on commit 9251b92

Please sign in to comment.