private void LocateButton_Click(object sender, RoutedEventArgs e)
        {
            using (var ofd = new OpenFileDialog()) //Creates a file dialog window
            {
                ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                // Sets default location in dialog window
                ofd.Title       = @"Locate Halo 2 exe";           // Gives it a title
                ofd.Filter      = @"Halo 2 Executable|halo2.exe"; // Filters out unncecessary files
                ofd.FilterIndex = 1;                              // Allows only 1 filter index

                //Ff chosen it will set the file path to the install path
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (ofd.SafeFileName != null)
                    {
                        Cfg.InstallPath = ofd.FileName.Replace(ofd.SafeFileName, ""); //removes halo2.exe from file name.
                    }
                }
            }
            Cfg.SetVariable("install directory =", Cfg.InstallPath, ref Cfg.ConfigFile); //sets variable in config
            Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile);           //saves config
            ButtonAction.Content = !CheckVersion() ? "Update" : "Play";                  //Check version and change main button depending
            Trace.WriteLine("Halo 2 game installation was detected.");                   //writes to debug file
            TextboxOutput.Text             = "Game installation verified.";              //displays what happened
            DownloadConfirmGrid.Visibility = Visibility.Hidden;
            ButtonAction.Visibility        = Visibility.Visible;
        }
Пример #2
0
        private bool Load() // TODO: Databind this
        {
            try
            {
                // If uid is default generate a new one
                if (Cfg.ConfigFile["profile xuid 1 ="] == "0000000000000000" || Cfg.ConfigFile["profile xuid 1 ="] == "")
                {
                    UidBox.Text = Auth.GenerateUid(); //Update text box with uid from generate
                    Cfg.SetVariable("profile xuid 1 =", UidBox.Text, ref Cfg.ConfigFile);
                    Cfg.SaveConfigFile("xlive.ini", Cfg.ConfigFile);
                }

                // Set textbox to "Player" for numbering TODO: Halo 2 names
                PlayerName.Text = Cfg.ConfigFile["profile name 1 ="] == " " ? "Player" : Cfg.ConfigFile["profile name 1 ="];

                CboxDebug.IsChecked = Convert.ToBoolean(Convert.ToInt32(Cfg.ConfigFile["debug ="]));
                UidBox.Text         = Cfg.ConfigFile["profile xuid 1 ="]; // Uid box text from cfg
                Trace.WriteLine("UID: " + UidBox.Text);                   // Write UID
                Trace.WriteLine("Name: " + PlayerName.Text);              // Write Name
                Trace.WriteLine("Debug: " + CboxDebug.IsChecked);         // Write debug selection
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        private void PathFinder()
        {
            if (!IsLoaded) //Don't update cfg while the control loads
            {
                return;
            }

            using (System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog()) //Creates a file dialog window
            {
                ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);    //sets default location in dialog window
                ofd.Title            = "Navigate to Halo 2 Install Path";                               //gives it a title
                ofd.Filter           = "Halo 2 Executable|halo2.exe";                                   //filters out unncecessary files
                ofd.FilterIndex      = 1;                                                               //allows only 1 filter index
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)                           //if chosen it will set the file path to the install path
                {
                    Cfg.InstallPath    = ofd.FileName.Replace(ofd.SafeFileName, "");                    //removes halo2.exe from file name.
                    TextboxOutput.Text = "Game installation verified.";                                 //displays what happened
                    Cfg.SetVariable("install_path =", Cfg.InstallPath, ref Cfg.ConfigFile);             //sets variable in config
                    Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile);                  //saves config
                    GetLatestVersions();
                    Setup();
                }
                Trace.WriteLine("Halo 2 game installation was detected."); //writes to debug file
            }
        }
