From c992cb2fdc11f1cac4bc5cbce26e8e2bb3b57da0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 26 Jun 2012 16:50:14 +0000 Subject: - microkernel addded; - version bumped to 0.92.2 git-svn-id: http://svn.miranda-ng.org/main/trunk@641 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/BasicHistory/zip/iowin32.c | 4 +- plugins/Chat/chat.h | 1 + plugins/Chat/options.cpp | 1 - plugins/Clist_classic/clistopts.cpp | 4 +- plugins/Clist_modern/modern_aniavatars.cpp | 22 +- plugins/Clist_modern/modern_cachefuncs.cpp | 20 +- plugins/Clist_modern/modern_clc.cpp | 2 +- plugins/Clist_modern/modern_clcitems.cpp | 4 +- plugins/Clist_modern/modern_clcmsgs.cpp | 6 +- plugins/Clist_modern/modern_clistsettings.cpp | 10 +- plugins/Clist_modern/modern_commonheaders.cpp | 6 +- plugins/Clist_modern/modern_skinengine.cpp | 40 +- plugins/Clist_modern/modern_toolbar.cpp | 20 +- plugins/Clist_modern/modern_xptheme.cpp | 10 +- plugins/Clist_mw/clc.cpp | 2 +- plugins/Clist_mw/clcidents.cpp | 8 +- plugins/Clist_mw/clistsettings.cpp | 6 +- plugins/Clist_nicer/INCLUDE/clc.h | 3 - plugins/Clist_nicer/SRC/clc.cpp | 4 +- plugins/ContactsPlus/utils.cpp | 12 - plugins/Db3x/dbcontacts.cpp | 18 +- plugins/Db3x/dbsettings.cpp | 22 +- plugins/Db3x_mmap/dbcontacts.cpp | 14 +- plugins/Db3x_mmap/dbmodulechain.cpp | 16 +- plugins/Db3x_mmap/dbsettings.cpp | 28 +- plugins/Db_autobackups/headers.h | 8 +- plugins/Db_autobackups/options.cpp | 1 - plugins/Dbx_mmap_SA/Dbtool/cleaning.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/dbtool.h | 17 - .../Dbtool/dbtool_sa_10.vcxproj.filters | 3 - plugins/Dbx_mmap_SA/Dbtool/encryption.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/finished.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/langpack.cpp | 388 ------------- plugins/Dbx_mmap_SA/Dbtool/main.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/openerror.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/progress.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp | 2 +- plugins/Dbx_mmap_SA/Dbtool/utf.cpp | 376 ------------ plugins/Dbx_mmap_SA/Dbtool/wizard.cpp | 5 +- plugins/Dbx_mmap_SA/commonheaders.h | 3 +- plugins/Dbx_mmap_SA/dialogs.cpp | 2 - plugins/IEView/HTMLBuilder.cpp | 8 +- plugins/IEView/ieview_main.cpp | 1 - plugins/LangMan/common.h | 4 +- plugins/LangMan/options.cpp | 2 - plugins/MirOTR/libgcrypt-1.4.6/cipher/cipher.c | 8 +- plugins/Popup/src/main.cpp | 1 - plugins/SRMM/cmdlist.cpp | 14 +- plugins/SRMM/msgdialog.cpp | 2 +- plugins/SRMM/richutil.cpp | 10 +- plugins/Scriver/msglog.cpp | 2 +- plugins/Scriver/richutil.cpp | 10 +- plugins/Scriver/utils.cpp | 2 +- plugins/SmileyAdd/regexp/WCPattern.cpp | 2 +- plugins/Svc_dbepp/dbeditorpp_10.vcxproj.filters | 3 - plugins/Svc_dbepp/exportimport.cpp | 13 - plugins/Svc_dbepp/headers.h | 3 - plugins/Svc_dbepp/watchedvars.cpp | 47 +- plugins/TabSRMM/chat/message.cpp | 2 +- plugins/TabSRMM/chat/tools.cpp | 4 +- plugins/TabSRMM/include/mim.h | 18 +- plugins/TabSRMM/src/buttonsbar.cpp | 32 +- plugins/TabSRMM/src/globals.cpp | 2 +- plugins/TabSRMM/src/infopanel.cpp | 2 +- plugins/TabSRMM/src/mim.cpp | 42 -- plugins/TabSRMM/src/msgdialog.cpp | 8 +- plugins/TabSRMM/src/sendlater.cpp | 6 +- plugins/TabSRMM/src/sendqueue.cpp | 8 +- plugins/TabSRMM/src/srmm.cpp | 2 +- plugins/TabSRMM/src/themeio.cpp | 12 +- plugins/TabSRMM/src/utils.cpp | 2 +- plugins/TipperYM/mir_smileys.cpp | 12 +- plugins/UserInfoEx/classMTime.cpp | 5 +- plugins/UserInfoEx/commonheaders.cpp | 1 - plugins/UserInfoEx/init.cpp | 1 + plugins/Variables/tokenregister.cpp | 10 +- plugins/helpers/gen_helpers.cpp | 134 ----- plugins/helpers/gen_helpers.h | 4 - plugins/mir_core/commonheaders.cpp | 2 + plugins/mir_core/commonheaders.h | 63 ++ plugins/mir_core/langpack.cpp | 630 ++++++++++++++++++++ plugins/mir_core/lists.cpp | 278 +++++++++ plugins/mir_core/memory.cpp | 280 +++++++++ plugins/mir_core/mir_core.def | 5 + plugins/mir_core/mir_core_10.vcxproj | 218 +++++++ plugins/mir_core/mir_core_10.vcxproj.filters | 64 ++ plugins/mir_core/miranda.cpp | 398 +++++++++++++ plugins/mir_core/miranda.h | 131 +++++ plugins/mir_core/modules.cpp | 644 +++++++++++++++++++++ plugins/mir_core/path.cpp | 210 +++++++ plugins/mir_core/timezones.cpp | 224 +++++++ plugins/mir_core/utf.cpp | 406 +++++++++++++ plugins/mir_core/utils.cpp | 150 +++++ 95 files changed, 3949 insertions(+), 1297 deletions(-) delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/langpack.cpp create mode 100644 plugins/mir_core/commonheaders.cpp create mode 100644 plugins/mir_core/commonheaders.h create mode 100644 plugins/mir_core/langpack.cpp create mode 100644 plugins/mir_core/lists.cpp create mode 100644 plugins/mir_core/memory.cpp create mode 100644 plugins/mir_core/mir_core.def create mode 100644 plugins/mir_core/mir_core_10.vcxproj create mode 100644 plugins/mir_core/mir_core_10.vcxproj.filters create mode 100644 plugins/mir_core/miranda.cpp create mode 100644 plugins/mir_core/miranda.h create mode 100644 plugins/mir_core/modules.cpp create mode 100644 plugins/mir_core/path.cpp create mode 100644 plugins/mir_core/timezones.cpp create mode 100644 plugins/mir_core/utf.cpp create mode 100644 plugins/mir_core/utils.cpp (limited to 'plugins') diff --git a/plugins/BasicHistory/zip/iowin32.c b/plugins/BasicHistory/zip/iowin32.c index 6a2a883be7..e697b7154d 100644 --- a/plugins/BasicHistory/zip/iowin32.c +++ b/plugins/BasicHistory/zip/iowin32.c @@ -228,7 +228,7 @@ ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) ret = (ZPOS64_T)-1; } else - ret=li.QuadPart; + ret = li.QuadPart; } return ret; } @@ -236,7 +236,7 @@ ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin) { - DWORD dwMoveMethod=0xFFFFFFFF; + DWORD dwMoveMethod = 0xFFFFFFFF; HANDLE hFile = NULL; long ret=-1; diff --git a/plugins/Chat/chat.h b/plugins/Chat/chat.h index ca73960017..b30f741da2 100644 --- a/plugins/Chat/chat.h +++ b/plugins/Chat/chat.h @@ -32,6 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include +#include #include #include #include diff --git a/plugins/Chat/options.cpp b/plugins/Chat/options.cpp index f8def495a0..381054d5ca 100644 --- a/plugins/Chat/options.cpp +++ b/plugins/Chat/options.cpp @@ -20,7 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "resource.h" #include "chat.h" -#include #include diff --git a/plugins/Clist_classic/clistopts.cpp b/plugins/Clist_classic/clistopts.cpp index 9a787df82b..83079d6d75 100644 --- a/plugins/Clist_classic/clistopts.cpp +++ b/plugins/Clist_classic/clistopts.cpp @@ -127,9 +127,9 @@ static INT_PTR CALLBACK DlgProcGenOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LP item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_ADDSTRING, 0, (LPARAM) TranslateT("Global")); SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_SETITEMDATA, item, (LPARAM) 0); for (i = 0; i < count; i++) { - if (!IsAccountEnabled(accs[i]) || CallProtoService( accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) + if (!IsAccountEnabled(accs[i]) || CallProtoService( accs[i]->szModuleName, PS_GETCAPS, PFLAGNUM_2, 0) == 0) continue; - item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_ADDSTRING, 0, (LPARAM) accs[i]->tszAccountName); + item = SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_ADDSTRING, 0, (LPARAM) accs[i]->tszAccountName); SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_SETITEMDATA, item, (LPARAM) accs[i]); if (dbv.type == DBVT_ASCIIZ && !lstrcmpA(dbv.pszVal, accs[i]->szModuleName)) SendDlgItemMessage(hwndDlg, IDC_PRIMARYSTATUS, CB_SETCURSEL, item, 0); diff --git a/plugins/Clist_modern/modern_aniavatars.cpp b/plugins/Clist_modern/modern_aniavatars.cpp index ae57520fa2..9c6dbdcb35 100644 --- a/plugins/Clist_modern/modern_aniavatars.cpp +++ b/plugins/Clist_modern/modern_aniavatars.cpp @@ -209,8 +209,8 @@ int AniAva_InitModule() RegisterClassEx(&wc); } InitializeCriticalSection(&AniAva.CS); - AniAva.Objects=li.List_Create(0,2); - AniAva.AniAvatarList=li.List_Create(0,1); + AniAva.Objects=List_Create(0,2); + AniAva.AniAvatarList=List_Create(0,1); AniAva.AniAvatarList->sortFunc=_AniAva_SortAvatarInfo; AniAva.bModuleStarted=TRUE; AniAva.hExitEvent=CreateEvent(NULL,FALSE,FALSE,NULL); @@ -238,7 +238,7 @@ int AniAva_UnloadModule() } mir_free(AniAva.Objects->items[i]); } - li.List_Destroy(AniAva.Objects); + List_Destroy(AniAva.Objects); mir_free(AniAva.Objects); for (i=0; irealCount; i++) @@ -248,7 +248,7 @@ int AniAva_UnloadModule() if (aai->pFrameDelays) free(aai->pFrameDelays); mir_free(aai); } - li.List_Destroy(AniAva.AniAvatarList); + List_Destroy(AniAva.AniAvatarList); mir_free(AniAva.AniAvatarList); _AniAva_RemoveAniAvaDC(&AniAva); SetEvent(AniAva.hExitEvent); @@ -328,7 +328,7 @@ int AniAva_AddAvatar(HANDLE hContact, TCHAR * szFilename, int width, int heigth) pavi->hWindow = NULL; pavi->hContact = hContact; pavi->bInvalidPos = 0; - li.List_Insert( AniAva.Objects, pavi, AniAva.Objects->realCount); + List_Insert( AniAva.Objects, pavi, AniAva.Objects->realCount); } //change avatar pavi->bToBeDeleted=FALSE; @@ -511,7 +511,7 @@ int AniAva_RemoveInvalidatedAvatars() pai->hWindow=NULL; if (!keepAvatar) _AniAva_RealRemoveAvatar(pai->dwAvatarUniqId); mir_free(pai); - li.List_Remove(AniAva.Objects,i); + List_Remove(AniAva.Objects,i); i--; } } @@ -635,7 +635,7 @@ static void _AniAva_RealRemoveAvatar(DWORD UniqueID) #ifdef _DEBUG __AniAva_DebugRenderStrip(); #endif - li.List_Remove(AniAva.AniAvatarList, j); + List_Remove(AniAva.AniAvatarList, j); mir_free(aai); _AniAva_ResumePainting(); break; @@ -671,7 +671,7 @@ static int _AniAva_LoadAvatarFromImage(TCHAR * szFileName, int width, int height aai.FrameSize.cx=width; aai.FrameSize.cy=height; - if (!li.List_GetIndex(AniAva.AniAvatarList,(void*)&aai,&idx)) idx=-1; + if (!List_GetIndex(AniAva.AniAvatarList,(void*)&aai,&idx)) idx=-1; if (idx==-1) //item not present in list { HBITMAP hBitmap=NULL; @@ -749,8 +749,8 @@ static int _AniAva_LoadAvatarFromImage(TCHAR * szFileName, int width, int height { //add to list int idx=AniAva.AniAvatarList->realCount; - li.List_GetIndex(AniAva.AniAvatarList, paai,&idx); - li.List_Insert(AniAva.AniAvatarList, (void*)paai, idx); + List_GetIndex(AniAva.AniAvatarList, paai,&idx); + List_Insert(AniAva.AniAvatarList, (void*)paai, idx); } return paai->dwAvatarUniqId; } @@ -1000,7 +1000,7 @@ static void _AniAva_ReduceAvatarImages(int startY, int dY, BOOL bDestroyWindow) { _AniAva_DestroyAvatarWindow(pai->hWindow); mir_free(pai); - li.List_Remove(AniAva.Objects,i); + List_Remove(AniAva.Objects,i); i--; } } diff --git a/plugins/Clist_modern/modern_cachefuncs.cpp b/plugins/Clist_modern/modern_cachefuncs.cpp index 0a741adb90..444fef27d7 100644 --- a/plugins/Clist_modern/modern_cachefuncs.cpp +++ b/plugins/Clist_modern/modern_cachefuncs.cpp @@ -96,7 +96,7 @@ void CSmileyString::AddListeningToIcon(struct SHORTDATA *dat, PDNCE pdnce, TCHAR int text_size = (int)_tcslen( szText ); - plText = li.List_Create( 0, 1 ); + plText = List_Create( 0, 1 ); // Add Icon { @@ -126,7 +126,7 @@ void CSmileyString::AddListeningToIcon(struct SHORTDATA *dat, PDNCE pdnce, TCHAR dat->text_smiley_height = max(piece->smiley_height, dat->text_smiley_height); iMaxSmileyHeight = max(piece->smiley_height, iMaxSmileyHeight); - li.List_Insert( plText, piece, plText->realCount); + List_Insert( plText, piece, plText->realCount); } // Add text @@ -136,7 +136,7 @@ void CSmileyString::AddListeningToIcon(struct SHORTDATA *dat, PDNCE pdnce, TCHAR piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = 0; piece->len = text_size; - li.List_Insert( plText, piece, plText->realCount); + List_Insert( plText, piece, plText->realCount); } } @@ -145,7 +145,7 @@ void CSmileyString::_CopySmileyList( SortedList *plInput ) // ASSERT( plText == NULL ); if ( !plInput || plInput->realCount == 0 ) return; - plText=li.List_Create( 0, 1 ); + plText=List_Create( 0, 1 ); for ( int i = 0; i < plInput->realCount; i++ ) { ClcContactTextPiece *pieceFrom=(ClcContactTextPiece *) plInput->items[i]; @@ -155,7 +155,7 @@ void CSmileyString::_CopySmileyList( SortedList *plInput ) *piece=*pieceFrom; if ( pieceFrom->type == TEXT_PIECE_TYPE_SMILEY) piece->smiley = CopyIcon( pieceFrom->smiley ); - li.List_Insert( plText, piece, plText->realCount ); + List_Insert( plText, piece, plText->realCount ); } } } @@ -188,7 +188,7 @@ void CSmileyString::DestroySmileyList() } } } - li.List_Destroy( plText ); + List_Destroy( plText ); } mir_free(plText); @@ -247,7 +247,7 @@ void CSmileyString::ReplaceSmileys(struct SHORTDATA *dat, PDNCE pdnce, TCHAR * s } // Lets add smileys - plText = li.List_Create( 0, 1 ); + plText = List_Create( 0, 1 ); for (unsigned i = 0; i < sp.numSmileys; ++i) { @@ -261,7 +261,7 @@ void CSmileyString::ReplaceSmileys(struct SHORTDATA *dat, PDNCE pdnce, TCHAR * s piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = last_pos ;//sp.str - text; piece->len = spr[i].startChar - last_pos; - li.List_Insert(plText, piece, plText->realCount); + List_Insert(plText, piece, plText->realCount); } // Add smiley @@ -291,7 +291,7 @@ void CSmileyString::ReplaceSmileys(struct SHORTDATA *dat, PDNCE pdnce, TCHAR * s dat->text_smiley_height = max( piece->smiley_height, dat->text_smiley_height ); iMaxSmileyHeight = max( piece->smiley_height, iMaxSmileyHeight ); - li.List_Insert(plText, piece, plText->realCount); + List_Insert(plText, piece, plText->realCount); } } // Get next @@ -308,7 +308,7 @@ void CSmileyString::ReplaceSmileys(struct SHORTDATA *dat, PDNCE pdnce, TCHAR * s piece->start_pos = last_pos; piece->len = text_size-last_pos; - li.List_Insert(plText, piece, plText->realCount); + List_Insert(plText, piece, plText->realCount); } } diff --git a/plugins/Clist_modern/modern_clc.cpp b/plugins/Clist_modern/modern_clc.cpp index e4626ceb63..40cd285410 100644 --- a/plugins/Clist_modern/modern_clc.cpp +++ b/plugins/Clist_modern/modern_clc.cpp @@ -1781,7 +1781,7 @@ static LRESULT clcOnIntmIconChanged(struct ClcData *dat, HWND hwnd, UINT msg, WP if (hSelItem) { struct ClcGroup *selgroup; if (pcli->pfnFindItem(hwnd, dat, hSelItem, &selcontact, &selgroup, NULL)) - dat->selection = pcli->pfnGetRowsPriorTo(&dat->list, selgroup, li.List_IndexOf(( SortedList* )&selgroup->cl, selcontact)); + dat->selection = pcli->pfnGetRowsPriorTo(&dat->list, selgroup, List_IndexOf(( SortedList* )&selgroup->cl, selcontact)); else dat->selection = -1; } diff --git a/plugins/Clist_modern/modern_clcitems.cpp b/plugins/Clist_modern/modern_clcitems.cpp index 89e0395129..0ceff512f9 100644 --- a/plugins/Clist_modern/modern_clcitems.cpp +++ b/plugins/Clist_modern/modern_clcitems.cpp @@ -345,11 +345,11 @@ int RestoreSelection( struct ClcData *dat, HANDLE hSelected ) if ( !selcontact->isSubcontact ) { - dat->selection = pcli->pfnGetRowsPriorTo( &dat->list, selgroup, li.List_IndexOf((SortedList*)&selgroup->cl, selcontact )); + dat->selection = pcli->pfnGetRowsPriorTo( &dat->list, selgroup, List_IndexOf((SortedList*)&selgroup->cl, selcontact )); } else { - dat->selection = pcli->pfnGetRowsPriorTo(&dat->list, selgroup, li.List_IndexOf((SortedList*)&selgroup->cl, selcontact->subcontacts )); + dat->selection = pcli->pfnGetRowsPriorTo(&dat->list, selgroup, List_IndexOf((SortedList*)&selgroup->cl, selcontact->subcontacts )); if (dat->selection != -1 ) dat->selection += selcontact->isSubcontact; diff --git a/plugins/Clist_modern/modern_clcmsgs.cpp b/plugins/Clist_modern/modern_clcmsgs.cpp index 6a444d32ac..872b24c6c4 100644 --- a/plugins/Clist_modern/modern_clcmsgs.cpp +++ b/plugins/Clist_modern/modern_clcmsgs.cpp @@ -122,7 +122,7 @@ LRESULT cli_ProcessExternalMessages(HWND hwnd,struct ClcData *dat,UINT msg,WPARA if (wParam != CLGN_ROOT) { if (!pcli->pfnFindItem(hwnd, dat, (HANDLE) lParam, &contact, &group, NULL)) return (LRESULT) (HANDLE) NULL; - i = li.List_IndexOf((SortedList*)&group->cl,contact); + i = List_IndexOf((SortedList*)&group->cl,contact); if (i<0) return 0; } switch (wParam) @@ -204,12 +204,12 @@ LRESULT cli_ProcessExternalMessages(HWND hwnd,struct ClcData *dat,UINT msg,WPARA if (!contact->isSubcontact) { - index=li.List_IndexOf((SortedList*)&group->cl,contact); + index=List_IndexOf((SortedList*)&group->cl,contact); mainindex=index; } else { - index=li.List_IndexOf((SortedList*)&group->cl,contact->subcontacts); + index=List_IndexOf((SortedList*)&group->cl,contact->subcontacts); mainindex=index; index+=contact->isSubcontact; } diff --git a/plugins/Clist_modern/modern_clistsettings.cpp b/plugins/Clist_modern/modern_clistsettings.cpp index 759b1ed8e3..9a7bacff7a 100644 --- a/plugins/Clist_modern/modern_clistsettings.cpp +++ b/plugins/Clist_modern/modern_clistsettings.cpp @@ -68,7 +68,7 @@ void InitDisplayNameCache(void) int i=0; InitCacheAsync(); InitAwayMsgModule(); - clistCache = li.List_Create( 0, 50 ); + clistCache = List_Create( 0, 50 ); clistCache->sortFunc = handleCompare; } void FreeDisplayNameCache() @@ -82,7 +82,7 @@ void FreeDisplayNameCache() mir_free_and_nill( clistCache->items[i] ); } - li.List_Destroy( clistCache ); + List_Destroy( clistCache ); mir_free_and_nill(clistCache); clistCache = NULL; } @@ -94,9 +94,9 @@ ClcCacheEntryBase* cliGetCacheEntry(HANDLE hContact) ClcCacheEntryBase* p; int idx; if (!clistCache) return NULL; - if ( !li.List_GetIndex( clistCache, &hContact, &idx )) { + if ( !List_GetIndex( clistCache, &hContact, &idx )) { if (( p = pcli->pfnCreateCacheItem( hContact )) != NULL ) { - li.List_Insert( clistCache, p, idx ); + List_Insert( clistCache, p, idx ); pcli->pfnInvalidateDisplayNameCacheEntry( hContact ); } } @@ -246,7 +246,7 @@ void FreeDisplayNameCache(SortedList *list) FreeDisplayNameCacheItem(( pdisplayNameCacheEntry )list->items[i] ); mir_free_and_nill(list->items[i]); } - li.List_Destroy(list); + List_Destroy(list); } */ diff --git a/plugins/Clist_modern/modern_commonheaders.cpp b/plugins/Clist_modern/modern_commonheaders.cpp index eb78d351c7..4cf9009138 100644 --- a/plugins/Clist_modern/modern_commonheaders.cpp +++ b/plugins/Clist_modern/modern_commonheaders.cpp @@ -316,7 +316,7 @@ void li_ListDestruct(SortedList *pList, ItemDestuctor pItemDestructor) int i=0; if (!pList) return; for (i=0; irealCount; i++) pItemDestructor(pList->items[i]); - li.List_Destroy(pList); + List_Destroy(pList); mir_free(pList); } @@ -325,13 +325,13 @@ void li_RemoveDestruct(SortedList *pList, int index, ItemDestuctor pItemDestruct if (index>=0 && indexrealCount) { pItemDestructor(pList->items[index]); - li.List_Remove(pList, index); + List_Remove(pList, index); } } void li_RemovePtrDestruct(SortedList *pList, void * ptr, ItemDestuctor pItemDestructor) { - if (li.List_RemovePtr(pList, ptr)) + if (List_RemovePtr(pList, ptr)) pItemDestructor(ptr); } diff --git a/plugins/Clist_modern/modern_skinengine.cpp b/plugins/Clist_modern/modern_skinengine.cpp index 7753867a9f..b9b9f8dbaf 100644 --- a/plugins/Clist_modern/modern_skinengine.cpp +++ b/plugins/Clist_modern/modern_skinengine.cpp @@ -526,7 +526,7 @@ int SkinEngineUnloadModule() EFFECTSSTACKITEM * effect=(EFFECTSSTACKITEM*)(pEffectStack->items[i]); mir_free_and_nill(effect); } - li.List_Destroy(pEffectStack); + List_Destroy(pEffectStack); mir_free_and_nill(pEffectStack); } if (g_pCachedWindow) @@ -623,7 +623,7 @@ HDC ske_RequestBufferDC(HDC hdcOwner, int dcID, int width, int height, BOOL fCle DCBUFFER * pBuf; if (BufferList==NULL) { - BufferList=li.List_Create(0,2); + BufferList=List_Create(0,2); BufferList->sortFunc=SortBufferList; InitializeCriticalSection(&BufferListCS); } @@ -632,7 +632,7 @@ HDC ske_RequestBufferDC(HDC hdcOwner, int dcID, int width, int height, BOOL fCle buf.hdcOwnedBy=hdcOwner; buf.nUsageID=dcID; buf.hDC=NULL; - pBuf=(DCBUFFER*)li.List_Find(BufferList,(void*)&buf); + pBuf=(DCBUFFER*)List_Find(BufferList,(void*)&buf); if (!pBuf) { //if not found - allocate it @@ -644,7 +644,7 @@ HDC ske_RequestBufferDC(HDC hdcOwner, int dcID, int width, int height, BOOL fCle pBuf->hDC=CreateCompatibleDC(hdcOwner); pBuf->oldBitmap=(HBITMAP)SelectObject(pBuf->hDC,pBuf->hBitmap); pBuf->dwDestroyAfterTime=0; - li.List_InsertPtr(BufferList,pBuf); + List_InsertPtr(BufferList,pBuf); } else { @@ -690,7 +690,7 @@ int ske_ReleaseBufferDC(HDC hDC, int keepTime) DeleteObject(pBuf->hBitmap); DeleteDC(pBuf->hDC); mir_free(pBuf); - li.List_Remove(BufferList,i); + List_Remove(BufferList,i); i--; } } @@ -2191,13 +2191,13 @@ int ske_UnloadSkin(SKINOBJECTSLIST * Skin) mir_free_and_nill(sf); } } - li.List_Destroy(gl_plSkinFonts); + List_Destroy(gl_plSkinFonts); mir_free_and_nill(gl_plSkinFonts); } } if (Skin->szSkinPlace) mir_free_and_nill(Skin->szSkinPlace); - if (Skin->pTextList) li.List_Destroy(Skin->pTextList); + if (Skin->pTextList) List_Destroy(Skin->pTextList); mir_free_and_nill(Skin->pTextList); ModernSkinButtonDeleteAll(); if (Skin->dwObjLPAlocated==0) { ske_UnlockSkin(); return 0;} @@ -2229,7 +2229,7 @@ int ske_UnloadSkin(SKINOBJECTSLIST * Skin) mir_free_and_nill(gt); } } - li.List_Destroy(dt->plTextList); + List_Destroy(dt->plTextList); mir_free_and_nill(dt->plTextList); } } @@ -2328,10 +2328,10 @@ static void ske_LinkSkinObjects(SKINOBJECTSLIST * pObjectList) { if (!globj->plTextList) { - globj->plTextList=li.List_Create(0,1); + globj->plTextList=List_Create(0,1); globj->plTextList->sortFunc=ske_SortTextGlyphObjectFunc; } - li.List_Insert(globj->plTextList,(void*)glText,globj->plTextList->realCount); + List_Insert(globj->plTextList,(void*)glText,globj->plTextList->realCount); qsort(globj->plTextList->items,globj->plTextList->realCount,sizeof(void*),(int(*)(const void*, const void*))globj->plTextList->sortFunc); pObjectList->pTextList->items[i]=NULL; } @@ -2348,7 +2348,7 @@ static void ske_LinkSkinObjects(SKINOBJECTSLIST * pObjectList) } } } - li.List_Destroy(pObjectList->pTextList); + List_Destroy(pObjectList->pTextList); mir_free_and_nill(pObjectList->pTextList); } } @@ -2754,7 +2754,7 @@ BOOL ske_ResetTextEffect(HDC hdc) { EFFECTSSTACKITEM * effect=(EFFECTSSTACKITEM*)(pEffectStack->items[i]); mir_free_and_nill(effect); - li.List_Remove(pEffectStack,i); + List_Remove(pEffectStack,i); return TRUE; } return FALSE; @@ -2766,7 +2766,7 @@ BOOL ske_SelectTextEffect(HDC hdc, BYTE EffectID, DWORD FirstColor, DWORD Second if (EffectID==-1) return ske_ResetTextEffect(hdc); if (!pEffectStack) { - pEffectStack=li.List_Create(0,1); + pEffectStack=List_Create(0,1); } { int i; @@ -2786,7 +2786,7 @@ BOOL ske_SelectTextEffect(HDC hdc, BYTE EffectID, DWORD FirstColor, DWORD Second effect->EffectID=EffectID; effect->FirstColor=FirstColor; effect->SecondColor=SecondColor; - li.List_Insert(pEffectStack, effect, 0); + List_Insert(pEffectStack, effect, 0); return TRUE; } return FALSE; @@ -4359,7 +4359,7 @@ static void OLDske_AddParseTextGlyphObject(char * szGlyphTextID,char * szDefineS if (!globj->plTextList) { - globj->plTextList=li.List_Create(0,1); + globj->plTextList=List_Create(0,1); globj->plTextList->sortFunc=ske_SortTextGlyphObjectFunc; } glText=(GLYPHTEXT*)mir_calloc(sizeof(GLYPHTEXT)); @@ -4387,7 +4387,7 @@ static void OLDske_AddParseTextGlyphObject(char * szGlyphTextID,char * szDefineS glText->dwShadow=ske_HexToARGB(GetParamN(szDefineString,buf,sizeof(buf),8,',',TRUE)); glText->stValueText=mir_a2u(GetParamN(szDefineString,buf,sizeof(buf),9,',',TRUE)); glText->stText=ske_ParseText(glText->stValueText); - li.List_Insert(globj->plTextList,(void*)glText,globj->plTextList->realCount); + List_Insert(globj->plTextList,(void*)glText,globj->plTextList->realCount); qsort(globj->plTextList->items,globj->plTextList->realCount,sizeof(void*),(int(*)(const void*, const void*))globj->plTextList->sortFunc); } } @@ -4428,8 +4428,8 @@ static void ske_AddParseTextGlyphObject(char * szGlyphTextID,char * szDefineStri glText->stText=ske_ParseText(glText->stValueText); if (!Skin->pTextList) - Skin->pTextList=li.List_Create(0,1); - li.List_InsertPtr(Skin->pTextList,glText); + Skin->pTextList=List_Create(0,1); + List_InsertPtr(Skin->pTextList,glText); } } @@ -4477,10 +4477,10 @@ static void ske_AddParseSkinFont(char * szFontID,char * szDefineString,SKINOBJEC { sf->szFontID=mir_strdup(szFontID); if (!gl_plSkinFonts) - gl_plSkinFonts=li.List_Create(0,1); + gl_plSkinFonts=List_Create(0,1); if (gl_plSkinFonts) { - li.List_Insert(gl_plSkinFonts,(void*)sf,gl_plSkinFonts->realCount); + List_Insert(gl_plSkinFonts,(void*)sf,gl_plSkinFonts->realCount); } } diff --git a/plugins/Clist_modern/modern_toolbar.cpp b/plugins/Clist_modern/modern_toolbar.cpp index 7720bae7fd..56078d03cc 100644 --- a/plugins/Clist_modern/modern_toolbar.cpp +++ b/plugins/Clist_modern/modern_toolbar.cpp @@ -192,7 +192,7 @@ HRESULT ToolbarLoadModule() RegisterClass(&wndclass); } } - tbdat.listOfButtons=li.List_Create(0,1); + tbdat.listOfButtons=List_Create(0,1); InitializeCriticalSection(&tbdat.cs); return S_OK; } @@ -322,7 +322,7 @@ static INT_PTR svcToolBarAddButton(WPARAM wParam, LPARAM lParam) mtbi->bVisible = bVisible; mtbi->bPanelID = bPanel; - li.List_InsertPtr(tbdat.listOfButtons,mtbi); + List_InsertPtr(tbdat.listOfButtons,mtbi); if (mtbi->bVisible) result=(INT_PTR)ToolBar_AddButtonToBars(mtbi); @@ -798,7 +798,7 @@ static LRESULT CALLBACK ToolBar_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM pMTBInfo->wLastHeight=Frame.height; pMTBInfo->nLineCount = 1; - pMTBInfo->pButtonList=li.List_Create(0,1); + pMTBInfo->pButtonList=List_Create(0,1); Frame.name=(char*) lpcs->lpCreateParams; hFrame=(HANDLE)CallService(MS_CLIST_FRAMES_ADDFRAME,(WPARAM)&Frame,(LPARAM)0); @@ -879,7 +879,7 @@ static LRESULT CALLBACK ToolBar_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM xpt_FreeThemeForWindow(hwnd); WindowList_Remove( tbdat.hToolBarWindowList, hwnd ); SendMessage(hwnd, MTBM_REMOVE_ALL_BUTTONS, 0, 0 ); - li.List_Destroy( pMTBInfo->pButtonList ); + List_Destroy( pMTBInfo->pButtonList ); mir_free( pMTBInfo->pButtonList ); SetWindowLongPtr( hwnd, GWLP_USERDATA, 0 ); mir_free( pMTBInfo ); @@ -902,7 +902,7 @@ static LRESULT CALLBACK ToolBar_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM mtbi->hWindow=hwndButton; mtbi->hwndToolBar=hwnd; - li.List_Insert(pMTBInfo->pButtonList, mtbi, pMTBInfo->pButtonList->realCount); //just insert pointer. such object are managed in global tbbutton list + List_Insert(pMTBInfo->pButtonList, mtbi, pMTBInfo->pButtonList->realCount); //just insert pointer. such object are managed in global tbbutton list if (hwndButton) { char * buttonId=(char *)_alloca(sizeof("ToolBar.")+strlen(mtbi->szButtonID)+2); @@ -930,9 +930,9 @@ static LRESULT CALLBACK ToolBar_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM mtbi->hwndToolBar = NULL; } } - li.List_Destroy( pMTBInfo->pButtonList ); + List_Destroy( pMTBInfo->pButtonList ); mir_free( pMTBInfo->pButtonList ); - pMTBInfo->pButtonList=li.List_Create(0,1); + pMTBInfo->pButtonList=List_Create(0,1); break; } case WM_SIZE: @@ -1072,14 +1072,14 @@ static LRESULT CALLBACK ToolBar_WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM mtbi=(MTB_BUTTONINFO*)pMTBInfo->pButtonList->items[i]; if (mtbi==(MTB_BUTTONINFO*)wParam) { - li.List_Remove(pMTBInfo->pButtonList,i); + List_Remove(pMTBInfo->pButtonList,i); for (int j=0; jrealCount; j++) if (mtbi==(MTB_BUTTONINFO*)tbdat.listOfButtons->items[j]) { - li.List_Remove(tbdat.listOfButtons,j); + List_Remove(tbdat.listOfButtons,j); break; } - li.List_RemovePtr(tbdat.listOfButtons,mtbi); + List_RemovePtr(tbdat.listOfButtons,mtbi); delete_MTB_BUTTONINFO((void*)mtbi); mtbi=NULL; pcli->pfnInvalidateRect(hwnd, NULL, FALSE); diff --git a/plugins/Clist_modern/modern_xptheme.cpp b/plugins/Clist_modern/modern_xptheme.cpp index 599cb55010..53b9b7541e 100644 --- a/plugins/Clist_modern/modern_xptheme.cpp +++ b/plugins/Clist_modern/modern_xptheme.cpp @@ -87,7 +87,7 @@ HRESULT XPThemesLoadModule() if (_xpt_ThemeSupport()) { InitializeCriticalSection(&xptCS); - xptObjectList=li.List_Create(0,1); + xptObjectList=List_Create(0,1); xptModuleLoaded=TRUE; } return S_OK; @@ -126,7 +126,7 @@ BOOL xpt_IsValidHandle(XPTHANDLE xptHandle) if (!xptHandle) return FALSE; xptlock(); { - if (li.List_IndexOf(xptObjectList, (void*)xptHandle)!=-1) + if (List_IndexOf(xptObjectList, (void*)xptHandle)!=-1) res=TRUE; } xptunlock(); @@ -143,7 +143,7 @@ XPTHANDLE xpt_AddThemeHandle(HWND hwnd, LPCWSTR className) xptObject->lpcwClassObject=className; xptObject->hOwnerWindow=hwnd; _sttXptReloadThemeData(xptObject); - li.List_InsertPtr(xptObjectList, (void*)xptObject); + List_InsertPtr(xptObjectList, (void*)xptObject); res=(XPTHANDLE)xptObject; } xptunlock(); @@ -159,7 +159,7 @@ void xpt_FreeThemeHandle(XPTHANDLE xptHandle) XPTObject* xptObject=(XPTObject*)xptHandle; _sttXptCloseThemeData(xptObject); _sttXptObjectDestructor((void *) xptHandle); - li.List_Remove(xptObjectList, li.List_IndexOf(xptObjectList,(void *) xptHandle)); + List_Remove(xptObjectList, List_IndexOf(xptObjectList,(void *) xptHandle)); } xptunlock(); } @@ -176,7 +176,7 @@ void xpt_FreeThemeForWindow(HWND hwnd) { _sttXptCloseThemeData(xptObject); _sttXptObjectDestructor((void *) xptObject); - li.List_Remove(xptObjectList, i); + List_Remove(xptObjectList, i); } else i++; diff --git a/plugins/Clist_mw/clc.cpp b/plugins/Clist_mw/clc.cpp index 4975eda998..d238f5a6bb 100644 --- a/plugins/Clist_mw/clc.cpp +++ b/plugins/Clist_mw/clc.cpp @@ -199,7 +199,7 @@ LRESULT CALLBACK ContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, L if (hSelItem) { struct ClcGroup *selgroup; if (FindItem(hwnd,dat,hSelItem,&selcontact,&selgroup,NULL)) - dat->selection = GetRowsPriorTo(&dat->list,selgroup,li.List_IndexOf((SortedList*)&selgroup->cl, selcontact)); + dat->selection = GetRowsPriorTo(&dat->list,selgroup,List_IndexOf((SortedList*)&selgroup->cl, selcontact)); else dat->selection = -1; } diff --git a/plugins/Clist_mw/clcidents.cpp b/plugins/Clist_mw/clcidents.cpp index 1cc940db2b..58517fa8c0 100644 --- a/plugins/Clist_mw/clcidents.cpp +++ b/plugins/Clist_mw/clcidents.cpp @@ -87,16 +87,16 @@ pdisplayNameCacheEntry GetCLCFullCacheEntry(struct ClcData *dat,HANDLE hContact) displayNameCacheEntry dnce; dnce.hContact = hContact; - displayNameCacheEntry *pdnce = (displayNameCacheEntry*)li.List_Find(&dat->lCLCContactsCache,&dnce); + displayNameCacheEntry *pdnce = (displayNameCacheEntry*)List_Find(&dat->lCLCContactsCache,&dnce); if (pdnce == NULL) { pdnce = (displayNameCacheEntry*)mir_calloc(sizeof(displayNameCacheEntry)); pdnce->hContact = hContact; int idx; - li.List_GetIndex(&dat->lCLCContactsCache,pdnce,&idx); - li.List_Insert(&dat->lCLCContactsCache,pdnce,idx); + List_GetIndex(&dat->lCLCContactsCache,pdnce,&idx); + List_Insert(&dat->lCLCContactsCache,pdnce,idx); - displayNameCacheEntry *pdnce2 = (displayNameCacheEntry*)li.List_Find(&dat->lCLCContactsCache,&dnce);//for check + displayNameCacheEntry *pdnce2 = (displayNameCacheEntry*)List_Find(&dat->lCLCContactsCache,&dnce);//for check if (pdnce2->hContact != pdnce->hContact) return NULL; diff --git a/plugins/Clist_mw/clistsettings.cpp b/plugins/Clist_mw/clistsettings.cpp index 25206e86ba..fcfbb58992 100644 --- a/plugins/Clist_mw/clistsettings.cpp +++ b/plugins/Clist_mw/clistsettings.cpp @@ -53,8 +53,8 @@ void InitDisplayNameCache(SortedList *list) displayNameCacheEntry *pdnce = (pdisplayNameCacheEntry)mir_calloc(sizeof(displayNameCacheEntry)); pdnce->hContact = hContact; InvalidateDisplayNameCacheEntryByPDNE(hContact,pdnce,0); - li.List_GetIndex(list,pdnce,&idx); - li.List_Insert(list,pdnce,idx); + List_GetIndex(list,pdnce,&idx); + List_Insert(list,pdnce,idx); hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0); i++; } } @@ -77,7 +77,7 @@ void FreeDisplayNameCache(SortedList *list) mir_free(list->items[i]); } - li.List_Destroy(list); + List_Destroy(list); } void CheckPDNCE(ClcCacheEntryBase *_pdnce) diff --git a/plugins/Clist_nicer/INCLUDE/clc.h b/plugins/Clist_nicer/INCLUDE/clc.h index fb412f46a5..27cb5d9a62 100644 --- a/plugins/Clist_nicer/INCLUDE/clc.h +++ b/plugins/Clist_nicer/INCLUDE/clc.h @@ -533,9 +533,6 @@ void ClearIcons(int mode); void SkinDrawBg(HWND hwnd, HDC hdc); int GetBasicFontID(struct ClcContact * contact); extern int __fastcall CLVM_GetContactHiddenStatus(HANDLE hContact, char *szStatus, struct ClcData *dat); -void Utf8Decode( char* str, wchar_t** ucs2 ); -char* Utf8Encode( const char* src ); -//int _DebugPopup(HANDLE hContact, const char *fmt, ...); void CreateViewModeFrame(); int GetExtraCache(HANDLE hContact, char *szProto); void ReloadExtraInfo(HANDLE hContact); diff --git a/plugins/Clist_nicer/SRC/clc.cpp b/plugins/Clist_nicer/SRC/clc.cpp index 439221be8d..17af82664b 100644 --- a/plugins/Clist_nicer/SRC/clc.cpp +++ b/plugins/Clist_nicer/SRC/clc.cpp @@ -404,7 +404,7 @@ LBL_Def: if (hSelItem) { struct ClcGroup *selgroup; if (pcli->pfnFindItem(hwnd, dat, hSelItem, &selcontact, &selgroup, NULL)) - dat->selection = pcli->pfnGetRowsPriorTo(&dat->list, selgroup, li.List_IndexOf((SortedList*) & selgroup->cl, selcontact)); + dat->selection = pcli->pfnGetRowsPriorTo(&dat->list, selgroup, List_IndexOf((SortedList*) & selgroup->cl, selcontact)); else dat->selection = -1; } @@ -573,7 +573,7 @@ LBL_Def: if (contact == 0 || group == 0) break; - iItem = pcli->pfnGetRowsPriorTo(&dat->list, group, li.List_IndexOf((SortedList*) & group->cl, contact)); + iItem = pcli->pfnGetRowsPriorTo(&dat->list, group, List_IndexOf((SortedList*) & group->cl, contact)); pcli->pfnInvalidateItem(hwnd, dat, iItem); goto LBL_Def; } diff --git a/plugins/ContactsPlus/utils.cpp b/plugins/ContactsPlus/utils.cpp index 43e8bed305..3bf63cf139 100644 --- a/plugins/ContactsPlus/utils.cpp +++ b/plugins/ContactsPlus/utils.cpp @@ -213,18 +213,6 @@ int DBWriteContactSettingStringT(HANDLE hContact, const char *szModule, const ch -int __fastcall SRCTranslateDialog(HWND hwndDlg) -{ - LANGPACKTRANSLATEDIALOG lptd; - - lptd.cbSize=sizeof(lptd); - lptd.flags=0; - lptd.hwndDlg=hwndDlg; - lptd.ignoreControls=NULL; - return CallService(MS_LANGPACK_TRANSLATEDIALOG,0,(LPARAM)&lptd); -} - - void DialogAddContactExecute(HWND hwndDlg, HANDLE hNewContact) { ADDCONTACTSTRUCT acs={0}; diff --git a/plugins/Db3x/dbcontacts.cpp b/plugins/Db3x/dbcontacts.cpp index 2918ba122b..ef128a491e 100644 --- a/plugins/Db3x/dbcontacts.cpp +++ b/plugins/Db3x/dbcontacts.cpp @@ -99,7 +99,7 @@ static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam) VLtemp.hContact = (HANDLE)wParam; EnterCriticalSection(&csDbAccess); while ( VLtemp.hContact ) { - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) { + if ( List_GetIndex(&lContacts,&VLtemp,&index)) { VL = ( DBCachedContactValueList* )lContacts.items[index]; if (VL->hNext != NULL) { if (!lParam || CheckProto(VL->hNext,(const char*)lParam)) { @@ -118,7 +118,7 @@ static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam) if ( VL == NULL ) { VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList)); VL->hContact = VLtemp.hContact; - li.List_Insert(&lContacts,VL,index); + List_Insert(&lContacts,VL,index); } VL->hNext = (HANDLE)dbc->ofsNext; if (VL->hNext != NULL && (!lParam || CheckProto(VL->hNext,(const char*)lParam))) { @@ -160,7 +160,7 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam) { DBCachedContactValueList VLtemp; VLtemp.hContact = (HANDLE)wParam; - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) + if ( List_GetIndex(&lContacts,&VLtemp,&index)) { DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index]; DBCachedContactValue* V = VL->first; @@ -173,7 +173,7 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam) } HeapFree( hCacheHeap, 0, VL ); - li.List_Remove(&lContacts,index); + List_Remove(&lContacts,index); } } dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL); @@ -214,7 +214,7 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam) { DBCachedContactValueList VLtemp; VLtemp.hContact = (HANDLE)ofsThis; - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) + if ( List_GetIndex(&lContacts,&VLtemp,&index)) { DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index]; VL->hNext = ( HANDLE )ofsNext; @@ -257,8 +257,8 @@ static INT_PTR AddContact(WPARAM wParam,LPARAM lParam) DBCachedContactValueList *VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList)); VL->hContact = (HANDLE)ofsNew; - li.List_GetIndex(&lContacts,VL,&index); - li.List_Insert(&lContacts,VL,index); + List_GetIndex(&lContacts,VL,&index); + List_Insert(&lContacts,VL,index); } LeaveCriticalSection(&csDbAccess); @@ -277,7 +277,7 @@ static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam) int index; DBCachedContactValueList VLtemp,*VL; VLtemp.hContact = (HANDLE)wParam; - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) + if ( List_GetIndex(&lContacts,&VLtemp,&index)) ret = TRUE; else { dbc=*(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL); @@ -286,7 +286,7 @@ static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam) if (ret) { VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList)); VL->hContact = (HANDLE)wParam; - li.List_Insert(&lContacts,VL,index); + List_Insert(&lContacts,VL,index); } } } LeaveCriticalSection(&csDbAccess); diff --git a/plugins/Db3x/dbsettings.cpp b/plugins/Db3x/dbsettings.cpp index c9cd3d01f7..ad7e470650 100644 --- a/plugins/Db3x/dbsettings.cpp +++ b/plugins/Db3x/dbsettings.cpp @@ -91,7 +91,7 @@ static char* InsertCachedSetting( const char* szName, size_t cbNameLen, int inde char* newValue = (char*)HeapAlloc( hCacheHeap, 0, cbNameLen ); *newValue = 0; strcpy(newValue+1,szName+1); - li.List_Insert(&lSettings,newValue,index); + List_Insert(&lSettings,newValue,index); return newValue; } @@ -108,7 +108,7 @@ static char* GetCachedSetting(const char *szModuleName,const char *szSettingName if (lastsetting && strcmp(szFullName+1,lastsetting) == 0) return lastsetting; - if ( li.List_GetIndex(&lSettings, szFullName, &index)) + if ( List_GetIndex(&lSettings, szFullName, &index)) lastsetting = (char*)lSettings.items[index] + 1; else lastsetting = InsertCachedSetting( szFullName, moduleNameLen+settingNameLen+3, index )+1; @@ -150,11 +150,11 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo if ( hContact == 0 ) { DBCachedGlobalValue Vtemp, *V; Vtemp.name = szSetting; - if ( li.List_GetIndex(&lGlobalSettings,&Vtemp,&index)) { + if ( List_GetIndex(&lGlobalSettings,&Vtemp,&index)) { V = (DBCachedGlobalValue*)lGlobalSettings.items[index]; if ( bAllocate == -1 ) { FreeCachedVariant( &V->value ); - li.List_Remove(&lGlobalSettings,index); + List_Remove(&lGlobalSettings,index); HeapFree(hCacheHeap,0,V); return NULL; } } @@ -164,7 +164,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo V = (DBCachedGlobalValue*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedGlobalValue)); V->name = szSetting; - li.List_Insert(&lGlobalSettings,V,index); + List_Insert(&lGlobalSettings,V,index); } return &V->value; @@ -174,7 +174,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo DBCachedContactValueList VLtemp,*VL; VLtemp.hContact=hContact; - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) { + if ( List_GetIndex(&lContacts,&VLtemp,&index)) { VL = (DBCachedContactValueList*)lContacts.items[index]; } else { @@ -183,7 +183,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList)); VL->hContact = hContact; - li.List_Insert(&lContacts,VL,index); + List_Insert(&lContacts,VL,index); } for ( V = VL->first; V != NULL; V = V->next) @@ -501,7 +501,7 @@ static INT_PTR SetSettingResident(WPARAM wParam,LPARAM lParam) strcpy( szTemp+1, ( char* )lParam ); EnterCriticalSection(&csDbAccess); - if ( !li.List_GetIndex( &lSettings, szTemp, &idx )) + if ( !List_GetIndex( &lSettings, szTemp, &idx )) szSetting = InsertCachedSetting( szTemp, cbSettingNameLen+2, idx ); else szSetting = (char *)lSettings.items[idx]; @@ -968,7 +968,7 @@ int InitSettings(void) void UninitSettings(void) { HeapDestroy(hCacheHeap); - li.List_Destroy(&lContacts); - li.List_Destroy(&lSettings); - li.List_Destroy(&lGlobalSettings); + List_Destroy(&lContacts); + List_Destroy(&lSettings); + List_Destroy(&lGlobalSettings); } diff --git a/plugins/Db3x_mmap/dbcontacts.cpp b/plugins/Db3x_mmap/dbcontacts.cpp index 51e533266d..0afd3469ab 100644 --- a/plugins/Db3x_mmap/dbcontacts.cpp +++ b/plugins/Db3x_mmap/dbcontacts.cpp @@ -62,8 +62,8 @@ DBCachedContactValueList* AddToCachedContactList(HANDLE hContact, int index) DBCachedContactValueList* VL; VL = (DBCachedContactValueList*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedContactValueList)); VL->hContact = hContact; - if (index == -1) li.List_GetIndex(&lContacts,VL,&index); - li.List_Insert(&lContacts,VL,index); + if (index == -1) List_GetIndex(&lContacts,VL,&index); + List_Insert(&lContacts,VL,index); return VL; } @@ -115,7 +115,7 @@ static INT_PTR FindNextContact(WPARAM wParam,LPARAM lParam) VLtemp.hContact = (HANDLE)wParam; EnterCriticalSection(&csDbAccess); while(VLtemp.hContact) { - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) { + if ( List_GetIndex(&lContacts,&VLtemp,&index)) { VL = ( DBCachedContactValueList* )lContacts.items[index]; if (VL->hNext != NULL) { if (!lParam || CheckProto(VL->hNext,(const char*)lParam)) { @@ -174,7 +174,7 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam) { DBCachedContactValueList VLtemp; VLtemp.hContact = (HANDLE)wParam; - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) + if ( List_GetIndex(&lContacts,&VLtemp,&index)) { DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index]; DBCachedContactValue* V = VL->first; @@ -188,7 +188,7 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam) if (VLtemp.hContact == hLastCachedContact) hLastCachedContact = NULL; - li.List_Remove(&lContacts,index); + List_Remove(&lContacts,index); } } dbc=(struct DBContact*)DBRead(wParam,sizeof(struct DBContact),NULL); @@ -229,7 +229,7 @@ static INT_PTR DeleteContact(WPARAM wParam,LPARAM lParam) { DBCachedContactValueList VLtemp; VLtemp.hContact = (HANDLE)ofsThis; - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) + if ( List_GetIndex(&lContacts,&VLtemp,&index)) { DBCachedContactValueList *VL = ( DBCachedContactValueList* )lContacts.items[index]; VL->hNext = ( HANDLE )ofsNext; @@ -285,7 +285,7 @@ static INT_PTR IsDbContact(WPARAM wParam,LPARAM lParam) int index; DBCachedContactValueList VLtemp; VLtemp.hContact = (HANDLE)wParam; - if ( li.List_GetIndex(&lContacts,&VLtemp,&index)) + if ( List_GetIndex(&lContacts,&VLtemp,&index)) ret = TRUE; else { dbc=(struct DBContact*)DBRead(ofsContact,sizeof(struct DBContact),NULL); diff --git a/plugins/Db3x_mmap/dbmodulechain.cpp b/plugins/Db3x_mmap/dbmodulechain.cpp index 671a239d48..5ad05b5abd 100644 --- a/plugins/Db3x_mmap/dbmodulechain.cpp +++ b/plugins/Db3x_mmap/dbmodulechain.cpp @@ -50,15 +50,15 @@ void AddToList(char *name, DWORD len, DWORD ofs) mn->name = name; mn->ofs = ofs; - if (li.List_GetIndex(&lMods,mn,&index)) + if (List_GetIndex(&lMods,mn,&index)) DatabaseCorruption( _T("%s (Module Name not unique)")); - li.List_Insert(&lMods,mn,index); + List_Insert(&lMods,mn,index); - if (li.List_GetIndex(&lOfs,mn,&index)) + if (List_GetIndex(&lOfs,mn,&index)) DatabaseCorruption( _T("%s (Module Offset not unique)")); - li.List_Insert(&lOfs,mn,index); + List_Insert(&lOfs,mn,index); } @@ -98,8 +98,8 @@ int InitModuleNames(void) void UninitModuleNames(void) { HeapDestroy(hModHeap); - li.List_Destroy(&lMods); - li.List_Destroy(&lOfs); + List_Destroy(&lMods); + List_Destroy(&lOfs); } static DWORD FindExistingModuleNameOfs(const char *szName) @@ -114,7 +114,7 @@ static DWORD FindExistingModuleNameOfs(const char *szName) if (lastmn && ModCompare(&mn,lastmn) == 0) return lastmn->ofs; - if (li.List_GetIndex(&lMods,&mn,&index)) { + if (List_GetIndex(&lMods,&mn,&index)) { pmn = (ModuleName*)lMods.items[index]; lastmn = pmn; return pmn->ofs; @@ -168,7 +168,7 @@ char *GetModuleNameByOfs(DWORD ofs) mn.name = NULL; mn.ofs = ofs; - if (li.List_GetIndex(&lOfs,&mn,&index)) { + if (List_GetIndex(&lOfs,&mn,&index)) { pmn = (ModuleName*)lOfs.items[index]; lastmn = pmn; return pmn->name; diff --git a/plugins/Db3x_mmap/dbsettings.cpp b/plugins/Db3x_mmap/dbsettings.cpp index 90dfecd727..7f7687ab4c 100644 --- a/plugins/Db3x_mmap/dbsettings.cpp +++ b/plugins/Db3x_mmap/dbsettings.cpp @@ -64,7 +64,7 @@ static char* InsertCachedSetting( const char* szName, size_t cbNameLen, int inde char* newValue = (char*)HeapAlloc( hCacheHeap, 0, cbNameLen ); *newValue = 0; strcpy(newValue+1,szName+1); - li.List_Insert(&lSettings,newValue,index); + List_Insert(&lSettings,newValue,index); return newValue; } @@ -81,7 +81,7 @@ static char* GetCachedSetting(const char *szModuleName,const char *szSettingName if (lastsetting && strcmp(szFullName+1,lastsetting) == 0) return lastsetting; - if (li.List_GetIndex(&lSettings,szFullName,&index)) + if (List_GetIndex(&lSettings,szFullName,&index)) lastsetting = (char*)lSettings.items[index]+1; else lastsetting = InsertCachedSetting( szFullName, settingNameLen+moduleNameLen+3, index )+1; @@ -129,11 +129,11 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo if ( hContact == 0 ) { DBCachedGlobalValue Vtemp, *V; Vtemp.name = szSetting; - if ( li.List_GetIndex(&lGlobalSettings,&Vtemp,&index)) { + if ( List_GetIndex(&lGlobalSettings,&Vtemp,&index)) { V = (DBCachedGlobalValue*)lGlobalSettings.items[index]; if ( bAllocate == -1 ) { FreeCachedVariant( &V->value ); - li.List_Remove(&lGlobalSettings,index); + List_Remove(&lGlobalSettings,index); HeapFree(hCacheHeap,0,V); return NULL; } } @@ -143,7 +143,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo V = (DBCachedGlobalValue*)HeapAlloc(hCacheHeap,HEAP_ZERO_MEMORY,sizeof(DBCachedGlobalValue)); V->name = szSetting; - li.List_Insert(&lGlobalSettings,V,index); + List_Insert(&lGlobalSettings,V,index); } return &V->value; @@ -158,7 +158,7 @@ static DBVARIANT* GetCachedValuePtr( HANDLE hContact, char* szSetting, int bAllo else { VLtemp.hContact=hContact; - if ( !li.List_GetIndex(&lContacts,&VLtemp,&index)) + if ( !List_GetIndex(&lContacts,&VLtemp,&index)) { if ( bAllocate != 1 ) return NULL; @@ -512,20 +512,20 @@ static INT_PTR SetSettingResident(WPARAM wParam,LPARAM lParam) strcpy( szTemp+1, ( char* )lParam ); EnterCriticalSection(&csDbAccess); - if ( !li.List_GetIndex( &lSettings, szTemp, &idx )) + if ( !List_GetIndex( &lSettings, szTemp, &idx )) szSetting = InsertCachedSetting( szTemp, cbSettingNameLen, idx ); else szSetting = (char *)lSettings.items[idx]; *szSetting = (char)wParam; - if ( !li.List_GetIndex( &lResidentSettings, szSetting+1, &idx )) + if ( !List_GetIndex( &lResidentSettings, szSetting+1, &idx )) { if (wParam) - li.List_Insert(&lResidentSettings,szSetting+1,idx); + List_Insert(&lResidentSettings,szSetting+1,idx); } else if (!wParam) - li.List_Remove(&lResidentSettings,idx); + List_Remove(&lResidentSettings,idx); LeaveCriticalSection(&csDbAccess); } @@ -1006,8 +1006,8 @@ int InitSettings(void) void UninitSettings(void) { HeapDestroy(hCacheHeap); - li.List_Destroy(&lContacts); - li.List_Destroy(&lSettings); - li.List_Destroy(&lGlobalSettings); - li.List_Destroy(&lResidentSettings); + List_Destroy(&lContacts); + List_Destroy(&lSettings); + List_Destroy(&lGlobalSettings); + List_Destroy(&lResidentSettings); } diff --git a/plugins/Db_autobackups/headers.h b/plugins/Db_autobackups/headers.h index 41da04b69b..93cc6fbc73 100644 --- a/plugins/Db_autobackups/headers.h +++ b/plugins/Db_autobackups/headers.h @@ -6,13 +6,14 @@ #include #include -#include -#include +#include #include #include + +#include +#include #include #include -#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include "m_folders.h" +#include #include "options.h" #include "resource.h" diff --git a/plugins/Db_autobackups/options.cpp b/plugins/Db_autobackups/options.cpp index 161d94ae4b..ef94ab8872 100644 --- a/plugins/Db_autobackups/options.cpp +++ b/plugins/Db_autobackups/options.cpp @@ -1,5 +1,4 @@ #include "headers.h" -#include Options options; static HWND hPathTip; diff --git a/plugins/Dbx_mmap_SA/Dbtool/cleaning.cpp b/plugins/Dbx_mmap_SA/Dbtool/cleaning.cpp index efbbde1640..a16a11e7ac 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/cleaning.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/cleaning.cpp @@ -29,7 +29,7 @@ INT_PTR CALLBACK CleaningDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lPa EnableWindow(GetDlgItem(hdlg,IDC_ERASEHISTORY),!opts.bAggressive); CheckDlgButton(hdlg,IDC_MARKREAD,opts.bMarkRead); CheckDlgButton(hdlg,IDC_CONVERTUTF,opts.bConvertUtf); - TranslateDialog(hdlg); + TranslateDialogDefault(hdlg); return TRUE; case WZN_PAGECHANGING: opts.bEraseHistory=IsDlgButtonChecked(hdlg,IDC_ERASEHISTORY)&&!opts.bAggressive; diff --git a/plugins/Dbx_mmap_SA/Dbtool/dbtool.h b/plugins/Dbx_mmap_SA/Dbtool/dbtool.h index 63b6b4ccf1..dd6af38cd5 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/dbtool.h +++ b/plugins/Dbx_mmap_SA/Dbtool/dbtool.h @@ -34,9 +34,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include -//#include // Only needed to keep m_database.h happy -#define CallService(a,b,c) 1 - #include "m_database.h" #include "database.h" // Note: This is a copy of database.h from the Miranda IM v0.3 tree. // Remember to update this when releasing new dbtool versions. @@ -104,18 +101,4 @@ DWORD ConvertModuleNameOfs(DWORD ofsOld); void FreeModuleChain(); extern BOOL bEncrypted; -int TranslateDialog(HWND hwndDlg); -void LoadLangPackModule(void); -void UnloadLangPackModule(void); - -char* LangPackTranslateString(const char *szEnglish, const int W); -__inline LPSTR Translate(LPSTR source) -{ return ( LPSTR )LangPackTranslateString( source, 0 ); -} - -#define TranslateT(s) (TCHAR*)LangPackTranslateString((LPCSTR)_T(s),1) -#define TranslateTS(s) (TCHAR*)LangPackTranslateString((LPCSTR)s,1) - -char* Utf8DecodeCP(char* str, int codepage, wchar_t** ucs2); -char* Utf8EncodeUcs2(const wchar_t* src); bool is_utf8_string(const char* str); diff --git a/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj.filters b/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj.filters index 202d0b374d..1c054474cd 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj.filters @@ -24,9 +24,6 @@ Source Files - - Source Files - Source Files diff --git a/plugins/Dbx_mmap_SA/Dbtool/encryption.cpp b/plugins/Dbx_mmap_SA/Dbtool/encryption.cpp index 3d00d70880..4f5c0a18b6 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/encryption.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/encryption.cpp @@ -230,7 +230,7 @@ BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) { HWND hwndCtrl; // if(pluginLink && ServiceExists(MS_LANGPACK_TRANSLATEDIALOG)) - TranslateDialog(hDlg); + TranslateDialogDefault(hDlg); if(lParam && !wrongPass) SetDlgItemTextA(hDlg, IDC_DBNAME, (LPCSTR)lParam); if(wrongPass) diff --git a/plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp b/plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp index 2b9ba5098a..3c9e37668a 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp @@ -49,7 +49,7 @@ static void ConvertOldEvent( DBEvent*& dbei ) } if ( msglenW > 0 && msglenW <= msglen ) { - char* utf8str = Utf8EncodeUcs2(( WCHAR* )&dbei->blob[ msglen ] ); + char* utf8str = Utf8EncodeW(( WCHAR* )&dbei->blob[ msglen ] ); dbei->cbBlob = (DWORD)strlen( utf8str )+1; dbei->flags |= DBEF_UTF; if (offsetof(DBEvent,blob)+dbei->cbBlob > memsize) { diff --git a/plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp b/plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp index 2fdd16c082..d904daf5b9 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp @@ -29,7 +29,7 @@ INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM l CheckDlgButton(hdlg,IDC_BACKUP,opts.bBackup); CheckDlgButton(hdlg,IDC_AGGRESSIVE,opts.bAggressive); SendMessage(hdlg,WM_COMMAND,MAKEWPARAM(IDC_CHECKONLY,BN_CLICKED),0); - TranslateDialog(hdlg); + TranslateDialogDefault(hdlg); return TRUE; case WZN_PAGECHANGING: opts.bCheckOnly=IsDlgButtonChecked(hdlg,IDC_CHECKONLY); diff --git a/plugins/Dbx_mmap_SA/Dbtool/finished.cpp b/plugins/Dbx_mmap_SA/Dbtool/finished.cpp index 1716f72dd4..08d0f5c893 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/finished.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/finished.cpp @@ -36,7 +36,7 @@ INT_PTR CALLBACK FinishedDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lPa SetDlgItemText(hdlg,IDC_BACKUPFILE,opts.backupFilename); } else ShowWindow(GetDlgItem(hdlg,IDC_STBACKUP),FALSE); - TranslateDialog(hdlg); + TranslateDialogDefault(hdlg); return TRUE; case WM_LAUNCHMIRANDA: if(IsDlgButtonChecked(hdlg,IDC_LAUNCHMIRANDA)) { diff --git a/plugins/Dbx_mmap_SA/Dbtool/langpack.cpp b/plugins/Dbx_mmap_SA/Dbtool/langpack.cpp deleted file mode 100644 index 7f2627cd11..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/langpack.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/* - -Miranda IM: the free IM client for Microsoft* Windows* - -Copyright 2000-2011 Miranda ICQ/IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -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; either version 2 -of the License, or (at your option) any later version. - -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, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "dbtool.h" - -struct LangPackEntry { - unsigned linePos; - DWORD englishHash; - char *english; //not currently used, the hash does everything - char *local; - wchar_t *wlocal; -}; - -struct LangPackStruct { - TCHAR filename[MAX_PATH]; - char language[64]; - char lastModifiedUsing[64]; - char authors[256]; - char authorEmail[128]; - struct LangPackEntry *entry; - int entryCount; - LCID localeID; - UINT defaultANSICp; -} static langPack; - -static void TrimString(char *str) -{ - size_t start, len = strlen(str); - while(str[0] && (unsigned char)str[len-1] <= ' ') str[--len] = 0; - for (start = 0; str[start] && (unsigned char)str[start] <= ' '; start++); - memmove(str, str + start, len - start + 1); -} - -static void TrimStringSimple(char *str) -{ - size_t len = strlen(str); - if (str[len-1] == '\n') str[--len] = '\0'; - if (str[len-1] == '\r') str[len-1] = '\0'; -} - -static int IsEmpty(char *str) -{ - int i = 0; - - while (str[i]) - { - if (str[i] != ' ' && str[i] != '\r' && str[i] != '\n') - return 0; - i++; - } - return 1; -} - -void ConvertBackslashes(char *str, UINT fileCp) -{ - char *pstr; - for (pstr = str; *pstr; pstr = CharNextExA(fileCp, pstr, 0)) - { - if ( *pstr == '\\' ) - { - switch( pstr[1] ) - { - case 'n': *pstr = '\n'; break; - case 't': *pstr = '\t'; break; - case 'r': *pstr = '\r'; break; - default: *pstr = pstr[1]; break; - } - memmove(pstr+1, pstr+2, strlen(pstr+2) + 1); - } - } -} - -#ifdef _DEBUG -#pragma optimize( "gt", on ) -#endif - -// MurmurHash2 -unsigned int __fastcall hash(const void * key, unsigned int len) -{ - // 'm' and 'r' are mixing constants generated offline. - // They're not really 'magic', they just happen to work well. - const unsigned int m = 0x5bd1e995; - const int r = 24; - - // Initialize the hash to a 'random' value - unsigned int h = len; - - // Mix 4 bytes at a time into the hash - const unsigned char * data = (const unsigned char *)key; - - while(len >= 4) - { - unsigned int k = *(unsigned int *)data; - - k *= m; - k ^= k >> r; - k *= m; - - h *= m; - h ^= k; - - data += 4; - len -= 4; - } - - // Handle the last few bytes of the input array - switch(len) - { - case 3: h ^= data[2] << 16; - case 2: h ^= data[1] << 8; - case 1: h ^= data[0]; - h *= m; - }; - - // Do a few final mixes of the hash to ensure the last few - // bytes are well-incorporated. - h ^= h >> 13; - h *= m; - h ^= h >> 15; - - return h; -} - -unsigned int __fastcall hashstrW(const char * key) -{ - if (key == NULL) return 0; - const unsigned int len = (unsigned int)wcslen((const wchar_t*)key); - char* buf = (char*)alloca(len + 1); - for (unsigned i = 0; i <= len ; ++i) - buf[i] = key[i << 1]; - return hash(buf, len); -} - -__inline unsigned int hashstr(const char * key) -{ - if (key == NULL) return 0; - const unsigned int len = (unsigned int)strlen((const char*)key); - return hash(key, len); -} - -#ifdef _DEBUG -#pragma optimize( "", on ) -#endif - -static int SortLangPackHashesProc(struct LangPackEntry *arg1,struct LangPackEntry *arg2) -{ - if(arg1->englishHashenglishHash) return -1; - if(arg1->englishHash>arg2->englishHash) return 1; - /* both source strings of the same hash (may not be the same string thou) put - the one that was written first to be found first */ - if(arg1->linePoslinePos) return -1; - if(arg1->linePos>arg2->linePos) return 1; - return 0; -} - - -static int SortLangPackHashesProc2(struct LangPackEntry *arg1,struct LangPackEntry *arg2) -{ - if(arg1->englishHashenglishHash) return -1; - if(arg1->englishHash>arg2->englishHash) return 1; - return 0; -} - -static int LoadLangPack(const TCHAR *szLangPack) -{ - FILE *fp; - char line[4096] = ""; - char *pszColon; - char *pszLine; - int entriesAlloced; - int startOfLine=0; - unsigned int linePos=1; - LCID langID; - UINT fileCp = CP_ACP; - - lstrcpy(langPack.filename,szLangPack); - fp = _tfopen(szLangPack,_T("rt")); - if(fp==NULL) return 1; - fgets(line,sizeof(line),fp); - size_t lineLen = strlen(line); - if (lineLen >= 3 && line[0]=='\xef' && line[1]=='\xbb' && line[2]=='\xbf') - { - fileCp = CP_UTF8; - memmove(line, line + 3, lineLen - 2); - } - TrimString(line); - if(lstrcmpA(line,"Miranda Language Pack Version 1")) {fclose(fp); return 2;} - //headers - while(!feof(fp)) { - startOfLine=ftell(fp); - if(fgets(line,sizeof(line),fp)==NULL) break; - TrimString(line); - if(IsEmpty(line) || line[0]==';' || line[0]==0) continue; - if(line[0]=='[') break; - pszColon=strchr(line,':'); - if(pszColon==NULL) {fclose(fp); return 3;} - *pszColon=0; - if (!lstrcmpA(line,"Language")) {_snprintf(langPack.language,sizeof(langPack.language),"%s",pszColon+1); TrimString(langPack.language);} - else if (!lstrcmpA(line,"Last-Modified-Using")) {_snprintf(langPack.lastModifiedUsing,sizeof(langPack.lastModifiedUsing),"%s",pszColon+1); TrimString(langPack.lastModifiedUsing);} - else if (!lstrcmpA(line,"Authors")) {_snprintf(langPack.authors,sizeof(langPack.authors),"%s",pszColon+1); TrimString(langPack.authors);} - else if (!lstrcmpA(line,"Author-email")) {_snprintf(langPack.authorEmail,sizeof(langPack.authorEmail),"%s",pszColon+1); TrimString(langPack.authorEmail);} - else if (!lstrcmpA(line, "Locale")) { - char szBuf[20], *stopped; - - TrimString(pszColon + 1); - langID = (USHORT)strtol(pszColon + 1, &stopped, 16); - langPack.localeID = MAKELCID(langID, 0); - GetLocaleInfoA(langPack.localeID, LOCALE_IDEFAULTANSICODEPAGE, szBuf, 10); - szBuf[5] = 0; // codepages have max. 5 digits - langPack.defaultANSICp = atoi(szBuf); - if (fileCp == CP_ACP) - fileCp = langPack.defaultANSICp; - } - } - - //body - fseek(fp,startOfLine,SEEK_SET); - entriesAlloced=0; - while(!feof(fp)) { - if(fgets(line,sizeof(line),fp)==NULL) break; - if(IsEmpty(line) || line[0]==';' || line[0]==0) continue; - TrimStringSimple(line); - ConvertBackslashes(line, fileCp); - if(line[0]=='[' && line[lstrlenA(line)-1]==']') { - if(langPack.entryCount && langPack.entry[langPack.entryCount-1].local==NULL) { - if(langPack.entry[langPack.entryCount-1].english!=NULL) free(langPack.entry[langPack.entryCount-1].english); - langPack.entryCount--; - } - pszLine = line+1; - line[lstrlenA(line)-1]='\0'; - TrimStringSimple(line); - if (++langPack.entryCount>entriesAlloced) { - entriesAlloced+=128; - langPack.entry=(struct LangPackEntry*)realloc(langPack.entry,sizeof(struct LangPackEntry)*entriesAlloced); - } - langPack.entry[langPack.entryCount-1].english=NULL; - langPack.entry[langPack.entryCount-1].englishHash=hashstr(pszLine); - langPack.entry[langPack.entryCount-1].local=NULL; - langPack.entry[langPack.entryCount-1].wlocal = NULL; - langPack.entry[langPack.entryCount-1].linePos=linePos++; - } - else if(langPack.entryCount) { - struct LangPackEntry* E = &langPack.entry[langPack.entryCount-1]; - - if(E->local==NULL) { - E->local = _strdup(line); - if (fileCp == CP_UTF8) - Utf8DecodeCP(E->local, langPack.defaultANSICp, NULL); - - { - int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0); - E->wlocal = (wchar_t *)malloc((iNeeded+1) * sizeof(wchar_t)); - MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal, iNeeded); - } - } - else { - size_t iOldLenA = strlen(E->local); - E->local = (char*)realloc(E->local, iOldLenA + strlen(line) + 2); - strcat(E->local, "\n"); - strcat(E->local, line); - if (fileCp == CP_UTF8) - Utf8DecodeCP(E->local + iOldLenA + 1, langPack.defaultANSICp, NULL); - { - int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0); - size_t iOldLen = wcslen(E->wlocal); - E->wlocal = (wchar_t*)realloc(E->wlocal, ( sizeof(wchar_t) * ( iOldLen + iNeeded + 2))); - wcscat(E->wlocal, L"\n"); - MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal + iOldLen+1, iNeeded); - } - } - } - } - fclose(fp); - - qsort(langPack.entry,langPack.entryCount,sizeof(LangPackEntry),(int(*)(const void*,const void*))SortLangPackHashesProc); - - return 0; -} - -char *LangPackTranslateString(const char *szEnglish, const int W) -{ - struct LangPackEntry key,*entry; - - if ( langPack.entryCount == 0 || szEnglish == NULL ) return (char*)szEnglish; - - key.englishHash = W ? hashstrW(szEnglish) : hashstr(szEnglish); - entry=(struct LangPackEntry*)bsearch(&key,langPack.entry,langPack.entryCount,sizeof(struct LangPackEntry),(int(*)(const void*,const void*))SortLangPackHashesProc2); - if(entry==NULL) return (char*)szEnglish; - while(entry>langPack.entry) - { - entry--; - if(entry->englishHash!=key.englishHash) { - entry++; - return W ? (char *)entry->wlocal : entry->local; - } - } - return W ? (char *)entry->wlocal : entry->local; -} - -#define FLAGS 1 - -static void TranslateWindow( HWND hwnd ) -{ - TCHAR title[2048]; - GetWindowText(hwnd, title, SIZEOF( title )); - { - TCHAR* result = ( TCHAR* )LangPackTranslateString(( char* )title, FLAGS ); - if ( result != title ) - SetWindowText(hwnd, result ); -} } - -static BOOL CALLBACK TranslateDialogEnumProc(HWND hwnd,LPARAM lParam) -{ - TCHAR szClass[32]; - int id = GetDlgCtrlID( hwnd ); - - GetClassName(hwnd,szClass,SIZEOF(szClass)); - if (!lstrcmpi(szClass,_T("static")) || !lstrcmpi(szClass,_T("hyperlink")) || !lstrcmpi(szClass,_T("button")) || !lstrcmpi(szClass,_T("MButtonClass"))) - TranslateWindow(hwnd); - else if (!lstrcmpi(szClass,_T("edit"))) { - if ( GetWindowLongPtr(hwnd,GWL_STYLE)&ES_READONLY) - TranslateWindow(hwnd); - } - return TRUE; -} - -int TranslateDialog( HWND hwndDlg ) -{ - TranslateWindow( hwndDlg ); - EnumChildWindows( hwndDlg,TranslateDialogEnumProc,0); - return 0; -} - -void LoadLangPackModule(void) -{ - HANDLE hFind; - TCHAR szSearch[MAX_PATH], *str2, szLangPack[MAX_PATH]; - WIN32_FIND_DATA fd; - - GetModuleFileName(GetModuleHandle(NULL),szSearch,MAX_PATH); - str2 = _tcsrchr(szSearch, '\\'); - if (str2) *str2 = 0; else str2 = szSearch; - _tcscat(szSearch, _T("\\langpack_*.txt")); - hFind = FindFirstFile(szSearch, &fd); - if (hFind != INVALID_HANDLE_VALUE) - { - FindClose(hFind); - - _tcscpy(str2 + 1, fd.cFileName); - _tcscpy(szLangPack, szSearch); - LoadLangPack(szLangPack); - } -} - -void UnloadLangPackModule(void) -{ - for (int i = 0; i < langPack.entryCount; i++) { - free(langPack.entry[i].english); - free(langPack.entry[i].local); - free(langPack.entry[i].wlocal); - } - if (langPack.entryCount) { - free(langPack.entry); - langPack.entry=0; - langPack.entryCount=0; - } -} - diff --git a/plugins/Dbx_mmap_SA/Dbtool/main.cpp b/plugins/Dbx_mmap_SA/Dbtool/main.cpp index 014881e34d..bdfb5ce706 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/main.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/main.cpp @@ -19,13 +19,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "dbtool.h" HINSTANCE hInst; +int hLangpack=0; DbToolOptions opts = {0}; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { hInst=hInstance; - LoadLangPackModule(); InitCommonControls(); DialogBox(hInst,MAKEINTRESOURCE(IDD_WIZARD),NULL,WizardDlgProc); return 0; diff --git a/plugins/Dbx_mmap_SA/Dbtool/openerror.cpp b/plugins/Dbx_mmap_SA/Dbtool/openerror.cpp index 292d688be7..1fa2964c20 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/openerror.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/openerror.cpp @@ -31,7 +31,7 @@ INT_PTR CALLBACK OpenErrorDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lP } if(opts.error==ERROR_SHARING_VIOLATION) ShowWindow(GetDlgItem(hdlg,IDC_INUSE),SW_SHOW); SetWindowLongPtr( GetDlgItem( hdlg, IDC_FILE ), GWL_STYLE, GetWindowLongPtr( GetDlgItem( hdlg, IDC_FILE ), GWL_STYLE ) | SS_PATHELLIPSIS ); - TranslateDialog( hdlg ); + TranslateDialogDefault( hdlg ); SetDlgItemText( hdlg, IDC_FILE, opts.filename ); return TRUE; case WM_COMMAND: diff --git a/plugins/Dbx_mmap_SA/Dbtool/progress.cpp b/plugins/Dbx_mmap_SA/Dbtool/progress.cpp index caca179482..5ddb8bd985 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/progress.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/progress.cpp @@ -104,7 +104,7 @@ INT_PTR CALLBACK ProgressDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lPa manualAbort=0; hEventRun=CreateEvent(NULL,TRUE,TRUE,NULL); hEventAbort=CreateEvent(NULL,TRUE,FALSE,NULL); - TranslateDialog(hdlg); + TranslateDialogDefault(hdlg); _beginthread(WorkerThread,0,NULL); return TRUE; case WM_MEASUREITEM: diff --git a/plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp b/plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp index 9b1a08640e..9db3517816 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp @@ -209,7 +209,7 @@ INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lPa CloseHandle( opts.hFile ); opts.hFile = NULL; } - TranslateDialog( hdlg ); + TranslateDialogDefault( hdlg ); return TRUE; } diff --git a/plugins/Dbx_mmap_SA/Dbtool/utf.cpp b/plugins/Dbx_mmap_SA/Dbtool/utf.cpp index 157d5d00f5..c56db053d8 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/utf.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/utf.cpp @@ -26,382 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "dbtool.h" -/* number of following bytes in sequence based on first byte value (for bytes above 0x7f) */ -static const char utf8_length[128] = -{ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x80-0x8f */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x90-0x9f */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xa0-0xaf */ - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0xb0-0xbf */ - 0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0xc0-0xcf */ - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, /* 0xd0-0xdf */ - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, /* 0xe0-0xef */ - 3,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0 /* 0xf0-0xff */ -}; - -/* first byte mask depending on UTF-8 sequence length */ -static const unsigned char utf8_mask[4] = { 0x7f, 0x1f, 0x0f, 0x07 }; - -/* minimum Unicode value depending on UTF-8 sequence length */ -static const unsigned int utf8_minval[4] = { 0x0, 0x80, 0x800, 0x10000 }; - - -/* get the next char value taking surrogates into account */ -static unsigned int getSurrogateValue(const wchar_t *src, unsigned int srclen) -{ - if (src[0] >= 0xd800 && src[0] <= 0xdfff) /* surrogate pair */ - { - if (src[0] > 0xdbff || /* invalid high surrogate */ - srclen <= 1 || /* missing low surrogate */ - src[1] < 0xdc00 || src[1] > 0xdfff) /* invalid low surrogate */ - return 0; - return 0x10000 + ((src[0] & 0x3ff) << 10) + (src[1] & 0x3ff); - } - return src[0]; -} - -/* query necessary dst length for src string */ -static int Ucs2toUtf8Len(const wchar_t *src, unsigned int srclen) -{ - int len; - unsigned int val; - - for (len = 0; srclen; srclen--, src++) - { - if (*src < 0x80) /* 0x00-0x7f: 1 byte */ - { - len++; - continue; - } - if (*src < 0x800) /* 0x80-0x7ff: 2 bytes */ - { - len += 2; - continue; - } - if (!(val = getSurrogateValue(src, srclen))) - { - return -2; - } - if (val < 0x10000) /* 0x800-0xffff: 3 bytes */ - len += 3; - else /* 0x10000-0x10ffff: 4 bytes */ - { - len += 4; - src++; - srclen--; - } - } - return len; -} - -int Ucs2toUtf8Len(const wchar_t *src) -{ - if ( src == 0 ) - return 0; - - return Ucs2toUtf8Len( src, (int)wcslen( src )); -} - -/* wide char to UTF-8 string conversion */ -/* return -1 on dst buffer overflow, -2 on invalid input char */ -int Ucs2toUtf8(const wchar_t *src, int srclen, char *dst, int dstlen) -{ - int len; - - for (len = dstlen; srclen; srclen--, src++) - { - WCHAR ch = *src; - unsigned int val; - - if (ch < 0x80) /* 0x00-0x7f: 1 byte */ - { - if (!len--) return -1; /* overflow */ - *dst++ = ch; - continue; - } - - if (ch < 0x800) /* 0x80-0x7ff: 2 bytes */ - { - if ((len -= 2) < 0) return -1; /* overflow */ - dst[1] = 0x80 | (ch & 0x3f); - ch >>= 6; - dst[0] = 0xc0 | ch; - dst += 2; - continue; - } - - if (!(val = getSurrogateValue(src, srclen))) - { - return -2; - } - - if (val < 0x10000) /* 0x800-0xffff: 3 bytes */ - { - if ((len -= 3) < 0) return -1; /* overflow */ - dst[2] = 0x80 | (val & 0x3f); - val >>= 6; - dst[1] = 0x80 | (val & 0x3f); - val >>= 6; - dst[0] = 0xe0 | val; - dst += 3; - } - else /* 0x10000-0x10ffff: 4 bytes */ - { - if ((len -= 4) < 0) return -1; /* overflow */ - dst[3] = 0x80 | (val & 0x3f); - val >>= 6; - dst[2] = 0x80 | (val & 0x3f); - val >>= 6; - dst[1] = 0x80 | (val & 0x3f); - val >>= 6; - dst[0] = 0xf0 | val; - dst += 4; - src++; - srclen--; - } - } - return dstlen - len; -} - -/* helper for the various utf8 mbstowcs functions */ -static unsigned int decodeUtf8Char(unsigned char ch, const char **str, const char *strend) -{ - unsigned int len = utf8_length[ch-0x80]; - unsigned int res = ch & utf8_mask[len]; - const char *end = *str + len; - - if (end > strend) return ~0; - switch(len) - { - case 3: - if ((ch = end[-3] ^ 0x80) >= 0x40) break; - res = (res << 6) | ch; - (*str)++; - case 2: - if ((ch = end[-2] ^ 0x80) >= 0x40) break; - res = (res << 6) | ch; - (*str)++; - case 1: - if ((ch = end[-1] ^ 0x80) >= 0x40) break; - res = (res << 6) | ch; - (*str)++; - if (res < utf8_minval[len]) break; - return res; - } - return ~0; -} - -/* query necessary dst length for src string */ -static inline int Utf8toUcs2Len(const char *src, int srclen) -{ - int ret = 0; - unsigned int res; - const char *srcend = src + srclen; - - while (src < srcend) - { - unsigned char ch = *src++; - if (ch < 0x80) /* special fast case for 7-bit ASCII */ - { - ret++; - continue; - } - if ((res = decodeUtf8Char(ch, &src, srcend)) <= 0x10ffff) - { - if (res > 0xffff) ret++; - ret++; - } - else return -2; /* bad char */ - /* otherwise ignore it */ - } - return ret; -} - -/* UTF-8 to wide char string conversion */ -/* return -1 on dst buffer overflow, -2 on invalid input char */ -int Utf8toUcs2(const char *src, int srclen, wchar_t *dst, int dstlen) -{ - unsigned int res; - const char *srcend = src + srclen; - wchar_t *dstend = dst + dstlen; - - while ((dst < dstend) && (src < srcend)) - { - unsigned char ch = *src++; - if (ch < 0x80) /* special fast case for 7-bit ASCII */ - { - *dst++ = ch; - continue; - } - if ((res = decodeUtf8Char(ch, &src, srcend)) <= 0xffff) - { - *dst++ = res; - } - else if (res <= 0x10ffff) /* we need surrogates */ - { - if (dst == dstend - 1) return -1; /* overflow */ - res -= 0x10000; - *dst++ = 0xd800 | (res >> 10); - *dst++ = 0xdc00 | (res & 0x3ff); - } - else return -2; /* bad char */ - /* otherwise ignore it */ - } - if (src < srcend) return -1; /* overflow */ - return dstlen - (dstend - dst); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Utf8Decode - converts UTF8-encoded string to the UCS2/MBCS format - -char* Utf8DecodeCP(char* str, int codepage, wchar_t** ucs2) -{ - int len; - bool needs_free = false; - wchar_t* tempBuf = NULL; - if ( ucs2 ) - *ucs2 = NULL; - - if (str == NULL) - return NULL; - - len = (int)strlen(str); - - if (len < 2) { - if (ucs2 != NULL) { - *ucs2 = tempBuf = (wchar_t*)malloc((len + 1) * sizeof(wchar_t)); - MultiByteToWideChar(codepage, 0, str, len, tempBuf, len); - tempBuf[len] = 0; - } - return str; - } - - int destlen = Utf8toUcs2Len(str, len); - if (destlen < 0) - return NULL; - - if (ucs2 == NULL) { - __try - { - tempBuf = (wchar_t*)alloca((destlen + 1) * sizeof(wchar_t)); - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - tempBuf = NULL; - needs_free = true; - } - } - - if ( tempBuf == NULL ) { - tempBuf = (wchar_t*)malloc((destlen + 1) * sizeof(wchar_t)); - if ( tempBuf == NULL ) - return NULL; - } - - Utf8toUcs2(str, len, tempBuf, destlen); - tempBuf[destlen] = 0; - WideCharToMultiByte(codepage, 0, tempBuf, -1, str, len + 1, "?", NULL); - - if (ucs2) - *ucs2 = tempBuf; - else if (needs_free) - free(tempBuf); - - return str; -} - -wchar_t* Utf8DecodeUcs2(const char* str) -{ - if (str == NULL) - return NULL; - - int len = (int)strlen(str); - - int destlen = Utf8toUcs2Len(str, len); - if (destlen < 0) return NULL; - - wchar_t* ucs2 = (wchar_t*)malloc((destlen + 1) * sizeof(wchar_t)); - if (ucs2 == NULL) return NULL; - - if (Utf8toUcs2(str, len, ucs2, destlen) >= 0) - { - ucs2[destlen] = 0; - return ucs2; - } - - free(ucs2); - - return NULL; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Utf8Encode - converts MBCS string to the UTF8-encoded format - -char* Utf8EncodeCP(const char* src, int codepage) -{ - int len; - bool needs_free = false; - char* result = NULL; - wchar_t* tempBuf; - - if (src == NULL) - return NULL; - - len = (int)strlen(src); - - __try - { - tempBuf = (wchar_t*)alloca((len + 1) * sizeof(wchar_t)); - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - tempBuf = (wchar_t*)malloc((len + 1) * sizeof(wchar_t)); - if (tempBuf == NULL) return NULL; - needs_free = true; - } - - len = MultiByteToWideChar(codepage, 0, src, -1, tempBuf, len + 1); - - int destlen = Ucs2toUtf8Len(tempBuf, len); - if (destlen >= 0) - { - result = (char*)malloc(destlen + 1); - if (result) - { - Ucs2toUtf8(tempBuf, len, result, destlen); - result[destlen] = 0; - } - } - - if (needs_free) - free(tempBuf); - - return result; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Utf8Encode - converts UCS2 string to the UTF8-encoded format - -char* Utf8EncodeUcs2(const wchar_t* src) -{ - if (src == NULL) - return NULL; - - int len = (int)wcslen(src); - - int destlen = Ucs2toUtf8Len(src, len); - if (destlen < 0) return NULL; - - char* result = (char*)malloc(destlen + 1); - if (result == NULL) - return NULL; - - Ucs2toUtf8(src, len, result, destlen); - result[destlen] = 0; - - return result; -} - bool is_utf8_string(const char* str) { int expect_bytes = 0, utf_found = 0; diff --git a/plugins/Dbx_mmap_SA/Dbtool/wizard.cpp b/plugins/Dbx_mmap_SA/Dbtool/wizard.cpp index ab3c46f360..8f3a9d5ca8 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/wizard.cpp +++ b/plugins/Dbx_mmap_SA/Dbtool/wizard.cpp @@ -97,7 +97,7 @@ INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lPara SendMessage(hdlg,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_DBTOOL))); hdlgPage=NULL; SendMessage(hdlg,WZM_GOTOPAGE,IDD_WELCOME,(LPARAM)WelcomeDlgProc); - TranslateDialog(hdlg); + TranslateDialogDefault(hdlg); return TRUE; case WZM_GOTOPAGE: if(hdlgPage!=NULL) DestroyWindow(hdlgPage); @@ -106,7 +106,7 @@ INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lPara EnableWindow(GetDlgItem(hdlg,IDCANCEL),TRUE); SetDlgItemText(hdlg,IDCANCEL,TranslateT("Cancel")); hdlgPage=CreateDialog(hInst,MAKEINTRESOURCE(wParam),hdlg,(DLGPROC)lParam); - TranslateDialog(hdlgPage); + TranslateDialogDefault(hdlgPage); SetWindowPos(hdlgPage,0,0,0,0,0,SWP_NOZORDER|SWP_NOSIZE); ShowWindow(hdlgPage,SW_SHOW); break; @@ -129,7 +129,6 @@ INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lPara if (opts.hOutFile) CloseHandle(opts.hOutFile); DestroyWindow(hdlgPage); - UnloadLangPackModule(); if(hBoldFont!=NULL) DeleteObject(hBoldFont); if(hEmfHeaderLogo!=NULL) DeleteEnhMetaFile(hEmfHeaderLogo); break; diff --git a/plugins/Dbx_mmap_SA/commonheaders.h b/plugins/Dbx_mmap_SA/commonheaders.h index 6d5dcd8d21..065fc3ab3e 100644 --- a/plugins/Dbx_mmap_SA/commonheaders.h +++ b/plugins/Dbx_mmap_SA/commonheaders.h @@ -29,8 +29,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //windows headers #include - +#include #include + #include #include #include diff --git a/plugins/Dbx_mmap_SA/dialogs.cpp b/plugins/Dbx_mmap_SA/dialogs.cpp index ffa0516fae..d8878a2dd1 100644 --- a/plugins/Dbx_mmap_SA/dialogs.cpp +++ b/plugins/Dbx_mmap_SA/dialogs.cpp @@ -4,8 +4,6 @@ #include #include -#include - #define MS_DB_CHANGEPASSWORD "DB/ChangePassword" extern char encryptKey[255]; diff --git a/plugins/IEView/HTMLBuilder.cpp b/plugins/IEView/HTMLBuilder.cpp index 9fa9e24824..e4211cac74 100644 --- a/plugins/IEView/HTMLBuilder.cpp +++ b/plugins/IEView/HTMLBuilder.cpp @@ -222,7 +222,7 @@ void HTMLBuilder::getUINs(HANDLE hContact, char *&uinIn, char *&uinOut) { switch (ci.type) { case CNFT_ASCIIZ: mir_snprintf(buf, sizeof(buf), "%s", ci.pszVal); - miranda_sys_free(ci.pszVal); + mir_free(ci.pszVal); break; case CNFT_DWORD: mir_snprintf(buf, sizeof(buf), "%u", ci.dVal); @@ -236,7 +236,7 @@ void HTMLBuilder::getUINs(HANDLE hContact, char *&uinIn, char *&uinOut) { switch (ci.type) { case CNFT_ASCIIZ: mir_snprintf(buf, sizeof(buf), "%s", ci.pszVal); - miranda_sys_free(ci.pszVal); + mir_free(ci.pszVal); break; case CNFT_DWORD: mir_snprintf(buf, sizeof(buf), "%u", ci.dVal); @@ -266,7 +266,7 @@ wchar_t *HTMLBuilder::getContactName(HANDLE hContact, const char* szProto) { } else { szName = Utils::dupString((wchar_t *)ci.pszVal); } - miranda_sys_free(ci.pszVal); + mir_free(ci.pszVal); } } } @@ -276,7 +276,7 @@ wchar_t *HTMLBuilder::getContactName(HANDLE hContact, const char* szProto) { if (ci.type == CNFT_ASCIIZ) { if (ci.pszVal) { szName = Utils::convertToWCS((char *)ci.pszVal); - miranda_sys_free(ci.pszVal); + mir_free(ci.pszVal); } } } diff --git a/plugins/IEView/ieview_main.cpp b/plugins/IEView/ieview_main.cpp index cc0facd49b..3f0aa95289 100644 --- a/plugins/IEView/ieview_main.cpp +++ b/plugins/IEView/ieview_main.cpp @@ -86,7 +86,6 @@ extern "C" int __declspec(dllexport) Load(PLUGINLINK *link) _strupr(ieviewModuleName); pluginLink = link; - mir_getMMI( &mmi ); mir_getLP(&pluginInfoEx); Utils::hookEvent_Ex(ME_OPT_INITIALISE, IEViewOptInit); diff --git a/plugins/LangMan/common.h b/plugins/LangMan/common.h index 1f47d8ef75..4ac9deb5b5 100644 --- a/plugins/LangMan/common.h +++ b/plugins/LangMan/common.h @@ -26,7 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma warning(disable:4201) /* nonstandard extension used : nameless struct/union */ #include #pragma warning(default:4201) /* nonstandard extension used : nameless struct/union */ -#include +#include +#include #include #include /* for mir_snprintf() */ @@ -44,6 +45,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include "langpack.h" #include "options.h" diff --git a/plugins/LangMan/options.cpp b/plugins/LangMan/options.cpp index a3347c7ac6..72f78dd597 100644 --- a/plugins/LangMan/options.cpp +++ b/plugins/LangMan/options.cpp @@ -20,8 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "common.h" -#include -#include extern HINSTANCE hInst; static HANDLE hHookOptInit; diff --git a/plugins/MirOTR/libgcrypt-1.4.6/cipher/cipher.c b/plugins/MirOTR/libgcrypt-1.4.6/cipher/cipher.c index 8cfe54fce1..f692159e2e 100644 --- a/plugins/MirOTR/libgcrypt-1.4.6/cipher/cipher.c +++ b/plugins/MirOTR/libgcrypt-1.4.6/cipher/cipher.c @@ -321,11 +321,11 @@ gcry_cipher_lookup_func_name (void *spec, void *data) gcry_cipher_spec_t *cipher = (gcry_cipher_spec_t *) spec; char *name = (char *) data; const char **aliases = cipher->aliases; - int i, ret = ! stricmp (name, cipher->name); + int i, ret = !_stricmp (name, cipher->name); if (aliases) for (i = 0; aliases[i] && (! ret); i++) - ret = ! stricmp (name, aliases[i]); + ret = !_stricmp (name, aliases[i]); return ret; } @@ -341,7 +341,7 @@ gcry_cipher_lookup_func_oid (void *spec, void *data) if (oid_specs) for (i = 0; oid_specs[i].oid && (! ret); i++) - if (! stricmp (oid, oid_specs[i].oid)) + if (!_stricmp (oid, oid_specs[i].oid)) ret = 1; return ret; @@ -437,7 +437,7 @@ search_oid (const char *oid, int *algorithm, gcry_cipher_oid_spec_t *oid_spec) int i; for (i = 0; cipher->oids[i].oid && !ret; i++) - if (! stricmp (oid, cipher->oids[i].oid)) + if (!_stricmp (oid, cipher->oids[i].oid)) { if (algorithm) *algorithm = module->mod_id; diff --git a/plugins/Popup/src/main.cpp b/plugins/Popup/src/main.cpp index 84b1921aa2..06779ef5d5 100644 --- a/plugins/Popup/src/main.cpp +++ b/plugins/Popup/src/main.cpp @@ -504,7 +504,6 @@ MIRAPI int Load(PLUGINLINK *link) DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hMainThread, THREAD_SET_CONTEXT, FALSE, 0); mir_getLI (&li); - mir_getMMI (&mmi); mir_getUTFI (&utfi); mir_getMTI (&MText); mir_getLP(&pluginInfoEx); diff --git a/plugins/SRMM/cmdlist.cpp b/plugins/SRMM/cmdlist.cpp index 1034b57949..91d082fc74 100644 --- a/plugins/SRMM/cmdlist.cpp +++ b/plugins/SRMM/cmdlist.cpp @@ -31,13 +31,13 @@ int tcmdlist_append(SortedList *list, TCHAR *data) TCmdList* n = (TCmdList*)list->items[0]; mir_free(n->szCmd); mir_free(n); - li.List_Remove(list, 0); + List_Remove(list, 0); } new_list = (TCmdList*)mir_alloc(sizeof(TCmdList)); new_list->szCmd = mir_tstrdup(data); - li.List_InsertPtr(list, new_list); + List_InsertPtr(list, new_list); return list->realCount - 1; } @@ -52,7 +52,7 @@ void tcmdlist_free(SortedList *list) mir_free(n[i]->szCmd); mir_free(n[i]); } - li.List_Destroy(list); + List_Destroy(list); mir_free(list); } @@ -78,7 +78,7 @@ static VOID CALLBACK MsgTimer(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTi tmlst = (TMsgQueue**)alloca((msgQueue.realCount - i) * sizeof(TMsgQueue*)); tmlst[ntl++] = item; - li.List_Remove(&msgQueue, i--); + List_Remove(&msgQueue, i--); } } LeaveCriticalSection(&csMsgQueue); @@ -99,7 +99,7 @@ void msgQueue_add(HANDLE hContact, HANDLE id, const TCHAR* szMsg, HANDLE hDbEven EnterCriticalSection(&csMsgQueue); if (!msgQueue.realCount && !timerId) timerId = SetTimer(NULL, 0, 5000, MsgTimer); - li.List_InsertPtr(&msgQueue, item); + List_InsertPtr(&msgQueue, item); LeaveCriticalSection(&csMsgQueue); } @@ -116,7 +116,7 @@ void msgQueue_processack(HANDLE hContact, HANDLE id, BOOL success, const char* s item = (TMsgQueue*)msgQueue.items[i]; if (item->hContact == hContact && item->id == id) { - li.List_Remove(&msgQueue, i); + List_Remove(&msgQueue, i); if (!msgQueue.realCount && timerId) { @@ -158,7 +158,7 @@ void msgQueue_destroy(void) mir_free(item->szMsg); mir_free(item); } - li.List_Destroy(&msgQueue); + List_Destroy(&msgQueue); LeaveCriticalSection(&csMsgQueue); diff --git a/plugins/SRMM/msgdialog.cpp b/plugins/SRMM/msgdialog.cpp index 6726dc4258..df25b409e0 100644 --- a/plugins/SRMM/msgdialog.cpp +++ b/plugins/SRMM/msgdialog.cpp @@ -784,7 +784,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP dat->wStatus = ID_STATUS_OFFLINE; dat->wOldStatus = dat->wStatus; dat->splitterPos = (int) DBGetContactSettingDword(DBGetContactSettingByte(NULL, SRMMMOD, SRMSGSET_SAVEPERCONTACT, SRMSGDEFSET_SAVEPERCONTACT)?dat->hContact:NULL, SRMMMOD, "splitterPos", (DWORD) - 1); - dat->cmdList = li.List_Create(0, 20); + dat->cmdList = List_Create(0, 20); dat->cmdListInd = -1; dat->nTypeMode = PROTOTYPE_SELFTYPING_OFF; SetTimer(hwndDlg, TIMERID_TYPE, 1000, NULL); diff --git a/plugins/SRMM/richutil.cpp b/plugins/SRMM/richutil.cpp index 92065ca0c8..7f77c98fa8 100644 --- a/plugins/SRMM/richutil.cpp +++ b/plugins/SRMM/richutil.cpp @@ -94,7 +94,7 @@ void RichUtil_Load(void) void RichUtil_Unload(void) { - li.List_Destroy(&sListInt); + List_Destroy(&sListInt); DeleteCriticalSection(&csRich); if (mTheme) FreeLibrary(mTheme); @@ -112,8 +112,8 @@ int RichUtil_SubClass(HWND hwndEdit) ru->hasUglyBorder = 0; EnterCriticalSection(&csRich); - if (!li.List_GetIndex(&sListInt, ru, &idx)) - li.List_Insert(&sListInt, ru, idx); + if (!List_GetIndex(&sListInt, ru, &idx)) + List_Insert(&sListInt, ru, idx); LeaveCriticalSection(&csRich); ru->origProc = (WNDPROC)SetWindowLongPtr(ru->hwnd, GWLP_WNDPROC, (LONG_PTR)&RichUtil_Proc); @@ -128,7 +128,7 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM TRichUtil *ru; EnterCriticalSection(&csRich); - ru = (TRichUtil *)li.List_Find(&sListInt, (TRichUtil*)&hwnd); + ru = (TRichUtil *)List_Find(&sListInt, (TRichUtil*)&hwnd); LeaveCriticalSection(&csRich); if (ru == NULL) return 0; @@ -246,7 +246,7 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } EnterCriticalSection(&csRich); - li.List_RemovePtr(&sListInt, ru); + List_RemovePtr(&sListInt, ru); LeaveCriticalSection(&csRich); mir_free(ru); diff --git a/plugins/Scriver/msglog.cpp b/plugins/Scriver/msglog.cpp index eaf139ce02..bb768cbb95 100644 --- a/plugins/Scriver/msglog.cpp +++ b/plugins/Scriver/msglog.cpp @@ -111,7 +111,7 @@ TCHAR *GetNickname(HANDLE hContact, const char* szProto) { szName = a2t((char *)ci.pszVal); } - miranda_sys_free(ci.pszVal); + mir_free(ci.pszVal); if (szName != NULL) { return szName; } diff --git a/plugins/Scriver/richutil.cpp b/plugins/Scriver/richutil.cpp index 52dff7505f..069d0cfaac 100644 --- a/plugins/Scriver/richutil.cpp +++ b/plugins/Scriver/richutil.cpp @@ -100,7 +100,7 @@ void RichUtil_Load(void) void RichUtil_Unload(void) { - li.List_Destroy(&sListInt); + List_Destroy(&sListInt); DeleteCriticalSection(&csRich); if (mTheme) FreeLibrary(mTheme); @@ -118,8 +118,8 @@ int RichUtil_SubClass(HWND hwndEdit) ru->hasUglyBorder = 0; EnterCriticalSection(&csRich); - if (!li.List_GetIndex(&sListInt, ru, &idx)) - li.List_Insert(&sListInt, ru, idx); + if (!List_GetIndex(&sListInt, ru, &idx)) + List_Insert(&sListInt, ru, idx); LeaveCriticalSection(&csRich); ru->origProc = (WNDPROC)SetWindowLongPtr(ru->hwnd, GWLP_WNDPROC, (LONG_PTR)&RichUtil_Proc); @@ -137,7 +137,7 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM tru.hwnd = hwnd; EnterCriticalSection(&csRich); - if (li.List_GetIndex(&sListInt, &tru, &idx)) + if (List_GetIndex(&sListInt, &tru, &idx)) ru = (TRichUtil*)sListInt.items[idx]; LeaveCriticalSection(&csRich); @@ -242,7 +242,7 @@ static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } EnterCriticalSection(&csRich); - li.List_Remove(&sListInt, idx); + List_Remove(&sListInt, idx); LeaveCriticalSection(&csRich); mir_free(ru); diff --git a/plugins/Scriver/utils.cpp b/plugins/Scriver/utils.cpp index e9a9dacad2..3551119adc 100644 --- a/plugins/Scriver/utils.cpp +++ b/plugins/Scriver/utils.cpp @@ -545,7 +545,7 @@ void GetContactUniqueId(struct SrmmWindowData *dat, char *buf, int maxlen) { switch (ci.type) { case CNFT_ASCIIZ: mir_snprintf(buf, maxlen, "%s", ci.pszVal); - miranda_sys_free(ci.pszVal); + mir_free(ci.pszVal); break; case CNFT_DWORD: mir_snprintf(buf, maxlen, "%u", ci.dVal); diff --git a/plugins/SmileyAdd/regexp/WCPattern.cpp b/plugins/SmileyAdd/regexp/WCPattern.cpp index d396bd187d..25f379f5e4 100644 --- a/plugins/SmileyAdd/regexp/WCPattern.cpp +++ b/plugins/SmileyAdd/regexp/WCPattern.cpp @@ -117,7 +117,7 @@ bkstring WCPattern::classUnion (bkstring s1, bkstring s2) const wchar_t * out = new wchar_t[66000]; std::sort(s1.begin(), s1.end()); std::sort(s2.begin(), s2.end()); - *std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), out) = 0; + wchar_t* p = std::set_union(s1.begin(), s1.end(), s2.begin(), s2.end(), out); *p = 0; bkstring ret = out; delete [] out; return ret; diff --git a/plugins/Svc_dbepp/dbeditorpp_10.vcxproj.filters b/plugins/Svc_dbepp/dbeditorpp_10.vcxproj.filters index 7b41fd05dd..f0f8d79957 100644 --- a/plugins/Svc_dbepp/dbeditorpp_10.vcxproj.filters +++ b/plugins/Svc_dbepp/dbeditorpp_10.vcxproj.filters @@ -36,9 +36,6 @@ Source Files - - Source Files - Source Files\ModSetting Enuming diff --git a/plugins/Svc_dbepp/exportimport.cpp b/plugins/Svc_dbepp/exportimport.cpp index 14faf47198..ad9f508a21 100644 --- a/plugins/Svc_dbepp/exportimport.cpp +++ b/plugins/Svc_dbepp/exportimport.cpp @@ -365,19 +365,6 @@ HANDLE CheckNewContact(char *myProto, char *uid, char *myName) } -TCHAR* __stdcall rtrim(TCHAR *string) -{ - TCHAR* p = string + _tcslen(string) - 1; - - while (p >= string) { - if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r') - break; - - *p-- = 0; - } - return string; -} - HANDLE Clist_GroupExists(WCHAR *tszGroup) { unsigned int i = 0; diff --git a/plugins/Svc_dbepp/headers.h b/plugins/Svc_dbepp/headers.h index 57663f56e1..e90738306b 100644 --- a/plugins/Svc_dbepp/headers.h +++ b/plugins/Svc_dbepp/headers.h @@ -211,9 +211,6 @@ void __cdecl PopulateModuleTreeThreadFunc(LPVOID di); void freeTree(HWND hwnd2Tree, HANDLE hContact); int findItemInTree(HWND hwnd2Tree, HANDLE hContact, char* module); -// threads.c -unsigned long forkthread ( void (__cdecl *threadcode)(void*),unsigned long stacksize,void *arg) ; - // settinglist.c void setupSettingsList(HWND hwnd2List); void saveListSettings(HWND hwnd2List); diff --git a/plugins/Svc_dbepp/watchedvars.cpp b/plugins/Svc_dbepp/watchedvars.cpp index 083a23b4b2..b7d2cf6b73 100644 --- a/plugins/Svc_dbepp/watchedvars.cpp +++ b/plugins/Svc_dbepp/watchedvars.cpp @@ -204,15 +204,8 @@ INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ListView_InsertColumn(GetDlgItem(hwnd, IDC_VARS),4,&sLC); PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS)); -/* if (DBGetContactSettingByte("NULL", modname, "LoadWatchesOnStartup",0)) - { - MENUITEMINFO mmi; - mmi.cbSize = sizeof(MENUITEMINFO); - mmi.fMask = MIIM_STATE; - mmi.fState = MFS_CHECKED; - SetMenuItemInfo(GetMenu(hwnd), MENU_LOADAUTOMATCIALLY, FALSE, &mmi); - } -*/ TranslateMenu(GetMenu(hwnd)); + + TranslateMenu(GetMenu(hwnd)); TranslateMenu(GetSubMenu(GetMenu(hwnd),0)); TranslateDialogDefault(hwnd); // do the icon @@ -247,43 +240,17 @@ INT_PTR CALLBACK WatchDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case MENU_REMALL_WATCHES: freeAllWatches(); ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_VARS)); - break; + break; case MENU_EXIT: case IDCANCEL: hwnd2watchedVarsWindow = 0; DestroyWindow(hwnd); - break; + break; case MENU_REFRESH: PopulateWatchedWindow(GetDlgItem(hwnd, IDC_VARS)); - break; - /* case MENU_LOADAUTOMATCIALLY: - { - MENUITEMINFO mmi; - mmi.cbSize = sizeof(MENUITEMINFO); - mmi.fMask = MIIM_STATE; - GetMenuItemInfo(GetSubMenu(GetMenu(hwnd),2), MENU_LOADAUTOMATCIALLY, FALSE, &mmi); - if (mmi.fState == MFS_CHECKED) - { - mmi.fState = MFS_UNCHECKED; - DBWriteContactSettingByte(NULL,modname, "LoadWatchesOnStartup", 0); - SetMenuItemInfo(GetSubMenu(GetMenu(hwnd),2), MENU_LOADAUTOMATCIALLY, FALSE, &mmi); - } - else if (mmi.fState == MFS_UNCHECKED) - { - mmi.fState = MFS_CHECKED; - DBWriteContactSettingByte(NULL,modname, "LoadWatchesOnStartup", 1); - SetMenuItemInfo(GetSubMenu(GetMenu(hwnd),2), MENU_LOADAUTOMATCIALLY, FALSE, &mmi); - } - } - break; - case MENU_SAVE_WATCHES: - saveWatchedList(); - break; - case MENU_LOAD_WATCHES: - loadWatchedList(); - break; - */ } - break; + } + break; + case WM_NOTIFY: switch(LOWORD(wParam)) { diff --git a/plugins/TabSRMM/chat/message.cpp b/plugins/TabSRMM/chat/message.cpp index 0a7f56b594..d8682bb1da 100644 --- a/plugins/TabSRMM/chat/message.cpp +++ b/plugins/TabSRMM/chat/message.cpp @@ -294,7 +294,7 @@ TCHAR* Chat_DoRtfToTags(char* pszText, SESSION_INFO* si) } mir_free(pIndex); - ptszResult = M->utf8_decodeW(pszText); + ptszResult = mir_utf8decodeW(pszText); return ptszResult; } diff --git a/plugins/TabSRMM/chat/tools.cpp b/plugins/TabSRMM/chat/tools.cpp index 3d8d54b381..04fba1aa40 100644 --- a/plugins/TabSRMM/chat/tools.cpp +++ b/plugins/TabSRMM/chat/tools.cpp @@ -1159,7 +1159,7 @@ TCHAR* a2tf(const TCHAR* str, int flags, DWORD cp) TCHAR *result; if (cp == CP_UTF8) - return(M->utf8_decodeW((char *)str)); + return(mir_utf8decodeW((char *)str)); if (cp == 0) cp = PluginConfig.m_LangPackCP; // CallService( MS_LANGPACK_GETCODEPAGE, 0, 0 ); @@ -1182,7 +1182,7 @@ static char* u2a(const wchar_t* src, DWORD cp) if (cp == 0) cp = PluginConfig.m_LangPackCP; else if (cp == CP_UTF8) - return(M->utf8_encodeW(src)); + return(mir_utf8encodeT(src)); cbLen = WideCharToMultiByte(cp, 0, src, -1, NULL, 0, NULL, NULL); result = (char*)mir_alloc(cbLen + 1); diff --git a/plugins/TabSRMM/include/mim.h b/plugins/TabSRMM/include/mim.h index 286848aa11..9ce72e3e69 100644 --- a/plugins/TabSRMM/include/mim.h +++ b/plugins/TabSRMM/include/mim.h @@ -43,7 +43,7 @@ extern FI_INTERFACE *FIF; * Win32 API definitions of functions dynamically obtained via GetProcAddress() * - uxtheme * - dwmapi - * - some GDI functions (AlphaBlend()..) + * - some GDI functions (AlphaBlend()..) */ typedef BOOL (WINAPI *SMI)( HMENU hmenu, LPCMENUINFO lpcmi ); typedef HRESULT (WINAPI *DEFICA)(HWND hwnd, const MARGINS *margins); @@ -97,7 +97,6 @@ class CMimAPI public: CMimAPI() { - GetUTFI(); InitPaths(); InitAPI(); getAeroState(); @@ -148,19 +147,6 @@ public: INT_PTR FASTCALL WriteTString (const HANDLE hContact, const char *szModule, const char *szSetting, const TCHAR *st) const; - /* - * utf helpers - */ - - char* FASTCALL utf8_decode (char* str, wchar_t** ucs2) const; - char* FASTCALL utf8_decodecp (char* str, int codepage, wchar_t** ucs2) const; - char* FASTCALL utf8_encode (const char* src) const; - char* FASTCALL utf8_encodecp (const char* src, int codepage) const; - char* FASTCALL utf8_encodeW (const wchar_t* src) const; - char* FASTCALL utf8_encodeT (const TCHAR* src) const; - TCHAR* FASTCALL utf8_decodeT (const char* src) const; - wchar_t* FASTCALL utf8_decodeW (const char* str) const; - /* * path utilities */ @@ -277,7 +263,6 @@ public: static bool m_shutDown, m_haveBufferedPaint; private: - UTF8_INTERFACE m_utfi; TCHAR m_szProfilePath[MAX_PATH + 2], m_szSkinsPath[MAX_PATH + 2], m_szSavedAvatarsPath[MAX_PATH + 2], m_szChatLogsPath[MAX_PATH + 2]; HMODULE m_hUxTheme, m_hDwmApi; bool m_VsAPI; @@ -292,7 +277,6 @@ private: HANDLE m_hChatLogLock; void InitAPI(); - void GetUTFI(); void InitPaths(); private: diff --git a/plugins/TabSRMM/src/buttonsbar.cpp b/plugins/TabSRMM/src/buttonsbar.cpp index 2f2c59ad6e..8822e094fd 100644 --- a/plugins/TabSRMM/src/buttonsbar.cpp +++ b/plugins/TabSRMM/src/buttonsbar.cpp @@ -41,7 +41,7 @@ static void li_ListDestruct(SortedList *pList, ItemDestuctor pItemDestructor) int i = 0; if (!pList) return; for (i = 0; i < pList->realCount; i++) pItemDestructor(pList->items[i]); - li.List_Destroy(pList); + List_Destroy(pList); mir_free(pList); } @@ -49,13 +49,13 @@ static void li_RemoveDestruct(SortedList *pList, int index, ItemDestuctor pItemD { if (index >= 0 && index < pList->realCount) { pItemDestructor(pList->items[index]); - li.List_Remove(pList, index); + List_Remove(pList, index); } } static void li_RemovePtrDestruct(SortedList *pList, void * ptr, ItemDestuctor pItemDestructor) { - if (li.List_RemovePtr(pList, ptr)) + if (List_RemovePtr(pList, ptr)) pItemDestructor(ptr); } @@ -137,8 +137,8 @@ static int Hlp_RemoveDatabaseSettings(HANDLE hContact, char *szModule, char *szP void CB_InitCustomButtons() { - LButtonsList = li.List_Create(0, 1); - RButtonsList = li.List_Create(0, 1); + LButtonsList = List_Create(0, 1); + RButtonsList = List_Create(0, 1); InitializeCriticalSection(&ToolBarCS); dwSepCount = M->GetDword("TabSRMM_Toolbar", "SeparatorsCount", 0); @@ -228,9 +228,9 @@ void CB_ReInitCustomButtons() cbd->opFlags ^= BBSF_NTBSWAPED; if (!(cbd->opFlags&BBSF_NTBDESTRUCT)) - li.List_InsertPtr(RButtonsList, cbd); + List_InsertPtr(RButtonsList, cbd); - li.List_Remove(LButtonsList, i); + List_Remove(LButtonsList, i); i--; } } @@ -241,9 +241,9 @@ void CB_ReInitCustomButtons() cbd->opFlags ^= BBSF_NTBSWAPED; if (!(cbd->opFlags&BBSF_NTBDESTRUCT)) - li.List_InsertPtr(LButtonsList, cbd); + List_InsertPtr(LButtonsList, cbd); - li.List_Remove(RButtonsList, i); + List_Remove(RButtonsList, i); i--; } } @@ -257,8 +257,8 @@ void CB_HardReInit() EnterCriticalSection(&ToolBarCS); li_ListDestruct(LButtonsList, listdestructor); li_ListDestruct(RButtonsList, listdestructor); - LButtonsList = li.List_Create(0, 1); - RButtonsList = li.List_Create(0, 1); + LButtonsList = List_Create(0, 1); + RButtonsList = List_Create(0, 1); LeaveCriticalSection(&ToolBarCS); LastCID = 4000; dwSepCount = 0; @@ -313,9 +313,9 @@ static INT_PTR CB_AddButton(WPARAM wParam, LPARAM lParam) CB_GetButtonSettings(NULL, cbd); if (cbd->bLSided) - li.List_InsertPtr(LButtonsList, cbd); + List_InsertPtr(LButtonsList, cbd); else if (cbd->bRSided) - li.List_InsertPtr(RButtonsList, cbd); + List_InsertPtr(RButtonsList, cbd); else return 1; if (cbd->dwButtonCID != cbd->dwButtonOrigID) @@ -415,7 +415,7 @@ static INT_PTR CB_RemoveButton(WPARAM wParam, LPARAM lParam) if (!strcmp(cbd->pszModuleName, bbdi->pszModuleName) && (cbd->dwButtonOrigID == bbdi->dwButtonID)) { tempCID = cbd->dwButtonCID; dwFlags = cbd->bLSided ? BBBF_ISLSIDEBUTTON : BBBF_ISRSIDEBUTTON; - li.List_Remove(LButtonsList, i); + List_Remove(LButtonsList, i); i--; } } @@ -427,7 +427,7 @@ static INT_PTR CB_RemoveButton(WPARAM wParam, LPARAM lParam) if (!strcmp(cbd->pszModuleName, bbdi->pszModuleName) && (cbd->dwButtonOrigID == bbdi->dwButtonID)) { tempCID = cbd->dwButtonCID; dwFlags = cbd->bLSided ? BBBF_ISLSIDEBUTTON : BBBF_ISRSIDEBUTTON; - li.List_Remove(RButtonsList, i); + List_Remove(RButtonsList, i); i--; } } @@ -1420,7 +1420,7 @@ INT_PTR CALLBACK DlgProcToolBar(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM l cbd->pszModuleName = "Tabsrmm_sep"; cbd->iButtonWidth = 22; cbd->opFlags = BBSF_NTBDESTRUCT; - li.List_InsertPtr(LButtonsList, cbd); + List_InsertPtr(LButtonsList, cbd); tvis.hParent = NULL; tvis.hInsertAfter = hti; diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index a1c7d1033e..aa242d977c 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -825,7 +825,7 @@ void CGlobals::logStatusChange(WPARAM wParam, const CContactCache *c) mir_sntprintf(buffer, safe_sizeof(buffer), TranslateT("changed status from %s to %s."), szOldStatus, szNewStatus); } - char *szMsg = M->utf8_encodeT(buffer); + char *szMsg = mir_utf8encodeT(buffer); dbei.pBlob = (PBYTE)szMsg; dbei.cbBlob = lstrlenA(szMsg) + 1; diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp index 11ede3460e..95b5375132 100644 --- a/plugins/TabSRMM/src/infopanel.cpp +++ b/plugins/TabSRMM/src/infopanel.cpp @@ -1389,7 +1389,7 @@ CTip::CTip(const HWND hwndParent, const HANDLE hContact, const TCHAR *pszText, c m_hContact = hContact; if(pszText) - m_pszText = M->utf8_encodeT(pszText); + m_pszText = mir_utf8encodeT(pszText); else m_pszText = 0; m_panel = panel; diff --git a/plugins/TabSRMM/src/mim.cpp b/plugins/TabSRMM/src/mim.cpp index dfd38998fd..dd4999d480 100644 --- a/plugins/TabSRMM/src/mim.cpp +++ b/plugins/TabSRMM/src/mim.cpp @@ -182,48 +182,6 @@ INT_PTR CMimAPI::WriteTString(const HANDLE hContact, const char *szModule = 0, c return(DBWriteContactSettingTString(hContact, szModule, szSetting, str)); } -void CMimAPI::GetUTFI() -{ - mir_getUTFI(&m_utfi); -} -char *CMimAPI::utf8_decode(char* str, wchar_t** ucs2) const -{ - return(m_utfi.utf8_decode(str, ucs2)); -} -char *CMimAPI::utf8_decodecp(char* str, int codepage, wchar_t** ucs2 ) const -{ - return(m_utfi.utf8_decodecp(str, codepage, ucs2)); -} -char *CMimAPI::utf8_encode(const char* src) const -{ - return(m_utfi.utf8_encode(src)); -} - -char *CMimAPI::utf8_encodecp(const char* src, int codepage) const -{ - return(m_utfi.utf8_encodecp(src, codepage)); -} - -char *CMimAPI::utf8_encodeW(const wchar_t* src) const -{ - return(m_utfi.utf8_encodeW(src)); -} - -char *CMimAPI::utf8_encodeT(const TCHAR* src) const -{ - return(m_utfi.utf8_encodeW(src)); -} - -TCHAR *CMimAPI::utf8_decodeT(const char* src) const -{ - return(m_utfi.utf8_decodeW(src)); -} - -wchar_t *CMimAPI::utf8_decodeW(const char* str) const -{ - return(m_utfi.utf8_decodeW(str)); -} - /** * Case insensitive _tcsstr * diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 9f59917293..5699b03e3c 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -3009,7 +3009,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP streamOut = Message_GetFromStream(GetDlgItem(hwndDlg, IDC_MESSAGE), dat, final_sendformat ? 0 : (CP_UTF8 << 16) | (SF_TEXT | SF_USECODEPAGE)); if (streamOut != NULL) { - decoded = M->utf8_decodeW(streamOut); + decoded = mir_utf8decodeW(streamOut); if (decoded != NULL) { char* utfResult = NULL; if (final_sendformat) @@ -3022,7 +3022,7 @@ INT_PTR CALLBACK DlgProcMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP memRequired = bufSize + ((lstrlenW(decoded) + 1) * sizeof(WCHAR)); } else { flags |= PREF_UTF; - utfResult = M->utf8_encodeW(decoded); + utfResult = mir_utf8encodeT(decoded); memRequired = (int)(strlen(utfResult)) + 1; } @@ -3158,7 +3158,7 @@ quote_from_last: CallService(MS_DB_EVENT_GET, (WPARAM)hDBEvent, (LPARAM)&dbei); iSize = (int)(strlen((char *)dbei.pBlob)) + 1; if (dbei.flags & DBEF_UTF) { - szConverted = M->utf8_decodeW((char*)szText); + szConverted = mir_utf8decodeW((char*)szText); iAlloced = TRUE; } else { if (iSize != dbei.cbBlob) @@ -3188,7 +3188,7 @@ quote_from_last: } else { wchar_t *converted = 0; szFromStream = Message_GetFromStream(GetDlgItem(hwndDlg, IDC_LOG), dat, SF_TEXT | SF_USECODEPAGE | SFF_SELECTION); - converted = M->utf8_decodeW(szFromStream); + converted = mir_utf8decodeW(szFromStream); Utils::FilterEventMarkers(converted); szQuoted = QuoteText(converted, iCharsPerLine, 0); SendDlgItemMessage(hwndDlg, IDC_MESSAGE, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)szQuoted); diff --git a/plugins/TabSRMM/src/sendlater.cpp b/plugins/TabSRMM/src/sendlater.cpp index 4490f8b2e6..1cc4a68785 100644 --- a/plugins/TabSRMM/src/sendlater.cpp +++ b/plugins/TabSRMM/src/sendlater.cpp @@ -367,7 +367,7 @@ int CSendLater::addJob(const char *szSetting, LPARAM lParam) * construct conventional send buffer */ - szAnsi = M->utf8_decodecp(szOrig_Utf, CP_ACP, &szWchar); + szAnsi = mir_utf8decodecp(szOrig_Utf, CP_ACP, &szWchar); iLen = lstrlenA(szAnsi); if(szWchar) required = iLen + 1 + ((lstrlenW(szWchar) + 1) * sizeof(wchar_t)); @@ -640,7 +640,7 @@ void CSendLater::qMgrFillList(bool fClear) lvItem.iSubItem = 1; ::SendMessage(m_hwndList, LVM_SETITEM, 0, reinterpret_cast(&lvItem)); - TCHAR* msg = M->utf8_decodeT((*it)->sendBuffer); + TCHAR* msg = mir_utf8decodeT((*it)->sendBuffer); TCHAR* preview = Utils::GetPreviewWithEllipsis(msg, 255); lvItem.pszText = preview; lvItem.iSubItem = 2; @@ -919,7 +919,7 @@ INT_PTR CALLBACK CSendLater::DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM job->writeFlags(); break; case ID_QUEUEMANAGER_COPYMESSAGETOCLIPBOARD: { - TCHAR *msg = M->utf8_decodeT(job->sendBuffer); + TCHAR *msg = mir_utf8decodeT(job->sendBuffer); Utils::CopyToClipBoard(msg, m_hwndDlg); mir_free(msg); break; diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index baf1289713..e3d22eb415 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -364,7 +364,7 @@ int SendQueue::getSendLength(const int iEntry, int sendMode) char *utf8; iLen = lstrlenA(m_jobs[iEntry].sendBuffer); wszBuf = (WCHAR *) & m_jobs[iEntry].sendBuffer[iLen + 1]; - utf8 = M->utf8_encodeW(wszBuf); + utf8 = mir_utf8encodeT(wszBuf); m_jobs[iEntry].iSendLength = lstrlenA(utf8); mir_free(utf8); return(m_jobs[iEntry].iSendLength); @@ -901,7 +901,7 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, HANDLE hContact, boo else szNote = TranslateT("The send later feature is not available on this protocol."); - char *utfText = M->utf8_encodeT(szNote); + char *utfText = mir_utf8encodeT(szNote); DBEVENTINFO dbei; dbei.cbSize = sizeof(dbei); dbei.eventType = EVENTTYPE_MESSAGE; @@ -943,7 +943,7 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, HANDLE hContact, boo mir_sntprintf(tszHeader, safe_sizeof(tszHeader), _T("M%d|"), time(0)); if(job->dwFlags & PREF_UTF || !(job->dwFlags & PREF_UNICODE)) { - char *utf_header = M->utf8_encodeT(tszHeader); + char *utf_header = mir_utf8encodeT(tszHeader); UINT required = lstrlenA(utf_header) + lstrlenA(job->sendBuffer) + 10; char *tszMsg = reinterpret_cast(mir_alloc(required)); @@ -969,7 +969,7 @@ int SendQueue::doSendLater(int iJobIndex, TWindowData *dat, HANDLE hContact, boo mir_sntprintf(tszMsg, required, _T("%s%s"), wszMsg, tszHeader); else mir_sntprintf(tszMsg, required, _T("%s%s"), tszHeader, wszMsg); - char *utf = M->utf8_encodeT(tszMsg); + char *utf = mir_utf8encodeT(tszMsg); if(fIsSendLater) DBWriteContactSettingString(hContact ? hContact : job->hOwner, "SendLater", szKeyName, utf); else diff --git a/plugins/TabSRMM/src/srmm.cpp b/plugins/TabSRMM/src/srmm.cpp index ebb6cb002c..7e009b436b 100644 --- a/plugins/TabSRMM/src/srmm.cpp +++ b/plugins/TabSRMM/src/srmm.cpp @@ -164,7 +164,7 @@ int _DebugTraceW(const wchar_t *fmt, ...) mir_snprintf(szLogFileName, MAX_PATH, "%s\\%s", szDataPath, "tabsrmm_debug.log"); f = fopen(szLogFileName, "a+"); if (f) { - char *szDebug = M->utf8_encodeW(debug); + char *szDebug = mir_utf8encodeT(debug); fputs(tszTime, f); fputs(szDebug, f); fputs("\n", f); diff --git a/plugins/TabSRMM/src/themeio.cpp b/plugins/TabSRMM/src/themeio.cpp index 2eb29884dd..b5998c2fe9 100644 --- a/plugins/TabSRMM/src/themeio.cpp +++ b/plugins/TabSRMM/src/themeio.cpp @@ -234,15 +234,15 @@ void TSAPI WriteThemeToINI(const TCHAR *szIniFilenameT, struct TWindowData *dat) for (i = 0; i <= TMPL_ERRMSG; i++) { char *encoded; if (dat == 0) - encoded = M->utf8_encodeW(LTR_Active.szTemplates[i]); + encoded = mir_utf8encodeT(LTR_Active.szTemplates[i]); else - encoded = M->utf8_encodeW(dat->pContainer->ltr_templates->szTemplates[i]); + encoded = mir_utf8encodeT(dat->pContainer->ltr_templates->szTemplates[i]); WritePrivateProfileStringA("Templates", TemplateNames[i], encoded, szIniFilename); mir_free(encoded); if (dat == 0) - encoded = M->utf8_encodeW(RTL_Active.szTemplates[i]); + encoded = mir_utf8encodeT(RTL_Active.szTemplates[i]); else - encoded = M->utf8_encodeW(dat->pContainer->rtl_templates->szTemplates[i]); + encoded = mir_utf8encodeT(dat->pContainer->rtl_templates->szTemplates[i]); WritePrivateProfileStringA("RTLTemplates", TemplateNames[i], encoded, szIniFilename); mir_free(encoded); } @@ -406,7 +406,7 @@ void TSAPI ReadThemeFromINI(const TCHAR *szIniFilenameT, TContainerData *dat, in if (strcmp(szTemplateBuffer, "[undef]")) { if (dat == 0) DBWriteContactSettingStringUtf(NULL, TEMPLATES_MODULE, TemplateNames[i], szTemplateBuffer); - decoded = M->utf8_decodeW(szTemplateBuffer); + decoded = mir_utf8decodeW(szTemplateBuffer); if (dat == 0) mir_sntprintf(LTR_Active.szTemplates[i], TEMPLATE_LENGTH, L"%s", decoded); else @@ -419,7 +419,7 @@ void TSAPI ReadThemeFromINI(const TCHAR *szIniFilenameT, TContainerData *dat, in if (strcmp(szTemplateBuffer, "[undef]")) { if (dat == 0) DBWriteContactSettingStringUtf(NULL, RTLTEMPLATES_MODULE, TemplateNames[i], szTemplateBuffer); - decoded = M->utf8_decodeW(szTemplateBuffer); + decoded = mir_utf8decodeW(szTemplateBuffer); if (dat == 0) mir_sntprintf(RTL_Active.szTemplates[i], TEMPLATE_LENGTH, L"%s", decoded); else diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index e80882a456..bfe5f0cb7b 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -1412,7 +1412,7 @@ INT_PTR CALLBACK CWarning::dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP str->insert(pos, L"\\line "); } - char *utf8 = M->utf8_encodeT(str->c_str()); + char *utf8 = mir_utf8encodeT(str->c_str()); ::SendDlgItemMessage(hwnd, IDC_WARNTEXT, EM_SETTEXTEX, (WPARAM)&stx, (LPARAM)utf8); mir_free(utf8); delete str; diff --git a/plugins/TipperYM/mir_smileys.cpp b/plugins/TipperYM/mir_smileys.cpp index 23fce34db2..5af05c4b22 100644 --- a/plugins/TipperYM/mir_smileys.cpp +++ b/plugins/TipperYM/mir_smileys.cpp @@ -354,8 +354,8 @@ void DestroySmileyList(SortedList* p_list) } } } - li.List_Destroy(p_list); //this free the p_list->items member - mir_free(p_list); //this free the p_list itself (alloc by li.List_Create) + List_Destroy(p_list); //this free the p_list->items member + mir_free(p_list); //this free the p_list itself (alloc by List_Create) } // Generete the list of smileys / text to be drawn @@ -388,7 +388,7 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco return NULL; // Lets add smileys - SortedList *plText = li.List_Create(0, 10); + SortedList *plText = List_Create(0, 10); TCHAR *word_start, *word_end; TCHAR *smiley_start, *smiley_end; @@ -428,7 +428,7 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = word_start - text; piece->len = word_end - word_start; - li.List_Insert(plText, piece, plText->realCount); + List_Insert(plText, piece, plText->realCount); word_start = word_end; } } @@ -458,7 +458,7 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco } *max_smiley_height = max(piece->smiley_height, *max_smiley_height); - li.List_Insert(plText, piece, plText->realCount); + List_Insert(plText, piece, plText->realCount); } word_start = word_end = smiley_end; @@ -480,7 +480,7 @@ SortedList *ReplaceSmileys(const TCHAR *text, int text_size, const char *protoco piece->type = TEXT_PIECE_TYPE_TEXT; piece->start_pos = word_start - text; piece->len = word_end - word_start; - li.List_Insert(plText, piece, plText->realCount); + List_Insert(plText, piece, plText->realCount); word_start = word_end; } diff --git a/plugins/UserInfoEx/classMTime.cpp b/plugins/UserInfoEx/classMTime.cpp index 6e03c02eaf..3b1dd2e081 100644 --- a/plugins/UserInfoEx/classMTime.cpp +++ b/plugins/UserInfoEx/classMTime.cpp @@ -291,9 +291,9 @@ DWORD MTime::TimeStamp() const li.QuadPart /= 10000000i64; li.QuadPart -= 11644473600i64; - if (li.QuadPart < 0) { + if (li.QuadPart < 0) return 0; - } + return (DWORD)li.QuadPart; } @@ -372,7 +372,6 @@ WORD MTime::DateFormatLong(LPTSTR ptszTimeFormat, WORD cchTimeFormat) VOID MTime::FromStampAsUTC(const DWORD dwTimeStamp) { LARGE_INTEGER li; - li.QuadPart = (dwTimeStamp + 11644473600i64) * 10000000i64; Set(li, FALSE); } diff --git a/plugins/UserInfoEx/commonheaders.cpp b/plugins/UserInfoEx/commonheaders.cpp index a69a664168..f74cb2261e 100644 --- a/plugins/UserInfoEx/commonheaders.cpp +++ b/plugins/UserInfoEx/commonheaders.cpp @@ -30,7 +30,6 @@ Last change by : $Author: ing.u.horn $ #include "commonheaders.h" // global: -PLUGINLINK* pluginLink = NULL; HINSTANCE ghInst = NULL; MM_INTERFACE mmi; //memory interface UTF8_INTERFACE utfi; //utf8 interface diff --git a/plugins/UserInfoEx/init.cpp b/plugins/UserInfoEx/init.cpp index 0054755e33..1cab813504 100644 --- a/plugins/UserInfoEx/init.cpp +++ b/plugins/UserInfoEx/init.cpp @@ -72,6 +72,7 @@ static HANDLE ghModernToolBarLoaded = NULL; static HANDLE ghShutdownHook = NULL; static HANDLE ghPrebuildStatusMenu = NULL; int hLangpack; +PLUGINLINK* pluginLink = NULL; /* ============================================================================================ diff --git a/plugins/Variables/tokenregister.cpp b/plugins/Variables/tokenregister.cpp index 56d30ffc30..54a40a5147 100644 --- a/plugins/Variables/tokenregister.cpp +++ b/plugins/Variables/tokenregister.cpp @@ -48,7 +48,7 @@ static TokenRegisterEntry* FindTokenRegisterByName(TCHAR *name) int idx; TokenRegisterEntry temp; temp.nameHash = NameHashFunction( name ); - if ( li.List_GetIndex(( SortedList* )&tokens, &temp, &idx )) + if ( List_GetIndex(( SortedList* )&tokens, &temp, &idx )) return tokens.items[ idx ]; return NULL; @@ -81,7 +81,7 @@ int deRegisterToken(TCHAR *token) { return -1; } - li.List_RemovePtr(( SortedList* )&tokens, tre ); + List_RemovePtr(( SortedList* )&tokens, tre ); LeaveCriticalSection(&csRegister); if ( !( tre->tr.flags & TRF_PARSEFUNC ) && tre->tr.szService != NULL ) @@ -151,8 +151,8 @@ INT_PTR registerToken(WPARAM wParam, LPARAM lParam) tre->tr.szCleanupService = _strdup( newVr->szCleanupService ); EnterCriticalSection(&csRegister); - li.List_GetIndex(( SortedList* )&tokens, tre, &idx ); - li.List_Insert(( SortedList* )&tokens, tre, idx ); + List_GetIndex(( SortedList* )&tokens, tre, &idx ); + List_Insert(( SortedList* )&tokens, tre, idx ); LeaveCriticalSection(&csRegister); return 0; @@ -316,7 +316,7 @@ int deinitTokenRegister() free( tre ); } - li.List_Destroy(( SortedList* )&tokens ); + List_Destroy(( SortedList* )&tokens ); LeaveCriticalSection(&csRegister); DeleteCriticalSection(&csRegister); diff --git a/plugins/helpers/gen_helpers.cpp b/plugins/helpers/gen_helpers.cpp index a792493284..87dd135c6f 100644 --- a/plugins/helpers/gen_helpers.cpp +++ b/plugins/helpers/gen_helpers.cpp @@ -267,140 +267,6 @@ TCHAR *itot(int num) { } -///////////////////////////////////////////////////////////////////////////////////////// -// Utf8Decode - converts UTF8-encoded string to the UCS2/MBCS format - -void Utf8Decode( char* str, wchar_t** ucs2 ) -{ - if ( str == NULL ) - return; - - size_t len = strlen( str ); - if ( len < 2 ) { - if ( ucs2 != NULL ) { - *ucs2 = ( wchar_t* )malloc(( len+1 )*sizeof( wchar_t )); - MultiByteToWideChar( CP_ACP, 0, str, len, *ucs2, len ); - ( *ucs2 )[ len ] = 0; - } - return; - } - - wchar_t* tempBuf = ( wchar_t* )alloca(( len+1 )*sizeof( wchar_t )); - { - wchar_t* d = tempBuf; - BYTE* s = ( BYTE* )str; - - while( *s ) - { - if (( *s & 0x80 ) == 0 ) { - *d++ = *s++; - continue; - } - - if (( s[0] & 0xE0 ) == 0xE0 && ( s[1] & 0xC0 ) == 0x80 && ( s[2] & 0xC0 ) == 0x80 ) { - *d++ = (( WORD )( s[0] & 0x0F) << 12 ) + ( WORD )(( s[1] & 0x3F ) << 6 ) + ( WORD )( s[2] & 0x3F ); - s += 3; - continue; - } - - if (( s[0] & 0xE0 ) == 0xC0 && ( s[1] & 0xC0 ) == 0x80 ) { - *d++ = ( WORD )(( s[0] & 0x1F ) << 6 ) + ( WORD )( s[1] & 0x3F ); - s += 2; - continue; - } - - *d++ = *s++; - } - - *d = 0; - } - - if ( ucs2 != NULL ) { - int fullLen = ( len+1 )*sizeof( wchar_t ); - *ucs2 = ( wchar_t* )malloc( fullLen ); - memcpy( *ucs2, tempBuf, fullLen ); - } - - WideCharToMultiByte( CP_ACP, 0, tempBuf, -1, str, len, NULL, NULL ); -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Utf8Encode - converts MBCS string to the UTF8-encoded format - -char* Utf8Encode( const char* src ) -{ - if ( src == NULL ) - return NULL; - - size_t len = strlen( src ); - char* result = ( char* )malloc( len*3 + 1 ); - if ( result == NULL ) - return NULL; - - wchar_t* tempBuf = ( wchar_t* )alloca(( len+1 )*sizeof( wchar_t )); - MultiByteToWideChar( CP_ACP, 0, src, -1, tempBuf, len ); - tempBuf[ len ] = 0; - { - wchar_t* s = tempBuf; - BYTE* d = ( BYTE* )result; - - while( *s ) { - int U = *s++; - - if ( U < 0x80 ) { - *d++ = ( BYTE )U; - } - else if ( U < 0x800 ) { - *d++ = 0xC0 + (( U >> 6 ) & 0x3F ); - *d++ = 0x80 + ( U & 0x003F ); - } - else { - *d++ = 0xE0 + ( U >> 12 ); - *d++ = 0x80 + (( U >> 6 ) & 0x3F ); - *d++ = 0x80 + ( U & 0x3F ); - } } - - *d = 0; - } - - return result; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Utf8Encode - converts UCS2 string to the UTF8-encoded format - -char* Utf8EncodeUcs2( const wchar_t* src ) -{ - int len = wcslen( src ); - char* result = ( char* )malloc( len*3 + 1 ); - if ( result == NULL ) - return NULL; - - { const wchar_t* s = src; - BYTE* d = ( BYTE* )result; - - while( *s ) { - int U = *s++; - - if ( U < 0x80 ) { - *d++ = ( BYTE )U; - } - else if ( U < 0x800 ) { - *d++ = 0xC0 + (( U >> 6 ) & 0x3F ); - *d++ = 0x80 + ( U & 0x003F ); - } - else { - *d++ = 0xE0 + ( U >> 12 ); - *d++ = 0x80 + (( U >> 6 ) & 0x3F ); - *d++ = 0x80 + ( U & 0x3F ); - } } - - *d = 0; - } - - return result; -} - // Helper functions that need MODULENAME #define SETTING_NOENCODINGCHECK "NoEncodingCheck" diff --git a/plugins/helpers/gen_helpers.h b/plugins/helpers/gen_helpers.h index 8f4d91b940..110ea9d30a 100644 --- a/plugins/helpers/gen_helpers.h +++ b/plugins/helpers/gen_helpers.h @@ -33,10 +33,6 @@ wchar_t* a2u( char* src ); int ttoi(TCHAR *string); TCHAR *itot(int num); -char* Utf8EncodeUcs2( const wchar_t* src ); -char* Utf8Encode( const char* src ); -void Utf8Decode( char* str, wchar_t** ucs2 ); - #define MAX_DEBUG 1024 #define __LOGLEVEL_DEBUG 10 diff --git a/plugins/mir_core/commonheaders.cpp b/plugins/mir_core/commonheaders.cpp new file mode 100644 index 0000000000..95b2201163 --- /dev/null +++ b/plugins/mir_core/commonheaders.cpp @@ -0,0 +1,2 @@ +#include "commonheaders.h" + diff --git a/plugins/mir_core/commonheaders.h b/plugins/mir_core/commonheaders.h new file mode 100644 index 0000000000..2d04e12f4b --- /dev/null +++ b/plugins/mir_core/commonheaders.h @@ -0,0 +1,63 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#define MIRANDA_VER 0x0A00 + +#define WINVER 0x0700 +#define _WIN32_WINNT 0x0700 +#define _WIN32_IE 0x0601 + +#define INCL_WINSOCK_API_TYPEDEFS 1 + +#include "m_stdhdr.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "miranda.h" + +#include +#include diff --git a/plugins/mir_core/langpack.cpp b/plugins/mir_core/langpack.cpp new file mode 100644 index 0000000000..d38dd6807d --- /dev/null +++ b/plugins/mir_core/langpack.cpp @@ -0,0 +1,630 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "commonheaders.h" + +#define LANGPACK_BUF_SIZE 4000 + +static int CompareMuuids(const LangPackMuuid* p1, const LangPackMuuid* p2) +{ + return memcmp(&p1->muuid, &p2->muuid, sizeof(MUUID)); +} + +static LIST lMuuids(10, CompareMuuids); +static LangPackMuuid* pCurrentMuuid = NULL; + +static BOOL bModuleInitialized = FALSE; + +struct LangPackEntry { + DWORD englishHash; + char *local; + wchar_t *wlocal; + LangPackMuuid* pMuuid; + LangPackEntry* pNext; // for langpack items with the same hash value +}; + +struct LangPackStruct { + TCHAR filename[MAX_PATH]; + TCHAR filePath[MAX_PATH]; + char language[64]; + char lastModifiedUsing[64]; + char authors[256]; + char authorEmail[128]; + LangPackEntry *entry; + int entryCount, entriesAlloced; + LCID localeID; + UINT defaultANSICp; +} static langPack; + +static int IsEmpty(char *str) +{ + int i = 0; + + while (str[i]) + { + if (str[i] != ' ' && str[i] != '\r' && str[i] != '\n') + return 0; + i++; + } + return 1; +} + +static void ConvertBackslashes(char *str, UINT fileCp) +{ + char *pstr; + for (pstr = str; *pstr; pstr = CharNextExA(fileCp, pstr, 0)) { + if (*pstr == '\\') { + switch(pstr[1]) { + case 'n': *pstr = '\n'; break; + case 't': *pstr = '\t'; break; + case 'r': *pstr = '\r'; break; + default: *pstr = pstr[1]; break; + } + memmove(pstr+1, pstr+2, strlen(pstr+2) + 1); +} } } + +#ifdef _DEBUG +//#pragma optimize("gt", on) +#endif + +// MurmurHash2 +MIR_CORE_DLL(unsigned int) mir_hash(const void * key, unsigned int len) +{ + // 'm' and 'r' are mixing constants generated offline. + // They're not really 'magic', they just happen to work well. + const unsigned int m = 0x5bd1e995; + const int r = 24; + + // Initialize the hash to a 'random' value + unsigned int h = len; + + // Mix 4 bytes at a time into the hash + const unsigned char * data = (const unsigned char *)key; + + while (len >= 4) + { + unsigned int k = *(unsigned int *)data; + + k *= m; + k ^= k >> r; + k *= m; + + h *= m; + h ^= k; + + data += 4; + len -= 4; + } + + // Handle the last few bytes of the input array + switch(len) + { + case 3: h ^= data[2] << 16; + case 2: h ^= data[1] << 8; + case 1: h ^= data[0]; + h *= m; + }; + + // Do a few final mixes of the hash to ensure the last few + // bytes are well-incorporated. + h ^= h >> 13; + h *= m; + h ^= h >> 15; + + return h; +} + +static int SortLangPackHashesProc(LangPackEntry *arg1, LangPackEntry *arg2) +{ + if (arg1->englishHash < arg2->englishHash) return -1; + if (arg1->englishHash > arg2->englishHash) return 1; + + return (arg1->pMuuid < arg2->pMuuid) ? -1 : 1; +} + +static void swapBytes(void* p, size_t iSize) +{ + char *head = (char *)p; // here + char *tail = head + iSize - 1; + + for (; tail > head; --tail, ++head) { + char temp = *head; + *head = *tail; + *tail = temp; + } +} + +static bool EnterMuuid(const char* p, MUUID& result) +{ + if (*p++ != '{') + return false; + + BYTE* d = (BYTE*)&result; + + for (int nBytes = 0; *p && nBytes < 24; p++) { + if (*p == '-') + continue; + + if (*p == '}') + break; + + if ( !isxdigit(*p)) + return false; + + if ( !isxdigit(p[1])) + return false; + + int c = 0; + if (sscanf(p, "%2x", &c) != 1) + return false; + + *d++ = (BYTE)c; + nBytes++; + p++; + } + + if (*p != '}') + return false; + + swapBytes(&result.a, sizeof(result.a)); + swapBytes(&result.b, sizeof(result.b)); + swapBytes(&result.c, sizeof(result.c)); + return true; +} + +static void LoadLangPackFile(FILE* fp, char* line, UINT fileCp) +{ + while ( !feof(fp)) { + if (fgets(line, LANGPACK_BUF_SIZE, fp) == NULL) + break; + + if (IsEmpty(line) || line[0] == ';' || line[0] == 0) + continue; + + rtrim(line); + + if (line[0] == '#') { + strlwr(line); + + if ( !memcmp(line+1, "include", 7)) { + TCHAR tszFileName[ MAX_PATH ]; + TCHAR* fileName = mir_a2t(ltrim(line+9)); + mir_sntprintf(tszFileName, SIZEOF(tszFileName), _T("%s%s"), langPack.filePath, fileName); + mir_free(fileName); + + FILE* p = _tfopen(tszFileName, _T("r")); + if (p) { + line[0] = 0; + fgets(line, SIZEOF(line), p); + + UINT fileCp = CP_ACP; + if (strlen(line) >= 3 && line[0] == '\xef' && line[1] == '\xbb' && line[2] == '\xbf') + { + fileCp = CP_UTF8; + fseek(p, 3, SEEK_SET); + } + else + { + fileCp = langPack.defaultANSICp; + fseek(p, 0, SEEK_SET); + } + + LoadLangPackFile(p, line, fileCp); + fclose(p); + } + } + else if ( !memcmp(line+1, "muuid", 5)) { + MUUID t; + if ( !EnterMuuid(line+7, t)) + continue; + + LangPackMuuid* pNew = (LangPackMuuid*)mir_alloc(sizeof(LangPackMuuid)); + memcpy(&pNew->muuid, &t, sizeof(t)); + pNew->pInfo = NULL; + lMuuids.insert(pNew); + pCurrentMuuid = pNew; + } + + continue; + } + + ConvertBackslashes(line, fileCp); + + if (line[0] == '[' && line[ lstrlenA(line)-1 ] == ']') { + if (langPack.entryCount && langPack.entry[ langPack.entryCount-1].local == NULL) + langPack.entryCount--; + + char* pszLine = line+1; + line[ lstrlenA(line)-1 ] = '\0'; + if (++langPack.entryCount > langPack.entriesAlloced) { + langPack.entriesAlloced += 128; + langPack.entry = (LangPackEntry*)mir_realloc(langPack.entry, sizeof(LangPackEntry)*langPack.entriesAlloced); + } + + LangPackEntry* E = &langPack.entry[ langPack.entryCount-1 ]; + E->englishHash = mir_hashstr(pszLine); + E->local = NULL; + E->wlocal = NULL; + E->pMuuid = pCurrentMuuid; + E->pNext = NULL; + continue; + } + + if ( !langPack.entryCount) + continue; + + LangPackEntry* E = &langPack.entry[ langPack.entryCount-1 ]; + if (E->local == NULL) { + E->local = mir_strdup(line); + if (fileCp == CP_UTF8) + Utf8DecodeCP(E->local, langPack.defaultANSICp, NULL); + + int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0); + E->wlocal = (wchar_t *)mir_alloc((iNeeded+1) * sizeof(wchar_t)); + MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal, iNeeded); + } + else { + size_t iOldLenA = strlen(E->local); + E->local = (char*)mir_realloc(E->local, iOldLenA + strlen(line) + 2); + strcat(E->local, "\n"); + strcat(E->local, line); + + if (fileCp == CP_UTF8) + Utf8DecodeCP(E->local + iOldLenA + 1, langPack.defaultANSICp, NULL); + + int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0); + size_t iOldLen = wcslen(E->wlocal); + E->wlocal = (wchar_t*)mir_realloc(E->wlocal, (sizeof(wchar_t) * (iOldLen + iNeeded + 2))); + wcscat(E->wlocal, L"\n"); + MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal + iOldLen + 1, iNeeded); + } + } +} + +MIR_CORE_DLL(int) LoadLangPack(const TCHAR *szLangPack) +{ + int startOfLine=0; + USHORT langID; + + lstrcpy(langPack.filename, szLangPack); + lstrcpy(langPack.filePath, szLangPack); + TCHAR* p = _tcsrchr(langPack.filePath, '\\'); + if (p) + p[1] = 0; + + FILE *fp = _tfopen(szLangPack, _T("rt")); + if (fp == NULL) + return 1; + + char line[ LANGPACK_BUF_SIZE ] = ""; + fgets(line, SIZEOF(line), fp); + + UINT fileCp = CP_ACP; + size_t lineLen = strlen(line); + if (lineLen >= 3 && line[0] == '\xef' && line[1] == '\xbb' && line[2] == '\xbf') + { + fileCp = CP_UTF8; + memmove(line, line + 3, lineLen - 2); + } + + lrtrim(line); + if (lstrcmpA(line, "Miranda Language Pack Version 1")) { + fclose(fp); + return 2; + } + + //headers + while ( !feof(fp)) { + startOfLine = ftell(fp); + if (fgets(line, SIZEOF(line), fp) == NULL) + break; + + lrtrim(line); + if (IsEmpty(line) || line[0] == ';' || line[0] == 0) + continue; + + if (line[0] == '[' || line[0] == '#') + break; + + char* pszColon = strchr(line, ':'); + if (pszColon == NULL) { + fclose(fp); + return 3; + } + + *pszColon++ = 0; + if ( !lstrcmpA(line, "Language")) {mir_snprintf(langPack.language, sizeof(langPack.language), "%s", pszColon); lrtrim(langPack.language);} + else if ( !lstrcmpA(line, "Last-Modified-Using")) {mir_snprintf(langPack.lastModifiedUsing, sizeof(langPack.lastModifiedUsing), "%s", pszColon); lrtrim(langPack.lastModifiedUsing);} + else if ( !lstrcmpA(line, "Authors")) {mir_snprintf(langPack.authors, sizeof(langPack.authors), "%s", pszColon); lrtrim(langPack.authors);} + else if ( !lstrcmpA(line, "Author-email")) {mir_snprintf(langPack.authorEmail, sizeof(langPack.authorEmail), "%s", pszColon); lrtrim(langPack.authorEmail);} + else if ( !lstrcmpA(line, "Locale")) { + char szBuf[20], *stopped; + + lrtrim(pszColon + 1); + langID = (USHORT)strtol(pszColon, &stopped, 16); + langPack.localeID = MAKELCID(langID, 0); + GetLocaleInfoA(langPack.localeID, LOCALE_IDEFAULTANSICODEPAGE, szBuf, 10); + szBuf[5] = 0; // codepages have max. 5 digits + langPack.defaultANSICp = atoi(szBuf); + if (fileCp == CP_ACP) + fileCp = langPack.defaultANSICp; + } + } + + //body + fseek(fp, startOfLine, SEEK_SET); + langPack.entriesAlloced = 0; + + LoadLangPackFile(fp, line, fileCp); + fclose(fp); + pCurrentMuuid = NULL; + + qsort(langPack.entry, langPack.entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static int SortLangPackHashesProc2(LangPackEntry *arg1, LangPackEntry *arg2) +{ + if (arg1->englishHash < arg2->englishHash) return -1; + if (arg1->englishHash > arg2->englishHash) return 1; + return 0; +} + +static char *LangPackTranslateString(LangPackMuuid* pUuid, const char *szEnglish, const int W) +{ + if (langPack.entryCount == 0 || szEnglish == NULL) + return (char*)szEnglish; + + LangPackEntry key, *entry; + key.englishHash = W ? mir_hashstrW((WCHAR*)szEnglish) : mir_hashstr(szEnglish); + entry = (LangPackEntry*)bsearch(&key, langPack.entry, langPack.entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc2); + if (entry == NULL) + return (char*)szEnglish; + + // try to find the exact match, otherwise the first entry will be returned + if (pUuid) { + for (LangPackEntry* p = entry->pNext; p != NULL; p = p->pNext) { + if (p->pMuuid == pUuid) { + entry = p; + break; + } } } + + return W ? (char *)entry->wlocal : entry->local; +} + +MIR_CORE_DLL(int) LangPackGetDefaultCodePage() +{ + return langPack.defaultANSICp; +} + +MIR_CORE_DLL(int) LangPackGetDefaultLocale() +{ + return (langPack.localeID == 0) ? LOCALE_USER_DEFAULT : langPack.localeID; +} + +MIR_CORE_DLL(TCHAR*) LangPackPcharToTchar(const char* pszStr) +{ + if (pszStr == NULL) + return NULL; + + { int len = (int)strlen(pszStr); + TCHAR* result = (TCHAR*)alloca((len+1)*sizeof(TCHAR)); + MultiByteToWideChar(LangPackGetDefaultCodePage(), 0, pszStr, -1, result, len); + result[len] = 0; + return mir_wstrdup(TranslateW(result)); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_CORE_DLL(char*) TranslateA_LP(const char* str, int hLangpack) +{ + return (char*)LangPackTranslateString(LangPackLookupUuid(hLangpack), str, FALSE); +} + +MIR_CORE_DLL(WCHAR*) TranslateW_LP(const WCHAR* str, int hLangpack) +{ + return (WCHAR*)LangPackTranslateString(LangPackLookupUuid(hLangpack), (LPCSTR)str, TRUE); +} + +MIR_CORE_DLL(void) TranslateMenu_LP(HMENU hMenu, int hLangpack) +{ + LangPackMuuid* uuid = LangPackLookupUuid(hLangpack); + + MENUITEMINFO mii; + mii.cbSize = MENUITEMINFO_V4_SIZE; + for (int i = GetMenuItemCount(hMenu)-1; i >= 0; i--) { + TCHAR str[256]; + mii.fMask = MIIM_TYPE|MIIM_SUBMENU; + mii.dwTypeData = (TCHAR*)str; + mii.cch = SIZEOF(str); + GetMenuItemInfo(hMenu, i, TRUE, &mii); + + if (mii.cch && mii.dwTypeData) { + TCHAR* result = (TCHAR*)LangPackTranslateString(uuid, (const char*)mii.dwTypeData, TRUE); + if (result != mii.dwTypeData) { + mii.dwTypeData = result; + mii.fMask = MIIM_TYPE; + SetMenuItemInfo(hMenu, i, TRUE, &mii); + } } + + if (mii.hSubMenu != NULL) TranslateMenu_LP(mii.hSubMenu, hLangpack); + } +} + +static void TranslateWindow(LangPackMuuid* pUuid, HWND hwnd) +{ + TCHAR title[2048]; + GetWindowText(hwnd, title, SIZEOF(title)); + + TCHAR* result = (TCHAR*)LangPackTranslateString(pUuid, (const char*)title, TRUE); + if (result != title) + SetWindowText(hwnd, result); +} + +struct LANGPACKTRANSLATEDIALOG +{ + HWND hwndDlg; + int hLangpack; +}; + +static BOOL CALLBACK TranslateDialogEnumProc(HWND hwnd, LPARAM lParam) +{ + int hLangpack = (int)lParam; + TCHAR szClass[32]; + int id = GetDlgCtrlID(hwnd); + + LangPackMuuid* uuid = LangPackLookupUuid(hLangpack); + + GetClassName(hwnd, szClass, SIZEOF(szClass)); + if ( !lstrcmpi(szClass, _T("static")) || !lstrcmpi(szClass, _T("hyperlink")) || !lstrcmpi(szClass, _T("button")) || !lstrcmpi(szClass, _T("MButtonClass")) || !lstrcmpi(szClass, _T("MHeaderbarCtrl"))) + TranslateWindow(uuid, hwnd); + else if ( !lstrcmpi(szClass, _T("edit"))) { + if (GetWindowLongPtr(hwnd, GWL_STYLE) & ES_READONLY) + TranslateWindow(uuid, hwnd); + } + return TRUE; +} + +MIR_CORE_DLL(void) TranslateDialog_LP(HWND hDlg, int hLangpack) +{ + TranslateWindow(LangPackLookupUuid(hLangpack), hDlg); + EnumChildWindows(hDlg, TranslateDialogEnumProc, hLangpack); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_CORE_DLL(LangPackMuuid*) LangPackLookupUuid(WPARAM wParam) +{ + int idx = (wParam >> 16) & 0xFFFF; + return (idx > 0 && idx <= lMuuids.getCount()) ? lMuuids[ idx-1 ] : NULL; +} + +MIR_CORE_DLL(int) LangPackMarkPluginLoaded(PLUGININFOEX* pInfo) +{ + LangPackMuuid tmp; tmp.muuid = pInfo->uuid; + int idx = lMuuids.getIndex(&tmp); + if (idx == -1) + return 0; + + lMuuids[ idx ]->pInfo = pInfo; + return (idx+1) << 16; +} + +MIR_CORE_DLL(void) LangPackDropUnusedItems(void) +{ + if (langPack.entryCount == 0) + return; + + LangPackEntry *s = langPack.entry+1, *d = s, *pLast = langPack.entry; + DWORD dwSavedHash = langPack.entry->englishHash; + bool bSortNeeded = false; + + for (int i=1; i < langPack.entryCount; i++, s++) { + if (s->pMuuid != NULL && s->pMuuid->pInfo == NULL) + s->pMuuid = NULL; + + if (s->englishHash != dwSavedHash) { + pLast = d; + if (s != d) + *d++ = *s; + else + d++; + dwSavedHash = s->englishHash; + } + else { + bSortNeeded = true; + LangPackEntry* p = (LangPackEntry*)mir_alloc(sizeof(LangPackEntry)); + *p = *s; + pLast->pNext = p; pLast = p; + } + } + + if (bSortNeeded) { + langPack.entryCount = (int)(d - langPack.entry); + qsort(langPack.entry, langPack.entryCount, sizeof(LangPackEntry), (int(*)(const void*, const void*))SortLangPackHashesProc); + } +} + +///////////////////////////////////////////////////////////////////////////////////////// + +int LoadLangPackModule(void) +{ + bModuleInitialized = TRUE; + + ZeroMemory(&langPack, sizeof(langPack)); + + TCHAR szSearch[MAX_PATH]; + PathToAbsoluteT(_T("langpack_*.txt"), szSearch, NULL); + + WIN32_FIND_DATA fd; + HANDLE hFind = FindFirstFile(szSearch, &fd); + if (hFind != INVALID_HANDLE_VALUE) { + PathToAbsoluteT(fd.cFileName, szSearch, NULL); + FindClose(hFind); + LoadLangPack(szSearch); + } + return 0; +} + +void UnloadLangPackModule() +{ + if ( !bModuleInitialized) return; + + int i; + for (i=0; i < lMuuids.getCount(); i++) + mir_free(lMuuids[i]); + lMuuids.destroy(); + + LangPackEntry* p = langPack.entry; + for (i=0; i < langPack.entryCount; i++, p++) { + if (p->pNext != NULL) { + for (LangPackEntry* p1 = p->pNext; p1 != NULL;) { + LangPackEntry* p2 = p1; p1 = p1->pNext; + mir_free(p2->local); + mir_free(p2->wlocal); + mir_free(p2); + } } + + mir_free(p->local); + mir_free(p->wlocal); + } + + if (langPack.entryCount) { + mir_free(langPack.entry); + langPack.entry=0; + langPack.entryCount=0; +} } + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_CORE_DLL(void) ReloadLangpack(TCHAR *pszStr) +{ + if (pszStr == NULL) + pszStr = langPack.filename; + + UnloadLangPackModule(); + LoadLangPack(pszStr); + LangPackDropUnusedItems(); +} diff --git a/plugins/mir_core/lists.cpp b/plugins/mir_core/lists.cpp new file mode 100644 index 0000000000..e4996fc156 --- /dev/null +++ b/plugins/mir_core/lists.cpp @@ -0,0 +1,278 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +/* a simple sorted list implementation */ + +MIR_CORE_DLL(SortedList*) List_Create(int p_limit, int p_increment) +{ + SortedList* result = (SortedList*)mir_calloc(sizeof(SortedList)); + if (result == NULL) + return(NULL); + + result->increment = p_increment; + result->limit = p_limit; + return(result); +} + +MIR_CORE_DLL(void) List_Destroy(SortedList* p_list) +{ + if (p_list == NULL) + return; + + if (p_list->items != NULL) { + mir_free(p_list->items); + p_list->items = NULL; + } + + p_list->realCount = p_list->limit = 0; +} + +MIR_CORE_DLL(void*) List_Find(SortedList* p_list, void* p_value) +{ + int index; + + if ( !List_GetIndex(p_list, p_value, &index)) + return(NULL); + + return(p_list->items[ index ]); +} + +#ifdef _DEBUG +#pragma optimize("gt", on) +#endif + +MIR_CORE_DLL(int) List_GetIndex(SortedList* p_list, void* p_value, int* p_index) +{ + if (p_value == NULL) + { + *p_index = -1; + return 0; + } + + switch ((INT_PTR)p_list->sortFunc) + { + case 0: + break; + + case HandleKeySort: +#ifdef _WIN64 + { + const unsigned __int64 val = *(unsigned __int64 *)p_value; + int low = 0; + int high = p_list->realCount - 1; + + while (low <= high) + { + int i = (low + high) / 2; + unsigned __int64 vali = *(unsigned __int64 *)p_list->items[i]; + if (vali == val) + { + *p_index = i; + return 1; + } + + if (vali < val) + low = i + 1; + else + high = i - 1; + } + + *p_index = low; + } + break; +#endif + + case NumericKeySort: + { + const unsigned val = *(unsigned *)p_value; + int low = 0; + int high = p_list->realCount - 1; + + while (low <= high) + { + int i = (low + high) / 2; + unsigned vali = *(unsigned *)p_list->items[i]; + if (vali == val) + { + *p_index = i; + return 1; + } + + if (vali < val) + low = i + 1; + else + high = i - 1; + } + + *p_index = low; + } + break; + + case PtrKeySort: + { + int low = 0; + int high = p_list->realCount - 1; + + while (low <= high) + { + int i = (low + high) / 2; + const void* vali = p_list->items[i]; + if (vali == p_value) + { + *p_index = i; + return 1; + } + + if (vali < p_value) + low = i + 1; + else + high = i - 1; + } + + *p_index = low; + } + break; + + default: + { + int low = 0; + int high = p_list->realCount - 1; + + while (low <= high) + { + int i = (low + high) / 2; + int result = p_list->sortFunc(p_list->items[i], p_value); + if (result == 0) + { + *p_index = i; + return 1; + } + + if (result < 0) + low = i + 1; + else + high = i - 1; + } + + *p_index = low; + } + break; + } + + return 0; +} + +MIR_CORE_DLL(int) List_IndexOf(SortedList* p_list, void* p_value) +{ + if (p_value == NULL) + return -1; + + int i; + for (i=0; i < p_list->realCount; i++) + if (p_list->items[i] == p_value) + return i; + + return -1; +} + +#ifdef _DEBUG +#pragma optimize("", on) +#endif + +MIR_CORE_DLL(int) List_Insert(SortedList* p_list, void* p_value, int p_index) +{ + if (p_value == NULL || p_index > p_list->realCount) + return 0; + + if (p_list->realCount == p_list->limit) + { + p_list->items = (void**)mir_realloc(p_list->items, sizeof(void*)*(p_list->realCount + p_list->increment)); + p_list->limit += p_list->increment; + } + + if (p_index < p_list->realCount) + memmove(p_list->items+p_index+1, p_list->items+p_index, sizeof(void*)*(p_list->realCount-p_index)); + + p_list->realCount++; + + p_list->items[ p_index ] = p_value; + return 1; +} + +MIR_CORE_DLL(int) List_InsertPtr(SortedList* list, void* p) +{ + if (p == NULL) + return -1; + + int idx = list->realCount; + List_GetIndex(list, p, &idx); + return List_Insert(list, p, idx); +} + +MIR_CORE_DLL(int) List_Remove(SortedList* p_list, int index) +{ + if (index < 0 || index > p_list->realCount) + return(0); + + p_list->realCount--; + if (p_list->realCount > index) + { + memmove(p_list->items+index, p_list->items+index+1, sizeof(void*)*(p_list->realCount-index)); + p_list->items[ p_list->realCount ] = NULL; + } + + return 1; +} + +MIR_CORE_DLL(int) List_RemovePtr(SortedList* list, void* p) +{ + int idx = -1; + if (List_GetIndex(list, p, &idx)) + List_Remove(list, idx); + + return idx; +} + +MIR_CORE_DLL(void) List_Copy(SortedList* s, SortedList* d, size_t itemSize) +{ + d->increment = s->increment; + d->limit = s->limit; + d->realCount = s->realCount; + d->items = (void**)mir_alloc( sizeof(void*) * d->realCount); + memcpy(d->items, s->items, sizeof(void*) * d->realCount); +} + +MIR_CORE_DLL(void) List_ObjCopy(SortedList* s, SortedList* d, size_t itemSize) +{ + int i; + + d->increment = s->increment; + d->sortFunc = s->sortFunc; + + for (i = 0; i < s->realCount; i++) { + void* item = new char[ itemSize ]; + memcpy(item, s->items[i], itemSize); + List_Insert(d, item, i); +} } diff --git a/plugins/mir_core/memory.cpp b/plugins/mir_core/memory.cpp new file mode 100644 index 0000000000..25b4d880c2 --- /dev/null +++ b/plugins/mir_core/memory.cpp @@ -0,0 +1,280 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +#define BLOCK_ALLOCED 0xABBABABA +#define BLOCK_FREED 0xDEADBEEF + +static int CheckBlock(void* blk) +{ + int result = FALSE; + char* p = (char*)blk - sizeof(DWORD)*2; + DWORD size, *b, *e; + + __try + { + size = *(DWORD*)p; + b = (DWORD*)&p[ sizeof(DWORD) ]; + e = (DWORD*)&p[ sizeof(DWORD)*2 + size ]; + + if (*b != BLOCK_ALLOCED || *e != BLOCK_ALLOCED) + { + if (*b == BLOCK_FREED && *e == BLOCK_FREED) + OutputDebugStringA("memory block is already deleted\n"); + else + OutputDebugStringA("memory block is corrupted\n"); + #if defined(_DEBUG) + DebugBreak(); + #endif + } + else result = TRUE; + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + OutputDebugStringA("access violation during checking memory block\n"); + #if defined(_DEBUG) + DebugBreak(); + #endif + } + + return result; +} + +/******************************************************************************/ + +MIR_CORE_DLL(void*) mir_alloc(size_t size) +{ + if (size == 0) + return NULL; + { + char* p = (char*)malloc(size + sizeof(DWORD)*3); + if (p == NULL) { + OutputDebugStringA("memory overflow\n"); + #if defined(_DEBUG) + DebugBreak(); + #endif + return NULL; + } + + *(DWORD*)p = (DWORD)size; + *(DWORD*)&p[ sizeof(DWORD) ] = BLOCK_ALLOCED; + *(DWORD*)&p[ size + sizeof(DWORD)*2 ] = BLOCK_ALLOCED; + return p + sizeof(DWORD)*2; +} } + +/******************************************************************************/ + +MIR_CORE_DLL(void*) mir_calloc(size_t size) +{ + void* p = mir_alloc(size); + if (p != NULL) + memset(p, 0, size); + return p; +} + +/******************************************************************************/ + +MIR_CORE_DLL(void*) mir_realloc(void* ptr, size_t size) +{ + char* p; + + if (ptr != NULL) { + if ( !CheckBlock(ptr)) + return NULL; + p = (char*)ptr - sizeof(DWORD)*2; + } + else p = NULL; + + p = (char*)realloc(p, size + sizeof(DWORD)*3); + if (p == NULL) { + OutputDebugStringA("memory overflow\n"); + #if defined(_DEBUG) + DebugBreak(); + #endif + return NULL; + } + + *(DWORD*)p = (DWORD)size; + *(DWORD*)&p[ sizeof(DWORD) ] = BLOCK_ALLOCED; + *(DWORD*)&p[ size + sizeof(DWORD)*2 ] = BLOCK_ALLOCED; + return p + sizeof(DWORD)*2; +} + +/******************************************************************************/ + +MIR_CORE_DLL(void) mir_free(void* ptr) +{ + char* p; + DWORD size; + + if (ptr == NULL) + return; + if ( !CheckBlock(ptr)) + return; + + p = (char*)ptr - sizeof(DWORD)*2; + size = *(DWORD*)p; + *(DWORD*)&p[ sizeof(DWORD) ] = BLOCK_FREED; + *(DWORD*)&p[ size + sizeof(DWORD)*2 ] = BLOCK_FREED; + free(p); +} + +/******************************************************************************/ + +MIR_CORE_DLL(char*) mir_strdup(const char* str) +{ + if (str != NULL) { + char* p = (char*)mir_alloc(strlen(str)+1); + if (p) + strcpy(p, str); + return p; + } + return NULL; +} + +/******************************************************************************/ + +MIR_CORE_DLL(char*) mir_strndup(const char* str, size_t len) +{ + if (str != NULL && len != 0) { + char* p = (char*)mir_alloc(len + 1); + if ( !p) { + memcpy(p, str, len); + p[ len ] = 0; + } + return p; + } + return NULL; +} + +/******************************************************************************/ + +MIR_CORE_DLL(WCHAR*) mir_wstrdup(const WCHAR* str) +{ + if (str != NULL) { + WCHAR* p = (WCHAR*)mir_alloc(sizeof(WCHAR)*(wcslen(str)+1)); + if (p) + wcscpy(p, str); + return p; + } + return NULL; +} + +/******************************************************************************/ + +MIR_CORE_DLL(int) mir_snprintf(char *buffer, size_t count, const char* fmt, ...) +{ + va_list va; + int len; + + va_start(va, fmt); + len = _vsnprintf(buffer, count-1, fmt, va); + va_end(va); + buffer[count-1] = 0; + return len; +} + +/******************************************************************************/ + +MIR_CORE_DLL(int) mir_sntprintf(TCHAR *buffer, size_t count, const TCHAR* fmt, ...) +{ + va_list va; + int len; + + va_start(va, fmt); + len = _vsntprintf(buffer, count-1, fmt, va); + va_end(va); + buffer[count-1] = 0; + return len; +} + +/******************************************************************************/ + +MIR_CORE_DLL(int) mir_vsnprintf(char *buffer, size_t count, const char* fmt, va_list va) +{ + int len; + + len = _vsnprintf(buffer, count-1, fmt, va); + buffer[count-1] = 0; + return len; +} + +/******************************************************************************/ + +MIR_CORE_DLL(int) mir_vsntprintf(TCHAR *buffer, size_t count, const TCHAR* fmt, va_list va) +{ + int len; + + len = _vsntprintf(buffer, count-1, fmt, va); + buffer[count-1] = 0; + return len; +} + +/******************************************************************************/ + +MIR_CORE_DLL(wchar_t*) mir_a2u_cp(const char* src, int codepage) +{ + if (src == NULL) + return NULL; + + int cbLen = MultiByteToWideChar(codepage, 0, src, -1, NULL, 0); + wchar_t* result = (wchar_t*)mir_alloc(sizeof(wchar_t)*(cbLen+1)); + if (result == NULL) + return NULL; + + MultiByteToWideChar(codepage, 0, src, -1, result, cbLen); + result[ cbLen ] = 0; + return result; +} + +/******************************************************************************/ + +MIR_CORE_DLL(wchar_t*) mir_a2u(const char* src) +{ + return mir_a2u_cp(src, LangPackGetDefaultCodePage()); +} + +/******************************************************************************/ + +MIR_CORE_DLL(char*) mir_u2a_cp(const wchar_t* src, int codepage) +{ + if (src == NULL) + return NULL; + + int cbLen = WideCharToMultiByte(codepage, 0, src, -1, NULL, 0, NULL, NULL); + char* result = (char*)mir_alloc(cbLen+1); + if (result == NULL) + return NULL; + + WideCharToMultiByte(codepage, 0, src, -1, result, cbLen, NULL, NULL); + result[ cbLen ] = 0; + return result; +} + +/******************************************************************************/ + +MIR_CORE_DLL(char*) mir_u2a(const wchar_t* src) +{ + return mir_u2a_cp(src, LangPackGetDefaultCodePage()); +} diff --git a/plugins/mir_core/mir_core.def b/plugins/mir_core/mir_core.def new file mode 100644 index 0000000000..78e8323ff8 --- /dev/null +++ b/plugins/mir_core/mir_core.def @@ -0,0 +1,5 @@ +LIBRARY mir_core + +EXPORTS + CallContactService @1 + CallProtoService @2 diff --git a/plugins/mir_core/mir_core_10.vcxproj b/plugins/mir_core/mir_core_10.vcxproj new file mode 100644 index 0000000000..ba1b174e58 --- /dev/null +++ b/plugins/mir_core/mir_core_10.vcxproj @@ -0,0 +1,218 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + + + + + + + + mir_core + {D9EFEA4B-B817-4DE1-BD62-68A5DB8F5F60} + + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + Unicode + + + DynamicLibrary + true + Unicode + + + DynamicLibrary + Unicode + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30128.1 + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)\ + $(SolutionDir)$(Configuration)\Obj\$(ProjectName)\ + $(SolutionDir)$(Configuration)64\ + $(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\ + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + EnableFastChecks + MultiThreadedDebugDLL + true + Level3 + EditAndContinue + 4996;%(DisableSpecificWarnings) + WIN32;_DEBUG;_WINDOWS;MIR_CORE_EXPORTS;_USRDLL;%(PreprocessorDefinitions) + Use + commonheaders.h + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + mir_core.def + true + false + Windows + miranda32.lib;ws2_32.lib;comctl32.lib;winmm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)\lib + $(IntDir)$(TargetName).lib + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + EnableFastChecks + MultiThreadedDebugDLL + true + Level3 + 4996;%(DisableSpecificWarnings) + WIN64;_DEBUG;_WINDOWS;MIR_CORE_EXPORTS;_USRDLL;%(PreprocessorDefinitions) + Use + commonheaders.h + + + _DEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + + + true + false + $(IntDir)$(TargetName).lib + Windows + miranda64.lib;ws2_32.lib;comctl32.lib;winmm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)\lib + + + + + Full + OnlyExplicitInline + Size + ..\..\include;%(AdditionalIncludeDirectories) + true + false + true + Level3 + 4996;%(DisableSpecificWarnings) + WIN32;NDEBUG;_WINDOWS;MIR_CORE_EXPORTS;_USRDLL;%(PreprocessorDefinitions) + Use + commonheaders.h + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + mir_core.def + true + true + true + false + Windows + miranda32.lib;ws2_32.lib;comctl32.lib;winmm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)\lib + $(IntDir)$(TargetName).lib + + + + + Full + OnlyExplicitInline + Size + ..\..\include;%(AdditionalIncludeDirectories) + true + false + true + Level3 + 4996;%(DisableSpecificWarnings) + WIN64;NDEBUG;_WINDOWS;MIR_CORE_EXPORTS;_USRDLL;%(PreprocessorDefinitions) + Use + commonheaders.h + + + NDEBUG;%(PreprocessorDefinitions) + ..\..\include\msapi + + + + + true + true + true + false + $(IntDir)$(TargetName).lib + Windows + miranda64.lib;ws2_32.lib;comctl32.lib;winmm.lib;version.lib;%(AdditionalDependencies) + $(SolutionDir)\lib + + + + + + \ No newline at end of file diff --git a/plugins/mir_core/mir_core_10.vcxproj.filters b/plugins/mir_core/mir_core_10.vcxproj.filters new file mode 100644 index 0000000000..30facd3a4c --- /dev/null +++ b/plugins/mir_core/mir_core_10.vcxproj.filters @@ -0,0 +1,64 @@ + + + + + {bf74d1c9-acd8-4fba-837d-734f024521c9} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {a578a180-0eb9-4c3e-b4ae-0eaefa01d207} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/plugins/mir_core/miranda.cpp b/plugins/mir_core/miranda.cpp new file mode 100644 index 0000000000..1e714089d1 --- /dev/null +++ b/plugins/mir_core/miranda.cpp @@ -0,0 +1,398 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2012 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "commonheaders.h" + +HWND hAPCWindow = NULL; + +int InitPathUtils(void); +void RecalculateTime(void); + +HANDLE hStackMutex, hThreadQueueEmpty; +int hLangpack = 0; +HINSTANCE hInst = 0; + +///////////////////////////////////////////////////////////////////////////////////////// +// exception handling + +static DWORD __cdecl sttDefaultFilter(DWORD, EXCEPTION_POINTERS*) +{ + return EXCEPTION_EXECUTE_HANDLER; +} + +pfnExceptionFilter pMirandaExceptFilter = sttDefaultFilter; + +MIR_CORE_DLL(pfnExceptionFilter) GetExceptionFilter() +{ + return pMirandaExceptFilter; +} + +MIR_CORE_DLL(pfnExceptionFilter) SetExceptionFilter(pfnExceptionFilter pMirandaExceptFilter) +{ + pfnExceptionFilter oldOne = pMirandaExceptFilter; + if (pMirandaExceptFilter != 0) + pMirandaExceptFilter = pMirandaExceptFilter; + return oldOne; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// thread support functions + +struct THREAD_WAIT_ENTRY +{ + DWORD dwThreadId; // valid if hThread isn't signalled + HANDLE hThread; + HINSTANCE hOwner; + void* pObject; + PVOID addr; +}; + +static LIST threads(10, NumericKeySortT); + +struct FORK_ARG { + HANDLE hEvent; + pThreadFunc threadcode; + pThreadFuncEx threadcodeex; + void *arg, *owner; +}; + +///////////////////////////////////////////////////////////////////////////////////////// +// forkthread - starts a new thread + +void __cdecl forkthread_r(void * arg) +{ + struct FORK_ARG * fa = (struct FORK_ARG *) arg; + void (*callercode)(void*)=fa->threadcode; + void * cookie=fa->arg; + CallService(MS_SYSTEM_THREAD_PUSH, 0, (LPARAM)callercode); + SetEvent(fa->hEvent); + __try + { + callercode(cookie); + } + __except(pMirandaExceptFilter(GetExceptionCode(), GetExceptionInformation())) + { + } + + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); + CallService(MS_SYSTEM_THREAD_POP, 0, 0); + return; +} + +MIR_CORE_DLL(UINT_PTR) forkthread( void (__cdecl *threadcode)(void*), unsigned long stacksize, void *arg) +{ + UINT_PTR rc; + struct FORK_ARG fa; + fa.hEvent=CreateEvent(NULL, FALSE, FALSE, NULL); + fa.threadcode=threadcode; + fa.arg=arg; + rc=_beginthread(forkthread_r, stacksize, &fa); + if ((UINT_PTR)-1L != rc) + WaitForSingleObject(fa.hEvent, INFINITE); + + CloseHandle(fa.hEvent); + return rc; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// forkthreadex - starts a new thread with the extended info and returns the thread id + +unsigned __stdcall forkthreadex_r(void * arg) +{ + struct FORK_ARG *fa = (struct FORK_ARG *)arg; + pThreadFuncEx threadcode = fa->threadcodeex; + pThreadFuncOwner threadcodeex = (pThreadFuncOwner)fa->threadcodeex; + void *cookie = fa->arg; + void *owner = fa->owner; + unsigned long rc = 0; + + CallService(MS_SYSTEM_THREAD_PUSH, (WPARAM)fa->owner, (LPARAM)threadcode); + SetEvent(fa->hEvent); + __try + { + if (owner) + rc = threadcodeex(owner, cookie); + else + rc = threadcode(cookie); + } + __except(pMirandaExceptFilter(GetExceptionCode(), GetExceptionInformation())) + { + } + + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); + CallService(MS_SYSTEM_THREAD_POP, 0, 0); + return rc; +} + +MIR_CORE_DLL(UINT_PTR) forkthreadex( + void *sec, + unsigned stacksize, + unsigned (__stdcall *threadcode)(void*), + void* owner, + void *arg, + unsigned *thraddr) +{ + UINT_PTR rc; + struct FORK_ARG fa = { 0 }; + fa.threadcodeex = threadcode; + fa.arg = arg; + fa.owner = owner; + fa.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + rc = _beginthreadex(sec, stacksize, forkthreadex_r, (void *)&fa, 0, thraddr); + if (rc) + WaitForSingleObject(fa.hEvent, INFINITE); + + CloseHandle(fa.hEvent); + return rc; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// APC and mutex functions + +static void __stdcall DummyAPCFunc(ULONG_PTR) +{ + /* called in the context of thread that cleared it's APC queue */ + return; +} + +static int MirandaWaitForMutex(HANDLE hEvent) +{ + for (;;) { + // will get WAIT_IO_COMPLETE for QueueUserAPC() which isnt a result + DWORD rc = MsgWaitForMultipleObjectsEx(1, &hEvent, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE); + if (rc == WAIT_OBJECT_0 + 1) { + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (IsDialogMessage(msg.hwnd, &msg)) continue; + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + else if (rc == WAIT_OBJECT_0) { // got object + return 1; + } + else if (rc == WAIT_ABANDONED_0 || rc == WAIT_FAILED) + return 0; + } +} + +static void CALLBACK KillAllThreads(HWND, UINT, UINT_PTR, DWORD) +{ + if ( MirandaWaitForMutex(hStackMutex)) { + for (int j=0; j < threads.getCount(); j++) { + THREAD_WAIT_ENTRY* p = threads[j]; + char szModuleName[ MAX_PATH ]; + GetModuleFileNameA(p->hOwner, szModuleName, sizeof(szModuleName)); + TerminateThread(p->hThread, 9999); + CloseHandle(p->hThread); + mir_free(p); + } + + threads.destroy(); + + ReleaseMutex(hStackMutex); + SetEvent(hThreadQueueEmpty); + } +} + +MIR_CORE_DLL(void) KillObjectThreads(void* owner) +{ + if (owner == NULL) + return; + + WaitForSingleObject(hStackMutex, INFINITE); + + HANDLE* threadPool = (HANDLE*)alloca(threads.getCount()*sizeof(HANDLE)); + int threadCount = 0; + + for (int j = threads.getCount(); j--;) { + THREAD_WAIT_ENTRY* p = threads[j]; + if (p->pObject == owner) + threadPool[ threadCount++ ] = p->hThread; + } + ReleaseMutex(hStackMutex); + + // is there anything to kill? + if (threadCount > 0) { + if ( WaitForMultipleObjects(threadCount, threadPool, TRUE, 5000) == WAIT_TIMEOUT) { + // forcibly kill all remaining threads after 5 secs + WaitForSingleObject(hStackMutex, INFINITE); + for (int j = threads.getCount()-1; j >= 0; j--) { + THREAD_WAIT_ENTRY* p = threads[j]; + if (p->pObject == owner) { + TerminateThread(p->hThread, 9999); + CloseHandle(p->hThread); + threads.remove(j); + mir_free(p); + } + } + ReleaseMutex(hStackMutex); + } + } +} + +MIR_CORE_DLL(void) UnwindThreadWait(void) +{ + // acquire the list and wake up any alertable threads + if ( MirandaWaitForMutex(hStackMutex)) { + int j; + for (j=0; j < threads.getCount(); j++) + QueueUserAPC(DummyAPCFunc, threads[j]->hThread, 0); + ReleaseMutex(hStackMutex); + } + + // give all unclosed threads 5 seconds to close + SetTimer(NULL, 0, 5000, KillAllThreads); + + // wait til the thread list is empty + MirandaWaitForMutex(hThreadQueueEmpty); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +typedef LONG (WINAPI *pNtQIT)(HANDLE, LONG, PVOID, ULONG, PULONG); +#define ThreadQuerySetWin32StartAddress 9 + +MIR_CORE_DLL(void*) GetCurrentThreadEntryPoint() +{ + LONG ntStatus; + HANDLE hDupHandle, hCurrentProcess; + DWORD_PTR dwStartAddress; + + pNtQIT NtQueryInformationThread = (pNtQIT)GetProcAddress(GetModuleHandle(_T("ntdll.dll")), "NtQueryInformationThread"); + if (NtQueryInformationThread == NULL) + return 0; + + hCurrentProcess = GetCurrentProcess(); + if ( !DuplicateHandle(hCurrentProcess, GetCurrentThread(), hCurrentProcess, &hDupHandle, THREAD_QUERY_INFORMATION, FALSE, 0)) { + SetLastError(ERROR_ACCESS_DENIED); + return NULL; + } + ntStatus = NtQueryInformationThread(hDupHandle, ThreadQuerySetWin32StartAddress, &dwStartAddress, sizeof(DWORD_PTR), NULL); + CloseHandle(hDupHandle); + + if (ntStatus != ERROR_SUCCESS) return 0; + return (void*)dwStartAddress; +} + +MIR_CORE_DLL(INT_PTR) UnwindThreadPush(WPARAM wParam, LPARAM lParam) +{ + ResetEvent(hThreadQueueEmpty); // thread list is not empty + if ( WaitForSingleObject(hStackMutex, INFINITE) == WAIT_OBJECT_0) { + THREAD_WAIT_ENTRY* p = (THREAD_WAIT_ENTRY*)mir_calloc(sizeof(THREAD_WAIT_ENTRY)); + + DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &p->hThread, 0, FALSE, DUPLICATE_SAME_ACCESS); + p->dwThreadId = GetCurrentThreadId(); + p->pObject = (void*)wParam; + p->hOwner = GetInstByAddress((void*)lParam); + p->addr = (void*)lParam; + threads.insert(p); + + ReleaseMutex(hStackMutex); + } + return 0; +} + +MIR_CORE_DLL(INT_PTR) UnwindThreadPop(WPARAM, LPARAM) +{ + if ( WaitForSingleObject(hStackMutex, INFINITE) == WAIT_OBJECT_0) { + DWORD dwThreadId = GetCurrentThreadId(); + for (int j=0; j < threads.getCount(); j++) { + THREAD_WAIT_ENTRY* p = threads[j]; + if (p->dwThreadId == dwThreadId) { + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); + CloseHandle(p->hThread); + threads.remove(j); + mir_free(p); + + if ( !threads.getCount()) { + threads.destroy(); + ReleaseMutex(hStackMutex); + SetEvent(hThreadQueueEmpty); // thread list is empty now + return 0; + } + + ReleaseMutex(hStackMutex); + return 0; + } + } + ReleaseMutex(hStackMutex); + } + return 1; +} + +static LRESULT CALLBACK APCWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_NULL) SleepEx(0, TRUE); + if (msg == WM_TIMECHANGE) RecalculateTime(); + return DefWindowProc(hwnd, msg, wParam, lParam); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// module init + +static void LoadSystemModule(void) +{ + INITCOMMONCONTROLSEX icce = {0}; + icce.dwSize = sizeof(icce); + icce.dwICC = ICC_WIN95_CLASSES | ICC_USEREX_CLASSES; + InitCommonControlsEx(&icce); + + if ( IsWinVerXPPlus()) { + hAPCWindow=CreateWindowEx(0, _T("ComboLBox"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); + SetClassLongPtr(hAPCWindow, GCL_STYLE, GetClassLongPtr(hAPCWindow, GCL_STYLE) | CS_DROPSHADOW); + DestroyWindow(hAPCWindow); + hAPCWindow = NULL; + } + + hAPCWindow = CreateWindowEx(0, _T("STATIC"), NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); + SetWindowLongPtr(hAPCWindow, GWLP_WNDPROC, (LONG_PTR)APCWndProc); + hStackMutex = CreateMutex(NULL, FALSE, NULL); + + InitPathUtils(); + LoadLangPackModule(); + InitialiseModularEngine(); + InitTimeZones(); +} + +static void UnloadSystemModule(void) +{ + DestroyModularEngine(); + UnloadLangPackModule(); + UninitTimeZones(); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// entry point + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + if (fdwReason == DLL_PROCESS_ATTACH) { + hInst = hinstDLL; + LoadSystemModule(); + } + else if(fdwReason == DLL_PROCESS_DETACH) + UnloadSystemModule(); + return TRUE; +} diff --git a/plugins/mir_core/miranda.h b/plugins/mir_core/miranda.h new file mode 100644 index 0000000000..3b639ac4aa --- /dev/null +++ b/plugins/mir_core/miranda.h @@ -0,0 +1,131 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#define NEWSTR_ALLOCA(A) (A == NULL)?NULL:strcpy((char*)alloca(strlen(A)+1), A) +#define NEWTSTR_ALLOCA(A) (A == NULL)?NULL:_tcscpy((TCHAR*)alloca((_tcslen(A)+1)* sizeof(TCHAR)), A) + +struct LangPackMuuid +{ + MUUID muuid; + PLUGININFOEX* pInfo; +}; + +MIR_CORE_DLL(int) LangPackMarkPluginLoaded(PLUGININFOEX* pInfo); + +MIR_CORE_DLL(LangPackMuuid*) LangPackLookupUuid(WPARAM wParam); + +int LoadLangPackModule(void); +void UnloadLangPackModule(void); + +int InitialiseModularEngine(void); +void DestroyModularEngine(void); + +void InitTimeZones(void); +void UninitTimeZones(void); + +int InitPathUtils(void); + +extern HINSTANCE hInst; + +/**** modules.cpp **********************************************************************/ + +struct THookSubscriber +{ + HINSTANCE hOwner; + int type; + union { + struct { + union { + MIRANDAHOOK pfnHook; + MIRANDAHOOKPARAM pfnHookParam; + MIRANDAHOOKOBJ pfnHookObj; + MIRANDAHOOKOBJPARAM pfnHookObjParam; + }; + void* object; + LPARAM lParam; + }; + struct { + HWND hwnd; + UINT message; + }; + }; +}; + +struct THook +{ + char name[ MAXMODULELABELLENGTH ]; + int id; + int subscriberCount; + THookSubscriber* subscriber; + MIRANDAHOOK pfnHook; + CRITICAL_SECTION csHook; +}; + +/**** langpack.cpp *********************************************************************/ + +char* LangPackTranslateString(struct LangPackMuuid* pUuid, const char *szEnglish, const int W); +TCHAR* LangPackTranslateStringT(int hLangpack, const TCHAR* tszEnglish); + +/**** options.cpp **********************************************************************/ + +HTREEITEM FindNamedTreeItemAtRoot(HWND hwndTree, const TCHAR* name); + +/**** utils.cpp ************************************************************************/ + +void HotkeyToName(TCHAR *buf, int size, BYTE shift, BYTE key); +WORD GetHotkeyValue(INT_PTR idHotkey); + +HBITMAP ConvertIconToBitmap(HICON hIcon, HIMAGELIST hIml, int iconId); + +class StrConvUT +{ +private: + wchar_t* m_body; + +public: + StrConvUT(const char* pSrc) : + m_body(mir_a2u(pSrc)) {} + + ~StrConvUT() { mir_free(m_body); } + operator const wchar_t* () const { return m_body; } +}; + +class StrConvAT +{ +private: + char* m_body; + +public: + StrConvAT(const wchar_t* pSrc) : + m_body(mir_u2a(pSrc)) {} + + ~StrConvAT() { mir_free(m_body); } + operator const char* () const { return m_body; } + operator const wchar_t* () const { return (wchar_t*)m_body; } // type cast to fake the interface definition + operator const LPARAM () const { return (LPARAM)m_body; } +}; + +#define StrConvT(x) StrConvUT(x) +#define StrConvTu(x) x +#define StrConvA(x) StrConvAT(x) +#define StrConvU(x) x diff --git a/plugins/mir_core/modules.cpp b/plugins/mir_core/modules.cpp new file mode 100644 index 0000000000..6a9aa54bcb --- /dev/null +++ b/plugins/mir_core/modules.cpp @@ -0,0 +1,644 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" +#include + +// list of hooks + +static int compareHooks(const THook* p1, const THook* p2) +{ + return strcmp(p1->name, p2->name); +} + +static LIST hooks(50, compareHooks); + +struct THookToMainThreadItem +{ + THook* hook; + HANDLE hDoneEvent; + WPARAM wParam; + LPARAM lParam; + int result; +}; + +// list of services + +struct TService +{ + DWORD nameHash; + HINSTANCE hOwner; + union { + MIRANDASERVICE pfnService; + MIRANDASERVICEPARAM pfnServiceParam; + MIRANDASERVICEOBJ pfnServiceObj; + MIRANDASERVICEOBJPARAM pfnServiceObjParam; + }; + int flags; + LPARAM lParam; + void* object; + char name[1]; +}; + +LIST services(100, NumericKeySortT); + +typedef struct +{ + HANDLE hDoneEvent; + WPARAM wParam; + LPARAM lParam; + int result; + const char *name; +} + TServiceToMainThreadItem; + +// other static variables +static BOOL bServiceMode = FALSE; +static CRITICAL_SECTION csHooks, csServices; +static DWORD mainThreadId; +static int hookId = 1; +static HANDLE hMainThread; +static HANDLE hMissingService; +static THook *pLastHook = NULL; + +/////////////////////////////////////////////////////////////////////////////// +// HOOKS + +MIR_CORE_DLL(HANDLE) CreateHookableEvent(const char *name) +{ + THook* ret; + int idx; + + if (name == NULL) + return NULL; + + EnterCriticalSection(&csHooks); + if ((idx = hooks.getIndex((THook*)name)) != -1) { + LeaveCriticalSection(&csHooks); + return NULL; + } + + ret = (THook*)mir_alloc(sizeof(THook)); + strncpy(ret->name, name, sizeof(ret->name)); ret->name[ MAXMODULELABELLENGTH-1 ] = 0; + ret->id = hookId++; + ret->subscriberCount = 0; + ret->subscriber = NULL; + ret->pfnHook = NULL; + InitializeCriticalSection(&ret->csHook); + hooks.insert(ret); + + LeaveCriticalSection(&csHooks); + return (HANDLE)ret; +} + +MIR_CORE_DLL(int) DestroyHookableEvent(HANDLE hEvent) +{ + EnterCriticalSection(&csHooks); + if (pLastHook == (THook*)hEvent) + pLastHook = NULL; + + int idx; + if ((idx = hooks.getIndex((THook*)hEvent)) == -1) { + LeaveCriticalSection(&csHooks); + return 1; + } + + THook* p = hooks[idx]; + if (p->subscriberCount) { + mir_free(p->subscriber); + p->subscriber = NULL; + p->subscriberCount = 0; + } + hooks.remove(idx); + DeleteCriticalSection(&p->csHook); + mir_free(p); + + LeaveCriticalSection(&csHooks); + return 0; +} + +MIR_CORE_DLL(int) SetHookDefaultForHookableEvent(HANDLE hEvent, MIRANDAHOOK pfnHook) +{ + THook* p = (THook*)hEvent; + + EnterCriticalSection(&csHooks); + if (hooks.getIndex(p) != -1) + p->pfnHook = pfnHook; + LeaveCriticalSection(&csHooks); + return 0; +} + +MIR_CORE_DLL(int) CallPluginEventHook(HINSTANCE hInst, HANDLE hEvent, WPARAM wParam, LPARAM lParam) +{ + int returnVal = 0; + THook* p = (THook*)hEvent; + if (p == NULL) + return -1; + + EnterCriticalSection(&p->csHook); + for (int i = 0; i < p->subscriberCount; i++) { + THookSubscriber* s = &p->subscriber[i]; + if (s->hOwner != hInst) + continue; + + switch (s->type) { + case 1: returnVal = s->pfnHook(wParam, lParam); break; + case 2: returnVal = s->pfnHookParam(wParam, lParam, s->lParam); break; + case 3: returnVal = s->pfnHookObj(s->object, wParam, lParam); break; + case 4: returnVal = s->pfnHookObjParam(s->object, wParam, lParam, s->lParam); break; + case 5: returnVal = SendMessage(s->hwnd, s->message, wParam, lParam); break; + default: continue; + } + if (returnVal) + break; + } + + if (p->subscriberCount == 0 && p->pfnHook != 0) + returnVal = p->pfnHook(wParam, lParam); + + LeaveCriticalSection(&p->csHook); + return returnVal; +} + +MIR_CORE_DLL(int) CallHookSubscribers(HANDLE hEvent, WPARAM wParam, LPARAM lParam) +{ + int returnVal = 0; + THook* p = (THook*)hEvent; + if (p == NULL) + return -1; + + EnterCriticalSection(&p->csHook); + + // NOTE: We've got the critical section while all this lot are called. That's mostly safe, though. + for (int i = 0; i < p->subscriberCount; i++) { + THookSubscriber* s = &p->subscriber[i]; + switch (s->type) { + case 1: returnVal = s->pfnHook(wParam, lParam); break; + case 2: returnVal = s->pfnHookParam(wParam, lParam, s->lParam); break; + case 3: returnVal = s->pfnHookObj(s->object, wParam, lParam); break; + case 4: returnVal = s->pfnHookObjParam(s->object, wParam, lParam, s->lParam); break; + case 5: returnVal = SendMessage(s->hwnd, s->message, wParam, lParam); break; + default: continue; + } + if (returnVal) + break; + } + + // check for no hooks and call the default hook if any + if (p->subscriberCount == 0 && p->pfnHook != 0) + returnVal = p->pfnHook(wParam, lParam); + + LeaveCriticalSection(&p->csHook); + return returnVal; +} + +static int checkHook(HANDLE hHook) +{ + if (hHook == NULL) + return -1; + + EnterCriticalSection(&csHooks); + if (pLastHook != hHook || !pLastHook) { + if (hooks.getIndex((THook*)hHook) == -1) { + LeaveCriticalSection(&csHooks); + return -1; + } + pLastHook = (THook*)hHook; + } + LeaveCriticalSection(&csHooks); + return 0; +} + +static void CALLBACK HookToMainAPCFunc(ULONG_PTR dwParam) +{ + THookToMainThreadItem* item = (THookToMainThreadItem*)dwParam; + + if (checkHook(item->hook) == -1) + item->result = -1; + else + item->result = CallHookSubscribers(item->hook, item->wParam, item->lParam); + SetEvent(item->hDoneEvent); +} + +MIR_CORE_DLL(int) NotifyEventHooks(HANDLE hEvent, WPARAM wParam, LPARAM lParam) +{ + extern HWND hAPCWindow; + + if ( GetCurrentThreadId() != mainThreadId) { + THookToMainThreadItem item; + + item.hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + item.hook = (THook*)hEvent; + item.wParam = wParam; + item.lParam = lParam; + + QueueUserAPC(HookToMainAPCFunc, hMainThread, (ULONG_PTR)&item); + PostMessage(hAPCWindow, WM_NULL, 0, 0); // let it process APC even if we're in a common dialog + WaitForSingleObject(item.hDoneEvent, INFINITE); + CloseHandle(item.hDoneEvent); + return item.result; + } + + return (checkHook(hEvent) == -1) ? -1 : CallHookSubscribers(hEvent, wParam, lParam); +} + +static HANDLE HookEventInt(int type, const char* name, MIRANDAHOOK hookProc, void* object, LPARAM lParam) +{ + int idx; + THook* p; + HANDLE ret; + + EnterCriticalSection(&csHooks); + if ((idx = hooks.getIndex((THook*)name)) == -1) { + #ifdef _DEBUG + OutputDebugStringA("Attempt to hook: \t"); + OutputDebugStringA(name); + OutputDebugStringA("\n"); + #endif + LeaveCriticalSection(&csHooks); + return NULL; + } + + p = hooks[ idx ]; + p->subscriber = (THookSubscriber*)mir_realloc(p->subscriber, sizeof(THookSubscriber)*(p->subscriberCount+1)); + p->subscriber[ p->subscriberCount ].type = type; + p->subscriber[ p->subscriberCount ].pfnHook = hookProc; + p->subscriber[ p->subscriberCount ].object = object; + p->subscriber[ p->subscriberCount ].lParam = lParam; + p->subscriber[ p->subscriberCount ].hOwner = GetInstByAddress(hookProc); + p->subscriberCount++; + + ret = (HANDLE)((p->id << 16) | p->subscriberCount); + LeaveCriticalSection(&csHooks); + return ret; +} + +MIR_CORE_DLL(HANDLE) HookEvent(const char* name, MIRANDAHOOK hookProc) +{ + return HookEventInt(1, name, hookProc, 0, 0); +} + +MIR_CORE_DLL(HANDLE) HookEventParam(const char* name, MIRANDAHOOKPARAM hookProc, LPARAM lParam) +{ + return HookEventInt(2, name, (MIRANDAHOOK)hookProc, 0, lParam); +} + +MIR_CORE_DLL(HANDLE) HookEventObj(const char* name, MIRANDAHOOKOBJ hookProc, void* object) +{ + return HookEventInt(3, name, (MIRANDAHOOK)hookProc, object, 0); +} + +MIR_CORE_DLL(HANDLE) HookEventObjParam(const char* name, MIRANDAHOOKOBJPARAM hookProc, void* object, LPARAM lParam) +{ + return HookEventInt(4, name, (MIRANDAHOOK)hookProc, object, lParam); +} + +MIR_CORE_DLL(HANDLE) HookEventMessage(const char* name, HWND hwnd, UINT message) +{ + int idx; + THook* p; + HANDLE ret; + + EnterCriticalSection(&csHooks); + if ((idx = hooks.getIndex((THook*)name)) == -1) { + #ifdef _DEBUG + MessageBoxA(NULL, "Attempt to hook non-existant event", name, MB_OK); + #endif + LeaveCriticalSection(&csHooks); + return NULL; + } + + p = hooks[ idx ]; + p->subscriber = (THookSubscriber*)mir_realloc(p->subscriber, sizeof(THookSubscriber)*(p->subscriberCount+1)); + p->subscriber[ p->subscriberCount ].type = 5; + p->subscriber[ p->subscriberCount ].hwnd = hwnd; + p->subscriber[ p->subscriberCount ].message = message; + p->subscriberCount++; + + ret = (HANDLE)((p->id << 16) | p->subscriberCount); + LeaveCriticalSection(&csHooks); + return ret; +} + +MIR_CORE_DLL(int) UnhookEvent(HANDLE hHook) +{ + int i; + THook* p = NULL; + + int hookId = (int)hHook >> 16; + int subscriberId = ((int)hHook & 0xFFFF) - 1; + + if (hHook == NULL) return 0; + + EnterCriticalSection(&csHooks); + for (i = 0; i < hooks.getCount(); i++) { + if (hooks[i]->id == hookId) { + p = hooks[i]; + break; + } } + + if (p == NULL) { + LeaveCriticalSection(&csHooks); + return 1; + } + + if (subscriberId >= p->subscriberCount || subscriberId < 0) { + LeaveCriticalSection(&csHooks); + return 1; + } + + p->subscriber[subscriberId].type = 0; + p->subscriber[subscriberId].pfnHook = NULL; + p->subscriber[subscriberId].hOwner = NULL; + while (p->subscriberCount && p->subscriber[p->subscriberCount-1].type == 0) + p->subscriberCount--; + if (p->subscriberCount == 0) { + if (p->subscriber) mir_free(p->subscriber); + p->subscriber = NULL; + } + LeaveCriticalSection(&csHooks); + return 0; +} + +MIR_CORE_DLL(void) KillModuleEventHooks(HINSTANCE hInst) +{ + int i, j; + + EnterCriticalSection(&csHooks); + for (i = hooks.getCount()-1; i >= 0; i--) { + if (hooks[i]->subscriberCount == 0) + continue; + + for (j = hooks[i]->subscriberCount-1; j >= 0; j--) { + if (hooks[i]->subscriber[j].hOwner == hInst) { + char szModuleName[ MAX_PATH ]; + GetModuleFileNameA(hooks[i]->subscriber[j].hOwner, szModuleName, sizeof(szModuleName)); + UnhookEvent((HANDLE)((hooks[i]->id << 16) + j + 1)); + if (hooks[i]->subscriberCount == 0) + break; + } } } + + LeaveCriticalSection(&csHooks); +} + +MIR_CORE_DLL(void) KillObjectEventHooks(void* pObject) +{ + int i, j; + + EnterCriticalSection(&csHooks); + for (i = hooks.getCount()-1; i >= 0; i--) { + if (hooks[i]->subscriberCount == 0) + continue; + + for (j = hooks[i]->subscriberCount-1; j >= 0; j--) { + if (hooks[i]->subscriber[j].object == pObject) { + UnhookEvent((HANDLE)((hooks[i]->id << 16) + j + 1)); + if (hooks[i]->subscriberCount == 0) + break; + } } } + + LeaveCriticalSection(&csHooks); +} + +/////////////////////SERVICES + +static __inline TService* FindServiceByName(const char *name) +{ + unsigned hash = mir_hashstr(name); + return services.find((TService*)&hash); +} + +static HANDLE CreateServiceInt(int type, const char *name, MIRANDASERVICE serviceProc, void* object, LPARAM lParam) +{ + if (name == NULL) + return NULL; + + TService tmp; + tmp.nameHash = mir_hashstr(name); + + EnterCriticalSection(&csServices); + + if (services.getIndex(&tmp) != -1) { + LeaveCriticalSection(&csServices); + return NULL; + } + + TService* p = (TService*)mir_alloc(sizeof(*p) + strlen(name)); + strcpy(p->name, name); + p->nameHash = tmp.nameHash; + p->pfnService = serviceProc; + p->hOwner = GetInstByAddress(serviceProc); + p->flags = type; + p->lParam = lParam; + p->object = object; + services.insert(p); + + LeaveCriticalSection(&csServices); + return (HANDLE)tmp.nameHash; +} + +MIR_CORE_DLL(HANDLE) CreateServiceFunction(const char *name, MIRANDASERVICE serviceProc) +{ + return CreateServiceInt(0, name, serviceProc, 0, 0); +} + +MIR_CORE_DLL(HANDLE) CreateServiceFunctionParam(const char *name, MIRANDASERVICEPARAM serviceProc, LPARAM lParam) +{ + return CreateServiceInt(1, name, (MIRANDASERVICE)serviceProc, 0, lParam); +} + +MIR_CORE_DLL(HANDLE) CreateServiceFunctionObj(const char *name, MIRANDASERVICEOBJ serviceProc, void* object) +{ + return CreateServiceInt(2, name, (MIRANDASERVICE)serviceProc, object, 0); +} + +MIR_CORE_DLL(HANDLE) CreateServiceFunctionObjParam(const char *name, MIRANDASERVICEOBJPARAM serviceProc, void* object, LPARAM lParam) +{ + return CreateServiceInt(3, name, (MIRANDASERVICE)serviceProc, object, lParam); +} + +MIR_CORE_DLL(int) DestroyServiceFunction(HANDLE hService) +{ + int idx; + + EnterCriticalSection(&csServices); + if ((idx = services.getIndex((TService*)&hService)) != -1) { + mir_free(services[idx]); + services.remove(idx); + } + + LeaveCriticalSection(&csServices); + return 0; +} + +MIR_CORE_DLL(int) ServiceExists(const char *name) +{ + if (name == NULL) + return FALSE; + + EnterCriticalSection(&csServices); + int ret = FindServiceByName(name) != NULL; + LeaveCriticalSection(&csServices); + return ret; +} + +MIR_CORE_DLL(INT_PTR) CallService(const char *name, WPARAM wParam, LPARAM lParam) +{ + #ifdef _DEBUG + if (name == NULL) { + MessageBoxA(0, "Someone tried to CallService(NULL, ..) see stack trace for details", "", 0); + DebugBreak(); + return CALLSERVICE_NOTFOUND; + } + #else + if (name == NULL) return CALLSERVICE_NOTFOUND; + #endif + + EnterCriticalSection(&csServices); + TService *pService = FindServiceByName(name); + if (pService == NULL) { + LeaveCriticalSection(&csServices); + #ifdef _DEBUG + OutputDebugStringA("Missing service called: \t"); + OutputDebugStringA(name); + OutputDebugStringA("\n"); + #endif + + return CALLSERVICE_NOTFOUND; + } + + MIRANDASERVICE pfnService = pService->pfnService; + int flags = pService->flags; + LPARAM fnParam = pService->lParam; + void* object = pService->object; + LeaveCriticalSection(&csServices); + switch(flags) { + case 1: return ((MIRANDASERVICEPARAM)pfnService)(wParam, lParam, fnParam); + case 2: return ((MIRANDASERVICEOBJ)pfnService)(object, wParam, lParam); + case 3: return ((MIRANDASERVICEOBJPARAM)pfnService)(object, wParam, lParam, fnParam); + default: return pfnService(wParam, lParam); +} } + +static void CALLBACK CallServiceToMainAPCFunc(ULONG_PTR dwParam) +{ + TServiceToMainThreadItem *item = (TServiceToMainThreadItem*) dwParam; + item->result = CallService(item->name, item->wParam, item->lParam); + SetEvent(item->hDoneEvent); +} + +MIR_CORE_DLL(INT_PTR) CallServiceSync(const char *name, WPARAM wParam, LPARAM lParam) +{ + extern HWND hAPCWindow; + + if (name == NULL) return CALLSERVICE_NOTFOUND; + // the service is looked up within the main thread, since the time it takes + // for the APC queue to clear the service being called maybe removed. + // even thou it may exists before the call, the critsec can't be locked between calls. + if (GetCurrentThreadId() != mainThreadId) { + TServiceToMainThreadItem item; + item.wParam = wParam; + item.lParam = lParam; + item.name = name; + item.hDoneEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + QueueUserAPC(CallServiceToMainAPCFunc, hMainThread, (ULONG_PTR) &item); + PostMessage(hAPCWindow, WM_NULL, 0, 0); // let this get processed in its own time + WaitForSingleObject(item.hDoneEvent, INFINITE); + CloseHandle(item.hDoneEvent); + return item.result; + } + + return CallService(name, wParam, lParam); +} + +MIR_CORE_DLL(int) CallFunctionAsync(void (__stdcall *func)(void *), void *arg) +{ + extern HWND hAPCWindow; + int r = QueueUserAPC((void (__stdcall *)(ULONG_PTR))func, hMainThread, (ULONG_PTR)arg); + PostMessage(hAPCWindow, WM_NULL, 0, 0); + return r; +} + +MIR_CORE_DLL(void) KillModuleServices(HINSTANCE hInst) +{ + int i; + + EnterCriticalSection(&csServices); + for (i = services.getCount()-1; i >= 0; i--) { + if (services[i]->hOwner == hInst) { + char szModuleName[ MAX_PATH ]; + GetModuleFileNameA(services[i]->hOwner, szModuleName, sizeof(szModuleName)); + DestroyServiceFunction((HANDLE)services[i]->nameHash); + } } + + LeaveCriticalSection(&csServices); +} + +MIR_CORE_DLL(void) KillObjectServices(void* pObject) +{ + int i; + + EnterCriticalSection(&csServices); + for (i = services.getCount()-1; i >= 0; i--) + if (services[i]->object == pObject) + DestroyServiceFunction((HANDLE)services[i]->nameHash); + + LeaveCriticalSection(&csServices); +} + +/////////////////////////////////////////////////////////////////////////////// + +int InitialiseModularEngine(void) +{ + InitializeCriticalSection(&csHooks); + InitializeCriticalSection(&csServices); + + mainThreadId = GetCurrentThreadId(); + DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &hMainThread, 0, FALSE, DUPLICATE_SAME_ACCESS); + + hMissingService = CreateHookableEvent(ME_SYSTEM_MISSINGSERVICE); + return 0; +} + +void DestroyModularEngine(void) +{ + EnterCriticalSection(&csHooks); + for (int i=0; i < hooks.getCount(); i++) { + THook* p = hooks[i]; + if (p->subscriberCount) + mir_free(p->subscriber); + DeleteCriticalSection(&p->csHook); + mir_free(p); + } + hooks.destroy(); + LeaveCriticalSection(&csHooks); + DeleteCriticalSection(&csHooks); + + EnterCriticalSection(&csServices); + for (int j=0; j < services.getCount(); j++) + mir_free(services[j]); + + services.destroy(); + LeaveCriticalSection(&csServices); + DeleteCriticalSection(&csServices); + CloseHandle(hMainThread); +} diff --git a/plugins/mir_core/path.cpp b/plugins/mir_core/path.cpp new file mode 100644 index 0000000000..fada3dcd18 --- /dev/null +++ b/plugins/mir_core/path.cpp @@ -0,0 +1,210 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "commonheaders.h" + +static char szMirandaPath[MAX_PATH]; +static char szMirandaPathLower[MAX_PATH]; +static TCHAR szMirandaPathW[MAX_PATH]; +static TCHAR szMirandaPathWLower[MAX_PATH]; + +static int pathIsAbsolute(const char *path) +{ + if (strlen(path) <= 2) + return 0; + if ((path[1] == ':' && path[2] == '\\') || (path[0] == '\\' && path[1] == '\\')) + return 1; + return 0; +} + +MIR_CORE_DLL(int) PathToRelative(const char *pSrc, char *pOut) +{ + if ( !pSrc || !strlen(pSrc) || strlen(pSrc)>MAX_PATH) return 0; + if ( !pathIsAbsolute(pSrc)) { + mir_snprintf(pOut, MAX_PATH, "%s", pSrc); + return (int)strlen(pOut); + } + + char szTmp[MAX_PATH]; + mir_snprintf(szTmp, SIZEOF(szTmp), "%s", pSrc); + _strlwr(szTmp); + if (strstr(szTmp, szMirandaPathLower)) { + mir_snprintf(pOut, MAX_PATH, "%s", pSrc+strlen(szMirandaPathLower)); + return (int)strlen(pOut); + } + else { + mir_snprintf(pOut, MAX_PATH, "%s", pSrc); + return (int)strlen(pOut); + } +} + +MIR_CORE_DLL(int) PathToAbsolute(const char *pSrc, char *pOut, char* base) +{ + if ( !pSrc || !strlen(pSrc) || strlen(pSrc) > MAX_PATH) + return 0; + + if (base == NULL) + base = szMirandaPath; + + char buf[MAX_PATH]; + if (pSrc[0] < ' ') + return mir_snprintf(pOut, MAX_PATH, "%s", pSrc); + else if (pathIsAbsolute(pSrc)) + return GetFullPathNameA(pSrc, MAX_PATH, pOut, NULL); + else if (pSrc[0] != '\\') + mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc); + else + mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc+1); + + return GetFullPathNameA(buf, MAX_PATH, pOut, NULL); +} + +MIR_CORE_DLL(void) CreatePathToFile(char* szFilePath) +{ + char* pszLastBackslash = strrchr(szFilePath, '\\'); + if (pszLastBackslash == NULL) + return; + + *pszLastBackslash = '\0'; + CreateDirectoryTree(szFilePath); + *pszLastBackslash = '\\'; +} + +MIR_CORE_DLL(int) CreateDirectoryTree(const char *szDir) +{ + DWORD dwAttributes; + char *pszLastBackslash, szTestDir[ MAX_PATH ]; + + lstrcpynA(szTestDir, szDir, SIZEOF(szTestDir)); + if ((dwAttributes = GetFileAttributesA(szTestDir)) != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) + return 0; + + pszLastBackslash = strrchr(szTestDir, '\\'); + if (pszLastBackslash == NULL) + return 0; + + *pszLastBackslash = '\0'; + CreateDirectoryTree(szTestDir); + *pszLastBackslash = '\\'; + return (CreateDirectoryA(szTestDir, NULL) == 0) ? GetLastError() : 0; +} + +/////////////////////////////////////////////////////////////////////////////// + +static int pathIsAbsoluteW(const TCHAR *path) +{ + if (lstrlen(path) <= 2) + return 0; + if ((path[1] == ':' && path[2] == '\\') || (path[0] == '\\' && path[1] == '\\')) + return 1; + return 0; +} + +MIR_CORE_DLL(int) PathToRelativeW(const WCHAR *pSrc, WCHAR *pOut) +{ + if ( !pSrc || !lstrlen(pSrc) || lstrlen(pSrc) > MAX_PATH) + return 0; + + if ( !pathIsAbsoluteW(pSrc)) + mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc); + else { + TCHAR szTmp[MAX_PATH]; + + mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%s"), pSrc); + _tcslwr(szTmp); + if (_tcsstr(szTmp, szMirandaPathWLower)) + mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc+lstrlen(szMirandaPathWLower)); + else + mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc); + } + return lstrlen(pOut); +} + +MIR_CORE_DLL(int) PathToAbsoluteW(const TCHAR *pSrc, TCHAR *pOut, TCHAR* base) +{ + if ( !pSrc || !wcslen(pSrc) || wcslen(pSrc) > MAX_PATH) + return 0; + + if (base == NULL) + base = szMirandaPathW; + + TCHAR buf[MAX_PATH]; + if (pSrc[0] < ' ') + return mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc); + else if (pathIsAbsoluteW(pSrc)) + return GetFullPathName(pSrc, MAX_PATH, pOut, NULL); + else if (pSrc[0] != '\\') + mir_sntprintf(buf, MAX_PATH, _T("%s%s"), base, pSrc); + else + mir_sntprintf(buf, MAX_PATH, _T("%s%s"), base, pSrc+1); + + return GetFullPathName(buf, MAX_PATH, pOut, NULL); +} + +MIR_CORE_DLL(void) CreatePathToFileW(WCHAR* wszFilePath) +{ + WCHAR* pszLastBackslash = wcsrchr(wszFilePath, '\\'); + if (pszLastBackslash == NULL) + return; + + *pszLastBackslash = '\0'; + CreateDirectoryTreeW(wszFilePath); + *pszLastBackslash = '\\'; +} + +MIR_CORE_DLL(int) CreateDirectoryTreeW(const WCHAR* szDir) +{ + DWORD dwAttributes; + WCHAR* pszLastBackslash, szTestDir[ MAX_PATH ]; + + lstrcpynW(szTestDir, szDir, SIZEOF(szTestDir)); + if ((dwAttributes = GetFileAttributesW(szTestDir)) != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) + return 0; + + pszLastBackslash = wcsrchr(szTestDir, '\\'); + if (pszLastBackslash == NULL) + return 0; + + *pszLastBackslash = '\0'; + CreateDirectoryTreeW(szTestDir); + *pszLastBackslash = '\\'; + return (CreateDirectoryW(szTestDir, NULL) == 0) ? GetLastError() : 0; +} + +int InitPathUtils(void) +{ + char *p = 0; + GetModuleFileNameA(hInst, szMirandaPath, SIZEOF(szMirandaPath)); + p = strrchr(szMirandaPath, '\\'); + if (p) + p[1] = 0; + mir_snprintf(szMirandaPathLower, MAX_PATH, "%s", szMirandaPath); + _strlwr(szMirandaPathLower); + + GetModuleFileName(hInst, szMirandaPathW, SIZEOF(szMirandaPathW)); + TCHAR *tp = _tcsrchr(szMirandaPathW, '\\'); + if (tp) + tp[1] = 0; + mir_sntprintf(szMirandaPathWLower, SIZEOF(szMirandaPathWLower), _T("%s"), szMirandaPathW); + _tcslwr(szMirandaPathWLower); + return 0; +} diff --git a/plugins/mir_core/timezones.cpp b/plugins/mir_core/timezones.cpp new file mode 100644 index 0000000000..24340cd3d8 --- /dev/null +++ b/plugins/mir_core/timezones.cpp @@ -0,0 +1,224 @@ +/* +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2010 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +implements services to handle location - based timezones, instead of +simple UTC offsets. +*/ + +#include "commonheaders.h" + +#include + +typedef DWORD (WINAPI *pfnGetDynamicTimeZoneInformation_t)(DYNAMIC_TIME_ZONE_INFORMATION *pdtzi); +static pfnGetDynamicTimeZoneInformation_t pfnGetDynamicTimeZoneInformation; + +typedef HRESULT (WINAPI *pfnSHLoadIndirectString_t)(LPCWSTR pszSource, LPWSTR pszOutBuf, UINT cchOutBuf, void **ppvReserved); +static pfnSHLoadIndirectString_t pfnSHLoadIndirectString; + +typedef LANGID (WINAPI *pfnGetUserDefaultUILanguage_t)(void); +static pfnGetUserDefaultUILanguage_t pfnGetUserDefaultUILanguage; + +typedef LANGID (WINAPI *pfnGetSystemDefaultUILanguage_t)(void); +static pfnGetSystemDefaultUILanguage_t pfnGetSystemDefaultUILanguage; + +typedef LPARAM (WINAPI *pfnSendMessageW_t)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); +static pfnSendMessageW_t pfnSendMessageW; + +typedef struct _REG_TZI_FORMAT +{ + LONG Bias; + LONG StandardBias; + LONG DaylightBias; + SYSTEMTIME StandardDate; + SYSTEMTIME DaylightDate; +} REG_TZI_FORMAT; + +#define MIM_TZ_DISPLAYLEN 128 + +struct MIM_TIMEZONE +{ + unsigned hash; + int offset; + + TCHAR tszName[MIM_TZ_NAMELEN]; // windows name for the time zone + wchar_t szDisplay[MIM_TZ_DISPLAYLEN]; // more descriptive display name (that's what usually appears in dialogs) + // every hour should be sufficient. + TIME_ZONE_INFORMATION tzi; + + static int compareBias(const MIM_TIMEZONE* p1, const MIM_TIMEZONE* p2) + { return p2->tzi.Bias - p1->tzi.Bias; } +}; + +typedef struct +{ + DWORD timestamp; // last time updated + MIM_TIMEZONE myTZ; // set to my own timezone +} TZ_INT_INFO; + +static TZ_INT_INFO myInfo; +bool muiInstalled; + +static OBJLIST g_timezones(55, NumericKeySortT); +static LIST g_timezonesBias(55, MIM_TIMEZONE::compareBias); + +void FormatTime (const SYSTEMTIME *st, const TCHAR *szFormat, TCHAR *szDest, int cbDest); +void UnixTimeToFileTime(time_t ts, LPFILETIME pft); +time_t FileTimeToUnixTime(LPFILETIME pft); + +#define fnSystemTimeToTzSpecificLocalTime SystemTimeToTzSpecificLocalTime + +void GetLocalizedString(HKEY hSubKey, const TCHAR *szName, wchar_t *szBuf, DWORD cbLen) +{ + szBuf[0] = 0; + if (muiInstalled) + { + TCHAR tszTempBuf[MIM_TZ_NAMELEN], tszName[30]; + mir_sntprintf(tszName, SIZEOF(tszName), _T("MUI_%s"), szName); + DWORD dwLength = cbLen * sizeof(TCHAR); + if (ERROR_SUCCESS == RegQueryValueEx(hSubKey, tszName, NULL, NULL, (unsigned char *)tszTempBuf, &dwLength)) + { + tszTempBuf[min(dwLength / sizeof(TCHAR), cbLen - 1)] = 0; + if (pfnSHLoadIndirectString) + pfnSHLoadIndirectString(StrConvU(tszTempBuf), szBuf, cbLen, NULL); + } + } + if (szBuf[0] == 0) + { + DWORD dwLength = cbLen * sizeof(wchar_t); + + + RegQueryValueEx(hSubKey, szName, NULL, NULL, (unsigned char *)szBuf, &dwLength); + szBuf[min(dwLength / sizeof(TCHAR), cbLen - 1)] = 0; + } +} + +void RecalculateTime(void) +{ + GetTimeZoneInformation(&myInfo.myTZ.tzi); + myInfo.timestamp = time(NULL); + myInfo.myTZ.offset = INT_MIN; + + bool found = false; + DYNAMIC_TIME_ZONE_INFORMATION dtzi; + + if (pfnGetDynamicTimeZoneInformation && pfnGetDynamicTimeZoneInformation(&dtzi) != TIME_ZONE_ID_INVALID) + { + TCHAR *myTzKey = mir_u2t(dtzi.TimeZoneKeyName); + _tcscpy(myInfo.myTZ.tszName, myTzKey); + mir_free(myTzKey); + found = true; + } + + for (int i = 0; i < g_timezones.getCount(); ++i) + { + MIM_TIMEZONE &tz = g_timezones[i]; + if (tz.offset != INT_MIN) tz.offset = INT_MIN; + + if ( !found) + { + if ( !wcscmp(tz.tzi.StandardName, myInfo.myTZ.tzi.StandardName) || + !wcscmp(tz.tzi.DaylightName, myInfo.myTZ.tzi.DaylightName)) + { + _tcscpy(myInfo.myTZ.tszName, tz.tszName); + found = true; + } + } + } +} + +void InitTimeZones(void) +{ + REG_TZI_FORMAT tzi; + HKEY hKey; + + const TCHAR *tszKey = IsWinVerNT() ? + _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones") : + _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Time Zones"); + + /* + * use GetDynamicTimeZoneInformation() on Vista+ - this will return a structure with + * the registry key name, so finding our own time zone later will be MUCH easier for + * localized systems or systems with a MUI pack installed + */ + if (IsWinVerVistaPlus()) + pfnGetDynamicTimeZoneInformation = (pfnGetDynamicTimeZoneInformation_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetDynamicTimeZoneInformation"); + + if (IsWinVer2000Plus()) + { + pfnSHLoadIndirectString = (pfnSHLoadIndirectString_t)GetProcAddress(GetModuleHandle(_T("shlwapi")), "SHLoadIndirectString"); + pfnGetSystemDefaultUILanguage = (pfnGetSystemDefaultUILanguage_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetSystemDefaultUILanguage"); + pfnGetUserDefaultUILanguage = (pfnGetUserDefaultUILanguage_t)GetProcAddress(GetModuleHandle(_T("kernel32")), "GetUserDefaultUILanguage"); + muiInstalled = pfnSHLoadIndirectString && pfnGetSystemDefaultUILanguage() != pfnGetUserDefaultUILanguage(); + } + + pfnSendMessageW = (pfnSendMessageW_t)GetProcAddress(GetModuleHandle(_T("user32")), "SendMessageW"); + + if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, tszKey, 0, KEY_ENUMERATE_SUB_KEYS, &hKey)) + { + DWORD dwIndex = 0; + HKEY hSubKey; + TCHAR tszName[MIM_TZ_NAMELEN]; + + DWORD dwSize = SIZEOF(tszName); + while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKey, dwIndex++, tszName, &dwSize, NULL, NULL, 0, NULL)) + { + if (ERROR_SUCCESS == RegOpenKeyEx(hKey, tszName, 0, KEY_QUERY_VALUE, &hSubKey)) + { + dwSize = sizeof(tszName); + + DWORD dwLength = sizeof(tzi); + if (ERROR_SUCCESS != RegQueryValueEx(hSubKey, _T("TZI"), NULL, NULL, (unsigned char *)&tzi, &dwLength)) + continue; + + MIM_TIMEZONE *tz = new MIM_TIMEZONE; + + tz->tzi.Bias = tzi.Bias; + tz->tzi.StandardDate = tzi.StandardDate; + tz->tzi.StandardBias = tzi.StandardBias; + tz->tzi.DaylightDate = tzi.DaylightDate; + tz->tzi.DaylightBias = tzi.DaylightBias; + + _tcscpy(tz->tszName, tszName); + tz->hash = mir_hashstrT(tszName); + tz->offset = INT_MIN; + + GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, SIZEOF(tz->szDisplay)); + GetLocalizedString(hSubKey, _T("Std"), tz->tzi.StandardName, SIZEOF(tz->tzi.StandardName)); + GetLocalizedString(hSubKey, _T("Dlt"), tz->tzi.DaylightName, SIZEOF(tz->tzi.DaylightName)); + + g_timezones.insert(tz); + g_timezonesBias.insert(tz); + + RegCloseKey(hSubKey); + } + dwSize = SIZEOF(tszName); + } + RegCloseKey(hKey); + } + + RecalculateTime(); +} + +void UninitTimeZones(void) +{ + g_timezonesBias.destroy(); + g_timezones.destroy(); +} diff --git a/plugins/mir_core/utf.cpp b/plugins/mir_core/utf.cpp new file mode 100644 index 0000000000..5ec6042758 --- /dev/null +++ b/plugins/mir_core/utf.cpp @@ -0,0 +1,406 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + + Copyright 2000 Alexandre Julliard of Wine project + (UTF-8 conversion routines) + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +/* number of following bytes in sequence based on first byte value (for bytes above 0x7f) */ +static const char utf8_length[128] = +{ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80-0x8f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90-0x9f */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0-0xaf */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0-0xbf */ + 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xc0-0xcf */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xd0-0xdf */ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xe0-0xef */ + 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xf0-0xff */ +}; + +/* first byte mask depending on UTF-8 sequence length */ +static const unsigned char utf8_mask[4] = { 0x7f, 0x1f, 0x0f, 0x07 }; + +/* minimum Unicode value depending on UTF-8 sequence length */ +static const unsigned int utf8_minval[4] = { 0x0, 0x80, 0x800, 0x10000 }; + +/* get the next char value taking surrogates into account */ +static unsigned int getSurrogateValue(const wchar_t *src, unsigned int srclen) +{ + if (src[0] >= 0xd800 && src[0] <= 0xdfff) { /* surrogate pair */ + if (src[0] > 0xdbff || /* invalid high surrogate */ + srclen <= 1 || /* missing low surrogate */ + src[1] < 0xdc00 || src[1] > 0xdfff) /* invalid low surrogate */ + return 0; + return 0x10000 + ((src[0] & 0x3ff) << 10) + (src[1] & 0x3ff); + } + return src[0]; +} + +/* query necessary dst length for src string */ +static int Ucs2toUtf8Len(const wchar_t *src, unsigned int srclen) +{ + int len; + unsigned int val; + + for (len = 0; srclen; srclen--, src++) { + if (*src < 0x80) { /* 0x00-0x7f: 1 byte */ + len++; + continue; + } + if (*src < 0x800) { /* 0x80-0x7ff: 2 bytes */ + len += 2; + continue; + } + if ( !(val = getSurrogateValue(src, srclen))) + return -2; + + if (val < 0x10000) /* 0x800-0xffff: 3 bytes */ + len += 3; + else { /* 0x10000-0x10ffff: 4 bytes */ + len += 4; + src++; + srclen--; + } + } + return len; +} + +MIR_CORE_DLL(int) Ucs2toUtf8Len(const wchar_t *src) +{ + if (src == 0) + return 0; + + return Ucs2toUtf8Len(src, (int)wcslen(src)); +} + +/* wide char to UTF-8 string conversion */ +/* return -1 on dst buffer overflow, -2 on invalid input char */ +int Ucs2toUtf8(const wchar_t *src, int srclen, char *dst, int dstlen) +{ + int len; + + for (len = dstlen; srclen; srclen--, src++) + { + WCHAR ch = *src; + unsigned int val; + + if (ch < 0x80) /* 0x00-0x7f: 1 byte */ + { + if ( !len--) return -1; /* overflow */ + *dst++ = ch; + continue; + } + + if (ch < 0x800) /* 0x80-0x7ff: 2 bytes */ + { + if ((len -= 2) < 0) return -1; /* overflow */ + dst[1] = 0x80 | (ch & 0x3f); + ch >>= 6; + dst[0] = 0xc0 | ch; + dst += 2; + continue; + } + + if ( !(val = getSurrogateValue(src, srclen))) + { + return -2; + } + + if (val < 0x10000) /* 0x800-0xffff: 3 bytes */ + { + if ((len -= 3) < 0) return -1; /* overflow */ + dst[2] = 0x80 | (val & 0x3f); + val >>= 6; + dst[1] = 0x80 | (val & 0x3f); + val >>= 6; + dst[0] = 0xe0 | val; + dst += 3; + } + else /* 0x10000-0x10ffff: 4 bytes */ + { + if ((len -= 4) < 0) return -1; /* overflow */ + dst[3] = 0x80 | (val & 0x3f); + val >>= 6; + dst[2] = 0x80 | (val & 0x3f); + val >>= 6; + dst[1] = 0x80 | (val & 0x3f); + val >>= 6; + dst[0] = 0xf0 | val; + dst += 4; + src++; + srclen--; + } + } + return dstlen - len; +} + +/* helper for the various utf8 mbstowcs functions */ +static unsigned int decodeUtf8Char(unsigned char ch, const char **str, const char *strend) +{ + unsigned int len = utf8_length[ch-0x80]; + unsigned int res = ch & utf8_mask[len]; + const char *end = *str + len; + + if (end > strend) return ~0; + switch(len) + { + case 3: + if ((ch = end[-3] ^ 0x80) >= 0x40) break; + res = (res << 6) | ch; + (*str)++; + case 2: + if ((ch = end[-2] ^ 0x80) >= 0x40) break; + res = (res << 6) | ch; + (*str)++; + case 1: + if ((ch = end[-1] ^ 0x80) >= 0x40) break; + res = (res << 6) | ch; + (*str)++; + if (res < utf8_minval[len]) break; + return res; + } + return ~0; +} + +/* query necessary dst length for src string */ +static inline int Utf8toUcs2Len(const char *src, int srclen) +{ + int ret = 0; + unsigned int res; + const char *srcend = src + srclen; + + while (src < srcend) + { + unsigned char ch = *src++; + if (ch < 0x80) /* special fast case for 7-bit ASCII */ + { + ret++; + continue; + } + if ((res = decodeUtf8Char(ch, &src, srcend)) <= 0x10ffff) + { + if (res > 0xffff) ret++; + ret++; + } + else return -2; /* bad char */ + /* otherwise ignore it */ + } + return ret; +} + +/* UTF-8 to wide char string conversion */ +/* return -1 on dst buffer overflow, -2 on invalid input char */ +int Utf8toUcs2(const char *src, int srclen, wchar_t *dst, int dstlen) +{ + unsigned int res; + const char *srcend = src + srclen; + wchar_t *dstend = dst + dstlen; + + while ((dst < dstend) && (src < srcend)) + { + unsigned char ch = *src++; + if (ch < 0x80) /* special fast case for 7-bit ASCII */ + { + *dst++ = ch; + continue; + } + if ((res = decodeUtf8Char(ch, &src, srcend)) <= 0xffff) + { + *dst++ = res; + } + else if (res <= 0x10ffff) /* we need surrogates */ + { + if (dst == dstend - 1) return -1; /* overflow */ + res -= 0x10000; + *dst++ = 0xd800 | (res >> 10); + *dst++ = 0xdc00 | (res & 0x3ff); + } + else return -2; /* bad char */ + /* otherwise ignore it */ + } + if (src < srcend) return -1; /* overflow */ + return dstlen - (dstend - dst); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Utf8Decode - converts UTF8-encoded string to the UCS2/MBCS format + +MIR_CORE_DLL(char*) Utf8DecodeCP(char* str, int codepage, wchar_t** ucs2) +{ + int len; + bool needs_free = false; + wchar_t* tempBuf = NULL; + if (ucs2) + *ucs2 = NULL; + + if (str == NULL) + return NULL; + + len = (int)strlen(str); + + if (len < 2) { + if (ucs2 != NULL) { + *ucs2 = tempBuf = (wchar_t*)mir_alloc((len + 1) * sizeof(wchar_t)); + MultiByteToWideChar(codepage, 0, str, len, tempBuf, len); + tempBuf[len] = 0; + } + return str; + } + + int destlen = Utf8toUcs2Len(str, len); + if (destlen < 0) + return NULL; + + if (ucs2 == NULL) { + __try + { + tempBuf = (wchar_t*)alloca((destlen + 1) * sizeof(wchar_t)); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + tempBuf = NULL; + needs_free = true; + } + } + + if (tempBuf == NULL) { + tempBuf = (wchar_t*)mir_alloc((destlen + 1) * sizeof(wchar_t)); + if (tempBuf == NULL) + return NULL; + } + + Utf8toUcs2(str, len, tempBuf, destlen); + tempBuf[destlen] = 0; + WideCharToMultiByte(codepage, 0, tempBuf, -1, str, len + 1, "?", NULL); + + if (ucs2) + *ucs2 = tempBuf; + else if (needs_free) + mir_free(tempBuf); + + return str; +} + +MIR_CORE_DLL(char*) Utf8Decode(char* str, wchar_t** ucs2) +{ + return Utf8DecodeCP(str, LangPackGetDefaultCodePage(), ucs2); +} + +MIR_CORE_DLL(wchar_t*) Utf8DecodeW(const char* str) +{ + if (str == NULL) + return NULL; + + int len = (int)strlen(str); + + int destlen = Utf8toUcs2Len(str, len); + if (destlen < 0) return NULL; + + wchar_t* ucs2 = (wchar_t*)mir_alloc((destlen + 1) * sizeof(wchar_t)); + if (ucs2 == NULL) return NULL; + + if (Utf8toUcs2(str, len, ucs2, destlen) >= 0) + { + ucs2[destlen] = 0; + return ucs2; + } + + mir_free(ucs2); + + return NULL; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Utf8Encode - converts MBCS string to the UTF8-encoded format + +MIR_CORE_DLL(char*) Utf8EncodeCP(const char* src, int codepage) +{ + int len; + bool needs_free = false; + char* result = NULL; + wchar_t* tempBuf; + + if (src == NULL) + return NULL; + + len = (int)strlen(src); + + __try + { + tempBuf = (wchar_t*)alloca((len + 1) * sizeof(wchar_t)); + } + __except(EXCEPTION_EXECUTE_HANDLER) + { + tempBuf = (wchar_t*)mir_alloc((len + 1) * sizeof(wchar_t)); + if (tempBuf == NULL) return NULL; + needs_free = true; + } + + len = MultiByteToWideChar(codepage, 0, src, -1, tempBuf, len + 1); + + int destlen = Ucs2toUtf8Len(tempBuf, len); + if (destlen >= 0) + { + result = (char*)mir_alloc(destlen + 1); + if (result) + { + Ucs2toUtf8(tempBuf, len, result, destlen); + result[destlen] = 0; + } + } + + if (needs_free) + mir_free(tempBuf); + + return result; +} + +MIR_CORE_DLL(char*) Utf8Encode(const char* src) +{ + return Utf8EncodeCP(src, LangPackGetDefaultCodePage()); +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Utf8Encode - converts UCS2 string to the UTF8-encoded format + +MIR_CORE_DLL(char*) Utf8EncodeW(const wchar_t* src) +{ + if (src == NULL) + return NULL; + + int len = (int)wcslen(src); + + int destlen = Ucs2toUtf8Len(src, len); + if (destlen < 0) return NULL; + + char* result = (char*)mir_alloc(destlen + 1); + if (result == NULL) + return NULL; + + Ucs2toUtf8(src, len, result, destlen); + result[destlen] = 0; + + return result; +} diff --git a/plugins/mir_core/utils.cpp b/plugins/mir_core/utils.cpp new file mode 100644 index 0000000000..f0fcdcfa07 --- /dev/null +++ b/plugins/mir_core/utils.cpp @@ -0,0 +1,150 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +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; either version 2 +of the License, or (at your option) any later version. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" + +MIR_CORE_DLL(char*) rtrim(char* str) +{ + if (str == NULL) + return NULL; + + char* p = strchr(str, 0); + while (--p >= str) { + switch (*p) { + case ' ': case '\t': case '\n': case '\r': + *p = 0; break; + default: + return str; + } + } + return str; +} + +MIR_CORE_DLL(WCHAR*) wrtrim(WCHAR *str) +{ + if (str == NULL) + return NULL; + + WCHAR* p = _tcschr(str, 0); + while (--p >= str) { + switch (*p) { + case ' ': case '\t': case '\n': case '\r': + *p = 0; break; + default: + return str; + } + } + return str; +} + +MIR_CORE_DLL(char*) ltrim(char* str) +{ + if (str == NULL) + return NULL; + + char* p = str; + for (;;) { + switch (*p) { + case ' ': case '\t': case '\n': case '\r': + ++p; break; + default: + memmove(str, p, strlen(p) + 1); + return str; + } + } +} + +MIR_CORE_DLL(char*) ltrimp(char* str) +{ + if (str == NULL) + return NULL; + + char* p = str; + for (;;) { + switch (*p) { + case ' ': case '\t': case '\n': case '\r': + ++p; break; + default: + return p; + } + } +} + +MIR_CORE_DLL(int) wildcmp(char * name, char * mask) +{ + char * last='\0'; + for (;; mask++, name++) { + if (*mask != '?' && *mask != *name) break; + if (*name == '\0') return ((BOOL)!*mask); + } + if (*mask != '*') return FALSE; + for (;; mask++, name++){ + while (*mask == '*') { + last = mask++; + if (*mask == '\0') return ((BOOL)!*mask); /* true */ + } + if (*name == '\0') return ((BOOL)!*mask); /* *mask == EOS */ + if (*mask != '?' && *mask != *name) name -= (size_t)(mask - last) - 1, mask = last; + } +} + +/////////////////////////////////////////////////////////////////////////////// + +static int sttComparePlugins(const HINSTANCE__* p1, const HINSTANCE__* p2) +{ + if (p1 == p2) + return 0; + + return (p1 < p2) ? -1 : 1; +} + +static LIST pluginListAddr(10, sttComparePlugins); + +MIR_CORE_DLL(void) RegisterModule(HINSTANCE hInst) +{ + pluginListAddr.insert(hInst); +} + +MIR_CORE_DLL(void) UnregisterModule(HINSTANCE hInst) +{ + pluginListAddr.remove(hInst); +} + +MIR_CORE_DLL(HINSTANCE) GetInstByAddress(void* codePtr) +{ + if (pluginListAddr.getCount() == 0) + return NULL; + + int idx; + List_GetIndex((SortedList*)&pluginListAddr, &codePtr, &idx); + if (idx > 0) + idx--; + + HINSTANCE result = pluginListAddr[idx]; + if (result < hInst && codePtr > hInst) + result = hInst; + else if (idx == 0 && codePtr < (void*)result) + result = NULL; + + return result; +} -- cgit v1.2.3