private void LoadData() { string assemblylocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // Load data version string dataversionfile = Path.Combine(assemblylocation, "data", DataVersionFile); dataversion = JsonConvert.DeserializeObject<Update.AHDataVersion>(File.ReadAllText(dataversionfile), new VersionConverter()); // Load card hashes string cardhashesfile = Path.Combine(assemblylocation, "data", HashListFile); cardhashlist = JsonConvert.DeserializeObject<List<CardHashData>>(File.ReadAllText(cardhashesfile)); // Load card tier info string cardtierfile = Path.Combine(assemblylocation, "data", TierListFile); cardtierlist = JsonConvert.DeserializeObject<List<CardTierInfo>>(File.ReadAllText(cardtierfile)); }
private async Task CheckDataUpdate() { if (!hasdataupdates && !Hearthstone_Deck_Tracker.API.Core.Game.IsRunning && arenawindow != null && !showingupdatemessage) { if ((DateTime.Now - lastdataupdatecheck) > dataupdatecheckinterval) { lastdataupdatecheck = DateTime.Now; Update.AHDataVersion latestdataversion = await Update.GetDataVersion(); if (latestdataversion != null) { string assemblylocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (latestdataversion.hashlist > dataversion.hashlist) { // Hash list updated, download the new hash list string hashliststr = await Update.DownloadString(Update.HashListUrl); if (hashliststr != null) { string hashlistfile = Path.Combine(assemblylocation, "data", HashListFile); File.WriteAllText(hashlistfile, hashliststr); } hasdataupdates = true; } if (latestdataversion.tierlist > dataversion.tierlist) { // Tier list updated, download the new tier list string tierliststr = await Update.DownloadString(Update.TierListUrl); if (tierliststr != null) { string tierlistfile = Path.Combine(assemblylocation, "data", TierListFile); File.WriteAllText(tierlistfile, tierliststr); } hasdataupdates = true; } if (hasdataupdates) { // Set the new data version dataversion = latestdataversion; // Write the new version file string dataversionfile = Path.Combine(assemblylocation, "data", DataVersionFile); string json = JsonConvert.SerializeObject(dataversion, Newtonsoft.Json.Formatting.Indented, new VersionConverter()); File.WriteAllText(dataversionfile, json); // Load the new data LoadData(); if (arenawindow != null) { var settings = new MetroDialogSettings { AffirmativeButtonText = "OK"}; var result = await arenawindow.ShowMessageAsync("Data update applied!", "The tier list and card data was updated to the latest version.", MessageDialogStyle.Affirmative, settings); haspluginupdates = false; lastpluginupdatecheck = DateTime.Now.AddDays(1); } // Delay checking for updates hasdataupdates = false; lastdataupdatecheck = DateTime.Now.AddDays(1); } } } } }