From 6b27aa506d7b45ce503d0a546cbe9d13746c2be3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 15 Oct 2012 21:31:54 +0000 Subject: Unicode translation for Import git-svn-id: http://svn.miranda-ng.org/main/trunk@1952 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Import/src/import.cpp | 89 +++++++++++++++++++---------------------- plugins/Import/src/import.h | 2 +- plugins/Import/src/progress.cpp | 13 +++--- plugins/Import/src/utils.cpp | 63 +++++++++++------------------ 4 files changed, 71 insertions(+), 96 deletions(-) (limited to 'plugins/Import') diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index 5b6ac6f7b8..f9ac5d815b 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -99,7 +99,7 @@ static HANDLE HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DW { HANDLE hContact = HContactFromNumericID(szModuleName, "UIN", uin); if (hContact == NULL) { - AddMessage( LPGEN("Ignored event from/to self")); + AddMessage( LPGENT("Ignored event from/to self")); return INVALID_HANDLE_VALUE; } @@ -112,23 +112,18 @@ static HANDLE HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DW hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szModuleName); DBWriteContactSettingDword(hContact, szModuleName, "UIN", uin); - AddMessage( LPGEN("Added contact %u (found in history)"), uin ); + AddMessage( LPGENT("Added contact %u (found in history)"), uin ); return hContact; } ///////////////////////////////////////////////////////////////////////////////////////// -static HANDLE AddContact(HWND hdlgProgress, char* szProto, char* pszUniqueSetting, DBVARIANT* id, TCHAR *nick, TCHAR *group) +static HANDLE AddContact(HWND hdlgProgress, char* szProto, char* pszUniqueSetting, DBVARIANT* id, const TCHAR* pszUserID, TCHAR *nick, TCHAR *group) { - HANDLE hContact; - char szid[ 40 ]; - char* pszUserID = ( id->type == DBVT_DWORD ) ? _ltoa( id->dVal, szid, 10 ) : id->pszVal; - - hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); + HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_ADD, 0, 0); if ( CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)szProto) != 0) { CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); - AddMessage( LPGEN("Failed to add %s contact %s"), szProto, pszUserID ); - srcDb->FreeVariant( id ); + AddMessage( LPGENT("Failed to add %S contact %s"), szProto, pszUserID ); return INVALID_HANDLE_VALUE; } @@ -138,9 +133,9 @@ static HANDLE AddContact(HWND hdlgProgress, char* szProto, char* pszUniqueSettin if (nick && *nick) { db_set_ws(hContact, "CList", "MyHandle", nick ); - AddMessage( LPGEN("Added %s contact %s, '%S'"), szProto, pszUserID, nick); + AddMessage( LPGENT("Added %S contact %s, '%s'"), szProto, pszUserID, nick); } - else AddMessage( LPGEN("Added %s contact %s"), szProto, pszUserID); + else AddMessage( LPGENT("Added %S contact %s"), szProto, pszUserID); srcDb->FreeVariant( id ); return hContact; @@ -176,53 +171,53 @@ static int ImportGroups() static HANDLE ImportContact(HANDLE hSrc) { HANDLE hDst; - TCHAR id[ 40 ], *pszUserName; + TCHAR id[ 40 ], *pszUniqueID; char szProto[100]; // Check what protocol this contact belongs to if ( myGetS(hSrc, "Protocol", "p", szProto)) { - AddMessage( LPGEN("Skipping contact with no protocol")); + AddMessage( LPGENT("Skipping contact with no protocol")); return NULL; } if ( !IsProtocolLoaded(szProto)) { - AddMessage( LPGEN("Skipping contact, %s not installed."), szProto); + AddMessage( LPGENT("Skipping contact, %S not installed."), szProto); return NULL; } // Skip protocols with no unique id setting (some non IM protocols return NULL) char* pszUniqueSetting = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); if ( !pszUniqueSetting || (INT_PTR)pszUniqueSetting == CALLSERVICE_NOTFOUND ) { - AddMessage( LPGEN("Skipping non-IM contact (%s)"), szProto ); + AddMessage( LPGENT("Skipping non-IM contact (%S)"), szProto ); return NULL; } DBVARIANT dbv; if ( myGet(hSrc, szProto, pszUniqueSetting, &dbv)) { - AddMessage( LPGEN("Skipping %s contact, ID not found"), szProto); + AddMessage( LPGENT("Skipping %S contact, ID not found"), szProto); return NULL; } // Does the contact already exist? switch (dbv.type) { case DBVT_DWORD: - pszUserName = _ltot(dbv.dVal, id, 10); + pszUniqueID = _ltot(dbv.dVal, id, 10); hDst = HContactFromNumericID( szProto, pszUniqueSetting, dbv.dVal ); break; case DBVT_ASCIIZ: - pszUserName = NEWTSTR_ALLOCA( _A2T(dbv.pszVal)); - hDst = HContactFromID(szProto, pszUniqueSetting, pszUserName); + pszUniqueID = NEWTSTR_ALLOCA( _A2T(dbv.pszVal)); + hDst = HContactFromID(szProto, pszUniqueSetting, pszUniqueID); break; case DBVT_WCHAR: - pszUserName = NEWTSTR_ALLOCA(dbv.ptszVal); - hDst = HContactFromID(szProto, pszUniqueSetting, pszUserName); + pszUniqueID = NEWTSTR_ALLOCA(dbv.ptszVal); + hDst = HContactFromID(szProto, pszUniqueSetting, pszUniqueID); break; } if (hDst != INVALID_HANDLE_VALUE) { - AddMessage( LPGEN("Skipping duplicate %s contact %S"), szProto, pszUserName ); + AddMessage( LPGENT("Skipping duplicate %S contact %s"), szProto, pszUniqueID ); srcDb->FreeVariant( &dbv ); return NULL; } @@ -231,7 +226,7 @@ static HANDLE ImportContact(HANDLE hSrc) if (tszNick == NULL) tszNick = myGetWs(hSrc, szProto, "Nick"); - hDst = AddContact(hdlgProgress, szProto, pszUniqueSetting, &dbv, tszNick, tszGroup); + hDst = AddContact(hdlgProgress, szProto, pszUniqueSetting, &dbv, pszUniqueID, tszNick, tszGroup); mir_free(tszGroup), mir_free(tszNick); if ( hDst != INVALID_HANDLE_VALUE) { @@ -283,7 +278,7 @@ static HANDLE ImportContact(HANDLE hSrc) srcDb->FreeVariant(&dbv); } } - else AddMessage( LPGEN("Unknown error while adding %s contact %S"), szProto, pszUserName ); + else AddMessage( LPGENT("Unknown error while adding %S contact %s"), szProto, pszUniqueID ); return hDst; } @@ -420,7 +415,7 @@ static void ImportHistory(HANDLE hContact, PROTOACCOUNT **protocol, int protoCou if (dstDb->AddEvent(hDst, &dbei) != NULL) nMessagesCount++; else - AddMessage( LPGEN("Failed to add message")); + AddMessage( LPGENT("Failed to add message")); } else nDupes++; @@ -455,18 +450,18 @@ void MirandaImport(HWND hdlg) // Just to keep the macros happy hdlgProgress = hdlg; if ((dstDb = GetCurrentDatabase()) == NULL) { - AddMessage( LPGEN("Error retrieving current profile, exiting.")); + AddMessage( LPGENT("Error retrieving current profile, exiting.")); return; } DATABASELINK* dblink = FindDatabasePlugin(importFile); if (dblink == NULL) { - AddMessage( LPGEN("There's no database driver to open the input file, exiting.")); + AddMessage( LPGENT("There's no database driver to open the input file, exiting.")); return; } if ((srcDb = dblink->Load(importFile)) == NULL) { - AddMessage( LPGEN("Error loading source file, exiting.")); + AddMessage( LPGENT("Error loading source file, exiting.")); return; } @@ -481,8 +476,8 @@ void MirandaImport(HWND hdlg) // Get number of contacts int nNumberOfContacts = srcDb->GetContactCount(); - AddMessage( LPGEN("Number of contacts in database: %d"), nNumberOfContacts ); - AddMessage( "" ); + AddMessage( LPGENT("Number of contacts in database: %d"), nNumberOfContacts ); + AddMessage( _T("")); // Configure database for fast writing dstDb->SetCacheSafetyMode(FALSE); @@ -492,18 +487,18 @@ void MirandaImport(HWND hdlg) // Import Groups if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_GROUPS)) { - AddMessage( LPGEN("Importing groups.")); + AddMessage( LPGENT("Importing groups.")); nGroupsCount = ImportGroups(); if (nGroupsCount == -1) - AddMessage( LPGEN("Group import failed.")); + AddMessage( LPGENT("Group import failed.")); - AddMessage( "" ); + AddMessage( _T("")); } // End of Import Groups // Import Contacts if (nImportOption != IMPORT_CUSTOM || (nCustomOptions & IOPT_CONTACTS)) { - AddMessage( LPGEN("Importing contacts.")); + AddMessage( LPGENT("Importing contacts.")); int i = 1; HANDLE hContact = srcDb->FindFirstContact(); while (hContact != NULL) { @@ -524,15 +519,15 @@ void MirandaImport(HWND hdlg) hContact = srcDb->FindNextContact(hContact); } } - else AddMessage( LPGEN("Skipping new contacts import.")); - AddMessage( "" ); + else AddMessage( LPGENT("Skipping new contacts import.")); + AddMessage( _T("")); // End of Import Contacts // Import history if (nImportOption != IMPORT_CONTACTS) { // Import NULL contact message chain if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_SYSTEM)) { - AddMessage( LPGEN("Importing system history.")); + AddMessage( LPGENT("Importing system history.")); int protoCount; PROTOACCOUNT **accs; @@ -541,13 +536,13 @@ void MirandaImport(HWND hdlg) if (protoCount > 0) ImportHistory(NULL, accs, protoCount); } - else AddMessage( LPGEN("Skipping system history import.")); + else AddMessage( LPGENT("Skipping system history import.")); - AddMessage( "" ); + AddMessage( _T("")); // Import other contact messages if (nImportOption == IMPORT_ALL || (nCustomOptions & 2046)) { // 2 - 1024 types - AddMessage( LPGEN("Importing history.")); + AddMessage( LPGENT("Importing history.")); HANDLE hContact = srcDb->FindFirstContact(); for(int i=1; hContact != NULL; i++) { ImportHistory(hContact, NULL, NULL); @@ -556,9 +551,9 @@ void MirandaImport(HWND hdlg) hContact = srcDb->FindNextContact(hContact); } } - else AddMessage( LPGEN("Skipping history import.")); + else AddMessage( LPGENT("Skipping history import.")); - AddMessage( "" ); + AddMessage( _T("")); } // End of Import History @@ -572,18 +567,18 @@ void MirandaImport(HWND hdlg) dwTimer = time(NULL) - dwTimer; // Print statistics - AddMessage( LPGEN("Import completed in %d seconds."), dwTimer ); + AddMessage( LPGENT("Import completed in %d seconds."), dwTimer ); SetProgress(100); AddMessage((nImportOption == IMPORT_CONTACTS) ? - LPGEN("Added %d contacts and %d groups.") : LPGEN("Added %d contacts, %d groups and %d events."), + LPGENT("Added %d contacts and %d groups.") : LPGENT("Added %d contacts, %d groups and %d events."), nContactsCount, nGroupsCount, nMessagesCount); if ( nImportOption != IMPORT_CONTACTS ) { if (nSkippedContacts) - AddMessage( LPGEN("Skipped %d contacts."), nSkippedContacts ); + AddMessage( LPGENT("Skipped %d contacts."), nSkippedContacts ); AddMessage((nImportOption == IMPORT_CUSTOM) ? - LPGEN("Skipped %d duplicates and %d filtered events.") : LPGEN("Skipped %d duplicates."), + LPGENT("Skipped %d duplicates and %d filtered events.") : LPGENT("Skipped %d duplicates."), nDupes, nSkippedEvents); } } diff --git a/plugins/Import/src/import.h b/plugins/Import/src/import.h index 738fc76bfa..5dbfd82cc7 100644 --- a/plugins/Import/src/import.h +++ b/plugins/Import/src/import.h @@ -101,7 +101,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define IOPT_CONTACTS 4096 #define IOPT_GROUPS 8192 -void AddMessage( const char* fmt, ... ); +void AddMessage( const TCHAR* fmt, ... ); void mySet( HANDLE hContact, const char* module, const char* var, DBVARIANT* dbv ); diff --git a/plugins/Import/src/progress.cpp b/plugins/Import/src/progress.cpp index 2328ce1222..8856fa837e 100644 --- a/plugins/Import/src/progress.cpp +++ b/plugins/Import/src/progress.cpp @@ -76,25 +76,22 @@ INT_PTR CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lP return FALSE; } -void AddMessage( const char* fmt, ... ) +void AddMessage( const TCHAR* fmt, ... ) { va_list args; - char msgBuf[ 4096 ]; + TCHAR msgBuf[ 4096 ]; va_start( args, fmt ); - mir_vsnprintf( msgBuf, sizeof(msgBuf), Translate(fmt), args ); + mir_vsntprintf( msgBuf, SIZEOF(msgBuf), TranslateTS(fmt), args ); #ifdef _LOGGING { FILE *stream; stream = fopen("Import Debug.log", "a"); - fprintf(stream, "%s\n", msgBuf); + fprintf(stream, "%S\n", msgBuf); fclose(stream); } #endif - { TCHAR* str = mir_a2t( msgBuf ); - SendMessage( hdlgProgress, PROGM_ADDMESSAGE, 0, ( LPARAM )str ); - mir_free( str ); - } + SendMessage(hdlgProgress, PROGM_ADDMESSAGE, 0, (LPARAM)msgBuf); } diff --git a/plugins/Import/src/utils.cpp b/plugins/Import/src/utils.cpp index 9d51d0f47c..b06cf06881 100644 --- a/plugins/Import/src/utils.cpp +++ b/plugins/Import/src/utils.cpp @@ -57,12 +57,9 @@ int CreateGroup(const TCHAR* group, HANDLE hContact) if ( !lstrcmp(dbv.ptszVal + 1, tszGrpName + 1 )) { if (hContact) - DBWriteContactSettingTString( hContact, "CList", "Group", tszGrpName+1 ); - else { - char *str = mir_t2a(tszGrpName + 1); - AddMessage( LPGEN("Skipping duplicate group %s."), str); - mir_free(str); - } + DBWriteContactSettingTString( hContact, "CList", "Group", tszGrpName+1 ); + else + AddMessage( LPGENT("Skipping duplicate group %s."), tszGrpName + 1); DBFreeVariant(&dbv); return 0; @@ -100,22 +97,20 @@ BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) dwEventTimeStamp = dbeiExisting.timestamp; // compare with last timestamp - if (dbei.timestamp > dwEventTimeStamp) - { + if (dbei.timestamp > dwEventTimeStamp) { // remember event hPreviousDbEvent = hExistingDbEvent; dwPreviousTimeStamp = dwEventTimeStamp; return FALSE; } - if (hContact != hPreviousContact) - { + if (hContact != hPreviousContact) { hPreviousContact = hContact; // remember event hPreviousDbEvent = hExistingDbEvent; dwPreviousTimeStamp = dwEventTimeStamp; - // get first event + // get first event if (!(hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDFIRST, (WPARAM)hContact, 0))) return FALSE; @@ -125,20 +120,18 @@ BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) dwEventTimeStamp = dbeiExisting.timestamp; // compare with first timestamp - if (dbei.timestamp <= dwEventTimeStamp) - { - // remember event + if (dbei.timestamp <= dwEventTimeStamp) { + // remember event dwPreviousTimeStamp = dwEventTimeStamp; hPreviousDbEvent = hExistingDbEvent; if ( dbei.timestamp != dwEventTimeStamp ) return FALSE; } - } + // check for equal timestamps - if (dbei.timestamp == dwPreviousTimeStamp) - { + if (dbei.timestamp == dwPreviousTimeStamp) { ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); dbeiExisting.cbSize = sizeof(dbeiExisting); CallService(MS_DB_EVENT_GET, (WPARAM)hPreviousDbEvent, (LPARAM)&dbeiExisting); @@ -147,18 +140,16 @@ BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) (dbei.eventType == dbeiExisting.eventType) && (dbei.cbBlob == dbeiExisting.cbBlob) && ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) - return TRUE; + return TRUE; // find event with another timestamp hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hPreviousDbEvent, 0); - while (hExistingDbEvent != NULL) - { + while (hExistingDbEvent != NULL) { ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); dbeiExisting.cbSize = sizeof(dbeiExisting); CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); - if (dbeiExisting.timestamp != dwPreviousTimeStamp) - { + if (dbeiExisting.timestamp != dwPreviousTimeStamp) { // use found event hPreviousDbEvent = hExistingDbEvent; dwPreviousTimeStamp = dbeiExisting.timestamp; @@ -172,18 +163,15 @@ BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) hExistingDbEvent = hPreviousDbEvent; - if (dbei.timestamp <= dwPreviousTimeStamp) - { + if (dbei.timestamp <= dwPreviousTimeStamp) { // look back - while (hExistingDbEvent != NULL) - { + while (hExistingDbEvent != NULL) { ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); dbeiExisting.cbSize = sizeof(dbeiExisting); CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); - if (dbei.timestamp > dbeiExisting.timestamp) - { - // remember event + if (dbei.timestamp > dbeiExisting.timestamp) { + // remember event hPreviousDbEvent = hExistingDbEvent; dwPreviousTimeStamp = dbeiExisting.timestamp; return FALSE; @@ -193,7 +181,7 @@ BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) if ((dbei.timestamp == dbeiExisting.timestamp) && (dbei.eventType == dbeiExisting.eventType) && (dbei.cbBlob == dbeiExisting.cbBlob) && - ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) + ((dbei.flags & DBEF_SENT) == (dbeiExisting.flags & DBEF_SENT))) { // remember event hPreviousDbEvent = hExistingDbEvent; @@ -204,20 +192,16 @@ BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) // Get previous event in chain hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDPREV, (WPARAM)hExistingDbEvent, 0); } - - } - else - { + } + else { // look forward - while (hExistingDbEvent != NULL) - { + while (hExistingDbEvent != NULL) { ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); dbeiExisting.cbSize = sizeof(dbeiExisting); CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); - if (dbei.timestamp < dbeiExisting.timestamp) - { - // remember event + if (dbei.timestamp < dbeiExisting.timestamp) { + // remember event hPreviousDbEvent = hExistingDbEvent; dwPreviousTimeStamp = dbeiExisting.timestamp; return FALSE; @@ -238,7 +222,6 @@ BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) // Get next event in chain hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hExistingDbEvent, 0); } - } // reset last event hPreviousContact = INVALID_HANDLE_VALUE; -- cgit v1.2.3