1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - TortoiseGit
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.
23 #include "ShellExtClassFactory.h"
24 //#include "git_dso.h"
26 UINT g_cRefThisDll
= 0; ///< reference count of this DLL.
27 HINSTANCE g_hmodThisDll
= NULL
; ///< handle to this DLL itself.
29 ShellCache g_ShellCache
; ///< caching of registry entries, ...
31 DWORD g_langTimeout
= 0;
32 HINSTANCE g_hResInst
= NULL
;
34 git_wc_status_kind g_filestatus
= git_wc_status_none
; ///< holds the corresponding status to the file/dir above
35 bool g_readonlyoverlay
= false;
36 bool g_lockedoverlay
= false;
38 bool g_normalovlloaded
= false;
39 bool g_modifiedovlloaded
= false;
40 bool g_conflictedovlloaded
= false;
41 bool g_readonlyovlloaded
= false;
42 bool g_deletedovlloaded
= false;
43 bool g_lockedovlloaded
= false;
44 bool g_addedovlloaded
= false;
45 bool g_ignoredovlloaded
= false;
46 bool g_unversionedovlloaded
= false;
47 CComCriticalSection g_csGlobalCOMGuard
;
49 LPCTSTR g_MenuIDString
= _T("TortoiseGit");
50 extern std::set
<CShellExt
*> g_exts
;
52 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
54 extern "C" int APIENTRY
55 DllMain(HINSTANCE hInstance
, DWORD dwReason
, LPVOID
/* lpReserved */)
58 // if no debugger is present, then don't load the dll.
59 // this prevents other apps from loading the dll and locking
62 bool bInShellTest
= false;
63 TCHAR buf
[_MAX_PATH
+ 1]; // MAX_PATH ok, the test really is for debugging anyway.
64 DWORD pathLength
= GetModuleFileName(NULL
, buf
, _MAX_PATH
);
67 if ((_tcsicmp(&buf
[pathLength
-14], _T("\\ShellTest.exe"))) == 0)
71 if ((_tcsicmp(&buf
[pathLength
-13], _T("\\verclsid.exe"))) == 0)
77 if (!::IsDebuggerPresent() && !bInShellTest
)
79 ATLTRACE("In debug load preventer\n");
84 // NOTE: Do *NOT* call apr_initialize() or apr_terminate() here in DllMain(),
85 // because those functions call LoadLibrary() indirectly through malloc().
86 // And LoadLibrary() inside DllMain() is not allowed and can lead to unexpected
87 // behavior and even may create dependency loops in the dll load order.
88 if (dwReason
== DLL_PROCESS_ATTACH
)
90 if (g_hmodThisDll
== NULL
)
92 g_csGlobalCOMGuard
.Init();
95 // Extension DLL one-time initialization
96 g_hmodThisDll
= hInstance
;
98 else if (dwReason
== DLL_PROCESS_DETACH
)
100 // sometimes an application doesn't release all COM objects
101 // but still unloads the dll.
102 // in that case, we do it ourselves
103 if (g_cRefThisDll
> 0)
105 std::set
<CShellExt
*>::iterator it
= g_exts
.begin();
106 while (it
!= g_exts
.end())
113 g_GitAdminDir
.Close();
117 g_csGlobalCOMGuard
.Term();
122 STDAPI
DllCanUnloadNow(void)
124 return (g_cRefThisDll
== 0 ? S_OK
: S_FALSE
);
127 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppvOut
)
131 FileState state
= FileStateInvalid
;
132 if (IsEqualIID(rclsid
, CLSID_Tortoisegit_UPTODATE
))
133 state
= FileStateVersioned
;
134 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_MODIFIED
))
135 state
= FileStateModified
;
136 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_CONFLICTING
))
137 state
= FileStateConflict
;
138 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_UNCONTROLLED
))
139 state
= FileStateUncontrolled
;
140 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_DROPHANDLER
))
141 state
= FileStateDropHandler
;
142 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_DELETED
))
143 state
= FileStateDeleted
;
144 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_READONLY
))
145 state
= FileStateReadOnly
;
146 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_LOCKED
))
147 state
= FileStateLockedOverlay
;
148 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_ADDED
))
149 state
= FileStateAddedOverlay
;
150 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_IGNORED
))
151 state
= FileStateIgnoredOverlay
;
152 else if (IsEqualIID(rclsid
, CLSID_Tortoisegit_UNVERSIONED
))
153 state
= FileStateUnversionedOverlay
;
155 if (state
!= FileStateInvalid
)
158 // git_dso_initialize2();
159 g_GitAdminDir
.Init();
162 CShellExtClassFactory
*pcf
= new CShellExtClassFactory(state
);
163 return pcf
->QueryInterface(riid
, ppvOut
);
166 return CLASS_E_CLASSNOTAVAILABLE
;