1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "ShellCache.h"
25 #include "RemoteCacheLink.h"
26 #include "GitStatus.h"
27 #include "GitFolderStatus.h"
28 #include "IconBitmapUtils.h"
30 #include "CrashReport.h"
31 #include "../version.h"
33 extern volatile LONG g_cRefThisDll
; // Reference count of this DLL.
34 extern HINSTANCE g_hmodThisDll
; // Instance handle for this DLL
35 extern ShellCache g_ShellCache
; // caching of registry entries, ...
36 extern DWORD g_langid
;
37 extern DWORD g_langTimeout
;
38 extern HINSTANCE g_hResInst
;
39 extern stdstring g_filepath
;
40 extern git_wc_status_kind g_filestatus
; ///< holds the corresponding status to the file/dir above
41 extern bool g_readonlyoverlay
; ///< whether to show the read only overlay or not
42 extern bool g_lockedoverlay
; ///< whether to show the locked overlay or not
44 extern bool g_normalovlloaded
;
45 extern bool g_modifiedovlloaded
;
46 extern bool g_conflictedovlloaded
;
47 extern bool g_readonlyovlloaded
;
48 extern bool g_deletedovlloaded
;
49 extern bool g_lockedovlloaded
;
50 extern bool g_addedovlloaded
;
51 extern bool g_ignoredovlloaded
;
52 extern bool g_unversionedovlloaded
;
53 extern LPCTSTR g_MenuIDString
;
55 extern void LoadLangDll();
56 extern CComCriticalSection g_csGlobalCOMGuard
;
57 typedef CComCritSecLock
<CComCriticalSection
> AutoLocker
;
59 // The actual OLE Shell context menu handler
61 * \ingroup TortoiseShell
62 * The main class of our COM object / Shell Extension.
63 * It contains all Interfaces we implement for the shell to use.
64 * \remark The implementations of the different interfaces are
65 * split into several *.cpp files to keep them in a reasonable size.
67 class CShellExt
: public IContextMenu3
,
71 IShellIconOverlayIdentifier
,
75 // COMPILER ERROR? You need the latest version of the
76 // platform SDK which has references to IColumnProvider
77 // in the header files. Download it here:
78 // http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
84 //std::map<int,std::string> verbMap;
85 std::map
<UINT_PTR
, UINT_PTR
> myIDMap
;
86 std::map
<UINT_PTR
, UINT_PTR
> mySubMenuMap
;
87 std::map
<stdstring
, UINT_PTR
> myVerbsMap
;
88 std::map
<UINT_PTR
, stdstring
> myVerbsIDMap
;
90 std::vector
<stdstring
> files_
;
91 DWORD itemStates
; ///< see the globals.h file for the ITEMIS_* defines
92 DWORD itemStatesFolder
; ///< used for states of the folder_ (folder background and/or drop target folder)
96 TCHAR stringtablebuffer
[255];
97 stdstring columnfilepath
; ///< holds the last file/dir path for the column provider
98 stdstring columnauthor
; ///< holds the corresponding author of the file/dir above
100 stdstring itemshorturl
;
101 stdstring ignoredprops
;
102 git_revnum_t columnrev
; ///< holds the corresponding revision to the file/dir above
103 git_wc_status_kind filestatus
;
105 GitFolderStatus m_CachedStatus
; // status cache
106 CRemoteCacheLink m_remoteCacheLink
;
107 IconBitmapUtils m_iconBitmapUtils
;
109 #if ENABLE_CRASHHANLDER
110 CCrashReportTGit m_crasher
;
113 #define MAKESTRING(ID) LoadStringEx(g_hResInst, ID, stringtablebuffer, _countof(stringtablebuffer), (WORD)CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)))
115 void InsertGitMenu(BOOL istop
, HMENU menu
, UINT pos
, UINT_PTR id
, UINT stringid
, UINT icon
, UINT idCmdFirst
, GitCommands com
, UINT uFlags
);
116 bool InsertIgnoreSubmenus(UINT
&idCmd
, UINT idCmdFirst
, HMENU hMenu
, HMENU subMenu
, UINT
&indexMenu
, int &indexSubMenu
, unsigned __int64 topmenu
, bool bShowIcons
, UINT uFlags
);
117 stdstring
WriteFileListToTempFile();
118 bool WriteClipboardPathsToTempFile(stdstring
& tempfile
);
119 LPCTSTR
GetMenuTextFromResource(int id
);
120 void GetColumnStatus(const TCHAR
* path
, BOOL bIsDir
);
121 void GetColumnInfo(DWORD dwIndex
, SHCOLUMNINFO
*psci
, UINT characterCount
, UINT title
, UINT description
);
122 bool ShouldInsertItem(const MenuInfo
& pair
) const;
123 bool ShouldEnableMenu(const YesNoPair
& pair
) const;
124 void TweakMenu(HMENU menu
);
125 void AddPathCommand(tstring
& gitCmd
, LPCTSTR command
, bool bFilesAllowed
);
126 void AddPathFileCommand(tstring
& gitCmd
, LPCTSTR command
);
127 void AddPathFileDropCommand(tstring
& gitCmd
, LPCTSTR command
);
128 STDMETHODIMP
QueryDropContext(UINT uFlags
, UINT idCmdFirst
, HMENU hMenu
, UINT
&indexMenu
);
129 bool IsIllegalFolder(std::wstring folder
, int * cslidarray
);
130 static void RunCommand(const tstring
& path
, const tstring
& command
, LPCTSTR errorMessage
);
132 /** \name IContextMenu2 wrappers
133 * IContextMenu2 wrapper functions to catch exceptions and send crash reports
136 STDMETHODIMP
QueryContextMenu_Wrap(HMENU hMenu
, UINT indexMenu
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
);
137 STDMETHODIMP
InvokeCommand_Wrap(LPCMINVOKECOMMANDINFO lpcmi
);
138 STDMETHODIMP
GetCommandString_Wrap(UINT_PTR idCmd
, UINT uFlags
, UINT FAR
*reserved
, LPSTR pszName
, UINT cchMax
);
139 STDMETHODIMP
HandleMenuMsg_Wrap(UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
142 /** \name IContextMenu3 wrappers
143 * IContextMenu3 wrapper functions to catch exceptions and send crash reports
146 STDMETHODIMP
HandleMenuMsg2_Wrap(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*pResult
);
149 /** \name IColumnProvider wrappers
150 * IColumnProvider wrapper functions to catch exceptions and send crash reports
153 STDMETHODIMP
GetColumnInfo_Wrap(DWORD dwIndex
, SHCOLUMNINFO
*psci
);
154 STDMETHODIMP
GetItemData_Wrap(LPCSHCOLUMNID pscid
, LPCSHCOLUMNDATA pscd
, VARIANT
*pvarData
);
155 STDMETHODIMP
Initialize_Wrap(LPCSHCOLUMNINIT psci
);
158 /** \name IShellExtInit wrappers
159 * IShellExtInit wrapper functions to catch exceptions and send crash reports
162 STDMETHODIMP
Initialize_Wrap(LPCITEMIDLIST pIDFolder
, LPDATAOBJECT pDataObj
, HKEY hKeyID
);
165 /** \name IShellIconOverlayIdentifier wrappers
166 * IShellIconOverlayIdentifier wrapper functions to catch exceptions and send crash reports
169 STDMETHODIMP
GetOverlayInfo_Wrap(LPWSTR pwszIconFile
, int cchMax
, int *pIndex
, DWORD
*pdwFlags
);
170 STDMETHODIMP
GetPriority_Wrap(int *pPriority
);
171 STDMETHODIMP
IsMemberOf_Wrap(LPCWSTR pwszPath
, DWORD dwAttrib
);
174 /** \name IShellPropSheetExt wrappers
175 * IShellPropSheetExt wrapper functions to catch exceptions and send crash reports
178 STDMETHODIMP
AddPages_Wrap(LPFNADDPROPSHEETPAGE lpfnAddPage
, LPARAM lParam
);
179 //STDMETHODIMP ReplacePage_Wrap(UINT, LPFNADDPROPSHEETPAGE, LPARAM);
182 /** \name ICopyHook wrapper
183 * ICopyHook wrapper functions to catch exceptions and send crash reports
186 STDMETHODIMP_(UINT
) CopyCallback_Wrap(HWND hWnd
, UINT wFunc
, UINT wFlags
, LPCTSTR pszSrcFile
, DWORD dwSrcAttribs
, LPCTSTR pszDestFile
, DWORD dwDestAttribs
);
190 CShellExt(FileState state
);
191 virtual ~CShellExt();
197 STDMETHODIMP
QueryInterface(REFIID
, LPVOID FAR
*);
198 STDMETHODIMP_(ULONG
) AddRef();
199 STDMETHODIMP_(ULONG
) Release();
202 /** \name IContextMenu2
203 * IContextMenu2 members
206 STDMETHODIMP
QueryContextMenu(HMENU hMenu
, UINT indexMenu
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
);
207 STDMETHODIMP
InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi
);
208 STDMETHODIMP
GetCommandString(UINT_PTR idCmd
, UINT uFlags
, UINT FAR
*reserved
, LPSTR pszName
, UINT cchMax
);
209 STDMETHODIMP
HandleMenuMsg(UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
212 /** \name IContextMenu3
213 * IContextMenu3 members
216 STDMETHODIMP
HandleMenuMsg2(UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
*pResult
);
219 /** \name IColumnProvider
220 * IColumnProvider members
223 STDMETHODIMP
GetColumnInfo(DWORD dwIndex
, SHCOLUMNINFO
*psci
);
224 STDMETHODIMP
GetItemData(LPCSHCOLUMNID pscid
, LPCSHCOLUMNDATA pscd
, VARIANT
*pvarData
);
225 STDMETHODIMP
Initialize(LPCSHCOLUMNINIT psci
);
228 /** \name IShellExtInit
229 * IShellExtInit methods
232 STDMETHODIMP
Initialize(LPCITEMIDLIST pIDFolder
, LPDATAOBJECT pDataObj
, HKEY hKeyID
);
235 /** \name IPersistFile
236 * IPersistFile methods
239 STDMETHODIMP
GetClassID(CLSID
*pclsid
);
240 STDMETHODIMP
Load(LPCOLESTR pszFileName
, DWORD dwMode
);
241 STDMETHODIMP
IsDirty(void) { return S_OK
; };
242 STDMETHODIMP
Save(LPCOLESTR
/*pszFileName*/, BOOL
/*fRemember*/) { return S_OK
; };
243 STDMETHODIMP
SaveCompleted(LPCOLESTR
/*pszFileName*/) { return S_OK
; };
244 STDMETHODIMP
GetCurFile(LPOLESTR
* /*ppszFileName*/) { return S_OK
; };
247 /** \name IShellIconOverlayIdentifier
248 * IShellIconOverlayIdentifier methods
251 STDMETHODIMP
GetOverlayInfo(LPWSTR pwszIconFile
, int cchMax
, int *pIndex
, DWORD
*pdwFlags
);
252 STDMETHODIMP
GetPriority(int *pPriority
);
253 STDMETHODIMP
IsMemberOf(LPCWSTR pwszPath
, DWORD dwAttrib
);
256 /** \name IShellPropSheetExt
257 * IShellPropSheetExt methods
260 STDMETHODIMP
AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage
, LPARAM lParam
);
261 STDMETHODIMP
ReplacePage (UINT
, LPFNADDPROPSHEETPAGE
, LPARAM
);
268 STDMETHODIMP_(UINT
) CopyCallback(HWND hWnd
, UINT wFunc
, UINT wFlags
, LPCTSTR pszSrcFile
, DWORD dwSrcAttribs
, LPCTSTR pszDestFile
, DWORD dwDestAttribs
);