private void InstallGamePatch(Launcher.LoginResult loginResult, bool gateStatus)
        {
            var mutex = new Mutex(false, "XivLauncherIsPatching");

            if (mutex.WaitOne(0, false))
            {
                if (Util.CheckIsGameOpen())
                {
                    CustomMessageBox.Show(
                        Loc.Localize("GameIsOpenError", "The game and/or the official launcher are open. XIVLauncher cannot patch the game if this is the case.\nPlease close the official launcher and try again."),
                        "XIVLauncher", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                    this.Dispatcher.Invoke(() =>
                    {
                        this.Show();
                        _isLoggingIn = false;
                    });
                }
                else
                {
                    Debug.Assert(loginResult.State == Launcher.LoginState.NeedsPatchGame,
                                 "loginResult.State == Launcher.LoginState.NeedsPatchGame ASSERTION FAILED");

                    var patcher = new PatchManager(loginResult.PendingPatches, App.Settings.GamePath, App.Settings.PatchPath, _installer);

                    var progressDialog = new PatchDownloadDialog(patcher);
                    progressDialog.Show();
                    this.Hide();

                    patcher.OnFinish += async(sender, args) =>
                    {
                        progressDialog.Dispatcher.Invoke(() =>
                        {
                            progressDialog.Hide();
                            progressDialog.Close();
                        });

                        if (args)
                        {
                            await this.Dispatcher.Invoke(() => StartGameAndAddon(loginResult, gateStatus));

                            _installer.Stop();
                        }
                        else
                        {
                            this.Dispatcher.Invoke(() =>
                            {
                                this.Show();
                                _isLoggingIn = false;
                            });
                        }

                        mutex.Close();
                        mutex = null;
                    };

                    patcher.Start();
                }
            }
            else
            {
                CustomMessageBox.Show(Loc.Localize("PatcherAlreadyInProgress", "XIVLauncher is already patching your game in another instance. Please check if XIVLauncher is still open."), "XIVLauncher", MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(0);
            }
        }
        private void HandleBootCheck(Action whenFinishAction)
        {
            try
            {
                App.Settings.PatchPath ??= new DirectoryInfo(Path.Combine(Paths.RoamingPath, "patches"));

                Game.Patch.PatchList.PatchListEntry[] bootPatches = null;
                try
                {
                    bootPatches = _launcher.CheckBootVersion(App.Settings.GamePath);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Unable to check boot version.");
                    MessageBox.Show(Loc.Localize("CheckBootVersionError", "XIVLauncher was not able to check the boot version for the select game installation. This can happen if a maintenance is currently in progress or if your connection to the version check server is not available. Please report this error if you are able to login with the official launcher, but not XIVLauncher."), "XIVLauncher", MessageBoxButton.OK, MessageBoxImage.Error);

                    _isLoggingIn = false;

                    Task.Run(SetupHeadlines);
                    Show();
                    Activate();
                    return;
                }

                if (bootPatches != null)
                {
                    var mutex = new Mutex(false, "XivLauncherIsPatching");
                    if (mutex.WaitOne(0, false))
                    {
                        if (Util.CheckIsGameOpen())
                        {
                            MessageBox.Show(
                                Loc.Localize("GameIsOpenError",
                                             "The game and/or the official launcher are open. XIVLauncher cannot patch the game if this is the case.\nPlease close the official launcher and try again."),
                                "XIVLauncher", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                            Environment.Exit(0);
                            return;
                        }

                        var patcher = new PatchManager(bootPatches, App.Settings.GamePath,
                                                       App.Settings.PatchPath, _installer);

                        var progressDialog = new PatchDownloadDialog(patcher);
                        progressDialog.Show();
                        this.Hide();

                        patcher.OnFinish += (sender, args) =>
                        {
                            progressDialog.Dispatcher.Invoke(() =>
                            {
                                progressDialog.Hide();
                                progressDialog.Close();
                            });

                            if (args)
                            {
                                whenFinishAction?.Invoke();
                            }
                            else
                            {
                                this.Dispatcher.Invoke(() =>
                                {
                                    this.Show();
                                    _isLoggingIn = false;
                                });
                            }

                            // This is a good indicator that we should clear the UID cache
                            UniqueIdCache.Instance.Reset();

                            mutex.Close();
                            mutex = null;
                        };

                        patcher.Start();
                    }
                    else
                    {
                        MessageBox.Show(Loc.Localize("PatcherAlreadyInProgress", "XIVLauncher is already patching your game in another instance. Please check if XIVLauncher is still open."), "XIVLauncher", MessageBoxButton.OK, MessageBoxImage.Error);
                        Environment.Exit(0);
                    }
                }
                else
                {
                    whenFinishAction?.Invoke();
                }
            }
            catch (Exception ex)
            {
                new ErrorWindow(ex, "Could not patch boot.", nameof(HandleBootCheck)).ShowDialog();
                Environment.Exit(0);
            }
        }