TortoiseSVN -> TortoiseGit
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob62a34b0c53a4f4f1df2b22daba79bfb25cce01e9
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - TortoiseGit
4 // Copyright (C) 2003-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 //#include "vld.h"
22 #include "TortoiseProc.h"
23 #include "SysImageList.h"
24 #include "CrashReport.h"
25 #include "CmdLineParser.h"
26 #include "Hooks.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "UnicodeUtils.h"
30 #include "MessageBox.h"
31 //#include "libintl.h"
32 #include "DirFileEnum.h"
33 //#include "SoundUtils.h"
34 //#include "SVN.h"
35 #include "GitAdminDir.h"
36 #include "Git.h"
37 //#include "SVNGlobal.h"
38 //#include "svn_types.h"
39 //#include "svn_dso.h"
40 //#include <openssl/ssl.h>
41 //#include <openssl/err.h>
43 #include "Commands\Command.h"
44 #include "CommonResource.h"
45 #include "..\version.h"
46 #include "JumpListHelpers.h"
47 #include "..\Settings\Settings.h"
48 #include "gitindex.h"
50 #define STRUCT_IOVEC_DEFINED
51 //#include "sasl.h"
53 #ifdef _DEBUG
54 #define new DEBUG_NEW
55 #endif
57 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
59 #define APPID (_T("TGIT.TGIT.1") _T(TSVN_PLATFORM))
61 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
62 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
63 END_MESSAGE_MAP()
65 //CString g_version;
66 //CString CGit::m_MsysGitPath;
67 //////////////////////////////////////////////////////////////////////////
69 CTortoiseProcApp::CTortoiseProcApp()
71 EnableHtmlHelp();
72 // int argc = 0;
73 // const char* const * argv = NULL;
74 // apr_app_initialize(&argc, &argv, NULL);
75 // svn_dso_initialize2();
76 SYS_IMAGE_LIST();
77 CHooks::Create();
78 g_GitAdminDir.Init();
79 m_bLoadUserToolbars = FALSE;
80 m_bSaveState = FALSE;
81 retSuccess = false;
85 CTortoiseProcApp::~CTortoiseProcApp()
87 // global application exit cleanup (after all SSL activity is shutdown)
88 // we have to clean up SSL ourselves, since neon doesn't do that (can't do it)
89 // because those cleanup functions work globally per process.
90 //ERR_free_strings();
91 //EVP_cleanup();
92 //CRYPTO_cleanup_all_ex_data();
94 // since it is undefined *when* the global object SVNAdminDir is
95 // destroyed, we tell it to destroy the memory pools and terminate apr
96 // *now* instead of later when the object itself is destroyed.
97 g_GitAdminDir.Close();
98 CHooks::Destroy();
99 SYS_IMAGE_LIST().Cleanup();
100 //apr_terminate();
103 // The one and only CTortoiseProcApp object
104 CTortoiseProcApp theApp;
105 HWND hWndExplorer;
107 BOOL CTortoiseProcApp::CheckMsysGitDir()
109 CGitIndexFileMap map;
110 //int status;
111 //CTGitPath path;
112 //path.SetFromGit(_T("src/gpl.txt"));
113 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
114 return g_Git.CheckMsysGitDir();
116 CCrashReport crasher("tortoisegit-bug@googlegroups.com", "Crash Report for TortoiseGit " APP_X64_STRING " : " STRPRODUCTVER, TRUE);// crash
118 // CTortoiseProcApp initialization
120 BOOL CTortoiseProcApp::InitInstance()
122 EnableCrashHandler();
123 InitializeJumpList();
124 CheckUpgrade();
125 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
126 CMFCButton::EnableWindowsTheming();
128 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
129 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
131 if(!CheckMsysGitDir())
133 UINT ret = CMessageBox::Show(NULL,_T("MSysGit (http://code.google.com/p/msysgit/) not found."),
134 _T("TortoiseGit"), 3, IDI_HAND, _T("&Set MSysGit path"), _T("&Goto WebSite"), _T("&Abort"));
135 if(ret == 2)
137 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
139 else if(ret == 1)
141 // open settings dialog
142 CSettings dlg(IDS_PROC_SETTINGS_TITLE);
143 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
144 dlg.SetTreeWidth(220);
146 dlg.DoModal();
147 dlg.HandleRestart();
149 return FALSE;
152 //set the resource dll for the required language
153 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
154 long langId = loc;
155 CString langDll;
156 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
157 langpath += "Languages";
158 // bindtextdomain("subversion", (LPCSTR)langpath);
159 // bind_textdomain_codeset("subversion", "UTF-8");
160 HINSTANCE hInst = NULL;
163 langDll.Format(_T("..\\Languages\\TortoiseProc%d.dll"), langId);
165 hInst = LoadLibrary(langDll);
167 CString sVer = _T(STRPRODUCTVER);
168 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
169 if (sFileVer.Compare(sVer)!=0)
171 FreeLibrary(hInst);
172 hInst = NULL;
174 if (hInst != NULL)
176 AfxSetResourceHandle(hInst);
178 else
180 DWORD lid = SUBLANGID(langId);
181 lid--;
182 if (lid > 0)
184 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
186 else
187 langId = 0;
189 } while ((hInst == NULL) && (langId != 0));
190 TCHAR buf[6];
191 _tcscpy_s(buf, _T("en"));
192 langId = loc;
193 CString sHelppath;
194 sHelppath = this->m_pszHelpFilePath;
195 sHelppath = sHelppath.MakeLower();
196 // MFC uses a help file with the same name as the application by default,
197 // which means we have to change that default to our language specific help files
198 sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseGit_en.chm"));
199 free((void*)m_pszHelpFilePath);
200 m_pszHelpFilePath=_tcsdup(sHelppath);
201 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
204 CString sLang = _T("_");
205 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, sizeof(buf)))
207 sLang += buf;
208 sHelppath.Replace(_T("_en"), sLang);
209 if (PathFileExists(sHelppath))
211 free((void*)m_pszHelpFilePath);
212 m_pszHelpFilePath=_tcsdup(sHelppath);
213 break;
216 sHelppath.Replace(sLang, _T("_en"));
217 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, sizeof(buf)))
219 sLang += _T("_");
220 sLang += buf;
221 sHelppath.Replace(_T("_en"), sLang);
222 if (PathFileExists(sHelppath))
224 free((void*)m_pszHelpFilePath);
225 m_pszHelpFilePath=_tcsdup(sHelppath);
226 break;
229 sHelppath.Replace(sLang, _T("_en"));
231 DWORD lid = SUBLANGID(langId);
232 lid--;
233 if (lid > 0)
235 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
237 else
238 langId = 0;
239 } while (langId);
240 setlocale(LC_ALL, "");
242 // InitCommonControls() is required on Windows XP if an application
243 // manifest specifies use of ComCtl32.dll version 6 or later to enable
244 // visual styles. Otherwise, any window creation will fail.
246 INITCOMMONCONTROLSEX used = {
247 sizeof(INITCOMMONCONTROLSEX),
248 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
249 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
250 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
251 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
252 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
254 InitCommonControlsEx(&used);
255 AfxOleInit();
256 AfxEnableControlContainer();
257 AfxInitRichEdit2();
258 CWinAppEx::InitInstance();
259 SetRegistryKey(_T("TortoiseGit"));
261 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
263 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
264 // in a message box
265 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
266 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
268 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
270 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
271 return FALSE;
274 CTGitPath cmdLinePath;
275 CTGitPathList pathList;
276 if ( parser.HasKey(_T("pathfile")) )
279 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
281 cmdLinePath.SetFromUnknown(sPathfileArgument);
282 if (pathList.LoadFromFile(cmdLinePath)==false)
283 return FALSE; // no path specified!
284 if ( parser.HasKey(_T("deletepathfile")) )
286 // We can delete the temporary path file, now that we've loaded it
287 ::DeleteFile(cmdLinePath.GetWinPath());
289 // This was a path to a temporary file - it's got no meaning now, and
290 // anybody who uses it again is in for a problem...
291 cmdLinePath.Reset();
294 else
297 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
298 int asterisk = sPathArgument.Find('*');
299 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
300 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
303 if (pathList.GetCount() == 0) {
304 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
307 hWndExplorer = NULL;
308 CString sVal = parser.GetVal(_T("hwnd"));
309 if (!sVal.IsEmpty())
310 hWndExplorer = (HWND)_ttoi64(sVal);
312 while (GetParent(hWndExplorer)!=NULL)
313 hWndExplorer = GetParent(hWndExplorer);
314 if (!IsWindow(hWndExplorer))
316 hWndExplorer = NULL;
319 // Subversion sometimes writes temp files to the current directory!
320 // Since TSVN doesn't need a specific CWD anyway, we just set it
321 // to the users temp folder: that way, Subversion is guaranteed to
322 // have write access to the CWD
324 DWORD len = GetCurrentDirectory(0, NULL);
325 if (len)
327 TCHAR * originalCurrentDirectory = new TCHAR[len];
328 if (GetCurrentDirectory(len, originalCurrentDirectory))
330 //sOrigCWD = originalCurrentDirectory;
331 //sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
333 delete [] originalCurrentDirectory;
335 TCHAR pathbuf[MAX_PATH];
336 GetTempPath(MAX_PATH, pathbuf);
337 SetCurrentDirectory(pathbuf);
340 // check for newer versions
341 if (CRegDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) != FALSE)
343 time_t now;
344 struct tm ptm;
346 time(&now);
347 if ((now != 0) && (localtime_s(&ptm, &now)==0))
349 int week = 0;
350 // we don't calculate the real 'week of the year' here
351 // because just to decide if we should check for an update
352 // that's not needed.
353 week = ptm.tm_yday / 7;
355 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
356 if (((DWORD)oldweek) == -1)
357 oldweek = week; // first start of TortoiseProc, no update check needed
358 else
360 if ((DWORD)week != oldweek)
362 oldweek = week;
364 TCHAR com[MAX_PATH+100];
365 GetModuleFileName(NULL, com, MAX_PATH);
366 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
368 CAppUtils::LaunchApplication(com, 0, false);
374 if (parser.HasVal(_T("configdir")))
376 // the user can override the location of the Subversion config directory here
377 CString sConfigDir = parser.GetVal(_T("configdir"));
378 // g_GitGlobal.SetConfigDir(sConfigDir);
380 // to avoid that SASL will look for and load its plugin dlls all around the
381 // system, we set the path here.
382 // Note that SASL doesn't have to be initialized yet for this to work
383 // sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::GetUTF8(CPathUtils::GetAppDirectory().TrimRight('\\')));
385 HANDLE TSVNMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
386 if(!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString()))
388 int i=0;
389 for(i=0;i<pathList.GetCount();i++)
390 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
391 break;
394 if(!g_Git.m_CurrentDir.IsEmpty())
395 SetCurrentDirectory(g_Git.m_CurrentDir);
398 CString err;
401 // requires CWD to be set
402 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
404 catch (char* msg)
406 err = CString(msg);
409 if (!err.IsEmpty())
411 UINT choice = CMessageBox::Show(hWndExplorer, err, _T("TortoiseGit Error"), 1, IDI_ERROR, _T("&Edit .git/config"), _T("Edit &global .gitconfig"), _T("&Abort"));
412 if (choice == 1)
414 // open the config file with alternative editor
415 CString path = g_Git.m_CurrentDir;
416 path += _T("\\.git\\config");
417 CAppUtils::LaunchAlternativeEditor(path);
419 else if (choice == 2)
421 // open the global config file with alternative editor
422 TCHAR buf[MAX_PATH];
423 SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, buf);
424 CString path = buf;
425 path += _T("\\.gitconfig");
426 CAppUtils::LaunchAlternativeEditor(path);
428 return FALSE;
432 // execute the requested command
433 CommandServer server;
434 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
435 if (cmd)
437 cmd->SetExplorerHwnd(hWndExplorer);
439 cmd->SetParser(parser);
440 cmd->SetPaths(pathList, cmdLinePath);
442 retSuccess = cmd->Execute();
443 delete cmd;
446 if (TSVNMutex)
447 ::CloseHandle(TSVNMutex);
449 // Look for temporary files left around by TortoiseSVN and
450 // remove them. But only delete 'old' files because some
451 // apps might still be needing the recent ones.
453 DWORD len = ::GetTempPath(0, NULL);
454 TCHAR * path = new TCHAR[len + 100];
455 len = ::GetTempPath (len+100, path);
456 if (len != 0)
458 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
459 FILETIME systime_;
460 ::GetSystemTimeAsFileTime(&systime_);
461 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
462 while (finder.FindNextFileNoDirectories())
464 CString filepath = finder.GetFilePath();
465 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
466 if (hFile != INVALID_HANDLE_VALUE)
468 FILETIME createtime_;
469 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
471 ::CloseHandle(hFile);
472 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
473 if ((createtime + 864000000000) < systime) //only delete files older than a day
475 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
476 ::DeleteFile(filepath);
479 else
480 ::CloseHandle(hFile);
484 delete[] path;
487 // Since the dialog has been closed, return FALSE so that we exit the
488 // application, rather than start the application's message pump.
489 return FALSE;
492 void CTortoiseProcApp::CheckUpgrade()
494 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
495 CString sVersion = regVersion;
496 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
497 return;
498 // we're starting the first time with a new version!
500 LONG lVersion = 0;
501 int pos = sVersion.Find(',');
502 if (pos > 0)
504 lVersion = (_ttol(sVersion.Left(pos))<<24);
505 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
506 pos = sVersion.Find(',', pos+1);
507 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
510 CRegDWORD regval = CRegDWORD(_T("Software\\TortoiseGit\\DontConvertBase"), 999);
511 if ((DWORD)regval != 999)
513 // there's a leftover registry setting we have to convert and then delete it
514 CRegDWORD newregval = CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"));
515 newregval = !regval;
516 regval.removeValue();
518 #if 0
519 if (lVersion <= 0x01010300)
521 CSoundUtils::RegisterTSVNSounds();
522 // remove all saved dialog positions
523 CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\")).removeKey();
524 CRegDWORD(_T("Software\\TortoiseGit\\RecursiveOverlay")).removeValue();
525 // remove the external cache key
526 CRegDWORD(_T("Software\\TortoiseGit\\ExternalCache")).removeValue();
528 #endif
529 if (lVersion <= 0x01020200)
531 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
532 // so remove the diff/merge scripts if they're the defaults
533 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
534 CString sDiff = diffreg;
535 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
536 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
537 diffreg = _T("");
538 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
539 sDiff = mergereg;
540 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
541 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
542 mergereg = _T("");
544 if (lVersion <= 0x01040000)
546 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
549 // set the custom diff scripts for every user
550 CString scriptsdir = CPathUtils::GetAppParentDirectory();
551 scriptsdir += _T("Diff-Scripts");
552 CSimpleFileFind files(scriptsdir);
553 while (files.FindNextFileNoDirectories())
555 CString file = files.GetFilePath();
556 CString filename = files.GetFileName();
557 CString ext = file.Mid(file.ReverseFind('-')+1);
558 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
559 CString kind;
560 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
562 kind = _T(" //E:vbscript");
564 if (file.Right(2).CompareNoCase(_T("js"))==0)
566 kind = _T(" //E:javascript");
569 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
571 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
572 CString diffregstring = diffreg;
573 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
574 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
576 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
578 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
579 CString diffregstring = diffreg;
580 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
581 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
585 // Initialize "Software\\TortoiseGit\\DiffProps" once with the same value as "Software\\TortoiseGit\\Diff"
586 CRegString regDiffPropsPath = CRegString(_T("Software\\TortoiseGit\\DiffProps"),_T("non-existant"));
587 CString strDiffPropsPath = regDiffPropsPath;
588 if ( strDiffPropsPath==_T("non-existant") )
590 CString strDiffPath = CRegString(_T("Software\\TortoiseGit\\Diff"));
591 regDiffPropsPath = strDiffPath;
594 // set the current version so we don't come here again until the next update!
595 regVersion = _T(STRPRODUCTVER);
598 void CTortoiseProcApp::EnableCrashHandler()
600 // the crash handler is enabled by default, but we disable it
601 // after 3 months after a release
603 #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
604 + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
606 #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
607 : __DATE__ [2] == 'b' ? 2 \
608 : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
609 : __DATE__ [2] == 'y' ? 5 \
610 : __DATE__ [2] == 'l' ? 7 \
611 : __DATE__ [2] == 'g' ? 8 \
612 : __DATE__ [2] == 'p' ? 9 \
613 : __DATE__ [2] == 't' ? 10 \
614 : __DATE__ [2] == 'v' ? 11 : 12)
616 #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
617 + (__DATE__ [5] - '0'))
619 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
621 CTime compiletime(YEAR, MONTH, DAY, 0, 0, 0);
622 CTime now = CTime::GetCurrentTime();
624 CTimeSpan timediff = now-compiletime;
625 if (timediff.GetDays() > 3*31)
627 // crasher.Enable(FALSE);
631 void CTortoiseProcApp::InitializeJumpList()
633 // for Win7 : use a custom jump list
634 CoInitialize(NULL);
635 SetAppID(APPID);
636 DeleteJumpList(APPID);
637 DoInitializeJumpList();
638 CoUninitialize();
641 void CTortoiseProcApp::DoInitializeJumpList()
643 ATL::CComPtr<ICustomDestinationList> pcdl;
644 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
645 if (FAILED(hr))
646 return;
648 hr = pcdl->SetAppID(APPID);
649 if (FAILED(hr))
650 return;
652 UINT uMaxSlots;
653 ATL::CComPtr<IObjectArray> poaRemoved;
654 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
655 if (FAILED(hr))
656 return;
658 ATL::CComPtr<IObjectCollection> poc;
659 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
660 if (FAILED(hr))
661 return;
663 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
664 sTemp.Remove('&');
666 ATL::CComPtr<IShellLink> psl;
667 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
668 if (SUCCEEDED(hr)) {
669 poc->AddObject(psl);
671 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
672 sTemp.Remove('&');
673 psl.Release(); // Need to release the object before calling operator&()
674 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
675 if (SUCCEEDED(hr)) {
676 poc->AddObject(psl);
679 ATL::CComPtr<IObjectArray> poa;
680 hr = poc.QueryInterface(&poa);
681 if (SUCCEEDED(hr)) {
682 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
683 pcdl->CommitList();
687 int CTortoiseProcApp::ExitInstance()
689 Gdiplus::GdiplusShutdown(m_gdiplusToken);
691 CWinAppEx::ExitInstance();
692 if (retSuccess)
693 return 0;
694 return -1;