diff --git a/EpinelPS/Data/GameData.cs b/EpinelPS/Data/GameData.cs index db21364..df092bd 100644 --- a/EpinelPS/Data/GameData.cs +++ b/EpinelPS/Data/GameData.cs @@ -325,19 +325,25 @@ namespace EpinelPS.Data } #endregion - public async Task LoadZip(string entry, IProgress bar) + public async Task LoadZip(string entry, IProgress bar) where T : new() { - var mainQuestData = MainZip.GetEntry(entry) ?? throw new Exception(entry + " does not exist in static data"); - using StreamReader mainQuestReader = new(MainZip.GetInputStream(mainQuestData)); - var mainQuestDataString = await mainQuestReader.ReadToEndAsync(); + var fileEntry = MainZip.GetEntry(entry); + if (fileEntry == null) + { + Logging.WriteLine(entry + " does not exist in static data", LogType.Error); + return new T(); + } - var questdata = JsonConvert.DeserializeObject(mainQuestDataString); - if (questdata == null) throw new Exception("failed to parse " + entry); + using StreamReader fileReader = new(MainZip.GetInputStream(fileEntry)); + string fileString = await fileReader.ReadToEndAsync(); + + T? deseralizedObject = JsonConvert.DeserializeObject(fileString); + if (deseralizedObject == null) throw new Exception("failed to parse " + entry); currentFile++; bar.Report((double)currentFile / totalFiles); - return questdata; + return deseralizedObject; } private async Task LoadZip(string entry, ProgressBar bar)