Move Cosmetic Download To Main Form Thread

This commit is contained in:
Alan Moon 2025-08-03 14:27:00 -07:00
parent b17d391406
commit 00df7505a7
2 changed files with 59 additions and 15 deletions

View File

@ -172,12 +172,29 @@ namespace qtc_net_client_2
var res = await _apiService.GetUserInformationAsync(user!.Id); var res = await _apiService.GetUserInformationAsync(user!.Id);
var pfpRes = await _apiService.GetUserProfilePic(user!.Id); var pfpRes = await _apiService.GetUserProfilePic(user!.Id);
// get cosmetic
byte[]? cosmeticData = null;
if (user.ProfileCosmeticId != 0)
{
var storeRes = await _apiService.GetStoreItem(user.ProfileCosmeticId);
if (storeRes != null && storeRes.Success && storeRes.Data != null)
{
using var client = new HttpClient();
using var response = await client.GetAsync(storeRes.Data.AssetUrl);
if (response.IsSuccessStatusCode)
{
cosmeticData = await response.Content.ReadAsByteArrayAsync();
}
else LoggingService.LogString($"Could Not Get User Cosmetic.\nStatus Code: {response.StatusCode}");
}
}
if (pfpRes != null && !pfpRes.Success) LoggingService.LogString($"User Has No Profile Picture Or It Could Not Be Loaded.\n{pfpRes.Message}"); if (pfpRes != null && !pfpRes.Success) LoggingService.LogString($"User Has No Profile Picture Or It Could Not Be Loaded.\n{pfpRes.Message}");
if (res.Data != null && res.Success) if (res.Data != null && res.Success)
{ {
LoggingService.LogString($"Opening Profile For User '{res.Data.Username}'"); LoggingService.LogString($"Opening Profile For User '{res.Data.Username}'");
Profile frmProfile = new Profile(res.Data, pfpRes, Contacts, _apiService, _gatewayService); Profile frmProfile = new Profile(res.Data, pfpRes, Contacts, _apiService, _gatewayService, cosmeticData);
frmProfile.Show(); frmProfile.Show();
} }
} }
@ -296,12 +313,29 @@ namespace qtc_net_client_2
var res = await _apiService.GetUserInformationAsync(user!.Id); var res = await _apiService.GetUserInformationAsync(user!.Id);
var pfpRes = await _apiService.GetUserProfilePic(user!.Id); var pfpRes = await _apiService.GetUserProfilePic(user!.Id);
// get cosmetic
byte[]? cosmeticData = null;
if (user.ProfileCosmeticId != 0)
{
var storeRes = await _apiService.GetStoreItem(user.ProfileCosmeticId);
if (storeRes != null && storeRes.Success && storeRes.Data != null)
{
using var client = new HttpClient();
using var response = await client.GetAsync(storeRes.Data.AssetUrl);
if (response.IsSuccessStatusCode)
{
cosmeticData = await response.Content.ReadAsByteArrayAsync();
}
else LoggingService.LogString($"Could Not Get User Cosmetic.\nStatus Code: {response.StatusCode}");
}
}
if (pfpRes != null && !pfpRes.Success) LoggingService.LogString($"User Has No Profile Picture Or It Could Not Be Loaded.\n{pfpRes.Message}"); if (pfpRes != null && !pfpRes.Success) LoggingService.LogString($"User Has No Profile Picture Or It Could Not Be Loaded.\n{pfpRes.Message}");
if (res.Data != null && res.Success) if (res.Data != null && res.Success)
{ {
LoggingService.LogString($"Opening Profile For User '{res.Data.Username}'"); LoggingService.LogString($"Opening Profile For User '{res.Data.Username}'");
Profile frmProfile = new Profile(res.Data, pfpRes, Contacts, _apiService, _gatewayService); Profile frmProfile = new Profile(res.Data, pfpRes, Contacts, _apiService, _gatewayService, cosmeticData);
frmProfile.Show(); frmProfile.Show();
} }
} }

View File

@ -1,24 +1,25 @@
using QtCNETAPI.Dtos.User; using qtc_net_client_2.ClientModel;
using QtCNETAPI.Services.ApiService; using qtc_net_client_2.Properties;
using qtc_net_client_2.Services;
using QtCNETAPI.Dtos.User;
using QtCNETAPI.Models; using QtCNETAPI.Models;
using QtCNETAPI.Schema;
using QtCNETAPI.Services.ApiService;
using QtCNETAPI.Services.GatewayService;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using QtCNETAPI.Services.GatewayService;
using qtc_net_client_2.ClientModel;
using qtc_net_client_2.Properties;
using qtc_net_client_2.Services;
using QtCNETAPI.Schema;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
namespace qtc_net_client_2.Forms namespace qtc_net_client_2.Forms
{ {
@ -29,13 +30,16 @@ namespace qtc_net_client_2.Forms
private IGatewayService _gatewayService; private IGatewayService _gatewayService;
private ServiceResponse<byte[]>? pfpRes; private ServiceResponse<byte[]>? pfpRes;
byte[]? cosmeticRes;
private List<Contact> contactsList; private List<Contact> contactsList;
public Profile(UserInformationDto userInfo, ServiceResponse<byte[]>? pfp, List<Contact> contacts, IApiService apiService, IGatewayService gatewayService) public Profile(UserInformationDto userInfo, ServiceResponse<byte[]>? pfp, List<Contact> contacts, IApiService apiService, IGatewayService gatewayService, byte[]? cosmetic = null)
{ {
_userInformationDto = userInfo; _userInformationDto = userInfo;
_apiService = apiService; _apiService = apiService;
_gatewayService = gatewayService; _gatewayService = gatewayService;
pfpRes = pfp; pfpRes = pfp;
cosmeticRes = cosmetic;
contactsList = contacts; contactsList = contacts;
InitializeComponent(); InitializeComponent();
@ -75,6 +79,12 @@ namespace qtc_net_client_2.Forms
break; break;
} }
if(cosmeticRes != null)
{
using var ms = new MemoryStream(cosmeticRes);
CombineProfileImageWithCosmetic(pbUserPfp.Image, new Bitmap(ms));
}
if (_userInformationDto.ProfileCosmeticId != 0) if (_userInformationDto.ProfileCosmeticId != 0)
{ {
var res = await _apiService.GetStoreItem(_userInformationDto.ProfileCosmeticId); var res = await _apiService.GetStoreItem(_userInformationDto.ProfileCosmeticId);
@ -86,7 +96,7 @@ namespace qtc_net_client_2.Forms
{ {
using (var stream = await response.Content.ReadAsStreamAsync()) using (var stream = await response.Content.ReadAsStreamAsync())
{ {
CombineProfileImageWithCosmetic(pbUserPfp.Image, new Bitmap(stream));
} }
response.Dispose(); response.Dispose();
} }