Example #1
0
        public async void Execute(object parameter)
        {
            try
            {
                if (_friendListViewModel?.FriendListCount >= FriendService.MaxAllowedFriends)
                {
                    GenericMessageDialog.Show(Properties.Resources.FriendListMaxFriendsReached,
                                              DialogIcon.Warning,
                                              DialogOptions.Ok);
                    return;
                }

                var friend = (FriendListItem)parameter;
                _friendListViewModel.FriendListItems.Remove(friend);
                await _friendService.ConfirmFriendRequest(friend.XUid);

                _updateFriendAction();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Properties.Resources.GenericUnexpectedErrorMessage,
                                          DialogIcon.Error,
                                          DialogOptions.Ok);
            }
        }
        private void LauncherOpenBtn_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            try
            {
                var launcherPath = Assembly.GetEntryAssembly().Location;

                if (!File.Exists(launcherPath))
                {
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperLauncherNotFound, DialogIcon.Error, DialogOptions.Ok);
                    Close();
                    return;
                }

                //outbound_tcp
                var rule = FirewallHelper.RuleExist("celeste_launcher_outbound_tcp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_launcher_outbound_tcp");
                }

                FirewallHelper.AddApplicationRule("celeste_launcher_outbound_tcp", launcherPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.TCP);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
            }

            LoadFirewallRules();

            IsEnabled = true;
        }
Example #3
0
        private async void OnVerifyEmail(object sender, RoutedEventArgs args)
        {
            if (!Misc.IsValidEmailAdress(EmailField.InputContent))
            {
                GenericMessageDialog.Show(Properties.Resources.RegisterInvalidEmail, DialogIcon.Error);
                return;
            }

            EmailInputGroup.IsEnabled = false;
            ResentKeyBtn.IsEnabled    = false;

            try
            {
                var response = await LegacyBootstrapper.WebSocketApi.DoValidMail(EmailField.InputContent);

                if (response.Result)
                {
                    GenericMessageDialog.Show($"{response.Message}", DialogIcon.Warning);
                    UserInformationInputGroup.IsEnabled = true;
                    EmailInputGroup.IsEnabled           = false;
                }
                else
                {
                    GenericMessageDialog.Show($"{Properties.Resources.RegisterError} {response.Message}", DialogIcon.Error);
                    EmailInputGroup.IsEnabled = true;
                    ResentKeyBtn.IsEnabled    = true;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error);
            }
        }
        private void EnableDiagnosticsMode(object sender, RoutedEventArgs e)
        {
            LegacyBootstrapper.UserConfig.IsDiagnosticMode = !LegacyBootstrapper.UserConfig.IsDiagnosticMode;

            if (LegacyBootstrapper.UserConfig.IsDiagnosticMode)
            {
                try
                {
                    var procdumpFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "procdump.exe");
                    if (!File.Exists(procdumpFileName))
                    {
                        var dialog = new GenericMessageDialog(Properties.Resources.EnableDiagnosticsModeInstallProcdumpPrompt, DialogIcon.Warning, DialogOptions.YesNo);
                        dialog.Owner = Window.GetWindow(this);

                        var dr = dialog.ShowDialog();
                        if (dr.Value == true)
                        {
                            var procDumpInstallerDialog = new ProcDumpInstaller();
                            procDumpInstallerDialog.Owner = Window.GetWindow(this);
                            procDumpInstallerDialog.ShowDialog();
                        }
                        else
                        {
                            LegacyBootstrapper.UserConfig.IsDiagnosticMode = false;
                        }
                    }
                }
                catch (Exception exception)
                {
                    LegacyBootstrapper.UserConfig.IsDiagnosticMode = false;
                    GenericMessageDialog.Show($"{Properties.Resources.EnableDiagnosticsModeProcdumpInstallError} {exception.Message}", DialogIcon.Warning, DialogOptions.Ok);
                }
            }
        }
        private void MultiplayerOpenBtn_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            try
            {
                //inbound_udp
                var rule = FirewallHelper.RuleExist("celeste_port1000_inbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_port1000_inbound_udp");
                }

                FirewallHelper.AddPortRule("celeste_port1000_inbound_udp", 1000,
                                           FirewallDirection.Inbound, FirewallProtocol.UDP);

                //outbound_udp
                rule = FirewallHelper.RuleExist("celeste_port1000_outbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_port1000_outbound_udp");
                }

                FirewallHelper.AddPortRule("celeste_port1000_outbound_udp", 1000,
                                           FirewallDirection.Outbound, FirewallProtocol.UDP);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
            }

            LoadFirewallRules();

            IsEnabled = true;
        }
