Cleanup: Drop unnecessary method definitions
[TortoiseGit.git] / src / TortoiseProc / Settings / SetMainPage.cpp
blob118f4ac9ef363bc897986f44034a7cd0ed638d91
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 "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)
42 m_regLanguage = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
43 CString temp=CRegString(REG_MSYSGIT_INSTALL,_T(""),FALSE,HKEY_LOCAL_MACHINE);;
44 if(!temp.IsEmpty())
45 temp+=_T("bin");
46 m_regMsysGitPath = CRegString(REG_MSYSGIT_PATH,temp,FALSE);
48 m_regMsysGitExtranPath =CRegString(REG_MSYSGIT_EXTRA_PATH);
50 m_sMsysGitPath = m_regMsysGitPath;
51 m_sMsysGitExtranPath = m_regMsysGitExtranPath;
53 m_regCheckNewer = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE);
56 CSetMainPage::~CSetMainPage()
60 void CSetMainPage::DoDataExchange(CDataExchange* pDX)
62 ISettingsPropPage::DoDataExchange(pDX);
63 DDX_Control(pDX, IDC_LANGUAGECOMBO, m_LanguageCombo);
64 m_dwLanguage = (DWORD)m_LanguageCombo.GetItemData(m_LanguageCombo.GetCurSel());
65 DDX_Text(pDX, IDC_MSYSGIT_PATH, m_sMsysGitPath);
66 DDX_Text(pDX, IDC_MSYSGIT_EXTERN_PATH, m_sMsysGitExtranPath);
67 DDX_Check(pDX, IDC_CHECKNEWERVERSION, m_bCheckNewer);
71 BEGIN_MESSAGE_MAP(CSetMainPage, ISettingsPropPage)
72 ON_CBN_SELCHANGE(IDC_LANGUAGECOMBO, OnModified)
73 // ON_EN_CHANGE(IDC_TEMPEXTENSIONS, OnModified)
74 ON_BN_CLICKED(IDC_EDITCONFIG, OnBnClickedEditconfig)
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)
84 END_MESSAGE_MAP()
86 BOOL CSetMainPage::OnInitDialog()
88 ISettingsPropPage::OnInitDialog();
90 // disable features that have not yet been implemented
91 GetDlgItem(IDC_SOUNDS)->EnableWindow( FALSE );
92 GetDlgItem(IDC_SOUNDS_TEXT)->EnableWindow( FALSE );
94 EnableToolTips();
97 m_dwLanguage = m_regLanguage;
98 m_bCheckNewer = m_regCheckNewer;
100 m_tooltips.Create(this);
101 m_tooltips.AddTool(IDC_MSYSGIT_PATH,IDS_MSYSGIT_PATH_TT);
102 m_tooltips.AddTool(IDC_CHECKNEWERVERSION, IDS_SETTINGS_CHECKNEWER_TT);
103 m_tooltips.AddTool(IDC_CREATELIB, IDS_SETTINGS_CREATELIB_TT);
105 GetDlgItem(IDC_CREATELIB)->EnableWindow(SysInfo::Instance().IsWin7OrLater());
107 SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH)->m_hWnd, SHACF_FILESYSTEM);
109 // set up the language selecting combobox
110 TCHAR buf[MAX_PATH];
111 GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME, buf, _countof(buf));
112 m_LanguageCombo.AddString(buf);
113 m_LanguageCombo.SetItemData(0, 1033);
114 CString path = CPathUtils::GetAppParentDirectory();
115 path = path + _T("Languages\\");
116 CSimpleFileFind finder(path, _T("*.dll"));
117 int langcount = 1;
118 while (finder.FindNextFileNoDirectories())
120 CString file = finder.GetFilePath();
121 CString filename = finder.GetFileName();
122 if (filename.Left(12).CompareNoCase(_T("TortoiseProc"))==0)
124 CString sVer = _T(STRPRODUCTVER);
125 sVer = sVer.Left(sVer.ReverseFind(','));
126 CString sFileVer = CPathUtils::GetVersionFromFile(file);
127 sFileVer = sFileVer.Left(sFileVer.ReverseFind(','));
128 if (sFileVer.Compare(sVer)!=0)
129 continue;
130 CString sLoc = filename.Mid(12);
131 sLoc = sLoc.Left(sLoc.GetLength()-4); // cut off ".dll"
132 if ((sLoc.Left(2) == L"32")&&(sLoc.GetLength() > 5))
133 continue;
134 DWORD loc = _tstoi(filename.Mid(12));
135 GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, _countof(buf));
136 CString sLang = buf;
137 GetLocaleInfo(loc, LOCALE_SNATIVECTRYNAME, buf, _countof(buf));
138 if (buf[0])
140 sLang += _T(" (");
141 sLang += buf;
142 sLang += _T(")");
144 m_LanguageCombo.AddString(sLang);
145 m_LanguageCombo.SetItemData(langcount++, loc);
149 for (int i=0; i<m_LanguageCombo.GetCount(); i++)
151 if (m_LanguageCombo.GetItemData(i) == m_dwLanguage)
152 m_LanguageCombo.SetCurSel(i);
155 UpdateData(FALSE);
156 return TRUE;
159 BOOL CSetMainPage::PreTranslateMessage(MSG* pMsg)
161 m_tooltips.RelayEvent(pMsg);
162 return ISettingsPropPage::PreTranslateMessage(pMsg);
165 void CSetMainPage::OnModified()
167 SetModified();
170 void CSetMainPage::OnMsysGitPathModify()
172 this->UpdateData();
173 CString str=this->m_sMsysGitPath;
174 if(!str.IsEmpty())
176 if(str[str.GetLength()-1]==_T('\'') || str[str.GetLength()-1]==_T('/'))
177 str=str.Left(str.GetLength()-1);
179 if(str.GetLength()>=3 && str.Find(_T("bin"), str.GetLength()-3) >=0)
181 str=str.Left(str.GetLength()-3);
182 str += _T("mingw\\bin");
183 if(::PathFileExists(str))
185 str+=_T(";");
186 if(this->m_sMsysGitExtranPath.Find(str)<0)
188 m_sMsysGitExtranPath = str + m_sMsysGitExtranPath;
189 this->UpdateData(FALSE);
194 SetModified();
197 BOOL CSetMainPage::OnApply()
199 UpdateData();
200 Store (m_dwLanguage, m_regLanguage);
201 if (m_sMsysGitPath.Compare(CString(m_regMsysGitPath)) ||
202 this->m_sMsysGitExtranPath.Compare(CString(m_regMsysGitExtranPath)))
204 Store (m_sMsysGitPath, m_regMsysGitPath);
205 Store (m_sMsysGitExtranPath, m_regMsysGitExtranPath);
206 m_restart = Restart_Cache;
208 Store (m_bCheckNewer, m_regCheckNewer);
210 // only complete if the msysgit directory is ok
211 if(g_Git.CheckMsysGitDir())
213 SetModified(FALSE);
214 return ISettingsPropPage::OnApply();
216 else
218 CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
219 return 0;
223 void CSetMainPage::OnBnClickedEditconfig()
225 #if 0
226 TCHAR buf[MAX_PATH];
227 SVN::EnsureConfigFile();
228 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buf);
229 CString path = buf;
230 path += _T("\\Subversion\\config");
231 CAppUtils::StartTextViewer(path);
232 #endif
235 void CSetMainPage::OnBnClickedChecknewerbutton()
237 TCHAR com[MAX_PATH+100];
238 GetModuleFileName(NULL, com, MAX_PATH);
239 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck /visible"));
241 CAppUtils::LaunchApplication(com, 0, false);
244 void CSetMainPage::OnBnClickedSounds()
246 if (SysInfo::Instance().IsVistaOrLater())
247 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,2"), NULL, false);
248 else
249 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,1"), NULL, false);
252 void CSetMainPage::OnBrowseDir()
254 CBrowseFolder browseFolder;
255 browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
256 CString dir;
257 this->UpdateData(TRUE);
258 dir=this->m_sMsysGitPath;
259 if (browseFolder.Show(GetSafeHwnd(), dir) == CBrowseFolder::OK)
261 m_sMsysGitPath=dir;
262 this->UpdateData(FALSE);
263 OnMsysGitPathModify();
265 SetModified(TRUE);
268 void CSetMainPage::OnCheck()
270 this->UpdateData(TRUE);
272 CString oldpath = m_regMsysGitPath;
273 CString oldextranpath = this->m_regMsysGitExtranPath;
275 Store(m_sMsysGitPath, m_regMsysGitPath);
276 Store(m_sMsysGitExtranPath, m_regMsysGitExtranPath);
278 g_Git.m_bInitialized = false;
280 if(g_Git.CheckMsysGitDir())
282 CString cmd;
283 CString out;
284 cmd=_T("git.exe --version");
285 g_Git.Run(cmd,&out,CP_UTF8);
286 this->GetDlgItem(IDC_MSYSGIT_VER)->SetWindowText(out);
288 else
290 CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);
293 Store (oldpath, m_regMsysGitPath);
294 Store (oldextranpath, m_regMsysGitExtranPath);
297 void CSetMainPage::OnBnClickedButtonShowEnv()
299 CString cmd;
300 CString tempfile=::GetTempFile();
302 cmd=_T("cmd /c set");
303 g_Git.RunLogFile(cmd,tempfile);
304 CAppUtils::LaunchAlternativeEditor(tempfile);
307 void CSetMainPage::OnBnClickedCreatelib()
309 CoInitialize(NULL);
310 EnsureGitLibrary();
311 CoUninitialize();