@@ -16,6 +16,8 @@ namespace BridgeVs.Helper.Settings
1616 [ CLSCompliant ( false ) , ComVisible ( true ) ]
1717 public sealed class PackageSettings : DialogPage
1818 {
19+
20+ private const string ErrorMessage = "Please insert a valid path to LINQPad" ;
1921 [ Category ( "LINQPad" ) ]
2022 [ DisplayName ( "Installation Path" ) ]
2123 [ Description ( "Sets the path to the LINQPad exe" ) ]
@@ -34,25 +36,33 @@ public string LINQPadInstallationPath
3436 var dte = ( DTE ) GetService ( typeof ( SDTE ) ) ;
3537 if ( dte != null )
3638 {
37- if ( string . IsNullOrEmpty ( value ) )
38- {
39- MessageBox . Show ( "Please insert a valid path to LINQPad" ) ;
40- return ;
41- }
42- bool possiblePath = value . IndexOfAny ( Path . GetInvalidPathChars ( ) ) == - 1 ;
39+ bool isPathInValid = string . IsNullOrEmpty ( value )
40+ || value . IndexOfAny ( Path . GetInvalidPathChars ( ) ) != - 1 ;
4341
44- if ( ! possiblePath )
42+ if ( isPathInValid )
4543 {
46- MessageBox . Show ( "Please insert a valid path to LINQPad" ) ;
44+ MessageBox . Show ( ErrorMessage ) ;
4745 return ;
4846 }
4947
50- if ( ! Directory . GetFiles ( value , "*.exe" , SearchOption . TopDirectoryOnly ) . Any ( p=> p . Contains ( "LINQPad.exe" ) ) )
48+ //check the inserted path is a valid directory that contains linqpad.exe
49+ //if the inserted value is a file then check for its directory otherwise a directory
50+ //has been inserted
51+ var insertedDirectory = File . Exists ( value ) ? Path . GetDirectoryName ( value ) : value ;
52+
53+ var isInvalidDirectory =
54+ ! Directory . Exists ( insertedDirectory )
55+ || ! Directory . GetFiles ( insertedDirectory , "*.exe" , SearchOption . TopDirectoryOnly )
56+ . Any ( p => p . Contains ( "LINQPad.exe" ) ) ;
57+
58+ if ( isInvalidDirectory )
5159 {
52- MessageBox . Show ( "Please insert a valid path to LINQPad" ) ;
60+ MessageBox . Show ( ErrorMessage ) ;
5361 return ;
5462 }
55- CommonRegistryConfigurations . SetLINQPadInstallationPath ( dte . Version , value ) ;
63+
64+ string filterInsertedDirectory = Path . GetFullPath ( insertedDirectory ) ;
65+ CommonRegistryConfigurations . SetLINQPadInstallationPath ( dte . Version , filterInsertedDirectory ) ;
5666 }
5767 }
5868 }
0 commit comments