Add optional support for github-windows and smartgit protocol handlers
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blobb386bf90264b6d8d8045d9597062927a4c10a36f
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("github-windows://openRepo/")) == 0)
274 url = url.Mid(26); // 26 = "github-windows://openRepo/".GetLength()
275 int questioMark = url.Find('?');
276 if (questioMark > 0)
277 url = url.Left(questioMark);
279 else if (url.Find(_T("smartgit://cloneRepo/")) == 0)
281 url = url.Mid(21); // 21 = "smartgit://cloneRepo/".GetLength()
283 else
285 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
286 return FALSE;
288 CString newCmd;
289 newCmd.Format(_T("/command:clone /url:\"%s\""), url);
290 parser = CCmdLineParser(newCmd);
293 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
295 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
296 return FALSE;
299 CTGitPath cmdLinePath;
300 CTGitPathList pathList;
301 if (g_sGroupingUUID.IsEmpty())
302 g_sGroupingUUID = parser.GetVal(L"groupuuid");
303 if ( parser.HasKey(_T("pathfile")) )
306 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
308 cmdLinePath.SetFromUnknown(sPathfileArgument);
309 if (pathList.LoadFromFile(cmdLinePath)==false)
310 return FALSE; // no path specified!
311 if ( parser.HasKey(_T("deletepathfile")) )
313 // We can delete the temporary path file, now that we've loaded it
314 ::DeleteFile(cmdLinePath.GetWinPath());
316 // This was a path to a temporary file - it's got no meaning now, and
317 // anybody who uses it again is in for a problem...
318 cmdLinePath.Reset();
321 else
324 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
325 if (parser.HasKey(_T("expaths")))
327 // an /expaths param means we're started via the buttons in our Win7 library
328 // and that means the value of /expaths is the current directory, and
329 // the selected paths are then added as additional parameters but without a key, only a value
331 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
332 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
333 // a save bet.
334 // Without this, a command line like:
335 // /command:commit /expaths:"D:\" "D:\Utils"
336 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
337 // mark and we'd end up with:
338 // argv[1] = /command:commit
339 // argv[2] = /expaths:D:" D:\Utils
340 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
341 CString cmdLine = GetCommandLineW();
342 cmdLine.Replace(L"\\", L"\\\\");
343 int nArgs = 0;
344 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
345 if (szArglist)
347 // argument 0 is the process path, so start with 1
348 for (int i = 1; i < nArgs; ++i)
350 if (szArglist[i][0] != '/')
352 if (!sPathArgument.IsEmpty())
353 sPathArgument += '*';
354 sPathArgument += szArglist[i];
357 sPathArgument.Replace(L"\\\\", L"\\");
359 LocalFree(szArglist);
361 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
363 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
364 return FALSE;
366 int asterisk = sPathArgument.Find('*');
367 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
368 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
371 if (pathList.GetCount() == 0) {
372 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
375 // Subversion sometimes writes temp files to the current directory!
376 // Since TSVN doesn't need a specific CWD anyway, we just set it
377 // to the users temp folder: that way, Subversion is guaranteed to
378 // have write access to the CWD
380 DWORD len = GetCurrentDirectory(0, NULL);
381 if (len)
383 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
384 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
386 sOrigCWD = originalCurrentDirectory.get();
387 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
390 TCHAR pathbuf[MAX_PATH];
391 GetTortoiseGitTempPath(MAX_PATH, pathbuf);
392 SetCurrentDirectory(pathbuf);
395 CheckForNewerVersion();
397 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
398 if (!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString(), parser.HasKey(_T("submodule")) == TRUE))
400 for (int i = 0; i < pathList.GetCount(); ++i)
401 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
402 break;
405 if(!g_Git.m_CurrentDir.IsEmpty())
407 sOrigCWD = g_Git.m_CurrentDir;
408 SetCurrentDirectory(g_Git.m_CurrentDir);
411 if (g_sGroupingUUID.IsEmpty())
413 CRegStdDWORD groupSetting = CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3);
414 switch (DWORD(groupSetting))
416 case 1:
417 case 2:
418 // implemented differently to TortoiseSVN atm
419 break;
420 case 3:
421 case 4:
423 CString wcroot;
424 if (g_GitAdminDir.HasAdminDir(g_Git.m_CurrentDir, true, &wcroot))
426 git_oid oid;
427 CStringA wcRootA(wcroot + CPathUtils::GetAppDirectory());
428 if (!git_odb_hash(&oid, wcRootA.GetBuffer(), wcRootA.GetLength(), GIT_OBJ_BLOB))
430 CStringA hash;
431 git_oid_tostr(hash.GetBufferSetLength(GIT_OID_HEXSZ + 1), GIT_OID_HEXSZ + 1, &oid);
432 hash.ReleaseBuffer();
433 g_sGroupingUUID = hash;
440 CString sAppID = GetTaskIDPerUUID(g_sGroupingUUID).c_str();
441 InitializeJumpList(sAppID);
442 EnsureGitLibrary(false);
445 CString err;
448 // requires CWD to be set
449 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
451 // make sure all config files are read in order to check that none contains an error
452 g_Git.GetConfigValue(_T("doesnot.exist"));
454 catch (char* msg)
456 err = CString(msg);
459 if (!err.IsEmpty())
461 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)));
462 if (choice == 1)
464 // open the config file with alternative editor
465 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitLocalConfig());
467 else if (choice == 2)
469 // open the global config file with alternative editor
470 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitGlobalConfig());
472 return FALSE;
476 // execute the requested command
477 CommandServer server;
478 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
479 if (cmd)
481 cmd->SetExplorerHwnd(hWndExplorer);
483 cmd->SetParser(parser);
484 cmd->SetPaths(pathList, cmdLinePath);
486 retSuccess = cmd->Execute();
487 delete cmd;
490 // Look for temporary files left around by TortoiseSVN and
491 // remove them. But only delete 'old' files because some
492 // apps might still be needing the recent ones.
494 DWORD len = GetTortoiseGitTempPath(0, NULL);
495 std::unique_ptr<TCHAR[]> path(new TCHAR[len + 100]);
496 len = GetTortoiseGitTempPath (len + 100, path.get());
497 if (len != 0)
499 CDirFileEnum finder(path.get());
500 FILETIME systime_;
501 ::GetSystemTimeAsFileTime(&systime_);
502 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
503 bool isDir;
504 CString filepath;
505 while (finder.NextFile(filepath, &isDir))
507 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, isDir ? FILE_FLAG_BACKUP_SEMANTICS : NULL, NULL);
508 if (hFile != INVALID_HANDLE_VALUE)
510 FILETIME createtime_;
511 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
513 ::CloseHandle(hFile);
514 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
515 if ((createtime + 864000000000) < systime) //only delete files older than a day
517 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
518 if (isDir)
519 ::RemoveDirectory(filepath);
520 else
521 ::DeleteFile(filepath);
524 else
525 ::CloseHandle(hFile);
531 // Since the dialog has been closed, return FALSE so that we exit the
532 // application, rather than start the application's message pump.
533 return FALSE;
536 void CTortoiseProcApp::CheckUpgrade()
538 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
539 CString sVersion = regVersion;
540 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
541 return;
542 // we're starting the first time with a new version!
544 LONG lVersion = 0;
545 int pos = sVersion.Find('.');
546 if (pos > 0)
548 lVersion = (_ttol(sVersion.Left(pos))<<24);
549 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
550 pos = sVersion.Find('.', pos+1);
551 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
553 else
555 pos = sVersion.Find(',');
556 if (pos > 0)
558 lVersion = (_ttol(sVersion.Left(pos))<<24);
559 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
560 pos = sVersion.Find(',', pos+1);
561 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
565 if (lVersion <= 0x01080401)
567 if (CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI"), FALSE) == TRUE)
568 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType")) = 1;
569 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI")).removeValue();
572 if (lVersion <= 0x01080202)
574 CSoundUtils::RegisterTGitSounds();
575 // upgrade to 1.8.3: force recreation of all diff scripts.
576 CAppUtils::SetupDiffScripts(true, CString());
579 if (lVersion <= 0x01080100)
581 if (CRegStdDWORD(_T("Software\\TortoiseGit\\LogTopoOrder"), TRUE) == FALSE)
582 CRegStdDWORD(_T("Software\\TortoiseGit\\LogOrderBy")) = 0;
584 // smoothly migrate broken msysgit path settings
585 CString oldmsysGitSetting = CRegString(REG_MSYSGIT_PATH);
586 oldmsysGitSetting.TrimRight(_T("\\"));
587 CString right = oldmsysGitSetting.Right(4);
588 if (oldmsysGitSetting.GetLength() > 4 && oldmsysGitSetting.Right(4) == _T("\\cmd"))
590 CString newPath = oldmsysGitSetting.Mid(0, oldmsysGitSetting.GetLength() - 3) + _T("bin");
591 if (PathFileExists(newPath + _T("\\git.exe")))
593 CRegString(REG_MSYSGIT_PATH) = newPath;
594 g_Git.m_bInitialized = FALSE;
595 g_Git.CheckMsysGitDir();
600 if (lVersion <= 0x01040000)
602 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
605 if (lVersion <= 0x01070600)
607 CoInitialize(NULL);
608 EnsureGitLibrary();
609 CoUninitialize();
610 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
611 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
612 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
613 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
616 if (lVersion <= 0x01070E00)
618 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
620 CAppUtils::SetupDiffScripts(false, CString());
622 // set the current version so we don't come here again until the next update!
623 regVersion = _T(STRPRODUCTVER);
626 void CTortoiseProcApp::InitializeJumpList(const CString& appid)
628 // for Win7 : use a custom jump list
629 CoInitialize(NULL);
630 SetAppID(appid);
631 DeleteJumpList(appid);
632 DoInitializeJumpList(appid);
633 CoUninitialize();
636 void CTortoiseProcApp::DoInitializeJumpList(const CString& appid)
638 ATL::CComPtr<ICustomDestinationList> pcdl;
639 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
640 if (FAILED(hr))
641 return;
643 hr = pcdl->SetAppID(appid);
644 if (FAILED(hr))
645 return;
647 UINT uMaxSlots;
648 ATL::CComPtr<IObjectArray> poaRemoved;
649 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
650 if (FAILED(hr))
651 return;
653 ATL::CComPtr<IObjectCollection> poc;
654 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
655 if (FAILED(hr))
656 return;
658 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
659 sTemp.Remove('&');
661 ATL::CComPtr<IShellLink> psl;
662 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
663 if (SUCCEEDED(hr)) {
664 poc->AddObject(psl);
666 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
667 sTemp.Remove('&');
668 psl.Release(); // Need to release the object before calling operator&()
669 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
670 if (SUCCEEDED(hr)) {
671 poc->AddObject(psl);
674 ATL::CComPtr<IObjectArray> poa;
675 hr = poc.QueryInterface(&poa);
676 if (SUCCEEDED(hr)) {
677 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
678 pcdl->CommitList();
682 int CTortoiseProcApp::ExitInstance()
684 Gdiplus::GdiplusShutdown(m_gdiplusToken);
686 CWinAppEx::ExitInstance();
687 if (retSuccess)
688 return 0;
689 return -1;
692 void CTortoiseProcApp::CheckForNewerVersion()
694 // check for newer versions
695 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
697 time_t now;
698 struct tm ptm;
700 time(&now);
701 if ((now != 0) && (localtime_s(&ptm, &now)==0))
703 #if PREVIEW
704 // Check daily for new preview releases
705 CRegDWORD oldday = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerDay"), (DWORD)-1);
706 if (((DWORD)oldday) == -1)
707 oldday = ptm.tm_yday;
708 else
710 if ((DWORD)oldday != (DWORD)ptm.tm_yday)
712 oldday = ptm.tm_yday;
713 #else
714 int week = 0;
715 // we don't calculate the real 'week of the year' here
716 // because just to decide if we should check for an update
717 // that's not needed.
718 week = ptm.tm_yday / 7;
720 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
721 if (((DWORD)oldweek) == -1)
722 oldweek = week; // first start of TortoiseProc, no update check needed
723 else
725 if ((DWORD)week != oldweek)
727 oldweek = week;
728 #endif
729 CAppUtils::RunTortoiseGitProc(_T("/command:updatecheck"), false, false);