private void LoadGambits() { try { if (!Directory.Exists(_gambitsFolder)) { return; } var directory = new DirectoryInfo(_gambitsFolder); var files = directory.GetFiles("*.json", SearchOption.TopDirectoryOnly); foreach (var file in files) { var gambitGroup = JsonConvert.DeserializeObject <GambitGroup>(File.ReadAllText(file.FullName)); if (gambitGroup == null) { continue; } GambitGroups.Add(gambitGroup); } } catch (Exception e) { Logger.Error(e.Message); } }
public void RecoverOldGambits() { try { if (!File.Exists(_oldGambitsFile)) { return; } var oldGambits = JsonConvert.DeserializeObject <List <Gambit> >(File.ReadAllText(_oldGambitsFile)); Logger.WriteInfo($"Trying To Recover {oldGambits.Count} Gambits"); foreach (var gambit in oldGambits) { // If a recovery group doesn't exist, create one if (!GambitGroups.Any(r => r.Job == gambit.Job && r.Name == "Recovered Gambits")) { var newGambitGroup = new GambitGroup { Name = "Recovered Gambits", Id = new Random().Next(int.MaxValue), ZoneId = 1, ZoneName = "Zone Name", Job = gambit.Job, Gambits = new ObservableCollection <Gambit>() }; GambitGroups.Add(newGambitGroup); } // find the recovery group var gambitGroup = GambitGroups.FirstOrDefault(r => r.Job == gambit.Job && r.Name == "Recovered Gambits"); // add the gambit to the group gambitGroup?.Gambits.Add(gambit); } } catch (Exception e) { // } CanRecoverOldGambits = false; // Rename the file File.Move($@"{JsonSettings.CharacterSettingsDirectory}/Magitek/Gambits.json", $@"{JsonSettings.CharacterSettingsDirectory}/Magitek/OldGambitsBackup.json"); }