Example #1
0
        private async void Launch(object sender, RoutedEventArgs e)
        {
            var Core   = App.Core;
            var Config = App.Config;

            if (Config.JavaPath == null)
            {
                if (MessageBox.Show("好气哦,Java在哪里啊 Σ(  ̄□ ̄||)!!\n需要给您打开下载页面吗?", "吓得我喝了杯82年的Java",
                                    MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    System.Diagnostics.Process.Start("https://www.java.com/zh_CN/download/manual.jsp");
                }
                return;
            }
            else
            {
                Core.JavaPath = Config.JavaPath;
            }

            Core.GameLaunch += OnGameLaunch;

            var LaunchVersion = App.Versions[Config.VersionIndex];

            var lostEssentials = DownloadHelper.GetLostEssentials(Core, LaunchVersion);

            if (lostEssentials.Any())
            {
                var downloadPage = new DownloadPage(lostEssentials, "下载依赖库");
                NavigationService.Navigate(downloadPage);
                await Task.Run(() => downloadPage.DownloadComplete.WaitOne());

                if (!downloadPage.Succeeded)
                {
                    if (MessageBox.Show("依赖库未全部下载成功,可能无法正常启动\n是否继续启动", "Σ(  ̄□ ̄||)",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No)
                    {
                        return;
                    }
                }
            }

            var lostAssets = DownloadHelper.GetLostAssets(Core, LaunchVersion);

            if (lostAssets.Any() && MessageBox.Show("资源文件缺失,是否补齐", "(σ゚∀゚)σ",
                                                    MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                var downloadPage = new DownloadPage(lostAssets, "下载资源文件");
                NavigationService.Navigate(downloadPage);
                await Task.Run(() => downloadPage.DownloadComplete.WaitOne());
            }

            var Result = Core.Launch(new LaunchOptions()
            {
                Version      = LaunchVersion,
                VersionSplit = Config.VersionSplit,

                Authenticator = (Config.Offline) ?
                                (IAuthenticator) new OfflineAuthenticator(Config.UserName) : new YggdrasilLogin(Config.Email, Config.PassWord, false),
                MaxMemory = Config.MaxMemory,

                Size = new WindowSize
                {
                    Width      = Config.WinWidth,
                    Height     = Config.WinHeight,
                    FullScreen = Config.FullScreen
                },

                ServerAddress = Config.ServerAddress,
                VersionType   = "GBCL-v2.0.6",
            }, x => x.AdvencedArguments.Add(Config.AdvancedArgs));

            if (Result.Success)
            {
                Launching = true;
                LaunchButton.IsEnabled = false;
                tb.Text = "(。-`ω´-) 启动中...";
                LaunchButton.Content = "启动中";
            }
            else
            {
                MessageBox.Show(Result.ErrorMessage, Result.ErrorType.ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
                LaunchButton.IsEnabled = true;
            }
        }
Example #2
0
        private async void Launch(object sender, RoutedEventArgs e)
        {
            if (Config.Args.JavaPath == null)
            {
                if (MessageBox.Show("好气哦,Java在哪里啊 Σ(  ̄□ ̄||)!!\n需要给您打开下载页面吗?", "吓得我喝了杯82年的Java",
                                    MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
                {
                    System.Diagnostics.Process.Start("https://www.java.com/zh_CN/download/manual.jsp");
                }
                return;
            }
            else
            {
                App.Core.JavaPath = Config.Args.JavaPath;
            }

            App.Core.GameLaunch += OnGameLaunch;

            var lostEssentials = DownloadHelper.GetLostEssentials(Config.Args.SelectedVersion);

            if (lostEssentials.Any())
            {
                var downloadPage = new DownloadPage();
                NavigationService.Navigate(downloadPage);
                bool hasDownloadSucceeded = await downloadPage.StartDownloadAsync(lostEssentials, "下载依赖库");

                if (!hasDownloadSucceeded)
                {
                    if (MessageBox.Show("依赖库未全部下载成功,可能无法正常启动\n是否继续启动", "Σ(  ̄□ ̄||)",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No)
                    {
                        return;
                    }
                }
            }

            var lostAssets = DownloadHelper.GetLostAssets(Config.Args.SelectedVersion);

            if (lostAssets.Any() && MessageBox.Show("资源文件缺失,是否补齐", "(σ゚∀゚)σ",
                                                    MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                var downloadPage = new DownloadPage();
                this.NavigationService?.Navigate(downloadPage);
                bool hasDownloadSucceeded = await downloadPage.StartDownloadAsync(lostAssets, "下载资源文件");

                if (!hasDownloadSucceeded)
                {
                    if (MessageBox.Show("资源文件未全部下载成功,游戏可能没有声效\n是否继续启动", "(´・ᆺ・`)",
                                        MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.No)
                    {
                        return;
                    }
                }
            }

            var Result = App.Core.Launch(new LaunchOptions
            {
                Version      = Config.Args.SelectedVersion,
                VersionSplit = Config.Args.IsVersionSplit,

                Authenticator = (Config.Args.IsOfflineMode) ?
                                (IAuthenticator) new OfflineAuthenticator(Config.Args.UserName) : new YggdrasilLogin(Config.Args.UserName, Config.Args.PassWord, false),
                MaxMemory = Config.Args.MaxMemory,

                Size = new WindowSize
                {
                    Width      = Config.Args.GameWinWidth,
                    Height     = Config.Args.GameWinHeight,
                    FullScreen = Config.Args.IsFullScreen
                },

                ServerAddress = Config.Args.ServerAddress,
                VersionType   = $"GBCL-v{Config.LauncherVersion}",
            }, x => x.AdvencedArguments.Add(Config.Args.AdvancedArgs));

            if (Result.Success)
            {
                _isLaunching            = true;
                _launchButton.IsEnabled = false;
                _titleBox.Text          = "(。-`ω´-) 启动中...";
                _launchButton.Content   = "启动中";
            }
            else
            {
                MessageBox.Show(Result.ErrorMessage, Result.ErrorType.ToString(), MessageBoxButton.OK, MessageBoxImage.Error);
                _launchButton.IsEnabled = true;
            }
        }