Fixed issue #922: Settings / Git / Config / Edit global .gitconfig uses wrong path
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob07403174d57b956d85aa89bb8846904df91c046d
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 SetDllDirectory(L"");
72 EnableHtmlHelp();
73 // int argc = 0;
74 // const char* const * argv = NULL;
75 // apr_app_initialize(&argc, &argv, NULL);
76 // svn_dso_initialize2();
77 SYS_IMAGE_LIST();
78 CHooks::Create();
79 g_GitAdminDir.Init();
80 m_bLoadUserToolbars = FALSE;
81 m_bSaveState = FALSE;
82 retSuccess = false;
86 CTortoiseProcApp::~CTortoiseProcApp()
88 // global application exit cleanup (after all SSL activity is shutdown)
89 // we have to clean up SSL ourselves, since neon doesn't do that (can't do it)
90 // because those cleanup functions work globally per process.
91 //ERR_free_strings();
92 //EVP_cleanup();
93 //CRYPTO_cleanup_all_ex_data();
95 // since it is undefined *when* the global object SVNAdminDir is
96 // destroyed, we tell it to destroy the memory pools and terminate apr
97 // *now* instead of later when the object itself is destroyed.
98 g_GitAdminDir.Close();
99 CHooks::Destroy();
100 SYS_IMAGE_LIST().Cleanup();
101 //apr_terminate();
104 // The one and only CTortoiseProcApp object
105 CTortoiseProcApp theApp;
106 HWND hWndExplorer;
108 BOOL CTortoiseProcApp::CheckMsysGitDir()
110 CGitIndexFileMap map;
111 //int status;
112 //CTGitPath path;
113 //path.SetFromGit(_T("src/gpl.txt"));
114 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
115 return g_Git.CheckMsysGitDir();
117 CCrashReport crasher("tortoisegit-bug@googlegroups.com", "Crash Report for TortoiseGit " APP_X64_STRING " : " STRPRODUCTVER, TRUE);// crash
119 // CTortoiseProcApp initialization
121 BOOL CTortoiseProcApp::InitInstance()
123 EnableCrashHandler();
124 InitializeJumpList();
125 CheckUpgrade();
126 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
127 CMFCButton::EnableWindowsTheming();
129 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
130 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
132 if(!CheckMsysGitDir())
134 UINT ret = CMessageBox::Show(NULL,_T("MSysGit (http://code.google.com/p/msysgit/) not found."),
135 _T("TortoiseGit"), 3, IDI_HAND, _T("&Set MSysGit path"), _T("&Goto WebSite"), _T("&Abort"));
136 if(ret == 2)
138 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
140 else if(ret == 1)
142 // open settings dialog
143 CSettings dlg(IDS_PROC_SETTINGS_TITLE);
144 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
145 dlg.SetTreeWidth(220);
147 dlg.DoModal();
148 dlg.HandleRestart();
150 return FALSE;
153 //set the resource dll for the required language
154 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
155 long langId = loc;
156 CString langDll;
157 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
158 langpath += "Languages";
159 // bindtextdomain("subversion", (LPCSTR)langpath);
160 // bind_textdomain_codeset("subversion", "UTF-8");
161 HINSTANCE hInst = NULL;
164 langDll.Format(_T("..\\Languages\\TortoiseProc%d.dll"), langId);
166 hInst = LoadLibrary(langDll);
168 CString sVer = _T(STRPRODUCTVER);
169 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
170 if (sFileVer.Compare(sVer)!=0)
172 FreeLibrary(hInst);
173 hInst = NULL;
175 if (hInst != NULL)
177 AfxSetResourceHandle(hInst);
179 else
181 DWORD lid = SUBLANGID(langId);
182 lid--;
183 if (lid > 0)
185 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
187 else
188 langId = 0;
190 } while ((hInst == NULL) && (langId != 0));
191 TCHAR buf[6];
192 _tcscpy_s(buf, _T("en"));
193 langId = loc;
194 CString sHelppath;
195 sHelppath = this->m_pszHelpFilePath;
196 sHelppath = sHelppath.MakeLower();
197 // MFC uses a help file with the same name as the application by default,
198 // which means we have to change that default to our language specific help files
199 sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseGit_en.chm"));
200 free((void*)m_pszHelpFilePath);
201 m_pszHelpFilePath=_tcsdup(sHelppath);
202 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
205 CString sLang = _T("_");
206 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
208 sLang += buf;
209 sHelppath.Replace(_T("_en"), sLang);
210 if (PathFileExists(sHelppath))
212 free((void*)m_pszHelpFilePath);
213 m_pszHelpFilePath=_tcsdup(sHelppath);
214 break;
217 sHelppath.Replace(sLang, _T("_en"));
218 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
220 sLang += _T("_");
221 sLang += buf;
222 sHelppath.Replace(_T("_en"), sLang);
223 if (PathFileExists(sHelppath))
225 free((void*)m_pszHelpFilePath);
226 m_pszHelpFilePath=_tcsdup(sHelppath);
227 break;
230 sHelppath.Replace(sLang, _T("_en"));
232 DWORD lid = SUBLANGID(langId);
233 lid--;
234 if (lid > 0)
236 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
238 else
239 langId = 0;
240 } while (langId);
241 setlocale(LC_ALL, "");
243 // InitCommonControls() is required on Windows XP if an application
244 // manifest specifies use of ComCtl32.dll version 6 or later to enable
245 // visual styles. Otherwise, any window creation will fail.
247 INITCOMMONCONTROLSEX used = {
248 sizeof(INITCOMMONCONTROLSEX),
249 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
250 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
251 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
252 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
253 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
255 InitCommonControlsEx(&used);
256 AfxOleInit();
257 AfxEnableControlContainer();
258 AfxInitRichEdit2();
259 CWinAppEx::InitInstance();
260 SetRegistryKey(_T("TortoiseGit"));
262 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
264 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
265 // in a message box
266 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
267 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
269 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
271 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
272 return FALSE;
275 CTGitPath cmdLinePath;
276 CTGitPathList pathList;
277 if ( parser.HasKey(_T("pathfile")) )
280 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
282 cmdLinePath.SetFromUnknown(sPathfileArgument);
283 if (pathList.LoadFromFile(cmdLinePath)==false)
284 return FALSE; // no path specified!
285 if ( parser.HasKey(_T("deletepathfile")) )
287 // We can delete the temporary path file, now that we've loaded it
288 ::DeleteFile(cmdLinePath.GetWinPath());
290 // This was a path to a temporary file - it's got no meaning now, and
291 // anybody who uses it again is in for a problem...
292 cmdLinePath.Reset();
295 else
298 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
299 int asterisk = sPathArgument.Find('*');
300 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
301 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
304 if (pathList.GetCount() == 0) {
305 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
308 hWndExplorer = NULL;
309 CString sVal = parser.GetVal(_T("hwnd"));
310 if (!sVal.IsEmpty())
311 hWndExplorer = (HWND)_ttoi64(sVal);
313 while (GetParent(hWndExplorer)!=NULL)
314 hWndExplorer = GetParent(hWndExplorer);
315 if (!IsWindow(hWndExplorer))
317 hWndExplorer = NULL;
320 // Subversion sometimes writes temp files to the current directory!
321 // Since TSVN doesn't need a specific CWD anyway, we just set it
322 // to the users temp folder: that way, Subversion is guaranteed to
323 // have write access to the CWD
325 DWORD len = GetCurrentDirectory(0, NULL);
326 if (len)
328 TCHAR * originalCurrentDirectory = new TCHAR[len];
329 if (GetCurrentDirectory(len, originalCurrentDirectory))
331 //sOrigCWD = originalCurrentDirectory;
332 //sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
334 delete [] originalCurrentDirectory;
336 TCHAR pathbuf[MAX_PATH];
337 GetTempPath(MAX_PATH, pathbuf);
338 SetCurrentDirectory(pathbuf);
341 // check for newer versions
342 if (CRegDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) != FALSE)
344 time_t now;
345 struct tm ptm;
347 time(&now);
348 if ((now != 0) && (localtime_s(&ptm, &now)==0))
350 int week = 0;
351 // we don't calculate the real 'week of the year' here
352 // because just to decide if we should check for an update
353 // that's not needed.
354 week = ptm.tm_yday / 7;
356 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
357 if (((DWORD)oldweek) == -1)
358 oldweek = week; // first start of TortoiseProc, no update check needed
359 else
361 if ((DWORD)week != oldweek)
363 oldweek = week;
365 TCHAR com[MAX_PATH+100];
366 GetModuleFileName(NULL, com, MAX_PATH);
367 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
369 CAppUtils::LaunchApplication(com, 0, false);
375 if (parser.HasVal(_T("configdir")))
377 // the user can override the location of the Subversion config directory here
378 CString sConfigDir = parser.GetVal(_T("configdir"));
379 // g_GitGlobal.SetConfigDir(sConfigDir);
381 // to avoid that SASL will look for and load its plugin dlls all around the
382 // system, we set the path here.
383 // Note that SASL doesn't have to be initialized yet for this to work
384 // sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::GetUTF8(CPathUtils::GetAppDirectory().TrimRight('\\')));
386 HANDLE TSVNMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
387 if(!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString()))
389 int i=0;
390 for(i=0;i<pathList.GetCount();i++)
391 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
392 break;
395 if(!g_Git.m_CurrentDir.IsEmpty())
396 SetCurrentDirectory(g_Git.m_CurrentDir);
399 CString err;
402 // requires CWD to be set
403 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
405 catch (char* msg)
407 err = CString(msg);
410 if (!err.IsEmpty())
412 UINT choice = CMessageBox::Show(hWndExplorer, err, _T("TortoiseGit Error"), 1, IDI_ERROR, _T("&Edit .git/config"), _T("Edit &global .gitconfig"), _T("&Abort"));
413 if (choice == 1)
415 // open the config file with alternative editor
416 CString path = g_Git.m_CurrentDir;
417 path += _T("\\.git\\config");
418 CAppUtils::LaunchAlternativeEditor(path);
420 else if (choice == 2)
422 // open the global config file with alternative editor
423 TCHAR buf[MAX_PATH];
424 ExpandEnvironmentStrings(_T("%HOMEDRIVE%\\%HOMEPATH%\\.gitconfig"), buf, MAX_PATH);
425 CAppUtils::LaunchAlternativeEditor(buf);
427 return FALSE;
431 // execute the requested command
432 CommandServer server;
433 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
434 if (cmd)
436 cmd->SetExplorerHwnd(hWndExplorer);
438 cmd->SetParser(parser);
439 cmd->SetPaths(pathList, cmdLinePath);
441 retSuccess = cmd->Execute();
442 delete cmd;
445 if (TSVNMutex)
446 ::CloseHandle(TSVNMutex);
448 // Look for temporary files left around by TortoiseSVN and
449 // remove them. But only delete 'old' files because some
450 // apps might still be needing the recent ones.
452 DWORD len = ::GetTempPath(0, NULL);
453 TCHAR * path = new TCHAR[len + 100];
454 len = ::GetTempPath (len+100, path);
455 if (len != 0)
457 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
458 FILETIME systime_;
459 ::GetSystemTimeAsFileTime(&systime_);
460 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
461 while (finder.FindNextFileNoDirectories())
463 CString filepath = finder.GetFilePath();
464 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
465 if (hFile != INVALID_HANDLE_VALUE)
467 FILETIME createtime_;
468 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
470 ::CloseHandle(hFile);
471 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
472 if ((createtime + 864000000000) < systime) //only delete files older than a day
474 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
475 ::DeleteFile(filepath);
478 else
479 ::CloseHandle(hFile);
483 delete[] path;
486 // Since the dialog has been closed, return FALSE so that we exit the
487 // application, rather than start the application's message pump.
488 return FALSE;
491 void CTortoiseProcApp::CheckUpgrade()
493 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
494 CString sVersion = regVersion;
495 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
496 return;
497 // we're starting the first time with a new version!
499 LONG lVersion = 0;
500 int pos = sVersion.Find(',');
501 if (pos > 0)
503 lVersion = (_ttol(sVersion.Left(pos))<<24);
504 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
505 pos = sVersion.Find(',', pos+1);
506 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
509 CRegDWORD regval = CRegDWORD(_T("Software\\TortoiseGit\\DontConvertBase"), 999);
510 if ((DWORD)regval != 999)
512 // there's a leftover registry setting we have to convert and then delete it
513 CRegDWORD newregval = CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"));
514 newregval = !regval;
515 regval.removeValue();
517 #if 0
518 if (lVersion <= 0x01010300)
520 CSoundUtils::RegisterTSVNSounds();
521 // remove all saved dialog positions
522 CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\")).removeKey();
523 CRegDWORD(_T("Software\\TortoiseGit\\RecursiveOverlay")).removeValue();
524 // remove the external cache key
525 CRegDWORD(_T("Software\\TortoiseGit\\ExternalCache")).removeValue();
527 #endif
528 if (lVersion <= 0x01020200)
530 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
531 // so remove the diff/merge scripts if they're the defaults
532 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
533 CString sDiff = diffreg;
534 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
535 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
536 diffreg = _T("");
537 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
538 sDiff = mergereg;
539 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
540 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
541 mergereg = _T("");
543 if (lVersion <= 0x01040000)
545 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
548 // set the custom diff scripts for every user
549 CString scriptsdir = CPathUtils::GetAppParentDirectory();
550 scriptsdir += _T("Diff-Scripts");
551 CSimpleFileFind files(scriptsdir);
552 while (files.FindNextFileNoDirectories())
554 CString file = files.GetFilePath();
555 CString filename = files.GetFileName();
556 CString ext = file.Mid(file.ReverseFind('-')+1);
557 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
558 CString kind;
559 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
561 kind = _T(" //E:vbscript");
563 if (file.Right(2).CompareNoCase(_T("js"))==0)
565 kind = _T(" //E:javascript");
568 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
570 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
571 CString diffregstring = diffreg;
572 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
573 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
575 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
577 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
578 CString diffregstring = diffreg;
579 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
580 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
584 // Initialize "Software\\TortoiseGit\\DiffProps" once with the same value as "Software\\TortoiseGit\\Diff"
585 CRegString regDiffPropsPath = CRegString(_T("Software\\TortoiseGit\\DiffProps"),_T("non-existant"));
586 CString strDiffPropsPath = regDiffPropsPath;
587 if ( strDiffPropsPath==_T("non-existant") )
589 CString strDiffPath = CRegString(_T("Software\\TortoiseGit\\Diff"));
590 regDiffPropsPath = strDiffPath;
593 // set the current version so we don't come here again until the next update!
594 regVersion = _T(STRPRODUCTVER);
597 void CTortoiseProcApp::EnableCrashHandler()
599 // the crash handler is enabled by default, but we disable it
600 // after 3 months after a release
602 #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
603 + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
605 #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
606 : __DATE__ [2] == 'b' ? 2 \
607 : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
608 : __DATE__ [2] == 'y' ? 5 \
609 : __DATE__ [2] == 'l' ? 7 \
610 : __DATE__ [2] == 'g' ? 8 \
611 : __DATE__ [2] == 'p' ? 9 \
612 : __DATE__ [2] == 't' ? 10 \
613 : __DATE__ [2] == 'v' ? 11 : 12)
615 #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
616 + (__DATE__ [5] - '0'))
618 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
620 CTime compiletime(YEAR, MONTH, DAY, 0, 0, 0);
621 CTime now = CTime::GetCurrentTime();
623 CTimeSpan timediff = now-compiletime;
624 if (timediff.GetDays() > 3*31)
626 // crasher.Enable(FALSE);
630 void CTortoiseProcApp::InitializeJumpList()
632 // for Win7 : use a custom jump list
633 CoInitialize(NULL);
634 SetAppID(APPID);
635 DeleteJumpList(APPID);
636 DoInitializeJumpList();
637 CoUninitialize();
640 void CTortoiseProcApp::DoInitializeJumpList()
642 ATL::CComPtr<ICustomDestinationList> pcdl;
643 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
644 if (FAILED(hr))
645 return;
647 hr = pcdl->SetAppID(APPID);
648 if (FAILED(hr))
649 return;
651 UINT uMaxSlots;
652 ATL::CComPtr<IObjectArray> poaRemoved;
653 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
654 if (FAILED(hr))
655 return;
657 ATL::CComPtr<IObjectCollection> poc;
658 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
659 if (FAILED(hr))
660 return;
662 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
663 sTemp.Remove('&');
665 ATL::CComPtr<IShellLink> psl;
666 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
667 if (SUCCEEDED(hr)) {
668 poc->AddObject(psl);
670 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
671 sTemp.Remove('&');
672 psl.Release(); // Need to release the object before calling operator&()
673 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
674 if (SUCCEEDED(hr)) {
675 poc->AddObject(psl);
678 ATL::CComPtr<IObjectArray> poa;
679 hr = poc.QueryInterface(&poa);
680 if (SUCCEEDED(hr)) {
681 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
682 pcdl->CommitList();
686 int CTortoiseProcApp::ExitInstance()
688 Gdiplus::GdiplusShutdown(m_gdiplusToken);
690 CWinAppEx::ExitInstance();
691 if (retSuccess)
692 return 0;
693 return -1;