コード例 #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>
        private void mainButton_Click(object sender, EventArgs e)
        {
            switch (Mode)
            {
            case ELauncherMode.Repair:
            {
                //bind events for UI updating
                Game.ProgressChanged    += OnGameDownloadProgressChanged;
                Game.GameRepairFinished += OnRepairFinished;
                Game.GameDownloadFailed += OnGameDownloadFailed;

                if (Checks.DoesServerProvidePlatform(Config.GetSystemTarget()))
                {
                    //repair the game asynchronously
                    Game.RepairGame();
                    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("noPlatformTitle");
                        platformNotProvidedNotification.BalloonTipText  = LocalizationCatalog.GetString("noPlatformMessage");

                        platformNotProvidedNotification.ShowBalloonTip(10000);
                    }

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

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

                if (Checks.DoesServerProvidePlatform(Config.GetSystemTarget()))
                {
                    //install the game asynchronously
                    MessageLabel.Text = LocalizationCatalog.GetString("installingLabel");
                    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("noPlatformTitle");
                        platformNotProvidedNotification.BalloonTipText  = LocalizationCatalog.GetString("noPlatformMessage");

                        platformNotProvidedNotification.ShowBalloonTip(10000);
                    }

                    MessageLabel.Text = LocalizationCatalog.GetString("noPlatformMessage");

                    SetLauncherMode(ELauncherMode.Install, false);
                }

                break;
            }

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

                if (Checks.IsLauncherOutdated())
                {
                    //update the launcher synchronously.
                    SetLauncherMode(ELauncherMode.Update, true);
                    Launcher.UpdateLauncher();
                }
                else
                {
                    if (Checks.DoesServerProvidePlatform(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("noPlatformTitle");
                            platformNotProvidedNotification.BalloonTipText  = LocalizationCatalog.GetString("noPlatformMessage");

                            platformNotProvidedNotification.ShowBalloonTip(10000);
                        }

                        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;
            }
            }
        }
コード例 #2
0
ファイル: MainWindow.cs プロジェクト: eyohansa/Launchpad
        /// <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    += OnGameDownloadProgressChanged;
                Game.GameRepairFinished += OnRepairFinished;
                Game.GameDownloadFailed += OnGameDownloadFailed;

                if (Checks.DoesServerProvidePlatform(Config.GetSystemTarget()))
                {
                    //install the game asynchronously
                    SetLauncherMode(ELauncherMode.Repair, true);
                    Game.RepairGame();
                }
                else
                {
                    Notification noProvide = new Notification();
                    noProvide.IconName = Stock.DialogError;
                    noProvide.Summary  = Mono.Unix.Catalog.GetString("Launchpad - Platform not provided!");
                    noProvide.Body     = Mono.Unix.Catalog.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      += OnGameDownloadProgressChanged;
                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.DoesServerProvidePlatform(Config.GetSystemTarget()))
                {
                    //install the game asynchronously
                    SetLauncherMode(ELauncherMode.Install, true);
                    Game.InstallGame();
                }
                else
                {
                    Notification noProvide = new Notification();
                    noProvide.IconName = Stock.DialogError;
                    noProvide.Summary  = Mono.Unix.Catalog.GetString("Launchpad - Platform not provided!");
                    noProvide.Body     = Mono.Unix.Catalog.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.UpdateLauncher();
                }
                else
                {
                    //bind events for UI updating
                    Game.GameDownloadFinished += OnGameDownloadFinished;
                    Game.ProgressChanged      += OnGameDownloadProgressChanged;
                    Game.GameDownloadFailed   += OnGameDownloadFailed;

                    //update the game asynchronously
                    if (Checks.DoesServerProvidePlatform(Config.GetSystemTarget()))
                    {
                        //install the game asynchronously
                        SetLauncherMode(ELauncherMode.Update, true);
                        Game.UpdateGame();
                    }
                    else
                    {
                        Notification noProvide = new Notification();
                        noProvide.IconName = Stock.DialogError;
                        noProvide.Summary  = Mono.Unix.Catalog.GetString("Launchpad - Platform not provided!");
                        noProvide.Body     = Mono.Unix.Catalog.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;
            }
            }
        }