CString Utf8DecodeUni(CStringA str) { #ifdef _UNICODE LPTSTR msg; Utf8DecodeCP(str.GetBuffer(), CP_ACP, &msg); return msg; #else return Utf8DecodeCP(str.GetBuffer(), CP_ACP, NULL); #endif }
CString PjToStr(const pj_str_t* str, BOOL utf) { CStringA rab; rab.Format("%.*s", str->slen, str->ptr); if (utf) { #ifdef _UNICODE WCHAR* msg; Utf8DecodeCP(rab.GetBuffer(), CP_ACP, &msg); return msg; #else return Utf8DecodeCP(rab.GetBuffer(), CP_ACP, NULL); #endif } else { return CString(rab); } }
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); } 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]=='[') break; 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); entriesAlloced=0; while(!feof(fp)) { if(fgets(line,SIZEOF(line),fp)==NULL) break; if(IsEmpty(line) || line[0]==';' || line[0]==0) continue; rtrim(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) mir_free(langPack.entry[langPack.entryCount-1].english); langPack.entryCount--; } pszLine = line+1; line[lstrlenA(line)-1]='\0'; if(++langPack.entryCount>entriesAlloced) { entriesAlloced+=128; langPack.entry=(struct LangPackEntry*)mir_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=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); } } } } fclose(fp); qsort(langPack.entry,langPack.entryCount,sizeof(LangPackEntry),(int(*)(const void*,const void*))SortLangPackHashesProc); return 0; }
static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam) { DBEVENTGETTEXT* egt = (DBEVENTGETTEXT*)lParam; if (egt == NULL) return 0; DBEVENTINFO *dbei = egt->dbei; DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)DbEventTypeGet((WPARAM)dbei->szModule, (LPARAM)dbei->eventType); if (et && ServiceExists(et->textService)) return CallService(et->textService, wParam, lParam); if (!dbei->pBlob) return 0; if (dbei->eventType == EVENTTYPE_AUTHREQUEST || dbei->eventType == EVENTTYPE_ADDED) { // EVENTTYPE_AUTHREQUEST: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) // EVENTTYPE_ADDED: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) DWORD uin = *(DWORD*)dbei->pBlob; HANDLE hContact = (HANDLE)*(DWORD*)(dbei->pBlob + sizeof(DWORD)); char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD)*2; ptrT tszNick(getEventString(dbei, buf)); ptrT tszFirst(getEventString(dbei, buf)); ptrT tszLast(getEventString(dbei, buf)); ptrT tszEmail(getEventString(dbei, buf)); CMString nick, text; if (tszFirst || tszLast) { nick.AppendFormat(_T("%s %s"), tszFirst, tszLast); nick.Trim(); } if (tszEmail) { if (!nick.IsEmpty()) nick.Append(_T(", ")); nick.Append(tszEmail); } if (uin != 0) { if (!nick.IsEmpty()) nick.Append(_T(", ")); nick.AppendFormat(_T("%d"), uin); } if (!nick.IsEmpty()) nick = _T("(") + nick + _T(")"); if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { ptrT tszReason(getEventString(dbei, buf)); text.Format(TranslateT("Authorization request from %s%s: %s"), (*tszNick == 0) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick, tszReason); } else text.Format(TranslateT("You were added by %s%s"), (*tszNick == 0) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick); return (egt->datatype == DBVT_WCHAR) ? (INT_PTR)mir_tstrdup(text) : (INT_PTR)mir_t2a(text); } if (dbei->eventType == EVENTTYPE_CONTACTS) { CMString text(TranslateT("Contacts: ")); // blob is: [uin(ASCIIZ), nick(ASCIIZ)]* char *buf = LPSTR(dbei->pBlob), *limit = LPSTR(dbei->pBlob) + dbei->cbBlob; while (buf < limit) { ptrT tszUin(getEventString(dbei, buf)); ptrT tszNick(getEventString(dbei, buf)); if (tszNick && *tszNick) text.AppendFormat(_T("\"%s\" "), tszNick); if (tszUin && *tszUin) text.AppendFormat(_T("<%s>; "), tszUin); } return (egt->datatype == DBVT_WCHAR) ? (INT_PTR)mir_tstrdup(text) : (INT_PTR)mir_t2a(text); } if (dbei->eventType == EVENTTYPE_FILE) { char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD); ptrT tszFileName(getEventString(dbei, buf)); ptrT tszDescription(getEventString(dbei, buf)); ptrT &ptszText = (lstrlen(tszDescription) == 0) ? tszFileName : tszDescription; switch (egt->datatype) { case DBVT_WCHAR: return (INT_PTR)ptszText.detouch(); case DBVT_ASCIIZ: return (INT_PTR)mir_t2a(ptszText); } return 0; } // by default treat an event's blob as a string if (egt->datatype == DBVT_WCHAR) { char *str = (char*)alloca(dbei->cbBlob + 1); memcpy(str, dbei->pBlob, dbei->cbBlob); str[dbei->cbBlob] = 0; if (dbei->flags & DBEF_UTF) { WCHAR *msg = NULL; Utf8DecodeCP(str, egt->codepage, &msg); if (msg) return (INT_PTR)msg; } return (INT_PTR)mir_a2t_cp(str, egt->codepage); } if (egt->datatype == DBVT_ASCIIZ) { char *msg = mir_strdup((char*)dbei->pBlob); if (dbei->flags & DBEF_UTF) Utf8DecodeCP(msg, egt->codepage, NULL); return (INT_PTR)msg; } return 0; }
static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam) { DBEVENTGETTEXT* egt = (DBEVENTGETTEXT*)lParam; BOOL bIsDenyUnicode = (egt->datatype & DBVTF_DENYUNICODE); DBEVENTINFO* dbei = egt->dbei; DBEVENTTYPEDESCR* et = ( DBEVENTTYPEDESCR* )DbEventTypeGet( ( WPARAM )dbei->szModule, ( LPARAM )dbei->eventType ); if ( et && ServiceExists( et->textService )) return CallService( et->textService, wParam, lParam ); if ( !dbei->pBlob ) return 0; if ( dbei->eventType == EVENTTYPE_FILE ) { char* filename = ((char *)dbei->pBlob) + sizeof(DWORD); char* descr = filename + lstrlenA( filename ) + 1; char* str = (*descr == 0) ? filename : descr; switch ( egt->datatype ) { case DBVT_WCHAR: return ( INT_PTR )(( dbei->flags & DBEF_UTF ) ? Utf8DecodeT( str ) : mir_a2t( str )); case DBVT_ASCIIZ: return ( INT_PTR )(( dbei->flags & DBEF_UTF ) ? Utf8Decode( mir_strdup( str ), NULL ) : mir_strdup( str )); } return 0; } // temporary fix for bug with event types conflict between jabber chat states notifications // and srmm's status changes, must be commented out in future releases if ( dbei->eventType == 25368 && dbei->cbBlob == 1 && dbei->pBlob[0] == 1 ) return 0; egt->datatype &= ~DBVTF_DENYUNICODE; if ( egt->datatype == DBVT_WCHAR ) { WCHAR* msg = NULL; if ( dbei->flags & DBEF_UTF ) { char* str = (char*)alloca(dbei->cbBlob + 1); if (str == NULL) return NULL; memcpy(str, dbei->pBlob, dbei->cbBlob); str[dbei->cbBlob] = 0; Utf8DecodeCP( str, egt->codepage, &msg ); } else { size_t msglen = strlen(( char* )dbei->pBlob) + 1, msglenW = 0; if ( msglen != dbei->cbBlob ) { size_t i, count = (( dbei->cbBlob - msglen ) / sizeof( WCHAR )); WCHAR* p = ( WCHAR* )&dbei->pBlob[ msglen ]; for ( i=0; i < count; i++ ) { if ( p[i] == 0 ) { msglenW = i; break; } } } if ( msglenW > 0 && msglenW < msglen && !bIsDenyUnicode ) msg = mir_wstrdup(( WCHAR* )&dbei->pBlob[ msglen ] ); else { msg = ( WCHAR* )mir_alloc( sizeof(WCHAR) * msglen ); MultiByteToWideChar( egt->codepage, 0, (char *) dbei->pBlob, -1, msg, (int)msglen ); } } return ( INT_PTR )msg; } else if ( egt->datatype == DBVT_ASCIIZ ) { char* msg = mir_strdup(( char* )dbei->pBlob ); if (dbei->flags & DBEF_UTF) Utf8DecodeCP( msg, egt->codepage, NULL ); return ( INT_PTR )msg; } return 0; }