-
Notifications
You must be signed in to change notification settings - Fork 2
/
LGit.cpp
executable file
·209 lines (185 loc) · 5.8 KB
/
LGit.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Initialization and sundry for the MSSCCI plugin.
*/
#include "stdafx.h"
/* This is initialized for dialog boxes later. */
static HINSTANCE dllInstance;
extern "C" BOOL APIENTRY DllMain(HANDLE hModule, DWORD reason, LPVOID _res)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
OutputDebugString("**Visual Git DllMain** proc attach\n");
dllInstance = (HINSTANCE)hModule;
break;
case DLL_THREAD_ATTACH:
OutputDebugString("**Visual Git DllMain** thread attach\n");
break;
case DLL_THREAD_DETACH:
OutputDebugString("**Visual Git DllMain** thread deattach\n");
break;
case DLL_PROCESS_DETACH:
OutputDebugString("**Visual Git DllMain** proc deattach\n");
break;
}
return TRUE;
}
LONG SccGetVersion (void)
{
LGitLog("**SccGetVersion** %x\n", SCC_VER_NUM);
return SCC_VER_NUM;
}
static void LGitInitOpts(void)
{
/* Options are global to the libgit2 singleton. */
/* XXX: versions (us, lg2, Windows)? */
git_libgit2_opts(GIT_OPT_SET_USER_AGENT,
"VisualGit");
/* Load options that are config-time from the registry. */
HKEY key;
DWORD valueLen = 255, type = REG_SZ;
BYTE value[255];
int ret;
/* Global system-wide, hence HKLM. We can load user settings later. */
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\Visual Git\\Visual Git",
0,
KEY_READ,
&key);
if (ret != ERROR_SUCCESS) {
LGitLog(" ! Opening the primary registry config failed\n");
/* Try the old path */
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\LGit\\LGit",
0,
KEY_READ,
&key);
if (ret != ERROR_SUCCESS) {
LGitLog(" ! Opening the fallback registry config failed\n");
return;
}
}
/*
* OpenSSL setting, ignored for WinHTTP. This is because OpenSSL defaults
* to loading from a hardcoded path, which is ridiculous. Load from a path
* specified in the registry (by our installer ideally) instead.
*/
ret = RegQueryValueEx(key,
"CertificateBundlePath",
NULL,
&type,
value,
&valueLen);
if (ret == ERROR_SUCCESS) {
/* Ignore return value since our transport may not use this */
ret = git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS,
(const char*)value,
NULL);
if (ret != 0) {
LGitLog(" ! Failed to set certificate path (may be harmless)\n");
}
} else {
LGitLog(" ! Failed to load certificate bundle value\n");
}
RegCloseKey(key);
}
/* XXX: Call on DPI/theme changes */
static void InitImageLists(LGitContext *ctx)
{
ctx->bitmapHeight = GetSystemMetrics(SM_CXSMICON);
HIMAGELIST icons;
HICON icon;
if (ctx->refTypeIl != NULL) {
ImageList_Destroy(ctx->refTypeIl);
}
icons = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
ILC_MASK, 6, 6);
icon = LoadIcon(ctx->dllInst, MAKEINTRESOURCE(IDI_BRANCH));
ImageList_AddIcon(icons, icon);
DestroyIcon(icon);
icon = LoadIcon(ctx->dllInst, MAKEINTRESOURCE(IDI_BRANCH_REMOTE));
ImageList_AddIcon(icons, icon);
DestroyIcon(icon);
icon = LoadIcon(ctx->dllInst, MAKEINTRESOURCE(IDI_TAG));
ImageList_AddIcon(icons, icon);
DestroyIcon(icon);
icon = LoadIcon(ctx->dllInst, MAKEINTRESOURCE(IDI_TAG_LIGHT));
ImageList_AddIcon(icons, icon);
DestroyIcon(icon);
icon = LoadIcon(ctx->dllInst, MAKEINTRESOURCE(IDI_HEAD));
ImageList_AddIcon(icons, icon);
DestroyIcon(icon);
ctx->refTypeIl = icons;
}
SCCRTN SccInitialize (LPVOID * context, // SCC provider contex
HWND hWnd, // IDE window
LPCSTR callerName, // IDE name
LPSTR sccName, // SCC provider name
LPLONG sccCaps, // SCC provider capabilities
LPSTR auxPathLabel, // Aux path label, used in project open
LPLONG checkoutCommentLen, // Check out comment max length
LPLONG commentLen) // Other comments max length
{
LGitLog("**SccInitialize**\n");
LGitLog(" Caller = %s\n", callerName);
int init_count = git_libgit2_init();
if (init_count < 0) {
LGitLibraryError(hWnd, "Error initializing LGit");
return SCC_E_INITIALIZEFAILED;
}
LGitLog(" InitCount = %d\n", init_count);
/* Should this be only on the first init count? */
LGitInitOpts();
strlcpy(sccName, "Visual Git", SCC_NAME_LEN);
*sccCaps = LGitGetCaps();
/* XXX: What are the /real/ limits? */
*checkoutCommentLen = 0; /* checkout comments are nonsensical */
*commentLen = 2048;
// XXX
strlcpy (auxPathLabel, "LGitProject:", SCC_AUXLABEL_LEN);
LGitLog(" LPVOID* Context=%p\n", context);
LGitLog(" *Context=%p\n", *context);
/*
* VC++ 6 will provide the last handle we initialized. Other IDEs don't do
* this. It's not some reuse scheme - don't get confused!
*/
if (context != NULL) {
*context = malloc(sizeof(LGitContext));
LGitContext *ctx = (LGitContext*)*context;
if (*context == NULL) {
return SCC_E_INITIALIZEFAILED;
}
LGitLog(" New *Context=%p\n", *context);
ZeroMemory(*context, sizeof(LGitContext));
strlcpy(ctx->appName, callerName, SCC_NAME_LEN);
ctx->dllInst = dllInstance;
/* gets reinitialized on project, but here, for empty proj */
LGitInitializeFonts(ctx);
/* initialize some stuff like image lists that can persist */
InitImageLists(ctx);
} else {
return SCC_E_INITIALIZEFAILED;
}
return SCC_OK;
}
SCCRTN SccUninitialize (LPVOID context)
{
LGitContext *ctx = (LGitContext*)context;
int uninit_count;
uninit_count = git_libgit2_shutdown();
LGitLog("**SccUninitialize** Context=%p\n", context);
LGitLog(" Uninit count =%d\n", uninit_count);
if (uninit_count < 0) {
LGitLibraryError(NULL, "Error ending LGit");
}
/* remember free shared resources */
if (context == NULL) {
LGitLog("!! Asked to free a null context\n");
} else {
ImageList_Destroy(ctx->refTypeIl);
free(context);
LGitLog(" Freed context\n");
}
return SCC_OK;
}