OSDN Git Service

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