public static async Task DownloadCarAsync([NotNull] string id, string version = null) { try { var entry = await CmApiProvider.GetContentAsync <AcContentEntry>($"car/{id}"); if (entry != null) { if (version != null && entry.UiVersion != version && entry.OriginVersion != version) { throw new InformativeException($"Can’t download car “{id}”", $"Not the required version: indexed is {entry.UiVersion ?? entry.OriginVersion}, while required is {version}."); } if (!entry.ImmediateDownload && entry.OriginUrl != null && (Keyboard.Modifiers & ModifierKeys.Control) == 0) { WindowsHelper.ViewInBrowser(entry.OriginUrl); } else { await ContentInstallationManager.Instance.InstallAsync(entry.DownloadUrl, new ContentInstallationParams(false) { DisplayName = entry.UiName, Version = entry.UiVersion, InformationUrl = entry.OriginUrl }); } } else { throw new InformativeException($"Can’t download car “{id}”", "Attempt to find a description failed."); } } catch (Exception e) { NonfatalError.Notify($"Can’t download car “{id}”", e); } }
private static async Task LoadAvailableIdsAsyncInner() { try { var ids = await CmApiProvider.GetContentAsync <Dictionary <string, string[]> >(); if (ids == null) { Logging.Warning("Can’t load lists of available-to-download IDs"); return; } AvailableCarIds = ids.GetValueOrDefault("cars"); AvailableTrackIds = ids.GetValueOrDefault("tracks"); AvailableIdsLoaded?.Invoke(null, EventArgs.Empty); } catch (Exception e) { Logging.Warning(e); } finally { _availableLoadingTask = null; _availableIdsLoaded = true; } }