void updatePositions() { if (!updateEmuPositions) { return; } List <Emulator> emus = new List <Emulator>(); foreach (ListViewItem item in emulatorListView.Items) { Emulator emu = item.Tag as Emulator; if (emu.Position != item.Index) { emu.Position = item.Index; emus.Add(emu); } } var handler = new BackgroundTaskHandler <Emulator>() { Items = emus }; handler.StatusDelegate = o => { return(string.Format("Updating {0} position...", o.Title)); }; handler.ActionDelegate = o => { o.SavePosition(); return(true); }; using (Conf_ProgressDialog dlg = new Conf_ProgressDialog(handler)) dlg.ShowDialog(); updateEmuPositions = false; }
void sendToImporter(IEnumerable <Game> games) { Importer importer = Emulators2Settings.Instance.Importer; BackgroundTaskHandler handler = new BackgroundTaskHandler(); handler.StatusDelegate = () => { return("sending to Importer..."); }; handler.ActionDelegate = () => { importer.AddGames(games); }; using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler)) progressDlg.ShowDialog(); }
//Approve selected match void approveButton_Click(object sender, EventArgs e) { importGridView.EndEdit(); if (importGridView.SelectedRows.Count < 1) { return; } List <RomMatch> matches = new List <RomMatch>(); foreach (DataGridViewRow row in importGridView.SelectedRows) { RomMatch romMatch = row.DataBoundItem as RomMatch; if (romMatch == null) { continue; } matches.Add(romMatch); } if (matches.Count == 0) { return; } else if (matches.Count == 1) { importer.Approve(matches[0]); } else { BackgroundTaskHandler handler = new BackgroundTaskHandler(); handler.StatusDelegate = () => { return("Approving roms..."); }; handler.ActionDelegate = () => { importer.Approve(matches); }; using (Conf_ProgressDialog dlg = new Conf_ProgressDialog(handler)) dlg.ShowDialog(); } updateButtons(); }
void delRomButton_Click(object sender, EventArgs e) { if (dBListView.SelectedItems.Count == 0) { return; } DialogResult dlg = MessageBox.Show( "Are you sure you want to delete the selected Game(s) and add them to the ignored files list?", "Delete Game(s)?", MessageBoxButtons.YesNo); if (dlg != DialogResult.Yes) { return; } saveSelectedGame = false; saveThumbs = false; savePCSettings = false; saveDiscs = false; Importer importer = Emulators2Settings.Instance.Importer; List <Game> games = new List <Game>(); foreach (ListViewItem item in dBListView.SelectedItems) { games.Add((Game)item.Tag); } BackgroundTaskHandler <Game> handler = new BackgroundTaskHandler <Game>() { Items = games }; handler.StatusDelegate = o => { return("removing " + o.Title); }; handler.ActionDelegate = o => { importer.Remove(o.GameID); using (ThumbGroup thumbGroup = new ThumbGroup(o)) { try { if (System.IO.Directory.Exists(thumbGroup.ThumbPath)) { System.IO.Directory.Delete(thumbGroup.ThumbPath, true); } } catch (Exception ex) { Logger.LogError("Error deleting {0} thumb directory - {1}", o.Title, ex.Message); } } Options.Instance.AddIgnoreFile(o.Path); foreach (GameDisc disc in o.GetDiscs()) { Options.Instance.AddIgnoreFile(disc.Path); } return(true); }; using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler)) progressDlg.ShowDialog(); string sql = "DELETE FROM {0} WHERE gameid IN ({1})"; string ids = ""; for (int x = 0; x < games.Count; x++) { if (x > 0) { ids += ","; } ids += games[x].GameID; } DB.Instance.Execute(sql, Game.TABLE_NAME, ids); DB.Instance.Execute(sql, GameDisc.TABLE_NAME, ids); dBListView.SelectedItems.Clear(); UpdatePanel(); }
EmulatorInfo updateEmuInfo(string platformText, string selectedKey, Dictionary <string, string> emuInfos, Func <object, bool> completedDelegate) { EmulatorInfo emuInfo = null; bool completed = false; BackgroundTaskHandler handler = new BackgroundTaskHandler(); handler.ActionDelegate = () => { handler.ExecuteProgressHandler(0, "Looking up platforms..."); string selectedId; if (emuInfos == null || string.IsNullOrEmpty(selectedKey)) { emuInfos = new EmulatorScraper().GetEmulators(platformText, out selectedKey); if (selectedKey == null || !emuInfos.TryGetValue(selectedKey, out selectedId)) { return; } } else if (!emuInfos.TryGetValue(selectedKey, out selectedId)) { return; } handler.ExecuteProgressHandler(33, "Retrieving info for " + selectedKey); emuInfo = new EmulatorScraper().GetInfo(selectedId); if (emuInfo == null) { return; } handler.ExecuteProgressHandler(67, "Updating " + emuInfo.Title); if (completedDelegate != null) { completed = completedDelegate(emuInfo); } else { completed = true; } }; using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler)) progressDlg.ShowDialog(); if (completed) { return(emuInfo); } if (emuInfos != null && string.IsNullOrEmpty(selectedKey)) { using (Conf_EmuLookupDialog lookupDlg = new Conf_EmuLookupDialog(emuInfos)) { if (lookupDlg.ShowDialog() == DialogResult.OK && lookupDlg.SelectedKey != null) { return(updateEmuInfo(null, lookupDlg.SelectedKey, emuInfos, completedDelegate)); } } } else { MessageBox.Show("Error retrieving online info.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(null); }
public void StartLaunch(Game game) { if (game == null) { return; } EmulatorProfile profile = game.GetSelectedProfile(); bool isConfig = Emulators2Settings.Instance.IsConfig; BackgroundTaskHandler handler = new BackgroundTaskHandler(); handler.ActionDelegate = () => { string errorStr = null; string path = null; if (game.IsGoodmerge) { try { path = Extractor.Instance.ExtractGame(game, profile, (l, p) => { handler.ExecuteProgressHandler(p, l); return(true); }); } catch (ExtractException ex) { errorStr = ex.Message; } } else { path = game.CurrentDisc.Path; } GUIGraphicsContext.form.Invoke(new System.Windows.Forms.MethodInvoker(() => { if (path != null) { try { handler.ExecuteProgressHandler(50, "Launching " + game.Title); Executor.Instance.LaunchGame(path, profile, (l, p) => { handler.ExecuteProgressHandler(p, l); return(true); }); if (!isConfig) { game.UpdateAndSaveGamePlayInfo(); } } catch (LaunchException ex) { Logger.LogError(ex.Message); errorStr = ex.Message; } } if (errorStr != null) { Emulators2Settings.Instance.ShowMPDialog("Error\r\n{0}", errorStr); } })); }; if (isConfig) { using (Conf_ProgressDialog dlg = new Conf_ProgressDialog(handler)) dlg.ShowDialog(); } else { GUIProgressDialogHandler guiDlg = new GUIProgressDialogHandler(handler); guiDlg.ShowDialog(); } }
void delRomButton_Click(object sender, EventArgs e) { if (importGridView.SelectedRows.Count < 1) { return; } if (MessageBox.Show( "Are you sure you want to delete the selected Game(s) and add them to the ignored files list?", "Delete Game(s)?", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } List <Game> games = new List <Game>(); foreach (DataGridViewRow row in importGridView.SelectedRows) { RomMatch match = row.DataBoundItem as RomMatch; if (match != null && match.Game != null) { games.Add(match.Game); } } BackgroundTaskHandler <Game> handler = new BackgroundTaskHandler <Game>() { Items = games }; handler.StatusDelegate = o => { return("removing " + o.Title); }; handler.ActionDelegate = o => { importer.Remove(o.GameID); using (ThumbGroup thumbGroup = new ThumbGroup(o)) { try { if (System.IO.Directory.Exists(thumbGroup.ThumbPath)) { System.IO.Directory.Delete(thumbGroup.ThumbPath, true); } } catch (Exception ex) { Logger.LogError("Error deleting {0} thumb directory - {1}", o.Title, ex.Message); } } Options.Instance.AddIgnoreFile(o.Path); foreach (GameDisc disc in o.GetDiscs()) { Options.Instance.AddIgnoreFile(disc.Path); } return(true); }; using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler)) progressDlg.ShowDialog(); string sql = "DELETE FROM {0} WHERE gameid IN ({1})"; string ids = ""; for (int x = 0; x < games.Count; x++) { if (x > 0) { ids += ","; } ids += games[x].GameID; } lock (DB.Instance.SyncRoot) { DB.Instance.Execute(sql, Game.TABLE_NAME, ids); DB.Instance.Execute(sql, GameDisc.TABLE_NAME, ids); } }
private void delEmuButton_Click(object sender, EventArgs e) { if (selectedEmulator == null || selectedEmulator.UID < 0) { return; } if (MessageBox.Show( string.Format("Are you sure you want to remove {0} and\r\nall of it's associated games from the database?", selectedEmulator.Title), "Delete Emulator?", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } saveSelectedEmulator = false; saveThumbs = false; saveProfile = false; List <Game> games = DB.Instance.GetGames(selectedEmulator); if (games.Count > 0) { Importer importer = Emulators2Settings.Instance.Importer; BackgroundTaskHandler <Game> handler = new BackgroundTaskHandler <Game>() { Items = games }; handler.StatusDelegate = o => { return("removing " + o.Title); }; handler.ActionDelegate = o => { importer.Remove(o.GameID); using (ThumbGroup thumbGroup = new ThumbGroup(o)) { try { if (System.IO.Directory.Exists(thumbGroup.ThumbPath)) { System.IO.Directory.Delete(thumbGroup.ThumbPath, true); } } catch (Exception ex) { Logger.LogError("Error deleting {0} thumb directory - {1}", o.Title, ex.Message); } } return(true); }; using (Conf_ProgressDialog progressDlg = new Conf_ProgressDialog(handler)) progressDlg.ShowDialog(); } selectedEmulator.Delete(); if (selectedListItem != null) { int index = selectedListItem.Index; if (index > 0) { index--; } emulatorListView.Items.Remove(selectedListItem); if (emulatorListView.Items.Count > index) { emulatorListView.SelectedItems.Clear(); emulatorListView.Items[index].Selected = true; } } }