Use RunTortoiseGitProc for updatecheck
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blobe87d4ddf2ad5880ef49a8a4bfd90204484a3b1a5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013 - 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 "TortoiseProc.h"
22 #include "SysImageList.h"
23 #include "..\Utils\CrashReport.h"
24 #include "CmdLineParser.h"
25 #include "Hooks.h"
26 #include "AppUtils.h"
27 #include "PathUtils.h"
28 #include "UnicodeUtils.h"
29 #include "MessageBox.h"
30 //#include "libintl.h"
31 #include "DirFileEnum.h"
32 //#include "SoundUtils.h"
33 #include "GitAdminDir.h"
34 #include "Git.h"
35 #include "SmartHandle.h"
36 #include "Commands\Command.h"
37 #include "..\version.h"
38 #include "JumpListHelpers.h"
39 #include "SinglePropSheetDlg.h"
40 #include "Settings\setmainpage.h"
41 #include "..\Settings\Settings.h"
42 #include "gitindex.h"
43 #include "Libraries.h"
44 #include "TaskbarUUID.h"
46 #define STRUCT_IOVEC_DEFINED
48 #ifdef _DEBUG
49 #define new DEBUG_NEW
50 #endif
52 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
54 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
55 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
56 END_MESSAGE_MAP()
58 //CString g_version;
59 //CString CGit::m_MsysGitPath;
60 //////////////////////////////////////////////////////////////////////////
62 CTortoiseProcApp::CTortoiseProcApp()
64 SetDllDirectory(L"");
65 // prevent from inheriting %GIT_DIR% from parent process by resetting it,
66 // use MSVC function instead of Windows API because MSVC runtime caches environment variables
67 _tputenv(_T("GIT_DIR="));
68 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
69 EnableHtmlHelp();
70 // int argc = 0;
71 // const char* const * argv = NULL;
72 SYS_IMAGE_LIST();
73 CHooks::Create();
74 m_bLoadUserToolbars = FALSE;
75 m_bSaveState = FALSE;
76 retSuccess = false;
77 m_gdiplusToken = NULL;
81 CTortoiseProcApp::~CTortoiseProcApp()
83 CHooks::Destroy();
84 SYS_IMAGE_LIST().Cleanup();
87 // The one and only CTortoiseProcApp object
88 CTortoiseProcApp theApp;
89 CString sOrigCWD;
90 CString g_sGroupingUUID;
91 HWND hWndExplorer;
93 BOOL CTortoiseProcApp::CheckMsysGitDir()
95 //CGitIndexFileMap map;
96 //int status;
97 //CTGitPath path;
98 //path.SetFromGit(_T("src/gpl.txt"));
99 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
100 return g_Git.CheckMsysGitDir();
102 CCrashReportTGit crasher(L"TortoiseGit " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
104 // CTortoiseProcApp initialization
106 BOOL CTortoiseProcApp::InitInstance()
108 CheckUpgrade();
109 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
110 CMFCButton::EnableWindowsTheming();
112 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
113 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
115 //set the resource dll for the required language
116 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
117 long langId = loc;
118 CString langDll;
119 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
120 langpath += "Languages";
121 // bindtextdomain("subversion", (LPCSTR)langpath);
122 // bind_textdomain_codeset("subversion", "UTF-8");
123 HINSTANCE hInst = NULL;
126 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
128 hInst = LoadLibrary(langDll);
130 CString sVer = _T(STRPRODUCTVER);
131 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
132 if (sFileVer.Compare(sVer)!=0)
134 FreeLibrary(hInst);
135 hInst = NULL;
137 if (hInst != NULL)
139 AfxSetResourceHandle(hInst);
141 else
143 DWORD lid = SUBLANGID(langId);
144 lid--;
145 if (lid > 0)
147 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
149 else
150 langId = 0;
152 } while ((hInst == NULL) && (langId != 0));
153 TCHAR buf[6];
154 _tcscpy_s(buf, _T("en"));
155 langId = loc;
156 // MFC uses a help file with the same name as the application by default,
157 // which means we have to change that default to our language specific help files
158 CString sHelppath = CPathUtils::GetAppDirectory() + _T("TortoiseGit_en.chm");
159 free((void*)m_pszHelpFilePath);
160 m_pszHelpFilePath=_tcsdup(sHelppath);
161 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
164 CString sLang = _T("_");
165 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
167 sLang += buf;
168 sHelppath.Replace(_T("_en"), sLang);
169 if (PathFileExists(sHelppath))
171 free((void*)m_pszHelpFilePath);
172 m_pszHelpFilePath=_tcsdup(sHelppath);
173 break;
176 sHelppath.Replace(sLang, _T("_en"));
177 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
179 sLang += _T("_");
180 sLang += buf;
181 sHelppath.Replace(_T("_en"), sLang);
182 if (PathFileExists(sHelppath))
184 free((void*)m_pszHelpFilePath);
185 m_pszHelpFilePath=_tcsdup(sHelppath);
186 break;
189 sHelppath.Replace(sLang, _T("_en"));
191 DWORD lid = SUBLANGID(langId);
192 lid--;
193 if (lid > 0)
195 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
197 else
198 langId = 0;
199 } while (langId);
200 setlocale(LC_ALL, "");
202 if(!CheckMsysGitDir())
204 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
205 if(ret == 2)
207 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
209 else if(ret == 1)
211 // open settings dialog
212 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
214 return FALSE;
216 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
218 int ret = CMessageBox::ShowCheck(NULL, IDS_PROC_OLDMSYSGIT, IDS_APPNAME, 1, IDI_EXCLAMATION, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON, IDS_IGNOREBUTTON, _T("OldMsysgitVersionWarning"), IDS_PROC_NOTSHOWAGAINIGNORE);
219 if (ret == 1)
221 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
222 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
223 return FALSE;
225 else if (ret == 2)
227 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
228 return FALSE;
232 // InitCommonControls() is required on Windows XP if an application
233 // manifest specifies use of ComCtl32.dll version 6 or later to enable
234 // visual styles. Otherwise, any window creation will fail.
236 INITCOMMONCONTROLSEX used = {
237 sizeof(INITCOMMONCONTROLSEX),
238 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
239 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
240 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
241 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
242 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
244 InitCommonControlsEx(&used);
245 AfxOleInit();
246 AfxEnableControlContainer();
247 AfxInitRichEdit2();
248 CWinAppEx::InitInstance();
249 SetRegistryKey(_T("TortoiseGit"));
250 AfxGetApp()->m_pszProfileName = _tcsdup(_T("TortoiseProc")); // w/o this ResizableLib will store data under TortoiseGitProc which is not compatible with older versions
252 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
254 hWndExplorer = NULL;
255 CString sVal = parser.GetVal(_T("hwnd"));
256 if (!sVal.IsEmpty())
257 hWndExplorer = (HWND)_ttoi64(sVal);
259 while (GetParent(hWndExplorer)!=NULL)
260 hWndExplorer = GetParent(hWndExplorer);
261 if (!IsWindow(hWndExplorer))
263 hWndExplorer = NULL;
266 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
267 // in a message box
268 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
269 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
271 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
273 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
274 return FALSE;
277 CTGitPath cmdLinePath;
278 CTGitPathList pathList;
279 if (g_sGroupingUUID.IsEmpty())
280 g_sGroupingUUID = parser.GetVal(L"groupuuid");
281 if ( parser.HasKey(_T("pathfile")) )
284 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
286 cmdLinePath.SetFromUnknown(sPathfileArgument);
287 if (pathList.LoadFromFile(cmdLinePath)==false)
288 return FALSE; // no path specified!
289 if ( parser.HasKey(_T("deletepathfile")) )
291 // We can delete the temporary path file, now that we've loaded it
292 ::DeleteFile(cmdLinePath.GetWinPath());
294 // This was a path to a temporary file - it's got no meaning now, and
295 // anybody who uses it again is in for a problem...
296 cmdLinePath.Reset();
299 else
302 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
303 if (parser.HasKey(_T("expaths")))
305 // an /expaths param means we're started via the buttons in our Win7 library
306 // and that means the value of /expaths is the current directory, and
307 // the selected paths are then added as additional parameters but without a key, only a value
309 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
310 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
311 // a save bet.
312 // Without this, a command line like:
313 // /command:commit /expaths:"D:\" "D:\Utils"
314 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
315 // mark and we'd end up with:
316 // argv[1] = /command:commit
317 // argv[2] = /expaths:D:" D:\Utils
318 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
319 CString cmdLine = GetCommandLineW();
320 cmdLine.Replace(L"\\", L"\\\\");
321 int nArgs = 0;
322 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
323 if (szArglist)
325 // argument 0 is the process path, so start with 1
326 for (int i = 1; i < nArgs; ++i)
328 if (szArglist[i][0] != '/')
330 if (!sPathArgument.IsEmpty())
331 sPathArgument += '*';
332 sPathArgument += szArglist[i];
335 sPathArgument.Replace(L"\\\\", L"\\");
337 LocalFree(szArglist);
339 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
341 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
342 return FALSE;
344 int asterisk = sPathArgument.Find('*');
345 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
346 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
349 if (pathList.GetCount() == 0) {
350 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
353 // Subversion sometimes writes temp files to the current directory!
354 // Since TSVN doesn't need a specific CWD anyway, we just set it
355 // to the users temp folder: that way, Subversion is guaranteed to
356 // have write access to the CWD
358 DWORD len = GetCurrentDirectory(0, NULL);
359 if (len)
361 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
362 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
364 sOrigCWD = originalCurrentDirectory.get();
365 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
368 TCHAR pathbuf[MAX_PATH];
369 GetTortoiseGitTempPath(MAX_PATH, pathbuf);
370 SetCurrentDirectory(pathbuf);
373 CheckForNewerVersion();
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);
382 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
383 if (!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString(), parser.HasKey(_T("submodule")) == TRUE))
385 for (int i = 0; i < pathList.GetCount(); ++i)
386 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
387 break;
390 if(!g_Git.m_CurrentDir.IsEmpty())
392 sOrigCWD = g_Git.m_CurrentDir;
393 SetCurrentDirectory(g_Git.m_CurrentDir);
396 if (g_sGroupingUUID.IsEmpty())
398 CRegStdDWORD groupSetting = CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3);
399 switch (DWORD(groupSetting))
401 case 1:
402 case 2:
403 // implemented differently to TortoiseSVN atm
404 break;
405 case 3:
406 case 4:
408 CString wcroot;
409 if (g_GitAdminDir.HasAdminDir(g_Git.m_CurrentDir, true, &wcroot))
411 git_oid oid;
412 CStringA wcRootA(wcroot);
413 if (!git_odb_hash(&oid, wcRootA.GetBuffer(), wcRootA.GetLength(), GIT_OBJ_BLOB))
415 CStringA hash;
416 git_oid_tostr(hash.GetBufferSetLength(GIT_OID_HEXSZ + 1), GIT_OID_HEXSZ + 1, &oid);
417 hash.ReleaseBuffer();
418 g_sGroupingUUID = hash;
425 CString sAppID = GetTaskIDPerUUID(g_sGroupingUUID).c_str();
426 InitializeJumpList(sAppID);
427 EnsureGitLibrary(false);
430 CString err;
433 // requires CWD to be set
434 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
436 // make sure all config files are read in order to check that none contains an error
437 g_Git.GetConfigValue(_T("doesnot.exist"));
439 catch (char* msg)
441 err = CString(msg);
444 if (!err.IsEmpty())
446 UINT choice = CMessageBox::Show(hWndExplorer, err, _T("TortoiseGit"), 1, IDI_ERROR, CString(MAKEINTRESOURCE(IDS_PROC_EDITLOCALGITCONFIG)), CString(MAKEINTRESOURCE(IDS_PROC_EDITGLOBALGITCONFIG)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON)));
447 if (choice == 1)
449 // open the config file with alternative editor
450 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitLocalConfig());
452 else if (choice == 2)
454 // open the global config file with alternative editor
455 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitGlobalConfig());
457 return FALSE;
461 // execute the requested command
462 CommandServer server;
463 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
464 if (cmd)
466 cmd->SetExplorerHwnd(hWndExplorer);
468 cmd->SetParser(parser);
469 cmd->SetPaths(pathList, cmdLinePath);
471 retSuccess = cmd->Execute();
472 delete cmd;
475 // Look for temporary files left around by TortoiseSVN and
476 // remove them. But only delete 'old' files because some
477 // apps might still be needing the recent ones.
479 DWORD len = GetTortoiseGitTempPath(0, NULL);
480 std::unique_ptr<TCHAR[]> path(new TCHAR[len + 100]);
481 len = GetTortoiseGitTempPath (len + 100, path.get());
482 if (len != 0)
484 CDirFileEnum finder(path.get());
485 FILETIME systime_;
486 ::GetSystemTimeAsFileTime(&systime_);
487 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
488 bool isDir;
489 CString filepath;
490 while (finder.NextFile(filepath, &isDir))
492 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, isDir ? FILE_FLAG_BACKUP_SEMANTICS : NULL, NULL);
493 if (hFile != INVALID_HANDLE_VALUE)
495 FILETIME createtime_;
496 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
498 ::CloseHandle(hFile);
499 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
500 if ((createtime + 864000000000) < systime) //only delete files older than a day
502 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
503 if (isDir)
504 ::RemoveDirectory(filepath);
505 else
506 ::DeleteFile(filepath);
509 else
510 ::CloseHandle(hFile);
516 // Since the dialog has been closed, return FALSE so that we exit the
517 // application, rather than start the application's message pump.
518 return FALSE;
521 void CTortoiseProcApp::CheckUpgrade()
523 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
524 CString sVersion = regVersion;
525 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
526 return;
527 // we're starting the first time with a new version!
529 LONG lVersion = 0;
530 int pos = sVersion.Find('.');
531 if (pos > 0)
533 lVersion = (_ttol(sVersion.Left(pos))<<24);
534 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
535 pos = sVersion.Find('.', pos+1);
536 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
538 else
540 pos = sVersion.Find(',');
541 if (pos > 0)
543 lVersion = (_ttol(sVersion.Left(pos))<<24);
544 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
545 pos = sVersion.Find(',', pos+1);
546 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
550 #if 0
551 if (lVersion <= 0x01010300)
553 CSoundUtils::RegisterTSVNSounds();
555 #endif
557 if (lVersion <= 0x01080100)
559 if (CRegStdDWORD(_T("Software\\TortoiseGit\\LogTopoOrder"), TRUE) == FALSE)
560 CRegStdDWORD(_T("Software\\TortoiseGit\\LogOrderBy")) = 0;
563 if (lVersion <= 0x01040000)
565 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
568 if (lVersion <= 0x01070600)
570 CoInitialize(NULL);
571 EnsureGitLibrary();
572 CoUninitialize();
573 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
574 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
575 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
576 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
579 if (lVersion <= 0x01070E00)
581 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
582 // upgrade to 1.7.15: force recreation of all diff scripts.
583 CAppUtils::SetupDiffScripts(true, CString());
585 CAppUtils::SetupDiffScripts(false, CString());
587 // set the current version so we don't come here again until the next update!
588 regVersion = _T(STRPRODUCTVER);
591 void CTortoiseProcApp::InitializeJumpList(const CString& appid)
593 // for Win7 : use a custom jump list
594 CoInitialize(NULL);
595 SetAppID(appid);
596 DeleteJumpList(appid);
597 DoInitializeJumpList(appid);
598 CoUninitialize();
601 void CTortoiseProcApp::DoInitializeJumpList(const CString& appid)
603 ATL::CComPtr<ICustomDestinationList> pcdl;
604 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
605 if (FAILED(hr))
606 return;
608 hr = pcdl->SetAppID(appid);
609 if (FAILED(hr))
610 return;
612 UINT uMaxSlots;
613 ATL::CComPtr<IObjectArray> poaRemoved;
614 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
615 if (FAILED(hr))
616 return;
618 ATL::CComPtr<IObjectCollection> poc;
619 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
620 if (FAILED(hr))
621 return;
623 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
624 sTemp.Remove('&');
626 ATL::CComPtr<IShellLink> psl;
627 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
628 if (SUCCEEDED(hr)) {
629 poc->AddObject(psl);
631 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
632 sTemp.Remove('&');
633 psl.Release(); // Need to release the object before calling operator&()
634 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
635 if (SUCCEEDED(hr)) {
636 poc->AddObject(psl);
639 ATL::CComPtr<IObjectArray> poa;
640 hr = poc.QueryInterface(&poa);
641 if (SUCCEEDED(hr)) {
642 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
643 pcdl->CommitList();
647 int CTortoiseProcApp::ExitInstance()
649 Gdiplus::GdiplusShutdown(m_gdiplusToken);
651 CWinAppEx::ExitInstance();
652 if (retSuccess)
653 return 0;
654 return -1;
657 void CTortoiseProcApp::CheckForNewerVersion()
659 // check for newer versions
660 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
662 time_t now;
663 struct tm ptm;
665 time(&now);
666 if ((now != 0) && (localtime_s(&ptm, &now)==0))
668 #if PREVIEW
669 // Check daily for new preview releases
670 CRegDWORD oldday = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerDay"), (DWORD)-1);
671 if (((DWORD)oldday) == -1)
672 oldday = ptm.tm_yday;
673 else
675 if ((DWORD)oldday != (DWORD)ptm.tm_yday)
677 oldday = ptm.tm_yday;
678 #else
679 int week = 0;
680 // we don't calculate the real 'week of the year' here
681 // because just to decide if we should check for an update
682 // that's not needed.
683 week = ptm.tm_yday / 7;
685 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
686 if (((DWORD)oldweek) == -1)
687 oldweek = week; // first start of TortoiseProc, no update check needed
688 else
690 if ((DWORD)week != oldweek)
692 oldweek = week;
693 #endif
694 CAppUtils::RunTortoiseGitProc(_T("/command:updatecheck"), false, false);