1 // TortoiseGit - 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 "GitPropertyPage.h"
33 std::set
<CShellExt
*> g_exts
;
35 // *********************** CShellExt *************************
36 CShellExt::CShellExt(FileState state
)
45 INITCOMMONCONTROLSEX used
= {
46 sizeof(INITCOMMONCONTROLSEX
),
47 ICC_LISTVIEW_CLASSES
| ICC_WIN95_CLASSES
| ICC_BAR_CLASSES
| ICC_USEREX_CLASSES
49 InitCommonControlsEx(&used
);
52 if (SysInfo::Instance().IsVistaOrLater())
54 HMODULE hUxTheme
= ::GetModuleHandle (_T("UXTHEME.DLL"));
56 pfnGetBufferedPaintBits
= (FN_GetBufferedPaintBits
)::GetProcAddress(hUxTheme
, "GetBufferedPaintBits");
57 pfnBeginBufferedPaint
= (FN_BeginBufferedPaint
)::GetProcAddress(hUxTheme
, "BeginBufferedPaint");
58 pfnEndBufferedPaint
= (FN_EndBufferedPaint
)::GetProcAddress(hUxTheme
, "EndBufferedPaint");
62 CShellExt::~CShellExt()
64 std::map
<UINT
, HBITMAP
>::iterator it
;
65 for (it
= bitmaps
.begin(); it
!= bitmaps
.end(); ++it
)
67 ::DeleteObject(it
->second
);
76 if ((g_langid
!= g_ShellCache
.GetLangID())&&((g_langTimeout
== 0)||(g_langTimeout
< GetTickCount())))
78 g_langid
= g_ShellCache
.GetLangID();
79 DWORD langId
= g_langid
;
80 TCHAR langDll
[MAX_PATH
*4];
81 HINSTANCE hInst
= NULL
;
82 TCHAR langdir
[MAX_PATH
] = {0};
83 char langdirA
[MAX_PATH
] = {0};
84 if (GetModuleFileName(g_hmodThisDll
, langdir
, MAX_PATH
)==0)
86 if (GetModuleFileNameA(g_hmodThisDll
, langdirA
, MAX_PATH
)==0)
88 TCHAR
* dirpoint
= _tcsrchr(langdir
, '\\');
89 char * dirpointA
= strrchr(langdirA
, '\\');
94 dirpoint
= _tcsrchr(langdir
, '\\');
95 dirpointA
= strrchr(langdirA
, '\\');
100 strcat_s(langdirA
, MAX_PATH
, "\\Languages");
101 // bindtextdomain ("subversion", langdirA);
105 _stprintf_s(langDll
, MAX_PATH
*4, _T("%s\\Languages\\TortoiseProc%d.dll"), langdir
, langId
);
106 BOOL versionmatch
= TRUE
;
114 DWORD dwReserved
,dwBufferSize
;
115 dwBufferSize
= GetFileVersionInfoSize((LPTSTR
)langDll
,&dwReserved
);
117 if (dwBufferSize
> 0)
119 LPVOID pBuffer
= (void*) malloc(dwBufferSize
);
121 if (pBuffer
!= (void*) NULL
)
125 LPSTR lpVersion
= NULL
;
126 VOID
* lpFixedPointer
;
127 TRANSARRAY
* lpTransArray
;
128 TCHAR strLangProduktVersion
[MAX_PATH
];
130 if (GetFileVersionInfo((LPTSTR
)langDll
,
135 // Query the current language
136 if (VerQueryValue( pBuffer
,
137 _T("\\VarFileInfo\\Translation"),
141 lpTransArray
= (TRANSARRAY
*) lpFixedPointer
;
143 _stprintf_s(strLangProduktVersion
, MAX_PATH
, _T("\\StringFileInfo\\%04x%04x\\ProductVersion"),
144 lpTransArray
[0].wLanguageID
, lpTransArray
[0].wCharacterSet
);
146 if (VerQueryValue(pBuffer
,
147 (LPTSTR
)strLangProduktVersion
,
148 (LPVOID
*)&lpVersion
,
151 // versionmatch = (_tcscmp((LPCTSTR)lpVersion, _T(STRPRODUCTVER)) == 0);
157 } // if (pBuffer != (void*) NULL)
158 } // if (dwBufferSize > 0)
160 versionmatch
= FALSE
;
163 hInst
= LoadLibrary(langDll
);
166 if (g_hResInst
!= g_hmodThisDll
)
167 FreeLibrary(g_hResInst
);
172 DWORD lid
= SUBLANGID(langId
);
176 langId
= MAKELANGID(PRIMARYLANGID(langId
), lid
);
181 } while ((hInst
== NULL
) && (langId
!= 0));
184 // either the dll for the selected language is not present, or
185 // it is the wrong version.
186 // fall back to English and set a timeout so we don't retry
187 // to load the language dll too often
188 if (g_hResInst
!= g_hmodThisDll
)
189 FreeLibrary(g_hResInst
);
190 g_hResInst
= g_hmodThisDll
;
192 // set a timeout of 10 seconds
193 if (g_ShellCache
.GetLangID() != 1033)
194 g_langTimeout
= GetTickCount() + 10000;
198 } // if (g_langid != g_ShellCache.GetLangID())
201 STDMETHODIMP
CShellExt::QueryInterface(REFIID riid
, LPVOID FAR
*ppv
)
205 if (IsEqualIID(riid
, IID_IShellExtInit
) || IsEqualIID(riid
, IID_IUnknown
))
207 *ppv
= (LPSHELLEXTINIT
)this;
209 else if (IsEqualIID(riid
, IID_IContextMenu
))
211 *ppv
= (LPCONTEXTMENU
)this;
213 else if (IsEqualIID(riid
, IID_IContextMenu2
))
215 *ppv
= (LPCONTEXTMENU2
)this;
217 else if (IsEqualIID(riid
, IID_IContextMenu3
))
219 *ppv
= (LPCONTEXTMENU3
)this;
221 else if (IsEqualIID(riid
, IID_IShellIconOverlayIdentifier
))
223 *ppv
= (IShellIconOverlayIdentifier
*)this;
225 else if (IsEqualIID(riid
, IID_IShellPropSheetExt
))
227 *ppv
= (LPSHELLPROPSHEETEXT
)this;
229 else if (IsEqualIID(riid
, IID_IColumnProvider
))
231 *ppv
= (IColumnProvider
*)this;
233 else if (IsEqualIID(riid
, IID_IShellCopyHook
))
235 *ppv
= (ICopyHook
*)this;
244 return E_NOINTERFACE
;
247 STDMETHODIMP_(ULONG
) CShellExt::AddRef()
252 STDMETHODIMP_(ULONG
) CShellExt::Release()
262 // IPersistFile members
263 STDMETHODIMP
CShellExt::GetClassID(CLSID
*pclsid
)
265 *pclsid
= CLSID_Tortoisegit_UNCONTROLLED
;
269 STDMETHODIMP
CShellExt::Load(LPCOLESTR
/*pszFileName*/, DWORD
/*dwMode*/)
275 UINT __stdcall
CShellExt::CopyCallback(HWND
/*hWnd*/, UINT wFunc
, UINT
/*wFlags*/, LPCTSTR pszSrcFile
, DWORD
/*dwSrcAttribs*/, LPCTSTR
/*pszDestFile*/, DWORD
/*dwDestAttribs*/)
277 if (wFunc
== FO_COPY
)
278 return IDYES
; // copying is not a problem for us
280 m_remoteCacheLink
.ReleaseLockForPath(CTGitPath(pszSrcFile
));
281 // we could now wait a little bit to give the cache time to release the handles.
282 // but the explorer/shell already retries any action for about two seconds
283 // if it first fails. So if the cache hasn't released the handle yet, the explorer
284 // will retry anyway, so we just leave here immediately.