OSDN Git Service

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