33using Avalonia . Input . Platform ;
44using Avalonia . Layout ;
55using Avalonia . Media ;
6+ using Avalonia . Platform . Storage ;
67using UniGetUI . Avalonia . Infrastructure ;
78using UniGetUI . Avalonia . ViewModels ;
89using UniGetUI . Avalonia . ViewModels . Pages . SettingsPages ;
@@ -78,7 +79,7 @@ private void BuildPage()
7879
7980 var execHint = new TextBlock
8081 {
81- Text = CoreTools . Translate ( "Not finding the file you are looking for? Make sure it has been added to path ." ) ,
82+ Text = CoreTools . Translate ( "Not finding the file you are looking for? Browse to it or make sure it has been added to PATH ." ) ,
8283 FontSize = 12 ,
8384 FontWeight = FontWeight . SemiBold ,
8485 Opacity = 0.7 ,
@@ -90,14 +91,21 @@ private void BuildPage()
9091 var execCombo = new ComboBox { HorizontalAlignment = HorizontalAlignment . Stretch } ;
9192 AutomationProperties . SetName ( execCombo , CoreTools . Translate ( "Select the executable to be used. The following list shows the executables found by UniGetUI" ) ) ;
9293 foreach ( var path in manager . FindCandidateExecutableFiles ( ) )
93- execCombo . Items . Add ( path ) ;
94+ AddExecutablePathItem ( execCombo , path ) ;
9495
9596 string savedPath = CoreSettings . GetDictionaryItem < string , string > ( CoreSettings . K . ManagerPaths , manager . Name ) ?? "" ;
97+ if ( ! string . IsNullOrEmpty ( savedPath ) && File . Exists ( savedPath ) )
98+ AddExecutablePathItem ( execCombo , savedPath ) ;
9699 if ( string . IsNullOrEmpty ( savedPath ) )
97100 {
98101 var ( found , path ) = manager . GetExecutableFile ( ) ;
99102 savedPath = found ? path : "" ;
100103 }
104+ else if ( ! File . Exists ( savedPath ) )
105+ {
106+ var ( found , path ) = manager . GetExecutableFile ( ) ;
107+ savedPath = found ? path : "" ;
108+ }
101109 execCombo . SelectedItem = savedPath ;
102110 execCombo . IsEnabled = customPathsAllowed ;
103111 execCombo . SelectionChanged += ( s , _ ) =>
@@ -106,9 +114,37 @@ private void BuildPage()
106114 ViewModel . OnExecutableSelected ( selected ) ;
107115 } ;
108116 Grid . SetRow ( execCombo , 1 ) ;
109- Grid . SetColumnSpan ( execCombo , 2 ) ;
117+ Grid . SetColumn ( execCombo , 0 ) ;
110118 execGrid . Children . Add ( execCombo ) ;
111119
120+ var browseExecutableButton = new Button
121+ {
122+ Content = CoreTools . Translate ( "Browse..." ) ,
123+ IsEnabled = customPathsAllowed ,
124+ Margin = new Thickness ( 8 , 0 , 0 , 0 ) ,
125+ } ;
126+ browseExecutableButton . Click += async ( _ , _ ) =>
127+ {
128+ if ( TopLevel . GetTopLevel ( this ) is not { } topLevel ) return ;
129+ var files = await topLevel . StorageProvider . OpenFilePickerAsync (
130+ new FilePickerOpenOptions
131+ {
132+ AllowMultiple = false ,
133+ Title = CoreTools . Translate ( "Select executable" ) ,
134+ FileTypeFilter = GetExecutableFileTypeFilter ( ) ,
135+ } ) ;
136+ if ( files is not [ { } file ] ) return ;
137+
138+ string ? path = file . TryGetLocalPath ( ) ;
139+ if ( string . IsNullOrWhiteSpace ( path ) ) return ;
140+
141+ AddExecutablePathItem ( execCombo , path ) ;
142+ execCombo . SelectedItem = path ;
143+ } ;
144+ Grid . SetRow ( browseExecutableButton , 1 ) ;
145+ Grid . SetColumn ( browseExecutableButton , 1 ) ;
146+ execGrid . Children . Add ( browseExecutableButton ) ;
147+
112148 if ( ! customPathsAllowed )
113149 {
114150 var securityWarning = new TextBlock
@@ -342,6 +378,34 @@ private void BuildPage()
342378 }
343379 }
344380
381+ private static IReadOnlyList < FilePickerFileType > GetExecutableFileTypeFilter ( )
382+ {
383+ if ( ! OperatingSystem . IsWindows ( ) )
384+ {
385+ return [ new FilePickerFileType ( CoreTools . Translate ( "All files" ) ) { Patterns = [ "*" ] } ] ;
386+ }
387+
388+ return
389+ [
390+ new FilePickerFileType ( CoreTools . Translate ( "Executable" ) ) { Patterns = [ "*.exe" ] } ,
391+ new FilePickerFileType ( CoreTools . Translate ( "All files" ) ) { Patterns = [ "*" ] } ,
392+ ] ;
393+ }
394+
395+ private static void AddExecutablePathItem ( ComboBox comboBox , string path )
396+ {
397+ if ( string . IsNullOrWhiteSpace ( path ) )
398+ return ;
399+
400+ foreach ( object ? item in comboBox . Items )
401+ {
402+ if ( string . Equals ( item ? . ToString ( ) , path , StringComparison . OrdinalIgnoreCase ) )
403+ return ;
404+ }
405+
406+ comboBox . Items . Add ( path ) ;
407+ }
408+
345409 private void BuildExtraControls ( CheckboxCard_Dict disableNotifsCard )
346410 {
347411 ExtraControls . Children . Clear ( ) ;
0 commit comments