cleanup: dropped a lot of unused code
[TortoiseGit.git] / src / TortoiseShell / TortoiseGIT.cpp
blob5b6653a8a8ed686ca384fae7b9fa742d55a1406b
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.
20 #include "stdafx.h"
21 #include "ShellExt.h"
22 #include "Guids.h"
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.
28 int g_cAprInit = 0;
29 ShellCache g_ShellCache; ///< caching of registry entries, ...
30 DWORD g_langid;
31 DWORD g_langTimeout = 0;
32 HINSTANCE g_hResInst = NULL;
33 stdstring g_filepath;
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 */)
57 #ifdef _DEBUG
58 // if no debugger is present, then don't load the dll.
59 // this prevents other apps from loading the dll and locking
60 // it.
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);
65 if(pathLength >= 14)
67 if ((_tcsicmp(&buf[pathLength-14], _T("\\ShellTest.exe"))) == 0)
69 bInShellTest = true;
71 if ((_tcsicmp(&buf[pathLength-13], _T("\\verclsid.exe"))) == 0)
73 bInShellTest = true;
77 if (!::IsDebuggerPresent() && !bInShellTest)
79 ATLTRACE("In debug load preventer\n");
80 return FALSE;
82 #endif
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())
108 delete *it;
109 it = g_exts.begin();
111 while (g_cAprInit--)
113 g_GitAdminDir.Close();
114 // apr_terminate();
117 g_csGlobalCOMGuard.Term();
119 return 1; // ok
122 STDAPI DllCanUnloadNow(void)
124 return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
127 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
129 *ppvOut = NULL;
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)
157 // apr_initialize();
158 // git_dso_initialize2();
159 g_GitAdminDir.Init();
160 g_cAprInit++;
162 CShellExtClassFactory *pcf = new CShellExtClassFactory(state);
163 return pcf->QueryInterface(riid, ppvOut);
166 return CLASS_E_CLASSNOTAVAILABLE;