mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-16 08:54:47 +01:00
improve compatibility with older game versions
This commit is contained in:
@@ -325,19 +325,25 @@ namespace EpinelPS.Data
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public async Task<T> LoadZip<T>(string entry, IProgress<double> bar)
|
public async Task<T> LoadZip<T>(string entry, IProgress<double> bar) where T : new()
|
||||||
{
|
{
|
||||||
var mainQuestData = MainZip.GetEntry(entry) ?? throw new Exception(entry + " does not exist in static data");
|
var fileEntry = MainZip.GetEntry(entry);
|
||||||
using StreamReader mainQuestReader = new(MainZip.GetInputStream(mainQuestData));
|
if (fileEntry == null)
|
||||||
var mainQuestDataString = await mainQuestReader.ReadToEndAsync();
|
{
|
||||||
|
Logging.WriteLine(entry + " does not exist in static data", LogType.Error);
|
||||||
|
return new T();
|
||||||
|
}
|
||||||
|
|
||||||
var questdata = JsonConvert.DeserializeObject<T>(mainQuestDataString);
|
using StreamReader fileReader = new(MainZip.GetInputStream(fileEntry));
|
||||||
if (questdata == null) throw new Exception("failed to parse " + entry);
|
string fileString = await fileReader.ReadToEndAsync();
|
||||||
|
|
||||||
|
T? deseralizedObject = JsonConvert.DeserializeObject<T>(fileString);
|
||||||
|
if (deseralizedObject == null) throw new Exception("failed to parse " + entry);
|
||||||
|
|
||||||
currentFile++;
|
currentFile++;
|
||||||
bar.Report((double)currentFile / totalFiles);
|
bar.Report((double)currentFile / totalFiles);
|
||||||
|
|
||||||
return questdata;
|
return deseralizedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<JArray> LoadZip(string entry, ProgressBar bar)
|
private async Task<JArray> LoadZip(string entry, ProgressBar bar)
|
||||||
|
|||||||
Reference in New Issue
Block a user