mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-04 15:15:01 +00:00
AboutThisProgram.cs - Made setting developer icons and names thread safe
This commit is contained in:
51
PCK-Studio/Classes/Extentions/ControlExtensions.cs
Normal file
51
PCK-Studio/Classes/Extentions/ControlExtensions.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PckStudio.Classes.Extentions
|
||||
{
|
||||
internal static class ControlExtensions
|
||||
{
|
||||
private delegate void SetPropertyThreadSafeDelegate<TResult>(
|
||||
Control @this,
|
||||
Expression<Func<TResult>> property,
|
||||
TResult value);
|
||||
|
||||
public static void SetPropertyThreadSafe<TResult>(
|
||||
this Control @this,
|
||||
Expression<Func<TResult>> property,
|
||||
TResult value)
|
||||
{
|
||||
var propertyInfo = (property.Body as MemberExpression).Member
|
||||
as PropertyInfo;
|
||||
|
||||
if (propertyInfo == null ||
|
||||
!@this.GetType().IsSubclassOf(propertyInfo.ReflectedType) ||
|
||||
@this.GetType().GetProperty(
|
||||
propertyInfo.Name,
|
||||
propertyInfo.PropertyType) == null)
|
||||
{
|
||||
throw new ArgumentException("The lambda expression 'property' must reference a valid property on this Control.");
|
||||
}
|
||||
|
||||
if (@this.InvokeRequired)
|
||||
{
|
||||
@this.Invoke(new SetPropertyThreadSafeDelegate<TResult>(SetPropertyThreadSafe), @this, property, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
@this.GetType().InvokeMember(
|
||||
propertyInfo.Name,
|
||||
BindingFlags.SetProperty,
|
||||
null,
|
||||
@this,
|
||||
new object[] { value });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,16 +38,20 @@ namespace PckStudio
|
||||
// TODO: check if avatar has changed and only acquire info once
|
||||
var devs = await AcquireDeveloperUserInfoAsync("PhoenixARC", "MattN-L", "EternalModz", "NessieHax");
|
||||
|
||||
phoenixarcPictureBox.Image = ImageExtentions.ImageFromUrl(devs[0].AvatarUrl);
|
||||
phoenixarcPictureBox.SetPropertyThreadSafe(() => phoenixarcPictureBox.Image, ImageExtentions.ImageFromUrl(devs[0].AvatarUrl));
|
||||
phoenixarcPictureBox.SetPropertyThreadSafe(() => phoenixarcPictureBox.Text, devs[0].Name);
|
||||
phoenixarcGitHubButton.Click += (sender, e) => Process.Start(devs[0].HtmlUrl);
|
||||
|
||||
mattNLPictureBox.Image = ImageExtentions.ImageFromUrl(devs[1].AvatarUrl);
|
||||
mattNLPictureBox.SetPropertyThreadSafe(() => mattNLPictureBox.Image, ImageExtentions.ImageFromUrl(devs[1].AvatarUrl));
|
||||
mattNLPictureBox.SetPropertyThreadSafe(() => mattNLPictureBox.Text, devs[1].Name);
|
||||
mattNLGitHubButton.Click += (sender, e) => Process.Start(devs[1].HtmlUrl);
|
||||
|
||||
eternalModzPictureBox.Image = ImageExtentions.ImageFromUrl(devs[2].AvatarUrl);
|
||||
eternalModzPictureBox.SetPropertyThreadSafe(() => eternalModzPictureBox.Image, ImageExtentions.ImageFromUrl(devs[2].AvatarUrl));
|
||||
eternalModzPictureBox.SetPropertyThreadSafe(() => eternalModzPictureBox.Text, devs[2].Name);
|
||||
eternalModzGitHubButton.Click += (sender, e) => Process.Start(devs[2].HtmlUrl);
|
||||
|
||||
mikuPictureBox.Image = ImageExtentions.ImageFromUrl(devs[3].AvatarUrl);
|
||||
mikuPictureBox.SetPropertyThreadSafe(() => mikuPictureBox.Image, ImageExtentions.ImageFromUrl(devs[3].AvatarUrl));
|
||||
mikuPictureBox.SetPropertyThreadSafe(() => mikuLabel.Text, devs[3].Name);
|
||||
mikuGitHubButton.Click += (sender, e) => Process.Start(devs[3].HtmlUrl);
|
||||
});
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -170,6 +170,7 @@
|
||||
<Compile Include="Classes\API\PCKCenter\PCKCollections.cs" />
|
||||
<Compile Include="Classes\API\PCKCenter\PCKCollectionsLocal.cs" />
|
||||
<Compile Include="Classes\API\PCKCenter\SaveLocalJSON.cs" />
|
||||
<Compile Include="Classes\Extentions\ControlExtensions.cs" />
|
||||
<Compile Include="Classes\Extentions\EnumerableExtentions.cs" />
|
||||
<Compile Include="Classes\FileTypes\CSMBFile.cs" />
|
||||
<Compile Include="Classes\FileTypes\PCKAudioFile.cs" />
|
||||
|
||||
Reference in New Issue
Block a user