Example #1
0
        /// <summary>
        /// Presents the user with a <see cref="FolderBrowserDialog"/> to manually find their Halo installation.
        /// </summary>
        /// <returns>Returns the <see cref="HaloInstallation"/> associated with the chosen directory, or
        /// <see langword="null"/>.</returns>
        private HaloInstallation ManuallyFindHaloInstallation()
        {
            string path = String.Empty;

            Thread thread = new Thread(() =>
            {
                FolderBrowserDialog dialog = new FolderBrowserDialog
                {
                    Description  = Resources.HaloMCCTitle,
                    SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
                };

                while (true)
                {
                    DialogResult result = dialog.ShowDialog();
                    if (result == DialogResult.Cancel)
                    {
                        bool cancel = MsgBoxHelpers.ConfirmYesNo(Resources.ConfirmPatchCancel,
                                                                 yes: () => true,
                                                                 no: () => { } // do nothing
                                                                 );

                        if (cancel)
                        {
                            Environment.Exit(0);
                        }
                    }
                    else if (result == DialogResult.OK)
                    {
                        if (Directory.Exists(dialog.SelectedPath))
                        {
                            HaloInstallation halo = new HaloInstallation(new DirectoryInfo(dialog.SelectedPath));
                            if (halo.GetGameExecutablePath().Exists&& halo.GetPakFilePath().Exists)
                            {
                                break;
                            }
                        }

                        MsgBoxHelpers.Error(Resources.InvalidFolder);
                    }
                }

                path = dialog.SelectedPath;
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            return(new HaloInstallation(new DirectoryInfo(path)));
        }
Example #2
0
        /// <summary>
        /// Asynchronously runs the patching process on the specified file.
        /// </summary>
        /// <param name="halo">The Halo installation.</param>
        private async Task PatchAsync(HaloInstallation halo)
        {
            FileInfo pakFile = halo.GetPakFilePath();

            if (!(pakFile?.Exists ?? false))
            {
                MsgBoxHelpers.Error(Resources.PakFileNotFound,
                                    callback: () => Environment.Exit(0));
                return;
            }

            Stream stream = File.Open(pakFile.FullName, FileMode.Open);

            if (halo.GetGameVersion() > new Version(1, 1270, 0, 0))
            {
                bool abort = !MsgBoxHelpers.ConfirmYesNo(
                    String.Format(Resources.UntestedVersion, halo.GetGameVersion()),
                    icon: MessageBoxIcon.Warning,
                    yes: () => true,
                    no: () => { } // internally returns default(T)
                    );

                if (abort)
                {
                    Environment.Exit(0);
                }
            }
            else
            {
                if (!this.ConfirmPatchNeeded(stream))
                {
                    MsgBoxHelpers.Info(Resources.GameAlreadyPatched, Resources.PatchSkipped, () => Environment.Exit(0));
                    return;
                }
            }

            if (this.ConfirmBackup())
            {
                // must close stream for backup to take place
                stream.Close();
                stream.Dispose();

                BackupProgressForm progressForm = new BackupProgressForm();
                progressForm.Show();
                progressForm.BringToFront();

                await FileHelpers.CreateBackupAsync(pakFile.FullName,
                                                    percentage =>
                {
                    progressForm.PercentageProgressBar.Value = (int)Math.Floor(percentage);
                    progressForm.Text =
                        String.Format(Resources.CreatingBackupPercentage, percentage);

                    Application.DoEvents();
                })
                .ConfigureAwait(false);

                // reopen stream for patching
                stream = File.Open(pakFile.FullName, FileMode.Open);
            }

            this.ApplyPatch(stream);
            stream.Close();
            stream.Dispose();

            MsgBoxHelpers.Info(Resources.PatchSuccessful, Resources.Done, () => Environment.Exit(0));
        }