private void PyxieWindow_Loaded(object sender, RoutedEventArgs e) { if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\Pyxie.xml")) { try { using (StreamReader streamReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "\\Pyxie.xml")) { XmlSerializer serializer = new XmlSerializer(typeof(Configuration)); Globals.Instance.Pyxie = (Configuration)serializer.Deserialize(streamReader); } } catch (Exception ex) { MessageBox.Show("Pyxie was unable to load your global configuration file:\r\n\r\n" + ex.ToString()); return; } } Version Current = typeof(MainWindow).Assembly.GetName().Version; ActiveProcessList = new ObservablePlayerCollection <Player>(); ProcessThread = new Thread(() => UpdateProcessSelections(ActiveProcessList)); ProcessThread.IsBackground = true; ProcessThread.Start(); this.PeopleList.DataContext = ActiveProcessList; this.GlobalSettings.DataContext = Globals.Instance.Pyxie; this.ExclusionsSettings.DataContext = Globals.Instance.Pyxie; }
public void UpdateProcessSelections(ObservablePlayerCollection <Player> ActiveProcessList) { while (!Globals.Exiting) { // Get current running processes named pol: var CurrentProcessList = Process.GetProcessesByName("pol").ToList(); if (CurrentProcessList.Count == 0 && ActiveProcessList.Count > 0) { //There are no POL Processes we need to handle //Clear them, Players will clean themselves up ActiveProcessList.Clear(); } else if (CurrentProcessList.Count > 0) { foreach (Process FFXI in CurrentProcessList) { // The process isn't responding, ignore it if (!FFXI.Responding) { continue; } if (!ActiveProcessList.Any(P => P.Id == FFXI.Id)) { if (FFXI.MainWindowTitle.Length == 0 || FFXI.MainWindowTitle.Contains(' ')) { continue; } // The character hasn't been added to the list yet ActiveProcessList.Add(new Player(FFXI)); HandleNewCharacter(); continue; } } foreach (Player FFXIChar in ActiveProcessList.ToList()) { if (!CurrentProcessList.Any(P => P.MainWindowTitle == FFXIChar.Name)) { FFXIChar.SaveSettings(); FFXIChar.Destroy(); ActiveProcessList.Remove(FFXIChar); } } } Thread.Sleep(100); } }