Smoothly migrate msysgit\cmd-paths to bin-paths on upgrade
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blobcfc2843c801f91c4966fcf0b24bb1f9d0114b91a
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"
45 #include "GitConfig.h"
47 #define STRUCT_IOVEC_DEFINED
49 #ifdef _DEBUG
50 #define new DEBUG_NEW
51 #endif
53 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
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 // prevent from inheriting %GIT_DIR% from parent process by resetting it,
67 // use MSVC function instead of Windows API because MSVC runtime caches environment variables
68 _tputenv(_T("GIT_DIR="));
69 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
70 EnableHtmlHelp();
71 // int argc = 0;
72 // const char* const * argv = NULL;
73 SYS_IMAGE_LIST();
74 CHooks::Create();
75 m_bLoadUserToolbars = FALSE;
76 m_bSaveState = FALSE;
77 retSuccess = false;
78 m_gdiplusToken = NULL;
82 CTortoiseProcApp::~CTortoiseProcApp()
84 CHooks::Destroy();
85 SYS_IMAGE_LIST().Cleanup();
88 // The one and only CTortoiseProcApp object
89 CTortoiseProcApp theApp;
90 CString sOrigCWD;
91 CString g_sGroupingUUID;
92 HWND hWndExplorer;
94 BOOL CTortoiseProcApp::CheckMsysGitDir()
96 //CGitIndexFileMap map;
97 //int status;
98 //CTGitPath path;
99 //path.SetFromGit(_T("src/gpl.txt"));
100 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
101 return g_Git.CheckMsysGitDir();
103 CCrashReportTGit crasher(L"TortoiseGit " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
105 // CTortoiseProcApp initialization
107 BOOL CTortoiseProcApp::InitInstance()
109 CheckUpgrade();
110 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
111 CMFCButton::EnableWindowsTheming();
113 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
114 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
116 //set the resource dll for the required language
117 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
118 long langId = loc;
119 CString langDll;
120 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
121 langpath += "Languages";
122 // bindtextdomain("subversion", (LPCSTR)langpath);
123 // bind_textdomain_codeset("subversion", "UTF-8");
124 HINSTANCE hInst = NULL;
127 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
129 hInst = LoadLibrary(langDll);
131 CString sVer = _T(STRPRODUCTVER);
132 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
133 if (sFileVer.Compare(sVer)!=0)
135 FreeLibrary(hInst);
136 hInst = NULL;
138 if (hInst != NULL)
140 AfxSetResourceHandle(hInst);
142 else
144 DWORD lid = SUBLANGID(langId);
145 lid--;
146 if (lid > 0)
148 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
150 else
151 langId = 0;
153 } while ((hInst == NULL) && (langId != 0));
154 TCHAR buf[6];
155 _tcscpy_s(buf, _T("en"));
156 langId = loc;
157 // MFC uses a help file with the same name as the application by default,
158 // which means we have to change that default to our language specific help files
159 CString sHelppath = CPathUtils::GetAppDirectory() + _T("TortoiseGit_en.chm");
160 free((void*)m_pszHelpFilePath);
161 m_pszHelpFilePath=_tcsdup(sHelppath);
162 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
165 CString sLang = _T("_");
166 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
168 sLang += buf;
169 sHelppath.Replace(_T("_en"), sLang);
170 if (PathFileExists(sHelppath))
172 free((void*)m_pszHelpFilePath);
173 m_pszHelpFilePath=_tcsdup(sHelppath);
174 break;
177 sHelppath.Replace(sLang, _T("_en"));
178 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
180 sLang += _T("_");
181 sLang += buf;
182 sHelppath.Replace(_T("_en"), sLang);
183 if (PathFileExists(sHelppath))
185 free((void*)m_pszHelpFilePath);
186 m_pszHelpFilePath=_tcsdup(sHelppath);
187 break;
190 sHelppath.Replace(sLang, _T("_en"));
192 DWORD lid = SUBLANGID(langId);
193 lid--;
194 if (lid > 0)
196 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
198 else
199 langId = 0;
200 } while (langId);
201 setlocale(LC_ALL, "");
203 if(!CheckMsysGitDir())
205 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
206 if(ret == 2)
208 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
210 else if(ret == 1)
212 // open settings dialog
213 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
215 return FALSE;
217 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
219 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);
220 if (ret == 1)
222 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
223 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
224 return FALSE;
226 else if (ret == 2)
228 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
229 return FALSE;
233 // InitCommonControls() is required on Windows XP if an application
234 // manifest specifies use of ComCtl32.dll version 6 or later to enable
235 // visual styles. Otherwise, any window creation will fail.
237 INITCOMMONCONTROLSEX used = {
238 sizeof(INITCOMMONCONTROLSEX),
239 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
240 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
241 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
242 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
243 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
245 InitCommonControlsEx(&used);
246 AfxOleInit();
247 AfxEnableControlContainer();
248 AfxInitRichEdit2();
249 CWinAppEx::InitInstance();
250 SetRegistryKey(_T("TortoiseGit"));
251 AfxGetApp()->m_pszProfileName = _tcsdup(_T("TortoiseProc")); // w/o this ResizableLib will store data under TortoiseGitProc which is not compatible with older versions
253 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
255 hWndExplorer = NULL;
256 CString sVal = parser.GetVal(_T("hwnd"));
257 if (!sVal.IsEmpty())
258 hWndExplorer = (HWND)_ttoi64(sVal);
260 while (GetParent(hWndExplorer)!=NULL)
261 hWndExplorer = GetParent(hWndExplorer);
262 if (!IsWindow(hWndExplorer))
264 hWndExplorer = NULL;
267 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
268 // in a message box
269 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
270 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
272 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
274 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
275 return FALSE;
278 CTGitPath cmdLinePath;
279 CTGitPathList pathList;
280 if (g_sGroupingUUID.IsEmpty())
281 g_sGroupingUUID = parser.GetVal(L"groupuuid");
282 if ( parser.HasKey(_T("pathfile")) )
285 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
287 cmdLinePath.SetFromUnknown(sPathfileArgument);
288 if (pathList.LoadFromFile(cmdLinePath)==false)
289 return FALSE; // no path specified!
290 if ( parser.HasKey(_T("deletepathfile")) )
292 // We can delete the temporary path file, now that we've loaded it
293 ::DeleteFile(cmdLinePath.GetWinPath());
295 // This was a path to a temporary file - it's got no meaning now, and
296 // anybody who uses it again is in for a problem...
297 cmdLinePath.Reset();
300 else
303 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
304 if (parser.HasKey(_T("expaths")))
306 // an /expaths param means we're started via the buttons in our Win7 library
307 // and that means the value of /expaths is the current directory, and
308 // the selected paths are then added as additional parameters but without a key, only a value
310 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
311 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
312 // a save bet.
313 // Without this, a command line like:
314 // /command:commit /expaths:"D:\" "D:\Utils"
315 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
316 // mark and we'd end up with:
317 // argv[1] = /command:commit
318 // argv[2] = /expaths:D:" D:\Utils
319 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
320 CString cmdLine = GetCommandLineW();
321 cmdLine.Replace(L"\\", L"\\\\");
322 int nArgs = 0;
323 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
324 if (szArglist)
326 // argument 0 is the process path, so start with 1
327 for (int i = 1; i < nArgs; ++i)
329 if (szArglist[i][0] != '/')
331 if (!sPathArgument.IsEmpty())
332 sPathArgument += '*';
333 sPathArgument += szArglist[i];
336 sPathArgument.Replace(L"\\\\", L"\\");
338 LocalFree(szArglist);
340 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
342 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
343 return FALSE;
345 int asterisk = sPathArgument.Find('*');
346 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
347 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
350 if (pathList.GetCount() == 0) {
351 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
354 // Subversion sometimes writes temp files to the current directory!
355 // Since TSVN doesn't need a specific CWD anyway, we just set it
356 // to the users temp folder: that way, Subversion is guaranteed to
357 // have write access to the CWD
359 DWORD len = GetCurrentDirectory(0, NULL);
360 if (len)
362 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
363 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
365 sOrigCWD = originalCurrentDirectory.get();
366 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
369 TCHAR pathbuf[MAX_PATH];
370 GetTortoiseGitTempPath(MAX_PATH, pathbuf);
371 SetCurrentDirectory(pathbuf);
374 CheckForNewerVersion();
376 if (parser.HasVal(_T("configdir")))
378 // the user can override the location of the Subversion config directory here
379 CString sConfigDir = parser.GetVal(_T("configdir"));
380 // g_GitGlobal.SetConfigDir(sConfigDir);
383 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
384 if (!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString(), parser.HasKey(_T("submodule")) == TRUE))
386 for (int i = 0; i < pathList.GetCount(); ++i)
387 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
388 break;
391 if(!g_Git.m_CurrentDir.IsEmpty())
393 sOrigCWD = g_Git.m_CurrentDir;
394 SetCurrentDirectory(g_Git.m_CurrentDir);
397 if (g_sGroupingUUID.IsEmpty())
399 CRegStdDWORD groupSetting = CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3);
400 switch (DWORD(groupSetting))
402 case 1:
403 case 2:
404 // implemented differently to TortoiseSVN atm
405 break;
406 case 3:
407 case 4:
409 CString wcroot;
410 if (g_GitAdminDir.HasAdminDir(g_Git.m_CurrentDir, true, &wcroot))
412 git_oid oid;
413 CStringA wcRootA(wcroot);
414 if (!git_odb_hash(&oid, wcRootA.GetBuffer(), wcRootA.GetLength(), GIT_OBJ_BLOB))
416 CStringA hash;
417 git_oid_tostr(hash.GetBufferSetLength(GIT_OID_HEXSZ + 1), GIT_OID_HEXSZ + 1, &oid);
418 hash.ReleaseBuffer();
419 g_sGroupingUUID = hash;
426 CString sAppID = GetTaskIDPerUUID(g_sGroupingUUID).c_str();
427 InitializeJumpList(sAppID);
428 EnsureGitLibrary(false);
431 CString err;
434 // requires CWD to be set
435 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
437 // make sure all config files are read in order to check that none contains an error
438 g_Git.GetConfigValue(_T("doesnot.exist"));
440 catch (char* msg)
442 err = CString(msg);
445 if (!err.IsEmpty())
447 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)));
448 if (choice == 1)
450 // open the config file with alternative editor
451 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitLocalConfig());
453 else if (choice == 2)
455 // open the global config file with alternative editor
456 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitGlobalConfig());
458 return FALSE;
462 // execute the requested command
463 CommandServer server;
464 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
465 if (cmd)
467 cmd->SetExplorerHwnd(hWndExplorer);
469 cmd->SetParser(parser);
470 cmd->SetPaths(pathList, cmdLinePath);
472 retSuccess = cmd->Execute();
473 delete cmd;
476 // Look for temporary files left around by TortoiseSVN and
477 // remove them. But only delete 'old' files because some
478 // apps might still be needing the recent ones.
480 DWORD len = GetTortoiseGitTempPath(0, NULL);
481 std::unique_ptr<TCHAR[]> path(new TCHAR[len + 100]);
482 len = GetTortoiseGitTempPath (len + 100, path.get());
483 if (len != 0)
485 CDirFileEnum finder(path.get());
486 FILETIME systime_;
487 ::GetSystemTimeAsFileTime(&systime_);
488 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
489 bool isDir;
490 CString filepath;
491 while (finder.NextFile(filepath, &isDir))
493 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, isDir ? FILE_FLAG_BACKUP_SEMANTICS : NULL, NULL);
494 if (hFile != INVALID_HANDLE_VALUE)
496 FILETIME createtime_;
497 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
499 ::CloseHandle(hFile);
500 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
501 if ((createtime + 864000000000) < systime) //only delete files older than a day
503 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
504 if (isDir)
505 ::RemoveDirectory(filepath);
506 else
507 ::DeleteFile(filepath);
510 else
511 ::CloseHandle(hFile);
517 // Since the dialog has been closed, return FALSE so that we exit the
518 // application, rather than start the application's message pump.
519 return FALSE;
522 void CTortoiseProcApp::CheckUpgrade()
524 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
525 CString sVersion = regVersion;
526 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
527 return;
528 // we're starting the first time with a new version!
530 LONG lVersion = 0;
531 int pos = sVersion.Find('.');
532 if (pos > 0)
534 lVersion = (_ttol(sVersion.Left(pos))<<24);
535 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
536 pos = sVersion.Find('.', pos+1);
537 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
539 else
541 pos = sVersion.Find(',');
542 if (pos > 0)
544 lVersion = (_ttol(sVersion.Left(pos))<<24);
545 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
546 pos = sVersion.Find(',', pos+1);
547 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
551 #if 0
552 if (lVersion <= 0x01010300)
554 CSoundUtils::RegisterTSVNSounds();
556 #endif
558 if (lVersion <= 0x01080100)
560 if (CRegStdDWORD(_T("Software\\TortoiseGit\\LogTopoOrder"), TRUE) == FALSE)
561 CRegStdDWORD(_T("Software\\TortoiseGit\\LogOrderBy")) = 0;
563 // smoothly migrate broken msysgit path settings
564 CString oldmsysGitSetting = CRegString(REG_MSYSGIT_PATH);
565 oldmsysGitSetting.TrimRight(_T("\\"));
566 CString right = oldmsysGitSetting.Right(4);
567 if (oldmsysGitSetting.GetLength() > 4 && oldmsysGitSetting.Right(4) == _T("\\cmd"))
569 CString newPath = oldmsysGitSetting.Mid(0, oldmsysGitSetting.GetLength() - 3) + _T("bin");
570 if (PathFileExists(newPath + _T("\\git.exe")))
572 CRegString(REG_MSYSGIT_PATH) = newPath;
573 g_Git.m_bInitialized = FALSE;
574 g_Git.CheckMsysGitDir();
579 if (lVersion <= 0x01040000)
581 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
584 if (lVersion <= 0x01070600)
586 CoInitialize(NULL);
587 EnsureGitLibrary();
588 CoUninitialize();
589 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
590 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
591 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
592 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
595 if (lVersion <= 0x01070E00)
597 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
598 // upgrade to 1.7.15: force recreation of all diff scripts.
599 CAppUtils::SetupDiffScripts(true, CString());
601 CAppUtils::SetupDiffScripts(false, CString());
603 // set the current version so we don't come here again until the next update!
604 regVersion = _T(STRPRODUCTVER);
607 void CTortoiseProcApp::InitializeJumpList(const CString& appid)
609 // for Win7 : use a custom jump list
610 CoInitialize(NULL);
611 SetAppID(appid);
612 DeleteJumpList(appid);
613 DoInitializeJumpList(appid);
614 CoUninitialize();
617 void CTortoiseProcApp::DoInitializeJumpList(const CString& appid)
619 ATL::CComPtr<ICustomDestinationList> pcdl;
620 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
621 if (FAILED(hr))
622 return;
624 hr = pcdl->SetAppID(appid);
625 if (FAILED(hr))
626 return;
628 UINT uMaxSlots;
629 ATL::CComPtr<IObjectArray> poaRemoved;
630 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
631 if (FAILED(hr))
632 return;
634 ATL::CComPtr<IObjectCollection> poc;
635 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
636 if (FAILED(hr))
637 return;
639 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
640 sTemp.Remove('&');
642 ATL::CComPtr<IShellLink> psl;
643 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
644 if (SUCCEEDED(hr)) {
645 poc->AddObject(psl);
647 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
648 sTemp.Remove('&');
649 psl.Release(); // Need to release the object before calling operator&()
650 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
651 if (SUCCEEDED(hr)) {
652 poc->AddObject(psl);
655 ATL::CComPtr<IObjectArray> poa;
656 hr = poc.QueryInterface(&poa);
657 if (SUCCEEDED(hr)) {
658 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
659 pcdl->CommitList();
663 int CTortoiseProcApp::ExitInstance()
665 Gdiplus::GdiplusShutdown(m_gdiplusToken);
667 CWinAppEx::ExitInstance();
668 if (retSuccess)
669 return 0;
670 return -1;
673 void CTortoiseProcApp::CheckForNewerVersion()
675 // check for newer versions
676 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
678 time_t now;
679 struct tm ptm;
681 time(&now);
682 if ((now != 0) && (localtime_s(&ptm, &now)==0))
684 #if PREVIEW
685 // Check daily for new preview releases
686 CRegDWORD oldday = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerDay"), (DWORD)-1);
687 if (((DWORD)oldday) == -1)
688 oldday = ptm.tm_yday;
689 else
691 if ((DWORD)oldday != (DWORD)ptm.tm_yday)
693 oldday = ptm.tm_yday;
694 #else
695 int week = 0;
696 // we don't calculate the real 'week of the year' here
697 // because just to decide if we should check for an update
698 // that's not needed.
699 week = ptm.tm_yday / 7;
701 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
702 if (((DWORD)oldweek) == -1)
703 oldweek = week; // first start of TortoiseProc, no update check needed
704 else
706 if ((DWORD)week != oldweek)
708 oldweek = week;
709 #endif
710 CAppUtils::RunTortoiseGitProc(_T("/command:updatecheck"), false, false);