OSDN Git Service

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