@@ -126,41 +126,46 @@ public virtual void Initialize()
126126
127127 public Tuple < bool , string > GetExecutableFile ( )
128128 {
129- var AvailablePaths = _findCandidateExecutableFiles ( ) ;
130- string ? Path = Settings . GetDictionaryItem < string , string > ( Settings . K . ManagerPaths , Name ) ;
131- if ( ! SecureSettings . Get ( SecureSettings . K . AllowCustomManagerPaths ) )
129+ var candidates = FindCandidateExecutableFiles ( ) ;
130+ if ( candidates . Count == 0 )
132131 {
133- if ( Path != null )
134- {
135- Logger . Info ( $ "Available path { Path } found but not used as AllowCustomManagerPaths is turned off") ;
136- }
137- Path = null ;
132+ // No paths were found
133+ return new ( false , "" ) ;
138134 }
139135
140- if ( AvailablePaths . Count == 0 )
136+ // If custom package manager paths are DISABLED, get the first one (as old UniGetUI did) and return it.
137+ if ( ! SecureSettings . Get ( SecureSettings . K . AllowCustomManagerPaths ) )
141138 {
142- Logger . Warn ( "No available paths found for manager " + Name ) ;
143-
144- if ( File . Exists ( Path ) && Path != null ) Logger . Info ( "Using stored path " + Path ) ;
145- else Logger . Error ( "Stored path " + Path + " is invalid" ) ;
146- return new Tuple < bool , string > ( File . Exists ( Path ) && Path != null , Path ?? "" ) ;
147- }
148- else if ( Path == null && File . Exists ( AvailablePaths . ElementAt ( 0 ) ) )
149- {
150- Logger . Info ( "Stored path for " + Name + " is missing, using AvailablePaths[0]: " + AvailablePaths . ElementAt ( 0 ) ) ;
151- return new Tuple < bool , string > ( true , AvailablePaths . ElementAt ( 0 ) ) ;
139+ return new ( true , candidates [ 0 ] ) ;
152140 }
153141 else
154142 {
155- if ( File . Exists ( Path ) && Path != null )
143+ string ? exeSelection = Settings . GetDictionaryItem < string , string > ( Settings . K . ManagerPaths , Name ) ;
144+ // If there is no executable selection for this package manager
145+ if ( string . IsNullOrEmpty ( exeSelection ) )
156146 {
157- Logger . Info ( "Using stored path " + Path ) ;
158- return new Tuple < bool , string > ( true , Path ) ;
147+ return new ( true , candidates [ 0 ] ) ;
148+ }
149+ else if ( ! File . Exists ( exeSelection ) )
150+ {
151+ Logger . Error ( $ "The selected executable path { exeSelection } for manager { Name } is not valid, the default will be used...") ;
152+ return new ( true , candidates [ 0 ] ) ;
159153 }
160- }
161154
162- Logger . Info ( "No suitable path found for " + Name ) ;
163- return new Tuple < bool , string > ( false , "" ) ;
155+ // While technically executables that are not in the path should work,
156+ // since detection of executables will be performed in the path only, it is more consistent
157+ // to throw an error when a non-path executable is used.
158+ if ( candidates . Select ( x => x . ToLower ( ) ) . Contains ( exeSelection . ToLower ( ) ) )
159+ {
160+ return new ( true , exeSelection ) ;
161+ }
162+ else
163+ {
164+ Logger . Error ( $ "The selected executable path { exeSelection } for manager { Name } was not found in path, the default will be used...") ;
165+ return new ( true , candidates [ 0 ] ) ;
166+ }
167+
168+ }
164169 }
165170
166171 /// <summary>
0 commit comments