summaryrefslogtreecommitdiff
path: root/dbeditorpp/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dbeditorpp/main.cpp')
-rw-r--r--dbeditorpp/main.cpp326
1 files changed, 67 insertions, 259 deletions
diff --git a/dbeditorpp/main.cpp b/dbeditorpp/main.cpp
index e5a0060..b94cceb 100644
--- a/dbeditorpp/main.cpp
+++ b/dbeditorpp/main.cpp
@@ -1,74 +1,60 @@
#include "headers.h"
-#pragma comment(exestr, "\n\n Bio was here 8-) \n")
-
// {A8A417EF-07AA-4f37-869F-7BFD74886534}
#define MIID_DBEDITOR {0xa8a417ef, 0x7aa, 0x4f37, { 0x86, 0x9f, 0x7b, 0xfd, 0x74, 0x88, 0x65, 0x34}}
+PLUGINLINK *pluginLink;
+HINSTANCE hInst = NULL;
-
+struct MM_INTERFACE mmi;
+struct UTF8_INTERFACE utfi;
HANDLE hTTBButt = NULL;
-DWORD mirandaVer;
BOOL bServiceMode = FALSE;
+BOOL usePopUps;
+HWND hwnd2watchedVarsWindow;
+int UDB;
+BYTE nameOrder[NAMEORDERCOUNT];
+HANDLE hUserMenu;
+HANDLE hRestore;
+WatchListArrayStruct WatchListArray;
+BYTE UsingIconManager;
//========================
// MirandaPluginInfo
//========================
-PLUGININFO pluginInfo={
- sizeof(PLUGININFO),
- modFullname,
- PLUGIN_MAKE_VERSION(3,2,0,0),
- "Advanced Database Editor. More advanced & bugfixed by Bio.\r\n[ "__DATE__" "__TIME__" ]",
- "Bio, Jonathan Gordon",
- "bio@msx.ru, jdgordy@gmail.com",
- "© 2003-2006 Bio, Jonathan Gordon",
- "http://addons.miranda-im.org/details.php?action=viewfile&id=2957",
- 0, //not transient
- 0 //doesn't replace anything built-in
-};
-
-__declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
-{
- if (mirandaVersion < PLUGIN_MAKE_VERSION(0, 7, 0, 0)) // 0.4 better. 0.3 have too many bugs
- {
- return NULL;
- }
- return &pluginInfo;
-}
-
PLUGININFOEX pluginInfoEx={
- sizeof(PLUGININFOEX),
- modFullname,
- PLUGIN_MAKE_VERSION(3,2,0,0),
- "Advanced Database Editor. More advanced & bugfixed by Bio.\r\n[ "__DATE__" "__TIME__" ]",
- "Bio, Jonathan Gordon",
- "bio@msx.ru, jdgordy@gmail.com",
- "© 2003-2006 Bio, Jonathan Gordon",
- "http://addons.miranda-im.org/details.php?action=viewfile&id=2957",
+ sizeof(PLUGININFOEX),
+ __PLUGIN_NAME,
+ PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
+ __DESCRIPTION,
+ __AUTHOR,
+ __AUTHOREMAIL,
+ __COPYRIGHT,
+ __AUTHORWEB,
UNICODE_AWARE,
0,
MIID_DBEDITOR
};
-
-__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
{
- mirandaVer = mirandaVersion;
+ if (mirandaVersion < PLUGIN_MAKE_VERSION(0, 7, 0, 0)) // 0.4 better. 0.3 have too many bugs
+ {
+ return NULL;
+ }
return &pluginInfoEx;
}
// we implement service mode interface
static const MUUID interfaces[] = {MIID_SERVICEMODE, MIID_LAST};
-__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
+extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
{
return interfaces;
}
-
//========================
// WINAPI DllMain
//========================
-
BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
hInst=hinstDLL;
@@ -78,7 +64,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
//===================
// MainInit
//===================
-
int MainInit(WPARAM wParam,LPARAM lParam)
{
return 0;
@@ -97,11 +82,11 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam)
if (hwnd2mainWindow)
{
HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS);
- if (info = (SettingListInfo*)GetWindowLong(hwnd2Settings,GWL_USERDATA))
+ if (info = (SettingListInfo*)GetWindowLongPtr(hwnd2Settings,GWLP_USERDATA))
{
if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule))
{
- setting = strdup(cws->szSetting);
+ setting = mir_tstrdup(cws->szSetting);
if (cws->value.type == DBVT_DELETED)
{
LVFINDINFO lvfi;
@@ -112,11 +97,11 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam)
index = ListView_FindItem(hwnd2Settings,-1,&lvfi);
if (index > -1)
ListView_DeleteItem(hwnd2Settings, index);
- safe_free(setting);
+ mir_free(setting);
return 0;
}
settingChanged(hwnd2Settings, hContact, info->module, setting);
- safe_free(setting);
+ mir_free(setting);
}
}
}
@@ -132,7 +117,7 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam)
if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting))
{
if (usePopUps)
- popupWatchedVar(hContact,cws->szModule, cws->szSetting);
+ popupWatchedVar(hContact, cws->szModule, cws->szSetting);
if (hwnd2watchedVarsWindow)
PopulateWatchedWindow(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS));
break;
@@ -143,14 +128,14 @@ int DBSettingChanged(WPARAM wParam,LPARAM lParam)
return 0;
}
-static int DBEditorppMenuCommand(WPARAM wParam,LPARAM lParam)
+INT_PTR DBEditorppMenuCommand(WPARAM wParam, LPARAM lParam)
{
if (!hwnd2mainWindow) // so only opens 1 at a time
{
hRestore = (HANDLE)wParam;
SetCursor(LoadCursor(NULL,IDC_WAIT));
- CreateDialog(hInst,MAKEINTRESOURCE(IDD_MAIN),0,MainDlgProc);
+ CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), 0, MainDlgProc);
}
else
{
@@ -168,7 +153,6 @@ static int DBEditorppMenuCommand(WPARAM wParam,LPARAM lParam)
return 0;
}
-
BOOL IsCP_UTF8(void)
{
CPINFO CPInfo;
@@ -176,29 +160,6 @@ BOOL IsCP_UTF8(void)
return GetCPInfo(CP_UTF8, &CPInfo);
}
-
-BOOL InitWFuctions(void)
-{
- HMODULE hDll = LoadLibrary("user32.dll");
- if (hDll)
- {
- _CreateDialogParamW = (HWND (WINAPI *)(HINSTANCE,LPCWSTR,HWND,DLGPROC,LPARAM))GetProcAddress(hDll, "CreateDialogParamW");
- _CreateWindowExW = (HWND (WINAPI *)(DWORD,LPCWSTR,LPCWSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID))GetProcAddress(hDll, "CreateWindowExW");
- _CallWindowProcW = (LRESULT (WINAPI *)(WNDPROC,HWND,UINT,WPARAM,LPARAM))GetProcAddress(hDll, "CallWindowProcW");
- _SetWindowLongW = (LONG (WINAPI *)(HWND,int,LONG))GetProcAddress(hDll, "SetWindowLongW");
- _SendMessageW = (LRESULT (WINAPI *)(HWND,UINT,WPARAM,LPARAM))GetProcAddress(hDll, "SendMessageW");
-
- if (_CreateDialogParamW &&
- _CreateWindowExW &&
- _CallWindowProcW &&
- _SetWindowLongW &&
- _SendMessageW)
- return 1;
-
- }
- return 0;
-}
-
HANDLE hTTBHook = NULL;
static int OnTTBLoaded(WPARAM wParam,LPARAM lParam)
{
@@ -227,7 +188,7 @@ HANDLE hModulesLoadedHook = NULL;
int ModulesLoaded(WPARAM wParam,LPARAM lParam)
{
DBVARIANT dbv;
- char *coreMods = "AutoAway, CLC, CList CListGroups, CLUI, Contact, DBEditorpp, Icons, Idle, Ignore, Netlib, Options, PluginDisable, Skin, SkinHotKeys, SkinSounds, SkinSoundsOff, SRAway, SRFile, SRMsg, SRUrl, UpdateCheck, UserInfo, UserOnline, _Filter, Protocol, KnownModules, SkinIcons, FirstRun";
+ char *coreMods = "";
char *mods;
char mod[64] = "";
char szModuleFileName[MAX_PATH];
@@ -240,8 +201,8 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam)
mods = coreMods;
}
- len=strlen(mods);
- while (i<len)
+ len = (int)strlen(mods);
+ while (i < len)
{
if (mods[i] == '\\' && mods[i+1] == ' ')
{
@@ -307,7 +268,7 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam)
// check OS support for unicode
// useless if DB doesnt not support unicode
- UOS = (UDB && IsCP_UTF8() && InitWFuctions() && IsWinVerNT());
+ UOS = (UDB && IsCP_UTF8() && IsWinVerNT());
// updater support
{
@@ -316,9 +277,9 @@ int ModulesLoaded(WPARAM wParam,LPARAM lParam)
update.cbSize = sizeof(Update);
- update.szComponentName = pluginInfo.shortName;
- update.pbVersion = (BYTE *)CreateVersionStringPlugin(&pluginInfo, szVersion);
- update.cpbVersion = strlen((char *)update.pbVersion);
+ update.szComponentName = pluginInfoEx.shortName;
+ update.pbVersion = (BYTE *)CreateVersionStringPluginEx(&pluginInfoEx, szVersion);
+ update.cpbVersion = (int)strlen((char *)update.pbVersion);
update.szUpdateURL = "http://addons.miranda-im.org/feed.php?dlsource=2957";
update.szVersionURL = "http://addons.miranda-im.org/details.php?action=viewfile&id=2957";
@@ -357,13 +318,18 @@ int PreShutdown(WPARAM wParam,LPARAM lParam)
return 0;
}
-int ServiceMode(WPARAM wParam,LPARAM lParam) {
+INT_PTR ServiceMode(WPARAM wParam,LPARAM lParam) {
bServiceMode = TRUE;
return 0;
}
+INT_PTR ImportFromFile(WPARAM wParam,LPARAM lParam)
+{
+ ImportSettingsFromFileMenuItem((HANDLE)wParam, (char*)lParam);
+ return 0;
+}
-int __declspec(dllexport) Load(PLUGINLINK *link)
+extern "C" __declspec(dllexport) int Load(PLUGINLINK *link)
{
CLISTMENUITEM mi;
/*
@@ -374,10 +340,8 @@ int __declspec(dllexport) Load(PLUGINLINK *link)
#endif
*/
pluginLink = link;
-
- if (mirandaVer < PLUGIN_MAKE_VERSION(0,7,0,0))
- return -1;
-
+ mir_getMMI(&mmi);
+ mir_getUTFI( &utfi );
hwnd2mainWindow = 0;
hwnd2watchedVarsWindow = 0;
@@ -388,9 +352,10 @@ int __declspec(dllexport) Load(PLUGINLINK *link)
// hHookedEvents[2] = HookEvent(ME_CLIST_PREBUILDCONTACTMENU,PrebuildContactMenu);
HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);
hModulesLoadedHook = HookEvent(ME_SYSTEM_MODULESLOADED,ModulesLoaded);
- CreateServiceFunction("DBEditorpp/MenuCommand",DBEditorppMenuCommand);
- CreateServiceFunction("DBEditorpp/RegisterModule",RegisterModule);
- CreateServiceFunction("DBEditorpp/RegisterSingleModule",RegisterSingleModule);
+ CreateServiceFunction("DBEditorpp/MenuCommand", DBEditorppMenuCommand);
+ CreateServiceFunction("DBEditorpp/RegisterModule", RegisterModule);
+ CreateServiceFunction("DBEditorpp/RegisterSingleModule", RegisterSingleModule);
+ CreateServiceFunction("DBEditorpp/Import", ImportFromFile);
ZeroMemory(&mi,sizeof(mi));
mi.cbSize=sizeof(mi);
mi.position=1900000001;
@@ -404,9 +369,9 @@ int __declspec(dllexport) Load(PLUGINLINK *link)
ZeroMemory(&mi,sizeof(mi));
mi.cbSize=sizeof(mi);
mi.position=1900000001;
- mi.flags=DBGetContactSettingByte(NULL,modname,"UserMenuItem",1)?0:CMIF_HIDDEN;
+ mi.flags=DBGetContactSettingByte(NULL,modname,"UserMenuItem",0)?0:CMIF_HIDDEN;
mi.hIcon=LoadIcon(hInst,MAKEINTRESOURCE(ICO_REGUSER));
- mi.pszName=Translate("Open user tree in DBE++");
+ mi.pszName="Open user tree in DBE++";
mi.pszService="DBEditorpp/MenuCommand";
mi.pszContactOwner=NULL;
hUserMenu = (HANDLE) CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) & mi);
@@ -429,7 +394,7 @@ int __declspec(dllexport) Load(PLUGINLINK *link)
return 0;
}
-int __declspec(dllexport) Unload(void)
+extern "C" __declspec(dllexport) int Unload(void)
{
FreeKnownModuleList();
freeAllWatches();
@@ -460,20 +425,6 @@ int DBGetContactSettingStringStatic(HANDLE hContact, char* szModule, char* szSet
return 0;
}
-
-int DBWriteContactSettingBlob(HANDLE hContact,const char *szModule,const char *szSetting, const BYTE *pbVal, WORD cbVal)
-{
- DBCONTACTWRITESETTING cws;
-
- cws.szModule = szModule;
- cws.szSetting = szSetting;
- cws.value.type = DBVT_BLOB;
- cws.value.pbVal = (BYTE*)pbVal;
- cws.value.cpbVal = cbVal;
- return CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)hContact,(LPARAM)&cws);
-}
-
-
int WriteBlobFromString(HANDLE hContact,const char *szModule,const char *szSetting, const char *szValue, int len)
{
int j=0, i = 0;
@@ -544,9 +495,9 @@ int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char*
case DBVT_UTF8:
if (UOS)
{
- int len = strlen(dbv.pszVal)+1;
- char *sz = _alloca(len*3);
- WCHAR *wc = _alloca(len*sizeof(WCHAR));
+ int len = (int)strlen(dbv.pszVal)+1;
+ char *sz = (char*)_alloca(len*3);
+ WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR));
MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len);
WideCharToMultiByte(CP_ACP, 0, wc, -1, sz, len, NULL, NULL);
strncpy(Value, sz, length);
@@ -588,16 +539,16 @@ int GetValueW(HANDLE hContact, const char* szModule, const char* szSetting, WCHA
switch(dbv.type) {
case DBVT_UTF8:
{
- int len = strlen(dbv.pszVal)+1;
- WCHAR *wc = _alloca(length*sizeof(WCHAR));
+ int len = (int)strlen(dbv.pszVal) + 1;
+ WCHAR *wc = (WCHAR*)_alloca(length*sizeof(WCHAR));
MultiByteToWideChar(CP_UTF8, 0, dbv.pszVal, -1, wc, len);
wcsncpy((WCHAR*)Value, wc, length);
}
break;
case DBVT_ASCIIZ:
{
- int len = strlen(dbv.pszVal)+1;
- WCHAR *wc = _alloca(len*sizeof(WCHAR));
+ int len = (int)strlen(dbv.pszVal) + 1;
+ WCHAR *wc = (WCHAR*)_alloca(len*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len);
wcsncpy((WCHAR*)Value, wc, length);
}
@@ -631,7 +582,7 @@ char *u2a( wchar_t* src )
if (src)
{
int cbLen = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );
- char* result = ( char* )calloc( cbLen+1, 1);
+ char* result = (char*)mir_calloc((cbLen+1)*sizeof(char));
if ( result == NULL )
return NULL;
@@ -656,149 +607,6 @@ wchar_t *a2u( char* src , wchar_t *buffer, int len )
return result;
}
-/*
-wchar_t *a2u( char* src )
-{
- int cbLen = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
- wchar_t* result = ( wchar_t* )calloc(sizeof(wchar_t),(cbLen+1));
- if ( result == NULL )
- return NULL;
-
- MultiByteToWideChar( CP_ACP, 0, src, -1, result, cbLen );
- result[ cbLen ] = 0;
- return result;
-}
-
-*/
-/*
- * The following UTF8 routines are
- *
- * Copyright (C) 2001 Peter Harris <peter.harris@hummingbird.com>
- * Copyright (C) 2001 Edmund Grimley Evans <edmundo@rano.org>
- *
- * under a GPL license
- *
- * --------------------------------------------------------------
- * Convert a string between UTF-8 and the locale's charset.
- * Invalid bytes are replaced by '#', and characters that are
- * not available in the target encoding are replaced by '?'.
- *
- * If the locale's charset is not set explicitly then it is
- * obtained using nl_langinfo(CODESET), where available, the
- * environment variable CHARSET, or assumed to be US-ASCII.
- *
- * Return value of conversion functions:
- *
- * -1 : memory allocation failed
- * 0 : data was converted exactly
- * 1 : valid data was converted approximately (using '?')
- * 2 : input was invalid (but still converted, using '#')
- * 3 : unknown encoding (but still converted, using '?')
- */
-
-
-/*
-unsigned char *make_utf8_string(const wchar_t *unicode)
-{
-
- int size = 0;
- int index = 0;
- int out_index = 0;
- unsigned char* out;
- unsigned short c;
-
-
- // first calculate the size of the target string
- c = unicode[index++];
- while(c) {
- if(c < 0x0080) {
- size += 1;
- } else if(c < 0x0800) {
- size += 2;
- } else {
- size += 3;
- }
- c = unicode[index++];
- }
-
- out = malloc(size + 1);
- if (out == NULL)
- return NULL;
- index = 0;
-
- c = unicode[index++];
- while(c)
- {
- if(c < 0x080) {
- out[out_index++] = (unsigned char)c;
- } else if(c < 0x800) {
- out[out_index++] = 0xc0 | (c >> 6);
- out[out_index++] = 0x80 | (c & 0x3f);
- } else {
- out[out_index++] = 0xe0 | (c >> 12);
- out[out_index++] = 0x80 | ((c >> 6) & 0x3f);
- out[out_index++] = 0x80 | (c & 0x3f);
- }
- c = unicode[index++];
- }
- out[out_index] = 0x00;
-
- return out;
-}
-
-
-wchar_t *make_unicode_string(const unsigned char *utf8)
-{
-
- int size = 0, index = 0, out_index = 0;
- wchar_t *out;
- unsigned char c;
-
-
- // first calculate the size of the target string
- c = utf8[index++];
- while(c) {
- if((c & 0x80) == 0) {
- index += 0;
- } else if((c & 0xe0) == 0xe0) {
- index += 2;
- } else {
- index += 1;
- }
- size += 1;
- c = utf8[index++];
- }
-
- out = malloc((size + 1) * sizeof(wchar_t));
- if (out == NULL)
- return NULL;
- index = 0;
-
- c = utf8[index++];
- while(c)
- {
- if((c & 0x80) == 0) {
- out[out_index++] = c;
- } else if((c & 0xe0) == 0xe0) {
- out[out_index] = (c & 0x1F) << 12;
- c = utf8[index++];
- out[out_index] |= (c & 0x3F) << 6;
- c = utf8[index++];
- out[out_index++] |= (c & 0x3F);
- } else {
- out[out_index] = (c & 0x3F) << 6;
- c = utf8[index++];
- out[out_index++] |= (c & 0x3F);
- }
- c = utf8[index++];
- }
- out[out_index] = 0;
-
- return out;
-}
-*/
-
-
int mir_snwprintf(WCHAR *buffer, size_t count, const WCHAR* fmt, ...)
{
va_list va;
@@ -833,7 +641,7 @@ WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode)
if (hContact && !proto)
{
- if (GetValue(hContact,"Protocol","p",name,sizeof(name)))
+ if (GetValue(hContact,"Protocol","p",name,SIZEOF(name)))
proto = name;
}
@@ -883,9 +691,9 @@ WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode)
if (r = GetDatabaseString(hContact,proto,"FirstName",res,SIZEOF(res),unicode))
{
if (unicode)
- len = wcslen(res);
+ len = (int)wcslen(res);
else
- len = strlen((char*)res);
+ len = (int)strlen((char*)res);
}
else
res[0] = 0;