This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
forked from gitextensions/gitextensions
/
FormFixHome.cs
137 lines (120 loc) · 6.05 KB
/
FormFixHome.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using System;
using System.IO;
using System.Windows.Forms;
using GitCommands;
namespace GitUI
{
public partial class FormFixHome : GitExtensionsForm
{
public static void CheckHomePath()
{
bool fixHome = false;
GitCommandHelpers.SetEnvironmentVariable();
if (!Directory.Exists(Environment.GetEnvironmentVariable("HOME")) ||
string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")))
{
fixHome = true;
}
else
{
//This is bad... or... it is the first time any git action has taken place.
if (!File.Exists(Environment.GetEnvironmentVariable("HOME") + "\\.gitconfig"))
{
//If there is a .gitconfig file in any of the obvious places, we can make
//a suggestion for HOME that is probably better then the current HOME
if (File.Exists(Environment.GetEnvironmentVariable("HOME", EnvironmentVariableTarget.User) + "\\.gitconfig") ||
File.Exists(Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH") + "\\.gitconfig") ||
File.Exists(Environment.GetEnvironmentVariable("USERPROFILE") + "\\.gitconfig"))
{
fixHome = true;
}
}
}
if (fixHome)
{
if (MessageBox.Show("The environment variable HOME does not point to a directory that contains the global git config file:" + Environment.NewLine +
"\"" + Environment.GetEnvironmentVariable("HOME") + "\"" + Environment.NewLine + Environment.NewLine +
"Do you want Git Extensions to help locate the correct folder?", "Global config", MessageBoxButtons.YesNo) == DialogResult.Yes)
new FormFixHome().ShowDialog();
}
}
public FormFixHome()
{
InitializeComponent(); Translate();
}
protected override void OnLoad(EventArgs e)
{
LoadSettings();
defaultHome.Text = string.Format(defaultHome.Text + " ({0})", GitCommandHelpers.GetDefaultHomeDir());
userprofileHome.Text = string.Format(userprofileHome.Text + " ({0})", Environment.GetEnvironmentVariable("USERPROFILE"));
}
private void LoadSettings()
{
if (!string.IsNullOrEmpty(Settings.CustomHomeDir))
{
defaultHome.Checked = userprofileHome.Checked = false;
otherHome.Checked = true;
otherHomeDir.Text = Settings.CustomHomeDir;
}
else if (Settings.UserProfileHomeDir)
{
defaultHome.Checked = otherHome.Checked = false;
userprofileHome.Checked = true;
}
else
{
userprofileHome.Checked = otherHome.Checked = false;
defaultHome.Checked = true;
}
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME", EnvironmentVariableTarget.User)) && File.Exists(Environment.GetEnvironmentVariable("HOME", EnvironmentVariableTarget.User) + "\\.gitconfig"))
{
MessageBox.Show("Located .gitconfig in %HOME% (" + Environment.GetEnvironmentVariable("HOME", EnvironmentVariableTarget.User) + "). This setting has been chosen automatically.");
defaultHome.Checked = true;
}
else
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH")) && File.Exists(Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH") + "\\.gitconfig"))
{
MessageBox.Show("Located .gitconfig in %HOMEDRIVE%%HOMEPATH% (" + Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH") + "). This setting has been chosen automatically.");
defaultHome.Checked = true;
}
else
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("USERPROFILE")) && File.Exists(Environment.GetEnvironmentVariable("USERPROFILE") + "\\.gitconfig"))
{
MessageBox.Show("Located .gitconfig in %USERPROFILE% (" + Environment.GetEnvironmentVariable("USERPROFILE") + "). This setting has been chosen automatically.");
userprofileHome.Checked = true;
}
}
private void ok_Click(object sender, EventArgs e)
{
if (otherHome.Checked)
{
if (string.IsNullOrEmpty(otherHomeDir.Text))
{
MessageBox.Show("Please enter a HOME directory.");
return;
}
Settings.CustomHomeDir = otherHomeDir.Text;
}
else
Settings.CustomHomeDir = "";
Settings.UserProfileHomeDir = userprofileHome.Checked;
GitCommandHelpers.SetEnvironmentVariable(true);
if (!Directory.Exists(Environment.GetEnvironmentVariable("HOME")) || string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")))
{
MessageBox.Show("The environment variable HOME point to a directory that is not accessible:" + Environment.NewLine +
"\"" + Environment.GetEnvironmentVariable("HOME") + "\"");
return;
}
Close();
}
private void otherHomeBrowse_Click(object sender, EventArgs e)
{
FolderBrowserDialog browseDialog = new FolderBrowserDialog();
browseDialog.SelectedPath = Environment.GetEnvironmentVariable("USERPROFILE");
if (browseDialog.ShowDialog() == DialogResult.OK)
{
otherHomeDir.Text = browseDialog.SelectedPath;
}
}
}
}