static void Main(string[] args) { if (SimpleGameReLauncher.GetProcess("HawkenLauncher") != null) { MessageBox.Show("There can only be one instance of the HawkenLauncher open at a time"); Environment.Exit(0); } string hawkenPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "MeteorEntertainment", "Hawken"); //Assign to the default path for now. try { hawkenPath = Program.GetHawkenInstallPath(); //Try to get path from registry } catch (Exception) { MessageBox.Show("Hawken not found. Please install Hawken from http://www.playhawken.com/ before playing"); Process.Start("http://www.playhawken.com/"); Environment.Exit(0); } var notifyIcon = new NotifyIcon(); notifyIcon.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); notifyIcon.Text = "Hawken is running. HawkenExhaust 0.3"; notifyIcon.Visible = true; try { new HawkenReLauncher("HawkenGame-Win32-Shipping", Path.Combine(hawkenPath, "Binaries", "Win32"), "HawkenLauncher", hawkenPath).runAll(); } catch (FileNotFoundException) { MessageBox.Show("Hawken not found. Please install Hawken from http://www.playhawken.com/ before playing"); Process.Start("http://www.playhawken.com/"); Environment.Exit(0); } }
/// <summary> /// This loop runs until the launcher process has quit. /// To close the application, handle OnLauncherClose. /// </summary> /// <param name="launcherProcessName">name of the launcher processes</param> protected void LauncherQuitListener(string launcherProcessName) { BackgroundWorker launcherChecker = new BackgroundWorker(); launcherChecker.DoWork += delegate { using (Process launcher = SimpleGameReLauncher.GetProcess(launcherProcessName)) launcher.WaitForExit(); }; launcherChecker.RunWorkerCompleted += delegate { OnLauncherClose(this); launcherChecker.Dispose(); }; launcherChecker.RunWorkerAsync(); }
/// <summary> /// This loop runs indefinetley looking for processName and then relaunching it. /// It runs on the main thread so as to keep the application alive. /// </summary> /// <param name="processName">name of the process to look for</param> /// <param name="processPath">path where process is located</param> protected void GameProcessListener(string processName, string processPath) { while (true) { Process process = null; while (process == null) { if (SimpleGameReLauncher.IsProcessRunning(processName)) { process = SimpleGameReLauncher.GetProcess(processName); process.Kill(); process.Dispose(); //Dispose the old process. break; } Thread.Sleep(500); } using (var gameProcess = Process.Start(Path.Combine(processPath, processName) + ".exe")) { gameProcess.WaitForExit(); } } }