Make sounds for indicating a warning or error work
[TortoiseGit.git] / src / TortoiseProc / Settings / SetMainPage.cpp
blob3b0fd9aa103b0a4a312900b316a27316e94ad830
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "SetMainPage.h"
23 #include "AppUtils.h"
24 #include "PathUtils.h"
25 #include "DirFileEnum.h"
26 #include "GITProgressDlg.h"
27 #include "..\version.h"
28 #include ".\setmainpage.h"
29 #include "Git.h"
30 #include "MessageBox.h"
31 #include "GitConfig.h"
32 #include "BrowseFolder.h"
33 #include "SysInfo.h"
34 #include "Libraries.h"
36 IMPLEMENT_DYNAMIC(CSetMainPage, ISettingsPropPage)
37 CSetMainPage::CSetMainPage()
38 : ISettingsPropPage(CSetMainPage::IDD)
39 , m_sMsysGitPath(_T(""))
40 , m_bCheckNewer(TRUE)
41 , m_dwLanguage(0)
43 m_regLanguage = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
44 CString temp=CRegString(REG_MSYSGIT_INSTALL,_T(""),FALSE,HKEY_LOCAL_MACHINE);;
45 if(!temp.IsEmpty())
46 temp+=_T("bin");
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_EDITCONFIG, OnBnClickedEditconfig)
76 ON_BN_CLICKED(IDC_CHECKNEWERVERSION, OnModified)
77 ON_BN_CLICKED(IDC_CHECKNEWERBUTTON, OnBnClickedChecknewerbutton)
78 ON_BN_CLICKED(IDC_SOUNDS, OnBnClickedSounds)
79 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE,OnBrowseDir)
80 ON_BN_CLICKED(IDC_MSYSGIT_CHECK,OnCheck)
81 ON_EN_CHANGE(IDC_MSYSGIT_PATH, OnMsysGitPathModify)
82 ON_EN_CHANGE(IDC_MSYSGIT_EXTERN_PATH, OnModified)
83 ON_BN_CLICKED(IDC_BUTTON_SHOW_ENV, &CSetMainPage::OnBnClickedButtonShowEnv)
84 ON_BN_CLICKED(IDC_CREATELIB, &CSetMainPage::OnBnClickedCreatelib)
85 END_MESSAGE_MAP()
87 BOOL CSetMainPage::OnInitDialog()
89 ISettingsPropPage::OnInitDialog();
91 EnableToolTips();
94 m_dwLanguage = m_regLanguage;
95 m_bCheckNewer = m_regCheckNewer;
97 m_tooltips.Create(this);
98 m_tooltips.AddTool(IDC_MSYSGIT_PATH,IDS_MSYSGIT_PATH_TT);
99 m_tooltips.AddTool(IDC_CHECKNEWERVERSION, IDS_SETTINGS_CHECKNEWER_TT);
100 m_tooltips.AddTool(IDC_CREATELIB, IDS_SETTINGS_CREATELIB_TT);
102 GetDlgItem(IDC_CREATELIB)->EnableWindow(SysInfo::Instance().IsWin7OrLater());
104 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH)->m_hWnd, SHACF_FILESYSTEM);
106 // set up the language selecting combobox
107 TCHAR buf[MAX_PATH];
108 GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME, buf, _countof(buf));
109 m_LanguageCombo.AddString(buf);
110 m_LanguageCombo.SetItemData(0, 1033);
111 CString path = CPathUtils::GetAppParentDirectory();
112 path = path + _T("Languages\\");
113 CSimpleFileFind finder(path, _T("*.dll"));
114 int langcount = 1;
115 while (finder.FindNextFileNoDirectories())
117 CString file = finder.GetFilePath();
118 CString filename = finder.GetFileName();
119 if (filename.Left(12).CompareNoCase(_T("TortoiseProc"))==0)
121 CString sVer = _T(STRPRODUCTVER);
122 sVer = sVer.Left(sVer.ReverseFind('.'));
123 CString sFileVer = CPathUtils::GetVersionFromFile(file);
124 sFileVer = sFileVer.Left(sFileVer.ReverseFind('.'));
125 if (sFileVer.Compare(sVer)!=0)
126 continue;
127 CString sLoc = filename.Mid(12);
128 sLoc = sLoc.Left(sLoc.GetLength()-4); // cut off ".dll"
129 if ((sLoc.Left(2) == L"32")&&(sLoc.GetLength() > 5))
130 continue;
131 DWORD loc = _tstoi(filename.Mid(12));
132 GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, _countof(buf));
133 CString sLang = buf;
134 GetLocaleInfo(loc, LOCALE_SNATIVECTRYNAME, buf, _countof(buf));
135 if (buf[0])
137 sLang += _T(" (");
138 sLang += buf;
139 sLang += _T(")");
141 m_LanguageCombo.AddString(sLang);
142 m_LanguageCombo.SetItemData(langcount++, loc);
146 for (int i=0; i<m_LanguageCombo.GetCount(); i++)
148 if (m_LanguageCombo.GetItemData(i) == m_dwLanguage)
149 m_LanguageCombo.SetCurSel(i);
152 UpdateData(FALSE);
153 return TRUE;
156 BOOL CSetMainPage::PreTranslateMessage(MSG* pMsg)
158 m_tooltips.RelayEvent(pMsg);
159 return ISettingsPropPage::PreTranslateMessage(pMsg);
162 void CSetMainPage::OnModified()
164 SetModified();
167 void CSetMainPage::OnMsysGitPathModify()
169 this->UpdateData();
170 CString str=this->m_sMsysGitPath;
171 if(!str.IsEmpty())
173 if(str[str.GetLength()-1]==_T('\'') || str[str.GetLength()-1]==_T('/'))
174 str=str.Left(str.GetLength()-1);
176 if(str.GetLength()>=3 && str.Find(_T("bin"), str.GetLength()-3) >=0)
178 str=str.Left(str.GetLength()-3);
179 str += _T("mingw\\bin");
180 if(::PathFileExists(str))
182 str+=_T(";");
183 if(this->m_sMsysGitExtranPath.Find(str)<0)
185 m_sMsysGitExtranPath = str + m_sMsysGitExtranPath;
186 this->UpdateData(FALSE);
191 SetModified();
194 BOOL CSetMainPage::OnApply()
196 UpdateData();
197 if (!m_sMsysGitPath.IsEmpty() && (m_sMsysGitPath.Right(1) == _T("\\") || m_sMsysGitPath.Right(1) == _T("/")))
199 m_sMsysGitPath = m_sMsysGitPath.Left(m_sMsysGitPath.GetLength() - 1);
200 UpdateData(FALSE);
202 Store (m_dwLanguage, m_regLanguage);
203 if (m_sMsysGitPath.Compare(CString(m_regMsysGitPath)) ||
204 this->m_sMsysGitExtranPath.Compare(CString(m_regMsysGitExtranPath)))
206 Store (m_sMsysGitPath, m_regMsysGitPath);
207 Store (m_sMsysGitExtranPath, m_regMsysGitExtranPath);
208 m_restart = Restart_Cache;
210 Store (m_bCheckNewer, m_regCheckNewer);
212 // only complete if the msysgit directory is ok
213 if(g_Git.CheckMsysGitDir())
215 SetModified(FALSE);
216 return ISettingsPropPage::OnApply();
218 else
220 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)
221 OnHelp();
222 return 0;
226 void CSetMainPage::OnBnClickedEditconfig()
228 #if 0
229 TCHAR buf[MAX_PATH];
230 SVN::EnsureConfigFile();
231 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buf);
232 CString path = buf;
233 path += _T("\\Subversion\\config");
234 CAppUtils::StartTextViewer(path);
235 #endif
238 void CSetMainPage::OnBnClickedChecknewerbutton()
240 CAppUtils::RunTortoiseGitProc(_T("/command:updatecheck /visible"), false, false);
243 void CSetMainPage::OnBnClickedSounds()
245 if (SysInfo::Instance().IsVistaOrLater())
246 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,2"), NULL, false);
247 else
248 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,1"), NULL, false);
251 void CSetMainPage::OnBrowseDir()
253 CBrowseFolder browseFolder;
254 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
255 CString dir;
256 this->UpdateData(TRUE);
257 dir=this->m_sMsysGitPath;
258 if (browseFolder.Show(GetSafeHwnd(), dir) == CBrowseFolder::OK)
260 m_sMsysGitPath=dir;
261 this->UpdateData(FALSE);
262 OnMsysGitPathModify();
264 SetModified(TRUE);
267 void CSetMainPage::OnCheck()
269 this->UpdateData(TRUE);
271 CString oldpath = m_regMsysGitPath;
272 CString oldextranpath = this->m_regMsysGitExtranPath;
274 Store(m_sMsysGitPath, m_regMsysGitPath);
275 Store(m_sMsysGitExtranPath, m_regMsysGitExtranPath);
277 g_Git.m_bInitialized = false;
279 if(g_Git.CheckMsysGitDir())
281 CString cmd;
282 CString out;
283 cmd=_T("git.exe --version");
284 g_Git.Run(cmd,&out,CP_UTF8);
285 this->GetDlgItem(IDC_MSYSGIT_VER)->SetWindowText(out);
286 if (out.IsEmpty())
287 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)
288 OnHelp();
290 else
292 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)
293 OnHelp();
296 Store (oldpath, m_regMsysGitPath);
297 Store (oldextranpath, m_regMsysGitExtranPath);
300 void CSetMainPage::OnBnClickedButtonShowEnv()
302 CString cmd;
303 CString tempfile=::GetTempFile();
305 cmd=_T("cmd /c set");
306 g_Git.RunLogFile(cmd,tempfile);
307 CAppUtils::LaunchAlternativeEditor(tempfile);
310 void CSetMainPage::OnBnClickedCreatelib()
312 CoInitialize(NULL);
313 EnsureGitLibrary();
314 CoUninitialize();