updated copyright year of files we changed since 2012-01-01
[TortoiseGit.git] / src / TortoiseProc / TortoiseProc.cpp
blob25c8f90dfc7330993e7e764e63aa648f381795ba
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 "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>
43 #include "Commands\Command.h"
44 #include "CommonResource.h"
45 #include "..\version.h"
46 #include "JumpListHelpers.h"
47 #include "..\Settings\Settings.h"
48 #include "gitindex.h"
50 #define STRUCT_IOVEC_DEFINED
51 //#include "sasl.h"
53 #ifdef _DEBUG
54 #define new DEBUG_NEW
55 #endif
57 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
59 #define APPID (_T("TGIT.TGIT.1") _T(TGIT_PLATFORM))
61 BEGIN_MESSAGE_MAP(CTortoiseProcApp, CWinAppEx)
62 ON_COMMAND(ID_HELP, CWinAppEx::OnHelp)
63 END_MESSAGE_MAP()
65 //CString g_version;
66 //CString CGit::m_MsysGitPath;
67 //////////////////////////////////////////////////////////////////////////
69 CTortoiseProcApp::CTortoiseProcApp()
71 SetDllDirectory(L"");
72 EnableHtmlHelp();
73 // int argc = 0;
74 // const char* const * argv = NULL;
75 // apr_app_initialize(&argc, &argv, NULL);
76 // svn_dso_initialize2();
77 SYS_IMAGE_LIST();
78 CHooks::Create();
79 g_GitAdminDir.Init();
80 m_bLoadUserToolbars = FALSE;
81 m_bSaveState = FALSE;
82 retSuccess = false;
86 CTortoiseProcApp::~CTortoiseProcApp()
88 // global application exit cleanup (after all SSL activity is shutdown)
89 // we have to clean up SSL ourselves, since neon doesn't do that (can't do it)
90 // because those cleanup functions work globally per process.
91 //ERR_free_strings();
92 //EVP_cleanup();
93 //CRYPTO_cleanup_all_ex_data();
95 // since it is undefined *when* the global object SVNAdminDir is
96 // destroyed, we tell it to destroy the memory pools and terminate apr
97 // *now* instead of later when the object itself is destroyed.
98 g_GitAdminDir.Close();
99 CHooks::Destroy();
100 SYS_IMAGE_LIST().Cleanup();
101 //apr_terminate();
104 // The one and only CTortoiseProcApp object
105 CTortoiseProcApp theApp;
106 HWND hWndExplorer;
108 BOOL CTortoiseProcApp::CheckMsysGitDir()
110 CGitIndexFileMap map;
111 //int status;
112 //CTGitPath path;
113 //path.SetFromGit(_T("src/gpl.txt"));
114 //map.GetFileStatus(_T("D:\\TortoiseGit"),&path, &status);
115 return g_Git.CheckMsysGitDir();
117 CCrashReport crasher("tortoisegit-bug@googlegroups.com", "Crash Report for TortoiseGit " APP_X64_STRING " : " STRPRODUCTVER, TRUE);// crash
119 // CTortoiseProcApp initialization
121 BOOL CTortoiseProcApp::InitInstance()
123 EnableCrashHandler();
124 InitializeJumpList();
125 CheckUpgrade();
126 CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
127 CMFCButton::EnableWindowsTheming();
129 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
130 Gdiplus::GdiplusStartup(&m_gdiplusToken,&gdiplusStartupInput,NULL);
132 if(!CheckMsysGitDir())
134 UINT ret = CMessageBox::Show(NULL,_T("MSysGit (http://code.google.com/p/msysgit/) not found."),
135 _T("TortoiseGit"), 3, IDI_HAND, _T("&Set MSysGit path"), _T("&Goto WebSite"), _T("&Abort"));
136 if(ret == 2)
138 ShellExecute(NULL, NULL, _T("http://code.google.com/p/msysgit/"), NULL, NULL, SW_SHOW);
140 else if(ret == 1)
142 // open settings dialog
143 CSettings dlg(IDS_PROC_SETTINGS_TITLE);
144 dlg.SetTreeViewMode(TRUE, TRUE, TRUE);
145 dlg.SetTreeWidth(220);
147 dlg.DoModal();
148 dlg.HandleRestart();
150 return FALSE;
153 //set the resource dll for the required language
154 CRegDWORD loc = CRegDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
155 long langId = loc;
156 CString langDll;
157 CStringA langpath = CStringA(CPathUtils::GetAppParentDirectory());
158 langpath += "Languages";
159 // bindtextdomain("subversion", (LPCSTR)langpath);
160 // bind_textdomain_codeset("subversion", "UTF-8");
161 HINSTANCE hInst = NULL;
164 langDll.Format(_T("..\\Languages\\TortoiseProc%d.dll"), langId);
166 hInst = LoadLibrary(langDll);
168 CString sVer = _T(STRPRODUCTVER);
169 CString sFileVer = CPathUtils::GetVersionFromFile(langDll);
170 if (sFileVer.Compare(sVer)!=0)
172 FreeLibrary(hInst);
173 hInst = NULL;
175 if (hInst != NULL)
177 AfxSetResourceHandle(hInst);
179 else
181 DWORD lid = SUBLANGID(langId);
182 lid--;
183 if (lid > 0)
185 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
187 else
188 langId = 0;
190 } while ((hInst == NULL) && (langId != 0));
191 TCHAR buf[6];
192 _tcscpy_s(buf, _T("en"));
193 langId = loc;
194 CString sHelppath;
195 sHelppath = this->m_pszHelpFilePath;
196 sHelppath = sHelppath.MakeLower();
197 // MFC uses a help file with the same name as the application by default,
198 // which means we have to change that default to our language specific help files
199 sHelppath.Replace(_T("tortoiseproc.chm"), _T("TortoiseGit_en.chm"));
200 free((void*)m_pszHelpFilePath);
201 m_pszHelpFilePath=_tcsdup(sHelppath);
202 sHelppath = CPathUtils::GetAppParentDirectory() + _T("Languages\\TortoiseGit_en.chm");
205 CString sLang = _T("_");
206 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO639LANGNAME, buf, _countof(buf)))
208 sLang += buf;
209 sHelppath.Replace(_T("_en"), sLang);
210 if (PathFileExists(sHelppath))
212 free((void*)m_pszHelpFilePath);
213 m_pszHelpFilePath=_tcsdup(sHelppath);
214 break;
217 sHelppath.Replace(sLang, _T("_en"));
218 if (GetLocaleInfo(MAKELCID(langId, SORT_DEFAULT), LOCALE_SISO3166CTRYNAME, buf, _countof(buf)))
220 sLang += _T("_");
221 sLang += buf;
222 sHelppath.Replace(_T("_en"), sLang);
223 if (PathFileExists(sHelppath))
225 free((void*)m_pszHelpFilePath);
226 m_pszHelpFilePath=_tcsdup(sHelppath);
227 break;
230 sHelppath.Replace(sLang, _T("_en"));
232 DWORD lid = SUBLANGID(langId);
233 lid--;
234 if (lid > 0)
236 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
238 else
239 langId = 0;
240 } while (langId);
241 setlocale(LC_ALL, "");
243 // InitCommonControls() is required on Windows XP if an application
244 // manifest specifies use of ComCtl32.dll version 6 or later to enable
245 // visual styles. Otherwise, any window creation will fail.
247 INITCOMMONCONTROLSEX used = {
248 sizeof(INITCOMMONCONTROLSEX),
249 ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_COOL_CLASSES | ICC_DATE_CLASSES |
250 ICC_HOTKEY_CLASS | ICC_INTERNET_CLASSES | ICC_LISTVIEW_CLASSES |
251 ICC_NATIVEFNTCTL_CLASS | ICC_PAGESCROLLER_CLASS | ICC_PROGRESS_CLASS |
252 ICC_TAB_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS |
253 ICC_USEREX_CLASSES | ICC_WIN95_CLASSES
255 InitCommonControlsEx(&used);
256 AfxOleInit();
257 AfxEnableControlContainer();
258 AfxInitRichEdit2();
259 CWinAppEx::InitInstance();
260 SetRegistryKey(_T("TortoiseGit"));
262 CCmdLineParser parser(AfxGetApp()->m_lpCmdLine);
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("path")) && parser.HasKey(_T("pathfile")))
271 CMessageBox::Show(NULL, IDS_ERR_INVALIDPATH, IDS_APPNAME, MB_ICONERROR);
272 return FALSE;
275 CTGitPath cmdLinePath;
276 CTGitPathList pathList;
277 if ( parser.HasKey(_T("pathfile")) )
280 CString sPathfileArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("pathfile")));
282 cmdLinePath.SetFromUnknown(sPathfileArgument);
283 if (pathList.LoadFromFile(cmdLinePath)==false)
284 return FALSE; // no path specified!
285 if ( parser.HasKey(_T("deletepathfile")) )
287 // We can delete the temporary path file, now that we've loaded it
288 ::DeleteFile(cmdLinePath.GetWinPath());
290 // This was a path to a temporary file - it's got no meaning now, and
291 // anybody who uses it again is in for a problem...
292 cmdLinePath.Reset();
295 else
298 CString sPathArgument = CPathUtils::GetLongPathname(parser.GetVal(_T("path")));
299 int asterisk = sPathArgument.Find('*');
300 cmdLinePath.SetFromUnknown(asterisk >= 0 ? sPathArgument.Left(asterisk) : sPathArgument);
301 pathList.LoadFromAsteriskSeparatedString(sPathArgument);
304 if (pathList.GetCount() == 0) {
305 pathList.AddPath(CTGitPath::CTGitPath(g_Git.m_CurrentDir));
308 hWndExplorer = NULL;
309 CString sVal = parser.GetVal(_T("hwnd"));
310 if (!sVal.IsEmpty())
311 hWndExplorer = (HWND)_ttoi64(sVal);
313 while (GetParent(hWndExplorer)!=NULL)
314 hWndExplorer = GetParent(hWndExplorer);
315 if (!IsWindow(hWndExplorer))
317 hWndExplorer = NULL;
320 // Subversion sometimes writes temp files to the current directory!
321 // Since TSVN doesn't need a specific CWD anyway, we just set it
322 // to the users temp folder: that way, Subversion is guaranteed to
323 // have write access to the CWD
325 DWORD len = GetCurrentDirectory(0, NULL);
326 if (len)
328 TCHAR * originalCurrentDirectory = new TCHAR[len];
329 if (GetCurrentDirectory(len, originalCurrentDirectory))
331 //sOrigCWD = originalCurrentDirectory;
332 //sOrigCWD = CPathUtils::GetLongPathname(sOrigCWD);
334 delete [] originalCurrentDirectory;
336 TCHAR pathbuf[MAX_PATH];
337 GetTempPath(MAX_PATH, pathbuf);
338 SetCurrentDirectory(pathbuf);
341 // check for newer versions
342 if (CRegDWORD(_T("Software\\TortoiseGit\\CheckNewer"), TRUE) != FALSE)
344 time_t now;
345 struct tm ptm;
347 time(&now);
348 if ((now != 0) && (localtime_s(&ptm, &now)==0))
350 int week = 0;
351 // we don't calculate the real 'week of the year' here
352 // because just to decide if we should check for an update
353 // that's not needed.
354 week = ptm.tm_yday / 7;
356 CRegDWORD oldweek = CRegDWORD(_T("Software\\TortoiseGit\\CheckNewerWeek"), (DWORD)-1);
357 if (((DWORD)oldweek) == -1)
358 oldweek = week; // first start of TortoiseProc, no update check needed
359 else
361 if ((DWORD)week != oldweek)
363 oldweek = week;
365 TCHAR com[MAX_PATH+100];
366 GetModuleFileName(NULL, com, MAX_PATH);
367 _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));
369 CAppUtils::LaunchApplication(com, 0, false);
375 if (parser.HasVal(_T("configdir")))
377 // the user can override the location of the Subversion config directory here
378 CString sConfigDir = parser.GetVal(_T("configdir"));
379 // g_GitGlobal.SetConfigDir(sConfigDir);
381 // to avoid that SASL will look for and load its plugin dlls all around the
382 // system, we set the path here.
383 // Note that SASL doesn't have to be initialized yet for this to work
384 // sasl_set_path(SASL_PATH_TYPE_PLUGIN, (LPSTR)(LPCSTR)CUnicodeUtils::GetUTF8(CPathUtils::GetAppDirectory().TrimRight('\\')));
386 HANDLE TSVNMutex = ::CreateMutex(NULL, FALSE, _T("TortoiseGitProc.exe"));
387 if(!g_Git.SetCurrentDir(cmdLinePath.GetWinPathString()))
389 int i=0;
390 for(i=0;i<pathList.GetCount();i++)
391 if(g_Git.SetCurrentDir(pathList[i].GetWinPath()))
392 break;
395 if(!g_Git.m_CurrentDir.IsEmpty())
396 SetCurrentDirectory(g_Git.m_CurrentDir);
399 CString err;
402 // requires CWD to be set
403 CGit::m_LogEncode = CAppUtils::GetLogOutputEncode();
405 catch (char* msg)
407 err = CString(msg);
410 if (!err.IsEmpty())
412 UINT choice = CMessageBox::Show(hWndExplorer, err, _T("TortoiseGit Error"), 1, IDI_ERROR, _T("&Edit .git/config"), _T("Edit &global .gitconfig"), _T("&Abort"));
413 if (choice == 1)
415 // open the config file with alternative editor
416 CString path;
417 g_GitAdminDir.GetAdminDirPath(g_Git.m_CurrentDir, path);
418 path += _T("config");
419 CAppUtils::LaunchAlternativeEditor(path);
421 else if (choice == 2)
423 // open the global config file with alternative editor
424 char charBuf[MAX_PATH];
425 TCHAR buf[MAX_PATH];
426 strcpy_s(charBuf, MAX_PATH, get_windows_home_directory());
427 _tcscpy_s(buf, MAX_PATH, CA2CT(charBuf));
428 _tcscat_s(buf, MAX_PATH, _T("\\.gitconfig"));
429 CAppUtils::LaunchAlternativeEditor(buf);
431 return FALSE;
435 // execute the requested command
436 CommandServer server;
437 Command * cmd = server.GetCommand(parser.GetVal(_T("command")));
438 if (cmd)
440 cmd->SetExplorerHwnd(hWndExplorer);
442 cmd->SetParser(parser);
443 cmd->SetPaths(pathList, cmdLinePath);
445 retSuccess = cmd->Execute();
446 delete cmd;
449 if (TSVNMutex)
450 ::CloseHandle(TSVNMutex);
452 // Look for temporary files left around by TortoiseSVN and
453 // remove them. But only delete 'old' files because some
454 // apps might still be needing the recent ones.
456 DWORD len = ::GetTempPath(0, NULL);
457 TCHAR * path = new TCHAR[len + 100];
458 len = ::GetTempPath (len+100, path);
459 if (len != 0)
461 CSimpleFileFind finder = CSimpleFileFind(path, _T("*svn*.*"));
462 FILETIME systime_;
463 ::GetSystemTimeAsFileTime(&systime_);
464 __int64 systime = (((_int64)systime_.dwHighDateTime)<<32) | ((__int64)systime_.dwLowDateTime);
465 while (finder.FindNextFileNoDirectories())
467 CString filepath = finder.GetFilePath();
468 HANDLE hFile = ::CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
469 if (hFile != INVALID_HANDLE_VALUE)
471 FILETIME createtime_;
472 if (::GetFileTime(hFile, &createtime_, NULL, NULL))
474 ::CloseHandle(hFile);
475 __int64 createtime = (((_int64)createtime_.dwHighDateTime)<<32) | ((__int64)createtime_.dwLowDateTime);
476 if ((createtime + 864000000000) < systime) //only delete files older than a day
478 ::SetFileAttributes(filepath, FILE_ATTRIBUTE_NORMAL);
479 ::DeleteFile(filepath);
482 else
483 ::CloseHandle(hFile);
487 delete[] path;
490 // Since the dialog has been closed, return FALSE so that we exit the
491 // application, rather than start the application's message pump.
492 return FALSE;
495 void CTortoiseProcApp::CheckUpgrade()
497 CRegString regVersion = CRegString(_T("Software\\TortoiseGit\\CurrentVersion"));
498 CString sVersion = regVersion;
499 if (sVersion.Compare(_T(STRPRODUCTVER))==0)
500 return;
501 // we're starting the first time with a new version!
503 LONG lVersion = 0;
504 int pos = sVersion.Find(',');
505 if (pos > 0)
507 lVersion = (_ttol(sVersion.Left(pos))<<24);
508 lVersion |= (_ttol(sVersion.Mid(pos+1))<<16);
509 pos = sVersion.Find(',', pos+1);
510 lVersion |= (_ttol(sVersion.Mid(pos+1))<<8);
513 if (lVersion <= 0x01070600)
515 CRegStdDWORD(_T("Software\\TortoiseGit\\ConvertBase")).removeValue();
516 CRegStdDWORD(_T("Software\\TortoiseGit\\DiffProps")).removeValue();
518 #if 0
519 if (lVersion <= 0x01010300)
521 CSoundUtils::RegisterTSVNSounds();
523 #endif
524 if (lVersion <= 0x01020200)
526 // upgrade to > 1.2.3 means the doc diff scripts changed from vbs to js
527 // so remove the diff/merge scripts if they're the defaults
528 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\.doc"));
529 CString sDiff = diffreg;
530 CString sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\diff-doc.vbs\"");
531 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
532 diffreg = _T("");
533 CRegString mergereg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\.doc"));
534 sDiff = mergereg;
535 sCL = _T("wscript.exe \"") + CPathUtils::GetAppParentDirectory()+_T("Diff-Scripts\\merge-doc.vbs\"");
536 if (sDiff.Left(sCL.GetLength()).CompareNoCase(sCL)==0)
537 mergereg = _T("");
539 if (lVersion <= 0x01040000)
541 CRegStdDWORD(_T("Software\\TortoiseGit\\OwnerdrawnMenus")).removeValue();
544 // set the custom diff scripts for every user
545 CString scriptsdir = CPathUtils::GetAppParentDirectory();
546 scriptsdir += _T("Diff-Scripts");
547 CSimpleFileFind files(scriptsdir);
548 while (files.FindNextFileNoDirectories())
550 CString file = files.GetFilePath();
551 CString filename = files.GetFileName();
552 CString ext = file.Mid(file.ReverseFind('-')+1);
553 ext = _T(".")+ext.Left(ext.ReverseFind('.'));
554 CString kind;
555 if (file.Right(3).CompareNoCase(_T("vbs"))==0)
557 kind = _T(" //E:vbscript");
559 if (file.Right(2).CompareNoCase(_T("js"))==0)
561 kind = _T(" //E:javascript");
564 if (filename.Left(5).CompareNoCase(_T("diff-"))==0)
566 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\DiffTools\\")+ext);
567 CString diffregstring = diffreg;
568 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
569 diffreg = _T("wscript.exe \"") + file + _T("\" %base %mine") + kind;
571 if (filename.Left(6).CompareNoCase(_T("merge-"))==0)
573 CRegString diffreg = CRegString(_T("Software\\TortoiseGit\\MergeTools\\")+ext);
574 CString diffregstring = diffreg;
575 if ((diffregstring.IsEmpty()) || (diffregstring.Find(filename)>=0))
576 diffreg = _T("wscript.exe \"") + file + _T("\" %merged %theirs %mine %base") + kind;
580 // set the current version so we don't come here again until the next update!
581 regVersion = _T(STRPRODUCTVER);
584 void CTortoiseProcApp::EnableCrashHandler()
586 // the crash handler is enabled by default, but we disable it
587 // after 3 months after a release
589 #define YEAR ((((__DATE__ [7] - '0') * 10 + (__DATE__ [8] - '0')) * 10 \
590 + (__DATE__ [9] - '0')) * 10 + (__DATE__ [10] - '0'))
592 #define MONTH (__DATE__ [2] == 'n' ? (__DATE__ [1] == 'a' ? 1 : 6) \
593 : __DATE__ [2] == 'b' ? 2 \
594 : __DATE__ [2] == 'r' ? (__DATE__ [0] == 'M' ? 3 : 4) \
595 : __DATE__ [2] == 'y' ? 5 \
596 : __DATE__ [2] == 'l' ? 7 \
597 : __DATE__ [2] == 'g' ? 8 \
598 : __DATE__ [2] == 'p' ? 9 \
599 : __DATE__ [2] == 't' ? 10 \
600 : __DATE__ [2] == 'v' ? 11 : 12)
602 #define DAY ((__DATE__ [4] == ' ' ? 0 : __DATE__ [4] - '0') * 10 \
603 + (__DATE__ [5] - '0'))
605 #define DATE_AS_INT (((YEAR - 2000) * 12 + MONTH) * 31 + DAY)
607 CTime compiletime(YEAR, MONTH, DAY, 0, 0, 0);
608 CTime now = CTime::GetCurrentTime();
610 CTimeSpan timediff = now-compiletime;
611 if (timediff.GetDays() > 3*31)
613 // crasher.Enable(FALSE);
617 void CTortoiseProcApp::InitializeJumpList()
619 // for Win7 : use a custom jump list
620 CoInitialize(NULL);
621 SetAppID(APPID);
622 DeleteJumpList(APPID);
623 DoInitializeJumpList();
624 CoUninitialize();
627 void CTortoiseProcApp::DoInitializeJumpList()
629 ATL::CComPtr<ICustomDestinationList> pcdl;
630 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
631 if (FAILED(hr))
632 return;
634 hr = pcdl->SetAppID(APPID);
635 if (FAILED(hr))
636 return;
638 UINT uMaxSlots;
639 ATL::CComPtr<IObjectArray> poaRemoved;
640 hr = pcdl->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved));
641 if (FAILED(hr))
642 return;
644 ATL::CComPtr<IObjectCollection> poc;
645 hr = poc.CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC_SERVER);
646 if (FAILED(hr))
647 return;
649 CString sTemp = CString(MAKEINTRESOURCE(IDS_MENUSETTINGS));
650 sTemp.Remove('&');
652 ATL::CComPtr<IShellLink> psl;
653 hr = CreateShellLink(_T("/command:settings"), (LPCTSTR)sTemp, 20, &psl);
654 if (SUCCEEDED(hr)) {
655 poc->AddObject(psl);
657 sTemp = CString(MAKEINTRESOURCE(IDS_MENUHELP));
658 sTemp.Remove('&');
659 psl.Release(); // Need to release the object before calling operator&()
660 hr = CreateShellLink(_T("/command:help"), (LPCTSTR)sTemp, 19, &psl);
661 if (SUCCEEDED(hr)) {
662 poc->AddObject(psl);
665 ATL::CComPtr<IObjectArray> poa;
666 hr = poc.QueryInterface(&poa);
667 if (SUCCEEDED(hr)) {
668 pcdl->AppendCategory((LPCTSTR)CString(MAKEINTRESOURCE(IDS_PROC_TASKS)), poa);
669 pcdl->CommitList();
673 int CTortoiseProcApp::ExitInstance()
675 Gdiplus::GdiplusShutdown(m_gdiplusToken);
677 CWinAppEx::ExitInstance();
678 if (retSuccess)
679 return 0;
680 return -1;