Skip to content

Commit

Permalink
fix: Safety measures for localization registration (SubnauticaModding…
Browse files Browse the repository at this point in the history
…#496)

Added safety checks for localization registration
  • Loading branch information
Metious authored Nov 14, 2023
1 parent f655a4d commit f4ec600
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Nautilus/Handlers/LanguageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,22 @@ public static void RegisterLocalizationFolder(string languageFolderName = "Local

foreach (var file in Directory.GetFiles(path))
{
var content = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(file));
if (Path.GetExtension(file) != ".json")
{
continue;
}

// I hate this
Dictionary<string, string> content = null;
try
{
content = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(file));
}
catch (Exception e)
{
InternalLogger.Error($"Exception caught while trying to deserialize localization file at path: '{file}'. Exception: {e}");
}

if (content is null)
{
InternalLogger.Warn($"Localization file '{file}' is empty, skipping registration.");
Expand Down

0 comments on commit f4ec600

Please sign in to comment.