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