// ReSharper disable once MemberCanBeMadeStatic.Global public async Task <Image> GetIconAsync(IHasIcon i) { bool goAgain; Image res = null; do { goAgain = false; var msg = new HttpRequestMessage(HttpMethod.Get, i.Icon); HttpResponseMessage msg2 = await _client.SendAsync(msg); switch ((int)msg2.StatusCode) { case 200: switch (i.IconFormat.ToLower()) { case "webp": res = WebPDecode(await msg2.Content.ReadAsByteArrayAsync()); break; case "jpg": case "jpeg": case "png": case "gif": res = Image.FromStream(await msg2.Content.ReadAsStreamAsync()); break; default: throw new UnknownImageFormatException("Image format " + i.IconFormat + " is not supported."); } res = Image.FromStream(await msg2.Content.ReadAsStreamAsync()); break; case 404: throw new NotFoundException("Icon " + i.Icon + " does not exist on the Discord CDN."); default: goAgain = true; break; } } while (goAgain); return(res); }
public Image GetIcon(IHasIcon i) { return(GetIconAsync(i).Await()); }
public static async Task <Image> GetIconAsync(this IHasIcon i, [CanBeNull] Client client) { client = client ?? DiscordEnvironment.CurrentClient; return(client == null ? null : await client.GetIconAsync(i)); }
public static Image GetIcon(this IHasIcon i, [CanBeNull] Client client) { return(GetIconAsync(i, client).Await()); }
private async Task ImportGameAssets(string mainPath) { GameIntegration.GameAssetManager.Purge(); if (AppConfig.Instance.importVanilla) { stepText.Text = LocalizationManager.Current.Interface.Translate("StartUp_ImportGameAssets_Window_Step_Unturned"); await GameIntegration.GameAssetManager.Import(mainPath, GameIntegration.EGameAssetOrigin.Unturned, (index, total) => { updateProgress(index, total); }, tokenSource); clearProgress(); if (tokenSource.IsCancellationRequested) { await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE); GameIntegration.GameAssetManager.Purge(); ThumbnailManager.Purge(); return; } GameAssetManager.HasImportedVanilla = true; } if (AppConfig.Instance.importWorkshop) { string workshopPath = PathUtility.GetUnturnedWorkshopPathFromUnturnedPath(mainPath); stepText.Text = LocalizationManager.Current.Interface.Translate("StartUp_ImportGameAssets_Window_Step_Workshop"); await GameIntegration.GameAssetManager.Import(workshopPath, GameIntegration.EGameAssetOrigin.Workshop, (index, total) => { updateProgress(index, total); }, tokenSource); clearProgress(); if (tokenSource.IsCancellationRequested) { await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE); GameIntegration.GameAssetManager.Purge(); ThumbnailManager.Purge(); return; } GameAssetManager.HasImportedWorkshop = true; } if (AppConfig.Instance.generateThumbnailsBeforehand && GameAssetManager.HasImportedAssets) { stepText.Text = LocalizationManager.Current.Interface.Translate("StartUp_ImportGameAssets_Window_Step_Thumbnails"); IHasIcon[] assetsWithIcons = GameIntegration.GameAssetManager.GetAllAssetsWithIcons().ToArray(); for (int i = 0; i < assetsWithIcons.Length; i++) { IHasIcon a = assetsWithIcons[i]; if (i % 25 == 0) { if (tokenSource.IsCancellationRequested) { await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE); GameIntegration.GameAssetManager.Purge(); ThumbnailManager.Purge(); return; } updateProgress(i, assetsWithIcons.Length); await Task.Delay(1); } else { await Task.Yield(); } ThumbnailManager.CreateThumbnail(a.ImagePath); } clearProgress(); if (tokenSource.IsCancellationRequested) { await App.Logger.Log("Cancelled after import", Logging.ELogLevel.TRACE); GameIntegration.GameAssetManager.Purge(); ThumbnailManager.Purge(); return; } } hasDone = true; Close(); }