forked from Maximus5/ConEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConEmuBg1900.cpp
293 lines (251 loc) · 8.45 KB
/
ConEmuBg1900.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
Copyright (c) 2010-present Maximus5
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "../common/defines.h"
#ifdef _DEBUG
#pragma warning( disable : 4995 )
#endif
#include "../common/pluginW1900.hpp" // Far3
#ifdef _DEBUG
#pragma warning( default : 4995 )
#endif
#include "../common/plugin_helper.h"
#include "ConEmuBg.h"
#include "../ConEmu/version.h"
//#define FCTL_GETPANELDIR FCTL_GETCURRENTDIRECTORY
//#define _ACTL_GETFARRECT 32
#ifdef _DEBUG
#define SHOW_DEBUG_EVENTS
#endif
struct PluginStartupInfo *InfoW1900 = NULL;
struct FarStandardFunctions *FSFW1900 = NULL;
extern GUID guid_ConEmuBg;
extern GUID guid_ConEmuBgCfgDlg;
extern GUID guid_ConEmuBgPluginMenu;
extern GUID guid_ConEmuBgPluginConfig;
#if 0
void WINAPI GetGlobalInfoW(struct GlobalInfo *Info)
{
//static wchar_t szTitle[16]; _wcscpy_c(szTitle, L"ConEmu");
//static wchar_t szDescr[64]; _wcscpy_c(szTitle, L"ConEmu support for Far Manager");
//static wchar_t szAuthr[64]; _wcscpy_c(szTitle, L"[email protected]");
//Info->StructSize = sizeof(GlobalInfo);
_ASSERTE(Info->StructSize >= sizeof(GlobalInfo));
Info->MinFarVersion = FARMANAGERVERSION;
// Build: YYMMDDX (YY - две цифры года, MM - месяц, DD - день, X - 0 и выше-номер подсборки)
Info->Version = MAKEFARVERSION(MVV_1,MVV_2,MVV_3,((MVV_1 % 100)*100000) + (MVV_2*1000) + (MVV_3*10) + (MVV_4 % 10),VS_RELEASE);
Info->Guid = guid_ConEmuBg;
Info->Title = L"ConEmu Background";
Info->Description = L"Paint Far panels background in the ConEmu window";
Info->Author = L"[email protected]";
}
#endif
void GetPluginInfoW1900(void *piv)
{
PluginInfo *pi = (PluginInfo*)piv;
//memset(pi, 0, sizeof(PluginInfo));
//pi->StructSize = sizeof(struct PluginInfo);
_ASSERTE(pi->StructSize>0 && ((size_t)pi->StructSize >= sizeof(*pi)/*(size_t)(((LPBYTE)&pi->MacroFunctionNumber) - (LPBYTE)pi))*/));
static wchar_t *szMenu[1], szMenu1[255];
szMenu[0] = szMenu1;
lstrcpynW(szMenu1, GetMsgW(CEPluginName), 240);
pi->Flags = (gbBackgroundEnabled?PF_PRELOAD:0) | PF_EDITOR | PF_VIEWER;
pi->PluginMenu.Guids = &guid_ConEmuBgPluginMenu;
pi->PluginMenu.Strings = szMenu;
pi->PluginMenu.Count = 1;
pi->PluginConfig.Guids = &guid_ConEmuBgPluginConfig;
pi->PluginConfig.Strings = szMenu;
pi->PluginConfig.Count = 1;
}
void SetStartupInfoW1900(void *aInfo)
{
INIT_FAR_PSI(::InfoW1900, ::FSFW1900, (PluginStartupInfo*)aInfo);
//_ASSERTE(FPS_SHOWSTATUSLINE == 0x00000040);
//_ASSERTE(FPS_SHOWCOLUMNTITLES == 0x00000020);
#ifdef _DEBUG
INT_PTR i;
wchar_t szPath[MAX_PATH];
lstrcpy(szPath, L"C:\\Windows\\TEMP\\fff.log");
i = FSFW1900->ProcessName(L"*\\TEMP\\*", szPath, 0, PN_CMPNAME);
i = FSFW1900->ProcessName(L"TEMP", szPath, 0, PN_CMPNAME);
i = FSFW1900->ProcessName(L"*TEMP*", szPath, 0, PN_CMPNAME);
lstrcpy(szPath, L"C:\\vc\\.svn\\fff.log");
i = FSFW1900->ProcessName(L"*\\.SVN\\*", szPath, 0, PN_CMPNAME);
lstrcpy(szPath, L"C:\\vc\\.svn\\");
i = FSFW1900->ProcessName(L"*\\.SVN\\*", szPath, 0, PN_CMPNAME);
#endif
VersionInfo FarVer = {0};
if (InfoW1900->AdvControl(&guid_ConEmuBg, ACTL_GETFARMANAGERVERSION, 0, &FarVer))
{
if (FarVer.Major == 3)
{
gFarVersion.dwBuild = FarVer.Build;
_ASSERTE(FarVer.Major<=0xFFFF && FarVer.Minor<=0xFFFF)
gFarVersion.dwVerMajor = (WORD)FarVer.Major;
gFarVersion.dwVerMinor = (WORD)FarVer.Minor;
gFarVersion.Bis = (FarVer.Stage==VS_BIS);
}
else
{
_ASSERTE(FarVer.Major == 3);
}
}
//int nLen = lstrlenW(InfoW1900->RootKey)+16;
//if (gszRootKey) free(gszRootKey);
//gszRootKey = (wchar_t*)calloc(nLen,2);
//lstrcpyW(gszRootKey, InfoW1900->RootKey);
//WCHAR* pszSlash = gszRootKey+lstrlenW(gszRootKey)-1;
//if (*pszSlash != L'\\') *(++pszSlash) = L'\\';
//lstrcpyW(pszSlash+1, L"ConEmuTh\\");
}
extern BOOL gbInfoW_OK;
HANDLE WINAPI OpenW1900(const void* apInfo)
{
const struct OpenInfo *Info = (const struct OpenInfo*)apInfo;
if (!gbInfoW_OK)
return NULL;
return OpenPluginWcmn(Info->OpenFrom, Info->Data);
}
void ExitFARW1900(void)
{
if (InfoW1900)
{
free(InfoW1900);
InfoW1900=NULL;
}
if (FSFW1900)
{
free(FSFW1900);
FSFW1900=NULL;
}
}
LPCWSTR GetMsgW1900(int aiMsg)
{
if (!InfoW1900 || !InfoW1900->GetMsg)
return L"";
return InfoW1900->GetMsg(&guid_ConEmuBg,aiMsg);
}
#define FAR_UNICODE 1867
#include "Configure.h"
int ConfigureW1900(int ItemNumber)
{
if (!InfoW1900)
return false;
return ConfigureProc(ItemNumber);
}
void SettingsLoadW1900()
{
FarSettingsCreate sc = {sizeof(FarSettingsCreate), guid_ConEmuBg, INVALID_HANDLE_VALUE};
FarSettingsItem fsi = {0};
if (InfoW1900->SettingsControl(INVALID_HANDLE_VALUE, SCTL_CREATE, 0, &sc))
{
//BYTE cVal; DWORD nVal;
for (ConEmuBgSettings *p = gSettings; p->pszValueName; p++)
{
if (p->nValueType == REG_BINARY)
{
_ASSERTE(p->nValueSize == 1);
//cVal = (BYTE)*(BOOL*)p->pValue;
fsi.Name = p->pszValueName;
fsi.Type = FST_DATA;
//fsi.Data.Size = 1;
//fsi.Data.Data = &cVal;
if (InfoW1900->SettingsControl(sc.Handle, SCTL_GET, 0, &fsi) && (fsi.Data.Size == sizeof(BYTE)))
*((BOOL*)p->pValue) = (*((BYTE*)fsi.Data.Data) != 0);
}
else if (p->nValueType == REG_DWORD)
{
_ASSERTE(p->nValueSize == 4);
fsi.Name = p->pszValueName;
fsi.Type = FST_DATA;
//fsi.Data.Size = 4;
//fsi.Data.Data = &nVal;
if (InfoW1900->SettingsControl(sc.Handle, SCTL_GET, 0, &fsi) && (fsi.Data.Size == sizeof(DWORD)))
*((DWORD*)p->pValue) = *((DWORD*)fsi.Data.Data);
}
else if (p->nValueType == REG_SZ)
{
fsi.Name = p->pszValueName;
fsi.Type = FST_STRING;
fsi.String = NULL;
if (InfoW1900->SettingsControl(sc.Handle, SCTL_GET, 0, &fsi) && fsi.String)
lstrcpyn((wchar_t*)p->pValue, fsi.String, p->nValueSize);
}
}
InfoW1900->SettingsControl(sc.Handle, SCTL_FREE, 0, 0);
}
}
void SettingsSaveW1900()
{
if (!InfoW1900)
return;
FarSettingsCreate sc = {sizeof(FarSettingsCreate), guid_ConEmuBg, INVALID_HANDLE_VALUE};
FarSettingsItem fsi = {0};
if (InfoW1900->SettingsControl(INVALID_HANDLE_VALUE, SCTL_CREATE, 0, &sc))
{
BYTE cVal;
for (ConEmuBgSettings *p = gSettings; p->pszValueName; p++)
{
if (p->nValueType == REG_BINARY)
{
_ASSERTE(p->nValueSize == 1);
cVal = (BYTE)*(BOOL*)p->pValue;
fsi.Name = p->pszValueName;
fsi.Type = FST_DATA;
fsi.Data.Size = 1;
fsi.Data.Data = &cVal;
InfoW1900->SettingsControl(sc.Handle, SCTL_SET, 0, &fsi);
}
else if (p->nValueType == REG_DWORD)
{
_ASSERTE(p->nValueSize == 4);
fsi.Name = p->pszValueName;
fsi.Type = FST_DATA;
fsi.Data.Size = 4;
fsi.Data.Data = p->pValue;
InfoW1900->SettingsControl(sc.Handle, SCTL_SET, 0, &fsi);
}
else if (p->nValueType == REG_SZ)
{
_ASSERTE(p->nValueSize == MAX_PATH);
fsi.Name = p->pszValueName;
fsi.Type = FST_STRING;
fsi.String = (wchar_t*)p->pValue; // ASCIIZ
InfoW1900->SettingsControl(sc.Handle, SCTL_SET, 0, &fsi);
}
}
InfoW1900->SettingsControl(sc.Handle, SCTL_FREE, 0, 0);
}
}
bool FMatchW1900(LPCWSTR asMask, LPWSTR asPath)
{
INT_PTR iRc = FSFW1900->ProcessName(asMask, asPath, 0, PN_CMPNAME);
return (iRc != 0);
}
int GetMacroAreaW1900()
{
int nArea = (int)InfoW1900->MacroControl(&guid_ConEmuBg, MCTL_GETAREA, 0, 0);
return nArea;
}