/// <Summary> /// When the 'Open Game' button is pressed, open a file browser to locate the game and open it. /// </Summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void OpenGameButton_Click(object sender, EventArgs e) { string intelFileName = ""; bool gameLaunched = false; // have the user identify the game to open try { OpenFileDialog fd = new OpenFileDialog(); fd.Title = "Open Game"; fd.FileName = "*" + Global.IntelExtension; DialogResult result = fd.ShowDialog(); if (result != DialogResult.OK) { return; } intelFileName = fd.FileName; } catch { Report.FatalError("Unable to open a game."); } // Launch the GUI CommandArguments args = new CommandArguments(); args.Add(CommandArguments.Option.GuiSwitch); args.Add(CommandArguments.Option.IntelFileName, intelFileName); try { Process.Start(Assembly.GetExecutingAssembly().Location, args.ToString()); gameLaunched = true; } catch { Report.Error("NovaLauncher.cs: OpenGameButton_Click() - Failed to launch GUI."); } // Launch the Console if this is a local game, i.e. if the console.state is in the same directory. string serverStateFileName = ""; FileInfo intelFileInfo = new FileInfo(intelFileName); string gamePathName = intelFileInfo.DirectoryName; DirectoryInfo gameDirectoryInfo = new DirectoryInfo(gamePathName); FileInfo[] gameFilesInfo = gameDirectoryInfo.GetFiles(); foreach (FileInfo file in gameFilesInfo) { if (file.Extension == Global.ServerStateExtension) { serverStateFileName = file.FullName; } } if (serverStateFileName.Length > 0) { args.Clear(); args.Add(CommandArguments.Option.ConsoleSwitch); args.Add(CommandArguments.Option.StateFileName, serverStateFileName); try { Process.Start(Assembly.GetExecutingAssembly().Location, args.ToString()); gameLaunched = true; } catch { Report.Error("NovaLauncher.cs: OpenGameButton_Click() - Failed to launch GUI."); } } if (gameLaunched) { Application.Exit(); } }