@@ -26,11 +26,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2626using System . IO ;
2727using System . Linq ;
2828using System . Reflection ;
29+ using System . Security ;
2930using System . Text ;
3031using System . Windows . Forms ;
3132using System . Xml . Linq ;
3233using GitAutoUpdateGUI . Properties ;
33- using NamespaceYouAreUsing ;
34+ using Tools ;
3435
3536namespace GitAutoUpdateGUI
3637{
@@ -1448,7 +1449,60 @@ private void buttonAddGitBinaryToWinPath_Click(object sender, EventArgs e)
14481449 // Path = %path% + textBoxGitBashBinariesPath.text minus "git.exe"
14491450 // TODO add implementation code
14501451 var winPath = Environment . GetEnvironmentVariable ( "Path" , EnvironmentVariableTarget . Machine ) ;
1451- MessageBox . Show ( "Here is your Windows Path variable: " + winPath ) ;
1452+ #if Debug
1453+ MessageBox . Show ( "Here is your current Windows Path variable: " + winPath ) ;
1454+ #endif
1455+ // verification of GitBash in textBoxGitBashBinariesPath
1456+ if ( textBoxGitBashBinariesPath . Text == string . Empty )
1457+ {
1458+ DisplayMessageOk ( Translate ( "The GitBash directory path is empty" ) +
1459+ Period + Crlf + Translate ( "Enter a correct path" ) ,
1460+ Translate ( "Directory empty" ) , MessageBoxButtons . OK ) ;
1461+ Logger . Add ( textBoxLog , Translate ( "The GitBash directory path is empty" ) ) ;
1462+ return ;
1463+ }
1464+
1465+ if ( ! File . Exists ( textBoxGitBashBinariesPath . Text ) )
1466+ {
1467+ DisplayMessageOk ( Translate ( "The executable GitBash directory path doesn't exist" ) +
1468+ Period + Crlf + Translate ( "Enter a correct path" ) ,
1469+ Translate ( "Wrong Directory" ) , MessageBoxButtons . OK ) ;
1470+ Logger . Add ( textBoxLog , Translate ( "The executable GitBash directory path doesn't exist" ) ) ;
1471+ return ;
1472+ }
1473+
1474+ winPath += Punctuation . SemiColon + Punctuation . Backslash +
1475+ textBoxGitBashBinariesPath . Text . Substring ( 0 , textBoxGitBashBinariesPath . Text . Length - 8 ) ;
1476+ #if Debug
1477+ MessageBox . Show ( "Here is your modifed Windows Path variable: " + winPath ) ;
1478+ #endif
1479+ bool additionSuccessful = false ;
1480+ try
1481+ {
1482+ Environment . SetEnvironmentVariable ( "Path" , winPath , EnvironmentVariableTarget . Machine ) ;
1483+ additionSuccessful = true ;
1484+ }
1485+ catch ( SecurityException securityException )
1486+ {
1487+ additionSuccessful = false ;
1488+ Logger . Add ( textBoxLog , Translate ( "There was a security error, probably lack of rights" ) + Punctuation . Colon +
1489+ Punctuation . OneSpace + securityException . Message ) ;
1490+ }
1491+ catch ( Exception exception )
1492+ {
1493+ additionSuccessful = false ;
1494+ Logger . Add ( textBoxLog , Translate ( "There was an error" ) + Punctuation . Colon +
1495+ Punctuation . OneSpace + exception . Message ) ;
1496+ }
1497+
1498+ if ( additionSuccessful )
1499+ {
1500+ DisplayMessageOk ( Translate ( "" ) , Translate ( "" ) , MessageBoxButtons . OK ) ;
1501+ }
1502+ else
1503+ {
1504+ DisplayMessageOk ( Translate ( "" ) , Translate ( "" ) , MessageBoxButtons . OK ) ;
1505+ }
14521506 }
14531507 }
14541508}
0 commit comments