Fixed warning
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob4776a6b8b5b7df0d59110ecb8b368faed05b77e1
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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"
45 #define STRUCT_IOVEC_DEFINED
47 #ifdef _DEBUG
48 #define new DEBUG_NEW
49 #endif
51 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
53 #define APPID (_T("TGIT.TGIT.1") _T(TGIT_PLATFORM))
55 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
56 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
57 END_MESSAGE_MAP()
59 //CString g_version;
60 //CString CGit::m_MsysGitPath;
61 //////////////////////////////////////////////////////////////////////////
63 CTortoiseProcApp::CTortoiseProcApp()
65 SetDllDirectory(L"");
66 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
67 EnableHtmlHelp();
68 // int argc = 0;
69 // const char* const * argv = NULL;
70 SYS_IMAGE_LIST();
71 CHooks::Create();
72 m_bLoadUserToolbars = FALSE;
73 m_bSaveState = FALSE;
74 retSuccess = false;
78 CTortoiseProcApp::~CTortoiseProcApp()
80 CHooks::Destroy();
81 SYS_IMAGE_LIST().Cleanup();
84 // The one and only CTortoiseProcApp object
85 CTortoiseProcApp theApp;
86 CString sOrigCWD;
87 HWND hWndExplorer;
89 BOOL CTortoiseProcApp::CheckMsysGitDir()
91 //CGitIndexFileMap map;
92 //int status;
93 //CTGitPath path;
94 //path.SetFromGit(_T("src/gpl.txt"));
95 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
96 return g_Git.CheckMsysGitDir();
98 CCrashReportTGit crasher(L"TortoiseGit " _T(APP_X64_STRING));
100 // CTortoiseProcApp initialization
102 BOOL CTortoiseProcApp::InitInstance()
104 CheckUpgrade();
105 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
106 CMFCButton::EnableWindowsTheming();
108 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
109 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
111 //set the resource dll for the required language
112 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
113 long langId = loc;
114 CString langDll;
115 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
116 langpath += "Languages";
117 // bindtextdomain("subversion", (LPCSTR)langpath);
118 // bind_textdomain_codeset("subversion", "UTF-8");
119 HINSTANCE hInst = NULL;
122 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
124 hInst = LoadLibrary(langDll);
126 CString sVer = _T(STRPRODUCTVER);
127 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
128 if (sFileVer.Compare(sVer)!=0)
130 FreeLibrary(hInst);
131 hInst = NULL;
133 if (hInst != NULL)
135 AfxSetResourceHandle(hInst);
137 else
139 DWORD lid = SUBLANGID(langId);
140 lid--;
141 if (lid > 0)
143 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
145 else
146 langId = 0;
148 } while ((hInst == NULL) && (langId != 0));
149 TCHAR buf[6];
150 _tcscpy_s(buf, _T("en"));
151 langId = loc;
152 CString sHelppath;
153 sHelppath = this->m_pszHelpFilePath;
154 sHelppath = sHelppath.MakeLower();
155 // MFC uses a help file with the same name as the application by default,
156 // which means we have to change that default to our language specific help files
157 sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseGit_en.chm"));
158 free((void*)m_pszHelpFilePath);
159 m_pszHelpFilePath=_tcsdup(sHelppath);
160 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
163 CString sLang = _T("_");
164 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
166 sLang += buf;
167 sHelppath.Replace(_T("_en"), sLang);
168 if (PathFileExists(sHelppath))
170 free((void*)m_pszHelpFilePath);
171 m_pszHelpFilePath=_tcsdup(sHelppath);
172 break;
175 sHelppath.Replace(sLang, _T("_en"));
176 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
178 sLang += _T("_");
179 sLang += buf;
180 sHelppath.Replace(_T("_en"), sLang);
181 if (PathFileExists(sHelppath))
183 free((void*)m_pszHelpFilePath);
184 m_pszHelpFilePath=_tcsdup(sHelppath);
185 break;
188 sHelppath.Replace(sLang, _T("_en"));
190 DWORD lid = SUBLANGID(langId);
191 lid--;
192 if (lid > 0)
194 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
196 else
197 langId = 0;
198 } while (langId);
199 setlocale(LC_ALL, "");
201 if(!CheckMsysGitDir())
203 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
204 if(ret == 2)
206 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
208 else if(ret == 1)
210 // open settings dialog
211 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
213 return FALSE;
215 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
217 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);
218 if (ret == 1)
220 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
221 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
222 return FALSE;
224 else if (ret == 2)
226 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
227 return FALSE;
231 // InitCommonControls() is required on Windows XP if an application
232 // manifest specifies use of ComCtl32.dll version 6 or later to enable
233 // visual styles. Otherwise, any window creation will fail.
235 INITCOMMONCONTROLSEX used = {
236 sizeof(INITCOMMONCONTROLSEX),
237 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
238 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
239 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
240 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
241 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
243 InitCommonControlsEx(&used);
244 AfxOleInit();
245 AfxEnableControlContainer();
246 AfxInitRichEdit2();
247 CWinAppEx::InitInstance();
248 SetRegistryKey(_T("TortoiseGit"));
250 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
252 hWndExplorer = NULL;
253 CString sVal = parser.GetVal(_T("hwnd"));
254 if (!sVal.IsEmpty())
255 hWndExplorer = (HWND)_ttoi64(sVal);
257 while (GetParent(hWndExplorer)!=NULL)
258 hWndExplorer = GetParent(hWndExplorer);
259 if (!IsWindow(hWndExplorer))
261 hWndExplorer = NULL;
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 if (parser.HasKey(_T("expaths")))
301 // an /expaths param means we're started via the buttons in our Win7 library
302 // and that means the value of /expaths is the current directory, and
303 // the selected paths are then added as additional parameters but without a key, only a value
305 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
306 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
307 // a save bet.
308 // Without this, a command line like:
309 // /command:commit /expaths:"D:\" "D:\Utils"
310 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
311 // mark and we'd end up with:
312 // argv[1] = /command:commit
313 // argv[2] = /expaths:D:" D:\Utils
314 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
315 CString cmdLine = GetCommandLineW();
316 cmdLine.Replace(L"\\", L"\\\\");
317 int nArgs = 0;
318 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
319 if (szArglist)
321 // argument 0 is the process path, so start with 1
322 for (int i=1; i<nArgs; i++)
324 if (szArglist[i][0] != '/')
326 if (!sPathArgument.IsEmpty())
327 sPathArgument += '*';
328 sPathArgument += szArglist[i];
331 sPathArgument.Replace(L"\\\\", L"\\");
333 LocalFree(szArglist);
335 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
337 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
338 return FALSE;
340 int asterisk = sPathArgument.Find('*');
341 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
342 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
345 if (pathList.GetCount() == 0) {
346 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
349 InitializeJumpList();
350 EnsureGitLibrary(false);
352 // Subversion sometimes writes temp files to the current directory!
353 // Since TSVN doesn't need a specific CWD anyway, we just set it
354 // to the users temp folder: that way, Subversion is guaranteed to
355 // have write access to the CWD
357 DWORD len = GetCurrentDirectory(0, NULL);
358 if (len)
360 auto_buffer<TCHAR> originalCurrentDirectory(len);
361 if (GetCurrentDirectory(len, originalCurrentDirectory))
363 sOrigCWD = originalCurrentDirectory;
364 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
367 TCHAR pathbuf[MAX_PATH];
368 GetTempPath(MAX_PATH, pathbuf);
369 SetCurrentDirectory(pathbuf);
372 CheckForNewerVersion();
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);
381 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
382 if (!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString(), parser.HasKey(_T("submodule")) == TRUE))
384 int i=0;
385 for(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);
397 CString err;
400 // requires CWD to be set
401 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
403 catch (char* msg)
405 err = CString(msg);
408 if (!err.IsEmpty())
410 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)));
411 if (choice == 1)
413 // open the config file with alternative editor
414 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitLocalConfig());
416 else if (choice == 2)
418 // open the global config file with alternative editor
419 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitGlobalConfig());
421 return FALSE;
425 // execute the requested command
426 CommandServer server;
427 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
428 if (cmd)
430 cmd->SetExplorerHwnd(hWndExplorer);
432 cmd->SetParser(parser);
433 cmd->SetPaths(pathList, cmdLinePath);
435 retSuccess = cmd->Execute();
436 delete cmd;
439 // Look for temporary files left around by TortoiseSVN and
440 // remove them. But only delete 'old' files because some
441 // apps might still be needing the recent ones.
443 DWORD len = ::GetTempPath(0, NULL);
444 TCHAR * path = new TCHAR[len + 100];
445 len = ::GetTempPath (len+100, path);
446 if (len != 0)
448 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
449 FILETIME systime_;
450 ::GetSystemTimeAsFileTime(&systime_);
451 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
452 while (finder.FindNextFileNoDirectories())
454 CString filepath = finder.GetFilePath();
455 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
456 if (hFile != INVALID_HANDLE_VALUE)
458 FILETIME createtime_;
459 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
461 ::CloseHandle(hFile);
462 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
463 if ((createtime + 864000000000) < systime) //only delete files older than a day
465 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
466 ::DeleteFile(filepath);
469 else
470 ::CloseHandle(hFile);
474 delete[] path;
477 // Since the dialog has been closed, return FALSE so that we exit the
478 // application, rather than start the application's message pump.
479 return FALSE;
482 void CTortoiseProcApp::CheckUpgrade()
484 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
485 CString sVersion = regVersion;
486 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
487 return;
488 // we're starting the first time with a new version!
490 LONG lVersion = 0;
491 int pos = sVersion.Find(',');
492 if (pos > 0)
494 lVersion = (_ttol(sVersion.Left(pos))<<24);
495 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
496 pos = sVersion.Find(',', pos+1);
497 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
500 if (lVersion <= 0x01070600)
502 CoInitialize(NULL);
503 EnsureGitLibrary();
504 CoUninitialize();
505 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
506 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
507 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
508 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
509 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
511 #if 0
512 if (lVersion <= 0x01010300)
514 CSoundUtils::RegisterTSVNSounds();
516 #endif
517 if (lVersion <= 0x01020200)
519 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
520 // so remove the diff/merge scripts if they're the defaults
521 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
522 CString sDiff = diffreg;
523 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
524 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
525 diffreg = _T("");
526 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
527 sDiff = mergereg;
528 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
529 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
530 mergereg = _T("");
532 if (lVersion <= 0x01040000)
534 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
537 // set the custom diff scripts for every user
538 CString scriptsdir = CPathUtils::GetAppParentDirectory();
539 scriptsdir += _T("Diff-Scripts");
540 CSimpleFileFind files(scriptsdir);
541 while (files.FindNextFileNoDirectories())
543 CString file = files.GetFilePath();
544 CString filename = files.GetFileName();
545 CString ext = file.Mid(file.ReverseFind('-')+1);
546 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
547 CString kind;
548 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
550 kind = _T(" //E:vbscript");
552 if (file.Right(2).CompareNoCase(_T("js"))==0)
554 kind = _T(" //E:javascript");
557 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
559 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
560 CString diffregstring = diffreg;
561 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
562 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
564 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
566 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
567 CString diffregstring = diffreg;
568 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
569 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
573 // set the current version so we don't come here again until the next update!
574 regVersion = _T(STRPRODUCTVER);
577 void CTortoiseProcApp::InitializeJumpList()
579 // for Win7 : use a custom jump list
580 CoInitialize(NULL);
581 SetAppID(APPID);
582 DeleteJumpList(APPID);
583 DoInitializeJumpList();
584 CoUninitialize();
587 void CTortoiseProcApp::DoInitializeJumpList()
589 ATL::CComPtr<ICustomDestinationList> pcdl;
590 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
591 if (FAILED(hr))
592 return;
594 hr = pcdl->SetAppID(APPID);
595 if (FAILED(hr))
596 return;
598 UINT uMaxSlots;
599 ATL::CComPtr<IObjectArray> poaRemoved;
600 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
601 if (FAILED(hr))
602 return;
604 ATL::CComPtr<IObjectCollection> poc;
605 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
606 if (FAILED(hr))
607 return;
609 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
610 sTemp.Remove('&');
612 ATL::CComPtr<IShellLink> psl;
613 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
614 if (SUCCEEDED(hr)) {
615 poc->AddObject(psl);
617 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
618 sTemp.Remove('&');
619 psl.Release(); // Need to release the object before calling operator&()
620 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
621 if (SUCCEEDED(hr)) {
622 poc->AddObject(psl);
625 ATL::CComPtr<IObjectArray> poa;
626 hr = poc.QueryInterface(&poa);
627 if (SUCCEEDED(hr)) {
628 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
629 pcdl->CommitList();
633 int CTortoiseProcApp::ExitInstance()
635 Gdiplus::GdiplusShutdown(m_gdiplusToken);
637 CWinAppEx::ExitInstance();
638 if (retSuccess)
639 return 0;
640 return -1;
643 void CTortoiseProcApp::CheckForNewerVersion()
645 // check for newer versions
646 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
648 time_t now;
649 struct tm ptm;
651 time(&now);
652 if ((now != 0) && (localtime_s(&ptm, &now)==0))
654 #if PREVIEW
655 // Check daily for new preview releases
656 CRegDWORD oldday = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerDay"), (DWORD)-1);
657 if (((DWORD)oldday) == -1)
658 oldday = ptm.tm_yday;
659 else
661 if ((DWORD)oldday != (DWORD)ptm.tm_yday)
663 oldday = ptm.tm_yday;
664 #else
665 int week = 0;
666 // we don't calculate the real 'week of the year' here
667 // because just to decide if we should check for an update
668 // that's not needed.
669 week = ptm.tm_yday / 7;
671 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
672 if (((DWORD)oldweek) == -1)
673 oldweek = week; // first start of TortoiseProc, no update check needed
674 else
676 if ((DWORD)week != oldweek)
678 oldweek = week;
679 #endif
680 TCHAR com[MAX_PATH+100];
681 GetModuleFileName(NULL, com, MAX_PATH);
682 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
684 CAppUtils::LaunchApplication(com, 0, false);