1818using System . Windows . Controls ;
1919using System . Windows . Data ;
2020using System . Windows . Input ;
21+ using System . Windows . Interop ;
2122using System . Windows . Media ;
23+ using System . Windows . Media . Imaging ;
2224using System . Windows . Shell ;
2325using UnityLauncherPro . Data ;
2426using UnityLauncherPro . Helpers ;
@@ -45,7 +47,7 @@ public partial class MainWindow : Window
4547const string githubURL = "https://github.com/unitycoder/UnityLauncherPro" ;
4648const string resourcesURL = "https://github.com/unitycoder/UnityResources" ;
4749const string defaultAdbLogCatArgs = "-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color" ;
48- System . Windows . Forms . NotifyIcon notifyIcon ;
50+ System . Windows . Forms . NotifyIcon notifyIcon = new System . Windows . Forms . NotifyIcon ( ) ;
4951
5052UnityVersion [ ] updatesSource ;
5153public static List < string > updatesAsStrings = new List < string > ( ) ;
@@ -110,6 +112,8 @@ void Init()
110112{
111113lblVersion . Content = "Build: " + Version . Stamp ;
112114}
115+
116+ CheckCustomIcon ( ) ;
113117}
114118
115119void Start ( )
@@ -160,8 +164,6 @@ void Start()
160164gridBuildReportData . Items . Clear ( ) ;
161165
162166// build notifyicon (using windows.forms)
163- notifyIcon = new System . Windows . Forms . NotifyIcon ( ) ;
164- notifyIcon . Icon = new Icon ( Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
165167notifyIcon . MouseClick += new System . Windows . Forms . MouseEventHandler ( NotifyIcon_MouseClick ) ;
166168
167169// get original colors
@@ -3756,7 +3758,43 @@ private void OnPipeConnection(IAsyncResult result)
37563758}
37573759}
37583760
3761+ private void CheckCustomIcon ( )
3762+ {
3763+ string customIconPath = Path . Combine ( Environment . CurrentDirectory , "icon.ico" ) ;
3764+ Console . WriteLine ( customIconPath ) ;
37593765
3766+ if ( File . Exists ( customIconPath ) )
3767+ {
3768+ try
3769+ {
3770+ // Load the custom icon using System.Drawing.Icon
3771+ using ( var icon = new System . Drawing . Icon ( customIconPath ) )
3772+ {
3773+ // Convert the icon to a BitmapSource and assign it to the WPF window's Icon property
3774+ this . Icon = Imaging . CreateBitmapSourceFromHIcon (
3775+ icon . Handle ,
3776+ Int32Rect . Empty ,
3777+ BitmapSizeOptions . FromEmptyOptions ( ) // Use BitmapSizeOptions here
3778+ ) ;
3779+
3780+ // window icon
3781+ IconImage . Source = this . Icon ;
3782+ // tray icon
3783+ notifyIcon . Icon = new Icon ( customIconPath ) ;
3784+ }
3785+ }
3786+ catch ( Exception ex )
3787+ {
3788+ SetStatus ( "Failed to load custom icon: " + ex . Message , MessageType . Warning ) ;
3789+ Debug . WriteLine ( $ "Failed to load custom icon:{ ex . Message } ") ;
3790+ }
3791+ }
3792+ else // no custom icon found
3793+ {
3794+ notifyIcon . Icon = new Icon ( Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
3795+ //Debug.WriteLine("Custom icon not found. Using default.");
3796+ }
3797+ }
37603798//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
37613799//{
37623800// var proj = GetSelectedProject();