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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
#ifndef _COMMONHEADERS_H
#define _COMMONHEADERS_H
//=====================================================
// Includes
//=====================================================
#include <Windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <io.h>
#include <time.h>
#include <stddef.h>
#include <shlwapi.h>
#include <process.h>
#include <string.h>
#include <malloc.h>
#include <newpluginapi.h>
#include <m_clist.h>
#include <m_database.h>
#include <m_db_int.h>
#include <m_gui.h>
#include <m_hotkeys.h>
#include <m_icolib.h>
#include <m_langpack.h>
#include <m_metacontacts.h>
#include <m_netlib.h>
#include <m_options.h>
#include <m_popup.h>
#include <m_protocols.h>
#include <m_protosvc.h>
#include <m_skin.h>
#include <m_userinfo.h>
#include <m_utils.h>
#include "m_toptoolbar.h"
#include "resource.h"
#include "version.h"
//=======================================================
// Definitions
//=======================================================
#define MODULENAME "DBEditorpp"
#define modFullname "Database Editor++"
#define modFullnameW L"Database Editor++"
struct CMPlugin : public PLUGIN<CMPlugin>
{
CMOption<bool> bExpandSettingsOnOpen, bRestoreOnOpen, bWarnOnDelete;
CMOption<WORD> iPopupDelay;
CMOption<DWORD> iPopupBkColor, iPopupTxtColor;
CMPlugin();
int Load() override;
int Unload() override;
};
#define FLD_SIZE 256
#define MSG_SIZE 256
#define NAME_SIZE 128
/***********************
ModuleTreeInfoStruct
this gets dumped as the lparam for each module tree item
************************/
// types
#define CONTACT_ROOT_ITEM 0
#define CONTACT 1
#define MODULE 2
#define STUB 4
#define EMPTY 8
struct ModuleTreeInfoStruct
{
int type; // from above types
MCONTACT hContact;
};
struct DBsetting
{
MCONTACT hContact;
char *module;
char *setting;
DBVARIANT dbv;
};
struct ModuleAndContact
{
char module[FLD_SIZE];
MCONTACT hContact;
};
// watchwindow
struct WatchListArrayStruct
{
DBsetting *item; // gotta malloc this
int count;
int size;
};
// module setting enum
struct ModSetLinkLinkItem
{
char *name;
ModSetLinkLinkItem *next;
};
struct ModuleSettingLL
{
ModSetLinkLinkItem *first;
ModSetLinkLinkItem *last;
};
struct ColumnsSettings
{
wchar_t *name;
int index;
char *dbname;
int defsize;
};
struct ColumnsSortParams
{
HWND hList;
int column;
int last;
};
enum ICONS
{
IMAGE_EMPTY,
IMAGE_BINARY,
IMAGE_BYTE,
IMAGE_WORD,
IMAGE_DWORD,
IMAGE_STRING,
IMAGE_UNICODE,
IMAGE_HANDLE,
IMAGE_SETTINGS,
IMAGE_CLOSED,
IMAGE_OPENED,
IMAGE_CONTACTS,
IMAGE_ONLINE,
IMAGE_OFFLINE
};
//=======================================================
// Variables
//=======================================================
extern int g_Mode;
extern int g_Hex;
extern int g_Order;
extern int g_Inline;
extern MCONTACT hRestore;
extern MIDatabase *g_db;
extern bool g_bServiceMode;
extern bool g_bUsePopups;
#define NAMEORDERCOUNT 9
#define MODE_UNLOADED 1
#define MODE_LOADED 2
#define MODE_ALL 3
#define HEX_BYTE 1
#define HEX_WORD 2
#define HEX_DWORD 4
// main
char *StringFromBlob(BYTE *blob, WORD len);
int WriteBlobFromString(MCONTACT hContact, const char *module, const char *setting, const char *value, int len);
wchar_t *DBVType(BYTE type);
DWORD getNumericValue(DBVARIANT *dbv);
int setNumericValue(MCONTACT hContact, const char *module, const char *setting, DWORD value, int type);
int IsRealUnicode(wchar_t *value);
int setTextValue(MCONTACT hContact, const char *module, const char *setting, wchar_t *value, int type);
int GetValueA(MCONTACT hContact, const char *module, const char *setting, char *value, int length);
int GetValueW(MCONTACT hContact, const char *module, const char *setting, wchar_t *value, int length);
int GetContactName(MCONTACT hContact, const char *proto, wchar_t *value, int maxlen);
int ApplyProtoFilter(MCONTACT hContact);
void loadListSettings(HWND hwnd, ColumnsSettings *cs);
void saveListSettings(HWND hwnd, ColumnsSettings *cs);
int CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam);
// main_window
class CMainDlg : public CDlgBase
{
int m_splitterPos;
int m_lastColumn = -1;
MCONTACT m_hContact = 0;
int m_selectedItem = -1; // item that is currently selected
char m_module[FLD_SIZE];
// for edit
HWND m_hwnd2Edit = nullptr;
char m_setting[FLD_SIZE];
int m_subitem = 0;
CSplitter m_splitter;
CCtrlTreeView m_modules;
CCtrlListView m_settings;
void addModuleDlg(MCONTACT hContact);
void deleteModuleDlg();
int doContacts(HTREEITEM contactsRoot, ModuleSettingLL *modlist, MCONTACT hSelectedContact, const char *selectedModule, const char *selectedSetting);
void doItems(ModuleSettingLL *modlist, int count);
void ImportSettingsMenuItem(MCONTACT hContact);
UI_MESSAGE_MAP(CMainDlg, CDlgBase);
UI_MESSAGE(WM_COMMAND, OnCommand);
UI_MESSAGE_MAP_END();
public:
CMainDlg();
__forceinline void msg(const wchar_t *pwszMessage) {
MessageBoxW((this != nullptr) ? m_hwnd : 0, pwszMessage, modFullnameW, MB_OK);
}
__forceinline int dlg(const wchar_t *pwszMessage, int code) {
return MessageBoxW((this != nullptr) ? m_hwnd : 0, pwszMessage, modFullnameW, code);
}
bool OnInitDialog() override;
void OnDestroy() override;
int Resizer(UTILRESIZECONTROL *urc) override;
LRESULT OnCommand(UINT, WPARAM, LPARAM);
void onChange_Splitter(CSplitter*);
// find window
#define FW_MODULE 0
#define FW_SETTINGNAME 1
#define FW_SETTINGVALUE 2
void FindItem(int type, MCONTACT, const char *szModule, const char *szSetting);
////////////////////////////////////////////////////////////////////////////////////////
// module tree
HTREEITEM findItemInTree(MCONTACT hContact, const char *module);
BOOL findAndRemoveDuplicates(MCONTACT hContact, const char *module);
void freeTree(MCONTACT hContact);
void insertItem(MCONTACT hContact, const char *module, HTREEITEM hParent);
void replaceTreeItem(MCONTACT hContact, const char *module, const char *newModule);
void onItemExpand_Modules(CCtrlTreeView::TEventInfo *ev);
void onSelChanged_Modules(CCtrlTreeView::TEventInfo *ev);
void onBeginLabelEdit_Modules(CCtrlTreeView::TEventInfo *ev);
void onEndLabelEdit_Modules(CCtrlTreeView::TEventInfo *ev);
void onContextMenu_Modules(CContextMenuPos *pos);
static void __cdecl PopulateModuleTreeThreadFunc(void *param);
////////////////////////////////////////////////////////////////////////////////////////
// settings list
void ClearListView();
void DeleteSettingsFromList(MCONTACT hContact, const char *module, const char *setting);
void EditFinish(int selected);
void EditLabel(int item, int subitem);
bool EditLabelWndProc(HWND hwnd, UINT, WPARAM);
bool ListWndProc(UINT, WPARAM wParam);
void PopulateSettings(MCONTACT hContact, const char *module);
void SelectSetting(const char *setting);
void addListHandle(MCONTACT hContact);
void addListItem(const char *setting, int resident);
void deleteListItem(const char *setting);
int findListItem(const char *setting);
void updateListItem(int index, const char *setting, DBVARIANT *dbv, int resident);
void editSetting(MCONTACT hContact, const char *module, const char *setting);
void copySetting(MCONTACT hContact, const char *module, const char *setting);
void newSetting(MCONTACT hContact, const char *module, int type);
void onSettingChanged(MCONTACT hContact, DBCONTACTWRITESETTING *cws);
void onClick_Settings(CCtrlListView::TEventInfo *ev);
void onDblClick_Settings(CCtrlListView::TEventInfo *ev);
void onColumnClick_Settings(CCtrlListView::TEventInfo *ev);
void onContextMenu_Settings(CContextMenuPos *pos);
};
extern CMainDlg *g_pMainWindow;
// deletemodules
int deleteModule(HWND hwndParent, MCONTACT hContact, const char *module, int confirm);
// renamemodule
int renameModule(MCONTACT hContact, const char *oldName, const char *newName);
// moduletree
void refreshTree(BOOL restore);
// exportimport
void exportDB(MCONTACT hContact, const char *module); // hContact == -1 export entire db. module == NULL export entire contact
void ImportSettingsFromFileMenuItem(MCONTACT hContact, const char *filePath); // ansi!
// find window
void newFindWindow();
// copymodule
void copyModuleMenuItem(HWND hwndParent, MCONTACT hContact, const char *module);
void copyModule(const char *module, MCONTACT hContactFrom, MCONTACT hContactTo);
// options
int OptInit(WPARAM wParam, LPARAM lParam);
// watchedvars
int WatchedArrayIndex(MCONTACT hContact, const char *module, const char *setting, int strict);
int addSettingToWatchList(MCONTACT hContact, const char *module, const char *setting);
void freeWatchListItem(int item);
void PopulateWatchedWindow();
void freeAllWatches();
void openWatchedVarWindow();
void popupWatchedVar(MCONTACT hContact, const char *module, const char *setting);
// modsettingenum
int EnumModules(ModuleSettingLL *msll);
int EnumSettings(MCONTACT hContact, const char *module, ModuleSettingLL *msll);
void FreeModuleSettingLL(ModuleSettingLL *msll);
int IsModuleEmpty(MCONTACT hContact, const char *module);
int LoadResidentSettings();
void FreeResidentSettings();
int IsResidentSetting(const char *module, const char *setting);
int EnumResidentSettings(const char *module, ModuleSettingLL *msll);
int fixResidentSettings();
// icons
void IcoLibRegister();
HICON LoadSkinnedDBEIcon(int icon);
HIMAGELIST LoadIcons();
int GetProtoIconIndex(const char *proto);
int ListView_GetItemTextA(HWND hwndLV, int i, int iSubItem, char *pszText, int cchTextMax);
int ListView_SetItemTextA(HWND hwndLV, int i, int iSubItem, const char *pszText);
#endif //_COMMONHEADERS_H
|