@@ -43,7 +43,28 @@ public partial class MainWindow : Window
43
43
public static readonly string projectNameFile = "ProjectName.txt" ;
44
44
public static string preferredVersion = null ;
45
45
public 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
+ }
47
68
48
69
const string contextRegRoot = "Software\\ Classes\\ Directory\\ Background\\ shell" ;
49
70
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro" ;
@@ -2131,7 +2152,7 @@ void CreateNewEmptyProject(string targetFolder = null)
2131
2152
Console . WriteLine ( "Create project " + NewProject . newVersion + " : " + rootFolder ) ;
2132
2153
if ( string . IsNullOrEmpty ( rootFolder ) ) return ;
2133
2154
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 ) ;
2135
2156
2136
2157
// add to list (just in case new project fails to start, then folder is already generated..)
2137
2158
if ( p != null ) AddNewProjectToList ( p ) ;
@@ -2154,7 +2175,7 @@ void CreateNewEmptyProject(string targetFolder = null)
2154
2175
{
2155
2176
newVersion = GetSelectedUnity ( ) . Version == null ? preferredVersion : GetSelectedUnity ( ) . Version ;
2156
2177
}
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 ) ;
2158
2179
2159
2180
if ( p != null ) AddNewProjectToList ( p ) ;
2160
2181
}
@@ -3472,16 +3493,31 @@ public int Compare(Object a, Object b)
3472
3493
3473
3494
private void btnExploreScriptsFolder_Click ( object sender , RoutedEventArgs e )
3474
3495
{
3475
- if ( Tools . LaunchExplorer ( Path . GetDirectoryName ( initScriptFileFullPath ) ) == false )
3496
+ // handle exe vs msix locations
3497
+ try
3476
3498
{
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 ) )
3480
3502
{
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
+ }
3483
3515
}
3484
3516
}
3517
+ catch ( Exception ex )
3518
+ {
3519
+ Console . WriteLine ( "Failed to open folder: " + ex . Message ) ;
3520
+ }
3485
3521
}
3486
3522
3487
3523
private void txtCustomInitFileURL_PreviewKeyDown ( object sender , KeyEventArgs e )
@@ -3823,7 +3859,7 @@ private void tabControl_PreviewKeyDown(object sender, KeyEventArgs e)
3823
3859
3824
3860
private void btnFetchLatestInitScript_Click ( object sender , RoutedEventArgs e )
3825
3861
{
3826
- Tools . DownloadInitScript ( initScriptFileFullPath , txtCustomInitFileURL . Text ) ;
3862
+ Tools . DownloadInitScript ( InitScriptFileFullPath , txtCustomInitFileURL . Text ) ;
3827
3863
}
3828
3864
3829
3865
private void btnHubLogs_Click ( object sender , RoutedEventArgs e )
@@ -3910,26 +3946,23 @@ private void OnPipeConnection(IAsyncResult result)
3910
3946
3911
3947
private void CheckCustomIcon ( )
3912
3948
{
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" ) ;
3915
3955
3916
3956
if ( File . Exists ( customIconPath ) )
3917
3957
{
3918
3958
try
3919
3959
{
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 ) )
3922
3961
{
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 ( ) ) ;
3931
3964
IconImage . Source = this . Icon ;
3932
- // tray icon
3965
+ // Tray icon
3933
3966
notifyIcon . Icon = new Icon ( customIconPath ) ;
3934
3967
}
3935
3968
}
@@ -3939,13 +3972,14 @@ private void CheckCustomIcon()
3939
3972
Debug . WriteLine ( $ "Failed to load custom icon: { ex . Message } ") ;
3940
3973
}
3941
3974
}
3942
- else // no custom icon found
3975
+ else
3943
3976
{
3977
+ // Fallback to default embedded icon
3944
3978
notifyIcon . Icon = new Icon ( Application . GetResourceStream ( new Uri ( "pack://application:,,,/Images/icon.ico" ) ) . Stream ) ;
3945
- //Debug.WriteLine("Custom icon not found. Using default.");
3946
3979
}
3947
3980
}
3948
3981
3982
+
3949
3983
private void chkCheckSRP_Checked ( object sender , RoutedEventArgs e )
3950
3984
{
3951
3985
if ( this . IsActive == false ) return ; // dont run code on window init
0 commit comments