/// <summary> /// Called when [activated]. /// </summary> /// <param name="disposables">The disposables.</param> protected override void OnActivated(CompositeDisposable disposables) { SetGame(gameService.GetSelected()); var updateSettings = updaterService.Get(); if (updateSettings.AutoUpdates == null) { async Task showPrompt() { var title = localizationManager.GetResource(LocalizationResources.Options.Updates.AutoUpdatePrompts.Title); var message = localizationManager.GetResource(LocalizationResources.Options.Updates.AutoUpdatePrompts.Message); if (await notificationAction.ShowPromptAsync(title, title, message, NotificationType.Info)) { updateSettings.AutoUpdates = true; SaveUpdateSettings(); await CheckForUpdatesAsync(true); } else { updateSettings.AutoUpdates = false; SaveUpdateSettings(); } } showPrompt().ConfigureAwait(false); } else if (updateSettings.AutoUpdates.GetValueOrDefault()) { CheckForUpdatesAsync(true).ConfigureAwait(false); } SetUpdateSettings(updateSettings); var updateCheckAllowed = this.WhenAnyValue(p => p.CheckingForUpdates, v => !v); OptionsCommand = ReactiveCommand.Create(() => { IsOpen = true; }).DisposeWith(disposables); CloseCommand = ReactiveCommand.Create(() => { IsOpen = false; }).DisposeWith(disposables); NavigateExeCommand = ReactiveCommand.CreateFromTask(async() => { IsOpen = false; var result = await fileDialogAction.OpenDialogAsync(NavigateExeTitle); IsOpen = true; if (!string.IsNullOrWhiteSpace(result)) { Game.ExecutableLocation = result; if (string.IsNullOrWhiteSpace(Game.LaunchArguments) || string.IsNullOrWhiteSpace(Game.UserDirectory)) { var defaultSettings = gameService.GetDefaultGameSettings(Game); if (string.IsNullOrWhiteSpace(Game.LaunchArguments)) { Game.LaunchArguments = defaultSettings.LaunchArguments; } if (string.IsNullOrWhiteSpace(Game.UserDirectory)) { Game.UserDirectory = defaultSettings.UserDirectory; } } SaveGame(); } }).DisposeWith(disposables); NavigateDirectoryCommand = ReactiveCommand.CreateFromTask(async() => { IsOpen = false; var result = await fileDialogAction.OpenFolderDialogAsync(NavigateUserDirTitle); IsOpen = true; if (!string.IsNullOrWhiteSpace(result)) { Game.UserDirectory = result; SaveGame(); } }).DisposeWith(disposables); ResetExeCommand = ReactiveCommand.Create(() => { var defaultSettings = gameService.GetDefaultGameSettings(Game); Game.ExecutableLocation = defaultSettings.ExecutableLocation; if (string.IsNullOrWhiteSpace(Game.LaunchArguments)) { Game.LaunchArguments = defaultSettings.LaunchArguments; } if (string.IsNullOrWhiteSpace(Game.UserDirectory)) { Game.UserDirectory = defaultSettings.UserDirectory; } SaveGame(); }).DisposeWith(disposables); ResetDirectoryCommand = ReactiveCommand.Create(() => { var defaultSettings = gameService.GetDefaultGameSettings(Game); Game.UserDirectory = defaultSettings.UserDirectory; SaveGame(); }).DisposeWith(disposables); ResetArgsCommand = ReactiveCommand.Create(() => { Game.LaunchArguments = gameService.GetDefaultGameSettings(Game).LaunchArguments; }).DisposeWith(disposables); AutoConfigureCommand = ReactiveCommand.CreateFromTask(async() => { IsOpen = false; var result = await fileDialogAction.OpenFolderDialogAsync(NavigateGameTitle); IsOpen = true; if (!string.IsNullOrWhiteSpace(result)) { var settings = gameService.GetGameSettingsFromJson(Game, result); if (settings != null) { Game.UserDirectory = settings.UserDirectory; Game.ExecutableLocation = settings.ExecutableLocation; Game.LaunchArguments = settings.LaunchArguments; SaveGame(); } } }).DisposeWith(disposables); CheckForUpdatesCommand = ReactiveCommand.CreateFromTask(async() => { await CheckForUpdatesAsync(); IsOpen = true; }, updateCheckAllowed).DisposeWith(disposables); var downloadingUpdates = false; var installingUpdates = false; InstallUpdatesCommand = ReactiveCommand.CreateFromTask(async() => { downloadingUpdates = true; await TriggerOverlayAsync(true, localizationManager.GetResource(LocalizationResources.Options.Updates.Overlay.UpdateDownloading)); if (await updater.DownloadUpdateAsync()) { downloadingUpdates = false; await TriggerOverlayAsync(true, localizationManager.GetResource(LocalizationResources.Options.Updates.Overlay.UpdateInstalling)); installingUpdates = true; await updater.InstallUpdateAsync(); installingUpdates = false; await TriggerOverlayAsync(false); } else { downloadingUpdates = false; await TriggerOverlayAsync(false); } }).DisposeWith(disposables); updater.Error.Subscribe(s => { var title = localizationManager.GetResource(LocalizationResources.Options.Updates.Errors.DownloadErrorTitle); var message = localizationManager.GetResource(LocalizationResources.Options.Updates.Errors.DownloadErrorMessage); logger.Error(s); notificationAction.ShowNotification(title, message, NotificationType.Error, 30); TriggerOverlay(false); }).DisposeWith(disposables); updater.Progress.Subscribe(s => { if (downloadingUpdates) { var message = localizationManager.GetResource(LocalizationResources.Options.Updates.Overlay.UpdateDownloading); var progress = Smart.Format(localizationManager.GetResource(LocalizationResources.Options.Updates.Overlay.UpdateDownloadProgress), new { Progress = s }); TriggerOverlay(true, message, progress); } else if (installingUpdates) { var message = localizationManager.GetResource(LocalizationResources.Options.Updates.Overlay.UpdateInstalling); var progress = Smart.Format(localizationManager.GetResource(LocalizationResources.Options.Updates.Overlay.UpdateDownloadProgress), new { Progress = s }); TriggerOverlay(true, message, progress); } }).DisposeWith(disposables); base.OnActivated(disposables); }