Пример #4
0
        private void PlayerName_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!IsLoaded) // Makes sure that we don't update cfg while the control loads
            {
                return;
            }

            Cfg.SetVariable("profile name 1 =", PlayerName.Text, ref Cfg.ConfigFile);
            Cfg.SaveConfigFile("xlive.ini", Cfg.ConfigFile);
        }
        /*
         * private void CboxDebug_Changed(object sender, RoutedEventArgs e)
         * {
         * if (!IsLoaded) //Don't update cfg while the control loads
         *  return;
         *
         * // Bools convert "nicely" to 0s and 1s :)
         * Cfg.SetVariable("debug =", Convert.ToString(Convert.ToInt32(CboxDebug.IsChecked)), ref Cfg.ConfigFile);
         * Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile);
         * }
         */

        private void GameArguments_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!IsLoaded) //Don't update cfg while the control loads
            {
                return;
            }

            Cfg.SetVariable("arguments =", GameArguments.Text, ref Cfg.ConfigFile);
            Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile);
        }
Пример #6
0
        private void CboxDebug_Changed(object sender, RoutedEventArgs e)
        {
            if (!IsLoaded) // Don't update cfg while the control loads
            {
                return;
            }

            // Bools convert "nicely" to 0s and 1s :)
            Cfg.SetVariable("debug =", Convert.ToString(Convert.ToInt32(CboxDebug.IsChecked)), ref Cfg.ConfigFile);
            Cfg.SaveConfigFile("xlive.ini", Cfg.ConfigFile);
        }
        private void PlayerName_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!IsLoaded || ButtonAction.Content == "Play") // Makes sure that we don't update cfg while the control loads
            {
                return;
            }

            StartTimer();

            Cfg.SetVariable("name =", UsernameBox.Text, ref Cfg.ConfigFile);
            Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile);
        }
        private async void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            if (_disableHalo2Download)
            {
                TextboxOutput.Text = "Halo 2 download is currently disabled please check back later";
                return;
            }

            DownloadConfirmGrid.Visibility = Visibility.Hidden;
            CancelButton.Visibility        = Visibility.Visible;
            TextboxOutput.Text             = "Decrypting Url...";

            using (var folderBrowser = new FolderBrowserDialog())                               //Creates a file dialog window
            {
                folderBrowser.RootFolder          = Environment.SpecialFolder.Desktop;          // Sets starting location in dialog window
                folderBrowser.Description         = @"Select where you want to install Halo 2"; // Gives it a title
                folderBrowser.ShowNewFolderButton = true;

                if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Cfg.InstallPath = folderBrowser.SelectedPath;
                    Trace.WriteLine("Halo 2 install path selected: " + Cfg.InstallPath);    //writes to debug file
                    Cfg.SetVariable("install_path =", Cfg.InstallPath, ref Cfg.ConfigFile); //sets variable in config
                    Cfg.SaveConfigFile(Cfg.InstallPath + "xlive.ini", Cfg.ConfigFile);      //saves config
                }
                else
                {
                    return;
                }
            }

            // Downloading
            try
            {
                await MegaDownload(GetRedirectUrl(_halo2DownloadUrl));
            }
            catch
            {
                TextboxOutput.Text             = "Error Downloading Halo 2. Please Restart.";
                DownloadConfirmGrid.Visibility = Visibility.Hidden;
                CancelButton.Visibility        = Visibility.Hidden;
                ButtonAction.Visibility        = Visibility.Visible;
                ButtonAction.Content           = "Restart";
                return;
            }

            // Extracting
            var compressed = ArchiveFactory.Open(Cfg.InstallPath + Halo2DownloadName);

            TextboxOutput.Text = "Extracting...";

            foreach (var entry in compressed.Entries)
            {
                if (!entry.IsDirectory)
                {
                    entry.WriteToDirectory(Cfg.InstallPath, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);
                }
            }

            ButtonAction.Content = !CheckVersion() ? "Update" : "Play";         //Check version and change main button depending
            Trace.WriteLine("Halo 2 game installation complete");               //writes to debug file
            TextboxOutput.Text             = "Halo 2 downloaded and installed"; //displays what happened
            DownloadConfirmGrid.Visibility = Visibility.Hidden;
            ButtonAction.Visibility        = Visibility.Visible;
        }
        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
            }
        }