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);
        }
Ejemplo n.º 2
0
        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();
            }
        }