/// <summary> /// Binds the asynchronous. /// </summary> /// <param name="game">The game.</param> /// <param name="skipOverlay">if set to <c>true</c> [skip overlay].</param> /// <returns>Task.</returns> protected virtual async Task BindAsync(IGame game = null, bool skipOverlay = false) { var raiseGameChanged = game != null; GameChangedRefresh = false; var id = idGenerator.GetNextId(); if (!skipOverlay) { await TriggerOverlayAsync(id, true, localizationManager.GetResource(LocalizationResources.Installed_Mods.LoadingMods)); } if (game == null) { game = gameService.GetSelected(); } ModFilePopulationCompleted = false; ActiveGame = game; if (game != null) { if (raiseGameChanged) { GameChangedRefresh = true; } var mods = await Task.Run(async() => await modService.GetInstalledModsAsync(game)); await Task.Run(async() => { await PopulateModFilesAsyncAsync(mods).ConfigureAwait(false); ModFilePopulationCompleted = true; EvalAchievementCompatibility(mods); }); await Task.Delay(100); Mods = mods.ToObservableCollection(); AllMods = Mods.ToHashSet(); var invalidMods = AllMods.Where(p => !p.IsValid); if (invalidMods.Any()) { await Dispatcher.UIThread.SafeInvokeAsync(async() => { await RemoveInvalidModsPromptAsync(invalidMods).ConfigureAwait(false); }); } var searchString = FilterMods.Text ?? string.Empty; FilteredMods = modService.FilterMods(Mods, searchString).ToObservableCollection(); AllModsEnabled = FilteredMods.Where(p => p.IsValid).Any() && FilteredMods.Where(p => p.IsValid).All(p => p.IsSelected); if (Disposables != null) { modChanged?.Dispose(); modChanged = null; modChanged = Mods.ToSourceList().Connect().WhenPropertyChanged(s => s.IsSelected).Subscribe(s => { if (!checkingState) { CheckModEnabledStateAsync().ConfigureAwait(false); } }).DisposeWith(Disposables); } var state = appStateService.Get(); InitSortersAndFilters(state); ApplyDefaultSort(); } else { if (raiseGameChanged) { GameChangedRefresh = true; } Mods = FilteredMods = new System.Collections.ObjectModel.ObservableCollection <IMod>(); AllMods = Mods.ToHashSet(); } if (!skipOverlay) { await TriggerOverlayAsync(id, false); } }