private void MetroWindow_Activated(object sender, EventArgs e) { if (Cfg.CheckIfProcessIsRunning(ProcessName))// Check if halo 2 is running { ButtonAction.Content = "Close Game"; } }
private void MetroWindow_Activated(object sender, EventArgs e) { if (Cfg.CheckIfProcessIsRunning(ProcessName) || Cfg.CheckIfProcessIsRunning(ProcessStartup)) { ButtonAction.Content = "Close Game"; } }
private void ButtonAction_Click(object sender, RoutedEventArgs e) { if ((string)ButtonAction.Content == "Play") { try { if (Cfg.CheckIfProcessIsRunning(ProcessName)) // Kill halo2 if its running (Should help with black screens) { KillProcess(ProcessName); } Process.Start(ProcessName + ".exe"); // Good to go! (may need target parameters later) } catch { Trace.WriteLine("Could not find or launch Halo 2 application."); TextboxOutput.Text = "Could not find or launch Halo 2 application."; } } else if ((string)ButtonAction.Content == "Close Game") // Game is open { if (Cfg.CheckIfProcessIsRunning(ProcessName)) // Might be redundant but we don't want crashes { KillProcess(ProcessName); } ButtonAction.Content = "Play"; } else if ((string)ButtonAction.Content == "Update") { KillProcess(ProcessName); // Kills Halo 2 before updating TODO: add dialog before closing ButtonAction.Content = "Updating..."; // Button is still enabled if download is long it might look strange // TODO: Implement a filelist.txt on server so we can grab needed files (append build number to only grab latest) if (!File.Exists("MF.dll")) // If we don't find mf.dll { DownloadFile(UpdateServer + "MF.dll", "MF.dll"); } if (!File.Exists("h2Update.exe") && _halo2Version != LatestHalo2Version) // If halo2 needs an update { DownloadFile(UpdateServer + "h2Update.exe", "h2Update.exe"); } if (!File.Exists("gungame.ini")) // If we don't find gungame.ini { DownloadFile(UpdateServer + "gungame.ini", "gungame.ini"); } if (_localVersion != _latestVersion) // If our xlive.dll is old { DownloadFile(UpdateServer + "xlive.dll", "xlive.dll"); } //Never update the launcher. //if (_latestLauncherVersion != _localLauncherVersion) // If our launcher is old update //DownloadFile(UpdateServer + "h2online.exe", "h2online.exe"); //Trace.WriteLine("Files Needed: " + _fileCount); } else if ((string)ButtonAction.Content == "Restart") // Restart { Trace.WriteLine("Application restarting"); Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); } }
private void ButtonAction_Click(object sender, RoutedEventArgs e) { if ((string)ButtonAction.Content == "Play") { try { if (Cfg.CheckIfProcessIsRunning(ProcessName) || Cfg.CheckIfProcessIsRunning(ProcessStartup)) //Kill halo2 or startup if its running (Should help with black screens) { KillProcess(ProcessName); KillProcess(ProcessStartup); } StartProcess(ProcessStartup); } catch { Trace.WriteLine("Could not find or launch Halo 2 application."); TextboxOutput.Text = "Could not find or launch Halo 2 application."; DownloadConfirmGrid.Visibility = Visibility.Visible; // Show download confirm ButtonAction.Visibility = Visibility.Hidden; // Hide action button TextboxOutput.Text = "Halo 2 could not be found. Locate or download?"; } } else if ((string)ButtonAction.Content == "Close Game") //Game is open { if (Cfg.CheckIfProcessIsRunning(ProcessName) || Cfg.CheckIfProcessIsRunning(ProcessStartup)) //Might be redundant but we don't want crashes { KillProcess(ProcessName); KillProcess(ProcessStartup); } ButtonAction.Content = "Play"; } else if ((string)ButtonAction.Content == "Update") { if (Cfg.CheckIfProcessIsRunning(ProcessName) || Cfg.CheckIfProcessIsRunning(ProcessStartup)) { KillProcess(ProcessName); KillProcess(ProcessStartup); } ButtonAction.Content = "Updating..."; // Button is still enabled if download is long it might look strange DownloadUpdate(); } else if ((string)ButtonAction.Content == "Login") { // User Is logging in if (PasswordPanel.Visibility == Visibility.Visible) { var loginResponse = Api.Login(UsernameBox.Text, PasswordBox.Password); if (loginResponse != "0") // Correct login { Cfg.SetVariable("login_token =", loginResponse, ref Cfg.ConfigFile); Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile); Setup(); } else // Incorrect login { TextboxOutput.Text = "Incorrect Login"; PasswordBox.Password = ""; } } } else if ((string)ButtonAction.Content == "Register") { if (Api.IsValidEmail(EmailBox.Text)) { var registerResponse = Api.Register(UsernameBox.Text, PasswordBox.Password, EmailBox.Text); if (registerResponse != "0") { var loginResponse = Api.Login(UsernameBox.Text, PasswordBox.Password); PasswordPanel.Visibility = Visibility.Collapsed; EmailPanel.Visibility = Visibility.Collapsed; Application.Current.MainWindow.Height = 200; if (loginResponse != "0") { Cfg.SetVariable("login_token =", loginResponse, ref Cfg.ConfigFile); Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile); Setup(); } } else { TextboxOutput.Text = "Error Registering. Please try again shortly."; } } else { TextboxOutput.Text = "Invalid Email"; EmailBox.Text = ""; } } else if ((string)ButtonAction.Content == "Verify") { PathFinder(); } else if ((string)ButtonAction.Content == "Restart") // Restart { //DO NOT TOUCH THIS //THIS UPDATES THE LAUNCHER //LEAVE THIS CODE ALONE Task.Delay(5000); ProcessStartInfo file_overwrite = new ProcessStartInfo(); file_overwrite.CreateNoWindow = true; file_overwrite.WindowStyle = ProcessWindowStyle.Hidden; file_overwrite.WorkingDirectory = LauncherDirectory; file_overwrite.FileName = "cmd.exe"; file_overwrite.Arguments = "/C ping 127.0.0.1 -n 1 -w 5000 > Nul & Del h2online.exe & ping 127.0.0.1 -n 1 -w 2000 > Nul & rename h2online_temp.exe h2online.exe & ping 127.0.0.1 -n 1 -w 2000 > Nul & start h2online.exe"; Process.Start(file_overwrite); Process.GetCurrentProcess().Kill(); //DO NOT TOUCH THIS //THIS UPDATES THE LAUNCHER //LEAVE THIS CODE ALONE } }