mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 12:23:39 +01:00
fix: add IsDataReady flag to DataManager
This commit is contained in:
parent
d447bc7c61
commit
1ac738cd25
2 changed files with 36 additions and 21 deletions
|
|
@ -16,36 +16,48 @@ namespace Dalamud.Data
|
|||
public class DataManager {
|
||||
private const string DataBaseUrl = "https://goaaats.github.io/ffxiv/tools/launcher/addons/Hooks/Data/";
|
||||
|
||||
public ReadOnlyDictionary<string, ushort> OpCodes;
|
||||
public ReadOnlyDictionary<string, ushort> ServerOpCodes;
|
||||
public ReadOnlyDictionary<uint, JObject> ContentFinderCondition;
|
||||
|
||||
public bool IsDataReady { get; private set; }
|
||||
|
||||
public DataManager() {
|
||||
// Set up default values so plugins do not null-reference when data is being loaded.
|
||||
this.OpCodes = new ReadOnlyDictionary<string, ushort>(new Dictionary<string, ushort>());
|
||||
this.ServerOpCodes = new ReadOnlyDictionary<string, ushort>(new Dictionary<string, ushort>());
|
||||
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(new Dictionary<uint, JObject>());
|
||||
}
|
||||
|
||||
public async Task Initialize() {
|
||||
Log.Verbose("Starting data download...");
|
||||
try {
|
||||
Log.Verbose("Starting data download...");
|
||||
|
||||
// This is due to GitHub not supporting TLS 1.0
|
||||
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
||||
// This is due to GitHub not supporting TLS 1.0
|
||||
System.Net.ServicePointManager.SecurityProtocol =
|
||||
SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
|
||||
|
||||
using var client = new HttpClient() {
|
||||
BaseAddress = new Uri(DataBaseUrl)
|
||||
};
|
||||
using var client = new HttpClient() {
|
||||
BaseAddress = new Uri(DataBaseUrl)
|
||||
};
|
||||
|
||||
var opCodeDict = JsonConvert.DeserializeObject<Dictionary<string, ushort>>(await client.GetStringAsync(DataBaseUrl + "opcode.json"));
|
||||
this.OpCodes = new ReadOnlyDictionary<string, ushort>(opCodeDict);
|
||||
var opCodeDict =
|
||||
JsonConvert.DeserializeObject<Dictionary<string, ushort>>(
|
||||
await client.GetStringAsync(DataBaseUrl + "serveropcode.json"));
|
||||
this.ServerOpCodes = new ReadOnlyDictionary<string, ushort>(opCodeDict);
|
||||
|
||||
Log.Verbose("Loaded {0} OpCodes.", opCodeDict.Count);
|
||||
Log.Verbose("Loaded {0} ServerOpCodes.", opCodeDict.Count);
|
||||
|
||||
var cfcs = JsonConvert.DeserializeObject<Dictionary<uint, JObject>>(await client.GetStringAsync(DataBaseUrl + "contentfindercondition.json"));
|
||||
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(cfcs);
|
||||
var cfcs = JsonConvert.DeserializeObject<Dictionary<uint, JObject>>(
|
||||
await client.GetStringAsync(DataBaseUrl + "contentfindercondition.json"));
|
||||
this.ContentFinderCondition = new ReadOnlyDictionary<uint, JObject>(cfcs);
|
||||
|
||||
Log.Verbose("Loaded {0} ContentFinderCondition.", cfcs.Count);
|
||||
Log.Verbose("Loaded {0} ContentFinderCondition.", cfcs.Count);
|
||||
|
||||
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
|
||||
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
|
||||
|
||||
IsDataReady = true;
|
||||
} catch (Exception ex) {
|
||||
Log.Error(ex, "Could not download data.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue