diff --git a/qtc-net-client-2/Forms/Main.cs b/qtc-net-client-2/Forms/Main.cs index 389ef0b..c5377de 100644 --- a/qtc-net-client-2/Forms/Main.cs +++ b/qtc-net-client-2/Forms/Main.cs @@ -172,12 +172,29 @@ namespace qtc_net_client_2 var res = await _apiService.GetUserInformationAsync(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 (res.Data != null && res.Success) { 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(); } } @@ -296,12 +313,29 @@ namespace qtc_net_client_2 var res = await _apiService.GetUserInformationAsync(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 (res.Data != null && res.Success) { 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(); } } diff --git a/qtc-net-client-2/Forms/Profile.cs b/qtc-net-client-2/Forms/Profile.cs index 1080ea6..6796347 100644 --- a/qtc-net-client-2/Forms/Profile.cs +++ b/qtc-net-client-2/Forms/Profile.cs @@ -1,24 +1,25 @@ -using QtCNETAPI.Dtos.User; -using QtCNETAPI.Services.ApiService; +using qtc_net_client_2.ClientModel; +using qtc_net_client_2.Properties; +using qtc_net_client_2.Services; +using QtCNETAPI.Dtos.User; using QtCNETAPI.Models; +using QtCNETAPI.Schema; +using QtCNETAPI.Services.ApiService; +using QtCNETAPI.Services.GatewayService; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; +using System.Drawing.Design; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; 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 { @@ -29,13 +30,16 @@ namespace qtc_net_client_2.Forms private IGatewayService _gatewayService; private ServiceResponse? pfpRes; + byte[]? cosmeticRes; + private List contactsList; - public Profile(UserInformationDto userInfo, ServiceResponse? pfp, List contacts, IApiService apiService, IGatewayService gatewayService) + public Profile(UserInformationDto userInfo, ServiceResponse? pfp, List contacts, IApiService apiService, IGatewayService gatewayService, byte[]? cosmetic = null) { _userInformationDto = userInfo; _apiService = apiService; _gatewayService = gatewayService; pfpRes = pfp; + cosmeticRes = cosmetic; contactsList = contacts; InitializeComponent(); @@ -75,6 +79,12 @@ namespace qtc_net_client_2.Forms break; } + if(cosmeticRes != null) + { + using var ms = new MemoryStream(cosmeticRes); + CombineProfileImageWithCosmetic(pbUserPfp.Image, new Bitmap(ms)); + } + if (_userInformationDto.ProfileCosmeticId != 0) { var res = await _apiService.GetStoreItem(_userInformationDto.ProfileCosmeticId); @@ -86,7 +96,7 @@ namespace qtc_net_client_2.Forms { using (var stream = await response.Content.ReadAsStreamAsync()) { - CombineProfileImageWithCosmetic(pbUserPfp.Image, new Bitmap(stream)); + } response.Dispose(); }