OSDN Git Service

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