Avoid CString.GetBuffer() and make use of default (LPCTSTR) operator
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob8e1fffc443d995799489c905d1f86c4a7ee5865e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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"
43 #include "ProjectProperties.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 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
54 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
55 END_MESSAGE_MAP()
57 //CString g_version;
58 //CString CGit::m_MsysGitPath;
59 //////////////////////////////////////////////////////////////////////////
61 CTortoiseProcApp::CTortoiseProcApp()
63 SetDllDirectory(L"");
64 // prevent from inheriting %GIT_DIR% from parent process by resetting it,
65 // use MSVC function instead of Windows API because MSVC runtime caches environment variables
66 _tputenv(_T("GIT_DIR="));
67 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
68 EnableHtmlHelp();
69 SYS_IMAGE_LIST();
70 CHooks::Create();
71 m_bLoadUserToolbars = FALSE;
72 m_bSaveState = FALSE;
73 retSuccess = false;
74 m_gdiplusToken = NULL;
77 CTortoiseProcApp::~CTortoiseProcApp()
79 CHooks::Destroy();
80 SYS_IMAGE_LIST().Cleanup();
83 // The one and only CTortoiseProcApp object
84 CTortoiseProcApp theApp;
85 CString sOrigCWD;
86 CString g_sGroupingUUID;
87 CString g_sGroupingIcon;
88 bool g_bGroupingRemoveIcon = false;
89 HWND hWndExplorer;
91 #if ENABLE_CRASHHANLDER
92 CCrashReportTGit crasher(L"TortoiseGit " _T(APP_X64_STRING), TGIT_VERMAJOR, TGIT_VERMINOR, TGIT_VERMICRO, TGIT_VERBUILD, TGIT_VERDATE);
93 #endif
95 // CTortoiseProcApp initialization
97 BOOL CTortoiseProcApp::InitInstance()
99 CheckUpgrade();
100 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
101 CMFCButton::EnableWindowsTheming();
103 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
104 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
106 //set the resource dll for the required language
107 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
108 long langId = loc;
110 CString langStr;
111 langStr.Format(_T("%ld"), langId);
112 CCrashReport::Instance().AddUserInfoToReport(L"LanguageID", langStr);
114 CString langDll;
115 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
116 langpath += "Languages";
117 HINSTANCE hInst = NULL;
120 langDll.Format(_T("%sLanguages\\TortoiseProc%ld.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
122 hInst = LoadLibrary(langDll);
124 CString sVer = _T(STRPRODUCTVER);
125 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
126 if (sFileVer.Compare(sVer)!=0)
128 FreeLibrary(hInst);
129 hInst = NULL;
131 if (hInst != NULL)
133 AfxSetResourceHandle(hInst);
135 else
137 DWORD lid = SUBLANGID(langId);
138 lid--;
139 if (lid > 0)
141 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
143 else
144 langId = 0;
146 } while ((hInst == NULL) && (langId != 0));
147 TCHAR buf[6] = { 0 };
148 _tcscpy_s(buf, _T("en"));
149 langId = loc;
150 // MFC uses a help file with the same name as the application by default,
151 // which means we have to change that default to our language specific help files
152 CString sHelppath = CPathUtils::GetAppDirectory() + _T("TortoiseGit_en.chm");
153 free((void*)m_pszHelpFilePath);
154 m_pszHelpFilePath=_tcsdup(sHelppath);
155 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
158 CString sLang = _T("_");
159 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
161 sLang += buf;
162 sHelppath.Replace(_T("_en"), sLang);
163 if (PathFileExists(sHelppath))
165 free((void*)m_pszHelpFilePath);
166 m_pszHelpFilePath=_tcsdup(sHelppath);
167 break;
170 sHelppath.Replace(sLang, _T("_en"));
171 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
173 sLang += _T("_");
174 sLang += buf;
175 sHelppath.Replace(_T("_en"), sLang);
176 if (PathFileExists(sHelppath))
178 free((void*)m_pszHelpFilePath);
179 m_pszHelpFilePath=_tcsdup(sHelppath);
180 break;
183 sHelppath.Replace(sLang, _T("_en"));
185 DWORD lid = SUBLANGID(langId);
186 lid--;
187 if (lid > 0)
189 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
191 else
192 langId = 0;
193 } while (langId);
194 setlocale(LC_ALL, "");
196 if (!g_Git.CheckMsysGitDir())
198 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
199 if(ret == 2)
201 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
203 else if(ret == 1)
205 // open settings dialog
206 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
208 return FALSE;
210 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
212 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);
213 if (ret == 1)
215 CMessageBox::RemoveRegistryKey(_T("OldMsysgitVersionWarning")); // only store answer if it is "Ignore"
216 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
217 return FALSE;
219 else if (ret == 2)
221 CMessageBox::RemoveRegistryKey(_T("OldMsysgitVersionWarning")); // only store answer if it is "Ignore"
222 return FALSE;
227 CCrashReport::Instance().AddUserInfoToReport(L"msysGitDir", CGit::ms_LastMsysGitDir);
228 CString versionString;
229 versionString.Format(_T("%d"), CGit::ms_LastMsysGitVersion);
230 CCrashReport::Instance().AddUserInfoToReport(L"msysGitVersion", versionString);
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)_wcstoui64(sVal, nullptr, 16);
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("urlhandler")))
274 CString url = parser.GetVal(_T("urlhandler"));
275 if (url.Find(_T("tgit://clone/")) == 0)
277 url = url.Mid(13); // 21 = "tgit://clone/".GetLength()
279 else if (url.Find(_T("github-windows://openRepo/")) == 0)
281 url = url.Mid(26); // 26 = "github-windows://openRepo/".GetLength()
282 int questioMark = url.Find('?');
283 if (questioMark > 0)
284 url = url.Left(questioMark);
286 else if (url.Find(_T("smartgit://cloneRepo/")) == 0)
288 url = url.Mid(21); // 21 = "smartgit://cloneRepo/".GetLength()
290 else
292 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
293 return FALSE;
295 CString newCmd;
296 newCmd.Format(_T("/command:clone /url:\"%s\" /hasurlhandler"), url);
297 parser = CCmdLineParser(newCmd);
300 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
302 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
303 return FALSE;
306 CTGitPath cmdLinePath;
307 CTGitPathList pathList;
308 if (g_sGroupingUUID.IsEmpty())
309 g_sGroupingUUID = parser.GetVal(L"groupuuid");
310 if ( parser.HasKey(_T("pathfile")) )
313 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
315 cmdLinePath.SetFromUnknown(sPathfileArgument);
316 if (pathList.LoadFromFile(cmdLinePath)==false)
317 return FALSE; // no path specified!
318 if ( parser.HasKey(_T("deletepathfile")) )
320 // We can delete the temporary path file, now that we've loaded it
321 ::DeleteFile(cmdLinePath.GetWinPath());
323 // This was a path to a temporary file - it's got no meaning now, and
324 // anybody who uses it again is in for a problem...
325 cmdLinePath.Reset();
328 else
331 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
332 if (parser.HasKey(_T("expaths")))
334 // an /expaths param means we're started via the buttons in our Win7 library
335 // and that means the value of /expaths is the current directory, and
336 // the selected paths are then added as additional parameters but without a key, only a value
338 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
339 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
340 // a save bet.
341 // Without this, a command line like:
342 // /command:commit /expaths:"D:\" "D:\Utils"
343 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
344 // mark and we'd end up with:
345 // argv[1] = /command:commit
346 // argv[2] = /expaths:D:" D:\Utils
347 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
348 CString cmdLine = GetCommandLineW();
349 cmdLine.Replace(L"\\", L"\\\\");
350 int nArgs = 0;
351 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
352 if (szArglist)
354 // argument 0 is the process path, so start with 1
355 for (int i = 1; i < nArgs; ++i)
357 if (szArglist[i][0] != '/')
359 if (!sPathArgument.IsEmpty())
360 sPathArgument += '*';
361 sPathArgument += szArglist[i];
364 sPathArgument.Replace(L"\\\\", L"\\");
366 LocalFree(szArglist);
368 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
370 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
371 return FALSE;
373 int asterisk = sPathArgument.Find('*');
374 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
375 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
378 if (pathList.IsEmpty()) {
379 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
382 // Subversion sometimes writes temp files to the current directory!
383 // Since TSVN doesn't need a specific CWD anyway, we just set it
384 // to the users temp folder: that way, Subversion is guaranteed to
385 // have write access to the CWD
387 DWORD len = GetCurrentDirectory(0, NULL);
388 if (len)
390 std::unique_ptr<TCHAR[]> originalCurrentDirectory(new TCHAR[len]);
391 if (GetCurrentDirectory(len, originalCurrentDirectory.get()))
393 sOrigCWD = originalCurrentDirectory.get();
394 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
397 TCHAR pathbuf[MAX_PATH] = {0};
398 GetTortoiseGitTempPath(MAX_PATH, pathbuf);
399 SetCurrentDirectory(pathbuf);
402 CheckForNewerVersion();
404 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
405 if (!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString(), parser.HasKey(_T("submodule")) == TRUE))
407 for (int i = 0; i < pathList.GetCount(); ++i)
408 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
409 break;
412 if(!g_Git.m_CurrentDir.IsEmpty())
414 sOrigCWD = g_Git.m_CurrentDir;
415 SetCurrentDirectory(g_Git.m_CurrentDir);
418 if (g_sGroupingUUID.IsEmpty())
420 CRegStdDWORD groupSetting = CRegStdDWORD(_T("Software\\TortoiseGit\\GroupTaskbarIconsPerRepo"), 3);
421 switch (DWORD(groupSetting))
423 case 1:
424 case 2:
425 // implemented differently to TortoiseSVN atm
426 break;
427 case 3:
428 case 4:
430 CString wcroot;
431 if (g_GitAdminDir.HasAdminDir(g_Git.m_CurrentDir, true, &wcroot))
433 git_oid oid;
434 CStringA wcRootA(wcroot + CPathUtils::GetAppDirectory());
435 if (!git_odb_hash(&oid, wcRootA, wcRootA.GetLength(), GIT_OBJ_BLOB))
437 CStringA hash;
438 git_oid_tostr(hash.GetBufferSetLength(GIT_OID_HEXSZ + 1), GIT_OID_HEXSZ + 1, &oid);
439 hash.ReleaseBuffer();
440 g_sGroupingUUID = hash;
442 ProjectProperties pp;
443 pp.ReadProps();
444 CString icon = pp.sIcon;
445 icon.Replace('/', '\\');
446 if (icon.IsEmpty())
447 g_bGroupingRemoveIcon = true;
448 g_sGroupingIcon = icon;
454 CString sAppID = GetTaskIDPerUUID(g_sGroupingUUID).c_str();
455 InitializeJumpList(sAppID);
456 EnsureGitLibrary(false);
459 CString err;
462 // requires CWD to be set
463 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
465 // make sure all config files are read in order to check that none contains an error
466 g_Git.GetConfigValue(_T("doesnot.exist"));
468 catch (char* msg)
470 err = CString(msg);
473 if (!err.IsEmpty())
475 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)));
476 if (choice == 1)
478 // open the config file with alternative editor
479 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitLocalConfig());
481 else if (choice == 2)
483 // open the global config file with alternative editor
484 CAppUtils::LaunchAlternativeEditor(g_Git.GetGitGlobalConfig());
486 return FALSE;
490 // execute the requested command
491 CommandServer server;
492 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
493 if (cmd)
495 cmd->SetExplorerHwnd(hWndExplorer);
497 cmd->SetParser(parser);
498 cmd->SetPaths(pathList, cmdLinePath);
500 retSuccess = cmd->Execute();
501 delete cmd;
504 // Look for temporary files left around by TortoiseSVN and
505 // remove them. But only delete 'old' files because some
506 // apps might still be needing the recent ones.
508 DWORD len = GetTortoiseGitTempPath(0, NULL);
509 std::unique_ptr<TCHAR[]> path(new TCHAR[len + 100]);
510 len = GetTortoiseGitTempPath (len + 100, path.get());
511 if (len != 0)
513 CDirFileEnum finder(path.get());
514 FILETIME systime_;
515 ::GetSystemTimeAsFileTime(&systime_);
516 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
517 bool isDir;
518 CString filepath;
519 while (finder.NextFile(filepath, &isDir))
521 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, isDir ? FILE_FLAG_BACKUP_SEMANTICS : NULL, NULL);
522 if (hFile != INVALID_HANDLE_VALUE)
524 FILETIME createtime_;
525 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
527 ::CloseHandle(hFile);
528 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
529 if ((createtime + 864000000000) < systime) //only delete files older than a day
531 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
532 if (isDir)
533 ::RemoveDirectory(filepath);
534 else
535 ::DeleteFile(filepath);
538 else
539 ::CloseHandle(hFile);
545 // Since the dialog has been closed, return FALSE so that we exit the
546 // application, rather than start the application's message pump.
547 return FALSE;
550 void CTortoiseProcApp::CheckUpgrade()
552 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
553 CString sVersion = regVersion;
554 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
555 return;
556 // we're starting the first time with a new version!
558 LONG lVersion = 0;
559 int 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);
567 else
569 pos = sVersion.Find(',');
570 if (pos > 0)
572 lVersion = (_ttol(sVersion.Left(pos))<<24);
573 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
574 pos = sVersion.Find(',', pos+1);
575 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
579 if (lVersion <= 0x01080401)
581 if (CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI"), FALSE) == TRUE)
582 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\DeliveryType")) = 1;
583 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\SendMail\\UseMAPI")).removeValue();
586 if (lVersion <= 0x01080202)
588 CSoundUtils::RegisterTGitSounds();
589 // upgrade to 1.8.3: force recreation of all diff scripts.
590 CAppUtils::SetupDiffScripts(true, CString());
593 if (lVersion <= 0x01080100)
595 if (CRegStdDWORD(_T("Software\\TortoiseGit\\LogTopoOrder"), TRUE) == FALSE)
596 CRegStdDWORD(_T("Software\\TortoiseGit\\LogOrderBy")) = 0;
598 // smoothly migrate broken msysgit path settings
599 CString oldmsysGitSetting = CRegString(REG_MSYSGIT_PATH);
600 oldmsysGitSetting.TrimRight(_T("\\"));
601 CString right = oldmsysGitSetting.Right(4);
602 if (oldmsysGitSetting.GetLength() > 4 && oldmsysGitSetting.Right(4) == _T("\\cmd"))
604 CString newPath = oldmsysGitSetting.Mid(0, oldmsysGitSetting.GetLength() - 3) + _T("bin");
605 if (PathFileExists(newPath + _T("\\git.exe")))
607 CRegString(REG_MSYSGIT_PATH) = newPath;
608 g_Git.m_bInitialized = FALSE;
609 g_Git.CheckMsysGitDir();
614 if (lVersion <= 0x01040000)
616 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
619 if (lVersion <= 0x01070600)
621 CoInitialize(NULL);
622 EnsureGitLibrary();
623 CoUninitialize();
624 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
625 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
626 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
627 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
630 if (lVersion <= 0x01070E00)
632 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
634 CAppUtils::SetupDiffScripts(false, CString());
636 // set the current version so we don't come here again until the next update!
637 regVersion = _T(STRPRODUCTVER);
640 void CTortoiseProcApp::InitializeJumpList(const CString& appid)
642 // for Win7 : use a custom jump list
643 CoInitialize(NULL);
644 SetAppID(appid);
645 DeleteJumpList(appid);
646 DoInitializeJumpList(appid);
647 CoUninitialize();
650 void CTortoiseProcApp::DoInitializeJumpList(const CString& appid)
652 ATL::CComPtr<ICustomDestinationList> pcdl;
653 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
654 if (FAILED(hr))
655 return;
657 hr = pcdl->SetAppID(appid);
658 if (FAILED(hr))
659 return;
661 UINT uMaxSlots;
662 ATL::CComPtr<IObjectArray> poaRemoved;
663 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
664 if (FAILED(hr))
665 return;
667 ATL::CComPtr<IObjectCollection> poc;
668 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
669 if (FAILED(hr))
670 return;
672 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
673 sTemp.Remove('&');
675 ATL::CComPtr<IShellLink> psl;
676 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
677 if (SUCCEEDED(hr)) {
678 poc->AddObject(psl);
680 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
681 sTemp.Remove('&');
682 psl.Release(); // Need to release the object before calling operator&()
683 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
684 if (SUCCEEDED(hr)) {
685 poc->AddObject(psl);
688 ATL::CComPtr<IObjectArray> poa;
689 hr = poc.QueryInterface(&poa);
690 if (SUCCEEDED(hr)) {
691 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
692 pcdl->CommitList();
696 int CTortoiseProcApp::ExitInstance()
698 Gdiplus::GdiplusShutdown(m_gdiplusToken);
700 CWinAppEx::ExitInstance();
701 if (retSuccess)
702 return 0;
703 return -1;
706 void CTortoiseProcApp::CheckForNewerVersion()
708 // check for newer versions
709 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
711 time_t now;
712 struct tm ptm;
714 time(&now);
715 if ((now != 0) && (localtime_s(&ptm, &now)==0))
717 #if PREVIEW
718 // Check daily for new preview releases
719 CRegDWORD oldday = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerDay"), (DWORD)-1);
720 if (((DWORD)oldday) == -1)
721 oldday = ptm.tm_yday;
722 else
724 if ((DWORD)oldday != (DWORD)ptm.tm_yday)
726 oldday = ptm.tm_yday;
727 #else
728 int week = 0;
729 // we don't calculate the real 'week of the year' here
730 // because just to decide if we should check for an update
731 // that's not needed.
732 week = ptm.tm_yday / 7;
734 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
735 if (((DWORD)oldweek) == -1)
736 oldweek = week; // first start of TortoiseProc, no update check needed
737 else
739 if ((DWORD)week != oldweek)
741 oldweek = week;
742 #endif
743 CAppUtils::RunTortoiseGitProc(_T("/command:updatecheck"), false, false);