diff options
author | mataes2007 <mataes2007@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb> | 2011-04-28 12:14:32 +0000 |
---|---|---|
committer | mataes2007 <mataes2007@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb> | 2011-04-28 12:14:32 +0000 |
commit | bed6bee936ff79d32c08245f0fedaee9d839f76f (patch) | |
tree | fd32ed9cb9241b2c6387b87eb0412e5e5d2ff7c5 /dbeditorpp/main.c | |
parent | 0a1ada17c01b0c517995b095eb43bb23c5b3c6f1 (diff) |
test rename
git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@64 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb
Diffstat (limited to 'dbeditorpp/main.c')
-rw-r--r-- | dbeditorpp/main.c | 918 |
1 files changed, 0 insertions, 918 deletions
diff --git a/dbeditorpp/main.c b/dbeditorpp/main.c deleted file mode 100644 index e5a0060..0000000 --- a/dbeditorpp/main.c +++ /dev/null @@ -1,918 +0,0 @@ -#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}}
-
-
-
-HANDLE hTTBButt = NULL;
-DWORD mirandaVer;
-BOOL bServiceMode = FALSE;
-
-//========================
-// 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",
- UNICODE_AWARE,
- 0,
- MIID_DBEDITOR
-};
-
-
-__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
-{
- mirandaVer = mirandaVersion;
- return &pluginInfoEx;
-}
-
-// we implement service mode interface
-static const MUUID interfaces[] = {MIID_SERVICEMODE, MIID_LAST};
-__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
-{
- return interfaces;
-}
-
-
-//========================
-// WINAPI DllMain
-//========================
-
-BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
-{
- hInst=hinstDLL;
- return TRUE;
-}
-
-//===================
-// MainInit
-//===================
-
-int MainInit(WPARAM wParam,LPARAM lParam)
-{
- return 0;
-}
-
-void settingChanged(HWND hwnd2Settings, HANDLE hContact, char* module, char* setting);
-
-int DBSettingChanged(WPARAM wParam,LPARAM lParam)
-{
- DBCONTACTWRITESETTING *cws=(DBCONTACTWRITESETTING*)lParam;
- HANDLE hContact = (HANDLE)wParam;
- char *setting;
- int i;
- SettingListInfo* info;
-
- if (hwnd2mainWindow)
- {
- HWND hwnd2Settings = GetDlgItem(hwnd2mainWindow, IDC_SETTINGS);
- if (info = (SettingListInfo*)GetWindowLong(hwnd2Settings,GWL_USERDATA))
- {
- if ((hContact == info->hContact) && !mir_strcmp(info->module, cws->szModule))
- {
- setting = strdup(cws->szSetting);
- if (cws->value.type == DBVT_DELETED)
- {
- LVFINDINFO lvfi;
- int index;
- lvfi.flags = LVFI_STRING;
- lvfi.psz = setting;
- lvfi.vkDirection = VK_DOWN;
- index = ListView_FindItem(hwnd2Settings,-1,&lvfi);
- if (index > -1)
- ListView_DeleteItem(hwnd2Settings, index);
- safe_free(setting);
- return 0;
- }
- settingChanged(hwnd2Settings, hContact, info->module, setting);
- safe_free(setting);
- }
- }
- }
- // watch list
- if (!hwnd2watchedVarsWindow && !usePopUps) return 0;
-
- for (i=0; i<WatchListArray.count; i++)
- {
- if (WatchListArray.item[i].module && (hContact == WatchListArray.item[i].hContact) )
- {
- if (!mir_strcmp(cws->szModule, WatchListArray.item[i].module))
- {
- if (!WatchListArray.item[i].setting || !mir_strcmp(cws->szSetting, WatchListArray.item[i].setting))
- {
- if (usePopUps)
- popupWatchedVar(hContact,cws->szModule, cws->szSetting);
- if (hwnd2watchedVarsWindow)
- PopulateWatchedWindow(GetDlgItem(hwnd2watchedVarsWindow, IDC_VARS));
- break;
- }
- }
- }
- }
- return 0;
-}
-
-static int 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);
- }
- else
- {
- ShowWindow(hwnd2mainWindow, SW_RESTORE);
- SetForegroundWindow(hwnd2mainWindow);
- if (!hRestore && wParam) {
- hRestore = (HANDLE)wParam;
- refreshTree(4);
- }
- }
-
- if (hTTBButt)
- CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hTTBButt, (LPARAM)(TTBST_RELEASED));
-
- return 0;
-}
-
-
-BOOL IsCP_UTF8(void)
-{
- CPINFO CPInfo;
-
- 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)
-{
- TTBButtonV2 ttbb = {0};
- HICON ico = LoadIcon(hInst,MAKEINTRESOURCE(ICO_DBE_BUTT));
- UnhookEvent(hTTBHook);
-
- ttbb.cbSize = sizeof(ttbb);
- ttbb.dwFlags=TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP;
- ttbb.pszServiceDown = "DBEditorpp/MenuCommand";
- ttbb.name = Translate("Database Editor++");
- ttbb.hIconUp = ico;
- ttbb.hIconDn = ico;
-// ttbb.tooltipDn = Translate("Show DataBase Editor");
-
- hTTBButt = (HANDLE)CallService(MS_TTB_ADDBUTTON, (WPARAM)&ttbb, 0);
-
- if (hTTBButt)
- CallService(MS_TTB_SETBUTTONOPTIONS,MAKEWPARAM(TTBO_TIPNAME,hTTBButt),
- (LPARAM)(Translate("Show DataBase Editor")));
-
- return 0;
-}
-
-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 *mods;
- char mod[64] = "";
- char szModuleFileName[MAX_PATH];
- int i=0, len;
- if (!DBGetContactSetting(NULL,modname,"CoreModules",&dbv) && dbv.type == DBVT_ASCIIZ)
- mods = dbv.pszVal;
- else
- {
- DBWriteContactSettingString(NULL,modname,"CoreModules",coreMods);
- mods = coreMods;
- }
-
- len=strlen(mods);
- while (i<len)
- {
- if (mods[i] == '\\' && mods[i+1] == ' ')
- {
- strcat(mod," ");
- i++;
- }
- else if (mods[i] == ' ' || mods[i] == ',' || mods[i] == '\r' || mods[i] == '\n'|| mods[i] == '\0')
- {
- if (mod[0])
- CallService("DBEditorpp/RegisterSingleModule",(WPARAM)mod,0);
- mod[0] = '\0';
- }
- else strncat(mod,&mods[i],1);
- i++;
- }
- if (mod[0]) CallService("DBEditorpp/RegisterSingleModule",(WPARAM)mod,0);
-
- doOldKnownModulesList(); // add the old plugins which havnt been changed over yet..
-
- // icons
- if (GetModuleFileName(hInst,szModuleFileName,MAX_PATH) && ServiceExists(MS_SKIN2_ADDICON))
- {
- UsingIconManager =1;
- addIcons(szModuleFileName);
- }
- else
- UsingIconManager = 0;
-
- DBFreeVariant(&dbv);
- UnhookEvent(hModulesLoadedHook);
-
- usePopUps = DBGetContactSettingByte(NULL,modname,"UsePopUps",0);
-
- // Load the name order
- for(i=0;i<NAMEORDERCOUNT;i++) nameOrder[i]=i;
-
- if(!DBGetContactSetting(NULL,"Contact","NameOrder",&dbv))
- {
- CopyMemory(nameOrder,dbv.pbVal,dbv.cpbVal);
- DBFreeVariant(&dbv);
- }
-
- // check DB engine for unicode support
- UDB = FALSE;
-
- if (ServiceExists(MS_DB_CONTACT_GETSETTING_STR))
- {
- DBCONTACTGETSETTING cgs;
- dbv.type = 0;
-
- if (DBGetContactSettingByte(NULL,modname,"WarnOnDelete",-1) == -1)
- DBWriteContactSettingByte(NULL,modname,"WarnOnDelete",1);
-
- cgs.szModule=modname;
- cgs.szSetting="WarnOnDelete";
- cgs.pValue=&dbv;
-
- if (!CallService(MS_DB_CONTACT_GETSETTING_STR, 0,(LPARAM)&cgs))
- if (dbv.type == DBVT_BYTE)
- UDB = TRUE;
-
- }
-
- // check OS support for unicode
- // useless if DB doesnt not support unicode
- UOS = (UDB && IsCP_UTF8() && InitWFuctions() && IsWinVerNT());
-
- // updater support
- {
- Update update = {0};
- char szVersion[16];
-
- update.cbSize = sizeof(Update);
-
- update.szComponentName = pluginInfo.shortName;
- update.pbVersion = (BYTE *)CreateVersionStringPlugin(&pluginInfo, szVersion);
- update.cpbVersion = 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";
-
- update.szBetaVersionURL = "http://forums.miranda-im.org/showpost.php?p=38051&postcount=1";
- update.szBetaUpdateURL = "http://etplanet.com/bio/miranda/archive/other/dbeditorpp.dll";
-
- CallService(MS_UPDATE_REGISTER, 0, (WPARAM)&update);
- }
-
- hTTBHook = HookEvent(ME_TTB_MODULELOADED, OnTTBLoaded);
-
- if ( bServiceMode ) {
- CallService("DBEditorpp/MenuCommand",0,0);
- }
-
- return 0;
-}
-
-HANDLE hHookedEvents[4] = {0};
-
-
-int PreShutdown(WPARAM wParam,LPARAM lParam)
-{
- int i;
-
- if (hwnd2watchedVarsWindow) DestroyWindow(hwnd2watchedVarsWindow);
- if (hwnd2mainWindow) DestroyWindow(hwnd2mainWindow);
- if (hwnd2importWindow) DestroyWindow(hwnd2importWindow);
-
- for(i=0;i<SIZEOF(hHookedEvents);i++)
- {
- if (hHookedEvents[i]) UnhookEvent(hHookedEvents[i]);
- }
-
- return 0;
-}
-
-int ServiceMode(WPARAM wParam,LPARAM lParam) {
- bServiceMode = TRUE;
- return 0;
-}
-
-
-int __declspec(dllexport) Load(PLUGINLINK *link)
-{
- CLISTMENUITEM mi;
-/*
- #ifndef NDEBUG //mem leak detector :-) Thanks Tornado!
- int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // Get current flag
- flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
- _CrtSetDbgFlag(flag); // Set flag to the new value
- #endif
-*/
- pluginLink = link;
-
- if (mirandaVer < PLUGIN_MAKE_VERSION(0,7,0,0))
- return -1;
-
-
- hwnd2mainWindow = 0;
- hwnd2watchedVarsWindow = 0;
- hwnd2importWindow = 0;
- hRestore = NULL;
- hHookedEvents[0] = HookEvent(ME_DB_CONTACT_SETTINGCHANGED,DBSettingChanged);
- hHookedEvents[1] = HookEvent(ME_OPT_INITIALISE,OptInit);
-// 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);
- ZeroMemory(&mi,sizeof(mi));
- mi.cbSize=sizeof(mi);
- mi.position=1900000001;
- mi.flags=0;
- mi.hIcon=LoadIcon(hInst,MAKEINTRESOURCE(ICO_REGEDIT));
- mi.pszName=modFullname;
- mi.pszService="DBEditorpp/MenuCommand";
- mi.pszContactOwner=NULL;
- CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi);
-
- ZeroMemory(&mi,sizeof(mi));
- mi.cbSize=sizeof(mi);
- mi.position=1900000001;
- mi.flags=DBGetContactSettingByte(NULL,modname,"UserMenuItem",1)?0:CMIF_HIDDEN;
- mi.hIcon=LoadIcon(hInst,MAKEINTRESOURCE(ICO_REGUSER));
- mi.pszName=Translate("Open user tree in DBE++");
- mi.pszService="DBEditorpp/MenuCommand";
- mi.pszContactOwner=NULL;
- hUserMenu = (HANDLE) CallService(MS_CLIST_ADDCONTACTMENUITEM, 0, (LPARAM) & mi);
-
- hHookedEvents[3] = CreateServiceFunction(MS_SERVICEMODE_LAUNCH, ServiceMode);
-
- CallService("DBEditorpp/RegisterSingleModule",(WPARAM)modname,0);
-
- // Ensure that the common control DLL is loaded.
- {
- INITCOMMONCONTROLSEX icex;
-
- icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
- icex.dwICC = ICC_LISTVIEW_CLASSES;
- InitCommonControlsEx(&icex);
- }
-
- ZeroMemory(&WatchListArray, sizeof(WatchListArray));
-
- return 0;
-}
-
-int __declspec(dllexport) Unload(void)
-{
- FreeKnownModuleList();
- freeAllWatches();
- return 0;
-}
-
-
-
-//=======================================================
-//DBGetContactSettingString (prob shouldnt use this unless u know how big the string is gonna be..)
-//=======================================================
-
-int DBGetContactSettingStringStatic(HANDLE hContact, char* szModule, char* szSetting, char* value, int maxLength)
-{
- DBVARIANT dbv;
- if (!DBGetContactSetting(hContact, szModule, szSetting, &dbv))
- {
- strncpy(value, dbv.pszVal, maxLength);
- DBFreeVariant(&dbv);
- return 1;
- }
- else
- {
- DBFreeVariant(&dbv);
- return 0;
- }
-
- 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;
- BYTE *data = NULL;
- BYTE b;
- int tmp;
-
- if (!(data = (BYTE *)_alloca(2+len/2)))
- {
- msg(Translate("Couldnt allocate enough memory!"), modFullname);
- 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;
- j++;
- }
- }
- j++;
- }
-
- if (i)
- return DBWriteContactSettingBlob(hContact,szModule,szSetting, data, (WORD)i);
-
- return 0;
-}
-
-
-int GetSetting(HANDLE hContact, const char *szModule, const char *szSetting, DBVARIANT *dbv)
-{
- DBCONTACTGETSETTING cgs;
-
- cgs.szModule=szModule;
- cgs.szSetting=szSetting;
- cgs.pValue=dbv;
- dbv->type = 0;
-
- if (UDB)
- return CallService(MS_DB_CONTACT_GETSETTING_STR,(WPARAM)hContact,(LPARAM)&cgs);
- else
- {
- int rr = CallService(MS_DB_CONTACT_GETSETTING,(WPARAM)hContact,(LPARAM)&cgs);
-
- if (dbv->type != DBVT_UTF8)
- return rr;
- else
- return 1;
- }
-}
-
-
-int GetValue(HANDLE hContact, const char* szModule, const char* szSetting, char* Value, int length)
-{
- DBVARIANT dbv = {0};
-
- if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv))
- {
- switch(dbv.type) {
- case DBVT_UTF8:
- if (UOS)
- {
- int len = strlen(dbv.pszVal)+1;
- char *sz = _alloca(len*3);
- WCHAR *wc = _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);
- break;
- }// else fall through
- case DBVT_ASCIIZ:
- strncpy(Value, dbv.pszVal, length);
- break;
- case DBVT_DWORD:
- _itoa(dbv.dVal,Value,10);
- break;
- case DBVT_BYTE:
- _itoa(dbv.bVal,Value,10);
- break;
- case DBVT_WORD:
- _itoa(dbv.wVal,Value,10);
- break;
- }
-
- DBFreeVariant(&dbv);
-
- Value[length-1] = 0;
- return 1;
- }
-
- if (Value)
- Value[0] = 0;
-
- return 0;
-}
-
-
-int GetValueW(HANDLE hContact, const char* szModule, const char* szSetting, WCHAR* Value, int length)
-{
- DBVARIANT dbv ={0};
-
- if (Value && length >= 10 && !GetSetting(hContact, szModule, szSetting, &dbv))
- {
- switch(dbv.type) {
- case DBVT_UTF8:
- {
- int len = strlen(dbv.pszVal)+1;
- WCHAR *wc = _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));
- MultiByteToWideChar(CP_ACP, 0, dbv.pszVal, -1, wc, len);
- wcsncpy((WCHAR*)Value, wc, length);
- }
- break;
- case DBVT_DWORD:
- _itow(dbv.dVal,Value,10);
- break;
- case DBVT_BYTE:
- _itow(dbv.bVal,Value,10);
- break;
- case DBVT_WORD:
- _itow(dbv.wVal,Value,10);
- break;
- }
-
- DBFreeVariant(&dbv);
-
- Value[length-1] = 0;
- return 1;
- }
-
- if (Value)
- Value[0] = 0;
-
- return 0;
-}
-
-
-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);
- if ( result == NULL )
- return NULL;
-
- WideCharToMultiByte( CP_ACP, 0, src, -1, result, cbLen, NULL, NULL );
- result[ cbLen ] = 0;
- return result;
- }
- else
- return NULL;
-}
-
-
-wchar_t *a2u( char* src , wchar_t *buffer, int len )
-{
- wchar_t *result = buffer;
- if ( result == NULL || len < 3)
- return NULL;
-
- MultiByteToWideChar( CP_ACP, 0, src, -1, result, len - 1 );
- result[ len - 1 ] = 0;
-
- 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;
- int len;
-
- va_start(va, fmt);
- len = _vsnwprintf(buffer, count-1, fmt, va);
- va_end(va);
-
- buffer[count-1] = 0;
-
- return len;
-}
-
-
-int GetDatabaseString(HANDLE hContact, const char *szModule, const char* szSetting, WCHAR *Value, int length, BOOL unicode)
-{
- if (unicode)
- return GetValueW(hContact, szModule, szSetting, Value, length);
- else
- return GetValue(hContact, szModule, szSetting, (char*)Value, length);
-}
-
-
-WCHAR *GetContactName(HANDLE hContact, const char *szProto, int unicode)
-{
-
- int i, r = 0;
- static WCHAR res[512];
- char *proto = (char*)szProto;
- char name[256];
-
- if (hContact && !proto)
- {
- if (GetValue(hContact,"Protocol","p",name,sizeof(name)))
- proto = name;
- }
-
- if (proto)
- {
-
- for(i=0;i<NAMEORDERCOUNT-1;i++)
- {
- switch(nameOrder[i]) {
- case 0: // custom name
- {
- r = GetDatabaseString(hContact,"CList","MyHandle",res,SIZEOF(res),unicode);
- break;
- }
- case 1: // nick
- {
- r = GetDatabaseString(hContact,proto,"Nick",res,SIZEOF(res),unicode);
- break;
- }
- case 2: // First Name
- {
- r = GetDatabaseString(hContact,proto,"FirstName",res,SIZEOF(res),unicode);
- break;
- }
- case 3: // E-mail
- {
- r = GetDatabaseString(hContact,proto,"e-mail",res,SIZEOF(res),unicode);
- break;
- }
- case 4: // Last Name
- {
- if (GetDatabaseString(hContact,proto,"LastName",res,SIZEOF(res),unicode))
- break;
- }
- case 5: // Unique id
- {
- // protocol must define a PFLAG_UNIQUEIDSETTING
- char *uid = (char*)CallProtoService(proto,PS_GETCAPS,PFLAG_UNIQUEIDSETTING,0);
- if ((int)uid!=CALLSERVICE_NOTFOUND && uid)
- r = GetDatabaseString(hContact,proto,uid,res,SIZEOF(res),unicode);
- break;
- }
- case 6: // first + last name
- {
- int len = 0;
-
- if (r = GetDatabaseString(hContact,proto,"FirstName",res,SIZEOF(res),unicode))
- {
- if (unicode)
- len = wcslen(res);
- else
- len = strlen((char*)res);
- }
- else
- res[0] = 0;
-
- if (len && len < SIZEOF(res) - 2)
- {
- if (unicode)
- wcscat(res,L" ");
- else
- strcat((char*)res," ");
-
- len++;
- }
-
- if (SIZEOF(res)-len > 1)
- r |= GetDatabaseString(hContact,proto,"LastName",&res[len],SIZEOF(res)-len,unicode);
-
- break;
- }
- }
-
- if (r) return res;
- }
- }
-
- if (unicode)
- return nick_unknownW;
- else
- return (WCHAR*)nick_unknown;
-}
|