/// <summary>
        /// Binds the asynchronous.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <returns>Task.</returns>
        protected virtual async Task BindAsync(IGame game = null)
        {
            await TriggerOverlayAsync(true, localizationManager.GetResource(LocalizationResources.Installed_Mods.LoadingMods));

            if (game == null)
            {
                game = gameService.GetSelected();
            }
            ModFilePopulationInCompleted = false;
            ActiveGame = game;
            if (game != null)
            {
                var mods = await Task.Run(() => modService.GetInstalledMods(game));

                await Task.Run(async() =>
                {
                    await PopulateModFilesAsyncAsync(mods).ConfigureAwait(false);
                    ModFilePopulationInCompleted = true;
                    EvalAchievementCompatibility(mods);
                });

                await Task.Delay(100);

                Mods    = mods.ToObservableCollection();
                AllMods = Mods.ToHashSet();
                var invalidMods = AllMods.Where(p => !p.IsValid);
                if (invalidMods.Count() > 0)
                {
                    await RemoveInvalidModsPromptAsync(invalidMods).ConfigureAwait(false);
                }
                var searchString = FilterMods.Text ?? string.Empty;
                FilteredMods = Mods.Where(p => p.Name.Contains(searchString, StringComparison.InvariantCultureIgnoreCase) ||
                                          (p.RemoteId.HasValue && p.RemoteId.GetValueOrDefault().ToString().Contains(searchString))).ToObservableCollection();
                AllModsEnabled = FilteredMods.Where(p => p.IsValid).Count() > 0 && 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
            {
                Mods    = FilteredMods = new System.Collections.ObjectModel.ObservableCollection <IMod>();
                AllMods = Mods.ToHashSet();
            }
            await TriggerOverlayAsync(false);
        }
예제 #2
0
    private async Task SaveApplication()
    {
        _saveToken.Cancel();
        _saveToken = new CancellationTokenSource();

        try
        {
            ApplicationTuple.Config.EnabledMods = AllMods.Where(x => x.Enabled == true).Select(x => x.Tuple.Config.ModId).ToArray();
            await ApplicationTuple.SaveAsync(_saveToken.Token);
        }
        catch (TaskCanceledException) { /* Ignored */ }
    }
예제 #3
0
        IEnumerable <ModViewModel> GetModList(string searchText, bool enabled)
        {
            if (string.IsNullOrEmpty(searchText) || string.IsNullOrWhiteSpace(searchText))
            {
                return(AllMods.Where(x => x.IsEnabled == enabled));
            }

            return(AllMods.Where(x =>
                                 x.IsEnabled == enabled &&
                                 (
                                     x.Title.ToLowerInvariant().Contains(searchText.ToLowerInvariant()) ||
                                     x.Description.ToLowerInvariant().Contains(searchText.ToLowerInvariant())
                                 )));
        }
예제 #4
0
 public IOrderedEnumerable <Mod> GetModsCached(BeatModsQuery query)
 {
     return(query.sort.SortModList(AllMods.Where((e) => query.MatchesIgnoreSort(e)), !query.sortDescending));
 }
예제 #5
0
 public IEnumerable <Mod> GetModsWithName(string modName, bool onlyApproved = true)
 {
     return(AllMods.Where((e) => string.Compare(e.Name, modName, StringComparison.OrdinalIgnoreCase) == 0)
            .OnlyKeepStatus(onlyApproved ? ModStatus.Approved : ModStatus.All)
            .OrderByDescending((e) => SemVersionExtenions.AsNumber(e.Version)));
 }
예제 #6
0
 private void SaveApplication()
 {
     ApplicationTuple.Config.EnabledMods = AllMods.Where(x => x.Enabled == true).Select(x => x.Tuple.Config.ModId).ToArray();
     ApplicationTuple.Save();
 }
        /// <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);
            }
        }