1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseProc.h"
22 #include "SetMainPage.h"
24 #include "PathUtils.h"
25 #include "DirFileEnum.h"
26 #include "GitProgressDlg.h"
27 #include "..\version.h"
28 #include "SetMainPage.h"
30 #include "MessageBox.h"
31 #include "GitForWindows.h"
32 #include "BrowseFolder.h"
34 #include "Libraries.h"
36 IMPLEMENT_DYNAMIC(CSetMainPage
, ISettingsPropPage
)
37 CSetMainPage::CSetMainPage()
38 : ISettingsPropPage(CSetMainPage::IDD
)
39 , m_sMsysGitPath(_T(""))
43 m_regLanguage
= CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
44 CString temp
= CRegString(REG_MSYSGIT_INSTALL
, _T(""), FALSE
, HKEY_LOCAL_MACHINE
);
47 m_regMsysGitPath
= CRegString(REG_MSYSGIT_PATH
,temp
,FALSE
);
49 m_regMsysGitExtranPath
=CRegString(REG_MSYSGIT_EXTRA_PATH
);
51 m_sMsysGitPath
= m_regMsysGitPath
;
52 m_sMsysGitExtranPath
= m_regMsysGitExtranPath
;
54 m_regCheckNewer
= CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE
);
57 CSetMainPage::~CSetMainPage()
61 void CSetMainPage::DoDataExchange(CDataExchange
* pDX
)
63 ISettingsPropPage::DoDataExchange(pDX
);
64 DDX_Control(pDX
, IDC_LANGUAGECOMBO
, m_LanguageCombo
);
65 m_dwLanguage
= (DWORD
)m_LanguageCombo
.GetItemData(m_LanguageCombo
.GetCurSel());
66 DDX_Text(pDX
, IDC_MSYSGIT_PATH
, m_sMsysGitPath
);
67 DDX_Text(pDX
, IDC_MSYSGIT_EXTERN_PATH
, m_sMsysGitExtranPath
);
68 DDX_Check(pDX
, IDC_CHECKNEWERVERSION
, m_bCheckNewer
);
72 BEGIN_MESSAGE_MAP(CSetMainPage
, ISettingsPropPage
)
73 ON_CBN_SELCHANGE(IDC_LANGUAGECOMBO
, OnModified
)
74 // ON_EN_CHANGE(IDC_TEMPEXTENSIONS, OnModified)
75 ON_BN_CLICKED(IDC_CHECKNEWERVERSION
, OnModified
)
76 ON_BN_CLICKED(IDC_CHECKNEWERBUTTON
, OnBnClickedChecknewerbutton
)
77 ON_BN_CLICKED(IDC_SOUNDS
, OnBnClickedSounds
)
78 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE
,OnBrowseDir
)
79 ON_BN_CLICKED(IDC_MSYSGIT_CHECK
,OnCheck
)
80 ON_EN_CHANGE(IDC_MSYSGIT_PATH
, OnMsysGitPathModify
)
81 ON_EN_CHANGE(IDC_MSYSGIT_EXTERN_PATH
, OnModified
)
82 ON_BN_CLICKED(IDC_BUTTON_SHOW_ENV
, &CSetMainPage::OnBnClickedButtonShowEnv
)
83 ON_BN_CLICKED(IDC_CREATELIB
, &CSetMainPage::OnBnClickedCreatelib
)
86 BOOL
CSetMainPage::OnInitDialog()
88 ISettingsPropPage::OnInitDialog();
91 AdjustControlSize(IDC_CHECKNEWERVERSION
);
93 m_dwLanguage
= m_regLanguage
;
94 m_bCheckNewer
= m_regCheckNewer
;
96 m_tooltips
.Create(this);
97 m_tooltips
.AddTool(IDC_MSYSGIT_PATH
,IDS_MSYSGIT_PATH_TT
);
98 m_tooltips
.AddTool(IDC_CHECKNEWERVERSION
, IDS_SETTINGS_CHECKNEWER_TT
);
99 m_tooltips
.AddTool(IDC_CREATELIB
, IDS_SETTINGS_CREATELIB_TT
);
101 GetDlgItem(IDC_CREATELIB
)->EnableWindow(SysInfo::Instance().IsWin7OrLater());
103 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH
)->m_hWnd
, SHACF_FILESYSTEM
);
105 // set up the language selecting combobox
106 TCHAR buf
[MAX_PATH
] = {0};
107 GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
108 m_LanguageCombo
.AddString(buf
);
109 m_LanguageCombo
.SetItemData(0, 1033);
110 CString path
= CPathUtils::GetAppParentDirectory();
111 path
= path
+ _T("Languages\\");
112 CSimpleFileFind
finder(path
, _T("*.dll"));
114 while (finder
.FindNextFileNoDirectories())
116 CString file
= finder
.GetFilePath();
117 CString filename
= finder
.GetFileName();
118 if (filename
.Left(12).CompareNoCase(_T("TortoiseProc"))==0)
120 CString sVer
= _T(STRPRODUCTVER
);
121 sVer
= sVer
.Left(sVer
.ReverseFind('.'));
122 CString sFileVer
= CPathUtils::GetVersionFromFile(file
);
123 sFileVer
= sFileVer
.Left(sFileVer
.ReverseFind('.'));
124 if (sFileVer
.Compare(sVer
)!=0)
126 CString sLoc
= filename
.Mid(12);
127 sLoc
= sLoc
.Left(sLoc
.GetLength()-4); // cut off ".dll"
128 if ((sLoc
.Left(2) == L
"32")&&(sLoc
.GetLength() > 5))
130 DWORD loc
= _tstoi(filename
.Mid(12));
131 GetLocaleInfo(loc
, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
133 GetLocaleInfo(loc
, LOCALE_SNATIVECTRYNAME
, buf
, _countof(buf
));
140 m_LanguageCombo
.AddString(sLang
);
141 m_LanguageCombo
.SetItemData(langcount
++, loc
);
145 for (int i
=0; i
<m_LanguageCombo
.GetCount(); i
++)
147 if (m_LanguageCombo
.GetItemData(i
) == m_dwLanguage
)
148 m_LanguageCombo
.SetCurSel(i
);
155 BOOL
CSetMainPage::PreTranslateMessage(MSG
* pMsg
)
157 m_tooltips
.RelayEvent(pMsg
);
158 return ISettingsPropPage::PreTranslateMessage(pMsg
);
161 void CSetMainPage::OnModified()
166 static void PerformCommonGitPathCleanup(CString
&path
)
170 if (path
.Find(L
"%") >= 0)
172 int neededSize
= ExpandEnvironmentStrings(path
, nullptr, 0);
173 CString
origPath(path
);
174 ExpandEnvironmentStrings(origPath
, path
.GetBufferSetLength(neededSize
), neededSize
);
175 path
.ReleaseBuffer();
178 path
.Replace(L
"/", L
"\\");
179 path
.Replace(L
"\\\\", L
"\\");
181 if (path
.GetLength() > 7 && path
.Right(7) == _T("git.exe"))
182 path
= path
.Left(path
.GetLength() - 7);
184 path
.TrimRight(L
"\\");
186 // prefer git.exe in bin-directory, see https://github.com/msysgit/msysgit/issues/103
187 if (path
.GetLength() > 5 && path
.Right(4) == _T("\\cmd") && PathFileExists(path
.Left(path
.GetLength() - 4) + _T("\\bin\\git.exe")))
188 path
= path
.Left(path
.GetLength() - 4) + _T("\\bin");
191 void CSetMainPage::OnMsysGitPathModify()
194 CString str
=this->m_sMsysGitPath
;
197 PerformCommonGitPathCleanup(str
);
199 if(str
.GetLength()>=3 && str
.Find(_T("bin"), str
.GetLength()-3) >=0)
201 str
=str
.Left(str
.GetLength()-3);
202 str
+= _T("mingw\\bin");
203 if(::PathFileExists(str
))
206 if(this->m_sMsysGitExtranPath
.Find(str
)<0)
208 m_sMsysGitExtranPath
= str
+ m_sMsysGitExtranPath
;
209 this->UpdateData(FALSE
);
217 BOOL
CSetMainPage::OnApply()
221 PerformCommonGitPathCleanup(m_sMsysGitPath
);
224 Store (m_dwLanguage
, m_regLanguage
);
225 if (m_sMsysGitPath
.Compare(CString(m_regMsysGitPath
)) ||
226 this->m_sMsysGitExtranPath
.Compare(CString(m_regMsysGitExtranPath
)))
228 Store (m_sMsysGitPath
, m_regMsysGitPath
);
229 Store (m_sMsysGitExtranPath
, m_regMsysGitExtranPath
);
230 m_restart
= Restart_Cache
;
232 Store (m_bCheckNewer
, m_regCheckNewer
);
234 // only complete if the msysgit directory is ok
235 g_Git
.m_bInitialized
= FALSE
;
236 if (g_Git
.CheckMsysGitDir(FALSE
))
239 return ISettingsPropPage::OnApply();
243 if (CMessageBox::Show(NULL
, _T("Invalid git.exe path.\nCheck help file for \"Git.exe Path\"."), _T("TortoiseGit"), 1, IDI_ERROR
, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_HELP
))) == 2)
249 void CSetMainPage::OnBnClickedChecknewerbutton()
251 CAppUtils::RunTortoiseGitProc(_T("/command:updatecheck /visible"), false, false);
254 void CSetMainPage::OnBnClickedSounds()
256 if (SysInfo::Instance().IsVistaOrLater())
257 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,2"), NULL
, false);
259 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,1"), NULL
, false);
262 void CSetMainPage::OnBrowseDir()
264 CBrowseFolder browseFolder
;
265 browseFolder
.m_style
= BIF_EDITBOX
| BIF_NEWDIALOGSTYLE
| BIF_RETURNFSANCESTORS
| BIF_RETURNONLYFSDIRS
;
267 this->UpdateData(TRUE
);
268 dir
=this->m_sMsysGitPath
;
269 if (browseFolder
.Show(GetSafeHwnd(), dir
) == CBrowseFolder::OK
)
272 PerformCommonGitPathCleanup(m_sMsysGitPath
);
273 this->UpdateData(FALSE
);
274 OnMsysGitPathModify();
279 void CSetMainPage::OnCheck()
281 GetDlgItem(IDC_MSYSGIT_VER
)->SetWindowText(L
"");
283 this->UpdateData(TRUE
);
285 PerformCommonGitPathCleanup(m_sMsysGitPath
);
288 OnMsysGitPathModify();
290 CString oldpath
= m_regMsysGitPath
;
291 CString oldextranpath
= this->m_regMsysGitExtranPath
;
293 Store(m_sMsysGitPath
, m_regMsysGitPath
);
294 Store(m_sMsysGitExtranPath
, m_regMsysGitExtranPath
);
296 g_Git
.m_bInitialized
= false;
298 if (g_Git
.CheckMsysGitDir(FALSE
))
302 cmd
=_T("git.exe --version");
303 int ret
= g_Git
.Run(cmd
,&out
,CP_UTF8
);
304 this->GetDlgItem(IDC_MSYSGIT_VER
)->SetWindowText(out
);
307 if (ret
== 0xC0000135 && CMessageBox::Show(NULL
, _T("Could not start git.exe. A dynamic library (dll) is missing.\nCheck help file for \"Extern DLL Path\"."), _T("TortoiseGit"), 1, IDI_ERROR
, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_HELP
))) == 2)
309 else if (CMessageBox::Show(NULL
, _T("Could not get read version information from git.exe.\nCheck help file for \"Git.exe Path\"."),_T("TortoiseGit"), 1, IDI_ERROR
, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_HELP
))) == 2)
315 if (CMessageBox::Show(NULL
, _T("Invalid git.exe path.\nCheck help file for \"Git.exe Path\"."), _T("TortoiseGit"), 1, IDI_ERROR
, CString(MAKEINTRESOURCE(IDS_MSGBOX_OK
)), CString(MAKEINTRESOURCE(IDS_MSGBOX_HELP
))) == 2)
319 Store (oldpath
, m_regMsysGitPath
);
320 Store (oldextranpath
, m_regMsysGitExtranPath
);
323 void CSetMainPage::OnBnClickedButtonShowEnv()
326 CString tempfile
=::GetTempFile();
328 cmd
=_T("cmd /c set");
329 if (g_Git
.RunLogFile(cmd
, tempfile
, &err
))
331 CMessageBox::Show(GetSafeHwnd(), _T("Could not get environment variables:\n") + err
, _T("TortoiseGit"), MB_OK
);
334 CAppUtils::LaunchAlternativeEditor(tempfile
);
337 void CSetMainPage::OnBnClickedCreatelib()