OSDN Git Service

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