Added CString wrapper for get_windows_home_directory()
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob85f1170fcaed2646603334ad4872e41d701c4332
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 "vld.h"
22 #include "TortoiseProc.h"
23 #include "SysImageList.h"
24 #include "..\Utils\CrashReport.h"
25 #include "CmdLineParser.h"
26 #include "Hooks.h"
27 #include "AppUtils.h"
28 #include "PathUtils.h"
29 #include "UnicodeUtils.h"
30 #include "MessageBox.h"
31 //#include "libintl.h"
32 #include "DirFileEnum.h"
33 //#include "SoundUtils.h"
34 //#include "SVN.h"
35 #include "GitAdminDir.h"
36 #include "Git.h"
37 //#include "SVNGlobal.h"
38 //#include "svn_types.h"
39 //#include "svn_dso.h"
40 //#include <openssl/ssl.h>
41 //#include <openssl/err.h>
42 #include "SmartHandle.h"
43 #include "Commands\Command.h"
44 #include "..\version.h"
45 #include "JumpListHelpers.h"
46 #include "SinglePropSheetDlg.h"
47 #include "Settings\setmainpage.h"
48 #include "..\Settings\Settings.h"
49 #include "gitindex.h"
50 #include "Libraries.h"
52 #define STRUCT_IOVEC_DEFINED
53 //#include "sasl.h"
55 #ifdef _DEBUG
56 #define new DEBUG_NEW
57 #endif
59 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
61 #define APPID (_T("TGIT.TGIT.1") _T(TGIT_PLATFORM))
63 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
64 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
65 END_MESSAGE_MAP()
67 //CString g_version;
68 //CString CGit::m_MsysGitPath;
69 //////////////////////////////////////////////////////////////////////////
71 CTortoiseProcApp::CTortoiseProcApp()
73 SetDllDirectory(L"");
74 CCrashReport::Instance().AddUserInfoToReport(L"CommandLine", GetCommandLine());
75 EnableHtmlHelp();
76 // int argc = 0;
77 // const char* const * argv = NULL;
78 // apr_app_initialize(&argc, &argv, NULL);
79 // svn_dso_initialize2();
80 SYS_IMAGE_LIST();
81 CHooks::Create();
82 g_GitAdminDir.Init();
83 m_bLoadUserToolbars = FALSE;
84 m_bSaveState = FALSE;
85 retSuccess = false;
89 CTortoiseProcApp::~CTortoiseProcApp()
91 // global application exit cleanup (after all SSL activity is shutdown)
92 // we have to clean up SSL ourselves, since neon doesn't do that (can't do it)
93 // because those cleanup functions work globally per process.
94 //ERR_free_strings();
95 //EVP_cleanup();
96 //CRYPTO_cleanup_all_ex_data();
98 // since it is undefined *when* the global object SVNAdminDir is
99 // destroyed, we tell it to destroy the memory pools and terminate apr
100 // *now* instead of later when the object itself is destroyed.
101 g_GitAdminDir.Close();
102 CHooks::Destroy();
103 SYS_IMAGE_LIST().Cleanup();
104 //apr_terminate();
107 // The one and only CTortoiseProcApp object
108 CTortoiseProcApp theApp;
109 CString sOrigCWD;
110 HWND hWndExplorer;
112 BOOL CTortoiseProcApp::CheckMsysGitDir()
114 //CGitIndexFileMap map;
115 //int status;
116 //CTGitPath path;
117 //path.SetFromGit(_T("src/gpl.txt"));
118 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
119 return g_Git.CheckMsysGitDir();
121 CCrashReportTGit crasher(L"TortoiseGit " _T(APP_X64_STRING));
123 // CTortoiseProcApp initialization
125 BOOL CTortoiseProcApp::InitInstance()
127 CheckUpgrade();
128 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
129 CMFCButton::EnableWindowsTheming();
131 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
132 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
134 //set the resource dll for the required language
135 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
136 long langId = loc;
137 CString langDll;
138 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
139 langpath += "Languages";
140 // bindtextdomain("subversion", (LPCSTR)langpath);
141 // bind_textdomain_codeset("subversion", "UTF-8");
142 HINSTANCE hInst = NULL;
145 langDll.Format(_T("%sLanguages\\TortoiseProc%d.dll"), (LPCTSTR)CPathUtils::GetAppParentDirectory(), langId);
147 hInst = LoadLibrary(langDll);
149 CString sVer = _T(STRPRODUCTVER);
150 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
151 if (sFileVer.Compare(sVer)!=0)
153 FreeLibrary(hInst);
154 hInst = NULL;
156 if (hInst != NULL)
158 AfxSetResourceHandle(hInst);
160 else
162 DWORD lid = SUBLANGID(langId);
163 lid--;
164 if (lid > 0)
166 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
168 else
169 langId = 0;
171 } while ((hInst == NULL) && (langId != 0));
172 TCHAR buf[6];
173 _tcscpy_s(buf, _T("en"));
174 langId = loc;
175 CString sHelppath;
176 sHelppath = this->m_pszHelpFilePath;
177 sHelppath = sHelppath.MakeLower();
178 // MFC uses a help file with the same name as the application by default,
179 // which means we have to change that default to our language specific help files
180 sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseGit_en.chm"));
181 free((void*)m_pszHelpFilePath);
182 m_pszHelpFilePath=_tcsdup(sHelppath);
183 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
186 CString sLang = _T("_");
187 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
189 sLang += buf;
190 sHelppath.Replace(_T("_en"), sLang);
191 if (PathFileExists(sHelppath))
193 free((void*)m_pszHelpFilePath);
194 m_pszHelpFilePath=_tcsdup(sHelppath);
195 break;
198 sHelppath.Replace(sLang, _T("_en"));
199 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
201 sLang += _T("_");
202 sLang += buf;
203 sHelppath.Replace(_T("_en"), sLang);
204 if (PathFileExists(sHelppath))
206 free((void*)m_pszHelpFilePath);
207 m_pszHelpFilePath=_tcsdup(sHelppath);
208 break;
211 sHelppath.Replace(sLang, _T("_en"));
213 DWORD lid = SUBLANGID(langId);
214 lid--;
215 if (lid > 0)
217 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
219 else
220 langId = 0;
221 } while (langId);
222 setlocale(LC_ALL, "");
224 if(!CheckMsysGitDir())
226 UINT ret = CMessageBox::Show(NULL, IDS_PROC_NOMSYSGIT, IDS_APPNAME, 3, IDI_HAND, IDS_PROC_SETMSYSGITPATH, IDS_PROC_GOTOMSYSGITWEBSITE, IDS_ABORTBUTTON);
227 if(ret == 2)
229 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
231 else if(ret == 1)
233 // open settings dialog
234 CSinglePropSheetDlg(CString(MAKEINTRESOURCE(IDS_PROC_SETTINGS_TITLE)), new CSetMainPage(), this->GetMainWnd()).DoModal();
236 return FALSE;
238 if (CAppUtils::GetMsysgitVersion() < 0x01070a00)
240 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);
241 if (ret == 1)
243 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
244 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
245 return FALSE;
247 else if (ret == 2)
249 CRegStdDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\OldMsysgitVersionWarning")).removeValue(); // only store answer if it is "Ignore"
250 return FALSE;
254 // InitCommonControls() is required on Windows XP if an application
255 // manifest specifies use of ComCtl32.dll version 6 or later to enable
256 // visual styles. Otherwise, any window creation will fail.
258 INITCOMMONCONTROLSEX used = {
259 sizeof(INITCOMMONCONTROLSEX),
260 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
261 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
262 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
263 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
264 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
266 InitCommonControlsEx(&used);
267 AfxOleInit();
268 AfxEnableControlContainer();
269 AfxInitRichEdit2();
270 CWinAppEx::InitInstance();
271 SetRegistryKey(_T("TortoiseGit"));
273 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
275 hWndExplorer = NULL;
276 CString sVal = parser.GetVal(_T("hwnd"));
277 if (!sVal.IsEmpty())
278 hWndExplorer = (HWND)_ttoi64(sVal);
280 while (GetParent(hWndExplorer)!=NULL)
281 hWndExplorer = GetParent(hWndExplorer);
282 if (!IsWindow(hWndExplorer))
284 hWndExplorer = NULL;
287 // if HKCU\Software\TortoiseGit\Debug is not 0, show our command line
288 // in a message box
289 if (CRegDWORD(_T("Software\\TortoiseGit\\Debug"), FALSE)==TRUE)
290 AfxMessageBox(AfxGetApp()->m_lpCmdLine, MB_OK | MB_ICONINFORMATION);
292 if ( parser.HasKey(_T("path")) && parser.HasKey(_T("pathfile")))
294 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
295 return FALSE;
298 CTGitPath cmdLinePath;
299 CTGitPathList pathList;
300 if ( parser.HasKey(_T("pathfile")) )
303 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
305 cmdLinePath.SetFromUnknown(sPathfileArgument);
306 if (pathList.LoadFromFile(cmdLinePath)==false)
307 return FALSE; // no path specified!
308 if ( parser.HasKey(_T("deletepathfile")) )
310 // We can delete the temporary path file, now that we've loaded it
311 ::DeleteFile(cmdLinePath.GetWinPath());
313 // This was a path to a temporary file - it's got no meaning now, and
314 // anybody who uses it again is in for a problem...
315 cmdLinePath.Reset();
318 else
321 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
322 if (parser.HasKey(_T("expaths")))
324 // an /expaths param means we're started via the buttons in our Win7 library
325 // and that means the value of /expaths is the current directory, and
326 // the selected paths are then added as additional parameters but without a key, only a value
328 // because of the "strange treatment of quotation marks and backslashes by CommandLineToArgvW"
329 // we have to escape the backslashes first. Since we're only dealing with paths here, that's
330 // a save bet.
331 // Without this, a command line like:
332 // /command:commit /expaths:"D:\" "D:\Utils"
333 // would fail because the "D:\" is treated as the backslash being the escape char for the quotation
334 // mark and we'd end up with:
335 // argv[1] = /command:commit
336 // argv[2] = /expaths:D:" D:\Utils
337 // See here for more details: http://blogs.msdn.com/b/oldnewthing/archive/2010/09/17/10063629.aspx
338 CString cmdLine = GetCommandLineW();
339 cmdLine.Replace(L"\\", L"\\\\");
340 int nArgs = 0;
341 LPWSTR *szArglist = CommandLineToArgvW(cmdLine, &nArgs);
342 if (szArglist)
344 // argument 0 is the process path, so start with 1
345 for (int i=1; i<nArgs; i++)
347 if (szArglist[i][0] != '/')
349 if (!sPathArgument.IsEmpty())
350 sPathArgument += '*';
351 sPathArgument += szArglist[i];
354 sPathArgument.Replace(L"\\\\", L"\\");
356 LocalFree(szArglist);
358 if (sPathArgument.IsEmpty() && parser.HasKey(L"path"))
360 CMessageBox::Show(hWndExplorer, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
361 return FALSE;
363 int asterisk = sPathArgument.Find('*');
364 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
365 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
368 if (pathList.GetCount() == 0) {
369 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
372 InitializeJumpList();
373 EnsureGitLibrary(false);
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 auto_buffer<TCHAR> originalCurrentDirectory(len);
384 if (GetCurrentDirectory(len, originalCurrentDirectory))
386 sOrigCWD = originalCurrentDirectory;
387 sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
390 TCHAR pathbuf[MAX_PATH];
391 GetTempPath(MAX_PATH, pathbuf);
392 SetCurrentDirectory(pathbuf);
395 CheckForNewerVersion();
397 if (parser.HasVal(_T("configdir")))
399 // the user can override the location of the Subversion config directory here
400 CString sConfigDir = parser.GetVal(_T("configdir"));
401 // g_GitGlobal.SetConfigDir(sConfigDir);
403 // to avoid that SASL will look for and load its plugin dlls all around the
404 // system, we set the path here.
405 // Note that SASL doesn't have to be initialized yet for this to work
406 // sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::GetUTF8(CPathUtils::GetAppDirectory().TrimRight('\\')));
408 CAutoGeneralHandle TGitMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
409 if(!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString()))
411 int i=0;
412 for(i=0;i<pathList.GetCount();i++)
413 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
414 break;
417 if(!g_Git.m_CurrentDir.IsEmpty())
419 sOrigCWD = g_Git.m_CurrentDir;
420 SetCurrentDirectory(g_Git.m_CurrentDir);
424 CString err;
427 // requires CWD to be set
428 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
430 catch (char* msg)
432 err = CString(msg);
435 if (!err.IsEmpty())
437 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)));
438 if (choice == 1)
440 // open the config file with alternative editor
441 CString path;
442 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, path);
443 path += _T("config");
444 CAppUtils::LaunchAlternativeEditor(path);
446 else if (choice == 2)
448 // open the global config file with alternative editor
449 CString filename = g_Git.GetHomeDirectory() + _T("\\.gitconfig");
450 CAppUtils::LaunchAlternativeEditor(filename);
452 return FALSE;
456 // execute the requested command
457 CommandServer server;
458 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
459 if (cmd)
461 cmd->SetExplorerHwnd(hWndExplorer);
463 cmd->SetParser(parser);
464 cmd->SetPaths(pathList, cmdLinePath);
466 retSuccess = cmd->Execute();
467 delete cmd;
470 // Look for temporary files left around by TortoiseSVN and
471 // remove them. But only delete 'old' files because some
472 // apps might still be needing the recent ones.
474 DWORD len = ::GetTempPath(0, NULL);
475 TCHAR * path = new TCHAR[len + 100];
476 len = ::GetTempPath (len+100, path);
477 if (len != 0)
479 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
480 FILETIME systime_;
481 ::GetSystemTimeAsFileTime(&systime_);
482 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
483 while (finder.FindNextFileNoDirectories())
485 CString filepath = finder.GetFilePath();
486 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
487 if (hFile != INVALID_HANDLE_VALUE)
489 FILETIME createtime_;
490 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
492 ::CloseHandle(hFile);
493 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
494 if ((createtime + 864000000000) < systime) //only delete files older than a day
496 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
497 ::DeleteFile(filepath);
500 else
501 ::CloseHandle(hFile);
505 delete[] path;
508 // Since the dialog has been closed, return FALSE so that we exit the
509 // application, rather than start the application's message pump.
510 return FALSE;
513 void CTortoiseProcApp::CheckUpgrade()
515 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
516 CString sVersion = regVersion;
517 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
518 return;
519 // we're starting the first time with a new version!
521 LONG lVersion = 0;
522 int pos = sVersion.Find(',');
523 if (pos > 0)
525 lVersion = (_ttol(sVersion.Left(pos))<<24);
526 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
527 pos = sVersion.Find(',', pos+1);
528 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
531 if (lVersion <= 0x01070600)
533 CoInitialize(NULL);
534 EnsureGitLibrary();
535 CoUninitialize();
536 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
537 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
538 if (CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) == FALSE)
539 CRegStdDWORD(_T("Software\\TortoiseGit\\VersionCheck")) = FALSE;
540 CRegStdDWORD(_T("Software\\TortoiseGit\\CheckNewer")).removeValue();
542 #if 0
543 if (lVersion <= 0x01010300)
545 CSoundUtils::RegisterTSVNSounds();
547 #endif
548 if (lVersion <= 0x01020200)
550 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
551 // so remove the diff/merge scripts if they're the defaults
552 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
553 CString sDiff = diffreg;
554 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
555 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
556 diffreg = _T("");
557 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
558 sDiff = mergereg;
559 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
560 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
561 mergereg = _T("");
563 if (lVersion <= 0x01040000)
565 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
568 // set the custom diff scripts for every user
569 CString scriptsdir = CPathUtils::GetAppParentDirectory();
570 scriptsdir += _T("Diff-Scripts");
571 CSimpleFileFind files(scriptsdir);
572 while (files.FindNextFileNoDirectories())
574 CString file = files.GetFilePath();
575 CString filename = files.GetFileName();
576 CString ext = file.Mid(file.ReverseFind('-')+1);
577 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
578 CString kind;
579 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
581 kind = _T(" //E:vbscript");
583 if (file.Right(2).CompareNoCase(_T("js"))==0)
585 kind = _T(" //E:javascript");
588 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
590 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
591 CString diffregstring = diffreg;
592 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
593 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
595 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
597 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
598 CString diffregstring = diffreg;
599 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
600 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
604 // set the current version so we don't come here again until the next update!
605 regVersion = _T(STRPRODUCTVER);
608 void CTortoiseProcApp::InitializeJumpList()
610 // for Win7 : use a custom jump list
611 CoInitialize(NULL);
612 SetAppID(APPID);
613 DeleteJumpList(APPID);
614 DoInitializeJumpList();
615 CoUninitialize();
618 void CTortoiseProcApp::DoInitializeJumpList()
620 ATL::CComPtr<ICustomDestinationList> pcdl;
621 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
622 if (FAILED(hr))
623 return;
625 hr = pcdl->SetAppID(APPID);
626 if (FAILED(hr))
627 return;
629 UINT uMaxSlots;
630 ATL::CComPtr<IObjectArray> poaRemoved;
631 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
632 if (FAILED(hr))
633 return;
635 ATL::CComPtr<IObjectCollection> poc;
636 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
637 if (FAILED(hr))
638 return;
640 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
641 sTemp.Remove('&');
643 ATL::CComPtr<IShellLink> psl;
644 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
645 if (SUCCEEDED(hr)) {
646 poc->AddObject(psl);
648 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
649 sTemp.Remove('&');
650 psl.Release(); // Need to release the object before calling operator&()
651 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
652 if (SUCCEEDED(hr)) {
653 poc->AddObject(psl);
656 ATL::CComPtr<IObjectArray> poa;
657 hr = poc.QueryInterface(&poa);
658 if (SUCCEEDED(hr)) {
659 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
660 pcdl->CommitList();
664 int CTortoiseProcApp::ExitInstance()
666 Gdiplus::GdiplusShutdown(m_gdiplusToken);
668 CWinAppEx::ExitInstance();
669 if (retSuccess)
670 return 0;
671 return -1;
674 void CTortoiseProcApp::CheckForNewerVersion()
676 // check for newer versions
677 if (CRegDWORD(_T("Software\\TortoiseGit\\VersionCheck"), TRUE) != FALSE)
679 time_t now;
680 struct tm ptm;
682 time(&now);
683 if ((now != 0) && (localtime_s(&ptm, &now)==0))
685 int week = 0;
686 // we don't calculate the real 'week of the year' here
687 // because just to decide if we should check for an update
688 // that's not needed.
689 week = ptm.tm_yday / 7;
691 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
692 if (((DWORD)oldweek) == -1)
693 oldweek = week; // first start of TortoiseProc, no update check needed
694 else
696 if ((DWORD)week != oldweek)
698 oldweek = week;
700 TCHAR com[MAX_PATH+100];
701 GetModuleFileName(NULL, com, MAX_PATH);
702 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
704 CAppUtils::LaunchApplication(com, 0, false);