OSDN Git Service

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