summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/DbEditorPP/dbeditorpp.vcxproj1
-rw-r--r--plugins/DbEditorPP/dbeditorpp.vcxproj.filters3
-rw-r--r--plugins/DbEditorPP/src/findwindow.cpp61
-rw-r--r--plugins/DbEditorPP/src/main.cpp373
-rw-r--r--plugins/DbEditorPP/src/stdafx.h8
-rw-r--r--plugins/DbEditorPP/src/utils.cpp367
-rw-r--r--plugins/DbEditorPP/src/version.h4
-rw-r--r--plugins/DbEditorPP/src/watchedvars.cpp3
8 files changed, 406 insertions, 414 deletions
diff --git a/plugins/DbEditorPP/dbeditorpp.vcxproj b/plugins/DbEditorPP/dbeditorpp.vcxproj
index 91255b08d0..140aa8bf05 100644
--- a/plugins/DbEditorPP/dbeditorpp.vcxproj
+++ b/plugins/DbEditorPP/dbeditorpp.vcxproj
@@ -42,6 +42,7 @@
<ClCompile Include="src\stdafx.cxx">
<PrecompiledHeader>Create</PrecompiledHeader>
</ClCompile>
+ <ClCompile Include="src\utils.cpp" />
<ClCompile Include="src\watchedvars.cpp" />
<ClInclude Include="src\resource.h" />
<ClInclude Include="src\stdafx.h" />
diff --git a/plugins/DbEditorPP/dbeditorpp.vcxproj.filters b/plugins/DbEditorPP/dbeditorpp.vcxproj.filters
index c9102b6676..96818394fd 100644
--- a/plugins/DbEditorPP/dbeditorpp.vcxproj.filters
+++ b/plugins/DbEditorPP/dbeditorpp.vcxproj.filters
@@ -47,6 +47,9 @@
<ClCompile Include="src\watchedvars.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\utils.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\resource.h">
diff --git a/plugins/DbEditorPP/src/findwindow.cpp b/plugins/DbEditorPP/src/findwindow.cpp
index fb049cd941..6615bc1405 100644
--- a/plugins/DbEditorPP/src/findwindow.cpp
+++ b/plugins/DbEditorPP/src/findwindow.cpp
@@ -1,24 +1,5 @@
#include "stdafx.h"
-
-
-#ifdef _UNICODE
-#define FindMatchT(a,b,c) FindMatchW(a,b,c)
-#else
-#define FindMatchT(a,b,c) FindMatchA(a,b,c)
-#endif
-
-
-#ifdef _UNICODE
-#define multiReplaceT(a,b,c,d) multiReplaceW(a,b,c,d)
-#else
-#define multiReplaceT(a,b,c,d) multiReplaceA(a,b,c,d)
-#endif
-
-
-static int lastColumn = -1;
-
-
#define F_CASE 1
#define F_EXACT 2
#define F_MODNAME 4
@@ -34,17 +15,17 @@ static int lastColumn = -1;
#define F_REPLACED 0x200
#define F_DELETED 0x400
+static int lastColumn = -1;
-typedef struct
+struct FindInfo
{
HWND hwnd; // hwnd to item list
wchar_t* search; // text to find
wchar_t* replace; // text to replace
int options; // or'd about items
-} FindInfo;
-
+};
-ColumnsSettings csResultList[] =
+static ColumnsSettings csResultList[] =
{
{ LPGENW("Result"), 0, "Search0width", 100 },
{ LPGENW("Contact"), 1, "Search1width", 100 },
@@ -112,7 +93,7 @@ INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE))
break;
- FindInfo *fi = (FindInfo*)mir_calloc(sizeof(FindInfo));
+ FindInfo *fi = (FindInfo *)mir_calloc(sizeof(FindInfo));
if (!fi)
break;
@@ -157,7 +138,7 @@ INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
case WM_GETMINMAXINFO:
{
- MINMAXINFO *mmi = (MINMAXINFO*)lParam;
+ MINMAXINFO *mmi = (MINMAXINFO *)lParam;
mmi->ptMinTrackSize.x = 610;
mmi->ptMinTrackSize.y = 300;
}
@@ -169,11 +150,11 @@ INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
case WM_NOTIFY:
if (LOWORD(wParam) != IDC_LIST) break;
- switch (((NMHDR*)lParam)->code) {
+ switch (((NMHDR *)lParam)->code) {
case NM_DBLCLK:
LVHITTESTINFO hti;
LVITEM lvi;
- hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
+ hti.pt = ((NMLISTVIEW *)lParam)->ptAction;
if (ListView_SubItemHitTest(hwndResults, &hti) > -1) {
if (hti.flags & LVHT_ONITEM) {
lvi.mask = LVIF_PARAM;
@@ -222,10 +203,10 @@ void newFindWindow()
CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_FIND), hwnd2mainWindow, FindWindowDlgProc);
}
-void ItemFound(HWND hwnd, MCONTACT hContact, const char *module, const char *setting, wchar_t* value, int type)
+void ItemFound(HWND hwnd, MCONTACT hContact, const char *module, const char *setting, wchar_t *value, int type)
{
wchar_t name[NAME_SIZE];
- wchar_t* mode;
+ wchar_t *mode;
if (type & F_REPLACED)
mode = TranslateT("Replaced");
@@ -256,7 +237,7 @@ void ItemFound(HWND hwnd, MCONTACT hContact, const char *module, const char *set
}
-char* multiReplaceA(const char *value, const char *search, const char *replace, int cs)
+char *multiReplaceA(const char *value, const char *search, const char *replace, int cs)
{
int slen = (int)mir_strlen(search);
int rlen = (int)mir_strlen(replace);
@@ -266,8 +247,8 @@ char* multiReplaceA(const char *value, const char *search, const char *replace,
int newlen = (!slen) ? rlen + 1 : ((rlen <= slen) ? vlen + 1 : vlen * rlen / slen + 1);
char *head;
- char *in = (char*)value;
- char *out = (char*)mir_alloc(newlen * sizeof(char));
+ char *in = (char *)value;
+ char *out = (char *)mir_alloc(newlen * sizeof(char));
out[0] = 0;
while (head = ci ? strstr(in, search) : StrStrIA(in, search)) {
@@ -281,7 +262,7 @@ char* multiReplaceA(const char *value, const char *search, const char *replace,
return out;
}
-WCHAR* multiReplaceW(const WCHAR *value, const WCHAR *search, const WCHAR *replace, int cs)
+WCHAR *multiReplaceW(const WCHAR *value, const WCHAR *search, const WCHAR *replace, int cs)
{
int slen = (int)mir_wstrlen(search);
int rlen = (int)mir_wstrlen(replace);
@@ -291,8 +272,8 @@ WCHAR* multiReplaceW(const WCHAR *value, const WCHAR *search, const WCHAR *repla
int newlen = (!slen) ? rlen + 1 : ((rlen <= slen) ? vlen + 1 : vlen * rlen / slen + 1);
WCHAR *head;
- WCHAR *in = (WCHAR*)value;
- WCHAR *out = (WCHAR*)mir_alloc(newlen * sizeof(WCHAR));
+ WCHAR *in = (WCHAR *)value;
+ WCHAR *out = (WCHAR *)mir_alloc(newlen * sizeof(WCHAR));
out[0] = 0;
while (head = ci ? wcsstr(in, search) : StrStrIW(in, search)) {
@@ -333,7 +314,7 @@ int FindMatchW(const WCHAR *text, WCHAR *search, int options)
}
-void fi_free(FindInfo* fi)
+void fi_free(FindInfo *fi)
{
mir_free(fi->search);
mir_free(fi->replace);
@@ -343,7 +324,7 @@ void fi_free(FindInfo* fi)
void __cdecl FindSettings(LPVOID param)
{
- FindInfo* fi = (FindInfo*)param;
+ FindInfo *fi = (FindInfo *)param;
HWND hwndParent = GetParent(fi->hwnd);
ModuleSettingLL ModuleList, SettingList;
@@ -461,14 +442,14 @@ void __cdecl FindSettings(LPVOID param)
case DBVT_ASCIIZ:
if (!value) value = mir_a2u(dbv.pszVal);
- if (FindMatchT(value, fi->search, fi->options)) {
+ if (FindMatchW(value, fi->search, fi->options)) {
foundCount++;
ptrW ptr;
wchar_t *newValue = value;
int flag = F_SETVAL;
if (fi->replace) {
- newValue = (fi->options & F_ENTIRE) ? fi->replace : ptr = multiReplaceT(value, fi->search, fi->replace, fi->options & F_CASE);
+ newValue = (fi->options & F_ENTIRE) ? fi->replace : ptr = multiReplaceW(value, fi->search, fi->replace, fi->options & F_CASE);
// !!!! delete or make empty ?
if (!newValue[0]) {
db_unset(hContact, module->name, setting->name);
@@ -477,12 +458,10 @@ void __cdecl FindSettings(LPVOID param)
deleteCount++;
}
else {
-#ifdef _UNICODE
// save as unicode if needed
if (dbv.type != DBVT_ASCIIZ || IsRealUnicode(newValue))
db_set_ws(hContact, module->name, setting->name, newValue);
else
-#endif
db_set_s(hContact, module->name, setting->name, _T2A(newValue));
flag |= F_REPLACED;
replaceCount++;
diff --git a/plugins/DbEditorPP/src/main.cpp b/plugins/DbEditorPP/src/main.cpp
index b2219577f8..17dac20404 100644
--- a/plugins/DbEditorPP/src/main.cpp
+++ b/plugins/DbEditorPP/src/main.cpp
@@ -105,8 +105,6 @@ static int OnTTBLoaded(WPARAM, LPARAM)
static int ModulesLoaded(WPARAM, LPARAM)
{
- IcoLibRegister();
-
// Register menu item
CMenuItem mi(&g_plugin);
mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000);
@@ -136,20 +134,7 @@ static int ModulesLoaded(WPARAM, LPARAM)
g_bUsePopups = g_plugin.getByte("UsePopUps", 0) != 0;
- // Load the name order
- for (int i = 0; i < NAMEORDERCOUNT; i++)
- nameOrder[i] = i;
-
- DBVARIANT dbv = {};
- if (!db_get_s(0, "Contact", "NameOrder", &dbv, DBVT_BLOB)) {
- memcpy(nameOrder, dbv.pbVal, dbv.cpbVal);
- db_free(&dbv);
- }
-
HookEvent(ME_TTB_MODULELOADED, OnTTBLoaded);
-
- if (g_bServiceMode)
- CallService("DBEditorpp/MenuCommand", 0, 0);
return 0;
}
@@ -164,8 +149,8 @@ static INT_PTR ServiceMode(WPARAM, LPARAM)
{
g_bServiceMode = true;
- IcoLibRegister();
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged);
+ DBEditorppMenuCommand(0, 0);
return SERVICE_ONLYDB; // load database and then call us
}
@@ -183,6 +168,8 @@ int CMPlugin::Load()
hRestore = NULL;
g_db = db_get_current();
+ IcoLibRegister();
+
HookEvent(ME_DB_CONTACT_SETTINGCHANGED, DBSettingChanged);
HookEvent(ME_OPT_INITIALISE, OptInit);
HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);
@@ -199,361 +186,23 @@ int CMPlugin::Load()
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-int CMPlugin::Unload()
-{
- freeAllWatches();
- return 0;
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-char *StringFromBlob(BYTE *blob, WORD len)
-{
- int j;
- char tmp[16];
-
- char *data = (char*)mir_alloc(3 * (len + 2));
- data[0] = 0;
-
- for (j = 0; j < len; j++) {
- mir_snprintf(tmp, "%02X ", blob[j]);
- mir_strcat(data, tmp);
- }
- return data;
-}
-
-int WriteBlobFromString(MCONTACT hContact, const char *szModule, const char *szSetting, const char *szValue, int len)
-{
- int j = 0, i = 0;
- BYTE b;
- int tmp, res = 0;
- BYTE *data = (BYTE*)mir_alloc(2 + len / 2);
-
- if (!data)
- return 0;
-
- while (j < len) {
- b = szValue[j];
-
- if ((b >= '0' && b <= '9') ||
- (b >= 'A' && b <= 'F') ||
- (b >= 'a' && b <= 'f')) {
- if (sscanf(&szValue[j], "%02X", &tmp) == 1) {
- data[i++] = (BYTE)(tmp & 0xFF);
- j++;
- }
- }
- j++;
- }
-
-
- if (i)
- res = !db_set_blob(hContact, szModule, szSetting, data, (WORD)i);
-
- mir_free(data);
- return res;
-}
-
-wchar_t *DBVType(BYTE type)
-{
- switch (type) {
- case DBVT_BYTE: return L"BYTE";
- case DBVT_WORD: return L"WORD";
- case DBVT_DWORD: return L"DWORD";
- case DBVT_ASCIIZ: return L"STRING";
- case DBVT_WCHAR:
- case DBVT_UTF8: return L"UNICODE";
- case DBVT_BLOB: return L"BLOB";
- case DBVT_DELETED: return L"DELETED";
- }
- return L"";
-}
-
-DWORD getNumericValue(DBVARIANT *dbv)
-{
- switch (dbv->type) {
- case DBVT_DWORD:
- return dbv->dVal;
- case DBVT_WORD:
- return dbv->wVal;
- case DBVT_BYTE:
- return dbv->bVal;
- }
- return 0;
-}
-
-int setNumericValue(MCONTACT hContact, const char *module, const char *setting, DWORD value, int type)
-{
- switch (type) {
- case DBVT_BYTE:
- if (value <= 0xFF)
- return !db_set_b(hContact, module, setting, (BYTE)value);
- break;
-
- case DBVT_WORD:
- if (value <= 0xFFFF)
- return !db_set_w(hContact, module, setting, (WORD)value);
- break;
-
- case DBVT_DWORD:
- return !db_set_dw(hContact, module, setting, value);
- }
- return 0;
-}
-
-int IsRealUnicode(wchar_t *value)
-{
- BOOL nonascii = 0;
- WideCharToMultiByte(Langpack_GetDefaultCodePage(), WC_NO_BEST_FIT_CHARS, value, -1, nullptr, 0, nullptr, &nonascii);
- return nonascii;
-}
-
-int setTextValue(MCONTACT hContact, const char *module, const char *setting, wchar_t *value, int type)
-{
-#ifdef _UNICODE
- if (type == DBVT_UTF8 || type == DBVT_WCHAR)
- return !db_set_ws(hContact, module, setting, value);
-
- if (type == DBVT_ASCIIZ && IsRealUnicode(value))
- return 0;
-#endif
- return !db_set_s(hContact, module, setting, _T2A(value));
-}
-
-int GetValueA(MCONTACT hContact, const char *module, const char *setting, char *value, int length)
-{
- DBVARIANT dbv = {};
-
- if (!module || !setting || !value)
- return 0;
-
- if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) {
- switch (dbv.type) {
-
- case DBVT_ASCIIZ:
- mir_strncpy(value, dbv.pszVal, length);
- break;
-
- case DBVT_DWORD:
- case DBVT_WORD:
- case DBVT_BYTE:
- _ultoa(getNumericValue(&dbv), value, 10);
- break;
-
- case DBVT_WCHAR:
- mir_strncpy(value, ptrA(mir_u2a(dbv.pwszVal)), length);
- break;
-
- case DBVT_UTF8:
- mir_strncpy(value, ptrA(mir_utf8decodeA(dbv.pszVal)), length);
- break;
-
- case DBVT_DELETED:
- value[0] = 0;
- return 0;
- }
-
- int type = dbv.type;
- db_free(&dbv);
- return type;
- }
-
- value[0] = 0;
- return 0;
-}
+ // Load the name order
+ for (int i = 0; i < NAMEORDERCOUNT; i++)
+ nameOrder[i] = i;
-int GetValueW(MCONTACT hContact, const char *module, const char *setting, WCHAR *value, int length)
-{
DBVARIANT dbv = {};
-
- if (!module || !setting || !value)
- return 0;
-
- if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) {
- switch (dbv.type) {
-
- case DBVT_ASCIIZ:
- mir_wstrncpy(value, ptrW(mir_a2u(dbv.pszVal)), length);
- break;
-
- case DBVT_DWORD:
- case DBVT_WORD:
- case DBVT_BYTE:
- _ultow(getNumericValue(&dbv), value, 10);
- break;
-
- case DBVT_WCHAR:
- mir_wstrncpy(value, dbv.pwszVal, length);
- break;
-
- case DBVT_UTF8:
- mir_wstrncpy(value, ptrW(mir_utf8decodeW(dbv.pszVal)), length);
- break;
-
- case DBVT_DELETED:
- value[0] = 0;
- return 0;
- }
-
- int type = dbv.type;
+ if (!db_get_s(0, "Contact", "NameOrder", &dbv, DBVT_BLOB)) {
+ memcpy(nameOrder, dbv.pbVal, dbv.cpbVal);
db_free(&dbv);
- return type;
}
- value[0] = 0;
return 0;
}
-int GetContactName(MCONTACT hContact, const char *proto, wchar_t *value, int maxlen)
-{
- if (!value)
- return 0;
-
- if (!hContact) {
- mir_wstrncpy(value, TranslateT("Settings"), maxlen);
- return 1;
- }
-
- char *szProto = (char*)proto;
- char tmp[FLD_SIZE];
- wchar_t name[NAME_SIZE]; name[0] = 0;
-
- if (hContact && (!proto || !proto[0]))
- if (!db_get_static(hContact, "Protocol", "p", tmp, _countof(tmp)))
- szProto = tmp;
-
- for (int i = 0; i < NAMEORDERCOUNT - 1; i++) {
- switch (nameOrder[i]) {
- case 0: // custom name
- GetValue(hContact, "CList", "MyHandle", name, _countof(name));
- break;
-
- case 1: // nick
- if (!szProto) break;
- GetValue(hContact, szProto, "Nick", name, _countof(name));
- break;
-
- case 2: // First Name
- // if (!szProto) break;
- // GetValue(hContact, szProto, "FirstName", name, _countof(name));
- break;
-
- case 3: // E-mail
- if (!szProto) break;
- GetValue(hContact, szProto, "e-mail", name, _countof(name));
- break;
-
- case 4: // Last Name
- // GetValue(hContact, szProto, "LastName", name, _countof(name));
- break;
-
- case 5: // Unique id
- if (szProto) {
- // protocol must define a PFLAG_UNIQUEIDSETTING
- const char *uid = Proto_GetUniqueId(szProto);
- if (uid)
- GetValue(hContact, szProto, uid, name, _countof(name));
- }
- break;
-
- case 6: // first + last name
- if (szProto) {
- GetValue(hContact, szProto, "FirstName", name, _countof(name));
-
- int len = (int)mir_wstrlen(name);
- if (len + 2 < _countof(name)) {
- if (len)
- mir_wstrncat(name, L" ", _countof(name));
- len++;
- GetValue(hContact, szProto, "LastName", &name[len], _countof(name) - len);
- }
- }
- break;
- }
-
- if (name[0])
- break;
- }
-
- if (!name[0])
- mir_wstrncpy(name, TranslateT("<UNKNOWN>"), _countof(name));
-
- if (szProto && szProto[0]) {
- if (g_Order)
- mir_snwprintf(value, maxlen, L"(%S) %s", szProto, name);
- else
- mir_snwprintf(value, maxlen, L"%s (%S)", name, szProto);
- }
- else mir_wstrncpy(value, name, maxlen);
-
- PROTOACCOUNT *pa = Proto_GetAccount(szProto);
- if (!pa->IsEnabled()) {
- mir_wstrncat(value, L" ", maxlen);
- mir_wstrncat(value, TranslateT("[UNLOADED]"), maxlen);
- }
-
- return 1;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
-int ApplyProtoFilter(MCONTACT hContact)
+int CMPlugin::Unload()
{
- if (g_Mode == MODE_ALL) return 0;
-
- int loaded = 0;
- char szProto[FLD_SIZE];
-
- if (!db_get_static(hContact, "Protocol", "p", szProto, _countof(szProto)))
- loaded = Proto_GetAccount(szProto) ? 1 : 0;
-
- if ((loaded && g_Mode == MODE_UNLOADED) || (!loaded && g_Mode == MODE_LOADED))
- return 1;
-
+ freeAllWatches();
return 0;
}
-
-void loadListSettings(HWND hwnd, ColumnsSettings *cs)
-{
- LVCOLUMN sLC = {};
- sLC.fmt = LVCFMT_LEFT;
- sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
- int i = 0;
- while (cs[i].name) {
- sLC.pszText = TranslateW(cs[i].name);
- sLC.cx = g_plugin.getWord(cs[i].dbname, cs[i].defsize);
- ListView_InsertColumn(hwnd, cs[i].index, &sLC);
- i++;
- }
-}
-
-void saveListSettings(HWND hwnd, ColumnsSettings *cs)
-{
- char tmp[FLD_SIZE];
- LVCOLUMN sLC = {};
- sLC.mask = LVCF_WIDTH;
- int i = 0;
- while (cs[i].name) {
- if (ListView_GetColumn(hwnd, cs[i].index, &sLC)) {
- mir_snprintf(tmp, cs[i].dbname, i);
- g_plugin.setWord(tmp, (WORD)sLC.cx);
- }
- i++;
- }
-}
-
-INT_PTR CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
-{
- ColumnsSortParams params = *(ColumnsSortParams *)myParam;
- const int maxSize = 1024;
- wchar_t text1[maxSize];
- wchar_t text2[maxSize];
- ListView_GetItemText(params.hList, lParam1, params.column, text1, _countof(text1));
- ListView_GetItemText(params.hList, lParam2, params.column, text2, _countof(text2));
-
- int res = mir_wstrcmpi(text1, text2);
- return (params.column == params.last) ? -res : res;
-}
diff --git a/plugins/DbEditorPP/src/stdafx.h b/plugins/DbEditorPP/src/stdafx.h
index 048e49168f..85d47b9edd 100644
--- a/plugins/DbEditorPP/src/stdafx.h
+++ b/plugins/DbEditorPP/src/stdafx.h
@@ -204,13 +204,7 @@ extern bool g_bUsePopups;
#define HEX_WORD 2
#define HEX_DWORD 4
-#ifdef _UNICODE
-#define GetValue(a,b,c,d,e) GetValueW(a,b,c,d,e)
-#else
-#define GetValue(a,b,c,d,e) GetValueA(a,b,c,d,e)
-#endif
-
-//main
+// 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);
diff --git a/plugins/DbEditorPP/src/utils.cpp b/plugins/DbEditorPP/src/utils.cpp
new file mode 100644
index 0000000000..7861e66266
--- /dev/null
+++ b/plugins/DbEditorPP/src/utils.cpp
@@ -0,0 +1,367 @@
+/*
+Copyright (C) 2012-21 Miranda NG team (https://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+extern BYTE nameOrder[NAMEORDERCOUNT];
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+char* StringFromBlob(BYTE *blob, WORD len)
+{
+ int j;
+ char tmp[16];
+
+ char *data = (char*)mir_alloc(3 * (len + 2));
+ data[0] = 0;
+
+ for (j = 0; j < len; j++) {
+ mir_snprintf(tmp, "%02X ", blob[j]);
+ mir_strcat(data, tmp);
+ }
+ return data;
+}
+
+int WriteBlobFromString(MCONTACT hContact, const char *szModule, const char *szSetting, const char *szValue, int len)
+{
+ int j = 0, i = 0;
+ BYTE b;
+ int tmp, res = 0;
+ BYTE *data = (BYTE*)mir_alloc(2 + len / 2);
+
+ if (!data)
+ return 0;
+
+ while (j < len) {
+ b = szValue[j];
+
+ if ((b >= '0' && b <= '9') ||
+ (b >= 'A' && b <= 'F') ||
+ (b >= 'a' && b <= 'f')) {
+ if (sscanf(&szValue[j], "%02X", &tmp) == 1) {
+ data[i++] = (BYTE)(tmp & 0xFF);
+ j++;
+ }
+ }
+ j++;
+ }
+
+
+ if (i)
+ res = !db_set_blob(hContact, szModule, szSetting, data, (WORD)i);
+
+ mir_free(data);
+ return res;
+}
+
+wchar_t* DBVType(BYTE type)
+{
+ switch (type) {
+ case DBVT_BYTE: return L"BYTE";
+ case DBVT_WORD: return L"WORD";
+ case DBVT_DWORD: return L"DWORD";
+ case DBVT_ASCIIZ: return L"STRING";
+ case DBVT_WCHAR:
+ case DBVT_UTF8: return L"UNICODE";
+ case DBVT_BLOB: return L"BLOB";
+ case DBVT_DELETED: return L"DELETED";
+ }
+ return L"";
+}
+
+DWORD getNumericValue(DBVARIANT *dbv)
+{
+ switch (dbv->type) {
+ case DBVT_DWORD:
+ return dbv->dVal;
+ case DBVT_WORD:
+ return dbv->wVal;
+ case DBVT_BYTE:
+ return dbv->bVal;
+ }
+ return 0;
+}
+
+int setNumericValue(MCONTACT hContact, const char *module, const char *setting, DWORD value, int type)
+{
+ switch (type) {
+ case DBVT_BYTE:
+ if (value <= 0xFF)
+ return !db_set_b(hContact, module, setting, (BYTE)value);
+ break;
+
+ case DBVT_WORD:
+ if (value <= 0xFFFF)
+ return !db_set_w(hContact, module, setting, (WORD)value);
+ break;
+
+ case DBVT_DWORD:
+ return !db_set_dw(hContact, module, setting, value);
+ }
+ return 0;
+}
+
+int IsRealUnicode(wchar_t *value)
+{
+ BOOL nonascii = 0;
+ WideCharToMultiByte(Langpack_GetDefaultCodePage(), WC_NO_BEST_FIT_CHARS, value, -1, nullptr, 0, nullptr, &nonascii);
+ return nonascii;
+}
+
+int setTextValue(MCONTACT hContact, const char *module, const char *setting, wchar_t *value, int type)
+{
+ if (type == DBVT_UTF8 || type == DBVT_WCHAR)
+ return !db_set_ws(hContact, module, setting, value);
+
+ if (type == DBVT_ASCIIZ && IsRealUnicode(value))
+ return 0;
+
+ return !db_set_s(hContact, module, setting, _T2A(value));
+}
+
+int GetValueA(MCONTACT hContact, const char *module, const char *setting, char *value, int length)
+{
+ DBVARIANT dbv = {};
+
+ if (!module || !setting || !value)
+ return 0;
+
+ if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) {
+ switch (dbv.type) {
+
+ case DBVT_ASCIIZ:
+ mir_strncpy(value, dbv.pszVal, length);
+ break;
+
+ case DBVT_DWORD:
+ case DBVT_WORD:
+ case DBVT_BYTE:
+ _ultoa(getNumericValue(&dbv), value, 10);
+ break;
+
+ case DBVT_WCHAR:
+ mir_strncpy(value, ptrA(mir_u2a(dbv.pwszVal)), length);
+ break;
+
+ case DBVT_UTF8:
+ mir_strncpy(value, ptrA(mir_utf8decodeA(dbv.pszVal)), length);
+ break;
+
+ case DBVT_DELETED:
+ value[0] = 0;
+ return 0;
+ }
+
+ int type = dbv.type;
+ db_free(&dbv);
+ return type;
+ }
+
+ value[0] = 0;
+ return 0;
+}
+
+int GetValueW(MCONTACT hContact, const char *module, const char *setting, WCHAR *value, int length)
+{
+ DBVARIANT dbv = {};
+
+ if (!module || !setting || !value)
+ return 0;
+
+ if (length >= 10 && !db_get_s(hContact, module, setting, &dbv, 0)) {
+ switch (dbv.type) {
+
+ case DBVT_ASCIIZ:
+ mir_wstrncpy(value, ptrW(mir_a2u(dbv.pszVal)), length);
+ break;
+
+ case DBVT_DWORD:
+ case DBVT_WORD:
+ case DBVT_BYTE:
+ _ultow(getNumericValue(&dbv), value, 10);
+ break;
+
+ case DBVT_WCHAR:
+ mir_wstrncpy(value, dbv.pwszVal, length);
+ break;
+
+ case DBVT_UTF8:
+ mir_wstrncpy(value, ptrW(mir_utf8decodeW(dbv.pszVal)), length);
+ break;
+
+ case DBVT_DELETED:
+ value[0] = 0;
+ return 0;
+ }
+
+ int type = dbv.type;
+ db_free(&dbv);
+ return type;
+ }
+
+ value[0] = 0;
+ return 0;
+}
+
+int GetContactName(MCONTACT hContact, const char *proto, wchar_t *value, int maxlen)
+{
+ if (!value)
+ return 0;
+
+ if (!hContact) {
+ mir_wstrncpy(value, TranslateT("Settings"), maxlen);
+ return 1;
+ }
+
+ char *szProto = (char*)proto;
+ char tmp[FLD_SIZE];
+ wchar_t name[NAME_SIZE]; name[0] = 0;
+
+ if (hContact && (!proto || !proto[0]))
+ if (!db_get_static(hContact, "Protocol", "p", tmp, _countof(tmp)))
+ szProto = tmp;
+
+ for (int i = 0; i < NAMEORDERCOUNT - 1; i++) {
+ switch (nameOrder[i]) {
+ case 0: // custom name
+ GetValueW(hContact, "CList", "MyHandle", name, _countof(name));
+ break;
+
+ case 1: // nick
+ if (!szProto) break;
+ GetValueW(hContact, szProto, "Nick", name, _countof(name));
+ break;
+
+ case 2: // First Name
+ // if (!szProto) break;
+ // GetValueW(hContact, szProto, "FirstName", name, _countof(name));
+ break;
+
+ case 3: // E-mail
+ if (!szProto) break;
+ GetValueW(hContact, szProto, "e-mail", name, _countof(name));
+ break;
+
+ case 4: // Last Name
+ // GetValueW(hContact, szProto, "LastName", name, _countof(name));
+ break;
+
+ case 5: // Unique id
+ if (szProto) {
+ // protocol must define a PFLAG_UNIQUEIDSETTING
+ const char *uid = Proto_GetUniqueId(szProto);
+ if (uid)
+ GetValueW(hContact, szProto, uid, name, _countof(name));
+ }
+ break;
+
+ case 6: // first + last name
+ if (szProto) {
+ GetValueW(hContact, szProto, "FirstName", name, _countof(name));
+
+ int len = (int)mir_wstrlen(name);
+ if (len + 2 < _countof(name)) {
+ if (len)
+ mir_wstrncat(name, L" ", _countof(name));
+ len++;
+ GetValueW(hContact, szProto, "LastName", &name[len], _countof(name) - len);
+ }
+ }
+ break;
+ }
+
+ if (name[0])
+ break;
+ }
+
+ if (!name[0])
+ mir_wstrncpy(name, TranslateT("<UNKNOWN>"), _countof(name));
+
+ if (szProto && szProto[0]) {
+ if (g_Order)
+ mir_snwprintf(value, maxlen, L"(%S) %s", szProto, name);
+ else
+ mir_snwprintf(value, maxlen, L"%s (%S)", name, szProto);
+ }
+ else mir_wstrncpy(value, name, maxlen);
+
+ PROTOACCOUNT *pa = Proto_GetAccount(szProto);
+ if (!pa->IsEnabled()) {
+ mir_wstrncat(value, L" ", maxlen);
+ mir_wstrncat(value, TranslateT("[UNLOADED]"), maxlen);
+ }
+
+ return 1;
+}
+
+int ApplyProtoFilter(MCONTACT hContact)
+{
+ if (g_Mode == MODE_ALL) return 0;
+
+ int loaded = 0;
+ char szProto[FLD_SIZE];
+
+ if (!db_get_static(hContact, "Protocol", "p", szProto, _countof(szProto)))
+ loaded = Proto_GetAccount(szProto) ? 1 : 0;
+
+ if ((loaded && g_Mode == MODE_UNLOADED) || (!loaded && g_Mode == MODE_LOADED))
+ return 1;
+
+ return 0;
+}
+
+void loadListSettings(HWND hwnd, ColumnsSettings *cs)
+{
+ LVCOLUMN sLC = {};
+ sLC.fmt = LVCFMT_LEFT;
+ sLC.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
+ int i = 0;
+ while (cs[i].name) {
+ sLC.pszText = TranslateW(cs[i].name);
+ sLC.cx = g_plugin.getWord(cs[i].dbname, cs[i].defsize);
+ ListView_InsertColumn(hwnd, cs[i].index, &sLC);
+ i++;
+ }
+}
+
+void saveListSettings(HWND hwnd, ColumnsSettings *cs)
+{
+ char tmp[FLD_SIZE];
+ LVCOLUMN sLC = {};
+ sLC.mask = LVCF_WIDTH;
+ int i = 0;
+ while (cs[i].name) {
+ if (ListView_GetColumn(hwnd, cs[i].index, &sLC)) {
+ mir_snprintf(tmp, cs[i].dbname, i);
+ g_plugin.setWord(tmp, (WORD)sLC.cx);
+ }
+ i++;
+ }
+}
+
+INT_PTR CALLBACK ColumnsCompare(LPARAM lParam1, LPARAM lParam2, LPARAM myParam)
+{
+ ColumnsSortParams params = *(ColumnsSortParams *)myParam;
+ const int maxSize = 1024;
+ wchar_t text1[maxSize];
+ wchar_t text2[maxSize];
+ ListView_GetItemText(params.hList, lParam1, params.column, text1, _countof(text1));
+ ListView_GetItemText(params.hList, lParam2, params.column, text2, _countof(text2));
+
+ int res = mir_wstrcmpi(text1, text2);
+ return (params.column == params.last) ? -res : res;
+}
diff --git a/plugins/DbEditorPP/src/version.h b/plugins/DbEditorPP/src/version.h
index bad0fea593..f731cc7a12 100644
--- a/plugins/DbEditorPP/src/version.h
+++ b/plugins/DbEditorPP/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 4
#define __MINOR_VERSION 0
-#define __RELEASE_NUM 1
-#define __BUILD_NUM 4
+#define __RELEASE_NUM 2
+#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/plugins/DbEditorPP/src/watchedvars.cpp b/plugins/DbEditorPP/src/watchedvars.cpp
index 47270f09c6..85cb2cac5e 100644
--- a/plugins/DbEditorPP/src/watchedvars.cpp
+++ b/plugins/DbEditorPP/src/watchedvars.cpp
@@ -339,13 +339,12 @@ void openWatchedVarWindow()
SetForegroundWindow(hwnd2watchedVarsWindow);
}
-
void popupWatchedVar(MCONTACT hContact, const char *module, const char *setting)
{
int timeout = g_plugin.iPopupDelay;
wchar_t value[MAX_SECONDLINE];
- int type = GetValue(hContact, module, setting, value, _countof(value));
+ int type = GetValueW(hContact, module, setting, value, _countof(value));
POPUPDATAW ppd;
GetContactName(hContact, nullptr, ppd.lpwzContactName, _countof(ppd.lpwzContactName));