Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startKind"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
        {
            if (!CheckWindowsBuildVersion())
            {
                var dialog = new MessageDialog("The minimum required Windows version for this App is 10.0.14393 (Aniversary Update). PoGo-UWP will exit now");
                await dialog.ShowAsync();

                App.Current.Exit();
            }

            bool forceToMainPage = false;

            // Check for updates (ignore resume)
            if (startKind == StartKind.Launch)
            {
                var latestUpdateInfo = await UpdateManager.IsUpdateAvailable();

                while (latestUpdateInfo == null || latestUpdateInfo.Status == UpdateManager.UpdateStatus.NoInternet)
                {
                    var dialog = new MessageDialog("Do you want try to connect again?", "No internet connection");

                    dialog.Commands.Add(new UICommand(Utils.Resources.CodeResources.GetString("YesText"))
                    {
                        Id = 0
                    });
                    dialog.Commands.Add(new UICommand(Utils.Resources.CodeResources.GetString("NoText"))
                    {
                        Id = 1
                    });
                    dialog.DefaultCommandIndex = 0;
                    dialog.CancelCommandIndex  = 1;

                    var result = await dialog.ShowAsyncQueue();

                    if ((int)result.Id != 0)
                    {
                        App.Current.Exit();
                    }
                    else
                    {
                        latestUpdateInfo = await UpdateManager.IsUpdateAvailable();
                    }
                }

                if (latestUpdateInfo.Status == UpdateManager.UpdateStatus.UpdateAvailable)
                {
                    var dialog =
                        new MessageDialog(string.Format(Utils.Resources.CodeResources.GetString("UpdatedVersionText"),
                                                        latestUpdateInfo.Version, latestUpdateInfo.Description));

                    dialog.Commands.Add(new UICommand(Utils.Resources.CodeResources.GetString("YesText"))
                    {
                        Id = 0
                    });
                    dialog.Commands.Add(new UICommand(Utils.Resources.CodeResources.GetString("NoText"))
                    {
                        Id = 1
                    });
                    dialog.DefaultCommandIndex = 0;
                    dialog.CancelCommandIndex  = 1;

                    var result = await dialog.ShowAsyncQueue();

                    if ((int)result.Id == 0)
                    {
                        var t1 = UpdateManager.InstallUpdate();
                        forceToMainPage = true;
                    }
                }
                else if (latestUpdateInfo.Status == UpdateManager.UpdateStatus.UpdateForced)
                {
                    //start forced update
                    var t1 = UpdateManager.InstallUpdate();
                    forceToMainPage = true;
                }
                else if (latestUpdateInfo.Status == UpdateManager.UpdateStatus.NextVersionNotReady)
                {
                    var twoLines = Environment.NewLine + Environment.NewLine;
                    var dialog   = new MessageDialog("Niantic has raised the minimum API level above what we have access to, so we've temporarily disabled the app to protect your account." +
                                                     twoLines + "DO NOT attempt to bypass this check. Accounts that access lower APIs than the minimum WILL BE BANNED by Niantic." + twoLines +
                                                     "An update will be ready soon. Please DO NOT open an issue on GitHub, you are seeing this message because we already know about it, and this is how we're telling you. " +
                                                     "Thank you for your patience." + twoLines + "- The PoGo-UWP Team");
                    dialog.Commands.Add(new UICommand("OK"));
                    dialog.DefaultCommandIndex = 0;
                    dialog.CancelCommandIndex  = 1;

                    var result = await dialog.ShowAsyncQueue();

                    App.Current.Exit();
                }
            }

            var webConfigurationInfo = await WebConfigurationManager.GetWebConfiguration();

            if (webConfigurationInfo != null)
            {
                WebConfigurationInfo wci = (WebConfigurationInfo)webConfigurationInfo;
                GymsAreDisabled = wci.gymsaredisabled;
            }

            AsyncSynchronizationContext.Register();

            // See if there is a key for the PokeHash server, ask one from the user if there isn't
            if (String.IsNullOrEmpty(SettingsService.Instance.PokehashAuthKey))
            {
                HockeyClient.Current.TrackPageView("PokehashKeyPage");
                await NavigationService.NavigateAsync(typeof(PokehashKeyPage), GameMapNavigationModes.AppStart);

                return;
            }

            var currentAccessToken = GameClient.GetAccessToken();

            if (currentAccessToken == null || forceToMainPage)
            {
                HockeyClient.Current.TrackPageView("MainPage");
                await NavigationService.NavigateAsync(typeof(MainPage));

                return;
            }
            else
            {
                try
                {
                    await GameClient.InitializeSession();

                    if (GameClient.IsInitialized)
                    {
                        HockeyClient.Current.TrackPageView("GameMapPage");
                        NavigationService.Navigate(typeof(GameMapPage), GameMapNavigationModes.AppStart);
                    }
                }
                catch (PtcLoginException ex)
                {
                    var errorMessage          = ex.Message ?? Utils.Resources.CodeResources.GetString("PtcLoginFailed");
                    ConfirmationDialog dialog = new Views.ConfirmationDialog(errorMessage);
                    dialog.Show();

                    HockeyClient.Current.TrackPageView("MainPage");
                    await NavigationService.NavigateAsync(typeof(MainPage));
                }
                catch (LocationException)
                {
                    ConfirmationDialog dialog = new Views.ConfirmationDialog(Utils.Resources.CodeResources.GetString("CouldNotGetLocation"));
                    dialog.Closed += (ss, ee) => { App.Current.Exit(); };
                    dialog.Show();
                }
                //catch (PokeHashException)
                //{
                //    var errorMessage = Utils.Resources.CodeResources.GetString("PokeHashException");
                //    ConfirmationDialog dialog = new Views.ConfirmationDialog(errorMessage);
                //    dialog.Closed += (ss, ee) => { Application.Current.Exit(); };
                //    dialog.Show();
                //}
                catch (HashVersionMismatchException ex)
                {
                    var errorMessage          = ex.Message + Utils.Resources.CodeResources.GetString("PokeHashVersionMismatch");
                    ConfirmationDialog dialog = new Views.ConfirmationDialog(errorMessage);
                    dialog.Closed += (ss, ee) => { Application.Current.Exit(); };
                    dialog.Show();
                }
                catch (Exception ex)    // When the PokeHash server returns an error, it is not safe to continue. Ask for another PokeHash Key
                {
                    var errorMessage          = ex.Message ?? Utils.Resources.CodeResources.GetString("HashingKeyExpired");
                    ConfirmationDialog dialog = new Views.ConfirmationDialog(errorMessage);
                    dialog.Show();

                    HockeyClient.Current.TrackPageView("PokehashKeyPage");
                    await NavigationService.NavigateAsync(typeof(PokehashKeyPage), GameMapNavigationModes.AppStart);
                }
            }

            await Task.CompletedTask;
        }