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