Kiln » TortoiseHg » TortoiseHg
Clone URL:  
ShellExt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "stdafx.h" #include "ShellExt.h" #include "TortoiseUtils.h" #include "StringUtils.h" #include "InitStatus.h" #include "ThgClassFactory.h" #include "CShellExtCMenu.h" #include "CShellExtOverlay.h" #include <olectl.h> #define INITGUID #include <initguid.h> DEFINE_GUID(CLSID_TortoiseHgCmenu, 0xb456db9fL, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); DEFINE_GUID(CLSID_TortoiseHg0, 0xb456dba0L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); DEFINE_GUID(CLSID_TortoiseHg1, 0xb456dba1L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); DEFINE_GUID(CLSID_TortoiseHg2, 0xb456dba2L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); DEFINE_GUID(CLSID_TortoiseHg3, 0xb456dba3L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); DEFINE_GUID(CLSID_TortoiseHg4, 0xb456dba4L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); DEFINE_GUID(CLSID_TortoiseHg5, 0xb456dba5L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); DEFINE_GUID(CLSID_TortoiseHg6, 0xb456dba6L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e); UINT g_cRefThisDll = 0; HINSTANCE g_hmodThisDll = NULL; CRITICAL_SECTION g_critical_section; typedef struct { HKEY hRootKey; LPTSTR lpszSubKey; LPTSTR lpszValueName; LPTSTR lpszData; } REGSTRUCT, *LPREGSTRUCT; VOID _LoadResources(); VOID _UnloadResources(); extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { if (dwReason == DLL_PROCESS_ATTACH) { TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH"); g_hmodThisDll = hInstance; ::InitializeCriticalSection(&g_critical_section); _LoadResources(); } else if (dwReason == DLL_PROCESS_DETACH) { TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH"); ::DeleteCriticalSection(&g_critical_section); _UnloadResources(); } if (g_cRefThisDll > 0) InitStatus::check(); return 1; } STDAPI DllCanUnloadNow(void) { TDEBUG_TRACE("DllCanUnloadNow"); return (g_cRefThisDll == 0 ? S_OK : S_FALSE); } STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut) { LPWSTR pwszShellExt; StringFromIID(rclsid, &pwszShellExt); TDEBUG_TRACE("DllGetClassObject clsid = " << WideToMultibyte(pwszShellExt)); *ppvOut = NULL; typedef ThgClassFactory<CShellExtOverlay> FactOvl; typedef ThgClassFactory<CShellExtCMenu> FactCmenu; if (IsEqualIID(rclsid, CLSID_TortoiseHgCmenu)) { FactCmenu *pcf = new FactCmenu(0); TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHgCmenu"); return pcf->QueryInterface(riid, ppvOut); } else if (IsEqualIID(rclsid, CLSID_TortoiseHg0)) { FactOvl *pcf = new FactOvl('C'); // clean TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg0"); ++InitStatus::inst().unchanged_; return pcf->QueryInterface(riid, ppvOut); } else if (IsEqualIID(rclsid, CLSID_TortoiseHg1)) { FactOvl *pcf = new FactOvl('A'); // added TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg1"); ++InitStatus::inst().added_; return pcf->QueryInterface(riid, ppvOut); } else if (IsEqualIID(rclsid, CLSID_TortoiseHg2)) { FactOvl *pcf = new FactOvl('M'); // modified TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg2"); ++InitStatus::inst().modified_; return pcf->QueryInterface(riid, ppvOut); } else if (IsEqualIID(rclsid, CLSID_TortoiseHg6)) { FactOvl *pcf = new FactOvl('?'); // not in repo TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg6"); ++InitStatus::inst().notinrepo_; return pcf->QueryInterface(riid, ppvOut); } return CLASS_E_CLASSNOTAVAILABLE; } VOID _LoadResources(VOID) { } VOID _UnloadResources(VOID) { } LPCRITICAL_SECTION CShellExt::GetCriticalSection() { return &g_critical_section; } void CShellExt::IncDllRef() { ThgCriticalSection cs(CShellExt::GetCriticalSection()); g_cRefThisDll++; } void CShellExt::DecDllRef() { ThgCriticalSection cs(CShellExt::GetCriticalSection()); g_cRefThisDll--; }