OSDN Git Service

Fixed issue #113: (10) Push and push times out on WebDAV passwords
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Settings / Settings.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 "Settings.h"\r
22 #include "MessageBox.h"\r
23 #include "..\..\TGitCache\CacheInterface.h"\r
24 #include "CommonResource.h"\r
25 #include "GitAdminDir.h"\r
26 \r
27 IMPLEMENT_DYNAMIC(CSettings, CTreePropSheet)\r
28 CSettings::CSettings(UINT nIDCaption,CTGitPath *cmdPath, CWnd* pParentWnd, UINT iSelectPage)\r
29         :CTreePropSheet(nIDCaption, pParentWnd, iSelectPage)\r
30 {\r
31         if(cmdPath)\r
32                 this->m_CmdPath=*cmdPath;\r
33 \r
34         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);\r
35         AddPropPages();\r
36 }\r
37 \r
38 CSettings::~CSettings()\r
39 {\r
40         RemovePropPages();\r
41 }\r
42 \r
43 void CSettings::AddPropPages()\r
44 {\r
45         m_pMainPage = new CSetMainPage();\r
46         m_pOverlayPage = new CSetOverlayPage();\r
47         m_pOverlaysPage = new CSetOverlayIcons();\r
48         m_pProxyPage = new CSetProxyPage();\r
49         m_pProgsDiffPage = new CSettingsProgsDiff();\r
50         m_pProgsMergePage = new CSettingsProgsMerge();\r
51         m_pProgsUniDiffPage = new CSettingsProgsUniDiff();\r
52         m_pLookAndFeelPage = new CSetLookAndFeelPage();\r
53         m_pDialogsPage = new CSetDialogs();\r
54         m_pMiscPage = new CSetMisc();\r
55         m_pRevisionGraphPage = new CSettingsRevisionGraph();\r
56 //      m_pLogCachePage = new CSetLogCache();\r
57 //      m_pLogCacheListPage = new CSettingsLogCaches();\r
58         m_pColorsPage = new CSettingsColors();\r
59     m_pColorsPage2 = new CSettingsColors2();\r
60     m_pColorsPage3 = new CSettingsColors3();\r
61         m_pSavedPage = new CSetSavedDataPage();\r
62 //      m_pHooksPage = new CSetHooks();\r
63         m_pBugTraqPage = new CSetBugTraq();\r
64         m_pTBlamePage = new CSettingsTBlame();\r
65         m_pGitConfig = new CSettingGitConfig();\r
66         m_pGitRemote = new CSettingGitRemote(m_CmdPath.GetWinPath());\r
67         m_pBugtraqConfig = new CSettingsBugtraqConfig(m_CmdPath.GetWinPath());\r
68 \r
69 \r
70         SetPageIcon(m_pMainPage, m_pMainPage->GetIconID());\r
71         SetPageIcon(m_pOverlayPage, m_pOverlayPage->GetIconID());\r
72         SetPageIcon(m_pOverlaysPage, m_pOverlaysPage->GetIconID());\r
73         SetPageIcon(m_pProxyPage, m_pProxyPage->GetIconID());\r
74         SetPageIcon(m_pProgsDiffPage, m_pProgsDiffPage->GetIconID());\r
75         SetPageIcon(m_pProgsMergePage, m_pProgsMergePage->GetIconID());\r
76         SetPageIcon(m_pProgsUniDiffPage, m_pProgsUniDiffPage->GetIconID());\r
77         SetPageIcon(m_pLookAndFeelPage, m_pLookAndFeelPage->GetIconID());\r
78         SetPageIcon(m_pDialogsPage, m_pDialogsPage->GetIconID());\r
79         SetPageIcon(m_pRevisionGraphPage, m_pRevisionGraphPage->GetIconID());\r
80         SetPageIcon(m_pMiscPage, m_pMiscPage->GetIconID());\r
81 ////    SetPageIcon(m_pLogCachePage, m_pLogCachePage->GetIconID());\r
82 //      SetPageIcon(m_pLogCacheListPage, m_pLogCacheListPage->GetIconID());\r
83         SetPageIcon(m_pColorsPage, m_pColorsPage->GetIconID());\r
84     SetPageIcon(m_pColorsPage2, m_pColorsPage2->GetIconID());\r
85     SetPageIcon(m_pColorsPage3, m_pColorsPage3->GetIconID());\r
86 \r
87         SetPageIcon(m_pSavedPage, m_pSavedPage->GetIconID());\r
88 //      SetPageIcon(m_pHooksPage, m_pHooksPage->GetIconID());\r
89 \r
90         SetPageIcon(m_pGitConfig, m_pGitConfig->GetIconID());\r
91         SetPageIcon(m_pGitRemote, m_pGitRemote->GetIconID());\r
92         SetPageIcon(m_pBugTraqPage, m_pBugTraqPage->GetIconID());\r
93         SetPageIcon(m_pBugtraqConfig, m_pBugtraqConfig->GetIconID());\r
94         SetPageIcon(m_pTBlamePage, m_pTBlamePage->GetIconID());\r
95 \r
96         AddPage(m_pMainPage);\r
97         AddPage(m_pOverlayPage);\r
98         AddPage(m_pOverlaysPage);\r
99         AddPage(m_pProxyPage);\r
100         AddPage(m_pProgsDiffPage);\r
101         AddPage(m_pProgsMergePage);\r
102         AddPage(m_pProgsUniDiffPage);\r
103         AddPage(m_pLookAndFeelPage);\r
104         AddPage(m_pDialogsPage);\r
105         AddPage(m_pMiscPage);\r
106         AddPage(m_pRevisionGraphPage);\r
107         AddPage(m_pColorsPage);\r
108         AddPage(m_pColorsPage2);\r
109         AddPage(m_pColorsPage3);\r
110         AddPage(m_pSavedPage);\r
111 \r
112         AddPage(m_pGitConfig);\r
113 \r
114         if(     g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )\r
115         {\r
116                 AddPage(m_pGitRemote);\r
117         }\r
118 //      AddPage(m_pGitRemotem_pLogCachePage);\r
119 //    AddPage(m_pLogCacheListPage);\r
120 //      AddPage(m_pHooksPage);\r
121         AddPage(m_pBugTraqPage);\r
122         if(     g_GitAdminDir.HasAdminDir(this->m_CmdPath.GetWinPath()) )\r
123         {\r
124                 AddPage(m_pBugtraqConfig);\r
125         }\r
126         AddPage(m_pTBlamePage);\r
127 }\r
128 \r
129 void CSettings::RemovePropPages()\r
130 {\r
131         delete m_pMainPage;\r
132         delete m_pOverlayPage;\r
133         delete m_pOverlaysPage;\r
134         delete m_pProxyPage;\r
135         delete m_pProgsDiffPage;\r
136         delete m_pProgsMergePage;\r
137         delete m_pProgsUniDiffPage;\r
138         delete m_pLookAndFeelPage;\r
139         delete m_pDialogsPage;\r
140     delete m_pRevisionGraphPage;\r
141         delete m_pMiscPage;\r
142 ////    delete m_pLogCachePage;\r
143 ////    delete m_pLogCacheListPage;\r
144         delete m_pColorsPage;\r
145         delete m_pColorsPage2;\r
146         delete m_pColorsPage3;\r
147         delete m_pSavedPage;\r
148 //      delete m_pHooksPage;\r
149         delete m_pBugTraqPage;\r
150         delete m_pTBlamePage;\r
151 \r
152         delete m_pGitConfig;\r
153         delete m_pGitRemote;\r
154         delete m_pBugtraqConfig;\r
155 \r
156 }\r
157 \r
158 void CSettings::HandleRestart()\r
159 {\r
160         int restart = ISettingsPropPage::Restart_None;\r
161         restart |= m_pMainPage->GetRestart();\r
162         restart |= m_pOverlayPage->GetRestart();\r
163         restart |= m_pOverlaysPage->GetRestart();\r
164         restart |= m_pProxyPage->GetRestart();\r
165         restart |= m_pProgsDiffPage->GetRestart();\r
166         restart |= m_pProgsMergePage->GetRestart();\r
167         restart |= m_pProgsUniDiffPage->GetRestart();\r
168         restart |= m_pLookAndFeelPage->GetRestart();\r
169         restart |= m_pDialogsPage->GetRestart();\r
170     restart |= m_pRevisionGraphPage->GetRestart();\r
171         restart |= m_pMiscPage->GetRestart();\r
172 ////    restart |= m_pLogCachePage->GetRestart();\r
173 //      restart |= m_pLogCacheListPage->GetRestart();\r
174         restart |= m_pColorsPage->GetRestart();\r
175         restart |= m_pColorsPage2->GetRestart();\r
176         restart |= m_pColorsPage3->GetRestart();\r
177         restart |= m_pSavedPage->GetRestart();\r
178 ////    restart |= m_pHooksPage->GetRestart();\r
179         restart |= m_pBugTraqPage->GetRestart();\r
180         restart |= m_pTBlamePage->GetRestart();\r
181 \r
182         restart |= m_pGitConfig->GetRestart();\r
183         restart |= m_pGitRemote->GetRestart();\r
184         restart |= m_pBugTraqPage->GetRestart();\r
185 \r
186         if (restart & ISettingsPropPage::Restart_System)\r
187         {\r
188                 DWORD_PTR res = 0;\r
189                 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);\r
190                 CMessageBox::Show(NULL, IDS_SETTINGS_RESTARTSYSTEM, IDS_APPNAME, MB_ICONINFORMATION);\r
191         }\r
192         if (restart & ISettingsPropPage::Restart_Cache)\r
193         {\r
194                 DWORD_PTR res = 0;\r
195                 ::SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 20, &res);\r
196                 // tell the cache to refresh everything\r
197                 HANDLE hPipe = CreateFile( \r
198                         GetCacheCommandPipeName(),              // pipe name \r
199                         GENERIC_READ |                                  // read and write access \r
200                         GENERIC_WRITE, \r
201                         0,                                                              // no sharing \r
202                         NULL,                                                   // default security attributes\r
203                         OPEN_EXISTING,                                  // opens existing pipe \r
204                         FILE_FLAG_OVERLAPPED,                   // default attributes \r
205                         NULL);                                                  // no template file \r
206 \r
207 \r
208                 if (hPipe != INVALID_HANDLE_VALUE) \r
209                 {\r
210                         // The pipe connected; change to message-read mode. \r
211                         DWORD dwMode; \r
212 \r
213                         dwMode = PIPE_READMODE_MESSAGE; \r
214                         if (SetNamedPipeHandleState( \r
215                                 hPipe,    // pipe handle \r
216                                 &dwMode,  // new pipe mode \r
217                                 NULL,     // don't set maximum bytes \r
218                                 NULL))    // don't set maximum time \r
219                         {\r
220                                 DWORD cbWritten; \r
221                                 TSVNCacheCommand cmd;\r
222                                 SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));\r
223                                 cmd.command = TSVNCACHECOMMAND_REFRESHALL;\r
224                                 BOOL fSuccess = WriteFile( \r
225                                         hPipe,                  // handle to pipe \r
226                                         &cmd,                   // buffer to write from \r
227                                         sizeof(cmd),    // number of bytes to write \r
228                                         &cbWritten,             // number of bytes written \r
229                                         NULL);                  // not overlapped I/O \r
230 \r
231                                 if (! fSuccess || sizeof(cmd) != cbWritten)\r
232                                 {\r
233                                         DisconnectNamedPipe(hPipe); \r
234                                         CloseHandle(hPipe); \r
235                                         hPipe = INVALID_HANDLE_VALUE;\r
236                                 }\r
237                                 if (hPipe != INVALID_HANDLE_VALUE)\r
238                                 {\r
239                                         // now tell the cache we don't need it's command thread anymore\r
240                                         DWORD cbWritten; \r
241                                         TSVNCacheCommand cmd;\r
242                                         SecureZeroMemory(&cmd, sizeof(TSVNCacheCommand));\r
243                                         cmd.command = TSVNCACHECOMMAND_END;\r
244                                         WriteFile( \r
245                                                 hPipe,                  // handle to pipe \r
246                                                 &cmd,                   // buffer to write from \r
247                                                 sizeof(cmd),    // number of bytes to write \r
248                                                 &cbWritten,             // number of bytes written \r
249                                                 NULL);                  // not overlapped I/O \r
250                                         DisconnectNamedPipe(hPipe); \r
251                                         CloseHandle(hPipe); \r
252                                         hPipe = INVALID_HANDLE_VALUE;\r
253                                 }\r
254                         }\r
255                         else\r
256                         {\r
257                                 ATLTRACE("SetNamedPipeHandleState failed"); \r
258                                 CloseHandle(hPipe);\r
259                         }\r
260                 }\r
261         }\r
262 }\r
263 \r
264 BEGIN_MESSAGE_MAP(CSettings, CTreePropSheet)\r
265         ON_WM_QUERYDRAGICON()\r
266         ON_WM_PAINT()\r
267 END_MESSAGE_MAP()\r
268 \r
269 BOOL CSettings::OnInitDialog()\r
270 {\r
271         BOOL bResult = CTreePropSheet::OnInitDialog();\r
272 \r
273         SetIcon(m_hIcon, TRUE);                 // Set big icon\r
274         SetIcon(m_hIcon, FALSE);                // Set small icon\r
275 \r
276         CenterWindow(CWnd::FromHandle(hWndExplorer));\r
277 \r
278         if(this->m_DefaultPage == _T("gitremote"))\r
279         {\r
280                 this->SetActivePage(this->m_pGitRemote);\r
281         }\r
282         if(this->m_DefaultPage == _T("main"))\r
283         {\r
284                 this->SetActivePage(this->m_pMainPage);\r
285         }\r
286         if(this->m_DefaultPage == _T("overlay"))\r
287         {\r
288                 this->SetActivePage(this->m_pOverlayPage);\r
289         }\r
290         if(this->m_DefaultPage == _T("overlays"))\r
291         {\r
292                 this->SetActivePage(this->m_pOverlaysPage);\r
293         }\r
294         if(this->m_DefaultPage == _T("proxy"))\r
295         {\r
296                 this->SetActivePage(this->m_pProxyPage);\r
297         }\r
298         \r
299         if(this->m_DefaultPage == _T("diff"))\r
300         {\r
301                 this->SetActivePage(this->m_pProgsDiffPage);\r
302         }\r
303         if(this->m_DefaultPage == _T("merge"))\r
304         {\r
305                 this->SetActivePage(this->m_pProgsMergePage);\r
306         }\r
307         if(this->m_DefaultPage == _T("unidiff"))\r
308         {\r
309                 this->SetActivePage(this->m_pProgsUniDiffPage);\r
310         }\r
311         if(this->m_DefaultPage == _T("look"))\r
312         {\r
313                 this->SetActivePage(this->m_pLookAndFeelPage);\r
314         }\r
315         if(this->m_DefaultPage == _T("dialog"))\r
316         {\r
317                 this->SetActivePage(this->m_pDialogsPage);\r
318         }\r
319         if(this->m_DefaultPage == _T("misc"))\r
320         {\r
321                 this->SetActivePage(this->m_pMiscPage);\r
322         }\r
323         if(this->m_DefaultPage == _T("graph"))\r
324         {\r
325                 this->SetActivePage(this->m_pRevisionGraphPage);\r
326         }\r
327 \r
328         if(this->m_DefaultPage == _T("color1"))\r
329         {\r
330                 this->SetActivePage(this->m_pColorsPage);\r
331         }\r
332         if(this->m_DefaultPage == _T("color2"))\r
333         {\r
334                 this->SetActivePage(this->m_pColorsPage2);\r
335         }\r
336         if(this->m_DefaultPage == _T("color3"))\r
337         {\r
338                 this->SetActivePage(this->m_pColorsPage3);\r
339         }\r
340         if(this->m_DefaultPage == _T("save"))\r
341         {\r
342                 this->SetActivePage(this->m_pSavedPage);\r
343         }\r
344 \r
345         return bResult;\r
346 }\r
347 \r
348 void CSettings::OnPaint()\r
349 {\r
350         if (IsIconic())\r
351         {\r
352                 CPaintDC dc(this); // device context for painting\r
353 \r
354                 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);\r
355 \r
356                 // Center icon in client rectangle\r
357                 int cxIcon = GetSystemMetrics(SM_CXICON);\r
358                 int cyIcon = GetSystemMetrics(SM_CYICON);\r
359                 CRect rect;\r
360                 GetClientRect(&rect);\r
361                 int x = (rect.Width() - cxIcon + 1) / 2;\r
362                 int y = (rect.Height() - cyIcon + 1) / 2;\r
363 \r
364                 // Draw the icon\r
365                 dc.DrawIcon(x, y, m_hIcon);\r
366         }\r
367         else\r
368         {\r
369                 CTreePropSheet::OnPaint();\r
370         }\r
371 }\r
372 \r
373 HCURSOR CSettings::OnQueryDragIcon()\r
374 {\r
375         return static_cast<HCURSOR>(m_hIcon);\r
376 }\r