Fixed issue #933: implement git stash --include-untracked
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob6061b059cc8009dc25956c2f477e8d1b1d639891
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(TGIT_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 char charBuf[MAX_PATH];
424 TCHAR buf[MAX_PATH];
425 strcpy_s(charBuf, MAX_PATH, get_windows_home_directory());
426 _tcscpy_s(buf, MAX_PATH, CA2CT(charBuf));
427 _tcscat_s(buf, MAX_PATH, _T("\\.gitconfig"));
428 CAppUtils::LaunchAlternativeEditor(buf);
430 return FALSE;
434 // execute the requested command
435 CommandServer server;
436 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
437 if (cmd)
439 cmd->SetExplorerHwnd(hWndExplorer);
441 cmd->SetParser(parser);
442 cmd->SetPaths(pathList, cmdLinePath);
444 retSuccess = cmd->Execute();
445 delete cmd;
448 if (TSVNMutex)
449 ::CloseHandle(TSVNMutex);
451 // Look for temporary files left around by TortoiseSVN and
452 // remove them. But only delete 'old' files because some
453 // apps might still be needing the recent ones.
455 DWORD len = ::GetTempPath(0, NULL);
456 TCHAR * path = new TCHAR[len + 100];
457 len = ::GetTempPath (len+100, path);
458 if (len != 0)
460 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
461 FILETIME systime_;
462 ::GetSystemTimeAsFileTime(&systime_);
463 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
464 while (finder.FindNextFileNoDirectories())
466 CString filepath = finder.GetFilePath();
467 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
468 if (hFile != INVALID_HANDLE_VALUE)
470 FILETIME createtime_;
471 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
473 ::CloseHandle(hFile);
474 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
475 if ((createtime + 864000000000) < systime) //only delete files older than a day
477 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
478 ::DeleteFile(filepath);
481 else
482 ::CloseHandle(hFile);
486 delete[] path;
489 // Since the dialog has been closed, return FALSE so that we exit the
490 // application, rather than start the application's message pump.
491 return FALSE;
494 void CTortoiseProcApp::CheckUpgrade()
496 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
497 CString sVersion = regVersion;
498 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
499 return;
500 // we're starting the first time with a new version!
502 LONG lVersion = 0;
503 int pos = sVersion.Find(',');
504 if (pos > 0)
506 lVersion = (_ttol(sVersion.Left(pos))<<24);
507 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
508 pos = sVersion.Find(',', pos+1);
509 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
512 CRegDWORD regval = CRegDWORD(_T("Software\\TortoiseGit\\DontConvertBase"), 999);
513 if ((DWORD)regval != 999)
515 // there's a leftover registry setting we have to convert and then delete it
516 CRegDWORD newregval = CRegDWORD(_T("Software\\TortoiseGit\\ConvertBase"));
517 newregval = !regval;
518 regval.removeValue();
520 #if 0
521 if (lVersion <= 0x01010300)
523 CSoundUtils::RegisterTSVNSounds();
524 // remove all saved dialog positions
525 CRegString(_T("Software\\TortoiseGit\\TortoiseProc\\ResizableState\\")).removeKey();
526 CRegDWORD(_T("Software\\TortoiseGit\\RecursiveOverlay")).removeValue();
527 // remove the external cache key
528 CRegDWORD(_T("Software\\TortoiseGit\\ExternalCache")).removeValue();
530 #endif
531 if (lVersion <= 0x01020200)
533 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
534 // so remove the diff/merge scripts if they're the defaults
535 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
536 CString sDiff = diffreg;
537 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
538 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
539 diffreg = _T("");
540 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
541 sDiff = mergereg;
542 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
543 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
544 mergereg = _T("");
546 if (lVersion <= 0x01040000)
548 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
551 // set the custom diff scripts for every user
552 CString scriptsdir = CPathUtils::GetAppParentDirectory();
553 scriptsdir += _T("Diff-Scripts");
554 CSimpleFileFind files(scriptsdir);
555 while (files.FindNextFileNoDirectories())
557 CString file = files.GetFilePath();
558 CString filename = files.GetFileName();
559 CString ext = file.Mid(file.ReverseFind('-')+1);
560 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
561 CString kind;
562 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
564 kind = _T(" //E:vbscript");
566 if (file.Right(2).CompareNoCase(_T("js"))==0)
568 kind = _T(" //E:javascript");
571 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
573 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
574 CString diffregstring = diffreg;
575 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
576 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
578 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
580 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
581 CString diffregstring = diffreg;
582 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
583 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
587 // Initialize "Software\\TortoiseGit\\DiffProps" once with the same value as "Software\\TortoiseGit\\Diff"
588 CRegString regDiffPropsPath = CRegString(_T("Software\\TortoiseGit\\DiffProps"),_T("non-existant"));
589 CString strDiffPropsPath = regDiffPropsPath;
590 if ( strDiffPropsPath==_T("non-existant") )
592 CString strDiffPath = CRegString(_T("Software\\TortoiseGit\\Diff"));
593 regDiffPropsPath = strDiffPath;
596 // set the current version so we don't come here again until the next update!
597 regVersion = _T(STRPRODUCTVER);
600 void CTortoiseProcApp::EnableCrashHandler()
602 // the crash handler is enabled by default, but we disable it
603 // after 3 months after a release
605 #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
606 + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
608 #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
609 : __DATE__ [2] == 'b' ? 2 \
610 : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
611 : __DATE__ [2] == 'y' ? 5 \
612 : __DATE__ [2] == 'l' ? 7 \
613 : __DATE__ [2] == 'g' ? 8 \
614 : __DATE__ [2] == 'p' ? 9 \
615 : __DATE__ [2] == 't' ? 10 \
616 : __DATE__ [2] == 'v' ? 11 : 12)
618 #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
619 + (__DATE__ [5] - '0'))
621 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
623 CTime compiletime(YEAR, MONTH, DAY, 0, 0, 0);
624 CTime now = CTime::GetCurrentTime();
626 CTimeSpan timediff = now-compiletime;
627 if (timediff.GetDays() > 3*31)
629 // crasher.Enable(FALSE);
633 void CTortoiseProcApp::InitializeJumpList()
635 // for Win7 : use a custom jump list
636 CoInitialize(NULL);
637 SetAppID(APPID);
638 DeleteJumpList(APPID);
639 DoInitializeJumpList();
640 CoUninitialize();
643 void CTortoiseProcApp::DoInitializeJumpList()
645 ATL::CComPtr<ICustomDestinationList> pcdl;
646 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
647 if (FAILED(hr))
648 return;
650 hr = pcdl->SetAppID(APPID);
651 if (FAILED(hr))
652 return;
654 UINT uMaxSlots;
655 ATL::CComPtr<IObjectArray> poaRemoved;
656 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
657 if (FAILED(hr))
658 return;
660 ATL::CComPtr<IObjectCollection> poc;
661 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
662 if (FAILED(hr))
663 return;
665 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
666 sTemp.Remove('&');
668 ATL::CComPtr<IShellLink> psl;
669 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
670 if (SUCCEEDED(hr)) {
671 poc->AddObject(psl);
673 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
674 sTemp.Remove('&');
675 psl.Release(); // Need to release the object before calling operator&()
676 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
677 if (SUCCEEDED(hr)) {
678 poc->AddObject(psl);
681 ATL::CComPtr<IObjectArray> poa;
682 hr = poc.QueryInterface(&poa);
683 if (SUCCEEDED(hr)) {
684 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
685 pcdl->CommitList();
689 int CTortoiseProcApp::ExitInstance()
691 Gdiplus::GdiplusShutdown(m_gdiplusToken);
693 CWinAppEx::ExitInstance();
694 if (retSuccess)
695 return 0;
696 return -1;