예제 #1
0
        private void InitializeWindow()
        {
            // Upgrade the stored settings if needed
            if (Properties.Settings.Default.UpgradeRequired)
            {
                Log.Information("Settings upgrade required...");
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeRequired = false;
                Properties.Settings.Default.Save();
            }

            LauncherSettings.TryMigrate(_setting);

            var gateStatus = false;

            try
            {
                gateStatus = _game.GetGateStatus();
            }
            catch
            {
                // ignored
            }

            if (!gateStatus)
            {
                WorldStatusPackIcon.Foreground = new SolidColorBrush(Color.FromRgb(242, 24, 24));
            }

            var version = Util.GetAssemblyVersion();

            if (Properties.Settings.Default.LastVersion != version)
            {
                new ChangelogWindow().ShowDialog();

                Properties.Settings.Default.LastVersion = version;

                Properties.Settings.Default.Save();
            }

            _accountManager = new AccountManager(_setting);

            var savedAccount = _accountManager.CurrentAccount;

            if (savedAccount != null)
            {
                SwitchAccount(savedAccount, false);
            }

            AutoLoginCheckBox.IsChecked = _setting.AutologinEnabled;

            if (_setting.AutologinEnabled && savedAccount != null && !Keyboard.Modifiers.HasFlag(ModifierKeys.Shift))
            {
                Log.Information("Engaging Autologin...");

                try
                {
#if DEBUG
                    HandleLogin(true);
                    return;
#else
                    if (!gateStatus)
                    {
                        var startLauncher = MessageBox.Show(
                            "Square Enix seems to be running maintenance work right now. The game shouldn't be launched. Do you want to start the official launcher to check for patches?", "XIVLauncher", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;

                        if (startLauncher)
                        {
                            Util.StartOfficialLauncher(_setting.GamePath, SteamCheckBox.IsChecked == true);
                        }

                        _setting.AutologinEnabled = false;
                        _isLoggingIn = false;
                    }
                    else
                    {
                        HandleLogin(true);
                        return;
                    }
#endif
                }
                catch (Exception ex)
                {
                    new ErrorWindow(ex, "Additionally, please check your login information or try again.", "AutoLogin", _setting)
                    .ShowDialog();
                    _setting.AutologinEnabled = false;
                    _isLoggingIn = false;
                }
            }

            if (_setting.GamePath?.Exists != true)
            {
                var setup = new FirstTimeSetup(_setting);
                setup.ShowDialog();
            }

            Task.Run(() => SetupHeadlines());

            AdminCheck.RunCheck();

            Show();
            Activate();

            Log.Information("MainWindow initialized.");
        }