1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2013 - TortoiseGit
4 // Copyright (C) 2003-2013 - 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.
22 // Initialize GUIDs (should be done only and at-least once per DLL/EXE)
27 #include "ShellObjects.h"
28 #include "..\version.h"
31 extern ShellObjects g_shellObjects
;
33 // *********************** CShellExt *************************
34 CShellExt::CShellExt(FileState state
)
35 #if ENABLE_CRASHHANLDER
36 : m_crasher(L
"TortoiseGit", TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
, TGIT_VERDATE
, false)
40 ,regDiffLater(L
"Software\\TortoiseGit\\DiffLater", L
"")
45 InterlockedIncrement(&g_cRefThisDll
);
48 AutoLocker
lock(g_csGlobalCOMGuard
);
49 g_shellObjects
.Insert(this);
52 INITCOMMONCONTROLSEX used
= {
53 sizeof(INITCOMMONCONTROLSEX
),
54 ICC_LISTVIEW_CLASSES
| ICC_WIN95_CLASSES
| ICC_BAR_CLASSES
| ICC_USEREX_CLASSES
56 InitCommonControlsEx(&used
);
60 CShellExt::~CShellExt()
62 AutoLocker
lock(g_csGlobalCOMGuard
);
63 InterlockedDecrement(&g_cRefThisDll
);
64 g_shellObjects
.Erase(this);
69 if ((g_langid
!= g_ShellCache
.GetLangID())&&((g_langTimeout
== 0)||(g_langTimeout
< GetTickCount())))
71 g_langid
= g_ShellCache
.GetLangID();
72 DWORD langId
= g_langid
;
73 TCHAR langDll
[MAX_PATH
*4];
74 HINSTANCE hInst
= NULL
;
75 TCHAR langdir
[MAX_PATH
] = {0};
76 char langdirA
[MAX_PATH
] = {0};
77 if (GetModuleFileName(g_hmodThisDll
, langdir
, _countof(langdir
))==0)
79 if (GetModuleFileNameA(g_hmodThisDll
, langdirA
, _countof(langdirA
))==0)
81 TCHAR
* dirpoint
= _tcsrchr(langdir
, '\\');
82 char * dirpointA
= strrchr(langdirA
, '\\');
87 dirpoint
= _tcsrchr(langdir
, '\\');
88 dirpointA
= strrchr(langdirA
, '\\');
93 strcat_s(langdirA
, "\\Languages");
94 // bindtextdomain ("subversion", langdirA);
97 IsWow64Process(GetCurrentProcess(), &bIsWow
);
102 _stprintf_s(langDll
, _T("%s\\Languages\\TortoiseProc32%lu.dll"), langdir
, langId
);
104 _stprintf_s(langDll
, _T("%s\\Languages\\TortoiseProc%lu.dll"), langdir
, langId
);
105 BOOL versionmatch
= TRUE
;
113 DWORD dwReserved
,dwBufferSize
;
114 dwBufferSize
= GetFileVersionInfoSize((LPTSTR
)langDll
,&dwReserved
);
116 if (dwBufferSize
> 0)
118 LPVOID pBuffer
= (void*) malloc(dwBufferSize
);
120 if (pBuffer
!= (void*) NULL
)
123 UINT nFixedLength
= 0;
124 LPSTR lpVersion
= NULL
;
125 VOID
* lpFixedPointer
;
126 TRANSARRAY
* lpTransArray
;
127 TCHAR strLangProductVersion
[MAX_PATH
];
129 if (GetFileVersionInfo((LPTSTR
)langDll
,
134 // Query the current language
135 if (VerQueryValue( pBuffer
,
136 _T("\\VarFileInfo\\Translation"),
140 lpTransArray
= (TRANSARRAY
*) lpFixedPointer
;
142 _stprintf_s(strLangProductVersion
, _T("\\StringFileInfo\\%04x%04x\\ProductVersion"),
143 lpTransArray
[0].wLanguageID
, lpTransArray
[0].wCharacterSet
);
145 if (VerQueryValue(pBuffer
,
146 (LPTSTR
)strLangProductVersion
,
147 (LPVOID
*)&lpVersion
,
150 versionmatch
= (_tcscmp((LPCTSTR
)lpVersion
, _T(STRPRODUCTVER
)) == 0);
156 } // if (pBuffer != (void*) NULL)
157 } // if (dwBufferSize > 0)
159 versionmatch
= FALSE
;
162 hInst
= LoadLibrary(langDll
);
165 if (g_hResInst
!= g_hmodThisDll
)
166 FreeLibrary(g_hResInst
);
171 DWORD lid
= SUBLANGID(langId
);
175 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
180 } while ((hInst
== NULL
) && (langId
!= 0));
183 // either the dll for the selected language is not present, or
184 // it is the wrong version.
185 // fall back to English and set a timeout so we don't retry
186 // to load the language dll too often
187 if (g_hResInst
!= g_hmodThisDll
)
188 FreeLibrary(g_hResInst
);
189 g_hResInst
= g_hmodThisDll
;
191 // set a timeout of 10 seconds
192 if (g_ShellCache
.GetLangID() != 1033)
193 g_langTimeout
= GetTickCount() + 10000;
197 } // if (g_langid != g_ShellCache.GetLangID())
200 STDMETHODIMP
CShellExt::QueryInterface(REFIID riid
, LPVOID FAR
*ppv
)
207 if (IsEqualIID(riid
, IID_IShellExtInit
) || IsEqualIID(riid
, IID_IUnknown
))
209 *ppv
= static_cast<LPSHELLEXTINIT
>(this);
211 else if (IsEqualIID(riid
, IID_IContextMenu
))
213 *ppv
= static_cast<LPCONTEXTMENU
>(this);
215 else if (IsEqualIID(riid
, IID_IContextMenu2
))
217 *ppv
= static_cast<LPCONTEXTMENU2
>(this);
219 else if (IsEqualIID(riid
, IID_IContextMenu3
))
221 *ppv
= static_cast<LPCONTEXTMENU3
>(this);
223 else if (IsEqualIID(riid
, IID_IShellIconOverlayIdentifier
))
225 *ppv
= static_cast<IShellIconOverlayIdentifier
*>(this);
227 else if (IsEqualIID(riid
, IID_IShellPropSheetExt
))
229 *ppv
= static_cast<LPSHELLPROPSHEETEXT
>(this);
231 else if (IsEqualIID(riid
, IID_IShellCopyHook
))
233 *ppv
= static_cast<ICopyHook
*>(this);
237 return E_NOINTERFACE
;
244 STDMETHODIMP_(ULONG
) CShellExt::AddRef()
249 STDMETHODIMP_(ULONG
) CShellExt::Release()
259 // IPersistFile members
260 STDMETHODIMP
CShellExt::GetClassID(CLSID
*pclsid
)
264 *pclsid
= CLSID_Tortoisegit_UNCONTROLLED
;
268 STDMETHODIMP
CShellExt::Load(LPCOLESTR
/*pszFileName*/, DWORD
/*dwMode*/)
274 UINT __stdcall
CShellExt::CopyCallback(HWND hWnd
, UINT wFunc
, UINT wFlags
, LPCTSTR pszSrcFile
, DWORD dwSrcAttribs
, LPCTSTR pszDestFile
, DWORD dwDestAttribs
)
278 return CopyCallback_Wrap(hWnd
, wFunc
, wFlags
, pszSrcFile
, dwSrcAttribs
, pszDestFile
, dwDestAttribs
);
280 __except(CCrashReport::Instance().SendReport(GetExceptionInformation()))
286 UINT __stdcall
CShellExt::CopyCallback_Wrap(HWND
/*hWnd*/, UINT wFunc
, UINT
/*wFlags*/, LPCTSTR pszSrcFile
, DWORD
/*dwSrcAttribs*/, LPCTSTR
/*pszDestFile*/, DWORD
/*dwDestAttribs*/)
288 if (wFunc
== FO_COPY
)
289 return IDYES
; // copying is not a problem for us
291 m_remoteCacheLink
.ReleaseLockForPath(CTGitPath(pszSrcFile
));
292 // we could now wait a little bit to give the cache time to release the handles.
293 // but the explorer/shell already retries any action for about two seconds
294 // if it first fails. So if the cache hasn't released the handle yet, the explorer
295 // will retry anyway, so we just leave here immediately.