Example #6
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                SetupScenarioSymlink();
                await GameScanner.InitializeFromCelesteManifest();

                var progress    = new Progress <ScanProgress>();
                var subProgress = new Progress <ScanSubProgress>();

                progress.ProgressChanged    += ProgressChanged;
                subProgress.ProgressChanged += SubProgressChanged;

                if (await Task.Run(async() => await GameScanner.ScanAndRepair(progress, subProgress, 1)))
                {
                    CurrentFileLabel.Content  = string.Empty;
                    MainProgressLabel.Content = Celeste_Launcher_Gui.Properties.Resources.GameScannerDoneLabel;
                    FileProgress.ProgressBar.IsIndeterminate = false;
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GameScannerDoneMessage, DialogIcon.None, DialogOptions.Ok);
                }
                else
                {
                    FailGameScan(Celeste_Launcher_Gui.Properties.Resources.GameScannerDidNotPass);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                FailGameScan(Celeste_Launcher_Gui.Properties.Resources.GameScannerFailed);
            }
            finally
            {
                Close();
            }
        }
Example #7
0
 private void FailGameScan(string reason)
 {
     FileProgress.ProgressBar.Foreground      = Brushes.Red;
     ScanTotalProgress.ProgressBar.Foreground = Brushes.Red;
     CurrentFileLabel.Content      = string.Empty;
     MainProgressLabel.Content     = string.Empty;
     TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error;
     GenericMessageDialog.Show(reason, DialogIcon.Error, DialogOptions.Ok);
 }
Example #8
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            LegacyBootstrapper.LoadUserConfig();
            LegacyBootstrapper.SetUILanguage();
            Steam.ConvertToSteam(LegacyBootstrapper.UserConfig.GameFilesPath);

            var dialog = new GenericMessageDialog(Celeste_Launcher_Gui.Properties.Resources.SteamConverterSuccess, DialogIcon.None, DialogOptions.Ok);

            dialog.ShowDialog();

            Current.Shutdown();
        }
        private void OpenUpdater(object sender, RoutedEventArgs e)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                GenericMessageDialog.Show(Properties.Resources.GameAlreadyRunningError, DialogIcon.Error, DialogOptions.Ok);
                return;
            }

            var updater = new UpdateWindow();

            updater.Owner = Window.GetWindow(this);
            updater.ShowDialog();
        }
        public async void Execute(object parameter)
        {
            try
            {
                var friend = (FriendListItem)parameter;
                _friendListViewModel.FriendListItems.Remove(friend);
                await _friendService.RemoveFriend(friend.XUid);

                _updateFriendAction();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Properties.Resources.GenericUnexpectedErrorMessage,
                                          DialogIcon.Error,
                                          DialogOptions.Ok);
            }
        }
