Skip to content

Commit 549a486

Browse files
committed
Changed the image to get from stream and added it to the client
1 parent f6cf6a4 commit 549a486

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/HyperMC.CurseForge/ForgeClient.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,17 @@ public async Task<MinecraftVersion[]> GetMinecraftVersions()
6464
{
6565
return await _forgeClient.Minecraft.RetrieveGameVersions();
6666
}
67+
68+
public async Task<Stream> GetImageFromURL(string url)
69+
{
70+
var result = await _forgeClient.HttpClient.GetAsync(url);
71+
72+
if (result.IsSuccessStatusCode)
73+
{
74+
return await result.Content.ReadAsStreamAsync();
75+
}
76+
77+
return null;
78+
}
6779
}
6880
}

src/HyperMC.CurseForge/IForgeClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using ForgedCurse.Enumeration;
22
using ForgedCurse.Json;
3+
using System.IO;
34
using System.Threading.Tasks;
45

56
namespace HyperMC.CurseForge
67
{
78
public interface IForgeClient
89
{
910
Task DownloadMod(Addon mod, string filePath);
11+
Task<Stream> GetImageFromURL(string url);
1012
Task<MinecraftVersion[]> GetMinecraftVersions();
1113
Task<Addon[]> SearchForMod(string modName = "", string version = "", int amount = 10, int offset = 0, MinecraftCategory category = MinecraftCategory.All, MinecraftSection seciton = MinecraftSection.Mod, AddonSorting sorting = AddonSorting.Featured);
1214
}

src/HyperMC/HyperMcView.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private async void ModpacksUpdated(object? sender, NotifyCollectionChangedEventA
129129
await _fileUesr.WriteToFile(_modpacks.ToArray(), $@"{_settings.ModPacksPath}\packs.json");
130130
}
131131

132-
private static ModpackBox CreateModpackBox(ModpackData data)
132+
private ModpackBox CreateModpackBox(ModpackData data)
133133
{
134134
Image thumbnail;
135135
if (string.IsNullOrWhiteSpace(data.Thumbnail))
@@ -138,7 +138,8 @@ private static ModpackBox CreateModpackBox(ModpackData data)
138138
}
139139
else
140140
{
141-
thumbnail = Image.FromFile(data.Thumbnail);
141+
// May need to be changed depending on how the image will be set
142+
thumbnail = Image.FromStream(_forgeClient.GetImageFromURL(data.Thumbnail).GetAwaiter().GetResult());
142143
}
143144

144145
return new()

0 commit comments

Comments
 (0)