Add context menu to delete all tags in Reference Browser
[TortoiseGit.git] / src / TortoiseShell / TortoiseGIT.cpp
blob55d1e8d1189289019f678f747c80492584ad0483
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2010, 2012 - TortoiseSVN
4 // Copyright (C) 2008-2012 - 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 "ShellObjects.h"
26 volatile LONG g_cRefThisDll = 0; ///< reference count of this DLL.
27 HINSTANCE g_hmodThisDll = NULL; ///< handle to this DLL itself.
28 ShellCache g_ShellCache; ///< caching of registry entries, ...
29 DWORD g_langid;
30 DWORD g_langTimeout = 0;
31 HINSTANCE g_hResInst = NULL;
32 stdstring g_filepath;
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");
50 ShellObjects g_shellObjects;
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 // do not clean up memory here:
101 // if an application doesn't release all COM objects
102 // but still unloads the dll, cleaning up ourselves
103 // will lead to crashes.
104 // better to leak some memory than to crash other apps.
105 // sometimes an application doesn't release all COM objects
106 // but still unloads the dll.
107 // in that case, we do it ourselves
108 g_csGlobalCOMGuard.Term();
110 return 1; // ok
113 STDAPI DllCanUnloadNow(void)
115 return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
118 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
120 if (ppvOut == 0)
121 return E_POINTER;
122 *ppvOut = NULL;
124 FileState state = FileStateInvalid;
125 if (IsEqualIID(rclsid, CLSID_Tortoisegit_UPTODATE))
126 state = FileStateVersioned;
127 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_MODIFIED))
128 state = FileStateModified;
129 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_CONFLICTING))
130 state = FileStateConflict;
131 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_UNCONTROLLED))
132 state = FileStateUncontrolled;
133 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_DROPHANDLER))
134 state = FileStateDropHandler;
135 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_DELETED))
136 state = FileStateDeleted;
137 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_READONLY))
138 state = FileStateReadOnly;
139 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_LOCKED))
140 state = FileStateLockedOverlay;
141 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_ADDED))
142 state = FileStateAddedOverlay;
143 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_IGNORED))
144 state = FileStateIgnoredOverlay;
145 else if (IsEqualIID(rclsid, CLSID_Tortoisegit_UNVERSIONED))
146 state = FileStateUnversionedOverlay;
148 if (state != FileStateInvalid)
150 CShellExtClassFactory *pcf = new (std::nothrow) CShellExtClassFactory(state);
151 if (pcf == NULL)
152 return E_OUTOFMEMORY;
153 // refcount currently set to 0
154 const HRESULT hr = pcf->QueryInterface(riid, ppvOut);
155 if(FAILED(hr))
156 delete pcf;
157 return hr;
160 return CLASS_E_CLASSNOTAVAILABLE;