Ejemplo n.º 1
0
        /// <summary>
        /// Handles switching between different functionalities depending on what is visible on the button to the user, such as
        /// * Installing
        /// * Updating
        /// * Repairing
        /// * Launching
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Empty arguments.</param>
        protected void OnPrimaryButtonClicked(object sender, EventArgs e)
        {
            switch (Mode)
            {
            case ELauncherMode.Repair:
            {
                //bind events for UI updating
                Game.ProgressChanged      += OnModuleInstallationProgressChanged;
                Game.GameDownloadFinished += OnGameDownloadFinished;
                Game.GameDownloadFailed   += OnGameDownloadFailed;

                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    //Repair the game asynchronously
                    SetLauncherMode(ELauncherMode.Repair, true);
                    Game.VerifyGame();
                }
                else
                {
                    Notification noProvide = new Notification();
                    noProvide.IconName = Stock.DialogError;
                    noProvide.Summary  = LocalizationCatalog.GetString("Launchpad - Platform not provided!");
                    noProvide.Body     = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.");
                    noProvide.Show();

                    SetLauncherMode(ELauncherMode.Install, false);
                }
                break;
            }

            case ELauncherMode.Install:
            {
                //bind events for UI updating
                Game.ProgressChanged      += OnModuleInstallationProgressChanged;
                Game.GameDownloadFinished += OnGameDownloadFinished;
                Game.GameDownloadFailed   += OnGameDownloadFailed;

                //check for a .provides file in the platform directory on the server
                //if there is none, the server does not provide a game for that platform
                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    //install the game asynchronously
                    SetLauncherMode(ELauncherMode.Install, true);
                    Game.InstallGame();
                }
                else
                {
                    Notification noProvide = new Notification();
                    noProvide.IconName = Stock.DialogError;
                    noProvide.Summary  = LocalizationCatalog.GetString("Launchpad - Platform not provided!");
                    noProvide.Body     = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.");
                    noProvide.Show();

                    SetLauncherMode(ELauncherMode.Install, false);
                }
                break;
            }

            case ELauncherMode.Update:
            {
                if (Checks.IsLauncherOutdated())
                {
                    SetLauncherMode(ELauncherMode.Update, true);
                    Launcher.LauncherDownloadFinished        += OnLauncherDownloadFinished;
                    Launcher.LauncherDownloadProgressChanged += OnModuleInstallationProgressChanged;
                    Launcher.UpdateLauncher();
                }
                else
                {
                    //bind events for UI updating
                    Game.ProgressChanged      += OnModuleInstallationProgressChanged;
                    Game.GameDownloadFinished += OnGameDownloadFinished;
                    Game.GameDownloadFailed   += OnGameDownloadFailed;

                    //update the game asynchronously
                    if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                    {
                        //install the game asynchronously
                        SetLauncherMode(ELauncherMode.Update, true);
                        Game.UpdateGame();
                    }
                    else
                    {
                        Notification noProvide = new Notification();
                        noProvide.IconName = Stock.DialogError;
                        noProvide.Summary  = LocalizationCatalog.GetString("Launchpad - Platform not provided!");
                        noProvide.Body     = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.");
                        noProvide.Show();

                        SetLauncherMode(ELauncherMode.Install, false);
                    }
                }
                break;
            }

            case ELauncherMode.Launch:
            {
                Game.GameLaunchFailed += OnGameLaunchFailed;
                Game.GameExited       += OnGameExited;

                //events such as LaunchFailed can fire before this has finished
                //thus, we set the mode before the actual launching of the game.
                SetLauncherMode(ELauncherMode.Launch, true);
                Game.LaunchGame();

                break;
            }

            default:
            {
                Console.WriteLine("No functionality for this mode.");
                break;
            }
            }
        }
