About tab - Fixed my icon being smoll, lmao

About tab - Use async image loader instead of manual bitmaps
Workshop - Use async image loader for entry icons
This commit is contained in:
Robert committed 2023-08-24 19:38:47 +02:00
1 parent 2a34381926
commit e21edd0ed6
13 files changed
+75 -223

No files matched your search

@@ -23,40 +23,6 @@ public class WorkshopService : IWorkshopService
});
}
/// <inheritdoc />
public async Task<Bitmap?> GetEntryIcon(Guid entryId, CancellationToken cancellationToken)
{
await _iconCacheLock.WaitAsync(cancellationToken);
try
{
if (_entryIconCache.TryGetValue(entryId, out Stream? cachedBitmap))
{
cachedBitmap.Seek(0, SeekOrigin.Begin);
return new Bitmap(cachedBitmap);
}
}
finally
{
_iconCacheLock.Release();
}
HttpClient client = _httpClientFactory.CreateClient(WorkshopConstants.WORKSHOP_CLIENT_NAME);
try
{
HttpResponseMessage response = await client.GetAsync($"entries/{entryId}/icon", cancellationToken);
response.EnsureSuccessStatusCode();
Stream data = await response.Content.ReadAsStreamAsync(cancellationToken);
_entryIconCache[entryId] = data;
return new Bitmap(data);
}
catch (HttpRequestException)
{
// ignored
return null;
}
}
public async Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken)
{
icon.Seek(0, SeekOrigin.Begin);
@@ -96,6 +62,5 @@ public class WorkshopService : IWorkshopService
public interface IWorkshopService
{
Task<Bitmap?> GetEntryIcon(Guid entryId, CancellationToken cancellationToken);
Task<ImageUploadResult> SetEntryIcon(Guid entryId, Progress<StreamProgress> progress, Stream icon, CancellationToken cancellationToken);
}