Beispiel #1
0
        internal static int Run(string[] args)
        {
            ConfigManager.DoNotSaveSettings = true;
            string        romPath;
            List <string> luaScriptsToLoad;

            CommandLineHelper.GetRomPathFromCommandLine(CommandLineHelper.PreprocessCommandLineArguments(args, false), out romPath, out luaScriptsToLoad);
            if (romPath == null)
            {
                //No rom specified
                return(-1);
            }

            List <string> lcArgs = CommandLineHelper.PreprocessCommandLineArguments(args, true);

            int    timeout    = 100;       //100 seconds
            string timeoutArg = lcArgs.Find(arg => arg.StartsWith("/timeout="));

            if (timeoutArg != null)
            {
                int timeoutValue;
                if (Int32.TryParse(timeoutArg.Substring(timeoutArg.IndexOf("=") + 1), out timeoutValue))
                {
                    timeout = timeoutValue;
                }
            }

            InteropEmu.InitDll();
            ConfigManager.ProcessSwitches(lcArgs);
            ConfigManager.Config.ApplyConfig();
            InteropEmu.SetFlag(EmulationFlags.ConsoleMode, true);

            InteropEmu.InitializeEmu(ConfigManager.HomeFolder, IntPtr.Zero, IntPtr.Zero, true, true, true);

            InteropEmu.LoadROM(romPath, string.Empty);

            DebugWorkspaceManager.GetWorkspace();

            foreach (string luaScript in luaScriptsToLoad)
            {
                try {
                    string script = File.ReadAllText(luaScript);
                    InteropEmu.DebugLoadScript(luaScript, script);
                } catch { }
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            Task.Run(() => {
                InteropEmu.Run();
            });

            InteropEmu.SetFlag(EmulationFlags.ForceMaxSpeed, true);

            sw.Start();
            int result = -1;

            while (sw.ElapsedMilliseconds < timeout * 1000)
            {
                System.Threading.Thread.Sleep(100);

                if (!InteropEmu.IsRunning())
                {
                    result = InteropEmu.GetStopCode();
                    break;
                }
            }

            InteropEmu.Stop();
            InteropEmu.Release();
            return(result);
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            try {
                Task.Run(() => {
                    //Cache deserializers in another thread
                    new XmlSerializer(typeof(Configuration));
                    new XmlSerializer(typeof(DebugWorkspace));
                });

                if (Type.GetType("Mono.Runtime") != null)
                {
                    Program.IsMono = true;
                }

                Program.OriginalFolder = Directory.GetCurrentDirectory();

                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                Application.ThreadException += Application_ThreadException;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                //Enable TLS 1.0/1.1/1.2 support
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (ConfigManager.GetConfigFile() == null)
                {
                    //Show config wizard
                    ResourceHelper.LoadResources(Language.SystemDefault);
                    Application.Run(new frmConfigWizard());

                    if (ConfigManager.GetConfigFile() == null)
                    {
                        Application.Exit();
                        return;
                    }
                }

                AppDomain.CurrentDomain.AssemblyResolve += LoadAssemblies;

                Directory.CreateDirectory(ConfigManager.HomeFolder);
                Directory.SetCurrentDirectory(ConfigManager.HomeFolder);
                try {
                    if (!ResourceManager.ExtractResources())
                    {
                        return;
                    }
                } catch (FileNotFoundException e) {
                    string message = "The Microsoft .NET Framework 4.5 could not be found. Please download and install the latest version of the .NET Framework from Microsoft's website and try again.";
                    switch (ResourceHelper.GetCurrentLanguage())
                    {
                    case Language.French: message = "Le .NET Framework 4.5 de Microsoft n'a pas été trouvé. Veuillez télécharger la plus récente version du .NET Framework à partir du site de Microsoft et essayer à nouveau."; break;

                    case Language.Japanese: message = "Microsoft .NET Framework 4.5はインストールされていないため、Mesenは起動できません。Microsoft .NET Frameworkの最新版をMicrosoftのサイトからダウンロードして、インストールしてください。"; break;

                    case Language.Russian: message = "Microsoft .NET Framework 4.5 не найден. Пожалуйста загрузите и установите последнюю версию .NET Framework с сайта Microsoft и попробуйте снова."; break;

                    case Language.Spanish: message = "Microsoft .NET Framework 4.5 no se ha encontrado. Por favor, descargue la versión más reciente de .NET Framework desde el sitio de Microsoft y vuelva a intentarlo."; break;

                    case Language.Ukrainian: message = "Microsoft .NET Framework 4.5 не знайдений. Будь ласка завантажте і встановіть останню версію .NET Framework з сайту Microsoft і спробуйте знову."; break;

                    case Language.Portuguese: message = "Microsoft .NET Framework 4.5 não foi encontrado. Por favor, baixe a versão mais recente de .NET Framework do site da Microsoft e tente novamente."; break;

                    case Language.Chinese: message = "找不到 Microsoft .NET Framework 4.5,请访问 Microsoft 官网下载安装之后再试。"; break;
                    }
                    MessageBox.Show(message + Environment.NewLine + Environment.NewLine + e.ToString(), "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                } catch (Exception e) {
                    string message = "An unexpected error has occurred.\n\nError details:\n{0}";
                    switch (ResourceHelper.GetCurrentLanguage())
                    {
                    case Language.French: message = "Une erreur inattendue s'est produite.\n\nDétails de l'erreur :\n{0}"; break;

                    case Language.Japanese: message = "予期しないエラーが発生しました。\n\nエラーの詳細:\n{0}"; break;

                    case Language.Russian: message = "Неизвестная ошибка.&#xA;&#xA;Подробно:&#xA;{0}"; break;

                    case Language.Spanish: message = "Se ha producido un error inesperado.&#xA;&#xA;Detalles del error:&#xA;{0}"; break;

                    case Language.Ukrainian: message = "Невідома помилка.&#xA;&#xA;Детально:&#xA;{0}"; break;

                    case Language.Portuguese: message = "Houve um erro inesperado.&#xA;&#xA;Detalhes do erro:&#xA;{0}"; break;

                    case Language.Chinese: message = "发生意外错误。\n\n详情:\n{0}"; break;
                    }
                    MessageBox.Show(string.Format(message, e.ToString()), "Mesen", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (!RuntimeChecker.TestDll())
                {
                    return;
                }

                if (CommandLineHelper.PreprocessCommandLineArguments(args, true).Contains("/testrunner"))
                {
                    Environment.ExitCode = TestRunner.Run(args);
                    return;
                }

                using (SingleInstance singleInstance = new SingleInstance()) {
                    if (singleInstance.FirstInstance || !ConfigManager.Config.PreferenceInfo.SingleInstance)
                    {
                        frmMain frmMain = new frmMain(args);

                        singleInstance.ListenForArgumentsFromSuccessiveInstances();
                        singleInstance.ArgumentsReceived += (object sender, ArgumentsReceivedEventArgs e) => {
                            if (frmMain.IsHandleCreated)
                            {
                                frmMain.BeginInvoke((MethodInvoker)(() => {
                                    frmMain.ProcessCommandLineArguments(CommandLineHelper.PreprocessCommandLineArguments(e.Args, true), false);
                                    frmMain.LoadGameFromCommandLine(CommandLineHelper.PreprocessCommandLineArguments(e.Args, false));
                                }));
                            }
                        };

                        Application.Run(frmMain);
                    }
                    else
                    {
                        if (singleInstance.PassArgumentsToFirstInstance(args))
                        {
                            Process current = Process.GetCurrentProcess();
                            foreach (Process process in Process.GetProcessesByName(current.ProcessName))
                            {
                                if (process.Id != current.Id)
                                {
                                    Program.SetForegroundWindow(process.MainWindowHandle);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Application.Run(new frmMain(args));
                        }
                    }
                }
            } catch (Exception e) {
                MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, e.ToString());
            }
        }