1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 #pragma warning (disable : 4786)
\r
23 // Initialize GUIDs (should be done only and at-least once per DLL/EXE)
\r
24 #include <initguid.h>
\r
27 #include "ShellExt.h"
\r
28 //#include "..\version.h"
\r
29 //#include "libintl.h"
\r
32 std::set<CShellExt *> g_exts;
\r
35 // *********************** CShellExt *************************
\r
36 CShellExt::CShellExt(FileState state)
\r
38 OSVERSIONINFOEX inf;
\r
39 SecureZeroMemory(&inf, sizeof(OSVERSIONINFOEX));
\r
40 inf.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
\r
41 GetVersionEx((OSVERSIONINFO *)&inf);
\r
42 fullver = MAKEWORD(inf.dwMinorVersion, inf.dwMajorVersion);
\r
49 g_exts.insert(this);
\r
51 INITCOMMONCONTROLSEX used = {
\r
52 sizeof(INITCOMMONCONTROLSEX),
\r
53 ICC_LISTVIEW_CLASSES | ICC_WIN95_CLASSES | ICC_BAR_CLASSES | ICC_USEREX_CLASSES
\r
55 InitCommonControlsEx(&used);
\r
58 if (fullver >= 0x0600)
\r
60 HMODULE hUxTheme = ::GetModuleHandle (_T("UXTHEME.DLL"));
\r
62 pfnGetBufferedPaintBits = (FN_GetBufferedPaintBits)::GetProcAddress(hUxTheme, "GetBufferedPaintBits");
\r
63 pfnBeginBufferedPaint = (FN_BeginBufferedPaint)::GetProcAddress(hUxTheme, "BeginBufferedPaint");
\r
64 pfnEndBufferedPaint = (FN_EndBufferedPaint)::GetProcAddress(hUxTheme, "EndBufferedPaint");
\r
68 CShellExt::~CShellExt()
\r
70 std::map<UINT, HBITMAP>::iterator it;
\r
71 for (it = bitmaps.begin(); it != bitmaps.end(); ++it)
\r
73 ::DeleteObject(it->second);
\r
82 if ((g_langid != g_ShellCache.GetLangID())&&((g_langTimeout == 0)||(g_langTimeout < GetTickCount())))
\r
84 g_langid = g_ShellCache.GetLangID();
\r
85 DWORD langId = g_langid;
\r
86 TCHAR langDll[MAX_PATH*4];
\r
87 HINSTANCE hInst = NULL;
\r
88 TCHAR langdir[MAX_PATH] = {0};
\r
89 char langdirA[MAX_PATH] = {0};
\r
90 if (GetModuleFileName(g_hmodThisDll, langdir, MAX_PATH)==0)
\r
92 if (GetModuleFileNameA(g_hmodThisDll, langdirA, MAX_PATH)==0)
\r
94 TCHAR * dirpoint = _tcsrchr(langdir, '\\');
\r
95 char * dirpointA = strrchr(langdirA, '\\');
\r
100 dirpoint = _tcsrchr(langdir, '\\');
\r
101 dirpointA = strrchr(langdirA, '\\');
\r
106 strcat_s(langdirA, MAX_PATH, "\\Languages");
\r
107 // bindtextdomain ("subversion", langdirA);
\r
111 _stprintf_s(langDll, MAX_PATH*4, _T("%s\\Languages\\TortoiseProc%d.dll"), langdir, langId);
\r
112 BOOL versionmatch = TRUE;
\r
117 WORD wCharacterSet;
\r
120 DWORD dwReserved,dwBufferSize;
\r
121 dwBufferSize = GetFileVersionInfoSize((LPTSTR)langDll,&dwReserved);
\r
123 if (dwBufferSize > 0)
\r
125 LPVOID pBuffer = (void*) malloc(dwBufferSize);
\r
127 if (pBuffer != (void*) NULL)
\r
129 UINT nInfoSize = 0,
\r
131 LPSTR lpVersion = NULL;
\r
132 VOID* lpFixedPointer;
\r
133 TRANSARRAY* lpTransArray;
\r
134 TCHAR strLangProduktVersion[MAX_PATH];
\r
136 if (GetFileVersionInfo((LPTSTR)langDll,
\r
141 // Query the current language
\r
142 if (VerQueryValue( pBuffer,
\r
143 _T("\\VarFileInfo\\Translation"),
\r
147 lpTransArray = (TRANSARRAY*) lpFixedPointer;
\r
149 _stprintf_s(strLangProduktVersion, MAX_PATH, _T("\\StringFileInfo\\%04x%04x\\ProductVersion"),
\r
150 lpTransArray[0].wLanguageID, lpTransArray[0].wCharacterSet);
\r
152 if (VerQueryValue(pBuffer,
\r
153 (LPTSTR)strLangProduktVersion,
\r
154 (LPVOID *)&lpVersion,
\r
157 // versionmatch = (_tcscmp((LPCTSTR)lpVersion, _T(STRPRODUCTVER)) == 0);
\r
163 } // if (pBuffer != (void*) NULL)
\r
164 } // if (dwBufferSize > 0)
\r
166 versionmatch = FALSE;
\r
169 hInst = LoadLibrary(langDll);
\r
172 if (g_hResInst != g_hmodThisDll)
\r
173 FreeLibrary(g_hResInst);
\r
174 g_hResInst = hInst;
\r
178 DWORD lid = SUBLANGID(langId);
\r
182 langId = MAKELANGID(PRIMARYLANGID(langId), lid);
\r
187 } while ((hInst == NULL) && (langId != 0));
\r
190 // either the dll for the selected language is not present, or
\r
191 // it is the wrong version.
\r
192 // fall back to English and set a timeout so we don't retry
\r
193 // to load the language dll too often
\r
194 if (g_hResInst != g_hmodThisDll)
\r
195 FreeLibrary(g_hResInst);
\r
196 g_hResInst = g_hmodThisDll;
\r
198 // set a timeout of 10 seconds
\r
199 if (g_ShellCache.GetLangID() != 1033)
\r
200 g_langTimeout = GetTickCount() + 10000;
\r
204 } // if (g_langid != g_ShellCache.GetLangID())
\r
207 STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv)
\r
211 if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))
\r
213 *ppv = (LPSHELLEXTINIT)this;
\r
215 else if (IsEqualIID(riid, IID_IContextMenu))
\r
217 *ppv = (LPCONTEXTMENU)this;
\r
219 else if (IsEqualIID(riid, IID_IContextMenu2))
\r
221 *ppv = (LPCONTEXTMENU2)this;
\r
223 else if (IsEqualIID(riid, IID_IContextMenu3))
\r
225 *ppv = (LPCONTEXTMENU3)this;
\r
227 else if (IsEqualIID(riid, IID_IShellIconOverlayIdentifier))
\r
229 *ppv = (IShellIconOverlayIdentifier*)this;
\r
231 else if (IsEqualIID(riid, IID_IShellPropSheetExt))
\r
233 *ppv = (LPSHELLPROPSHEETEXT)this;
\r
235 else if (IsEqualIID(riid, IID_IColumnProvider))
\r
237 *ppv = (IColumnProvider *)this;
\r
239 else if (IsEqualIID(riid, IID_IShellCopyHook))
\r
241 *ppv = (ICopyHook *)this;
\r
250 return E_NOINTERFACE;
\r
253 STDMETHODIMP_(ULONG) CShellExt::AddRef()
\r
258 STDMETHODIMP_(ULONG) CShellExt::Release()
\r
268 // IPersistFile members
\r
269 STDMETHODIMP CShellExt::GetClassID(CLSID *pclsid)
\r
271 *pclsid = CLSID_Tortoisegit_UNCONTROLLED;
\r
275 STDMETHODIMP CShellExt::Load(LPCOLESTR /*pszFileName*/, DWORD /*dwMode*/)
\r
280 // ICopyHook member
\r
281 UINT __stdcall CShellExt::CopyCallback(HWND /*hWnd*/, UINT wFunc, UINT /*wFlags*/, LPCTSTR pszSrcFile, DWORD /*dwSrcAttribs*/, LPCTSTR /*pszDestFile*/, DWORD /*dwDestAttribs*/)
\r
283 if (wFunc == FO_COPY)
\r
284 return IDYES; // copying is not a problem for us
\r
286 // m_remoteCacheLink.ReleaseLockForPath(CTSVNPath(pszSrcFile));
\r
287 // we could now wait a little bit to give the cache time to release the handles.
\r
288 // but the explorer/shell already retries any action for about two seconds
\r
289 // if it first fails. So if the cache hasn't released the handle yet, the explorer
\r
290 // will retry anyway, so we just leave here immediately.
\r