OSDN Git Service

a8e9e1c19aa2b6b0fc20a78dbd0c63c0fe47fefa
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Settings / SetMainPage.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseProc.h"\r
21 #include "SetMainPage.h"\r
22 #include "AppUtils.h"\r
23 #include "PathUtils.h"\r
24 #include "DirFileEnum.h"\r
25 #include "SVNProgressDlg.h"\r
26 #include "..\version.h"\r
27 #include ".\setmainpage.h"\r
28 #include "Git.h"\r
29 #include "MessageBox.h"\r
30 #include "CommonResource.h"\r
31 #include "GitConfig.h"\r
32 #include "BrowseFolder.h"\r
33 \r
34 IMPLEMENT_DYNAMIC(CSetMainPage, ISettingsPropPage)\r
35 CSetMainPage::CSetMainPage()\r
36         : ISettingsPropPage(CSetMainPage::IDD)\r
37         , m_sMsysGitPath(_T(""))\r
38         , m_bCheckNewer(TRUE)\r
39         , m_bLastCommitTime(FALSE)\r
40         , m_bUseDotNetHack(FALSE)\r
41 {\r
42         m_regLanguage = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);\r
43         CString temp=CRegString(REG_MSYSGIT_INSTALL,_T(""),FALSE,HKEY_LOCAL_MACHINE);;\r
44         if(!temp.IsEmpty())\r
45                 temp+=_T("bin");\r
46         m_regMsysGitPath = CRegString(REG_MSYSGIT_PATH,temp,FALSE,HKEY_LOCAL_MACHINE);\r
47         m_regCheckNewer = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE);\r
48         m_regLastCommitTime = CRegString(_T("Software\\Tigris.org\\Subversion\\Config\\miscellany\\use-commit-times"), _T(""));\r
49         if ((GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)==0)&&(GetLastError()==ERROR_ENVVAR_NOT_FOUND))\r
50                 m_bUseDotNetHack = false;\r
51         else\r
52                 m_bUseDotNetHack = true;\r
53 }\r
54 \r
55 CSetMainPage::~CSetMainPage()\r
56 {\r
57 }\r
58 \r
59 void CSetMainPage::DoDataExchange(CDataExchange* pDX)\r
60 {\r
61         ISettingsPropPage::DoDataExchange(pDX);\r
62         DDX_Control(pDX, IDC_LANGUAGECOMBO, m_LanguageCombo);\r
63         m_dwLanguage = (DWORD)m_LanguageCombo.GetItemData(m_LanguageCombo.GetCurSel());\r
64         DDX_Text(pDX, IDC_MSYSGIT_PATH, m_sMsysGitPath);\r
65 //      DDX_Check(pDX, IDC_CHECKNEWERVERSION, m_bCheckNewer);\r
66 //      DDX_Check(pDX, IDC_COMMITFILETIMES, m_bLastCommitTime);\r
67 //      DDX_Check(pDX, IDC_ASPDOTNETHACK, m_bUseDotNetHack);\r
68 }\r
69 \r
70 \r
71 BEGIN_MESSAGE_MAP(CSetMainPage, ISettingsPropPage)\r
72         ON_CBN_SELCHANGE(IDC_LANGUAGECOMBO, OnModified)\r
73 //      ON_EN_CHANGE(IDC_TEMPEXTENSIONS, OnModified)\r
74         ON_BN_CLICKED(IDC_EDITCONFIG, OnBnClickedEditconfig)\r
75         ON_BN_CLICKED(IDC_CHECKNEWERVERSION, OnModified)\r
76         ON_BN_CLICKED(IDC_CHECKNEWERBUTTON, OnBnClickedChecknewerbutton)\r
77         ON_BN_CLICKED(IDC_COMMITFILETIMES, OnModified)\r
78         ON_BN_CLICKED(IDC_SOUNDS, OnBnClickedSounds)\r
79         ON_BN_CLICKED(IDC_ASPDOTNETHACK, OnASPHACK)\r
80         ON_BN_CLICKED(IDC_MSYSGIT_BROWSE,OnBrowseDir)\r
81         ON_BN_CLICKED(IDC_MSYSGIT_CHECK,OnCheck)\r
82         ON_EN_CHANGE(IDC_MSYSGIT_PATH, OnModified)\r
83 END_MESSAGE_MAP()\r
84 \r
85 BOOL CSetMainPage::OnInitDialog()\r
86 {\r
87         ISettingsPropPage::OnInitDialog();\r
88 \r
89         // disable features that have not yet been implemented\r
90         GetDlgItem(IDC_CHECKNEWERVERSION)->EnableWindow( FALSE );\r
91         GetDlgItem(IDC_CHECKNEWERBUTTON)->EnableWindow( FALSE );\r
92         GetDlgItem(IDC_SOUNDS)->EnableWindow( FALSE );\r
93         GetDlgItem(IDC_SOUNDS_TEXT)->EnableWindow( FALSE );\r
94         \r
95         EnableToolTips();\r
96 \r
97         m_sMsysGitPath = m_regMsysGitPath;\r
98         m_dwLanguage = m_regLanguage;\r
99         m_bCheckNewer = m_regCheckNewer;\r
100 \r
101         CString temp;\r
102         temp = m_regLastCommitTime;\r
103         m_bLastCommitTime = (temp.CompareNoCase(_T("yes"))==0);\r
104 \r
105         m_tooltips.Create(this);\r
106         m_tooltips.AddTool(IDC_MSYSGIT_PATH,IDS_MSYSGIT_PATH_TT);\r
107         //m_tooltips.AddTool(IDC_CHECKNEWERVERSION, IDS_SETTINGS_CHECKNEWER_TT);\r
108         //m_tooltips.AddTool(IDC_COMMITFILETIMES, IDS_SETTINGS_COMMITFILETIMES_TT);\r
109         //m_tooltips.AddTool(IDC_ASPDOTNETHACK, IDS_SETTINGS_DOTNETHACK_TT);\r
110 \r
111         // set up the language selecting combobox\r
112         SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH)->m_hWnd, SHACF_FILESYSTEM);\r
113 \r
114         TCHAR buf[MAX_PATH];\r
115         GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));\r
116         m_LanguageCombo.AddString(buf);\r
117         m_LanguageCombo.SetItemData(0, 1033);\r
118         CString path = CPathUtils::GetAppParentDirectory();\r
119         path = path + _T("Languages\\");\r
120         CSimpleFileFind finder(path, _T("*.dll"));\r
121         int langcount = 1;\r
122         while (finder.FindNextFileNoDirectories())\r
123         {\r
124                 CString file = finder.GetFilePath();\r
125                 CString filename = finder.GetFileName();\r
126                 if (filename.Left(12).CompareNoCase(_T("TortoiseProc"))==0)\r
127                 {\r
128                         CString sVer = _T(STRPRODUCTVER);\r
129                         sVer = sVer.Left(sVer.ReverseFind(','));\r
130                         CString sFileVer = CPathUtils::GetVersionFromFile(file);\r
131                         sFileVer = sFileVer.Left(sFileVer.ReverseFind(','));\r
132                         if (sFileVer.Compare(sVer)!=0)\r
133                                 continue;\r
134                         DWORD loc = _tstoi(filename.Mid(12));\r
135                         TCHAR buf[MAX_PATH];\r
136                         GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));\r
137                         m_LanguageCombo.AddString(buf);\r
138                         m_LanguageCombo.SetItemData(langcount++, loc);\r
139                 }\r
140         }\r
141         \r
142         for (int i=0; i<m_LanguageCombo.GetCount(); i++)\r
143         {\r
144                 if (m_LanguageCombo.GetItemData(i) == m_dwLanguage)\r
145                         m_LanguageCombo.SetCurSel(i);\r
146         }\r
147 \r
148         UpdateData(FALSE);\r
149         return TRUE;\r
150 }\r
151 \r
152 BOOL CSetMainPage::PreTranslateMessage(MSG* pMsg)\r
153 {\r
154         m_tooltips.RelayEvent(pMsg);\r
155         return ISettingsPropPage::PreTranslateMessage(pMsg);\r
156 }\r
157 \r
158 void CSetMainPage::OnModified()\r
159 {\r
160         SetModified();\r
161 }\r
162 \r
163 void CSetMainPage::OnASPHACK()\r
164 {\r
165         if (CMessageBox::Show(m_hWnd, IDS_SETTINGS_ASPHACKWARNING, IDS_APPNAME, MB_ICONWARNING|MB_YESNO) == IDYES)\r
166         {\r
167                 SetModified();\r
168         }\r
169         else\r
170         {\r
171                 UpdateData();\r
172                 m_bUseDotNetHack = !m_bUseDotNetHack;\r
173                 UpdateData(FALSE);\r
174         }\r
175 }\r
176 \r
177 BOOL CSetMainPage::OnApply()\r
178 {\r
179         UpdateData();\r
180         Store (m_dwLanguage, m_regLanguage);\r
181         if (m_sMsysGitPath.Compare(CString(m_regMsysGitPath)))\r
182         {\r
183                 Store (m_sMsysGitPath, m_regMsysGitPath);\r
184                 m_restart = Restart_Cache;\r
185         }\r
186         Store (m_bCheckNewer, m_regCheckNewer);\r
187         Store ((m_bLastCommitTime ? _T("yes") : _T("no")), m_regLastCommitTime);\r
188 \r
189         CRegString asphack_local(_T("System\\CurrentControlSet\\Control\\Session Manager\\Environment\\SVN_ASP_DOT_NET_HACK"), _T(""), FALSE, HKEY_LOCAL_MACHINE);\r
190         CRegString asphack_user(_T("Environment\\SVN_ASP_DOT_NET_HACK"));\r
191         if (m_bUseDotNetHack)\r
192         {\r
193                 asphack_local = _T("*");\r
194                 if (asphack_local.LastError)\r
195                         asphack_user = _T("*");\r
196                 if ((GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)==0)&&(GetLastError()==ERROR_ENVVAR_NOT_FOUND))\r
197                 {\r
198                         DWORD_PTR dwRet = 0;\r
199                         SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);\r
200                         m_restart = Restart_System;\r
201                 }\r
202         }\r
203         else\r
204         {\r
205                 asphack_local.removeValue();\r
206                 asphack_user.removeValue();\r
207                 if (GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)!=0)\r
208                 {\r
209                         DWORD_PTR dwRet = 0;\r
210                         SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);\r
211                         m_restart = Restart_System;\r
212                 }\r
213         }\r
214         // only complete if the msysgit directory is ok\r
215         if(g_Git.CheckMsysGitDir())\r
216         {\r
217                 SetModified(FALSE);\r
218                 return ISettingsPropPage::OnApply();\r
219         }\r
220         else\r
221         {\r
222                 CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
223                 return 0;\r
224         }\r
225 }\r
226 \r
227 void CSetMainPage::OnBnClickedEditconfig()\r
228 {\r
229 #if 0\r
230         TCHAR buf[MAX_PATH];\r
231         SVN::EnsureConfigFile();\r
232         SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buf);\r
233         CString path = buf;\r
234         path += _T("\\Subversion\\config");\r
235         CAppUtils::StartTextViewer(path);\r
236 #endif\r
237 }\r
238 \r
239 void CSetMainPage::OnBnClickedChecknewerbutton()\r
240 {\r
241         TCHAR com[MAX_PATH+100];\r
242         GetModuleFileName(NULL, com, MAX_PATH);\r
243         _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck /visible"));\r
244 \r
245         CAppUtils::LaunchApplication(com, 0, false);\r
246 }\r
247 \r
248 void CSetMainPage::OnBnClickedSounds()\r
249 {\r
250         OSVERSIONINFOEX inf;\r
251         SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));\r
252         inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);\r
253         GetVersionEx((OSVERSIONINFO *)&inf);\r
254         WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);\r
255         \r
256         if (fullver >= 0x0600)\r
257                 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,2"), NULL, false);\r
258         else\r
259                 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,1"), NULL, false);\r
260 }\r
261 \r
262 void CSetMainPage::OnBrowseDir()\r
263 {\r
264         CBrowseFolder browseFolder;\r
265         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
266         CString dir;\r
267         this->UpdateData(TRUE);\r
268         dir=this->m_sMsysGitPath;\r
269         if (browseFolder.Show(GetSafeHwnd(), dir) == CBrowseFolder::OK) \r
270         {\r
271                 m_sMsysGitPath=dir;\r
272                 Store (m_sMsysGitPath, m_regMsysGitPath);\r
273                 this->UpdateData(FALSE);\r
274         }\r
275         SetModified(TRUE);\r
276 }\r
277 \r
278 void CSetMainPage::OnCheck()\r
279 {\r
280         if(g_Git.CheckMsysGitDir())\r
281         {\r
282                 CString cmd;\r
283                 CString out;\r
284                 cmd=_T("git.exe --version");\r
285                 g_Git.Run(cmd,&out,CP_UTF8);\r
286                 this->GetDlgItem(IDC_MSYSGIT_VER)->SetWindowText(out);\r
287         }else\r
288         {\r
289                 CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
290         }\r
291 }\r
292 \r
293 \r