OSDN Git Service

e59d116dd4c357bdfa1496ba9009b1b23a28696c
[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 \r
32 IMPLEMENT_DYNAMIC(CSetMainPage, ISettingsPropPage)\r
33 CSetMainPage::CSetMainPage()\r
34         : ISettingsPropPage(CSetMainPage::IDD)\r
35         , m_sTempExtensions(_T(""))\r
36         , m_bCheckNewer(TRUE)\r
37         , m_bLastCommitTime(FALSE)\r
38         , m_bUseDotNetHack(FALSE)\r
39 {\r
40         m_regLanguage = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);\r
41 //      CString temp(SVN_CONFIG_DEFAULT_GLOBAL_IGNORES);\r
42 //      m_regExtensions = CRegString(_T("Software\\Tigris.org\\Subversion\\Config\\miscellany\\global-ignores"), temp);\r
43         m_regCheckNewer = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE);\r
44         m_regLastCommitTime = CRegString(_T("Software\\Tigris.org\\Subversion\\Config\\miscellany\\use-commit-times"), _T(""));\r
45         if ((GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)==0)&&(GetLastError()==ERROR_ENVVAR_NOT_FOUND))\r
46                 m_bUseDotNetHack = false;\r
47         else\r
48                 m_bUseDotNetHack = true;\r
49 }\r
50 \r
51 CSetMainPage::~CSetMainPage()\r
52 {\r
53 }\r
54 \r
55 void CSetMainPage::DoDataExchange(CDataExchange* pDX)\r
56 {\r
57         ISettingsPropPage::DoDataExchange(pDX);\r
58         DDX_Control(pDX, IDC_LANGUAGECOMBO, m_LanguageCombo);\r
59         m_dwLanguage = (DWORD)m_LanguageCombo.GetItemData(m_LanguageCombo.GetCurSel());\r
60         DDX_Text(pDX, IDC_TEMPEXTENSIONS, m_sTempExtensions);\r
61         DDX_Check(pDX, IDC_CHECKNEWERVERSION, m_bCheckNewer);\r
62         DDX_Check(pDX, IDC_COMMITFILETIMES, m_bLastCommitTime);\r
63         DDX_Check(pDX, IDC_ASPDOTNETHACK, m_bUseDotNetHack);\r
64 }\r
65 \r
66 \r
67 BEGIN_MESSAGE_MAP(CSetMainPage, ISettingsPropPage)\r
68         ON_CBN_SELCHANGE(IDC_LANGUAGECOMBO, OnModified)\r
69         ON_EN_CHANGE(IDC_TEMPEXTENSIONS, OnModified)\r
70         ON_BN_CLICKED(IDC_EDITCONFIG, OnBnClickedEditconfig)\r
71         ON_BN_CLICKED(IDC_CHECKNEWERVERSION, OnModified)\r
72         ON_BN_CLICKED(IDC_CHECKNEWERBUTTON, OnBnClickedChecknewerbutton)\r
73         ON_BN_CLICKED(IDC_COMMITFILETIMES, OnModified)\r
74         ON_BN_CLICKED(IDC_SOUNDS, OnBnClickedSounds)\r
75         ON_BN_CLICKED(IDC_ASPDOTNETHACK, OnASPHACK)\r
76 END_MESSAGE_MAP()\r
77 \r
78 BOOL CSetMainPage::OnInitDialog()\r
79 {\r
80         ISettingsPropPage::OnInitDialog();\r
81 \r
82         EnableToolTips();\r
83 \r
84         m_sTempExtensions = m_regExtensions;\r
85         m_dwLanguage = m_regLanguage;\r
86         m_bCheckNewer = m_regCheckNewer;\r
87 \r
88         CString temp;\r
89         temp = m_regLastCommitTime;\r
90         m_bLastCommitTime = (temp.CompareNoCase(_T("yes"))==0);\r
91 \r
92         m_tooltips.Create(this);\r
93         m_tooltips.AddTool(IDC_TEMPEXTENSIONS, IDS_SETTINGS_TEMPEXTENSIONS_TT);\r
94         m_tooltips.AddTool(IDC_CHECKNEWERVERSION, IDS_SETTINGS_CHECKNEWER_TT);\r
95         m_tooltips.AddTool(IDC_COMMITFILETIMES, IDS_SETTINGS_COMMITFILETIMES_TT);\r
96         m_tooltips.AddTool(IDC_ASPDOTNETHACK, IDS_SETTINGS_DOTNETHACK_TT);\r
97 \r
98         // set up the language selecting combobox\r
99         TCHAR buf[MAX_PATH];\r
100         GetLocaleInfo(1033, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));\r
101         m_LanguageCombo.AddString(buf);\r
102         m_LanguageCombo.SetItemData(0, 1033);\r
103         CString path = CPathUtils::GetAppParentDirectory();\r
104         path = path + _T("Languages\\");\r
105         CSimpleFileFind finder(path, _T("*.dll"));\r
106         int langcount = 1;\r
107         while (finder.FindNextFileNoDirectories())\r
108         {\r
109                 CString file = finder.GetFilePath();\r
110                 CString filename = finder.GetFileName();\r
111                 if (filename.Left(12).CompareNoCase(_T("TortoiseProc"))==0)\r
112                 {\r
113                         CString sVer = _T(STRPRODUCTVER);\r
114                         sVer = sVer.Left(sVer.ReverseFind(','));\r
115                         CString sFileVer = CPathUtils::GetVersionFromFile(file);\r
116                         sFileVer = sFileVer.Left(sFileVer.ReverseFind(','));\r
117                         if (sFileVer.Compare(sVer)!=0)\r
118                                 continue;\r
119                         DWORD loc = _tstoi(filename.Mid(12));\r
120                         TCHAR buf[MAX_PATH];\r
121                         GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, sizeof(buf)/sizeof(TCHAR));\r
122                         m_LanguageCombo.AddString(buf);\r
123                         m_LanguageCombo.SetItemData(langcount++, loc);\r
124                 }\r
125         }\r
126         \r
127         for (int i=0; i<m_LanguageCombo.GetCount(); i++)\r
128         {\r
129                 if (m_LanguageCombo.GetItemData(i) == m_dwLanguage)\r
130                         m_LanguageCombo.SetCurSel(i);\r
131         }\r
132 \r
133         UpdateData(FALSE);\r
134         return TRUE;\r
135 }\r
136 \r
137 BOOL CSetMainPage::PreTranslateMessage(MSG* pMsg)\r
138 {\r
139         m_tooltips.RelayEvent(pMsg);\r
140         return ISettingsPropPage::PreTranslateMessage(pMsg);\r
141 }\r
142 \r
143 void CSetMainPage::OnModified()\r
144 {\r
145         SetModified();\r
146 }\r
147 \r
148 void CSetMainPage::OnASPHACK()\r
149 {\r
150         if (CMessageBox::Show(m_hWnd, IDS_SETTINGS_ASPHACKWARNING, IDS_APPNAME, MB_ICONWARNING|MB_YESNO) == IDYES)\r
151         {\r
152                 SetModified();\r
153         }\r
154         else\r
155         {\r
156                 UpdateData();\r
157                 m_bUseDotNetHack = !m_bUseDotNetHack;\r
158                 UpdateData(FALSE);\r
159         }\r
160 }\r
161 \r
162 BOOL CSetMainPage::OnApply()\r
163 {\r
164         UpdateData();\r
165         Store (m_dwLanguage, m_regLanguage);\r
166         if (m_sTempExtensions.Compare(CString(m_regExtensions)))\r
167         {\r
168                 Store (m_sTempExtensions, m_regExtensions);\r
169                 m_restart = Restart_Cache;\r
170         }\r
171         Store (m_bCheckNewer, m_regCheckNewer);\r
172         Store ((m_bLastCommitTime ? _T("yes") : _T("no")), m_regLastCommitTime);\r
173 \r
174         CRegString asphack_local(_T("System\\CurrentControlSet\\Control\\Session Manager\\Environment\\SVN_ASP_DOT_NET_HACK"), _T(""), FALSE, HKEY_LOCAL_MACHINE);\r
175         CRegString asphack_user(_T("Environment\\SVN_ASP_DOT_NET_HACK"));\r
176         if (m_bUseDotNetHack)\r
177         {\r
178                 asphack_local = _T("*");\r
179                 if (asphack_local.LastError)\r
180                         asphack_user = _T("*");\r
181                 if ((GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)==0)&&(GetLastError()==ERROR_ENVVAR_NOT_FOUND))\r
182                 {\r
183                         DWORD_PTR dwRet = 0;\r
184                         SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);\r
185                         m_restart = Restart_System;\r
186                 }\r
187         }\r
188         else\r
189         {\r
190                 asphack_local.removeValue();\r
191                 asphack_user.removeValue();\r
192                 if (GetEnvironmentVariable(_T("SVN_ASP_DOT_NET_HACK"), NULL, 0)!=0)\r
193                 {\r
194                         DWORD_PTR dwRet = 0;\r
195                         SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)_T("Environment"), SMTO_ABORTIFHUNG, 1000, &dwRet);\r
196                         m_restart = Restart_System;\r
197                 }\r
198         }\r
199         SetModified(FALSE);\r
200         return ISettingsPropPage::OnApply();\r
201 }\r
202 \r
203 void CSetMainPage::OnBnClickedEditconfig()\r
204 {\r
205 #if 0\r
206         TCHAR buf[MAX_PATH];\r
207         SVN::EnsureConfigFile();\r
208         SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buf);\r
209         CString path = buf;\r
210         path += _T("\\Subversion\\config");\r
211         CAppUtils::StartTextViewer(path);\r
212 #endif\r
213 }\r
214 \r
215 void CSetMainPage::OnBnClickedChecknewerbutton()\r
216 {\r
217         TCHAR com[MAX_PATH+100];\r
218         GetModuleFileName(NULL, com, MAX_PATH);\r
219         _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck /visible"));\r
220 \r
221         CAppUtils::LaunchApplication(com, 0, false);\r
222 }\r
223 \r
224 void CSetMainPage::OnBnClickedSounds()\r
225 {\r
226         OSVERSIONINFOEX inf;\r
227         SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));\r
228         inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);\r
229         GetVersionEx((OSVERSIONINFO *)&inf);\r
230         WORD fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);\r
231         \r
232         if (fullver >= 0x0600)\r
233                 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,2"), NULL, false);\r
234         else\r
235                 CAppUtils::LaunchApplication(_T("RUNDLL32 Shell32,Control_RunDLL mmsys.cpl,,1"), NULL, false);\r
236 }\r
237 \r
238 \r
239 \r
240 \r
241 \r
242 \r
243 \r