Skip to content

Commit 2a94ce6

Browse files
committed
Add code for adding GitBash binary path to Windows path variable
1 parent 3fb8cf8 commit 2a94ce6

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

GitAutoUpdateGUI/FormMain.cs

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2626
using System.IO;
2727
using System.Linq;
2828
using System.Reflection;
29+
using System.Security;
2930
using System.Text;
3031
using System.Windows.Forms;
3132
using System.Xml.Linq;
3233
using GitAutoUpdateGUI.Properties;
33-
using NamespaceYouAreUsing;
34+
using Tools;
3435

3536
namespace 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
}

GitAutoUpdateGUI/Punctuation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
*/
2020
using System;
2121

22-
namespace NamespaceYouAreUsing
22+
namespace Tools
2323
{
2424
public static class Punctuation
2525
{
2626
public const string Comma = ",";
2727
public const string Colon = ":";
28+
public const string SemiColon = ";";
2829
public const string OneSpace = " ";
2930
public const string Dash = "-";
3031
public const string UnderScore = "_";

GitAutoUpdateGUI/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Punctuation" version="1.2.0" targetFramework="net45" />
3+
<package id="Punctuation" version="1.3.0" targetFramework="net45" />
44
</packages>

0 commit comments

Comments
 (0)