Make tgit protocol handler include a command
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob44b4c5b7927858b39c64db8e2600f0dc974810bc
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 "DirFileEnum.h"
31 #include "GitAdminDir.h"
32 #include "Git.h"
33 #include "SmartHandle.h"
34 #include "Commands\Command.h"
35 #include "..\version.h"
36 #include "JumpListHelpers.h"
37 #include "SinglePropSheetDlg.h"
38 #include "Settings\setmainpage.h"
39 #include "Libraries.h"
40 #include "TaskbarUUID.h"
41 #include "GitConfig.h"
42 #include "SoundUtils.h"
44 #define STRUCT_IOVEC_DEFINED
46 #ifdef _DEBUG
47 #define new DEBUG_NEW
48 #endif
50 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
52 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
53 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
54 END_MESSAGE_MAP()
56 //CString g_version;
57 //CString CGit::m_MsysGitPath;
58 //////////////////////////////////////////////////////////////////////////
60 CTortoiseProcApp::CTortoiseProcApp()
62 SetDllDirectory(L"");
63 // prevent from inheriting %GIT_DIR% from parent process by resetting it,
64 // use MSVC function instead of Windows API because MSVC runtime caches environment variables
65 _tputenv(_T("GIT_DIR="));
66 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
67 EnableHtmlHelp();
68 SYS_IMAGE_LIST();
69 CHooks::Create();
70 m_bLoadUserToolbars = FALSE;
71 m_bSaveState = FALSE;
72 retSuccess = false;
73 m_gdiplusToken = NULL;
76 CTortoiseProcApp::~CTortoiseProcApp()
78 CHooks::Destroy();
79 SYS_IMAGE_LIST().Cleanup();
82 // The one and only CTortoiseProcApp object
83 CTortoiseProcApp theApp;
84 CString sOrigCWD;
85 CString g_sGroupingUUID;
86 HWND hWndExplorer;
88 #if ENABLE_CRASHHANLDER
89 CCrashReportTGit crasher(L"TortoiseGit " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
90 #endif
92 // CTortoiseProcApp initialization
94 BOOL CTortoiseProcApp::InitInstance()
96 CheckUpgrade();
97 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
98 CMFCButton::EnableWindowsTheming();
100 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
101 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
103 //set the resource dll for the required language
104 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
105 long langId = loc;
107 CString langStr;
108 langStr.Format(_T("%d"), langId);
109 CCrashReport::Instance().AddUserInfoToReport(L"LanguageID", langStr);
111 CString langDll;
112 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
113 langpath += "Languages";
114 HINSTANCE hInst = NULL;
117 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
119 hInst = LoadLibrary(langDll);
121 CString sVer = _T(STRPRODUCTVER);
122 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
123 if (sFileVer.Compare(sVer)!=0)
125 FreeLibrary(hInst);
126 hInst = NULL;
128 if (hInst != NULL)
130 AfxSetResourceHandle(hInst);
132 else
134 DWORD lid = SUBLANGID(langId);
135 lid--;
136 if (lid > 0)
138 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
140 else
141 langId = 0;
143 } while ((hInst == NULL) && (langId != 0));
144 TCHAR buf[6];
145 _tcscpy_s(buf, _T("en"));
146 langId = loc;
147 // MFC uses a help file with the same name as the application by default,
148 // which means we have to change that default to our language specific help files
149 CString sHelppath = CPathUtils::GetAppDirectory() + _T("TortoiseGit_en.chm");
150 free((void*)m_pszHelpFilePath);
151 m_pszHelpFilePath=_tcsdup(sHelppath);
152 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
155 CString sLang = _T("_");
156 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
158 sLang += buf;
159 sHelppath.Replace(_T("_en"), sLang);
160 if (PathFileExists(sHelppath))
162 free((void*)m_pszHelpFilePath);
163 m_pszHelpFilePath=_tcsdup(sHelppath);
164 break;
167 sHelppath.Replace(sLang, _T("_en"));
168 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
170 sLang += _T("_");
171 sLang += buf;
172 sHelppath.Replace(_T("_en"), sLang);
173 if (PathFileExists(sHelppath))
175 free((void*)m_pszHelpFilePath);
176 m_pszHelpFilePath=_tcsdup(sHelppath);
177 break;
180 sHelppath.Replace(sLang, _T("_en"));
182 DWORD lid = SUBLANGID(langId);
183 lid--;
184 if (lid > 0)
186 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
188 else
189 langId = 0;
190 } while (langId);
191 setlocale(LC_ALL, "");
193 if (!g_Git.CheckMsysGitDir())
195 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
196 if(ret == 2)
198 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
200 else if(ret == 1)
202 // open settings dialog
203 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
205 return FALSE;
207 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
209 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);
210 if (ret == 1)
212 CMessageBox::RemoveRegistryKey(_T("OldMsysgitVersionWarning")); // only store answer if it is "Ignore"
213 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
214 return FALSE;
216 else if (ret == 2)
218 CMessageBox::RemoveRegistryKey(_T("OldMsysgitVersionWarning")); // only store answer if it is "Ignore"
219 return FALSE;
224 CCrashReport::Instance().AddUserInfoToReport(L"msysGitDir", CGit::ms_LastMsysGitDir);
225 CString versionString;
226 versionString.Format(_T("%d"), CGit::ms_LastMsysGitVersion);
227 CCrashReport::Instance().AddUserInfoToReport(L"msysGitVersion", versionString);
230 // InitCommonControls() is required on Windows XP if an application
231 // manifest specifies use of ComCtl32.dll version 6 or later to enable
232 // visual styles. Otherwise, any window creation will fail.
234 INITCOMMONCONTROLSEX used = {
235 sizeof(INITCOMMONCONTROLSEX),
236 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
237 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
238 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
239 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
240 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
242 InitCommonControlsEx(&used);
243 AfxOleInit();
244 AfxEnableControlContainer();
245 AfxInitRichEdit2();
246 CWinAppEx::InitInstance();
247 SetRegistryKey(_T("TortoiseGit"));
248 AfxGetApp()->m_pszProfileName = _tcsdup(_T("TortoiseProc")); // w/o this ResizableLib will store data under TortoiseGitProc which is not compatible with older versions
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("urlhandler")))
271 CString url = parser.GetVal(_T("urlhandler"));
272 if (url.Find(_T("tgit://clone/")) == 0)
274 url = url.Mid(13); // 21 = "tgit://clone/".GetLength()
276 else if (url.Find(_T("github-windows://openRepo/")) == 0)
278 url = url.Mid(26); // 26 = "github-windows://openRepo/".GetLength()
279 int questioMark = url.Find('?');
280 if (questioMark > 0)
281 url = url.Left(questioMark);
283 else if (url.Find(_T("smartgit://cloneRepo/")) == 0)
285 url = url.Mid(21); // 21 = "smartgit://cloneRepo/".GetLength()
287 else
289 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
290 return FALSE;
292 CString newCmd;
293 newCmd.Format(_T("/command:clone /url:\"%s\""), url);
294 parser = CCmdLineParser(newCmd);
297 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
299 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
300 return FALSE;
303 CTGitPath cmdLinePath;
304 CTGitPathList pathList;
305 if (g_sGroupingUUID.IsEmpty())
306 g_sGroupingUUID = parser.GetVal(L"groupuuid");
307 if ( parser.HasKey(_T("pathfile")) )
310 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
312 cmdLinePath.SetFromUnknown(sPathfileArgument);
313 if (pathList.LoadFromFile(cmdLinePath)==false)
314 return FALSE; // no path specified!
315 if ( parser.HasKey(_T("deletepathfile")) )
317 // We can delete the temporary path file, now that we've loaded it
318 ::DeleteFile(cmdLinePath.GetWinPath());
320 // This was a path to a temporary file - it's got no meaning now, and
321 // anybody who uses it again is in for a problem...
322 cmdLinePath.Reset();
325 else
328 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
329 if (parser.HasKey(_T("expaths")))
331 // an /expaths param means we're started via the buttons in our Win7 library
332 // and that means the value of /expaths is the current directory, and
333 // the selected paths are then added as additional parameters but without a key, only a value
335 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
336 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
337 // a save bet.
338 // Without this, a command line like:
339 // /command:commit /expaths:"D:\" "D:\Utils"
340 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
341 // mark and we'd end up with:
342 // argv[1] = /command:commit
343 // argv[2] = /expaths:D:" D:\Utils
344 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
345 CString cmdLine = GetCommandLineW();
346 cmdLine.Replace(L"\\", L"\\\\");
347 int nArgs = 0;
348 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
349 if (szArglist)
351 // argument 0 is the process path, so start with 1
352 for (int i = 1; i < nArgs; ++i)
354 if (szArglist[i][0] != '/')
356 if (!sPathArgument.IsEmpty())
357 sPathArgument += '*';
358 sPathArgument += szArglist[i];
361 sPathArgument.Replace(L"\\\\", L"\\");
363 LocalFree(szArglist);
365 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
367 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
368 return FALSE;
370 int asterisk = sPathArgument.Find('*');
371 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
372 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
375 if (pathList.GetCount() == 0) {
376 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
379 // Subversion sometimes writes temp files to the current directory!
380 // Since TSVN doesn't need a specific CWD anyway, we just set it
381 // to the users temp folder: that way, Subversion is guaranteed to
382 // have write access to the CWD
384 DWORD len = GetCurrentDirectory(0, NULL);
385 if (len)
387 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
388 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
390 sOrigCWD = originalCurrentDirectory.get();
391 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
394 TCHAR pathbuf[MAX_PATH];
395 GetTortoiseGitTempPath(MAX_PATH, pathbuf);
396 SetCurrentDirectory(pathbuf);
399 CheckForNewerVersion();
401 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
402 if (!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString(), parser.HasKey(_T("submodule")) == TRUE))
404 for (int i = 0; i < pathList.GetCount(); ++i)
405 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
406 break;
409 if(!g_Git.m_CurrentDir.IsEmpty())
411 sOrigCWD = g_Git.m_CurrentDir;
412 SetCurrentDirectory(g_Git.m_CurrentDir);
415 if (g_sGroupingUUID.IsEmpty())
417 CRegStdDWORD groupSetting = CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3);
418 switch (DWORD(groupSetting))
420 case 1:
421 case 2:
422 // implemented differently to TortoiseSVN atm
423 break;
424 case 3:
425 case 4:
427 CString wcroot;
428 if (g_GitAdminDir.HasAdminDir(g_Git.m_CurrentDir, true, &wcroot))
430 git_oid oid;
431 CStringA wcRootA(wcroot + CPathUtils::GetAppDirectory());
432 if (!git_odb_hash(&oid, wcRootA.GetBuffer(), wcRootA.GetLength(), GIT_OBJ_BLOB))
434 CStringA hash;
435 git_oid_tostr(hash.GetBufferSetLength(GIT_OID_HEXSZ + 1), GIT_OID_HEXSZ + 1, &oid);
436 hash.ReleaseBuffer();
437 g_sGroupingUUID = hash;
444 CString sAppID = GetTaskIDPerUUID(g_sGroupingUUID).c_str();
445 InitializeJumpList(sAppID);
446 EnsureGitLibrary(false);
449 CString err;
452 // requires CWD to be set
453 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
455 // make sure all config files are read in order to check that none contains an error
456 g_Git.GetConfigValue(_T("doesnot.exist"));
458 catch (char* msg)
460 err = CString(msg);
463 if (!err.IsEmpty())
465 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)));
466 if (choice == 1)
468 // open the config file with alternative editor
469 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitLocalConfig());
471 else if (choice == 2)
473 // open the global config file with alternative editor
474 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitGlobalConfig());
476 return FALSE;
480 // execute the requested command
481 CommandServer server;
482 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
483 if (cmd)
485 cmd->SetExplorerHwnd(hWndExplorer);
487 cmd->SetParser(parser);
488 cmd->SetPaths(pathList, cmdLinePath);
490 retSuccess = cmd->Execute();
491 delete cmd;
494 // Look for temporary files left around by TortoiseSVN and
495 // remove them. But only delete 'old' files because some
496 // apps might still be needing the recent ones.
498 DWORD len = GetTortoiseGitTempPath(0, NULL);
499 std::unique_ptr<TCHAR[]> path(new TCHAR[len + 100]);
500 len = GetTortoiseGitTempPath (len + 100, path.get());
501 if (len != 0)
503 CDirFileEnum finder(path.get());
504 FILETIME systime_;
505 ::GetSystemTimeAsFileTime(&systime_);
506 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
507 bool isDir;
508 CString filepath;
509 while (finder.NextFile(filepath, &isDir))
511 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, isDir ? FILE_FLAG_BACKUP_SEMANTICS : NULL, NULL);
512 if (hFile != INVALID_HANDLE_VALUE)
514 FILETIME createtime_;
515 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
517 ::CloseHandle(hFile);
518 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
519 if ((createtime + 864000000000) < systime) //only delete files older than a day
521 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
522 if (isDir)
523 ::RemoveDirectory(filepath);
524 else
525 ::DeleteFile(filepath);
528 else
529 ::CloseHandle(hFile);
535 // Since the dialog has been closed, return FALSE so that we exit the
536 // application, rather than start the application's message pump.
537 return FALSE;
540 void CTortoiseProcApp::CheckUpgrade()
542 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
543 CString sVersion = regVersion;
544 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
545 return;
546 // we're starting the first time with a new version!
548 LONG lVersion = 0;
549 int pos = sVersion.Find('.');
550 if (pos > 0)
552 lVersion = (_ttol(sVersion.Left(pos))<<24);
553 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
554 pos = sVersion.Find('.', pos+1);
555 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
557 else
559 pos = sVersion.Find(',');
560 if (pos > 0)
562 lVersion = (_ttol(sVersion.Left(pos))<<24);
563 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
564 pos = sVersion.Find(',', pos+1);
565 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
569 if (lVersion <= 0x01080401)
571 if (CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI"), FALSE) == TRUE)
572 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType")) = 1;
573 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI")).removeValue();
576 if (lVersion <= 0x01080202)
578 CSoundUtils::RegisterTGitSounds();
579 // upgrade to 1.8.3: force recreation of all diff scripts.
580 CAppUtils::SetupDiffScripts(true, CString());
583 if (lVersion <= 0x01080100)
585 if (CRegStdDWORD(_T("Software\\TortoiseGit\\LogTopoOrder"), TRUE) == FALSE)
586 CRegStdDWORD(_T("Software\\TortoiseGit\\LogOrderBy")) = 0;
588 // smoothly migrate broken msysgit path settings
589 CString oldmsysGitSetting = CRegString(REG_MSYSGIT_PATH);
590 oldmsysGitSetting.TrimRight(_T("\\"));
591 CString right = oldmsysGitSetting.Right(4);
592 if (oldmsysGitSetting.GetLength() > 4 && oldmsysGitSetting.Right(4) == _T("\\cmd"))
594 CString newPath = oldmsysGitSetting.Mid(0, oldmsysGitSetting.GetLength() - 3) + _T("bin");
595 if (PathFileExists(newPath + _T("\\git.exe")))
597 CRegString(REG_MSYSGIT_PATH) = newPath;
598 g_Git.m_bInitialized = FALSE;
599 g_Git.CheckMsysGitDir();
604 if (lVersion <= 0x01040000)
606 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
609 if (lVersion <= 0x01070600)
611 CoInitialize(NULL);
612 EnsureGitLibrary();
613 CoUninitialize();
614 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
615 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
616 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
617 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
620 if (lVersion <= 0x01070E00)
622 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
624 CAppUtils::SetupDiffScripts(false, CString());
626 // set the current version so we don't come here again until the next update!
627 regVersion = _T(STRPRODUCTVER);
630 void CTortoiseProcApp::InitializeJumpList(const CString& appid)
632 // for Win7 : use a custom jump list
633 CoInitialize(NULL);
634 SetAppID(appid);
635 DeleteJumpList(appid);
636 DoInitializeJumpList(appid);
637 CoUninitialize();
640 void CTortoiseProcApp::DoInitializeJumpList(const CString& appid)
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;
696 void CTortoiseProcApp::CheckForNewerVersion()
698 // check for newer versions
699 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
701 time_t now;
702 struct tm ptm;
704 time(&now);
705 if ((now != 0) && (localtime_s(&ptm, &now)==0))
707 #if PREVIEW
708 // Check daily for new preview releases
709 CRegDWORD oldday = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerDay"), (DWORD)-1);
710 if (((DWORD)oldday) == -1)
711 oldday = ptm.tm_yday;
712 else
714 if ((DWORD)oldday != (DWORD)ptm.tm_yday)
716 oldday = ptm.tm_yday;
717 #else
718 int week = 0;
719 // we don't calculate the real 'week of the year' here
720 // because just to decide if we should check for an update
721 // that's not needed.
722 week = ptm.tm_yday / 7;
724 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
725 if (((DWORD)oldweek) == -1)
726 oldweek = week; // first start of TortoiseProc, no update check needed
727 else
729 if ((DWORD)week != oldweek)
731 oldweek = week;
732 #endif
733 CAppUtils::RunTortoiseGitProc(_T("/command:updatecheck"), false, false);