public void HandlePipeMessage(string arg) { if (arg != string.Empty) { Uri uri = new Uri(arg); Nexus.NexusUrl nexusUrl = new Nexus.NexusUrl(uri); int correctedIndex = -1; Dispatcher.Invoke(() => correctedIndex = gamePicker.SelectedIndex); if (nexusUrl.GameName != _currGame.Name_Nexus) { var games = _db.GetCollection <Game>("games").FindAll().ToList(); correctedIndex = games.FindIndex(x => x.Name_Nexus == nexusUrl.GameName); } if (correctedIndex >= 0) { Task.Run(() => { Dispatcher.Invoke((Action)(async() => { gamePicker.SelectedIndex = correctedIndex; await _modManager.CreateMod(_currGame, nexusUrl); }), DispatcherPriority.ApplicationIdle); }); } else { MessageBox.Show("Error: You are trying to install a mod for a game you don't have on your machine or isn't configured"); } } //Thread t = new Thread(_modManager.CreateMod); //t.SetApartmentState(ApartmentState.STA); //t.Start(); }
public MainWindow(Mutex mutex, DatabaseContext_Main db, Service_JsonParser jsonParser, NamedPipeManager npm, List <DatabaseContext_Profile> profiles, ProfilesManager profMngr, Nexus.NexusUrl modUri = null) { InitializeComponent(); _mutex = mutex; _jsonParser = jsonParser; _db = db; _dbProfiles = profiles; _currProfileDb = _dbProfiles.FirstOrDefault(x => _currGame.Id == x.GameId); _namedPipeManager = npm; _profilesManager = profMngr; _mulConverter = new MultiplicationMathConverter(); _addConverter = new AdditionMathConverter(); _namedPipeManager.ChangeMessageReceivedHandler(HandlePipeMessage); mainGrid.Dispatcher.BeginInvoke((Action)(() => { InitGamePicker(); _accountHandler = new AccountHandler(WhenLogsIn); _accountHandler.Init(); _modManager = new ModManager(_currProfileDb, ModList_View, Downloads_View, _accountHandler); profilePicker.SelectionChanged += profilePicker_SelectionChanged; if (modUri != null) { _modManager.CreateMod(_currGame, modUri).GetAwaiter(); } _db.UpdateCurrentGame(_currGame, SetGame); })); if (!_namedPipeManager.IsRunning) { Task.Run(async() => await _namedPipeManager.Listen_NamedPipe(Dispatcher)); } }