Example #11
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var osInfo = OsVersionInfo.GetOsVersionInfo();

            if (osInfo.Major < 6 || osInfo.Major == 6 && osInfo.Minor < 2)
            {
                GenericMessageDialog.Show(string.Format(Celeste_Launcher_Gui.Properties.Resources.WindowsFeatureHelperUnsupportedOS, osInfo.FullName),
                                          DialogIcon.Warning);

                Close();
                return;
            }

            try
            {
                foreach (var feature in await Dism.GetWindowsFeatureInfo(new[] { "DirectPlay", "NetFx3" }))
                {
                    if (string.Equals(feature.Key, "DirectPlay", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var(statusText, colorLabel, canBeEnabled) = GetLabelStatusForDismFeature(feature.Value);

                        DirectPlayStatusLabel.Text       = statusText;
                        DirectPlayStatusLabel.Foreground = new SolidColorBrush(colorLabel);
                        EnableDirectPlayBtn.IsEnabled    = canBeEnabled;
                    }
                    else if (string.Equals(feature.Key, "NetFx3", StringComparison.CurrentCultureIgnoreCase))
                    {
                        var(statusText, colorLabel, canBeEnabled) = GetLabelStatusForDismFeature(feature.Value);

                        NetFrameworkStatusLabel.Text       = statusText;
                        NetFrameworkStatusLabel.Foreground = new SolidColorBrush(colorLabel);
                        EnableNetFrameworkBtn.IsEnabled    = canBeEnabled;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                NetFrameworkStatusLabel.Text       = Celeste_Launcher_Gui.Properties.Resources.WindowsFeatureHelperFeatureNotSupportedError;
                NetFrameworkStatusLabel.Foreground = new SolidColorBrush(Colors.Red);
            }
        }
Example #12
0
        private async void EnableNetFrameworkBtnClick(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            try
            {
                var feature = await Dism.EnableWindowsFeatures("NetFx3", OnDismInstallProgress);

                var(statusText, colorLabel, canBeEnabled) = GetLabelStatusForDismFeature(feature);

                NetFrameworkStatusLabel.Text       = statusText;
                NetFrameworkStatusLabel.Foreground = new SolidColorBrush(colorLabel);
                EnableNetFrameworkBtn.IsEnabled    = canBeEnabled;
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
            }
            IsEnabled = true;
        }
        private void LoadFirewallRules()
        {
            try
            {
                //Launcher
                var launcherPath = Assembly.GetEntryAssembly().Location;

                if (!File.Exists(launcherPath))
                {
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperLauncherNotFound, DialogIcon.Error, DialogOptions.Ok);
                    Close();
                    return;
                }

                var rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_outbound_tcp");
                if (rule == null)
                {
                    LauncherOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath ||
                        rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Outbound)
                    {
                        LauncherOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        LauncherOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                var path = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig?.GameFilesPath)
                    ? LegacyBootstrapper.UserConfig?.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(path, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperSpartanNotFound, DialogIcon.Error, DialogOptions.Ok);
                    Close();
                    return;
                }

                //Spartan
                var rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_tcp");
                var rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_udp");
                if (rule1 == null || rule2 == null)
                {
                    SpartanInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath ||
                        rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Inbound ||
                        rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath ||
                        rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Inbound)
                    {
                        SpartanInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        SpartanInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_tcp");
                rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_udp");
                if (rule1 == null || rule2 == null)
                {
                    SpartanOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath ||
                        rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Outbound ||
                        rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath ||
                        rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Outbound)
                    {
                        SpartanOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        SpartanOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                //Port 1000
                rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_inbound_udp");
                if (rule == null)
                {
                    MultiplayerInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) ||
                        rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Inbound)
                    {
                        MultiplayerInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        MultiplayerInboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }

                rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_outbound_udp");
                if (rule == null)
                {
                    MultiplayerOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound;
                    MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) ||
                        rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Outbound)
                    {
                        MultiplayerOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid;
                        MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        MultiplayerOutboundStatus.Content    = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen;
                        MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
            }
        }
Example #14
0
        private async void OnRegister(object sender, RoutedEventArgs args)
        {
            if (ConfirmPasswordField.PasswordInputBox.Password != PasswordField.PasswordInputBox.Password)
            {
                GenericMessageDialog.Show(Properties.Resources.RegisterPasswordMismatch, DialogIcon.Error);
                return;
            }

            if (!Misc.IsValidEmailAdress(EmailField.InputContent))
            {
                GenericMessageDialog.Show(Properties.Resources.RegisterInvalidEmail, DialogIcon.Error);
                return;
            }

            if (!Misc.IsValidUserName(UsernameField.InputContent))
            {
                GenericMessageDialog.Show(Properties.Resources.RegisterInvalidUsername, DialogIcon.Error);
                return;
            }

            if (PasswordField.PasswordInputBox.Password.Length < 8 || PasswordField.PasswordInputBox.Password.Length > 32)
            {
                GenericMessageDialog.Show(Properties.Resources.RegisterInvalidPasswordLength, DialogIcon.Error);
                return;
            }

            if (!Misc.IsValidPassword(PasswordField.PasswordInputBox.Password))
            {
                GenericMessageDialog.Show(Properties.Resources.RegisterInvalidPasswordLength, DialogIcon.Error);
                return;
            }

            if (VerifyKeyField.InputContent.Length != 32)
            {
                GenericMessageDialog.Show(Properties.Resources.RegisterInvalidKeyLength, DialogIcon.Error);
                return;
            }

            RegisterBtn.IsEnabled = false;

            try
            {
                var response = await LegacyBootstrapper.WebSocketApi.DoRegister(EmailField.InputContent, VerifyKeyField.InputContent,
                                                                                UsernameField.InputContent, PasswordField.PasswordInputBox.Password);

                if (response.Result)
                {
                    GenericMessageDialog.Show($@"{response.Message}");

                    NavigationService.Navigate(new Uri("Pages/MainMenuPage.xaml", UriKind.Relative));
                }
                else
                {
                    GenericMessageDialog.Show($@"{Properties.Resources.RegisterError} {response.Message}", DialogIcon.Error);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error);
            }

            RegisterBtn.IsEnabled = true;
        }
        private void SpartanOpenBtn_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;
            try
            {
                var path = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig?.GameFilesPath)
                    ? LegacyBootstrapper.UserConfig?.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(path, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperSpartanNotFound, DialogIcon.Error, DialogOptions.Ok);
                    Close();
                    return;
                }

                //inbound_tcp
                var rule = FirewallHelper.RuleExist("celeste_spartan_inbound_tcp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_inbound_tcp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_inbound_tcp", spartanPath,
                                                  FirewallDirection.Inbound, FirewallProtocol.TCP);

                //outbound_tcp
                rule = FirewallHelper.RuleExist("celeste_spartan_outbound_tcp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_outbound_tcp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_outbound_tcp", spartanPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.TCP);

                //inbound_udp
                rule = FirewallHelper.RuleExist("celeste_spartan_inbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_inbound_udp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_inbound_udp", spartanPath,
                                                  FirewallDirection.Inbound, FirewallProtocol.UDP);

                //outbound_udp
                rule = FirewallHelper.RuleExist("celeste_spartan_outbound_udp");
                if (rule)
                {
                    FirewallHelper.RemoveRules("celeste_spartan_outbound_udp");
                }

                FirewallHelper.AddApplicationRule("celeste_spartan_outbound_udp", spartanPath,
                                                  FirewallDirection.Outbound, FirewallProtocol.UDP);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
            }

            LoadFirewallRules();

            IsEnabled = true;
        }
