public virtual async Task ImportGames(string emulatorPath, IEnumerable <GameInfo> gameInfos, Action <GameInfo, string> callback, Action deferredCallback) { var updateGameInfos = new Queue <Action>(); await gameInfos.ParallelForEachAsync(async gameInfo => { if (gameInfo.GameId != null) { return; } var(name, region, id) = await IdentifyGame(emulatorPath, gameInfo.Path); var newInfo = new GameInfo(gameInfo) { DisplayName = name, Region = region, GameId = id != "???" ? id : null }; var cover = await coverService.GetCoverForGame(newInfo); updateGameInfos.Enqueue(() => { gameLibraryService.UpdateGameInfo(newInfo.Name, newInfo, shouldReloadLibrary: true); remoteConfigService.ImportConfig(newInfo.GameId, emulatorPath); }); callback.Invoke(newInfo, cover); }, maxDegreeOfParallelism : 20); while (updateGameInfos.Count > 0) { updateGameInfos.Dequeue()?.Invoke(); } deferredCallback?.Invoke(); }
private void GetAllCoversAsync() { Task.Run(() => Parallel.For(0, gameModels.Count, async index => gameModels[index].CoverPath = await coverService.GetCoverForGame(gameLibraryService.Games[index]))); }