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