Ejemplo n.º 2
0
        /// <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);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles switching between different functionalities depending on what is visible on the button to the user, such as
        /// * Installing
        /// * Updating
        /// * Repairing
        /// * Launching
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Empty arguments.</param>
        private void mainButton_Click(object sender, EventArgs e)
        {
            switch (Mode)
            {
            case ELauncherMode.Repair:
            {
                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    // Repair the game asynchronously
                    Game.VerifyGame();
                    SetLauncherMode(ELauncherMode.Repair, true);
                }
                else
                {
                    // Whoops, the server doesn't provide the game for the platform we requested (usually the on we're running on)
                    // Alert the user and revert back to the default install mode
                    Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Launchpad.Launcher.Resources.RocketIcon.ico");
                    if (iconStream != null)
                    {
                        NotifyIcon platformNotProvidedNotification = new NotifyIcon
                        {
                            Icon            = new System.Drawing.Icon(iconStream),
                            Visible         = true,
                            BalloonTipTitle = LocalizationCatalog.GetString("Launchpad - Platform not provided!"),
                            BalloonTipText  =
                                LocalizationCatalog.GetString("The server does not provide the game for the selected platform.")
                        };


                        platformNotProvidedNotification.ShowBalloonTip(10000);
                    }
                    Log.Info($"The server does not provide files for platform \"{ConfigHandler.GetCurrentPlatform()}\". " +
                             "A .provides file must be present in the platforms' root directory.");

                    MessageLabel.Text = LocalizationCatalog.GetString("The server does not provide files for the selected platform.");
                    SetLauncherMode(ELauncherMode.Install, false);
                }
                break;
            }

            case ELauncherMode.Install:
            {
                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    // Install the game asynchronously
                    SetLauncherMode(ELauncherMode.Install, true);
                    Game.InstallGame();
                }
                else
                {
                    // Whoops, the server doesn't provide the game for the platform we requested (usually the on we're running on)
                    // Alert the user and revert back to the default install mode
                    Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Launchpad.Launcher.Resources.RocketIcon.ico");
                    if (iconStream != null)
                    {
                        NotifyIcon platformNotProvidedNotification = new NotifyIcon
                        {
                            Icon            = new System.Drawing.Icon(iconStream),
                            Visible         = true,
                            BalloonTipTitle = LocalizationCatalog.GetString("Launchpad - Platform not provided!"),
                            BalloonTipText  =
                                LocalizationCatalog.GetString("The server does not provide the game for the selected platform.")
                        };


                        platformNotProvidedNotification.ShowBalloonTip(10000);
                    }
                    Log.Info($"The server does not provide files for platform \"{ConfigHandler.GetCurrentPlatform()}\". " +
                             "A .provides file must be present in the platforms' root directory.");

                    MessageLabel.Text = LocalizationCatalog.GetString("The server does not provide files for the selected platform.");
                    SetLauncherMode(ELauncherMode.Install, false);
                }

                break;
            }

            case ELauncherMode.Update:
            {
                if (Checks.IsLauncherOutdated())
                {
                    // Update the launcher synchronously.
                    SetLauncherMode(ELauncherMode.Update, true);
                    Launcher.UpdateLauncher();
                }
                else
                {
                    if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                    {
                        // Update the game asynchronously
                        SetLauncherMode(ELauncherMode.Update, true);
                        Game.UpdateGame();
                    }
                    else
                    {
                        // Whoops, the server doesn't provide the game for the platform we requested (usually the on we're running on)
                        // Alert the user and revert back to the default install mode
                        Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Launchpad.Launcher.Resources.RocketIcon.ico");
                        if (iconStream != null)
                        {
                            NotifyIcon platformNotProvidedNotification = new NotifyIcon
                            {
                                Icon            = new System.Drawing.Icon(iconStream),
                                Visible         = true,
                                BalloonTipTitle = LocalizationCatalog.GetString("Launchpad - Platform not provided!"),
                                BalloonTipText  =
                                    LocalizationCatalog.GetString("The server does not provide the game for the selected platform.")
                            };


                            platformNotProvidedNotification.ShowBalloonTip(10000);
                        }
                        Log.Info($"The server does not provide files for platform \"{ConfigHandler.GetCurrentPlatform()}\". " +
                                 "A .provides file must be present in the platforms' root directory.");

                        MessageLabel.Text = LocalizationCatalog.GetString("The server does not provide files for the selected platform.");
                        SetLauncherMode(ELauncherMode.Install, false);
                    }
                }

                break;
            }

            case ELauncherMode.Launch:
            {
                SetLauncherMode(ELauncherMode.Launch, true);
                Game.LaunchGame();

                break;
            }

            default:
            {
                Log.Warn("The main button was pressed with an invalid active mode. No functionality has been defined for this mode.");
                break;
            }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handles switching between different functionalities depending on what is visible on the button to the user, such as
        /// * Installing
        /// * Updating
        /// * Repairing
        /// * Launching
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Empty arguments.</param>
        private void mainButton_Click(object sender, EventArgs e)
        {
            switch (Mode)
            {
            case ELauncherMode.Repair:
            {
                //bind events for UI updating
                Game.ProgressChanged      += OnModuleInstallationProgressChanged;
                Game.GameDownloadFinished += OnGameDownloadFinished;
                Game.GameDownloadFailed   += OnGameDownloadFailed;

                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    //repair the game asynchronously
                    Game.VerifyGame();
                    SetLauncherMode(ELauncherMode.Repair, true);
                }
                else
                {
                    //whoops, the server doesn't provide the game for the platform we requested (usually the on we're running on)
                    //alert the user and revert back to the default install mode
                    Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Launchpad.Launcher.Resources.RocketIcon.ico");
                    if (iconStream != null)
                    {
                        NotifyIcon platformNotProvidedNotification = new NotifyIcon();
                        platformNotProvidedNotification.Icon    = new System.Drawing.Icon(iconStream);
                        platformNotProvidedNotification.Visible = true;

                        platformNotProvidedNotification.BalloonTipTitle = LocalizationCatalog.GetString("Launchpad - Platform not provided!");
                        platformNotProvidedNotification.BalloonTipText  = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.");

                        platformNotProvidedNotification.ShowBalloonTip(10000);
                    }

                    MessageLabel.Text = LocalizationCatalog.GetString("The server does not provide files for the selected platform.");
                    SetLauncherMode(ELauncherMode.Install, false);
                }
                break;
            }

            case ELauncherMode.Install:
            {
                //bind events for UI updating
                Game.ProgressChanged      += OnModuleInstallationProgressChanged;
                Game.GameDownloadFinished += OnGameDownloadFinished;
                Game.GameDownloadFailed   += OnGameDownloadFailed;

                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    //install the game asynchronously
                    SetLauncherMode(ELauncherMode.Install, true);
                    Game.InstallGame();
                }
                else
                {
                    //whoops, the server doesn't provide the game for the platform we requested (usually the on we're running on)
                    //alert the user and revert back to the default install mode
                    Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Launchpad.Launcher.Resources.RocketIcon.ico");
                    if (iconStream != null)
                    {
                        NotifyIcon platformNotProvidedNotification = new NotifyIcon();
                        platformNotProvidedNotification.Icon    = new System.Drawing.Icon(iconStream);
                        platformNotProvidedNotification.Visible = true;

                        platformNotProvidedNotification.BalloonTipTitle = LocalizationCatalog.GetString("Launchpad - Platform not provided!");
                        platformNotProvidedNotification.BalloonTipText  = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.");

                        platformNotProvidedNotification.ShowBalloonTip(10000);
                    }

                    MessageLabel.Text = LocalizationCatalog.GetString("The server does not provide files for the selected platform.");
                    SetLauncherMode(ELauncherMode.Install, false);
                }

                break;
            }

            case ELauncherMode.Update:
            {
                //bind events for UI updating
                Game.ProgressChanged      += OnModuleInstallationProgressChanged;
                Game.GameDownloadFinished += OnGameDownloadFinished;
                Game.GameDownloadFailed   += OnGameDownloadFailed;

                if (Checks.IsLauncherOutdated())
                {
                    //update the launcher synchronously.
                    SetLauncherMode(ELauncherMode.Update, true);
                    Launcher.LauncherDownloadFinished        += OnLauncherDownloadFinished;
                    Launcher.LauncherDownloadProgressChanged += OnModuleInstallationProgressChanged;
                    Launcher.UpdateLauncher();
                }
                else
                {
                    if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                    {
                        //update the game asynchronously
                        SetLauncherMode(ELauncherMode.Update, true);
                        Game.UpdateGame();
                    }
                    else
                    {
                        //whoops, the server doesn't provide the game for the platform we requested (usually the on we're running on)
                        //alert the user and revert back to the default install mode
                        Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Launchpad.Launcher.Resources.RocketIcon.ico");
                        if (iconStream != null)
                        {
                            NotifyIcon platformNotProvidedNotification = new NotifyIcon();
                            platformNotProvidedNotification.Icon    = new System.Drawing.Icon(iconStream);
                            platformNotProvidedNotification.Visible = true;

                            platformNotProvidedNotification.BalloonTipTitle = LocalizationCatalog.GetString("Launchpad - Platform not provided!");
                            platformNotProvidedNotification.BalloonTipText  = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.");

                            platformNotProvidedNotification.ShowBalloonTip(10000);
                        }

                        MessageLabel.Text = LocalizationCatalog.GetString("The server does not provide files for the selected platform.");
                        SetLauncherMode(ELauncherMode.Install, false);
                    }
                }

                break;
            }

            case ELauncherMode.Launch:
            {
                Game.GameLaunchFailed += OnGameLaunchFailed;
                Game.GameExited       += OnGameExited;

                SetLauncherMode(ELauncherMode.Launch, true);
                Game.LaunchGame();

                break;
            }

            default:
            {
                Console.WriteLine("No functionality for this mode.");
                break;
            }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles switching between different functionalities depending on what is visible on the button to the user, such as
        /// * Installing
        /// * Updating
        /// * Repairing
        /// * Launching
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">Empty arguments.</param>
        protected void OnPrimaryButtonClicked(object sender, EventArgs e)
        {
            switch (Mode)
            {
            case ELauncherMode.Repair:
            {
                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    // Repair the game asynchronously
                    SetLauncherMode(ELauncherMode.Repair, true);
                    Game.VerifyGame();
                }
                else
                {
                    Notification noProvide = new Notification
                    {
                        IconName = Stock.DialogError,
                        Summary  = LocalizationCatalog.GetString("Launchpad - Platform not provided!"),
                        Body     = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.")
                    };
                    noProvide.Show();

                    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.Install, false);
                }
                break;
            }

            case ELauncherMode.Install:
            {
                //check for a .provides file in the platform directory on the server
                //if there is none, the server does not provide a game for that platform
                if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                {
                    //install the game asynchronously
                    SetLauncherMode(ELauncherMode.Install, true);
                    Game.InstallGame();
                }
                else
                {
                    Notification noProvide = new Notification
                    {
                        IconName = Stock.DialogError,
                        Summary  = LocalizationCatalog.GetString("Launchpad - Platform not provided!"),
                        Body     = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.")
                    };
                    noProvide.Show();

                    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.Install, false);
                }
                break;
            }

            case ELauncherMode.Update:
            {
                if (Checks.IsLauncherOutdated())
                {
                    SetLauncherMode(ELauncherMode.Update, true);
                    Launcher.UpdateLauncher();
                }
                else
                {
                    // Uppdate the game asynchronously
                    if (Checks.IsPlatformAvailable(Config.GetSystemTarget()))
                    {
                        // Install the game asynchronously
                        SetLauncherMode(ELauncherMode.Update, true);
                        Game.UpdateGame();
                    }
                    else
                    {
                        Notification noProvide = new Notification
                        {
                            IconName = Stock.DialogError,
                            Summary  = LocalizationCatalog.GetString("Launchpad - Platform not provided!"),
                            Body     = LocalizationCatalog.GetString("The server does not provide the game for the selected platform.")
                        };
                        noProvide.Show();

                        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.Install, false);
                    }
                }
                break;
            }

            case ELauncherMode.Launch:
            {
                // Events such as LaunchFailed can fire before this has finished
                // Thus, we set the mode before the actual launching of the game.
                SetLauncherMode(ELauncherMode.Launch, true);
                Game.LaunchGame();

                break;
            }

            case ELauncherMode.Inactive:
            {
                Log.Warn("The main button was pressed with an invalid active mode. No functionality has been defined for this mode.");
                break;
            }

            default:
            {
                Log.Warn("The main button was pressed with an invalid active mode. No functionality has been defined for this mode.");
                break;
            }
            }
        }