@@ -43,7 +43,28 @@ public partial class MainWindow : Window
4343public static readonly string projectNameFile = "ProjectName.txt" ;
4444public static string preferredVersion = null ;
4545public static int projectNameSetting = 0 ; // 0 = folder or ProjectName.txt if exists, 1=ProductName
46- public static readonly string initScriptFileFullPath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Scripts" , "InitializeProject.cs" ) ;
46+
47+ // required setup for exe and msix builds
48+ public static string InitScriptFileFullPath
49+ {
50+ get
51+ {
52+ string basePath ;
53+ if ( AppDomain . CurrentDomain . BaseDirectory . Contains ( @"\WindowsApps\" ) )
54+ {
55+ // MSIX: Use user-writable folder
56+ basePath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "UnityLauncherPro" , "Scripts" ) ;
57+ }
58+ else
59+ {
60+ // EXE: Use app folder
61+ basePath = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , "Scripts" ) ;
62+ }
63+ // Ensure directory exists
64+ if ( ! Directory . Exists ( basePath ) ) Directory . CreateDirectory ( basePath ) ;
65+ return Path . Combine ( basePath , "InitializeProject.cs" ) ;
66+ }
67+ }
4768
4869const string contextRegRoot = "Software\\ Classes\\ Directory\\ Background\\ shell" ;
4970const string githubURL = "https://github.com/unitycoder/UnityLauncherPro" ;
@@ -2131,7 +2152,7 @@ void CreateNewEmptyProject(string targetFolder = null)
21312152Console . WriteLine ( "Create project " + NewProject . newVersion + " : " + rootFolder ) ;
21322153if ( string . IsNullOrEmpty ( rootFolder ) ) return ;
21332154
2134- var p = Tools . FastCreateProject ( NewProject . newVersion , rootFolder , NewProject . newProjectName , NewProject . templateZipPath , NewProject . platformsForThisUnity , NewProject . selectedPlatform , ( bool ) chkUseInitScript . IsChecked , initScriptFileFullPath , NewProject . forceDX11 ) ;
2155+ var p = Tools . FastCreateProject ( NewProject . newVersion , rootFolder , NewProject . newProjectName , NewProject . templateZipPath , NewProject . platformsForThisUnity , NewProject . selectedPlatform , ( bool ) chkUseInitScript . IsChecked , InitScriptFileFullPath , NewProject . forceDX11 ) ;
21352156
21362157// add to list (just in case new project fails to start, then folder is already generated..)
21372158if ( p != null ) AddNewProjectToList ( p ) ;
@@ -2154,7 +2175,7 @@ void CreateNewEmptyProject(string targetFolder = null)
21542175{
21552176newVersion = GetSelectedUnity ( ) . Version == null ? preferredVersion : GetSelectedUnity ( ) . Version ;
21562177}
2157- var p = Tools . FastCreateProject ( newVersion , rootFolder , null , null , null , null , ( bool ) chkUseInitScript . IsChecked , initScriptFileFullPath ) ;
2178+ var p = Tools . FastCreateProject ( newVersion , rootFolder , null , null , null , null , ( bool ) chkUseInitScript . IsChecked , InitScriptFileFullPath ) ;
21582179
21592180if ( p != null ) AddNewProjectToList ( p ) ;
21602181}
@@ -3472,16 +3493,31 @@ public int Compare(Object a, Object b)
34723493
34733494private void btnExploreScriptsFolder_Click ( object sender , RoutedEventArgs e )
34743495{
3475- if ( Tools . LaunchExplorer ( Path . GetDirectoryName ( initScriptFileFullPath ) ) == false )
3496+ // handle exe vs msix locations
3497+ try
34763498{
3477- // if failed, open parent folder (probably path was using URL or no scripts yet)
3478- var parentPath = Directory . GetParent ( Path . GetDirectoryName ( initScriptFileFullPath ) ) . FullName ;
3479- if ( Tools . LaunchExplorer ( parentPath ) == false )
3499+ string scriptFolder = Path . GetDirectoryName ( InitScriptFileFullPath ) ;
3500+
3501+ if ( ! Tools . LaunchExplorer ( scriptFolder ) )
34803502{
3481- // if still failed, open exe folder
3482- Tools . LaunchExplorer ( AppDomain . CurrentDomain . BaseDirectory ) ;
3503+ // fallback: try parent of script folder
3504+ string parentPath = Directory . GetParent ( scriptFolder ) ? . FullName ;
3505+
3506+ if ( string . IsNullOrEmpty ( parentPath ) || ! Tools . LaunchExplorer ( parentPath ) )
3507+ {
3508+ // final fallback: show %LOCALAPPDATA% for MSIX, or exe dir for EXE builds
3509+ string fallback = AppDomain . CurrentDomain . BaseDirectory . Contains ( @"\WindowsApps\" )
3510+ ? Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData )
3511+ : AppDomain . CurrentDomain . BaseDirectory ;
3512+
3513+ Tools . LaunchExplorer ( fallback ) ;
3514+ }
34833515}
34843516}
3517+ catch ( Exception ex )
3518+ {
3519+ Console . WriteLine ( "Failed to open folder: " + ex . Message ) ;
3520+ }
34853521}
34863522
34873523private void txtCustomInitFileURL_PreviewKeyDown ( object sender , KeyEventArgs e )
@@ -3823,7 +3859,7 @@ private void tabControl_PreviewKeyDown(object sender, KeyEventArgs e)
38233859
38243860private void btnFetchLatestInitScript_Click ( object sender , RoutedEventArgs e )
38253861{
3826- Tools . DownloadInitScript ( initScriptFileFullPath , txtCustomInitFileURL . Text ) ;
3862+ Tools . DownloadInitScript ( InitScriptFileFullPath , txtCustomInitFileURL . Text ) ;
38273863}
38283864
38293865private void btnHubLogs_Click ( object sender , RoutedEventArgs e )
@@ -3910,26 +3946,23 @@ private void OnPipeConnection(IAsyncResult result)
39103946
39113947private void CheckCustomIcon ( )
39123948{
3913- string customIconPath = Path . Combine ( Environment . CurrentDirectory , "icon.ico" ) ;
3914- //Console.WriteLine(customIconPath);
3949+ // Use app-specific writable folder (same as used for themes/scripts)
3950+ string baseFolder = AppDomain . CurrentDomain . BaseDirectory . Contains ( @"\WindowsApps\" )
3951+ ? Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "UnityLauncherPro" )
3952+ : AppDomain . CurrentDomain . BaseDirectory ;
3953+
3954+ string customIconPath = Path . Combine ( baseFolder , "icon.ico" ) ;
39153955
39163956if ( File . Exists ( customIconPath ) )
39173957{
39183958try
39193959{
3920- // Load the custom icon using System.Drawing.Icon
3921- using ( var icon = new System . Drawing . Icon ( customIconPath ) )
3960+ using ( var icon = new Icon ( customIconPath ) )
39223961{
3923- // Convert the icon to a BitmapSource and assign it to the WPF window's Icon property
3924- this . Icon = Imaging . CreateBitmapSourceFromHIcon (
3925- icon . Handle ,
3926- Int32Rect . Empty ,
3927- BitmapSizeOptions . FromEmptyOptions ( ) // Use BitmapSizeOptions here
3928- ) ;
3929-
3930- // window icon
3962+ // Set WPF window icon
3963+ this . Icon = Imaging . CreateBitmapSourceFromHIcon ( icon . Handle , Int32Rect . Empty , BitmapSizeOptions . FromEmptyOptions ( ) ) ;
39313964IconImage . Source = this . Icon ;
3932- //tray icon
3965+ //Tray icon
39333966notifyIcon . Icon = new Icon ( customIconPath ) ;
39343967}
39353968}
@@ -3939,13 +3972,14 @@ private void CheckCustomIcon()
39393972Debug . WriteLine ( $ "Failed to load custom icon:{ ex . Message } ") ;
39403973}
39413974}
3942- else // no custom icon found
3975+ else
39433976{
3977+ // Fallback to default embedded icon
39443978notifyIcon . Icon = new Icon ( Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
3945- //Debug.WriteLine("Custom icon not found. Using default.");
39463979}
39473980}
39483981
3982+
39493983private void chkCheckSRP_Checked ( object sender , RoutedEventArgs e )
39503984{
39513985if ( this . IsActive == false ) return ; // dont run code on window init