OSDN Git Service

956488a489072c4c48441df77dcaa214e89619bf
[tortoisegit/TortoiseGitJp.git] / TortoiseProc / TortoiseProc.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 "vld.h"\r
21 #include "TortoiseProc.h"\r
22 #include "SysImageList.h"\r
23 #include "CrashReport.h"\r
24 #include "CmdLineParser.h"\r
25 #include "Hooks.h"\r
26 #include "AppUtils.h"\r
27 #include "PathUtils.h"\r
28 #include "UnicodeUtils.h"\r
29 #include "MessageBox.h"\r
30 #include "libintl.h"\r
31 #include "DirFileEnum.h"\r
32 #include "SoundUtils.h"\r
33 #include "SVN.h"\r
34 #include "SVNAdminDir.h"\r
35 #include "SVNGlobal.h"\r
36 #include "svn_types.h"\r
37 #include "svn_dso.h"\r
38 #include <openssl/ssl.h>\r
39 #include <openssl/err.h>\r
40 \r
41 #include "Commands\Command.h"\r
42 \r
43 #include "..\version.h"\r
44 #define STRUCT_IOVEC_DEFINED\r
45 #include "sasl.h"\r
46 \r
47 #ifdef _DEBUG\r
48 #define new DEBUG_NEW\r
49 #endif\r
50 \r
51 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")\r
52 \r
53 \r
54 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)\r
55         ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)\r
56 END_MESSAGE_MAP()\r
57 \r
58 \r
59 \r
60 //////////////////////////////////////////////////////////////////////////\r
61 \r
62 CTortoiseProcApp::CTortoiseProcApp()\r
63 {\r
64         EnableHtmlHelp();\r
65         int argc = 0;\r
66         const char* const * argv = NULL;\r
67         apr_app_initialize(&argc, &argv, NULL);\r
68         svn_dso_initialize2();\r
69         SYS_IMAGE_LIST();\r
70         CHooks::Create();\r
71         g_SVNAdminDir.Init();\r
72         m_bLoadUserToolbars = FALSE;\r
73         m_bSaveState = FALSE;\r
74         retSuccess = false;\r
75 }\r
76 \r
77 CTortoiseProcApp::~CTortoiseProcApp()\r
78 {\r
79         sasl_done();\r
80 \r
81         // global application exit cleanup (after all SSL activity is shutdown)\r
82         // we have to clean up SSL ourselves, since neon doesn't do that (can't do it)\r
83         // because those cleanup functions work globally per process.\r
84         ERR_free_strings();\r
85         EVP_cleanup();\r
86         CRYPTO_cleanup_all_ex_data();\r
87 \r
88         // since it is undefined *when* the global object SVNAdminDir is\r
89         // destroyed, we tell it to destroy the memory pools and terminate apr\r
90         // *now* instead of later when the object itself is destroyed.\r
91         g_SVNAdminDir.Close();\r
92         CHooks::Destroy();\r
93         SYS_IMAGE_LIST().Cleanup();\r
94         apr_terminate();\r
95 }\r
96 \r
97 // The one and only CTortoiseProcApp object\r
98 CTortoiseProcApp theApp;\r
99 HWND hWndExplorer;\r
100 CString sOrigCWD;\r
101 \r
102 CCrashReport crasher("crashreports@tortoisesvn.tigris.org", "Crash Report for TortoiseSVN " APP_X64_STRING " : " STRPRODUCTVER, TRUE);// crash\r
103 \r
104 // CTortoiseProcApp initialization\r
105 \r
106 BOOL CTortoiseProcApp::InitInstance()\r
107 {\r
108         EnableCrashHandler();\r
109         CheckUpgrade();\r
110         CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));\r
111         CMFCButton::EnableWindowsTheming();\r
112         //set the resource dll for the required language\r
113         CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseSVN\\LanguageID"), 1033);\r
114         long langId = loc;\r
115         CString langDll;\r
116         CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());\r
117         langpath += "Languages";\r
118         bindtextdomain("subversion", (LPCSTR)langpath);\r
119         bind_textdomain_codeset("subversion", "UTF-8");\r
120         HINSTANCE hInst = NULL;\r
121         do\r
122         {\r
123                 langDll.Format(_T("..\\Languages\\TortoiseProc%d.dll"), langId);\r
124                 \r
125                 hInst = LoadLibrary(langDll);\r
126 \r
127                 CString sVer = _T(STRPRODUCTVER);\r
128                 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);\r
129                 if (sFileVer.Compare(sVer)!=0)\r
130                 {\r
131                         FreeLibrary(hInst);\r
132                         hInst = NULL;\r
133                 }\r
134                 if (hInst != NULL)\r
135                 {\r
136                         AfxSetResourceHandle(hInst);\r
137                 }\r
138                 else\r
139                 {\r
140                         DWORD lid = SUBLANGID(langId);\r
141                         lid--;\r
142                         if (lid > 0)\r
143                         {\r
144                                 langId = MAKELANGID(PRIMARYLANGID(langId), lid);\r
145                         }\r
146                         else\r
147                                 langId = 0;\r
148                 }\r
149         } while ((hInst == NULL) && (langId != 0));\r
150         TCHAR buf[6];\r
151         _tcscpy_s(buf, _T("en"));\r
152         langId = loc;\r
153         CString sHelppath;\r
154         sHelppath = this->m_pszHelpFilePath;\r
155         sHelppath = sHelppath.MakeLower();\r
156         // MFC uses a help file with the same name as the application by default,\r
157         // which means we have to change that default to our language specific help files\r
158         sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseSVN_en.chm"));\r
159         free((void*)m_pszHelpFilePath);\r
160         m_pszHelpFilePath=_tcsdup(sHelppath);\r
161         sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseSVN_en.chm");\r
162         do\r
163         {\r
164                 CString sLang = _T("_");\r
165                 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, sizeof(buf)))\r
166                 {\r
167                         sLang += buf;\r
168                         sHelppath.Replace(_T("_en"), sLang);\r
169                         if (PathFileExists(sHelppath))\r
170                         {\r
171                                 free((void*)m_pszHelpFilePath);\r
172                                 m_pszHelpFilePath=_tcsdup(sHelppath);\r
173                                 break;\r
174                         }\r
175                 }\r
176                 sHelppath.Replace(sLang, _T("_en"));\r
177                 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, sizeof(buf)))\r
178                 {\r
179                         sLang += _T("_");\r
180                         sLang += buf;\r
181                         sHelppath.Replace(_T("_en"), sLang);\r
182                         if (PathFileExists(sHelppath))\r
183                         {\r
184                                 free((void*)m_pszHelpFilePath);\r
185                                 m_pszHelpFilePath=_tcsdup(sHelppath);\r
186                                 break;\r
187                         }\r
188                 }\r
189                 sHelppath.Replace(sLang, _T("_en"));\r
190 \r
191                 DWORD lid = SUBLANGID(langId);\r
192                 lid--;\r
193                 if (lid > 0)\r
194                 {\r
195                         langId = MAKELANGID(PRIMARYLANGID(langId), lid);\r
196                 }\r
197                 else\r
198                         langId = 0;\r
199         } while (langId);\r
200         setlocale(LC_ALL, "");\r
201         \r
202         // InitCommonControls() is required on Windows XP if an application\r
203         // manifest specifies use of ComCtl32.dll version 6 or later to enable\r
204         // visual styles.  Otherwise, any window creation will fail.\r
205         \r
206     INITCOMMONCONTROLSEX used = {\r
207         sizeof(INITCOMMONCONTROLSEX),\r
208                         ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |\r
209                         ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |\r
210                         ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |\r
211                         ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |\r
212                         ICC_USEREX_CLASSES | ICC_WIN95_CLASSES\r
213     };\r
214     InitCommonControlsEx(&used);\r
215         AfxOleInit();\r
216         AfxEnableControlContainer();\r
217         AfxInitRichEdit2();\r
218         CWinAppEx::InitInstance();\r
219         SetRegistryKey(_T("TortoiseSVN"));\r
220 \r
221         CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);\r
222 \r
223         // if HKCU\Software\TortoiseSVN\Debug is not 0, show our command line\r
224         // in a message box\r
225         if (CRegDWORD(_T("Software\\TortoiseSVN\\Debug"), FALSE)==TRUE)\r
226                 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);\r
227 \r
228         if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))\r
229         {\r
230                 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);\r
231                 return FALSE;\r
232         }\r
233 \r
234         CTSVNPath cmdLinePath;\r
235         CTSVNPathList pathList;\r
236         if ( parser.HasKey(_T("pathfile")) )\r
237         {\r
238                 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));\r
239                 cmdLinePath.SetFromUnknown(sPathfileArgument);\r
240                 if (pathList.LoadFromFile(cmdLinePath)==false)\r
241                         return FALSE;           // no path specified!\r
242                 if ( parser.HasKey(_T("deletepathfile")) )\r
243                 {\r
244                         // We can delete the temporary path file, now that we've loaded it\r
245                         ::DeleteFile(cmdLinePath.GetWinPath());\r
246                 }\r
247                 // This was a path to a temporary file - it's got no meaning now, and\r
248                 // anybody who uses it again is in for a problem...\r
249                 cmdLinePath.Reset();\r
250         }\r
251         else\r
252         {\r
253                 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));\r
254                 int asterisk = sPathArgument.Find('*');\r
255                 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);\r
256                 pathList.LoadFromAsteriskSeparatedString(sPathArgument);\r
257         }\r
258         \r
259         hWndExplorer = NULL;\r
260         CString sVal = parser.GetVal(_T("hwnd"));\r
261         if (!sVal.IsEmpty())\r
262                 hWndExplorer = (HWND)_ttoi64(sVal);\r
263 \r
264         while (GetParent(hWndExplorer)!=NULL)\r
265                 hWndExplorer = GetParent(hWndExplorer);\r
266         if (!IsWindow(hWndExplorer))\r
267         {\r
268                 hWndExplorer = NULL;\r
269         }\r
270         \r
271         // Subversion sometimes writes temp files to the current directory!\r
272         // Since TSVN doesn't need a specific CWD anyway, we just set it\r
273         // to the users temp folder: that way, Subversion is guaranteed to\r
274         // have write access to the CWD\r
275         {\r
276                 DWORD len = GetCurrentDirectory(0, NULL);\r
277                 if (len)\r
278                 {\r
279                         TCHAR * originalCurrentDirectory = new TCHAR[len];\r
280                         if (GetCurrentDirectory(len, originalCurrentDirectory))\r
281                         {\r
282                                 sOrigCWD = originalCurrentDirectory;\r
283                                 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);\r
284                         }\r
285                         delete [] originalCurrentDirectory;\r
286                 }\r
287                 TCHAR pathbuf[MAX_PATH];\r
288                 GetTempPath(MAX_PATH, pathbuf);\r
289                 SetCurrentDirectory(pathbuf);           \r
290         }\r
291 \r
292         // check for newer versions\r
293         if (CRegDWORD(_T("Software\\TortoiseSVN\\CheckNewer"), TRUE) != FALSE)\r
294         {\r
295                 time_t now;\r
296                 struct tm ptm;\r
297 \r
298                 time(&now);\r
299                 if ((now != 0) && (localtime_s(&ptm, &now)==0))\r
300                 {\r
301                         int week = 0;\r
302                         // we don't calculate the real 'week of the year' here\r
303                         // because just to decide if we should check for an update\r
304                         // that's not needed.\r
305                         week = ptm.tm_yday / 7;\r
306 \r
307                         CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseSVN\\CheckNewerWeek"), (DWORD)-1);\r
308                         if (((DWORD)oldweek) == -1)\r
309                                 oldweek = week;         // first start of TortoiseProc, no update check needed\r
310                         else\r
311                         {\r
312                                 if ((DWORD)week != oldweek)\r
313                                 {\r
314                                         oldweek = week;\r
315 \r
316                                         TCHAR com[MAX_PATH+100];\r
317                                         GetModuleFileName(NULL, com, MAX_PATH);\r
318                                         _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));\r
319 \r
320                                         CAppUtils::LaunchApplication(com, 0, false);\r
321                                 }\r
322                         }\r
323                 }\r
324         }\r
325 \r
326         if (parser.HasVal(_T("configdir")))\r
327         {\r
328                 // the user can override the location of the Subversion config directory here\r
329                 CString sConfigDir = parser.GetVal(_T("configdir"));\r
330                 g_SVNGlobal.SetConfigDir(sConfigDir);\r
331         }\r
332         // to avoid that SASL will look for and load its plugin dlls all around the\r
333         // system, we set the path here.\r
334         // Note that SASL doesn't have to be initialized yet for this to work\r
335         sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::GetUTF8(CPathUtils::GetAppDirectory().TrimRight('\\')));\r
336 \r
337         HANDLE TSVNMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseProc.exe"));  \r
338         {\r
339                 CString err = SVN::CheckConfigFile();\r
340                 if (!err.IsEmpty())\r
341                 {\r
342                         CMessageBox::Show(hWndExplorer, err, _T("TortoiseSVN"), MB_ICONERROR);\r
343                         // Normally, we give-up and exit at this point, but there is a trap here\r
344                         // in that the user might need to use the settings dialog to edit the config file.\r
345                         if (CString(parser.GetVal(_T("command"))).Compare(_T("settings"))==0)\r
346                         {\r
347                                 // just open the config file\r
348                                 TCHAR buf[MAX_PATH];\r
349                                 SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buf);\r
350                                 CString path = buf;\r
351                                 path += _T("\\Subversion\\config");\r
352                                 CAppUtils::StartTextViewer(path);\r
353                                 return FALSE;\r
354                         }\r
355                 }\r
356         }\r
357 \r
358         // execute the requested command\r
359         CommandServer server;\r
360         Command * cmd = server.GetCommand(parser.GetVal(_T("command")));\r
361         if (cmd)\r
362         {\r
363                 cmd->SetExplorerHwnd(hWndExplorer);\r
364                 cmd->SetParser(parser);\r
365                 cmd->SetPaths(pathList, cmdLinePath);\r
366                 retSuccess = cmd->Execute();\r
367                 delete cmd;\r
368         }\r
369 \r
370         if (TSVNMutex)\r
371                 ::CloseHandle(TSVNMutex);\r
372 \r
373         // Look for temporary files left around by TortoiseSVN and\r
374         // remove them. But only delete 'old' files because some\r
375         // apps might still be needing the recent ones.\r
376         {\r
377                 DWORD len = ::GetTempPath(0, NULL);\r
378                 TCHAR * path = new TCHAR[len + 100];\r
379                 len = ::GetTempPath (len+100, path);\r
380                 if (len != 0)\r
381                 {\r
382                         CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));\r
383                         FILETIME systime_;\r
384                         ::GetSystemTimeAsFileTime(&systime_);\r
385                         __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);\r
386                         while (finder.FindNextFileNoDirectories())\r
387                         {\r
388                                 CString filepath = finder.GetFilePath();\r
389                                 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);\r
390                                 if (hFile != INVALID_HANDLE_VALUE)\r
391                                 {\r
392                                         FILETIME createtime_;\r
393                                         if (::GetFileTime(hFile, &createtime_, NULL, NULL))\r
394                                         {\r
395                                                 ::CloseHandle(hFile);\r
396                                                 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);\r
397                                                 if ((createtime + 864000000000) < systime)              //only delete files older than a day\r
398                                                 {\r
399                                                         ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);\r
400                                                         ::DeleteFile(filepath);\r
401                                                 }\r
402                                         }\r
403                                         else\r
404                                                 ::CloseHandle(hFile);\r
405                                 }\r
406                         }\r
407                 }       \r
408                 delete[] path;          \r
409         }\r
410 \r
411 \r
412         // Since the dialog has been closed, return FALSE so that we exit the\r
413         // application, rather than start the application's message pump.\r
414         return FALSE;\r
415 }\r
416 \r
417 \r
418 \r
419 void CTortoiseProcApp::CheckUpgrade()\r
420 {\r
421         CRegString regVersion = CRegString(_T("Software\\TortoiseSVN\\CurrentVersion"));\r
422         CString sVersion = regVersion;\r
423         if (sVersion.Compare(_T(STRPRODUCTVER))==0)\r
424                 return;\r
425         // we're starting the first time with a new version!\r
426         \r
427         LONG lVersion = 0;\r
428         int pos = sVersion.Find(',');\r
429         if (pos > 0)\r
430         {\r
431                 lVersion = (_ttol(sVersion.Left(pos))<<24);\r
432                 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);\r
433                 pos = sVersion.Find(',', pos+1);\r
434                 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);\r
435         }\r
436         \r
437         CRegDWORD regval = CRegDWORD(_T("Software\\TortoiseSVN\\DontConvertBase"), 999);\r
438         if ((DWORD)regval != 999)\r
439         {\r
440                 // there's a leftover registry setting we have to convert and then delete it\r
441                 CRegDWORD newregval = CRegDWORD(_T("Software\\TortoiseSVN\\ConvertBase"));\r
442                 newregval = !regval;\r
443                 regval.removeValue();\r
444         }\r
445 \r
446         if (lVersion <= 0x01010300)\r
447         {\r
448                 CSoundUtils::RegisterTSVNSounds();\r
449                 // remove all saved dialog positions\r
450                 CRegString(_T("Software\\TortoiseSVN\\TortoiseProc\\ResizableState\\")).removeKey();\r
451                 CRegDWORD(_T("Software\\TortoiseSVN\\RecursiveOverlay")).removeValue();\r
452                 // remove the external cache key\r
453                 CRegDWORD(_T("Software\\TortoiseSVN\\ExternalCache")).removeValue();\r
454         }\r
455         \r
456         if (lVersion <= 0x01020200)\r
457         {\r
458                 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js\r
459                 // so remove the diff/merge scripts if they're the defaults\r
460                 CRegString diffreg = CRegString(_T("Software\\TortoiseSVN\\DiffTools\\.doc"));\r
461                 CString sDiff = diffreg;\r
462                 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");\r
463                 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)\r
464                         diffreg = _T("");\r
465                 CRegString mergereg = CRegString(_T("Software\\TortoiseSVN\\MergeTools\\.doc"));\r
466                 sDiff = mergereg;\r
467                 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");\r
468                 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)\r
469                         mergereg = _T("");\r
470         }\r
471         if (lVersion <= 0x01040000)\r
472         {\r
473                 CRegStdWORD(_T("Software\\TortoiseSVN\\OwnerdrawnMenus")).removeValue();\r
474         }\r
475         \r
476         // set the custom diff scripts for every user\r
477         CString scriptsdir = CPathUtils::GetAppParentDirectory();\r
478         scriptsdir += _T("Diff-Scripts");\r
479         CSimpleFileFind files(scriptsdir);\r
480         while (files.FindNextFileNoDirectories())\r
481         {\r
482                 CString file = files.GetFilePath();\r
483                 CString filename = files.GetFileName();\r
484                 CString ext = file.Mid(file.ReverseFind('-')+1);\r
485                 ext = _T(".")+ext.Left(ext.ReverseFind('.'));\r
486                 CString kind;\r
487                 if (file.Right(3).CompareNoCase(_T("vbs"))==0)\r
488                 {\r
489                         kind = _T(" //E:vbscript");\r
490                 }\r
491                 if (file.Right(2).CompareNoCase(_T("js"))==0)\r
492                 {\r
493                         kind = _T(" //E:javascript");\r
494                 }\r
495                 \r
496                 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)\r
497                 {\r
498                         CRegString diffreg = CRegString(_T("Software\\TortoiseSVN\\DiffTools\\")+ext);\r
499                         CString diffregstring = diffreg;\r
500                         if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))\r
501                                 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;\r
502                 }\r
503                 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)\r
504                 {\r
505                         CRegString diffreg = CRegString(_T("Software\\TortoiseSVN\\MergeTools\\")+ext);\r
506                         CString diffregstring = diffreg;\r
507                         if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))\r
508                                 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;\r
509                 }\r
510         }\r
511 \r
512         // Initialize "Software\\TortoiseSVN\\DiffProps" once with the same value as "Software\\TortoiseSVN\\Diff"\r
513         CRegString regDiffPropsPath = CRegString(_T("Software\\TortoiseSVN\\DiffProps"),_T("non-existant"));\r
514         CString strDiffPropsPath = regDiffPropsPath;\r
515         if ( strDiffPropsPath==_T("non-existant") )\r
516         {\r
517                 CString strDiffPath = CRegString(_T("Software\\TortoiseSVN\\Diff"));\r
518                 regDiffPropsPath = strDiffPath;\r
519         }\r
520 \r
521         // set the current version so we don't come here again until the next update!\r
522         regVersion = _T(STRPRODUCTVER); \r
523 }\r
524 \r
525 void CTortoiseProcApp::EnableCrashHandler()\r
526 {\r
527         // the crash handler is enabled by default, but we disable it\r
528         // after 3 months after a release\r
529 \r
530 #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10  \\r
531               + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))\r
532 \r
533 #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6)      \\r
534                 : __DATE__ [2] == 'b' ? 2                               \\r
535                 : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4)   \\r
536                 : __DATE__ [2] == 'y' ? 5                                                               \\r
537                 : __DATE__ [2] == 'l' ? 7                               \\r
538                 : __DATE__ [2] == 'g' ? 8                               \\r
539                 : __DATE__ [2] == 'p' ? 9                               \\r
540                 : __DATE__ [2] == 't' ? 10                               \\r
541                 : __DATE__ [2] == 'v' ? 11 : 12)\r
542 \r
543  #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10       \\r
544               + (__DATE__ [5] - '0'))\r
545 \r
546  #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)\r
547 \r
548         CTime compiletime(YEAR, MONTH, DAY, 0, 0, 0);\r
549         CTime now = CTime::GetCurrentTime();\r
550 \r
551         CTimeSpan timediff = now-compiletime;\r
552         if (timediff.GetDays() > 3*31)\r
553         {\r
554                 crasher.Enable(FALSE);\r
555         }\r
556 }\r
557 \r
558 int CTortoiseProcApp::ExitInstance()\r
559 {\r
560         CWinAppEx::ExitInstance();\r
561         if (retSuccess)\r
562                 return 0;\r
563         return -1;\r
564 }\r