/// <summary> /// delete descriptor as an asynchronous operation. /// </summary> /// <param name="mods">The mods.</param> protected virtual async Task DeleteDescriptorAsync(IEnumerable <IMod> mods) { if (mods?.Count() > 0) { await TriggerOverlayAsync(true, message : localizationManager.GetResource(LocalizationResources.Installed_Mods.RefreshingModList)); await modService.DeleteDescriptorsAsync(mods); await modService.InstallModsAsync(); RefreshMods(); var title = localizationManager.GetResource(LocalizationResources.Notifications.DescriptorsRefreshed.Title); var message = localizationManager.GetResource(LocalizationResources.Notifications.DescriptorsRefreshed.Message); notificationAction.ShowNotification(title, message, NotificationType.Info); await TriggerOverlayAsync(false); } }
/// <summary> /// delete descriptor as an asynchronous operation. /// </summary> /// <param name="mods">The mods.</param> protected virtual async Task DeleteDescriptorAsync(IEnumerable <IMod> mods) { if (mods?.Count() > 0) { var id = idGenerator.GetNextId(); await TriggerOverlayAsync(id, true, message : localizationManager.GetResource(LocalizationResources.Installed_Mods.RefreshingModList)); await modService.DeleteDescriptorsAsync(mods); var result = await modService.InstallModsAsync(Mods); if (result != null && result.Any(p => p.Invalid)) { await ShowInvalidModsNotificationAsync(result.Where(p => p.Invalid).ToList()); } RefreshMods(); var title = localizationManager.GetResource(LocalizationResources.Notifications.DescriptorsRefreshed.Title); var message = localizationManager.GetResource(LocalizationResources.Notifications.DescriptorsRefreshed.Message); notificationAction.ShowNotification(title, message, NotificationType.Info); await TriggerOverlayAsync(id, false); } }
/// <summary> /// Called when [activated]. /// </summary> /// <param name="disposables">The disposables.</param> protected override void OnActivated(CompositeDisposable disposables) { Task.Run(() => EvalResumeAvailabilityLoopAsync().ConfigureAwait(false)); ShowAdvancedFeatures = (gameService.GetSelected()?.AdvancedFeaturesSupported).GetValueOrDefault(); AnalyzeClass = string.Empty; var allowModSelectionEnabled = this.WhenAnyValue(v => v.AllowModSelection); var applyEnabled = Observable.Merge(this.WhenAnyValue(v => v.ApplyingCollection, v => !v), allowModSelectionEnabled); this.WhenAnyValue(v => v.CollectionMods.SelectedModCollection).Subscribe(s => { if (s != null) { AllowModSelection = true; InstalledMods.AllowModSelection = true; CollectionMods.AllowModSelection = true; } else { AllowModSelection = false; InstalledMods.AllowModSelection = false; CollectionMods.AllowModSelection = false; } InstallModsAsync().ConfigureAwait(true); }).DisposeWith(disposables); this.WhenAnyValue(v => v.InstalledMods.Mods).Subscribe(v => { CollectionMods.SetMods(v, InstalledMods.ActiveGame); }); this.WhenAnyValue(v => v.InstalledMods.RefreshingMods).Subscribe(s => { CollectionMods.HandleModRefresh(s, InstalledMods.Mods, InstalledMods.ActiveGame); }).DisposeWith(disposables); this.WhenAnyValue(v => v.CollectionMods.NeedsModListRefresh).Where(x => x).Subscribe(s => { InstalledMods.RefreshMods(); }).DisposeWith(disposables); this.WhenAnyValue(p => p.InstalledMods.PerformingEnableAll).Subscribe(s => { CollectionMods.HandleEnableAllToggled(s, InstalledMods.AllModsEnabled, InstalledMods.FilteredMods); }).DisposeWith(disposables); ApplyCommand = ReactiveCommand.Create(() => { ApplyCollectionAsync(idGenerator.GetNextId()).ConfigureAwait(true); }, applyEnabled).DisposeWith(disposables); AnalyzeCommand = ReactiveCommand.CreateFromTask(async() => { var game = gameService.GetSelected(); if (game != null && CollectionMods.SelectedMods?.Count > 0 && CollectionMods.SelectedModCollection != null) { var id = idGenerator.GetNextId(); await TriggerOverlayAsync(id, true, localizationManager.GetResource(LocalizationResources.App.WaitBackgroundOperationMessage)); await shutDownState.WaitUntilFreeAsync(); modPatchCollectionService.ResetPatchStateCache(); var mode = await modPatchCollectionService.GetPatchStateModeAsync(CollectionMods.SelectedModCollection.Name); if (mode == PatchStateMode.None) { await TriggerOverlayAsync(id, false); await Task.Delay(50); IsModeOpen = true; } else { await AnalyzeModsAsync(id, mode); } } }, allowModSelectionEnabled).DisposeWith(disposables); async Task <bool> ensureSteamIsRunning(IGameSettings args) { if (gameService.IsSteamGame(args)) { // Check if process is running var processes = Process.GetProcesses(); if (!processes.Any(p => p.ProcessName.Equals(SteamProcess, StringComparison.OrdinalIgnoreCase))) { await appAction.OpenAsync(SteamLaunch); var attempts = 0; while (!processes.Any(p => p.ProcessName.Equals(SteamProcess, StringComparison.OrdinalIgnoreCase))) { if (attempts > 3) { break; } await Task.Delay(3000); processes = Process.GetProcesses(); attempts++; } } } return(true); } async Task launchGame(bool continueGame) { var game = gameService.GetSelected(); if (game != null) { var args = gameService.GetLaunchSettings(game, continueGame); if (!string.IsNullOrWhiteSpace(args.ExecutableLocation)) { var id = idGenerator.GetNextId(); await TriggerOverlayAsync(id, true, localizationManager.GetResource(LocalizationResources.Mod_Actions.LaunchGame.Overlay)); if (game.RefreshDescriptors) { await modService.DeleteDescriptorsAsync(InstalledMods.Mods); await modService.InstallModsAsync(InstalledMods.Mods); } await ApplyCollectionAsync(id, false); await MessageBus.PublishAsync(new LaunchingGameEvent(game.Type)); if (gameService.IsSteamLaunchPath(args)) { if (await appAction.OpenAsync(args.ExecutableLocation)) { if (game.CloseAppAfterGameLaunch) { await appAction.ExitAppAsync(); } } else { notificationAction.ShowNotification(localizationManager.GetResource(LocalizationResources.Mod_Actions.LaunchGame.LaunchError.Title), localizationManager.GetResource(LocalizationResources.Mod_Actions.LaunchGame.LaunchError.Message), NotificationType.Error, 10); await TriggerOverlayAsync(id, false); } } else { await ensureSteamIsRunning(args); if (await appAction.RunAsync(args.ExecutableLocation, args.LaunchArguments)) { if (game.CloseAppAfterGameLaunch) { await appAction.ExitAppAsync(); } else { await TriggerOverlayAsync(id, false); } } else { notificationAction.ShowNotification(localizationManager.GetResource(LocalizationResources.Mod_Actions.LaunchGame.LaunchError.Title), localizationManager.GetResource(LocalizationResources.Mod_Actions.LaunchGame.LaunchError.Message), NotificationType.Error, 10); await TriggerOverlayAsync(id, false); } } } else { notificationAction.ShowNotification(localizationManager.GetResource(LocalizationResources.Mod_Actions.LaunchGame.NotSet.Title), localizationManager.GetResource(LocalizationResources.Mod_Actions.LaunchGame.NotSet.Message), NotificationType.Warning, 10); } } } LaunchGameCommand = ReactiveCommand.CreateFromTask(async() => { await launchGame(false); }, allowModSelectionEnabled).DisposeWith(disposables); ResumeGameCommand = ReactiveCommand.CreateFromTask(async() => { await launchGame(true); }, allowModSelectionEnabled).DisposeWith(disposables); AdvancedModeCommand = ReactiveCommand.CreateFromTask(async() => { await AnalyzeModsAsync(idGenerator.GetNextId(), PatchStateMode.Advanced); }).DisposeWith(disposables); DefaultModeCommand = ReactiveCommand.CreateFromTask(async() => { await AnalyzeModsAsync(idGenerator.GetNextId(), PatchStateMode.Default); }).DisposeWith(disposables); CloseModeCommand = ReactiveCommand.Create(() => { ForceClosePopups(); }).DisposeWith(disposables); var previousCollectionNotification = string.Empty; CollectionMods.ConflictSolverStateChanged += (collectionName, state) => { AnalyzeClass = !state ? InvalidConflictSolverClass : string.Empty; if (!state && previousCollectionNotification != collectionName) { notificationAction.ShowNotification(localizationManager.GetResource(LocalizationResources.Notifications.ConflictSolverUpdate.Title), localizationManager.GetResource(LocalizationResources.Notifications.ConflictSolverUpdate.Message), NotificationType.Warning, 30); previousCollectionNotification = collectionName; } }; gameDirectoryChangedHandler.Message.Subscribe(s => { InstalledMods.RefreshMods(); EvalResumeAvailability(s.Game); }).DisposeWith(disposables); this.WhenAnyValue(v => v.InstalledMods.ModFilePopulationInCompleted).Subscribe(s => { CollectionMods.CanExportModHashReport = s; }).DisposeWith(disposables); base.OnActivated(disposables); }