public static async Task <byte[]> GetCoverImageBytes(ModelSaberEntry entry) { if (entry == null) { return(null); } Uri thumbnailURL; if (!Uri.TryCreate(entry.Thumbnail, UriKind.Absolute, out thumbnailURL)) { thumbnailURL = new Uri(entry.Download.Substring(0, entry.Download.LastIndexOf("/")) + "/" + entry.Thumbnail); } client.BaseAddress = null; HttpResponseMessage response = await client.GetAsync(thumbnailURL); // GIF loading code doesn't work, fix it later. it's pretty scuffed anyways, maybe just make it actually work as a gif... /*if (thumbnailURL.ToString().EndsWith(".gif")) * { * // oh boy, it's a gif. time for some processing stuff so we can just get the first frame. * // Maybe you can add a proper animation to this later * * byte[] byteArray = await response.Content.ReadAsByteArrayAsync(); * return await Task.Run(() => * { * TaskCompletionSource<byte[]> source = new TaskCompletionSource<byte[]>(); * AnimationLoader.Process(AnimationType.GIF, byteArray, (Texture2D tex, Rect[] uvs, float[] delays, int width, int height) => * { * // Why in the world are these textures not readable * // BSML PLS * // Some hacky magic to make it work * Texture2D duplicatedTexture = new Texture2D(tex.width, tex.height, TextureFormat.ARGB32, false); * Graphics.CopyTexture(tex, duplicatedTexture); * * source.SetResult(duplicatedTexture.EncodeToPNG()); * }); * return source.Task; * }); * }*/ return(await response.Content.ReadAsByteArrayAsync()); }
public static async Task <byte[]> GetModelBytes(ModelSaberEntry entry) { if (entry == null) { return(null); } if (modelDownloadCache.ContainsKey(entry.Id)) { return(modelDownloadCache[entry.Id]); } Uri downloadURL; if (!Uri.TryCreate(entry.Download, UriKind.Absolute, out downloadURL)) { downloadURL = new Uri(entry.Download.Substring(0, entry.Download.LastIndexOf("/")) + "/" + entry.Download); } client.BaseAddress = null; HttpResponseMessage response = await client.GetAsync(downloadURL); byte[] modelBytes = await response.Content.ReadAsByteArrayAsync(); modelDownloadCache.Add(entry.Id, modelBytes); return(modelBytes); }