/// <summary> /// Initializes the UI of the launcher, performing varying checks against the patching server. /// </summary> /// <returns>A task that must be awaited.</returns> public Task InitializeAsync() { if (this.IsInitialized) { return(Task.CompletedTask); } // First of all, check if we can connect to the patching service. if (!this.Checks.CanPatch()) { var dialog = new MessageDialog ( this, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings.") ); dialog.Run(); dialog.Destroy(); this.StatusLabel.Text = LocalizationCatalog.GetString("Could not connect to server."); this.MenuRepairItem.Sensitive = false; } else { LoadBanner(); LoadChangelog(); // If we can connect, proceed with the rest of our checks. if (ChecksHandler.IsInitialStartup()) { DisplayInitialStartupDialog(); } // If the launcher does not need an update at this point, we can continue checks for the game if (!this.Checks.IsLauncherOutdated()) { if (!this.Checks.IsPlatformAvailable(this.Configuration.SystemTarget)) { Log.Info ( $"The server does not provide files for platform \"{PlatformHelpers.GetCurrentPlatform()}\". " + "A .provides file must be present in the platforms' root directory." ); SetLauncherMode(ELauncherMode.Inactive, false); } else { if (!this.Checks.IsGameInstalled()) { // If the game is not installed, offer to install it Log.Info("The game has not yet been installed."); SetLauncherMode(ELauncherMode.Install, false); // Since the game has not yet been installed, disallow manual repairs this.MenuRepairItem.Sensitive = false; // and reinstalls this.MenuReinstallItem.Sensitive = false; } else { // If the game is installed (which it should be at this point), check if it needs to be updated if (this.Checks.IsGameOutdated()) { // If it does, offer to update it Log.Info("The game is outdated."); SetLauncherMode(ELauncherMode.Update, false); } else { // All checks passed, so we can offer to launch the game. Log.Info("All checks passed. Game can be launched."); SetLauncherMode(ELauncherMode.Launch, false); } } } } else { // The launcher was outdated. Log.Info($"The launcher is outdated. \n\tLocal version: {this.LocalVersionService.GetLocalLauncherVersion()}"); SetLauncherMode(ELauncherMode.Update, false); } } this.IsInitialized = true; return(Task.CompletedTask); }
public MainWindow() : base(WindowType.Toplevel) { //Initialize the config files and check values. Config.Initialize(); // The config must be initialized before the handlers can be instantiated Checks = new ChecksHandler(); Launcher = new LauncherHandler(); Game = new GameHandler(); //Initialize the GTK UI this.Build(); // Set the initial launcher mode SetLauncherMode(ELauncherMode.Inactive, false); //set the window title Title = "Launchpad - " + Config.GetGameName(); ScrolledBrowserWindow.Add(Browser); ScrolledBrowserWindow.ShowAll(); IndicatorLabel.Text = LocalizationCatalog.GetString("Idle"); //First of all, check if we can connect to the FTP server. if (!Checks.CanPatch()) { MessageDialog dialog = new MessageDialog( null, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings.")); dialog.Run(); dialog.Destroy(); IndicatorLabel.Text = LocalizationCatalog.GetString("Could not connect to server."); refreshAction1.Sensitive = false; } else { //if we can connect, proceed with the rest of our checks. if (ChecksHandler.IsInitialStartup()) { MessageDialog shouldInstallHereDialog = new MessageDialog( null, DialogFlags.Modal, MessageType.Question, ButtonsType.OkCancel, String.Format(LocalizationCatalog.GetString( "This appears to be the first time you're starting the launcher.\n" + "Is this the location where you would like to install the game?" + "\n\n{0}"), ConfigHandler.GetLocalDir() )); if (shouldInstallHereDialog.Run() == (int)ResponseType.Ok) { shouldInstallHereDialog.Destroy(); //yes, install here Console.WriteLine("Installing in current directory."); ConfigHandler.CreateUpdateCookie(); } else { shouldInstallHereDialog.Destroy(); //no, don't install here Console.WriteLine("Exiting..."); Environment.Exit(0); } } if (Config.ShouldAllowAnonymousStats()) { StatsHandler.SendUsageStats(); } // Load the changelog. Try a direct URL first, and a protocol-specific // implementation after. if (Launcher.CanAccessStandardChangelog()) { Browser.Open(Config.GetChangelogURL()); } else { Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished; Launcher.LoadFallbackChangelog(); } // If the launcher does not need an update at this point, we can continue checks for the game if (!Checks.IsLauncherOutdated()) { if (!Checks.IsGameInstalled()) { //if the game is not installed, offer to install it Console.WriteLine("Not installed."); SetLauncherMode(ELauncherMode.Install, false); } else { //if the game is installed (which it should be at this point), check if it needs to be updated if (Checks.IsGameOutdated()) { //if it does, offer to update it Console.WriteLine("Game is outdated or not installed"); SetLauncherMode(ELauncherMode.Update, false); } else { //if not, enable launching the game SetLauncherMode(ELauncherMode.Launch, false); } } } else { //the launcher was outdated. SetLauncherMode(ELauncherMode.Update, false); } } }
public MainForm() { InitializeComponent(); Config.Initialize(); // The config must be initialized before the handlers can be instantiated Checks = new ChecksHandler(); Launcher = new LauncherHandler(); Game = new GameHandler(); SetLauncherMode(ELauncherMode.Inactive, false); MessageLabel.Text = LocalizationCatalog.GetString("Idle"); downloadProgressLabel.Text = String.Empty; //set the window text to match the game name this.Text = "Launchpad - " + Config.GetGameName(); //first of all, check if we can connect to the FTP server. if (!Checks.CanPatch()) { MessageBox.Show( this, LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings."), LocalizationCatalog.GetString("Could not connect to server."), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); MessageLabel.Text = LocalizationCatalog.GetString("Could not connect to server."); PrimaryButton.Text = ":("; PrimaryButton.Enabled = false; } else { //if we can connect, proceed with the rest of our checks. if (ChecksHandler.IsInitialStartup()) { DialogResult shouldInstallHere = MessageBox.Show( this, String.Format( LocalizationCatalog.GetString("This appears to be the first time you're starting the launcher.\n" + "Is this the location where you would like to install the game?" + "\n\n{0}"), ConfigHandler.GetLocalDir()), LocalizationCatalog.GetString("Initial startup"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (shouldInstallHere == DialogResult.Yes) { //yes, install here ConfigHandler.CreateUpdateCookie(); } else { //no, don't install here Environment.Exit(2); } } if (Config.ShouldAllowAnonymousStats()) { StatsHandler.SendUsageStats(); } // Load the changelog. Try a direct URL first, and a protocol-specific // implementation after. if (Launcher.CanAccessStandardChangelog()) { changelogBrowser.Navigate(Config.GetChangelogURL()); } else { Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished; Launcher.LoadFallbackChangelog(); } //Does the launcher need an update? if (!Checks.IsLauncherOutdated()) { if (!Checks.IsGameInstalled()) { SetLauncherMode(ELauncherMode.Install, false); } else { if (Checks.IsGameOutdated()) { SetLauncherMode(ELauncherMode.Update, false); } else { SetLauncherMode(ELauncherMode.Launch, false); } } } else { SetLauncherMode(ELauncherMode.Update, false); } } }
/// <summary> /// Creates a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() : base(Gtk.WindowType.Toplevel) { // Initialize the GTK UI this.Build(); // Bind the handler events Game.ProgressChanged += OnModuleInstallationProgressChanged; Game.DownloadFinished += OnGameDownloadFinished; Game.DownloadFailed += OnGameDownloadFailed; Game.LaunchFailed += OnGameLaunchFailed; Game.GameExited += OnGameExited; Launcher.LauncherDownloadProgressChanged += OnModuleInstallationProgressChanged; Launcher.LauncherDownloadFinished += OnLauncherDownloadFinished; Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished; // Set the initial launcher mode SetLauncherMode(ELauncherMode.Inactive, false); // Set the window title Title = LocalizationCatalog.GetString("Launchpad - {0}", Config.GetGameName()); // Create a new changelog widget, and add it to the scrolled window this.Browser = new Changelog(this.browserWindow); browserWindow.ShowAll(); indicatorLabel.Text = LocalizationCatalog.GetString("Idle"); // First of all, check if we can connect to the patching service. if (!Checks.CanPatch()) { MessageDialog dialog = new MessageDialog( null, DialogFlags.Modal, MessageType.Warning, ButtonsType.Ok, LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings.")); dialog.Run(); dialog.Destroy(); indicatorLabel.Text = LocalizationCatalog.GetString("Could not connect to server."); repairGameAction.Sensitive = false; } else { // TODO: Load this asynchronously // Load the game banner (if there is one) if (Config.GetPatchProtocol().CanProvideBanner()) { using (MemoryStream bannerStream = new MemoryStream()) { // Fetch the banner from the server Config.GetPatchProtocol().GetBanner().Save(bannerStream, ImageFormat.Png); // Load the image into a pixel buffer bannerStream.Position = 0; this.gameBanner.Pixbuf = new Pixbuf(bannerStream); } } // If we can connect, proceed with the rest of our checks. if (ChecksHandler.IsInitialStartup()) { Log.Info("This instance is the first start of the application in this folder."); MessageDialog shouldInstallHereDialog = new MessageDialog( null, DialogFlags.Modal, MessageType.Question, ButtonsType.OkCancel, LocalizationCatalog.GetString( "This appears to be the first time you're starting the launcher.\n" + "Is this the location where you would like to install the game?") + $"\n\n{ConfigHandler.GetLocalDir()}" ); if (shouldInstallHereDialog.Run() == (int)ResponseType.Ok) { shouldInstallHereDialog.Destroy(); // Yes, install here Log.Info("User accepted installation in this directory. Installing in current directory."); ConfigHandler.CreateLauncherCookie(); } else { shouldInstallHereDialog.Destroy(); // No, don't install here Log.Info("User declined installation in this directory. Exiting..."); Environment.Exit(2); } } if (Config.ShouldAllowAnonymousStats()) { StatsHandler.SendUsageStats(); } // Load the changelog. Try a direct URL first, and a protocol-specific // implementation after. if (LauncherHandler.CanAccessStandardChangelog()) { Browser.Navigate(Config.GetChangelogURL()); } else { Launcher.LoadFallbackChangelog(); } // If the launcher does not need an update at this point, we can continue checks for the game if (!Checks.IsLauncherOutdated()) { if (!Checks.IsPlatformAvailable(Config.GetSystemTarget())) { Log.Info($"The server does not provide files for platform \"{ConfigHandler.GetCurrentPlatform()}\". " + "A .provides file must be present in the platforms' root directory."); SetLauncherMode(ELauncherMode.Inactive, false); } else { if (!Checks.IsGameInstalled()) { // If the game is not installed, offer to install it Log.Info("The game has not yet been installed."); SetLauncherMode(ELauncherMode.Install, false); // Since the game has not yet been installed, disallow manual repairs this.repairGameAction.Sensitive = false; // and reinstalls this.reinstallGameAction.Sensitive = false; } else { // If the game is installed (which it should be at this point), check if it needs to be updated if (Checks.IsGameOutdated()) { // If it does, offer to update it Log.Info($"The game is outdated. \n\tLocal version: {Config.GetLocalGameVersion()}"); SetLauncherMode(ELauncherMode.Update, false); } else { // All checks passed, so we can offer to launch the game. Log.Info("All checks passed. Game can be launched."); SetLauncherMode(ELauncherMode.Launch, false); } } } } else { // The launcher was outdated. Log.Info($"The launcher is outdated. \n\tLocal version: {Config.GetLocalLauncherVersion()}"); SetLauncherMode(ELauncherMode.Update, false); } } }
public MainForm() { InitializeComponent(); InitializeLocalizedStrings(); // Bind the handler events Game.ProgressChanged += OnModuleInstallationProgressChanged; Game.GameDownloadFinished += OnGameDownloadFinished; Game.GameDownloadFailed += OnGameDownloadFailed; Game.GameLaunchFailed += OnGameLaunchFailed; Game.GameExited += OnGameExited; Launcher.LauncherDownloadProgressChanged += OnModuleInstallationProgressChanged; Launcher.LauncherDownloadFinished += OnLauncherDownloadFinished; Launcher.ChangelogDownloadFinished += OnChangelogDownloadFinished; SetLauncherMode(ELauncherMode.Inactive, false); MessageLabel.Text = LocalizationCatalog.GetString("Idle"); downloadProgressLabel.Text = string.Empty; // Set the window text to match the game name this.Text = LocalizationCatalog.GetString("Launchpad - ") + Config.GetGameName(); // First of all, check if we can connect to the FTP server. if (!Checks.CanPatch()) { MessageBox.Show( this, LocalizationCatalog.GetString("Failed to connect to the patch server. Please check your settings."), LocalizationCatalog.GetString("Could not connect to server."), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); MessageLabel.Text = LocalizationCatalog.GetString("Could not connect to server."); PrimaryButton.Text = LocalizationCatalog.GetString("Inactive"); PrimaryButton.Enabled = false; } else { // If we can connect, proceed with the rest of our checks. if (ChecksHandler.IsInitialStartup()) { Log.Info("This instance is the first start of the application in this folder."); DialogResult shouldInstallHere = MessageBox.Show( this, string.Format( LocalizationCatalog.GetString("This appears to be the first time you're starting the launcher.\n" + "Is this the location where you would like to install the game?" + "\n\n{0}"), ConfigHandler.GetLocalDir()), LocalizationCatalog.GetString("Initial startup"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (shouldInstallHere == DialogResult.Yes) { // Yes, install here Log.Info("User accepted installation in this directory. Installing in current directory."); ConfigHandler.CreateUpdateCookie(); } else { // No, don't install here Log.Info("User declined installation in this directory. Exiting..."); Environment.Exit(2); } } if (Config.ShouldAllowAnonymousStats()) { StatsHandler.SendUsageStats(); } // Load the changelog. Try a direct URL first, and a protocol-specific // implementation after. if (Launcher.CanAccessStandardChangelog()) { changelogBrowser.Navigate(Config.GetChangelogURL()); } else { Launcher.LoadFallbackChangelog(); } // Does the launcher need an update? if (!Checks.IsLauncherOutdated()) { if (!Checks.IsGameInstalled()) { Log.Info("The game has not yet been installed."); SetLauncherMode(ELauncherMode.Install, false); } else { if (Checks.IsGameOutdated()) { Log.Info($"The game is outdated. \n\tLocal version: {Config.GetLocalGameVersion()}"); SetLauncherMode(ELauncherMode.Update, false); } else { Log.Info("All checks passed. Game can be launched."); SetLauncherMode(ELauncherMode.Launch, false); } } } else { Log.Info($"The launcher is outdated. \n\tLocal version: {Config.GetLocalLauncherVersion()}"); SetLauncherMode(ELauncherMode.Update, false); } } }