some spaces-tabs code cleanup
[TortoiseGit.git] / src / TortoiseProc / Settings / SetMainPage.cpp
blobab4c6fb28a9c1a011aa63ea860542b9615458278
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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 "SVNProgressDlg.h"
27 #include "..\version.h"
28 #include ".\setmainpage.h"
29 #include "Git.h"
30 #include "MessageBox.h"
31 #include "CommonResource.h"
32 #include "GitConfig.h"
33 #include "BrowseFolder.h"
35 IMPLEMENT_DYNAMIC(CSetMainPage, ISettingsPropPage)
36 CSetMainPage::CSetMainPage()
37 : ISettingsPropPage(CSetMainPage::IDD)
38 , m_sMsysGitPath(_T(""))
39 , m_bCheckNewer(TRUE)
41 m_regLanguage = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
42 CString temp=CRegString(REG_MSYSGIT_INSTALL,_T(""),FALSE,HKEY_LOCAL_MACHINE);;
43 if(!temp.IsEmpty())
44 temp+=_T("bin");
45 m_regMsysGitPath = CRegString(REG_MSYSGIT_PATH,temp,FALSE);
47 m_regMsysGitExtranPath =CRegString(REG_MSYSGIT_EXTRA_PATH);
49 m_sMsysGitPath = m_regMsysGitPath;
50 m_sMsysGitExtranPath = m_regMsysGitExtranPath;
52 m_regCheckNewer = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE);
55 CSetMainPage::~CSetMainPage()
59 void CSetMainPage::DoDataExchange(CDataExchange* pDX)
61 ISettingsPropPage::DoDataExchange(pDX);
62 DDX_Control(pDX, IDC_LANGUAGECOMBO, m_LanguageCombo);
63 m_dwLanguage = (DWORD)m_LanguageCombo.GetItemData(m_LanguageCombo.GetCurSel());
64 DDX_Text(pDX, IDC_MSYSGIT_PATH, m_sMsysGitPath);
65 DDX_Text(pDX, IDC_MSYSGIT_EXTERN_PATH, m_sMsysGitExtranPath);
66 DDX_Check(pDX, IDC_CHECKNEWERVERSION, m_bCheckNewer);
70 BEGIN_MESSAGE_MAP(CSetMainPage, ISettingsPropPage)
71 ON_CBN_SELCHANGE(IDC_LANGUAGECOMBO, OnModified)
72 // ON_EN_CHANGE(IDC_TEMPEXTENSIONS, OnModified)
73 ON_BN_CLICKED(IDC_EDITCONFIG, OnBnClickedEditconfig)
74 ON_BN_CLICKED(IDC_CHECKNEWERVERSION, OnModified)
75 ON_BN_CLICKED(IDC_CHECKNEWERBUTTON, OnBnClickedChecknewerbutton)
76 ON_BN_CLICKED(IDC_SOUNDS, OnBnClickedSounds)
77 ON_BN_CLICKED(IDC_MSYSGIT_BROWSE,OnBrowseDir)
78 ON_BN_CLICKED(IDC_MSYSGIT_CHECK,OnCheck)
79 ON_EN_CHANGE(IDC_MSYSGIT_PATH, OnMsysGitPathModify)
80 ON_EN_CHANGE(IDC_MSYSGIT_EXTERN_PATH, OnModified)
81 ON_BN_CLICKED(IDC_BUTTON_SHOW_ENV, &CSetMainPage::OnBnClickedButtonShowEnv)
82 END_MESSAGE_MAP()
84 BOOL CSetMainPage::OnInitDialog()
86 ISettingsPropPage::OnInitDialog();
88 // disable features that have not yet been implemented
89 GetDlgItem(IDC_SOUNDS)->EnableWindow( FALSE );
90 GetDlgItem(IDC_SOUNDS_TEXT)->EnableWindow( FALSE );
92 EnableToolTips();
95 m_dwLanguage = m_regLanguage;
96 m_bCheckNewer = m_regCheckNewer;
98 m_tooltips.Create(this);
99 m_tooltips.AddTool(IDC_MSYSGIT_PATH,IDS_MSYSGIT_PATH_TT);
100 m_tooltips.AddTool(IDC_CHECKNEWERVERSION, IDS_SETTINGS_CHECKNEWER_TT);
102 // set up the language selecting combobox
103 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH)->m_hWnd, SHACF_FILESYSTEM);
105 TCHAR buf[MAX_PATH];
106 GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));
107 m_LanguageCombo.AddString(buf);
108 m_LanguageCombo.SetItemData(0, 1033);
109 CString path = CPathUtils::GetAppParentDirectory();
110 path = path + _T("Languages\\");
111 CSimpleFileFind finder(path, _T("*.dll"));
112 int langcount = 1;
113 while (finder.FindNextFileNoDirectories())
115 CString file = finder.GetFilePath();
116 CString filename = finder.GetFileName();
117 if (filename.Left(12).CompareNoCase(_T("TortoiseProc"))==0)
119 CString sVer = _T(STRPRODUCTVER);
120 sVer = sVer.Left(sVer.ReverseFind(','));
121 CString sFileVer = CPathUtils::GetVersionFromFile(file);
122 sFileVer = sFileVer.Left(sFileVer.ReverseFind(','));
123 if (sFileVer.Compare(sVer)!=0)
124 continue;
125 DWORD loc = _tstoi(filename.Mid(12));
126 TCHAR buf[MAX_PATH];
127 GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));
128 m_LanguageCombo.AddString(buf);
129 m_LanguageCombo.SetItemData(langcount++, loc);
133 for (int i=0; i<m_LanguageCombo.GetCount(); i++)
135 if (m_LanguageCombo.GetItemData(i) == m_dwLanguage)
136 m_LanguageCombo.SetCurSel(i);
139 UpdateData(FALSE);
140 return TRUE;
143 BOOL CSetMainPage::PreTranslateMessage(MSG* pMsg)
145 m_tooltips.RelayEvent(pMsg);
146 return ISettingsPropPage::PreTranslateMessage(pMsg);
149 void CSetMainPage::OnModified()
151 SetModified();
154 void CSetMainPage::OnMsysGitPathModify()
156 this->UpdateData();
157 CString str=this->m_sMsysGitPath;
158 if(!str.IsEmpty())
160 if(str[str.GetLength()-1]==_T('\'') || str[str.GetLength()-1]==_T('/'))
161 str=str.Left(str.GetLength()-1);
163 if(str.GetLength()>=3 && str.Find(_T("bin"), str.GetLength()-3) >=0)
165 str=str.Left(str.GetLength()-3);
166 str += _T("mingw\\bin");
167 if(::PathFileExists(str))
169 str+=_T(";");
170 if(this->m_sMsysGitExtranPath.Find(str)<0)
172 m_sMsysGitExtranPath = str + m_sMsysGitExtranPath;
173 this->UpdateData(FALSE);
178 SetModified();
181 BOOL CSetMainPage::OnApply()
183 UpdateData();
184 Store (m_dwLanguage, m_regLanguage);
185 if (m_sMsysGitPath.Compare(CString(m_regMsysGitPath)) ||
186 this->m_sMsysGitExtranPath.Compare(CString(m_regMsysGitExtranPath)))
188 Store (m_sMsysGitPath, m_regMsysGitPath);
189 Store (m_sMsysGitExtranPath, m_regMsysGitExtranPath);
190 m_restart = Restart_Cache;
192 Store (m_bCheckNewer, m_regCheckNewer);
194 // only complete if the msysgit directory is ok
195 if(g_Git.CheckMsysGitDir())
197 SetModified(FALSE);
198 return ISettingsPropPage::OnApply();
200 else
202 CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
203 return 0;
207 void CSetMainPage::OnBnClickedEditconfig()
209 #if 0
210 TCHAR buf[MAX_PATH];
211 SVN::EnsureConfigFile();
212 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buf);
213 CString path = buf;
214 path += _T("\\Subversion\\config");
215 CAppUtils::StartTextViewer(path);
216 #endif
219 void CSetMainPage::OnBnClickedChecknewerbutton()
221 TCHAR com[MAX_PATH+100];
222 GetModuleFileName(NULL, com, MAX_PATH);
223 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck /visible"));
225 CAppUtils::LaunchApplication(com, 0, false);
228 void CSetMainPage::OnBnClickedSounds()
230 OSVERSIONINFOEX inf;
231 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
232 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
233 GetVersionEx((OSVERSIONINFO *)&inf);
234 WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
236 if (fullver >= 0x0600)
237 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,2"), NULL, false);
238 else
239 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,1"), NULL, false);
242 void CSetMainPage::OnBrowseDir()
244 CBrowseFolder browseFolder;
245 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
246 CString dir;
247 this->UpdateData(TRUE);
248 dir=this->m_sMsysGitPath;
249 if (browseFolder.Show(GetSafeHwnd(), dir) == CBrowseFolder::OK)
251 m_sMsysGitPath=dir;
252 this->UpdateData(FALSE);
253 OnMsysGitPathModify();
255 SetModified(TRUE);
258 void CSetMainPage::OnCheck()
260 this->UpdateData(TRUE);
262 CString oldpath = m_regMsysGitPath;
263 CString oldextranpath = this->m_regMsysGitExtranPath;
265 Store(m_sMsysGitPath, m_regMsysGitPath);
266 Store(m_sMsysGitExtranPath, m_regMsysGitExtranPath);
268 g_Git.m_bInitialized = false;
270 if(g_Git.CheckMsysGitDir())
272 CString cmd;
273 CString out;
274 cmd=_T("git.exe --version");
275 g_Git.Run(cmd,&out,CP_UTF8);
276 this->GetDlgItem(IDC_MSYSGIT_VER)->SetWindowText(out);
277 }else
279 CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
282 Store (oldpath, m_regMsysGitPath);
283 Store (oldextranpath, m_regMsysGitExtranPath);
286 void CSetMainPage::OnBnClickedButtonShowEnv()
288 CString cmd;
289 CString tempfile=::GetTempFile();
291 cmd=_T("cmd /c set");
292 g_Git.RunLogFile(cmd,tempfile);
293 CAppUtils::LaunchAlternativeEditor(tempfile);