示例#1
0
        private void Login(CharacterData data)
        {
            if (!XIVGame.GetGateStatus())
            {
                MessageBox.Show("Square Enix seems to be running maintenance work right now. The game shouldn't be launched.", "Error", MessageBoxButton.OK);
                return;
            }

            string otp = string.Empty;

            if (data.useOtp)
            {
                OTPInputDialog inputDialog = new OTPInputDialog();
                inputDialog.ShowDialog();

                otp = inputDialog.UserInputOTPString;
                if (otp == string.Empty)
                {
                    return;
                }
            }

            try
            {
                var sid = XIVGame.GetRealSid(data.username, data.password, otp, data.isSteam);
                if (sid.Equals("BAD"))
                {
                    return;
                }

                var ffxivGame = XIVGame.LaunchGame(sid, 1, true, 0, data.isSteam);
                if (ffxivGame != null)
                {
                    EscalateProcess(ffxivGame, data.cpuIds, data.priority);
                }

                App.Current.Shutdown();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Logging in failed, check your login information or try again.\n" + exc.Message, "Error", MessageBoxButton.OK);
            }
        }
        private async void MainView_Loaded(
            object sender,
            RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(this.Config.SavedID))
            {
                this.IDTextBox.Focusable = true;
                this.IDTextBox.Focus();
            }
            else
            {
                this.OTPTextBox.Focusable = true;
                this.OTPTextBox.Focus();
            }

            if (!this.IsActive)
            {
                this.Activate();
            }

            if (!this.Config.ExistGame)
            {
                MessageBox.Show(
                    @"You will now be asked to select the path your game is installed in." + Environment.NewLine +
                    @"It should contain the folders ""game"" and ""boot"".",
                    "Select Game Path",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                var fsd = new FolderSelectDialog();
                fsd.Title = "Choose your game path";

                if (fsd.ShowDialog(new WindowInteropHelper(this).Handle))
                {
                    this.Config.GamePath = fsd.FileName;
                }
            }

            if (this.Config.AutoLogin &&
                !SettingsHelper.IsAdministrator() &&
                this.CanExecute())
            {
                var stat = await Task.Run(() => XIVGame.GetGateStatus());

                if (!stat)
                {
                    MessageBox.Show(
                        "SQUARE ENIX seems to be running maintenance work right now.\nThe game shouldn't be launched.",
                        "Login failed",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information);

                    this.Config.AutoLogin = false;
                    Settings.Instance.Save();

                    return;
                }

                try
                {
                    await Task.Run(() =>
                                   XIVGame.LaunchGame(
                                       XIVGame.GetRealSid(
                                           this.Config.SavedID,
                                           this.Config.SavedPW,
                                           this.Config.OnetimePassword),
                                       (int)this.Config.Language,
                                       this.Config.IsDX11,
                                       this.Config.UseSteam,
                                       (int)this.Config.ExpansionLevel));

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(
                        "Logging in failed, check your login information or try again.\n\n" + ex,
                        "Login failed",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }
        private async void LoginAsync()
        {
            Settings.Instance.Save();

#if !DEBUG
            if (!this.Config.ExistGame)
            {
                MessageBox.Show(
                    "FFXIV not found.\nPlease setup options. [Options] -> [Game Path]",
                    "Not Avalable",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                return;
            }

            var stat = await Task.Run(() => XIVGame.GetGateStatus());

            if (!stat)
            {
                MessageBox.Show(
                    "SQUARE ENIX seems to be running maintenance work right now.\nThe game shouldn't be launched.",
                    "Login failed",
                    MessageBoxButton.OK,
                    MessageBoxImage.Information);

                return;
            }
#endif

            try
            {
                var kicked = false;

                foreach (var tool in Models.Settings.Instance.ToolSettings)
                {
                    tool.IsRunning = false;
                }

                // ツールを起動する
                await Task.Run(() =>
                {
                    foreach (var tool in Models.Settings.Instance.ToolSettings
                             .Where(x =>
                                    x.IsEnabled &&
                                    !x.IsPostProcess)
                             .OrderBy(x => x.Priority))
                    {
                        if (tool.Run())
                        {
                            kicked = true;
                            Thread.Sleep(TimeSpan.FromSeconds(0.5));
                        }

                        tool.IsRunning = true;
                    }
                });

                if (kicked)
                {
                    await Task.Delay(TimeSpan.FromSeconds(Settings.Instance.DelayLaunchFFXIV));
                }

#if !DEBUG
                // FFXIVを起動する
                await Task.Run(() =>
                               XIVGame.LaunchGame(
                                   XIVGame.GetRealSid(
                                       this.Config.SavedID,
                                       this.Config.SavedPW,
                                       this.Config.OnetimePassword),
                                   (int)this.Config.Language,
                                   this.Config.IsDX11,
                                   this.Config.UseSteam,
                                   (int)this.Config.ExpansionLevel));
#else
                Debug.WriteLine("●FFXIV Started");
#endif
                var ffxivStartedTime = DateTime.Now;

                // ポストプロセスツールを起動する
                await Task.Run(() =>
                {
                    var posts =
                        from x in Models.Settings.Instance.ToolSettings
                        where
                        x.IsEnabled &&
                        x.IsPostProcess
                        orderby
                        x.Delay,
                    x.Priority
                    select
                    x;

                    var startTime = DateTime.Now;
                    while ((DateTime.Now - startTime).TotalMinutes <= 5.0)
                    {
                        foreach (var tool in posts)
                        {
                            if (DateTime.Now >= ffxivStartedTime.AddSeconds(tool.Delay))
                            {
                                tool.Run();
                                tool.IsRunning = true;
                            }
                        }

                        if (!posts.Any(x => !x.IsRunning))
                        {
                            break;
                        }

                        Thread.Sleep(TimeSpan.FromSeconds(0.05));
                    }
                });

                // 起動したら終わる
                await Task.Delay(TimeSpan.FromSeconds(0.5));

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "Logging in failed, check your login information or try again.\n\n" + ex,
                    "Login failed",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
        }