OSDN Git Service

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