public static ConsumablesInfoImporter GetConsumablesInfo() { using (WebClient wc = new WebClient()) { string jsonFile = Commons.GetCurrentDirectory() + "/coninfotype.json"; wc.DownloadFile("https://onedrive.live.com/download?cid=919CD8D21AC2180D&resid=919CD8D21AC2180D%2116820&authkey=AEsjf3lBZE8zABY", jsonFile); string jsonText = File.ReadAllText(jsonFile); ConsumablesInfoImporter Import = JsonConvert.DeserializeObject <ConsumablesInfoImporter>(jsonText); return(Import); } }
public static void AddConsumablesInfo(bool ForceUpdate = false) { if (Program.Settings == null) { return; } ConsumablesInfoImporter import = WGAPI.GetConsumablesInfo(); if (!import.Status.Equals("ok")) { return; } if (ForceUpdate || (Program.Settings.ConsumablesInfoVersion != null && !Program.Settings.ConsumablesInfoVersion.Equals(import.Version))) { foreach (Ship ship in Program.AllShips) { ship.Consumables = new List <ConsumableInfo>(); ship.Airstrike = new ModuleAirstrike(); } Program.Settings.ConsumablesInfoVersion = import.Version; foreach (KeyValuePair <string, List <ConsumablesInfoTypeImporter> > list in import.Consumables) { Enum.TryParse(list.Key, out ConsumableType CType); foreach (ConsumablesInfoTypeImporter con in list.Value) { List <Ship> ShipList = new List <Ship>(); if (con.GroupSelection != null && !con.GroupSelection.Equals("")) { ShipList = ShipFinder.FindShips(con.ID, con.GroupSelection, con.Exceptions); } else { ShipList = ShipFinder.FindShips(con.ID, con.Group, con.Exceptions); } foreach (Ship ship in ShipList) { ship.Consumables.Add(new ConsumableInfo() { Duration = con.Duration, Range = con.Range, Type = CType, Cooldown = con.Cooldown, Charges = con.Charges, ExtraInfo = con.ExtraInfo }); } } } foreach (KeyValuePair <string, ModuleAirstrike> airstrike in import.Airstrike) { long shipId = Convert.ToInt64(airstrike.Key); Ship ship = Program.AllShips.Find(e => e.ID == shipId); if (ship != null) { ship.Airstrike = airstrike.Value; } } UpdateUpgradesInfo(); BinarySerialize.WriteToBinaryFile <List <Ship> >(Commons.GetShipListFileName(), Program.AllShips); } }