Update Version Number to 0.8.1.0
[TortoiseGit.git] / src / TortoiseShell / TortoiseSVN.cpp
blob1cc10b8cfbb21fc8950c68e14ee9a2f009e40194
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.
19 #include "stdafx.h"
20 #include "ShellExt.h"
21 #include "Guids.h"
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.
27 int g_cAprInit = 0;
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");
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 */)
56 #ifdef _DEBUG
57 // if no debugger is present, then don't load the dll.
58 // this prevents other apps from loading the dll and locking
59 // it.
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);
64 if(pathLength >= 14)
66 if ((_tcsicmp(&buf[pathLength-14], _T("\\ShellTest.exe"))) == 0)
68 bInShellTest = true;
70 if ((_tcsicmp(&buf[pathLength-13], _T("\\verclsid.exe"))) == 0)
72 bInShellTest = true;
76 if (!::IsDebuggerPresent() && !bInShellTest)
78 ATLTRACE("In debug load preventer\n");
79 return FALSE;
81 #endif
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())
107 delete *it;
108 it = g_exts.begin();
110 while (g_cAprInit--)
112 g_GitAdminDir.Close();
113 // apr_terminate();
116 g_csGlobalCOMGuard.Term();
118 return 1; // ok
121 STDAPI DllCanUnloadNow(void)
123 return (g_cRefThisDll == 0 ? S_OK : S_FALSE);
126 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)
128 *ppvOut = NULL;
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)
156 // apr_initialize();
157 // git_dso_initialize2();
158 g_GitAdminDir.Init();
159 g_cAprInit++;
161 CShellExtClassFactory *pcf = new CShellExtClassFactory(state);
162 return pcf->QueryInterface(riid, ppvOut);
165 return CLASS_E_CLASSNOTAVAILABLE;