Example #16
0
        private async void PerformLogin(object sender, RoutedEventArgs e)
        {
            LoginButton.IsEnabled = false;
            try
            {
                var         storedCredentials = UserCredentialService.GetStoredUserCredentials();
                LoginResult loginResult;

                _logger.Information("Stored credentials is null: {@IsNull}", (storedCredentials == null));

                if (storedCredentials != null && (RememberPasswordOption.IsChecked ?? false))
                {
                    _logger.Information("Performing login with stored credentials");
                    loginResult = await PerformLogin(storedCredentials.Email, storedCredentials.Password);
                }
                else
                {
                    _logger.Information("Performing login with entered credentials");

                    var password = PasswordInputField.PasswordInputBox.SecurePassword;
                    var email    = EmailInputField.InputContent;

                    if (password.Length < 8)
                    {
                        GenericMessageDialog.Show($"{Properties.Resources.LoginTooShortPassword}", DialogIcon.Error, DialogOptions.Ok);
                        return;
                    }

                    if (password.Length > 32)
                    {
                        GenericMessageDialog.Show($"{Properties.Resources.LoginTooLongPassword}", DialogIcon.Error, DialogOptions.Ok);
                        return;
                    }

                    if (!Misc.IsValidEmailAdress(email))
                    {
                        GenericMessageDialog.Show($"{Properties.Resources.LoginBadEmail}", DialogIcon.Error, DialogOptions.Ok);
                        return;
                    }

                    loginResult = await PerformLogin(email, password);
                }

                if (loginResult.Result)
                {
                    _logger.Information("Login succeeded");
                    LegacyBootstrapper.UserConfig.LoginInfo.RememberMe = RememberPasswordOption.IsChecked ?? false;
                    LegacyBootstrapper.UserConfig.LoginInfo.AutoLogin  = AutoLoginOption.IsChecked ?? false;

                    if (LegacyBootstrapper.UserConfig.LoginInfo.RememberMe && storedCredentials == null)
                    {
                        _logger.Information("User has selected to store new credentials");
                        UserCredentialService.StoreCredential(EmailInputField.InputContent, PasswordInputField.PasswordInputBox.SecurePassword);
                    }

                    LegacyBootstrapper.UserConfig.Save(LegacyBootstrapper.UserConfigFilePath);

                    LegacyBootstrapper.CurrentUser = loginResult.User;

                    NavigationService.Navigate(new Uri("Pages/OverviewPage.xaml", UriKind.Relative));
                }
                else
                {
                    _logger.Information("Failed signing in because {@Message}", loginResult.Message);
                    GenericMessageDialog.Show($"{Properties.Resources.LoginErrorMessage} {loginResult.Message}", DialogIcon.Error, DialogOptions.Ok);
                    PasswordInputField.PasswordInputBox.Clear();
                    UserCredentialService.ClearVault();
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                GenericMessageDialog.Show(Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok);
                PasswordInputField.PasswordInputBox.Clear();
                UserCredentialService.ClearVault();
            }
            finally
            {
                LoginButton.IsEnabled = true;
            }
        }
Example #17
0
        public static async Task StartGame(bool isOffline = false)
        {
            Logger.Information("Preparing to start game, is offline: {@isOffline}", isOffline);

            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                Logger.Information("Game is already started with PID {@PID}", pname.Select(t => t.Id));
                GenericMessageDialog.Show(Properties.Resources.GameAlreadyRunningError, DialogIcon.Warning);
                return;
            }

            //QuickGameScan
            if (!isOffline || InternetUtils.IsConnectedToInternet())
            {
                Logger.Information("User is online, will perform game scan");
                try
                {
                    var success = false;

                    while (!success)
                    {
                        Logger.Information("Starting quick game scan");
                        var gameFilePath = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig.GameFilesPath)
                            ? LegacyBootstrapper.UserConfig.GameFilesPath
                            : GameScannerManager.GetGameFilesRootPath();

                        Logger.Information("Preparing games canner api");

                        var gameScannner = new GameScannerManager(gameFilePath, LegacyBootstrapper.UserConfig.IsSteamVersion);
                        await gameScannner.InitializeFromCelesteManifest();

                        if (!await gameScannner.Scan(true))
                        {
                            Logger.Information("Game scanner did not approve game files");

                            var dialogResult = GenericMessageDialog.Show(
                                Properties.Resources.GameScannerDidNotPassQuickScan,
                                DialogIcon.None,
                                DialogOptions.YesNo);

                            if (dialogResult.Value)
                            {
                                var gamePathSelectionWindow = new GamePathSelectionWindow();
                                gamePathSelectionWindow.ShowDialog();
                            }
                            else
                            {
                                success = true;
                            }
                        }
                        else
                        {
                            Logger.Information("Game files passed file scanner");
                            success = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, ex.Message);
                    GenericMessageDialog.Show(Properties.Resources.GameScannerScanError, DialogIcon.Warning);
                }
            }

            //isSteam
            if (!LegacyBootstrapper.UserConfig.IsSteamVersion)
            {
                var steamApiDll = Path.Combine(LegacyBootstrapper.UserConfig.GameFilesPath, "steam_api.dll");
                if (File.Exists(steamApiDll))
                {
                    File.Delete(steamApiDll);
                }
            }

            //MpSettings
            if (!isOffline && LegacyBootstrapper.UserConfig.MpSettings != null)
            {
                if (LegacyBootstrapper.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    LegacyBootstrapper.UserConfig.MpSettings.PublicIp = LegacyBootstrapper.CurrentUser.Ip;

                    if (LegacyBootstrapper.UserConfig.MpSettings.PortMappingType == PortMappingType.Upnp)
                    {
                        try
                        {
                            await OpenNat.MapPortTask(1000, 1000);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex, ex.Message);
                            LegacyBootstrapper.UserConfig.MpSettings.PortMappingType = PortMappingType.NatPunch;

                            GenericMessageDialog.Show(Properties.Resources.UPnPDisabledError, DialogIcon.Error);
                        }
                        finally
                        {
                            NatDiscoverer.TraceSource.Close();
                        }
                    }
                }
            }

            try
            {
                //Launch Game
                var gamePath = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig.GameFilesPath)
                    ? LegacyBootstrapper.UserConfig.GameFilesPath
                    : GameScannerManager.GetGameFilesRootPath();

                var spartanPath = Path.Combine(gamePath, "Spartan.exe");

                if (!File.Exists(spartanPath))
                {
                    GenericMessageDialog.Show(Properties.Resources.GameScannerSpartanNotFound, DialogIcon.Error);
                    return;
                }

                string lang;
                switch (LegacyBootstrapper.UserConfig.GameLanguage)
                {
                case GameLanguage.deDE:
                    lang = "de-DE";
                    break;

                case GameLanguage.enUS:
                    lang = "en-US";
                    break;

                case GameLanguage.esES:
                    lang = "es-ES";
                    break;

                case GameLanguage.frFR:
                    lang = "fr-FR";
                    break;

                case GameLanguage.itIT:
                    lang = "it-IT";
                    break;

                case GameLanguage.zhCHT:
                    lang = "zh-CHT";
                    break;

                case GameLanguage.ptBR:
                    lang = "pt-BR";
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(LegacyBootstrapper.UserConfig.GameLanguage),
                                                          LegacyBootstrapper.UserConfig.GameLanguage, null);
                }

                try
                {
                    if (LegacyBootstrapper.UserConfig.IsDiagnosticMode)
                    {
                        Logger.Information("Diagnostics mode is enabled");
                        //
                        try
                        {
                            var killInfo = new ProcessStartInfo("cmd.exe", "/c taskkill /F /IM procdump.exe /T")
                            {
                                WorkingDirectory       = gamePath,
                                CreateNoWindow         = true,
                                UseShellExecute        = false,
                                RedirectStandardError  = true,
                                RedirectStandardOutput = true
                            };

                            Logger.Information("Starting prcoess {@Proc} with args {@Procargs}", killInfo.FileName, killInfo.Arguments);
                            Process.Start(killInfo);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(ex, ex.Message);
                        }

                        var       procdumpFileName   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "procdump.exe");
                        const int maxNumOfCrashDumps = 30;
                        if (!File.Exists(procdumpFileName))
                        {
                            Logger.Information("Could not find procdump.exe");
                            LegacyBootstrapper.UserConfig.IsDiagnosticMode = false;
                            throw new FileNotFoundException(
                                      Properties.Resources.DiagnosticsModeMissingProcdump,
                                      procdumpFileName);
                        }

                        // First ensure that all directories are set
                        var pathToCrashDumpFolder =
                            Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                         @"Spartan\MiniDumps");

                        Logger.Information("CrashDumpFolder is set to {@CrashDumpFolder}", pathToCrashDumpFolder);

                        if (!Directory.Exists(pathToCrashDumpFolder))
                        {
                            Directory.CreateDirectory(pathToCrashDumpFolder);
                        }

                        // Check for cleanup
                        Directory.GetFiles(pathToCrashDumpFolder)
                        .OrderByDescending(File.GetLastWriteTime) // Sort by age --> old one last
                        .Skip(maxNumOfCrashDumps)                 // Skip max num crash dumps
                        .ToList()
                        .ForEach(File.Delete);                    // Remove the rest

                        var excludeExceptions = new[]
                        {
                            "E0434F4D.COM", // .NET native exception
                            "E06D7363.msc",
                            "E06D7363.PAVEEFileLoadException@@",
                            "E0434F4D.System.IO.FileNotFoundException" // .NET managed exception
                        };

                        var excludeExcpetionsCmd = string.Join(" ", excludeExceptions.Select(elem => "-fx " + elem));

                        var fullCmdArgs = "-accepteula -mm -e 1 -n 10 " + excludeExcpetionsCmd +
                                          " -g -w Spartan.exe \"" + pathToCrashDumpFolder + "\"";

                        var startInfo = new ProcessStartInfo(procdumpFileName, fullCmdArgs)
                        {
                            WorkingDirectory       = gamePath,
                            CreateNoWindow         = true,
                            UseShellExecute        = false,
                            RedirectStandardError  = true,
                            RedirectStandardOutput = true
                        };

                        Logger.Information("Starting prcoess {@Proc} with args {@Procargs}", startInfo.FileName, startInfo.Arguments);

                        Process.Start(startInfo);
                    }
                }
                catch (Exception exception)
                {
                    Logger.Error(exception, exception.Message);
                    GenericMessageDialog.Show(Properties.Resources.DiagnosticsModeError, DialogIcon.Warning);
                }

                //SymLink CustomScn Folder
                var profileDir        = Path.Combine(Environment.GetEnvironmentVariable("userprofile"));
                var customScnGamePath = Path.Combine(gamePath, "Scenario", "CustomScn");
                var scenarioUserPath  = Path.Combine(profileDir, "Documents", "Spartan", "Scenario");

                Logger.Information("CustomScn directory: {@customScnPath}", customScnGamePath);
                Logger.Information("Scenario directory: {@scenarioPath}", scenarioUserPath);

                if (!Directory.Exists(scenarioUserPath))
                {
                    Directory.CreateDirectory(scenarioUserPath);
                }

                if (Directory.Exists(customScnGamePath) &&
                    (!Misc.IsSymLink(customScnGamePath, Misc.SymLinkFlag.Directory) ||
                     !string.Equals(Misc.GetRealPath(customScnGamePath), scenarioUserPath, StringComparison.OrdinalIgnoreCase)))
                {
                    Directory.Delete(customScnGamePath, true);
                    Misc.CreateSymbolicLink(customScnGamePath, scenarioUserPath, Misc.SymLinkFlag.Directory);
                }
                else
                {
                    Misc.CreateSymbolicLink(customScnGamePath, scenarioUserPath, Misc.SymLinkFlag.Directory);
                }

                string arg;
                if (isOffline)
                {
                    arg = $"--offline --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }
                else if (LegacyBootstrapper.UserConfig?.MpSettings == null ||
                         LegacyBootstrapper.UserConfig.MpSettings.ConnectionType == ConnectionType.Wan)
                {
                    arg = LegacyBootstrapper.UserConfig.MpSettings.PortMappingType == PortMappingType.NatPunch
                        ? $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033"
                        : $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --no-nat-punchthrough --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }
                else
                {
                    arg =
                        $"--email \"{CurrentEmail}\" --password \"{CurrentPassword.GetValue()}\" --online-ip \"{LegacyBootstrapper.UserConfig.MpSettings.PublicIp}\" --ignore_rest LauncherLang={lang} LauncherLocale=1033";
                }

                Logger.Information("Starting game {@GameExecutable} at {@GamePath}", spartanPath, gamePath);
                Process.Start(new ProcessStartInfo(spartanPath, arg)
                {
                    WorkingDirectory = gamePath
                });
            }
            catch (Exception exception)
            {
                Logger.Error(exception, exception.Message);
                GenericMessageDialog.Show(Properties.Resources.StartGameError, DialogIcon.Error);
            }
        }
        public static void InitializeLegacyComponents()
        {
            if (!FileSystem.IsWritableDirectory(AppDomain.CurrentDomain.BaseDirectory))
            {
                MessageBox.Show(string.Format(Properties.Resources.InstallationPathForbidden, AppDomain.CurrentDomain.BaseDirectory), "Celeste Launcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                System.Windows.Application.Current.Shutdown();
                return;
            }

            Logger.Information("Initializing bootstrapper");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // TODO: Move this to app.xaml.cs
            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                Logger.Information("Launcher is already started, will exit");
                GenericMessageDialog.Show(Properties.Resources.LauncherAlreadyRunningMessage, DialogIcon.Warning, DialogOptions.Ok);
                return;
            }

            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            LoadUserConfig();

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                    Logger.Information("Game path set to {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No game path is set");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Check if Steam Version
            try
            {
                var isSteamVersion = Assembly.GetEntryAssembly().Location
                                     .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase);

                if (UserConfig.IsSteamVersion != isSteamVersion)
                {
                    UserConfig.IsSteamVersion = isSteamVersion;
                    UserConfig.Save(UserConfigFilePath);
                }

                Logger.Information("IsSteamVersion: {@IsSteamVersion}", UserConfig.IsSteamVersion);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);
            Logger.Information("Initialized web socket");

            GC.KeepAlive(mutex);

            Logger.Information("Initializing fingerprint provider");
            FingerPrintProvider.Initialize();

            SetUILanguage();

            Logger.Information("Bootstrapper initialized");
        }
        public static void InitializeLegacyComponents()
        {
            Logger.Information("Initializing bootstrapper");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // TODO: Move this to app.xaml.cs
            var mutex = new Mutex(true, AppName, out bool createdNew);

            //Only one instance
            if (!createdNew)
            {
                Logger.Information("Launcher is already started, will exit");
                GenericMessageDialog.Show(Properties.Resources.LauncherAlreadyRunningMessage, DialogIcon.Warning, DialogOptions.Ok);
                return;
            }

            //
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                    Logger.Information("User config loaded from {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No user config loaded, path {@Path} does not exist", UserConfigFilePath);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            try
            {
                if (string.IsNullOrWhiteSpace(UserConfig.GameFilesPath))
                {
                    UserConfig.GameFilesPath = GameScannerManager.GetGameFilesRootPath();
                    Logger.Information("Game path set to {@Path}", UserConfigFilePath);
                }
                else
                {
                    Logger.Information("No game path is set");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Check if Steam Version
            try
            {
                UserConfig.IsSteamVersion = Assembly.GetEntryAssembly().Location
                                            .EndsWith("AOEOnline.exe", StringComparison.OrdinalIgnoreCase);

                Logger.Information("IsSteamVersion: {@IsSteamVersion}", UserConfig.IsSteamVersion);
            }
            catch (Exception ex)
            {
                Logger.Error(ex, ex.Message);
            }

            //Init WebSocketApi
            WebSocketApi = new WebSocketApi(UserConfig.ServerUri);
            Logger.Information("Initialized web socket");

            GC.KeepAlive(mutex);

            Logger.Information("Initializing fingerprint provider");
            FingerPrintProvider.Initialize();

            SetUILanguage();

            Logger.Information("Bootstrapper initialized");
        }