OSDN Git Service

Add Setting Dialog for Setup MSysGit
[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 END_MESSAGE_MAP()\r
83 \r
84 BOOL CSetMainPage::OnInitDialog()\r
85 {\r
86         ISettingsPropPage::OnInitDialog();\r
87 \r
88         EnableToolTips();\r
89 \r
90         m_sMsysGitPath = m_regMsysGitPath;\r
91         m_dwLanguage = m_regLanguage;\r
92         m_bCheckNewer = m_regCheckNewer;\r
93 \r
94         CString temp;\r
95         temp = m_regLastCommitTime;\r
96         m_bLastCommitTime = (temp.CompareNoCase(_T("yes"))==0);\r
97 \r
98         m_tooltips.Create(this);\r
99         m_tooltips.AddTool(IDC_MSYSGIT_PATH,IDS_MSYSGIT_PATH_TT);\r
100         //m_tooltips.AddTool(IDC_CHECKNEWERVERSION, IDS_SETTINGS_CHECKNEWER_TT);\r
101         //m_tooltips.AddTool(IDC_COMMITFILETIMES, IDS_SETTINGS_COMMITFILETIMES_TT);\r
102         //m_tooltips.AddTool(IDC_ASPDOTNETHACK, IDS_SETTINGS_DOTNETHACK_TT);\r
103 \r
104         // set up the language selecting combobox\r
105         SHAutoComplete(GetDlgItem(IDC_MSYSGIT_PATH)->m_hWnd, SHACF_FILESYSTEM);\r
106 \r
107         TCHAR buf[MAX_PATH];\r
108         GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));\r
109         m_LanguageCombo.AddString(buf);\r
110         m_LanguageCombo.SetItemData(0, 1033);\r
111         CString path = CPathUtils::GetAppParentDirectory();\r
112         path = path + _T("Languages\\");\r
113         CSimpleFileFind finder(path, _T("*.dll"));\r
114         int langcount = 1;\r
115         while (finder.FindNextFileNoDirectories())\r
116         {\r
117                 CString file = finder.GetFilePath();\r
118                 CString filename = finder.GetFileName();\r
119                 if (filename.Left(12).CompareNoCase(_T("TortoiseProc"))==0)\r
120                 {\r
121                         CString sVer = _T(STRPRODUCTVER);\r
122                         sVer = sVer.Left(sVer.ReverseFind(','));\r
123                         CString sFileVer = CPathUtils::GetVersionFromFile(file);\r
124                         sFileVer = sFileVer.Left(sFileVer.ReverseFind(','));\r
125                         if (sFileVer.Compare(sVer)!=0)\r
126                                 continue;\r
127                         DWORD loc = _tstoi(filename.Mid(12));\r
128                         TCHAR buf[MAX_PATH];\r
129                         GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));\r
130                         m_LanguageCombo.AddString(buf);\r
131                         m_LanguageCombo.SetItemData(langcount++, loc);\r
132                 }\r
133         }\r
134         \r
135         for (int i=0; i<m_LanguageCombo.GetCount(); i++)\r
136         {\r
137                 if (m_LanguageCombo.GetItemData(i) == m_dwLanguage)\r
138                         m_LanguageCombo.SetCurSel(i);\r
139         }\r
140 \r
141         UpdateData(FALSE);\r
142         return TRUE;\r
143 }\r
144 \r
145 BOOL CSetMainPage::PreTranslateMessage(MSG* pMsg)\r
146 {\r
147         m_tooltips.RelayEvent(pMsg);\r
148         return ISettingsPropPage::PreTranslateMessage(pMsg);\r
149 }\r
150 \r
151 void CSetMainPage::OnModified()\r
152 {\r
153         SetModified();\r
154 }\r
155 \r
156 void CSetMainPage::OnASPHACK()\r
157 {\r
158         if (CMessageBox::Show(m_hWnd, IDS_SETTINGS_ASPHACKWARNING, IDS_APPNAME, MB_ICONWARNING|MB_YESNO) == IDYES)\r
159         {\r
160                 SetModified();\r
161         }\r
162         else\r
163         {\r
164                 UpdateData();\r
165                 m_bUseDotNetHack = !m_bUseDotNetHack;\r
166                 UpdateData(FALSE);\r
167         }\r
168 }\r
169 \r
170 BOOL CSetMainPage::OnApply()\r
171 {\r
172         UpdateData();\r
173         Store (m_dwLanguage, m_regLanguage);\r
174         if (m_sMsysGitPath.Compare(CString(m_regMsysGitPath)))\r
175         {\r
176                 Store (m_sMsysGitPath, m_regMsysGitPath);\r
177                 m_restart = Restart_Cache;\r
178         }\r
179         Store (m_bCheckNewer, m_regCheckNewer);\r
180         Store ((m_bLastCommitTime ? _T("yes") : _T("no")), m_regLastCommitTime);\r
181 \r
182         CRegString asphack_local(_T("System\\CurrentControlSet\\Control\\Session Manager\\Environment\\SVN_ASP_DOT_NET_HACK"), _T(""), FALSE, HKEY_LOCAL_MACHINE);\r
183         CRegString asphack_user(_T("Environment\\SVN_ASP_DOT_NET_HACK"));\r
184         if (m_bUseDotNetHack)\r
185         {\r
186                 asphack_local = _T("*");\r
187                 if (asphack_local.LastError)\r
188                         asphack_user = _T("*");\r
189                 if ((GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)==0)&&(GetLastError()==ERROR_ENVVAR_NOT_FOUND))\r
190                 {\r
191                         DWORD_PTR dwRet = 0;\r
192                         SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);\r
193                         m_restart = Restart_System;\r
194                 }\r
195         }\r
196         else\r
197         {\r
198                 asphack_local.removeValue();\r
199                 asphack_user.removeValue();\r
200                 if (GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)!=0)\r
201                 {\r
202                         DWORD_PTR dwRet = 0;\r
203                         SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);\r
204                         m_restart = Restart_System;\r
205                 }\r
206         }\r
207         SetModified(FALSE);\r
208         return ISettingsPropPage::OnApply();\r
209 }\r
210 \r
211 void CSetMainPage::OnBnClickedEditconfig()\r
212 {\r
213 #if 0\r
214         TCHAR buf[MAX_PATH];\r
215         SVN::EnsureConfigFile();\r
216         SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buf);\r
217         CString path = buf;\r
218         path += _T("\\Subversion\\config");\r
219         CAppUtils::StartTextViewer(path);\r
220 #endif\r
221 }\r
222 \r
223 void CSetMainPage::OnBnClickedChecknewerbutton()\r
224 {\r
225         TCHAR com[MAX_PATH+100];\r
226         GetModuleFileName(NULL, com, MAX_PATH);\r
227         _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck /visible"));\r
228 \r
229         CAppUtils::LaunchApplication(com, 0, false);\r
230 }\r
231 \r
232 void CSetMainPage::OnBnClickedSounds()\r
233 {\r
234         OSVERSIONINFOEX inf;\r
235         SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));\r
236         inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);\r
237         GetVersionEx((OSVERSIONINFO *)&inf);\r
238         WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);\r
239         \r
240         if (fullver >= 0x0600)\r
241                 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,2"), NULL, false);\r
242         else\r
243                 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,1"), NULL, false);\r
244 }\r
245 \r
246 void CSetMainPage::OnBrowseDir()\r
247 {\r
248         CBrowseFolder browseFolder;\r
249         browseFolder.m_style = BIF_EDITBOX | BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;\r
250         CString dir;\r
251         this->UpdateData(TRUE);\r
252         dir=this->m_sMsysGitPath;\r
253         if (browseFolder.Show(GetSafeHwnd(), dir) == CBrowseFolder::OK) \r
254         {\r
255                 m_sMsysGitPath=dir;\r
256                 Store (m_sMsysGitPath, m_regMsysGitPath);\r
257                 this->UpdateData(FALSE);\r
258         }\r
259         SetModified(TRUE);\r
260 }\r
261 \r
262 void CSetMainPage::OnCheck()\r
263 {\r
264         if(g_Git.CheckMsysGitDir())\r
265         {\r
266                 CString cmd;\r
267                 CString out;\r
268                 cmd=_T("git.exe --version");\r
269                 g_Git.Run(cmd,&out,CP_UTF8);\r
270                 this->GetDlgItem(IDC_MSYSGIT_VER)->SetWindowText(out);\r
271         }else\r
272         {\r
273                 CMessageBox::Show(NULL,_T("Msys Git Install Path Error"),_T("TortoiseGit"),MB_OK|MB_ICONERROR);\r
274         }\r
275 }\r
276 \r
277 \r