From d828acae837c71992f6a5f9dd688ba7afd944e56 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Mon, 23 Jul 2012 07:10:03 +0000 Subject: Dbx_mmap_SA, Import_SA, Dbtool_SA: changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1108 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dbx_mmap_SA/Cryptors/RC4/cryptor.c | 133 -- plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj | 10 +- .../Cryptors/RC4/rc4_10.vcxproj.filters | 10 +- plugins/Dbx_mmap_SA/Cryptors/RC4/src/cryptor.c | 133 ++ plugins/Dbx_mmap_SA/Dbtool/Version.h | 9 - plugins/Dbx_mmap_SA/Dbtool/Version.rc | 42 - plugins/Dbx_mmap_SA/Dbtool/aggressive.cpp | 59 - plugins/Dbx_mmap_SA/Dbtool/cleaning.cpp | 63 - plugins/Dbx_mmap_SA/Dbtool/contactchain.cpp | 105 -- plugins/Dbx_mmap_SA/Dbtool/database.h | 179 --- plugins/Dbx_mmap_SA/Dbtool/dbtool.exe.manifest | 31 - plugins/Dbx_mmap_SA/Dbtool/dbtool.h | 104 -- plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj | 70 +- .../Dbtool/dbtool_sa_10.vcxproj.filters | 66 +- plugins/Dbx_mmap_SA/Dbtool/disk.cpp | 112 -- plugins/Dbx_mmap_SA/Dbtool/encryption.cpp | 299 ---- plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp | 363 ----- plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp | 69 - plugins/Dbx_mmap_SA/Dbtool/finaltasks.cpp | 78 - plugins/Dbx_mmap_SA/Dbtool/finished.cpp | 82 -- plugins/Dbx_mmap_SA/Dbtool/initialchecks.cpp | 98 -- plugins/Dbx_mmap_SA/Dbtool/main.cpp | 33 - plugins/Dbx_mmap_SA/Dbtool/modulechain.cpp | 146 -- plugins/Dbx_mmap_SA/Dbtool/openerror.cpp | 55 - plugins/Dbx_mmap_SA/Dbtool/progress.cpp | 213 --- plugins/Dbx_mmap_SA/Dbtool/res/Version.rc | 42 + plugins/Dbx_mmap_SA/Dbtool/res/dbtool.exe.manifest | 31 + plugins/Dbx_mmap_SA/Dbtool/res/resource.rc | 368 +++++ plugins/Dbx_mmap_SA/Dbtool/resource.h | 58 - plugins/Dbx_mmap_SA/Dbtool/resource.rc | 368 ----- plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp | 303 ---- plugins/Dbx_mmap_SA/Dbtool/settingschain.cpp | 72 - plugins/Dbx_mmap_SA/Dbtool/src/Version.h | 9 + plugins/Dbx_mmap_SA/Dbtool/src/aggressive.cpp | 59 + plugins/Dbx_mmap_SA/Dbtool/src/cleaning.cpp | 63 + plugins/Dbx_mmap_SA/Dbtool/src/contactchain.cpp | 105 ++ plugins/Dbx_mmap_SA/Dbtool/src/database.h | 179 +++ plugins/Dbx_mmap_SA/Dbtool/src/dbtool.h | 106 ++ plugins/Dbx_mmap_SA/Dbtool/src/disk.cpp | 112 ++ plugins/Dbx_mmap_SA/Dbtool/src/encryption.cpp | 299 ++++ plugins/Dbx_mmap_SA/Dbtool/src/eventchain.cpp | 363 +++++ plugins/Dbx_mmap_SA/Dbtool/src/fileaccess.cpp | 69 + plugins/Dbx_mmap_SA/Dbtool/src/finaltasks.cpp | 78 + plugins/Dbx_mmap_SA/Dbtool/src/finished.cpp | 82 ++ plugins/Dbx_mmap_SA/Dbtool/src/initialchecks.cpp | 98 ++ plugins/Dbx_mmap_SA/Dbtool/src/main.cpp | 33 + plugins/Dbx_mmap_SA/Dbtool/src/modulechain.cpp | 146 ++ plugins/Dbx_mmap_SA/Dbtool/src/openerror.cpp | 55 + plugins/Dbx_mmap_SA/Dbtool/src/progress.cpp | 213 +++ plugins/Dbx_mmap_SA/Dbtool/src/resource.h | 58 + plugins/Dbx_mmap_SA/Dbtool/src/selectdb.cpp | 303 ++++ plugins/Dbx_mmap_SA/Dbtool/src/settingschain.cpp | 72 + plugins/Dbx_mmap_SA/Dbtool/src/user.cpp | 71 + plugins/Dbx_mmap_SA/Dbtool/src/utf.cpp | 69 + plugins/Dbx_mmap_SA/Dbtool/src/welcome.cpp | 61 + plugins/Dbx_mmap_SA/Dbtool/src/wizard.cpp | 137 ++ plugins/Dbx_mmap_SA/Dbtool/src/worker.cpp | 76 + plugins/Dbx_mmap_SA/Dbtool/user.cpp | 71 - plugins/Dbx_mmap_SA/Dbtool/utf.cpp | 69 - plugins/Dbx_mmap_SA/Dbtool/welcome.cpp | 61 - plugins/Dbx_mmap_SA/Dbtool/wizard.cpp | 137 -- plugins/Dbx_mmap_SA/Dbtool/worker.cpp | 76 - plugins/Dbx_mmap_SA/Import_SA/ICQserver.cpp | 73 - plugins/Dbx_mmap_SA/Import_SA/ICQserver.h | 62 - plugins/Dbx_mmap_SA/Import_SA/Version.rc | 42 - plugins/Dbx_mmap_SA/Import_SA/encryption.cpp | 310 ---- plugins/Dbx_mmap_SA/Import_SA/import.h | 112 -- plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj | 52 +- .../Import_SA/import_sa_10.vcxproj.filters | 53 +- plugins/Dbx_mmap_SA/Import_SA/main.cpp | 541 ------- plugins/Dbx_mmap_SA/Import_SA/mirabilis.cpp | 1492 -------------------- plugins/Dbx_mmap_SA/Import_SA/mirabilis.h | 200 --- plugins/Dbx_mmap_SA/Import_SA/miranda.cpp | 1491 ------------------- plugins/Dbx_mmap_SA/Import_SA/mirandadb0700.h | 148 -- plugins/Dbx_mmap_SA/Import_SA/mirandahistory.cpp | 208 --- plugins/Dbx_mmap_SA/Import_SA/progress.cpp | 100 -- plugins/Dbx_mmap_SA/Import_SA/res/Version.rc | 42 + plugins/Dbx_mmap_SA/Import_SA/res/resource.rc | 322 +++++ plugins/Dbx_mmap_SA/Import_SA/resource.h | 68 - plugins/Dbx_mmap_SA/Import_SA/resource.rc | 322 ----- plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.cpp | 73 + plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.h | 62 + plugins/Dbx_mmap_SA/Import_SA/src/encryption.cpp | 310 ++++ plugins/Dbx_mmap_SA/Import_SA/src/import.h | 115 ++ plugins/Dbx_mmap_SA/Import_SA/src/main.cpp | 541 +++++++ plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.cpp | 1492 ++++++++++++++++++++ plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.h | 200 +++ plugins/Dbx_mmap_SA/Import_SA/src/miranda.cpp | 1491 +++++++++++++++++++ plugins/Dbx_mmap_SA/Import_SA/src/mirandadb0700.h | 148 ++ .../Dbx_mmap_SA/Import_SA/src/mirandahistory.cpp | 208 +++ plugins/Dbx_mmap_SA/Import_SA/src/progress.cpp | 100 ++ plugins/Dbx_mmap_SA/Import_SA/src/resource.h | 68 + plugins/Dbx_mmap_SA/Import_SA/src/version.h | 14 + plugins/Dbx_mmap_SA/Import_SA/src/wizard.cpp | 215 +++ plugins/Dbx_mmap_SA/Import_SA/version.h | 14 - plugins/Dbx_mmap_SA/Import_SA/wizard.cpp | 215 --- plugins/Dbx_mmap_SA/commonheaders.h | 117 -- plugins/Dbx_mmap_SA/db3x_mmap.rc | 275 ---- plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj | 50 +- .../Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters | 50 +- plugins/Dbx_mmap_SA/dbintf_sa.cpp | 234 --- plugins/Dbx_mmap_SA/dbintf_sa.h | 71 - plugins/Dbx_mmap_SA/dbpreset.cpp | 296 ---- plugins/Dbx_mmap_SA/dbx_mmap_sa-translation.txt | 383 ----- plugins/Dbx_mmap_SA/dialogs.cpp | 543 ------- .../Dbx_mmap_SA/docs/dbx_mmap_sa-translation.txt | 383 +++++ plugins/Dbx_mmap_SA/icos/backup.ico | Bin 2550 -> 0 bytes plugins/Dbx_mmap_SA/icos/logo.ico | Bin 8550 -> 0 bytes plugins/Dbx_mmap_SA/icos/pass.ico | Bin 2550 -> 0 bytes plugins/Dbx_mmap_SA/icos/restart.ico | Bin 2550 -> 0 bytes plugins/Dbx_mmap_SA/init.cpp | 168 --- plugins/Dbx_mmap_SA/options.h | 38 - plugins/Dbx_mmap_SA/res/db3x_mmap.rc | 275 ++++ plugins/Dbx_mmap_SA/res/logo.ico | Bin 0 -> 8550 bytes plugins/Dbx_mmap_SA/res/pass.ico | Bin 0 -> 2550 bytes plugins/Dbx_mmap_SA/res/version.rc | 42 + plugins/Dbx_mmap_SA/resource.h | 54 - plugins/Dbx_mmap_SA/security.cpp | 392 ----- plugins/Dbx_mmap_SA/src/commonheaders.h | 119 ++ plugins/Dbx_mmap_SA/src/dbintf_sa.cpp | 234 +++ plugins/Dbx_mmap_SA/src/dbintf_sa.h | 71 + plugins/Dbx_mmap_SA/src/dbpreset.cpp | 296 ++++ plugins/Dbx_mmap_SA/src/dialogs.cpp | 543 +++++++ plugins/Dbx_mmap_SA/src/init.cpp | 168 +++ plugins/Dbx_mmap_SA/src/options.h | 38 + plugins/Dbx_mmap_SA/src/resource.h | 54 + plugins/Dbx_mmap_SA/src/security.cpp | 392 +++++ plugins/Dbx_mmap_SA/src/version.h | 6 + plugins/Dbx_mmap_SA/version.h | 6 - plugins/Dbx_mmap_SA/version.rc | 42 - 130 files changed, 11650 insertions(+), 11728 deletions(-) delete mode 100644 plugins/Dbx_mmap_SA/Cryptors/RC4/cryptor.c create mode 100644 plugins/Dbx_mmap_SA/Cryptors/RC4/src/cryptor.c delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/Version.h delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/Version.rc delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/aggressive.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/cleaning.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/contactchain.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/database.h delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/dbtool.exe.manifest delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/dbtool.h delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/disk.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/encryption.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/finaltasks.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/finished.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/initialchecks.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/main.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/modulechain.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/openerror.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/progress.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/res/Version.rc create mode 100644 plugins/Dbx_mmap_SA/Dbtool/res/dbtool.exe.manifest create mode 100644 plugins/Dbx_mmap_SA/Dbtool/res/resource.rc delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/resource.h delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/resource.rc delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/settingschain.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/Version.h create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/aggressive.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/cleaning.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/contactchain.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/database.h create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/dbtool.h create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/disk.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/encryption.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/eventchain.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/fileaccess.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/finaltasks.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/finished.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/initialchecks.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/main.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/modulechain.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/openerror.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/progress.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/resource.h create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/selectdb.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/settingschain.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/user.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/utf.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/welcome.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/wizard.cpp create mode 100644 plugins/Dbx_mmap_SA/Dbtool/src/worker.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/user.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/utf.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/welcome.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/wizard.cpp delete mode 100644 plugins/Dbx_mmap_SA/Dbtool/worker.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/ICQserver.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/ICQserver.h delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/Version.rc delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/encryption.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/import.h delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/main.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/mirabilis.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/mirabilis.h delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/miranda.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/mirandadb0700.h delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/mirandahistory.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/progress.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/res/Version.rc create mode 100644 plugins/Dbx_mmap_SA/Import_SA/res/resource.rc delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/resource.h delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/resource.rc create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.h create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/encryption.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/import.h create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/main.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.h create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/miranda.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/mirandadb0700.h create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/mirandahistory.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/progress.cpp create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/resource.h create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/version.h create mode 100644 plugins/Dbx_mmap_SA/Import_SA/src/wizard.cpp delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/version.h delete mode 100644 plugins/Dbx_mmap_SA/Import_SA/wizard.cpp delete mode 100644 plugins/Dbx_mmap_SA/commonheaders.h delete mode 100644 plugins/Dbx_mmap_SA/db3x_mmap.rc delete mode 100644 plugins/Dbx_mmap_SA/dbintf_sa.cpp delete mode 100644 plugins/Dbx_mmap_SA/dbintf_sa.h delete mode 100644 plugins/Dbx_mmap_SA/dbpreset.cpp delete mode 100644 plugins/Dbx_mmap_SA/dbx_mmap_sa-translation.txt delete mode 100644 plugins/Dbx_mmap_SA/dialogs.cpp create mode 100644 plugins/Dbx_mmap_SA/docs/dbx_mmap_sa-translation.txt delete mode 100644 plugins/Dbx_mmap_SA/icos/backup.ico delete mode 100644 plugins/Dbx_mmap_SA/icos/logo.ico delete mode 100644 plugins/Dbx_mmap_SA/icos/pass.ico delete mode 100644 plugins/Dbx_mmap_SA/icos/restart.ico delete mode 100644 plugins/Dbx_mmap_SA/init.cpp delete mode 100644 plugins/Dbx_mmap_SA/options.h create mode 100644 plugins/Dbx_mmap_SA/res/db3x_mmap.rc create mode 100644 plugins/Dbx_mmap_SA/res/logo.ico create mode 100644 plugins/Dbx_mmap_SA/res/pass.ico create mode 100644 plugins/Dbx_mmap_SA/res/version.rc delete mode 100644 plugins/Dbx_mmap_SA/resource.h delete mode 100644 plugins/Dbx_mmap_SA/security.cpp create mode 100644 plugins/Dbx_mmap_SA/src/commonheaders.h create mode 100644 plugins/Dbx_mmap_SA/src/dbintf_sa.cpp create mode 100644 plugins/Dbx_mmap_SA/src/dbintf_sa.h create mode 100644 plugins/Dbx_mmap_SA/src/dbpreset.cpp create mode 100644 plugins/Dbx_mmap_SA/src/dialogs.cpp create mode 100644 plugins/Dbx_mmap_SA/src/init.cpp create mode 100644 plugins/Dbx_mmap_SA/src/options.h create mode 100644 plugins/Dbx_mmap_SA/src/resource.h create mode 100644 plugins/Dbx_mmap_SA/src/security.cpp create mode 100644 plugins/Dbx_mmap_SA/src/version.h delete mode 100644 plugins/Dbx_mmap_SA/version.h delete mode 100644 plugins/Dbx_mmap_SA/version.rc diff --git a/plugins/Dbx_mmap_SA/Cryptors/RC4/cryptor.c b/plugins/Dbx_mmap_SA/Cryptors/RC4/cryptor.c deleted file mode 100644 index 1f5f61705f..0000000000 --- a/plugins/Dbx_mmap_SA/Cryptors/RC4/cryptor.c +++ /dev/null @@ -1,133 +0,0 @@ -#include - -#define buf_size 1024 - -typedef struct{ - void* (__stdcall *GenerateKey)(char* key); - void (__stdcall *FreeKey)(void* key); - void (__stdcall *EncryptMem)(BYTE* data, int size, void* key); - void (__stdcall *DecryptMem)(BYTE* data, int size, void* key); - - char* Name; - char* Info; - char* Author; - char* Site; - char* Email; - - DWORD Version; - - WORD uid; -} Cryptor; - -typedef struct rc4_key -{ - BYTE state[256]; - BYTE x; - BYTE y; -} rc4_key; - -#define swap_byte(x,y) t = *(x); *(x) = *(y); *(y) = t - -void prepare_key(BYTE *key_data_ptr, size_t key_data_len, rc4_key *key) -{ - int i = 0; - BYTE t = 0; - BYTE index1 = 0; - BYTE index2 = 0; - BYTE* state = 0; - unsigned long counter = 0; - - state = &key->state[0]; - for(counter = 0; counter < 256; counter++) - state[counter] = (BYTE)counter; - key->x = 0; - key->y = 0; - index1 = 0; - index2 = 0; - for(counter = 0; counter < 256; counter++) - { - index2 = (key_data_ptr[index1] + state[counter] + index2) % 256; - swap_byte(&state[counter], &state[index2]); - index1 = (index1 + 1) % key_data_len; - } -} - -void rc4(BYTE *buffer_ptr, int buffer_len, rc4_key *key) -{ - BYTE t = 0; - BYTE x = 0; - BYTE y = 0; - BYTE* state = 0; - BYTE xorIndex = 0; - DWORD counter = 0; - BYTE old_state[256]; - - x = key->x; - y = key->y; - state = &key->state[0]; - memcpy(old_state, key->state, 256); - for(counter = 0; counter < (DWORD)buffer_len; counter++) - { - x = (x + 1) % 256; - y = (state[x] + y) % 256; - swap_byte(&state[x], &state[y]); - xorIndex = (state[x] + state[y]) % 256; - buffer_ptr[counter] ^= state[xorIndex]; - } - memcpy(key->state, old_state, 256); - //key->x = x; - //key->y = y; -} - - -void zero_fill(BYTE * pBuf, size_t bufSize) -{ - size_t i; - for(i = 0; i < bufSize; i++) - pBuf[i] = 0; -} - -void* __stdcall GenerateKey(char* pwd) -{ - rc4_key* key; - key = (rc4_key*)malloc(sizeof(rc4_key)); - zero_fill((BYTE*)key, sizeof(key)); - prepare_key(pwd, strlen(pwd), key); - return key; -} - -void __stdcall FreeKey(void* key) -{ - free(key); -} - -void __stdcall EncryptMem(BYTE* data, int size, void* key) -{ - rc4(data, size, key); -} - -void __stdcall DecryptMem(BYTE* data, int size, void* key) -{ - rc4(data, size, key); -} - -Cryptor cryptor = - { - GenerateKey, - FreeKey, - EncryptMem, - DecryptMem, - "RC4", - "Old, very easy to crack stream cipher", - "Unknown", - "http://ru.wikipedia.org/wiki/RC4", - "nomail", - 0x00000100, - 0xDEAD - }; - - -__declspec(dllexport) Cryptor* GetCryptor() -{ - return &cryptor; -} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj b/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj index 1112e6790e..8860121739 100644 --- a/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj +++ b/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj @@ -72,7 +72,7 @@ Full - WIN32;NDEBUG;_WINDOWS;_USRDLL;RC4_EXPORTS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true Level3 Size @@ -90,7 +90,7 @@ Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;RC4_EXPORTS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) MultiThreadedDebugDLL true Level3 @@ -107,7 +107,7 @@ Full - WIN64;NDEBUG;_WINDOWS;_USRDLL;RC4_EXPORTS;%(PreprocessorDefinitions) + WIN64;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true Level3 Size @@ -125,7 +125,7 @@ Disabled - WIN64;_DEBUG;_WINDOWS;_USRDLL;RC4_EXPORTS;%(PreprocessorDefinitions) + WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) MultiThreadedDebugDLL true Level3 @@ -139,7 +139,7 @@ - + diff --git a/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj.filters b/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj.filters index 43730c5940..bf6bc68de3 100644 --- a/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/Cryptors/RC4/rc4_10.vcxproj.filters @@ -5,17 +5,9 @@ {4FC737F1-C7A5-4376-A066-2A32D752A2FF} cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav - - + Source Files diff --git a/plugins/Dbx_mmap_SA/Cryptors/RC4/src/cryptor.c b/plugins/Dbx_mmap_SA/Cryptors/RC4/src/cryptor.c new file mode 100644 index 0000000000..1f5f61705f --- /dev/null +++ b/plugins/Dbx_mmap_SA/Cryptors/RC4/src/cryptor.c @@ -0,0 +1,133 @@ +#include + +#define buf_size 1024 + +typedef struct{ + void* (__stdcall *GenerateKey)(char* key); + void (__stdcall *FreeKey)(void* key); + void (__stdcall *EncryptMem)(BYTE* data, int size, void* key); + void (__stdcall *DecryptMem)(BYTE* data, int size, void* key); + + char* Name; + char* Info; + char* Author; + char* Site; + char* Email; + + DWORD Version; + + WORD uid; +} Cryptor; + +typedef struct rc4_key +{ + BYTE state[256]; + BYTE x; + BYTE y; +} rc4_key; + +#define swap_byte(x,y) t = *(x); *(x) = *(y); *(y) = t + +void prepare_key(BYTE *key_data_ptr, size_t key_data_len, rc4_key *key) +{ + int i = 0; + BYTE t = 0; + BYTE index1 = 0; + BYTE index2 = 0; + BYTE* state = 0; + unsigned long counter = 0; + + state = &key->state[0]; + for(counter = 0; counter < 256; counter++) + state[counter] = (BYTE)counter; + key->x = 0; + key->y = 0; + index1 = 0; + index2 = 0; + for(counter = 0; counter < 256; counter++) + { + index2 = (key_data_ptr[index1] + state[counter] + index2) % 256; + swap_byte(&state[counter], &state[index2]); + index1 = (index1 + 1) % key_data_len; + } +} + +void rc4(BYTE *buffer_ptr, int buffer_len, rc4_key *key) +{ + BYTE t = 0; + BYTE x = 0; + BYTE y = 0; + BYTE* state = 0; + BYTE xorIndex = 0; + DWORD counter = 0; + BYTE old_state[256]; + + x = key->x; + y = key->y; + state = &key->state[0]; + memcpy(old_state, key->state, 256); + for(counter = 0; counter < (DWORD)buffer_len; counter++) + { + x = (x + 1) % 256; + y = (state[x] + y) % 256; + swap_byte(&state[x], &state[y]); + xorIndex = (state[x] + state[y]) % 256; + buffer_ptr[counter] ^= state[xorIndex]; + } + memcpy(key->state, old_state, 256); + //key->x = x; + //key->y = y; +} + + +void zero_fill(BYTE * pBuf, size_t bufSize) +{ + size_t i; + for(i = 0; i < bufSize; i++) + pBuf[i] = 0; +} + +void* __stdcall GenerateKey(char* pwd) +{ + rc4_key* key; + key = (rc4_key*)malloc(sizeof(rc4_key)); + zero_fill((BYTE*)key, sizeof(key)); + prepare_key(pwd, strlen(pwd), key); + return key; +} + +void __stdcall FreeKey(void* key) +{ + free(key); +} + +void __stdcall EncryptMem(BYTE* data, int size, void* key) +{ + rc4(data, size, key); +} + +void __stdcall DecryptMem(BYTE* data, int size, void* key) +{ + rc4(data, size, key); +} + +Cryptor cryptor = + { + GenerateKey, + FreeKey, + EncryptMem, + DecryptMem, + "RC4", + "Old, very easy to crack stream cipher", + "Unknown", + "http://ru.wikipedia.org/wiki/RC4", + "nomail", + 0x00000100, + 0xDEAD + }; + + +__declspec(dllexport) Cryptor* GetCryptor() +{ + return &cryptor; +} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Dbtool/Version.h b/plugins/Dbx_mmap_SA/Dbtool/Version.h deleted file mode 100644 index 1ee2b8a4cf..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/Version.h +++ /dev/null @@ -1,9 +0,0 @@ -#include "m_version.h" - -#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION -#define __VERSION_STRING MIRANDA_VERSION_STRING -#define __VERSION_DWORD MIRANDA_VERSION_DWORD -#define __INTERNAL_NAME "dbtool" -#define __FILENAME "dbtool.exe" -#define __DESCRIPTION "Miranda IM Database Tool" -#define __COPYRIGHT "© 2000-2011 Miranda IM project" diff --git a/plugins/Dbx_mmap_SA/Dbtool/Version.rc b/plugins/Dbx_mmap_SA/Dbtool/Version.rc deleted file mode 100644 index b6ce62273e..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/Version.rc +++ /dev/null @@ -1,42 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "afxres.h" -#include "version.h" - -#ifdef _WIN32 -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#endif //_WIN32 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION __FILEVERSION_STRING - PRODUCTVERSION __FILEVERSION_STRING - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x0L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "FileDescription", __DESCRIPTION - VALUE "InternalName", __INTERNAL_NAME - VALUE "LegalCopyright", __COPYRIGHT - VALUE "OriginalFilename", __FILENAME - VALUE "ProductName", __DESCRIPTION - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END diff --git a/plugins/Dbx_mmap_SA/Dbtool/aggressive.cpp b/plugins/Dbx_mmap_SA/Dbtool/aggressive.cpp deleted file mode 100644 index 5ec62707f1..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/aggressive.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -#define BLOCKSIZE 65536 - -extern DWORD sourceFileSize; -extern DWORD spaceProcessed; -extern DWORD sp; -static DWORD ofsCurrent; - -int WorkAggressive(int firstTime) -{ - int blockBytes,i; - BYTE *buf; - - if(firstTime) { - if (!opts.bAggressive) return ERROR_NO_MORE_ITEMS; - AddToStatus(STATUS_MESSAGE,TranslateT("Performing aggressive pass")); - ofsCurrent=0; - spaceProcessed=0; - sp=0; - } - blockBytes=min(BLOCKSIZE+3,(int)(sourceFileSize-ofsCurrent)); - if(blockBytes<=0) return ERROR_NO_MORE_ITEMS; - buf = opts.pFile+ofsCurrent; - blockBytes-=3; - for(i=0;iend of file (plain offset) - |-->first contact (DBContact) - | |-->next contact (DBContact) - | | \--> ... - | |-->first settings (DBContactSettings) - | | |-->next settings (DBContactSettings) - | | | \--> ... - | | \-->module name (DBModuleName) - | \-->first/last/firstunread event - |-->user contact (DBContact) - | |-->next contact=NULL - | |-->first settings as above - | \-->first/last/firstunread event as above - \-->first module name (DBModuleName) - \-->next module name (DBModuleName) - \--> ... -*/ - -#define DB_RESIZE_GRANULARITY 16384 -#define DB_THIS_VERSION 0x00000700u -#define DB_SETTINGS_RESIZE_GRANULARITY 128 - -#include -struct DBHeader { - BYTE signature[16]; // 'Miranda ICQ DB',0,26 - - WORD checkWord; - WORD cryptorUID; - DWORD ofsFileEnd; //offset of the end of the database - place to write - //new structures - DWORD slackSpace; //a counter of the number of bytes that have been - //wasted so far due to deleting structures and/or - //re-making them at the end. We should compact when - //this gets above a threshold - DWORD contactCount; //number of contacts in the chain,excluding the user - DWORD ofsFirstContact; //offset to first struct DBContact in the chain - DWORD ofsUser; //offset to struct DBContact representing the user - DWORD ofsFirstModuleName; //offset to first struct DBModuleName in the chain -}; - -#define DBCONTACT_SIGNATURE 0x43DECADEu -struct DBContact { - DWORD signature; - DWORD ofsNext; //offset to the next contact in the chain. zero if - //this is the 'user' contact or the last contact - //in the chain - DWORD ofsFirstSettings; //offset to the first DBContactSettings in the - //chain for this contact. - DWORD eventCount; //number of events in the chain for this contact - DWORD ofsFirstEvent,ofsLastEvent; //offsets to the first and last DBEvent in - //the chain for this contact - DWORD ofsFirstUnreadEvent; //offset to the first (chronological) unread event - //in the chain, 0 if all are read - DWORD timestampFirstUnread; //timestamp of the event at ofsFirstUnreadEvent -}; - -#define DBMODULENAME_SIGNATURE 0x4DDECADEu -struct DBModuleName { - DWORD signature; - DWORD ofsNext; //offset to the next module name in the chain - BYTE cbName; //number of characters in this module name - char name[1]; //name, no nul terminator -}; - -#define DBCONTACTSETTINGS_SIGNATURE 0x53DECADEu -struct DBContactSettings { - DWORD signature; - DWORD ofsNext; //offset to the next contactsettings in the chain - DWORD ofsModuleName; //offset to the DBModuleName of the owner of these - //settings - DWORD cbBlob; //size of the blob in bytes. May be larger than the - //actual size for reducing the number of moves - //required using granularity in resizing - BYTE blob[1]; //the blob. a back-to-back sequence of DBSetting - //structs, the last has cbName=0 -}; - -/* not a valid structure, content is figured out on the fly -struct DBSetting { - BYTE cbName; //number of bytes in the name of this setting - //this =0 marks the end - char szName[...]; //setting name, excluding nul - BYTE dataType; //type of data. see m_database.h, db/contact/getsetting - union { //a load of types of data, length is defined by dataType - BYTE bVal; WORD wVal; DWORD dVal; - struct { - WORD cbString; - char szVal[...]; //excludes nul terminator - }; - struct { - WORD cbBlob; - BYTE blobVal[...]; - }; - }; -}; -*/ - -#define DBEVENT_SIGNATURE 0x45DECADEu -struct DBEvent { - DWORD signature; - DWORD ofsPrev,ofsNext; //offset to the previous and next events in the - //chain. Chain is sorted chronologically - DWORD ofsModuleName; //offset to a DBModuleName struct of the name of - //the owner of this event - DWORD timestamp; //seconds since 00:00:00 01/01/1970 - DWORD flags; //see m_database.h, db/event/add - WORD eventType; //module-defined event type - DWORD cbBlob; //number of bytes in the blob - BYTE blob[1]; //the blob. module-defined formatting -}; -#include - -//databasecorruption: called if any signatures are broken. very very fatal -void DatabaseCorruption(const char *szPart); -PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail); //any preview result could be invalidated by the next call -void DBWrite(DWORD ofs,PVOID pData,int count); -void DBFlush(int setting); -void DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes); -DWORD CreateNewSpace(int bytes); -void DeleteSpace(DWORD ofs,int bytes); -void GetProfileDirectory(char *szPath,int cbPath); -int GetDefaultProfilePath(char *szPath,int cbPath,int *specified); -int ShouldShowProfileManager(void); - -#ifdef _DEBUG -#define MAXCACHEDREADSIZE 512 -#else -#define MAXCACHEDREADSIZE 2048 //technically 4096 would work, but I'm not going to push it -#endif - -#ifdef _DEBUG -//#define DBLOGGING -#endif -#ifdef DBLOGGING -void DBLog(const char *file,int line,const char *fmt,...); -#define logg() DBLog(__FILE__,__LINE__,"") -#define log0(s) DBLog(__FILE__,__LINE__,s) -#define log1(s,a) DBLog(__FILE__,__LINE__,s,a) -#define log2(s,a,b) DBLog(__FILE__,__LINE__,s,a,b) -#define log3(s,a,b,c) DBLog(__FILE__,__LINE__,s,a,b,c) -#define log4(s,a,b,c,d) DBLog(__FILE__,__LINE__,s,a,b,c,d) -#else -#define logg() -#define log0(s) -#define log1(s,a) -#define log2(s,a,b) -#define log3(s,a,b,c) -#define log4(s,a,b,c,d) -#endif \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Dbtool/dbtool.exe.manifest b/plugins/Dbx_mmap_SA/Dbtool/dbtool.exe.manifest deleted file mode 100644 index 1b6aab686b..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/dbtool.exe.manifest +++ /dev/null @@ -1,31 +0,0 @@ - - - -Miranda - - - - - - - - - - - - - diff --git a/plugins/Dbx_mmap_SA/Dbtool/dbtool.h b/plugins/Dbx_mmap_SA/Dbtool/dbtool.h deleted file mode 100644 index dd6af38cd5..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/dbtool.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -Miranda Database Tool -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 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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. -#include "resource.h" - -#define WZM_GOTOPAGE (WM_USER+1) -#define WZN_PAGECHANGING (WM_USER+1221) -#define WZN_CANCELCLICKED (WM_USER+1222) - -struct DbToolOptions { - TCHAR filename[MAX_PATH]; - TCHAR workingFilename[MAX_PATH]; - TCHAR outputFilename[MAX_PATH]; - TCHAR backupFilename[MAX_PATH]; - HANDLE hFile; - HANDLE hOutFile; - HANDLE hMap; - BYTE *pFile; - DWORD error; - int bCheckOnly,bBackup,bAggressive; - int bEraseHistory,bMarkRead,bConvertUtf; -}; - -extern HINSTANCE hInst; -extern DbToolOptions opts; -extern DBHeader dbhdr; - -int DoMyControlProcessing(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam,INT_PTR *bReturn); - -INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK CleaningDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK ProgressDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK FinishedDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK OpenErrorDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); - -struct DBSignature { - char name[15]; - BYTE eof; -}; -static struct DBSignature dbSignature={"Miranda ICQ DB",0x1A}; -static struct DBSignature dbSignatureEncrypted={"Miranda ICQ SD",0x1A}; - -#define SIZEOF(X) (sizeof(X)/sizeof(X[0])) - -#define STATUS_MESSAGE 0 -#define STATUS_WARNING 1 -#define STATUS_ERROR 2 -#define STATUS_FATAL 3 -#define STATUS_SUCCESS 4 -#define STATUS_CLASSMASK 0x0f -int AddToStatus(DWORD flags, TCHAR* fmt,...); -void SetProgressBar(int perThou); - -int PeekSegment(DWORD ofs,PVOID buf,int cbBytes); -int ReadSegment(DWORD ofs,PVOID buf,int cbBytes); -#define WSOFS_END 0xFFFFFFFF -#define WS_ERROR 0xFFFFFFFF -DWORD WriteSegment(DWORD ofs,PVOID buf,int cbBytes); -int ReadWrittenSegment(DWORD ofs,PVOID buf,int cbBytes); -int SignatureValid(DWORD ofs,DWORD signature); -DWORD ConvertModuleNameOfs(DWORD ofsOld); -void FreeModuleChain(); -extern BOOL bEncrypted; - -bool is_utf8_string(const char* str); diff --git a/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj b/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj index 0aa02d798d..7b734e1736 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj +++ b/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj @@ -69,14 +69,13 @@ Disabled ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - _DEBUG;WIN32;_WINDOWS;DATABASE_INDEPENDANT;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL Use dbtool.h Level3 EditAndContinue - 4996;%(DisableSpecificWarnings) _DEBUG;%(PreprocessorDefinitions) @@ -99,13 +98,12 @@ Disabled ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - _DEBUG;WIN64;_WINDOWS;DATABASE_INDEPENDANT;%(PreprocessorDefinitions) + WIN64;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL Use dbtool.h Level3 - 4996;%(DisableSpecificWarnings) _DEBUG;%(PreprocessorDefinitions) @@ -130,14 +128,13 @@ OnlyExplicitInline Size ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - NDEBUG;WIN32;_WINDOWS;DATABASE_INDEPENDANT;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true false true Use dbtool.h Level3 - 4996;%(DisableSpecificWarnings) false Fast @@ -166,14 +163,13 @@ OnlyExplicitInline Size ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - NDEBUG;WIN64;_WINDOWS;DATABASE_INDEPENDANT;%(PreprocessorDefinitions) + WIN64;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true false true Use dbtool.h Level3 - 4996;%(DisableSpecificWarnings) false Fast @@ -197,44 +193,38 @@ - - - + + + Create - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - + + 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 1c054474cd..d7c4efe5f7 100644 --- a/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/Dbtool/dbtool_sa_10.vcxproj.filters @@ -21,100 +21,86 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files\Workers - + Source Files\Workers - + Source Files\Workers - + Source Files\Workers - + Source Files\Workers - + Source Files\Workers - + Source Files\Workers - + Source Files\Workers - + Source Files\Wizard Pages - + Source Files\Wizard Pages - + Source Files\Wizard Pages - + Source Files\Wizard Pages - + Source Files\Wizard Pages - + Source Files\Wizard Pages - + Source Files\Wizard Pages - + Source Files - + Source Files - + Header Files - + Header Files - + Header Files - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - - + Resource Files - + Resource Files diff --git a/plugins/Dbx_mmap_SA/Dbtool/disk.cpp b/plugins/Dbx_mmap_SA/Dbtool/disk.cpp deleted file mode 100644 index 1ac84a3dc6..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/disk.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -extern DWORD spaceProcessed,sourceFileSize; - -int SignatureValid(DWORD ofs,DWORD signature) -{ - DWORD sig; - - if(ofs+sizeof(sig)>=sourceFileSize) { - AddToStatus(STATUS_ERROR,TranslateT("Invalid offset found (database truncated?)")); - return 0; - } - - sig = *(DWORD*)(opts.pFile+ofs); - - return sig==signature; -} - -int PeekSegment(DWORD ofs,PVOID buf,int cbBytes) -{ - DWORD bytesRead; - - if(ofs>=sourceFileSize) { - AddToStatus(STATUS_ERROR,TranslateT("Invalid offset found")); - return ERROR_SEEK; - } - - if (ofs+cbBytes>sourceFileSize) - bytesRead = sourceFileSize - ofs; - else - bytesRead = cbBytes; - - if(bytesRead==0) { - AddToStatus(STATUS_ERROR,TranslateT("Error reading, database truncated? (%u)"),GetLastError()); - return ERROR_READ_FAULT; - } - - CopyMemory(buf, opts.pFile+ofs, bytesRead); - - if ((int)bytesReadsourceFileSize) { - AddToStatus(STATUS_WARNING,TranslateT("Can't write to working file, aggressive mode may be too aggressive now")); - ZeroMemory(opts.pFile+ofs,sourceFileSize-ofs); - } - else - ZeroMemory(opts.pFile+ofs,cbBytes); - } - spaceProcessed+=cbBytes; - return ERROR_SUCCESS; -} - -DWORD WriteSegment(DWORD ofs,PVOID buf,int cbBytes) -{ - DWORD bytesWritten; - if(opts.bCheckOnly) return 0xbfbfbfbf; - if(ofs==WSOFS_END) { - ofs=dbhdr.ofsFileEnd; - dbhdr.ofsFileEnd+=cbBytes; - } - SetFilePointer(opts.hOutFile,ofs,NULL,FILE_BEGIN); - WriteFile(opts.hOutFile,buf,cbBytes,&bytesWritten,NULL); - if ((int)bytesWritten dbhdr.ofsFileEnd ) - return ERROR_SEEK; - - SetFilePointer(opts.hOutFile,ofs,NULL,FILE_BEGIN); - ReadFile(opts.hOutFile,buf,cbBytes,&bytesRead,NULL); - if ((int)bytesReadcryptor = GetCryptor(); - strcpy(Modules[ModulesCount]->dllname, fd.cFileName); - Modules[ModulesCount]->hLib = hLib; - - _snprintf(buf,SIZEOF(buf),"%d.%d.%d.%d", HIBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), HIBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version))); - - mbstowcs(Name, Modules[ModulesCount]->cryptor->Name, 100); - mbstowcs(Version, buf, 100); - mbstowcs(DllName, Modules[ModulesCount]->dllname, 100); - - AddToStatus(STATUS_MESSAGE,TranslateT("Cryptor loaded: %s [%s] (%s)"), Name, Version, DllName); - - ModulesCount++; - }else{ - FreeLibrary(hLib); - } - } - if(ModulesCount >= 100) break; - if (!FindNextFileA(hFile, &fd)) break; - } - - AddToStatus(STATUS_MESSAGE,TranslateT("%d crypto modules loaded"), ModulesCount); -} - -void UnloadSecurity() -{ - int i; - - if(CryptoEngine) CryptoEngine->FreeKey(key); - - for(i = 0; i < ModulesCount; i++) - { - FreeLibrary(Modules[i]->hLib); - free(Modules[i]); - } -} - -void EncoderInit() -{ - encryptKey[encryptKeyLength] = 0; - key = CryptoEngine->GenerateKey(encryptKey); -} - -void EncodeCopyMemory(BYTE * dst, void * src, size_t size ) -{ - memcpy(dst, src, size); - CryptoEngine->EncryptMem(dst, (int)size, key); -} - -void DecodeCopyMemory(BYTE * dst, void * src, size_t size ) -{ - memcpy(dst, src, size); - CryptoEngine->DecryptMem(dst, (int)size, key); -} - - -void EncodeMemory(BYTE * mem, size_t size) -{ - CryptoEngine->EncryptMem(mem, (int)size, key); -} - -void DecodeMemory(BYTE * mem, size_t size) -{ - CryptoEngine->DecryptMem(mem, (int)size, key); -} - -int bCheckingPass = 0; - -int CheckPassword(WORD checkWord, WORD cryptorUID, char * szDBName) -{ - WORD ver; - int res; - - if(bCheckingPass) return 0; - bCheckingPass = 1; - - { - int i; - int Found = 0; - for(i = 0; i < ModulesCount; i++) { - if(cryptorUID == Modules[i]->cryptor->uid){ - CryptoEngine = Modules[i]->cryptor; - Found = 1; - break; - } - } - if (!Found){ - AddToStatus(STATUS_FATAL, TranslateT("Sorry, but your database encrypted with unknown module"), MB_OK); - bCheckingPass = 0; - return 0; - } - } - - { - wchar_t Name[100], Author[100]; - - mbstowcs(Name, CryptoEngine->Name, 100); - mbstowcs(Author, CryptoEngine->Author, 100); - - AddToStatus(STATUS_MESSAGE, TranslateT("Database encrypted with %s by %s"), Name, Author); - } - - while(1){ - res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LOGIN), NULL, (DLGPROC)DlgStdInProc, (LPARAM)szDBName); - if(res == IDCANCEL) - { - wrongPass = 0; - bCheckingPass = 0; - return 0; - } - if(encryptKeyLength < 1) continue; - EncoderInit(); - DecodeCopyMemory((BYTE*)&ver, &checkWord, sizeof(checkWord)); - if(ver == 0x5195) - { - wrongPass = 0; - bCheckingPass = 0; - return 1; - } - wrongPass++; - } - - bCheckingPass = 0; -} - - -UINT oldLangID = 0; -void LanguageChanged(HWND hDlg) -{ - UINT LangID = (UINT)GetKeyboardLayout(0); - char Lang[3] = {0}; - if (LangID != oldLangID) - { - oldLangID = LangID; - GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); - SetDlgItemTextA(hDlg, IDC_LANG, Lang); - } -} - -BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) -{ - switch(uMsg) - { - case WM_INITDIALOG: - { - HWND hwndCtrl; - TranslateDialogDefault(hDlg); - - if(lParam && !wrongPass) SetDlgItemTextA(hDlg, IDC_DBNAME, (LPCSTR)lParam); - if(wrongPass) - { - if (wrongPass > 2) - { - hwndCtrl = GetDlgItem(hDlg, IDC_USERPASS); - EnableWindow(hwndCtrl, FALSE); - hwndCtrl = GetDlgItem(hDlg, IDOK); - EnableWindow(hwndCtrl, FALSE); - - SetDlgItemText(hDlg, IDC_LOGININFO, TranslateT("Too many errors!")); - - } - else - { - SetDlgItemText(hDlg, IDC_LOGININFO, TranslateT("Password is not correct!")); - } - } - oldLangID = 0; - SetTimer(hDlg,1,200,NULL); - LanguageChanged(hDlg); - return TRUE; - } - - case WM_CTLCOLORSTATIC: - { - if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) - { - SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkMode((HDC)wParam, TRANSPARENT); - return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); - } - - return FALSE; - } - - case WM_COMMAND: - { - UINT uid = LOWORD(wParam); - - if(uid == IDOK){ - if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) - { - encryptKeyLength = GetDlgItemTextA(hDlg, IDC_USERPASS, encryptKey, 254); - EndDialog(hDlg,IDOK); - }else{ - - } - }else if(uid == IDCANCEL){ - EndDialog(hDlg,IDCANCEL); - } - } - case WM_TIMER: - { - LanguageChanged(hDlg); - return FALSE; - } - case WM_DESTROY: - { - KillTimer(hDlg, 1); - return FALSE; - } - } - - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp b/plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp deleted file mode 100644 index 3c9e37668a..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/* -Miranda Database Tool -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" - -static BOOL backLookup; -static DWORD ofsThisEvent,ofsPrevEvent; -static DWORD ofsDestPrevEvent; -static DWORD eventCount; -static DWORD lastTimestamp; -static DWORD ofsFirstUnread,timestampFirstUnread; -static DWORD memsize = 0; -static DBEvent* memblock = NULL; -static DBEvent* dbePrevEvent = NULL; - -static void ConvertOldEvent( DBEvent*& dbei ) -{ - int msglen = (int)strlen(( char* )dbei->blob) + 1, msglenW = 0; - if ( msglen != (int) dbei->cbBlob ) { - int i, count = (( dbei->cbBlob - msglen ) / sizeof( WCHAR )); - WCHAR* p = ( WCHAR* )&dbei->blob[ msglen ]; - for ( i=0; i < count; i++ ) { - if ( p[i] == 0 ) { - msglenW = i; - break; - } } } - else { - if ( !is_utf8_string(( char* )dbei->blob)) - dbei->flags &= ~DBEF_UTF; - } - - if ( msglenW > 0 && msglenW <= 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) { - memsize = offsetof(DBEvent,blob)+dbei->cbBlob; - memblock = (DBEvent*)realloc(memblock, memsize); - dbei = memblock; - } - memcpy( &dbei->blob, utf8str, dbei->cbBlob ); - free(utf8str); -} } - -static void WriteOfsNextToPrevious(DWORD ofsPrev,DBContact *dbc,DWORD ofsNext) -{ - if(ofsPrev) - WriteSegment(ofsPrev+offsetof(DBEvent,ofsNext),&ofsNext,sizeof(DWORD)); - else - dbc->ofsFirstEvent=ofsNext; -} - -static void FinishUp(DWORD ofsLast,DBContact *dbc) -{ - WriteOfsNextToPrevious(ofsLast,dbc,0); - if(eventCount!=dbc->eventCount) - AddToStatus(STATUS_WARNING,TranslateT("Event count marked wrongly: correcting")); - dbc->eventCount=eventCount; - dbc->ofsLastEvent=ofsLast; - if(opts.bMarkRead) { - dbc->ofsFirstUnreadEvent=0; - dbc->timestampFirstUnread=0; - } - else { - dbc->ofsFirstUnreadEvent=ofsFirstUnread; - dbc->timestampFirstUnread=timestampFirstUnread; - } - if (memsize && memblock) { - free(memblock); - memsize = 0; - memblock = NULL; - } -} - -static DWORD WriteEvent(DBEvent *dbe) -{ - DWORD ofs = WriteSegment( WSOFS_END, dbe, offsetof(DBEvent,blob)+dbe->cbBlob ); - if ( ofs == WS_ERROR ) { - free( memblock ); - memblock = NULL; - memsize = 0; - return 0; - } - return ofs; -} - -int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime) -{ - DBEvent *dbeNew,dbeOld; - DBEvent *dbePrev = NULL; - DWORD ofsDestThis; - int isUnread=0; - - if(firstTime) { - dbePrevEvent = NULL; - ofsPrevEvent=0; - ofsDestPrevEvent=0; - ofsThisEvent=dbc->ofsFirstEvent; - eventCount=0; - backLookup=0; - lastTimestamp=0; - ofsFirstUnread=timestampFirstUnread=0; - if(opts.bEraseHistory) { - dbc->eventCount=0; - dbc->ofsFirstEvent=0; - dbc->ofsLastEvent=0; - dbc->ofsFirstUnreadEvent=0; - dbc->timestampFirstUnread=0; - return ERROR_NO_MORE_ITEMS; - } } - - if(ofsThisEvent==0) { - FinishUp(ofsDestPrevEvent,dbc); - return ERROR_NO_MORE_ITEMS; - } - if (!SignatureValid(ofsThisEvent,DBEVENT_SIGNATURE)) - { - DWORD ofsNew = 0; - DWORD ofsTmp = dbc->ofsLastEvent; - - if (!backLookup && ofsTmp) { - backLookup = 1; - while(SignatureValid(ofsTmp,DBEVENT_SIGNATURE)) - { - if(PeekSegment(ofsTmp,&dbeOld,sizeof(dbeOld))!=ERROR_SUCCESS) - break; - ofsNew = ofsTmp; - ofsTmp = dbeOld.ofsPrev; - } - } - if (ofsNew) { - AddToStatus(STATUS_WARNING,TranslateT("Event chain corrupted, trying to recover...")); - ofsThisEvent = ofsNew; - } else { - AddToStatus(STATUS_ERROR,TranslateT("Event chain corrupted, further entries ignored")); - FinishUp(ofsDestPrevEvent,dbc); - return ERROR_NO_MORE_ITEMS; - } - } - - if(PeekSegment(ofsThisEvent,&dbeOld,sizeof(dbeOld))!=ERROR_SUCCESS) { - FinishUp(ofsDestPrevEvent,dbc); - return ERROR_NO_MORE_ITEMS; - } - - if(firstTime) { - if (!(dbeOld.flags&DBEF_FIRST)) { - AddToStatus(STATUS_WARNING,TranslateT("First event not marked as such: correcting")); - dbeOld.flags|=DBEF_FIRST; - } - dbeOld.ofsPrev=ofsContact; - lastTimestamp=dbeOld.timestamp; - } - else if(dbeOld.flags&DBEF_FIRST) { - AddToStatus(STATUS_WARNING,TranslateT("Event marked as first which is not: correcting")); - dbeOld.flags&=~DBEF_FIRST; - } - - if(dbeOld.flags&~(DBEF_FIRST|DBEF_READ|DBEF_SENT|DBEF_RTL|DBEF_UTF)) { - AddToStatus(STATUS_WARNING,TranslateT("Extra flags found in event: removing")); - dbeOld.flags&=(DBEF_FIRST|DBEF_READ|DBEF_SENT|DBEF_RTL|DBEF_UTF); - } - - if (!(dbeOld.flags&(DBEF_READ|DBEF_SENT))) { - if(opts.bMarkRead) dbeOld.flags|=DBEF_READ; - else if(ofsFirstUnread==0) { - if(dbc->ofsFirstUnreadEvent!=ofsThisEvent || dbc->timestampFirstUnread!=dbeOld.timestamp) - AddToStatus(STATUS_WARNING,TranslateT("First unread event marked wrong: fixing")); - isUnread=1; - } } - - if(dbeOld.cbBlob>1024*1024 || dbeOld.cbBlob==0) { - AddToStatus(STATUS_ERROR,TranslateT("Infeasibly large event blob: skipping")); - ofsThisEvent=dbeOld.ofsNext; - return ERROR_SUCCESS; - } - - if ( dbePrevEvent && dbeOld.timestamp == lastTimestamp ) { - int len = offsetof(DBEvent,blob)+dbePrevEvent->cbBlob; - dbePrev = (DBEvent*)malloc(len); - memcpy(dbePrev, dbePrevEvent, len); - } - - if (offsetof(DBEvent,blob)+dbeOld.cbBlob > memsize) { - memsize = offsetof(DBEvent,blob)+dbeOld.cbBlob; - memblock = (DBEvent*)realloc(memblock, memsize); - } - dbeNew=memblock; - - if(ReadSegment(ofsThisEvent,dbeNew,offsetof(DBEvent,blob)+dbeOld.cbBlob)!=ERROR_SUCCESS) { - FinishUp(ofsDestPrevEvent,dbc); - return ERROR_NO_MORE_ITEMS; - } - - if ((dbeNew->ofsModuleName=ConvertModuleNameOfs(dbeOld.ofsModuleName))==0) { - ofsThisEvent=dbeOld.ofsNext; - return ERROR_SUCCESS; - } - - if (!firstTime && dbeOld.ofsPrev!=ofsPrevEvent) - AddToStatus(STATUS_WARNING,TranslateT("Event not backlinked correctly: fixing")); - - dbeNew->flags=dbeOld.flags; - dbeNew->ofsPrev=ofsDestPrevEvent; - dbeNew->ofsNext=0; - - if ( dbeOld.eventType == EVENTTYPE_MESSAGE && opts.bConvertUtf ) - ConvertOldEvent(dbeNew); - - if ( dbePrev ) - { - if ( dbePrev->cbBlob == dbeNew->cbBlob && - dbePrev->ofsModuleName == dbeNew->ofsModuleName && - dbePrev->eventType == dbeNew->eventType && - (dbePrev->flags & DBEF_SENT) == (dbeNew->flags & DBEF_SENT) && - !memcmp( dbePrev->blob, dbeNew->blob, dbeNew->cbBlob ) - ) { - AddToStatus(STATUS_WARNING,TranslateT("Duplicate event was found: skipping")); - if (dbc->eventCount) - dbc->eventCount--; - free(dbePrev); - // ofsDestPrevEvent is still the same! - ofsPrevEvent=ofsThisEvent; - ofsThisEvent=dbeOld.ofsNext; - return ERROR_SUCCESS; - } - free(dbePrev); - } - else if ( !firstTime && dbeNew->timestamp < lastTimestamp ) - { - DWORD found = 0; - DBEvent dbeTmp; - DWORD ofsTmp; - - if (opts.bCheckOnly) - { - if (!opts.bAggressive) - { - ofsTmp = dbeOld.ofsPrev; - while(PeekSegment(ofsTmp,&dbeTmp,sizeof(dbeTmp))==ERROR_SUCCESS) - { - if (dbeTmp.ofsPrev == ofsContact) { - found = 1; - break; - } - if (dbeTmp.timestamp < dbeNew->timestamp) { - found = 2; - break; - } - ofsTmp = dbeTmp.ofsPrev; - } - } - AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct")); - } - else - { - ofsTmp = ofsDestPrevEvent; - while(ReadWrittenSegment(ofsTmp,&dbeTmp,sizeof(dbeTmp))==ERROR_SUCCESS) - { - if (dbeTmp.ofsPrev == ofsContact) { - found = 1; - break; - } - if (dbeTmp.timestamp < dbeNew->timestamp) { - found = 2; - break; - } - ofsTmp = dbeTmp.ofsPrev; - } - if (found) - AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct: fixing")); - else - AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct: unable to fix")); - } - - // insert before FIRST - if (found == 1 && !opts.bCheckOnly) { - dbeNew->flags|=DBEF_FIRST; - dbeNew->ofsPrev=ofsContact; - dbeNew->ofsNext=dbc->ofsFirstEvent; - - ofsDestThis = WriteEvent(dbeNew); - if ( !ofsDestThis ) - return ERROR_HANDLE_DISK_FULL; - - if ( isUnread && timestampFirstUnread >= dbeNew->timestamp ) { - ofsFirstUnread=ofsDestThis; - timestampFirstUnread=dbeNew->timestamp; - } - // fix first event - WriteOfsNextToPrevious(0,dbc,ofsDestThis); - // fix next event - WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,ofsPrev),&ofsDestThis,sizeof(DWORD)); - dbeTmp.flags &=~DBEF_FIRST; - WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,flags),&dbeTmp.flags,sizeof(DWORD)); - } - else if (found == 2 && !opts.bCheckOnly) { - - dbeNew->ofsPrev=ofsTmp; - dbeNew->ofsNext=dbeTmp.ofsNext; - - ofsDestThis = WriteEvent(dbeNew); - if ( !ofsDestThis ) - return ERROR_HANDLE_DISK_FULL; - - if ( isUnread && timestampFirstUnread >= dbeNew->timestamp ) { - ofsFirstUnread=ofsDestThis; - timestampFirstUnread=dbeNew->timestamp; - } - // fix previous event - WriteOfsNextToPrevious(dbeNew->ofsPrev,dbc,ofsDestThis); - // fix next event - WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,ofsPrev),&ofsDestThis,sizeof(DWORD)); - } - - if (found) { - eventCount++; - // ofsDestPrevEvent is still the same! - ofsPrevEvent=ofsThisEvent; - ofsThisEvent=dbeOld.ofsNext; - return ERROR_SUCCESS; - } - } - - lastTimestamp=dbeNew->timestamp; - dbePrevEvent = dbeNew; - - ofsDestThis = WriteEvent(dbeNew); - if ( !ofsDestThis ) - return ERROR_HANDLE_DISK_FULL; - - if ( isUnread ) { - ofsFirstUnread=ofsDestThis; - timestampFirstUnread=dbeOld.timestamp; - } - - eventCount++; - WriteOfsNextToPrevious(ofsDestPrevEvent,dbc,ofsDestThis); - - ofsDestPrevEvent=ofsDestThis; - ofsPrevEvent=ofsThisEvent; - ofsThisEvent=dbeOld.ofsNext; - return ERROR_SUCCESS; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp b/plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp deleted file mode 100644 index d904daf5b9..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/fileaccess.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - INT_PTR bReturn; - - if(DoMyControlProcessing(hdlg,message,wParam,lParam,&bReturn)) return bReturn; - switch(message) { - case WM_INITDIALOG: - CheckDlgButton(hdlg,IDC_CHECKONLY,opts.bCheckOnly); - CheckDlgButton(hdlg,IDC_BACKUP,opts.bBackup); - CheckDlgButton(hdlg,IDC_AGGRESSIVE,opts.bAggressive); - SendMessage(hdlg,WM_COMMAND,MAKEWPARAM(IDC_CHECKONLY,BN_CLICKED),0); - TranslateDialogDefault(hdlg); - return TRUE; - case WZN_PAGECHANGING: - opts.bCheckOnly=IsDlgButtonChecked(hdlg,IDC_CHECKONLY); - opts.bAggressive=IsDlgButtonChecked(hdlg,IDC_AGGRESSIVE); - if(opts.bCheckOnly) opts.bBackup=0; - else opts.bBackup=IsDlgButtonChecked(hdlg,IDC_BACKUP); - break; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_SELECTDB,(LPARAM)SelectDbDlgProc); - break; - case IDOK: - if(opts.bCheckOnly) { - if (!opts.hFile) { - opts.hFile = CreateFile( opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); - if ( opts.hFile == INVALID_HANDLE_VALUE ) { - opts.hFile = NULL; - opts.error = GetLastError(); - SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, ( LPARAM )OpenErrorDlgProc ); - break; - } - } - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressDlgProc); - } - else - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_CLEANING,(LPARAM)CleaningDlgProc); - break; - case IDC_CHECKONLY: - EnableWindow(GetDlgItem(hdlg,IDC_BACKUP),!IsDlgButtonChecked(hdlg,IDC_CHECKONLY)); - EnableWindow(GetDlgItem(hdlg,IDC_STBACKUP),!IsDlgButtonChecked(hdlg,IDC_CHECKONLY)); - break; - } - break; - } - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/finaltasks.cpp b/plugins/Dbx_mmap_SA/Dbtool/finaltasks.cpp deleted file mode 100644 index 2ed8b7183d..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/finaltasks.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -extern int errorCount; - -int WorkFinalTasks(int firstTime) -{ - FreeModuleChain(); - AddToStatus(STATUS_MESSAGE,TranslateT("Processing final tasks")); - dbhdr.slackSpace=0; - if(WriteSegment(0,&dbhdr,sizeof(dbhdr))==WS_ERROR) - return ERROR_WRITE_FAULT; - if (opts.hFile) { - CloseHandle(opts.hFile); - opts.hFile = NULL; - } - if ( opts.hOutFile ) { - CloseHandle(opts.hOutFile); - opts.hOutFile = NULL; - } - if (opts.pFile) { - UnmapViewOfFile(opts.pFile); - opts.pFile = NULL; - } - if (opts.hMap) { - CloseHandle(opts.hMap); - opts.hMap = NULL; - } - if(errorCount && !opts.bBackup && !opts.bCheckOnly) { - extern time_t ts; - time_t dlg_ts = time(NULL); - if ( IDYES == MessageBox( NULL, - TranslateT("Errors were encountered, however you selected not to backup the original database. It is strongly recommended that you do so in case important data was omitted. Do you wish to keep a backup of the original database?"), - TranslateT("Miranda Database Tool"), MB_YESNO )) - opts.bBackup = 1; - ts += time(NULL) - dlg_ts; - } - if(opts.bBackup) { - int i; - TCHAR dbPath[MAX_PATH],dbFile[MAX_PATH]; - _tcscpy( dbPath, opts.filename ); - TCHAR* str2 = _tcsrchr( dbPath, '\\' ); - if ( str2 != NULL ) { - _tcscpy( dbFile, str2+1 ); - *str2 = 0; - } - else { - _tcscpy( dbFile, dbPath ); - dbPath[0] = 0; - } - for(i=1;;i++) { - if(i==1) wsprintf(opts.backupFilename,TranslateT("%s\\Backup of %s"),dbPath,dbFile); - else wsprintf(opts.backupFilename,TranslateT("%s\\Backup (%d) of %s"),dbPath,i,dbFile); - if(_taccess(opts.backupFilename,0)==-1) break; - } - MoveFile(opts.filename,opts.backupFilename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to rename original file")); - } - else if (!opts.bCheckOnly) DeleteFile(opts.filename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to delete original file")); - if (!opts.bCheckOnly) MoveFile(opts.outputFilename,opts.filename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to rename output file")); - return ERROR_NO_MORE_ITEMS; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/finished.cpp b/plugins/Dbx_mmap_SA/Dbtool/finished.cpp deleted file mode 100644 index 08d0f5c893..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/finished.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -#define WM_LAUNCHMIRANDA (WM_USER+1) -INT_PTR CALLBACK FinishedDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - INT_PTR bReturn; - - if(DoMyControlProcessing(hdlg,message,wParam,lParam,&bReturn)) return bReturn; - switch(message) { - case WM_INITDIALOG: - EnableWindow(GetDlgItem(GetParent(hdlg),IDC_BACK),FALSE); - SetDlgItemText(GetParent(hdlg),IDCANCEL,TranslateT("&Finish")); - SetWindowLongPtr(GetDlgItem(hdlg,IDC_DBFILE),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hdlg,IDC_DBFILE),GWL_STYLE)|SS_PATHELLIPSIS); - SetDlgItemText( hdlg, IDC_DBFILE, opts.filename ); - if(opts.bBackup) { - ShowWindow(GetDlgItem(hdlg,IDC_STBACKUP),TRUE); - SetWindowLongPtr(GetDlgItem(hdlg,IDC_BACKUPFILE),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hdlg,IDC_BACKUPFILE),GWL_STYLE)|SS_PATHELLIPSIS); - SetDlgItemText(hdlg,IDC_BACKUPFILE,opts.backupFilename); - } - else ShowWindow(GetDlgItem(hdlg,IDC_STBACKUP),FALSE); - TranslateDialogDefault(hdlg); - return TRUE; - case WM_LAUNCHMIRANDA: - if(IsDlgButtonChecked(hdlg,IDC_LAUNCHMIRANDA)) { - TCHAR dbFile[MAX_PATH],dbPath[MAX_PATH],*str2; - _tcscpy(dbPath,opts.filename); - str2 = _tcsrchr(dbPath,'\\'); - if ( str2 == NULL ) { - _tcscpy( dbFile, dbPath ); - dbPath[ 0 ] = 0; - } - else { - _tcscpy( dbFile, str2+1 ); - *str2 = 0; - } - str2 = _tcsrchr( dbFile, '.' ); - if ( str2 != NULL ) - *str2 = 0; - _tcscat( dbPath, _T("\\miranda32.exe")); - if ( GetFileAttributes( dbPath ) == INVALID_FILE_ATTRIBUTES ) { - GetModuleFileName( NULL, dbPath, SIZEOF( dbPath )); - if (( str2 = _tcsrchr( dbPath, '\\' )) != NULL ) - *str2 = 0; - else - dbPath[0] = 0; - _tcscat( dbPath, _T("\\miranda32.exe")); - } - ShellExecute( hdlg, NULL, dbPath, dbFile, _T(""), SW_SHOW ); - } - break; - case WZN_CANCELCLICKED: - SendMessage(hdlg,WM_LAUNCHMIRANDA,0,0); - break; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDOK: - SendMessage(hdlg,WM_LAUNCHMIRANDA,0,0); - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_SELECTDB,(LPARAM)SelectDbDlgProc); - break; - } - break; - } - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/initialchecks.cpp b/plugins/Dbx_mmap_SA/Dbtool/initialchecks.cpp deleted file mode 100644 index 385d31cb92..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/initialchecks.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -BOOL bEncrypted; -extern DWORD sourceFileSize,spaceUsed; -int CheckPassword(WORD version, WORD cryptorUID, char * szDBName); -void InitSecurity(); - -int WorkInitialChecks(int firstTime) -{ - DWORD bytesRead; - - sourceFileSize=GetFileSize(opts.hFile,NULL); - if(sourceFileSize==0) { - AddToStatus(STATUS_WARNING,TranslateT("Database is newly created and has no data to process")); - AddToStatus(STATUS_SUCCESS,TranslateT("Processing completed successfully")); - return ERROR_INVALID_DATA; - } - ReadFile(opts.hFile,&dbhdr,sizeof(dbhdr),&bytesRead,NULL); - if(bytesRead")); - opts.hOutFile=INVALID_HANDLE_VALUE; - } - else { - _tcscpy(opts.outputFilename,opts.filename); - *_tcsrchr(opts.outputFilename,'.')=0; - _tcscat(opts.outputFilename,TranslateT(" (Output).dat")); - opts.hOutFile = CreateFile(opts.outputFilename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_FLAG_SEQUENTIAL_SCAN,NULL); - if ( opts.hOutFile == INVALID_HANDLE_VALUE ) { - AddToStatus(STATUS_FATAL,TranslateT("Can't create output file (%u)"),GetLastError()); - return ERROR_ACCESS_DENIED; - } - } - - opts.hMap = CreateFileMapping(opts.hFile, NULL, opts.bAggressive?PAGE_WRITECOPY:PAGE_READONLY, 0, 0, NULL); - - if (opts.hMap) - opts.pFile = (BYTE*)MapViewOfFile(opts.hMap, opts.bAggressive?FILE_MAP_COPY:FILE_MAP_READ, 0, 0 ,0); - else { - AddToStatus(STATUS_FATAL,TranslateT("Can't create file mapping (%u)"),GetLastError()); - return ERROR_ACCESS_DENIED; - } - - if (!opts.pFile) { - AddToStatus(STATUS_FATAL,TranslateT("Can't create map view of file (%u)"),GetLastError()); - return ERROR_ACCESS_DENIED; - } - if(ReadSegment(0,&dbhdr,sizeof(dbhdr))!=ERROR_SUCCESS) return ERROR_READ_FAULT; - if(WriteSegment(0,&dbhdr,sizeof(dbhdr))==WS_ERROR) return ERROR_HANDLE_DISK_FULL; - spaceUsed=dbhdr.ofsFileEnd-dbhdr.slackSpace; - dbhdr.ofsFileEnd=sizeof(dbhdr); - return ERROR_NO_MORE_ITEMS; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/main.cpp b/plugins/Dbx_mmap_SA/Dbtool/main.cpp deleted file mode 100644 index d505751bd5..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/main.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -HINSTANCE hInst; -int hLangpack=0; - -DbToolOptions opts = {0}; - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -{ - hInst=hInstance; - InitCommonControls(); - LoadLangPackModule(); - DialogBox(hInst,MAKEINTRESOURCE(IDD_WIZARD),NULL,WizardDlgProc); - return 0; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/modulechain.cpp b/plugins/Dbx_mmap_SA/Dbtool/modulechain.cpp deleted file mode 100644 index 2b91059176..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/modulechain.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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 ModChainEntry { - DWORD ofsOld,ofsNew; - int size; - char name[257]; -} static *modChain=NULL; -static int modChainCount; -static DWORD ofsCurrent; -static int phase,iCurrentModName; -static DWORD ofsLast; -static int last_mod = 0; - -int WorkModuleChain(int firstTime) -{ - DBModuleName moduleName,*newModName; - - if(firstTime) { - AddToStatus(STATUS_MESSAGE,TranslateT("Processing module name chain")); - modChainCount=0; - last_mod = 0; - if(modChain!=NULL) free(modChain); - modChain = (ModChainEntry*)malloc(sizeof(ModChainEntry)); - phase=0; - ofsCurrent=dbhdr.ofsFirstModuleName; - } - switch(phase) { - case 0: - if(ofsCurrent==0) { - phase++; - return ERROR_SUCCESS; - } - if (!SignatureValid(ofsCurrent,DBMODULENAME_SIGNATURE)) { - AddToStatus(STATUS_ERROR,TranslateT("Module chain corrupted, further entries ignored")); - phase++; - return ERROR_SUCCESS; - } - if(PeekSegment(ofsCurrent,&moduleName,offsetof(DBModuleName,name))!=ERROR_SUCCESS) { - phase++; - return ERROR_SUCCESS; - } - if(moduleName.cbName>256) - AddToStatus(STATUS_WARNING,TranslateT("Unreasonably long module name, skipping")); - else { - modChain=(ModChainEntry*)realloc(modChain,sizeof(ModChainEntry)*++modChainCount); - - modChain[modChainCount-1].ofsOld=ofsCurrent; - modChain[modChainCount-1].size=offsetof(DBModuleName,name)+moduleName.cbName; - modChain[modChainCount-1].ofsNew=0; - - if (moduleName.cbName) - PeekSegment(ofsCurrent+offsetof(DBModuleName,name),&modChain[modChainCount-1].name,moduleName.cbName); - modChain[modChainCount-1].name[moduleName.cbName]=0; - } - ofsCurrent=moduleName.ofsNext; - break; - case 1: - ofsLast = 0; - iCurrentModName=0; - dbhdr.ofsFirstModuleName=0; - phase++; - case 2: - if(iCurrentModName>=modChainCount) { - DWORD dw = 0; - if(ofsLast) WriteSegment(ofsLast+offsetof(DBModuleName,ofsNext),&dw,sizeof(DWORD)); - return ERROR_NO_MORE_ITEMS; - } - if(modChain[iCurrentModName].ofsNew==0) { - newModName=(DBModuleName*)_alloca(modChain[iCurrentModName].size); - if(ReadSegment(modChain[iCurrentModName].ofsOld,newModName,modChain[iCurrentModName].size)!=ERROR_SUCCESS) - return ERROR_NO_MORE_ITEMS; - if ((modChain[iCurrentModName].ofsNew=WriteSegment(WSOFS_END,newModName,modChain[iCurrentModName].size))==WS_ERROR) - return ERROR_HANDLE_DISK_FULL; - { // check duplicated modulenames - int i, n=0; - for(i=iCurrentModName+1;iitemWidth=listWidth; - mis->itemHeight=fontHeight; - return TRUE; - } - case WM_DRAWITEM: - { LPDRAWITEMSTRUCT dis=(LPDRAWITEMSTRUCT)lParam; - TCHAR str[256]; - int bold=0; - HFONT hoFont; - if ((int)dis->itemID==-1) break; - SendMessage(dis->hwndItem,LB_GETTEXT,dis->itemID,(LPARAM)str); - switch(dis->itemData&STATUS_CLASSMASK) { - case STATUS_MESSAGE: - SetTextColor(dis->hDC,RGB(0,0,0)); - break; - case STATUS_WARNING: - SetTextColor(dis->hDC,RGB(192,128,0)); - break; - case STATUS_ERROR: - SetTextColor(dis->hDC,RGB(192,0,0)); - break; - case STATUS_FATAL: - bold=1; - SetTextColor(dis->hDC,RGB(192,0,0)); - break; - case STATUS_SUCCESS: - bold=1; - SetTextColor(dis->hDC,RGB(0,192,0)); - break; - } - if(bold) hoFont=(HFONT)SelectObject(dis->hDC,hBoldFont); - ExtTextOut(dis->hDC,dis->rcItem.left,dis->rcItem.top,ETO_CLIPPED|ETO_OPAQUE,&dis->rcItem,str,(UINT)_tcslen(str),NULL); - if(bold) SelectObject(dis->hDC,hoFont); - return TRUE; - } - case WM_PROCESSINGDONE: - SetProgressBar(1000); - EnableWindow(GetDlgItem(GetParent(hdlg),IDOK),TRUE); - if(manualAbort==1) - EndDialog(GetParent(hdlg),0); - else if(manualAbort==2) { - if(opts.bCheckOnly) - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_FILEACCESS,(LPARAM)FileAccessDlgProc); - else { - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_CLEANING,(LPARAM)CleaningDlgProc); - CloseHandle(opts.hOutFile); - opts.hOutFile = NULL; - } - break; - } - AddToStatus(STATUS_SUCCESS,TranslateT("Click Next to continue")); - break; - case WZN_CANCELCLICKED: - ResetEvent(hEventRun); - if(IsWindowEnabled(GetDlgItem(GetParent(hdlg),IDOK))) break; - if(MessageBox(hdlg,TranslateT("Processing has not yet completed, if you cancel now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to cancel?"),TranslateT("Miranda Database Tool"),MB_YESNO)==IDYES) { - manualAbort=1; - SetEvent(hEventAbort); - } - SetEvent(hEventRun); - SetWindowLongPtr(hdlg,DWLP_MSGRESULT,TRUE); - return TRUE; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - ResetEvent(hEventRun); - if (!IsWindowEnabled(GetDlgItem(GetParent(hdlg),IDOK))) { - if(MessageBox(hdlg,TranslateT("Processing has not yet completed, if you go back now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to go back?"),TranslateT("Miranda Database Tool"),MB_YESNO)==IDYES) { - manualAbort=2; - SetEvent(hEventAbort); - } - SetEvent(hEventRun); - break; - } - SetEvent(hEventRun); - if(opts.bCheckOnly) - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_FILEACCESS,(LPARAM)FileAccessDlgProc); - else - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_CLEANING,(LPARAM)CleaningDlgProc); - break; - case IDOK: - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_FINISHED,(LPARAM)FinishedDlgProc); - break; - } - break; - case WM_DESTROY: - if (hEventAbort) { - CloseHandle(hEventAbort); - hEventAbort = NULL; - } - if (hEventRun) { - CloseHandle(hEventRun); - hEventRun = NULL; - } - if (hBoldFont) { - DeleteObject(hBoldFont); - hBoldFont = NULL; - } - break; - } - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/res/Version.rc b/plugins/Dbx_mmap_SA/Dbtool/res/Version.rc new file mode 100644 index 0000000000..f9dd44c219 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/res/Version.rc @@ -0,0 +1,42 @@ +// Microsoft Visual C++ generated resource script. +// +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include "afxres.h" +#include "..\src\version.h" + +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#endif //_WIN32 + +VS_VERSION_INFO VERSIONINFO + FILEVERSION __FILEVERSION_STRING + PRODUCTVERSION __FILEVERSION_STRING + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "FileDescription", __DESCRIPTION + VALUE "InternalName", __INTERNAL_NAME + VALUE "LegalCopyright", __COPYRIGHT + VALUE "OriginalFilename", __FILENAME + VALUE "ProductName", __DESCRIPTION + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/plugins/Dbx_mmap_SA/Dbtool/res/dbtool.exe.manifest b/plugins/Dbx_mmap_SA/Dbtool/res/dbtool.exe.manifest new file mode 100644 index 0000000000..1b6aab686b --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/res/dbtool.exe.manifest @@ -0,0 +1,31 @@ + + + +Miranda + + + + + + + + + + + + + diff --git a/plugins/Dbx_mmap_SA/Dbtool/res/resource.rc b/plugins/Dbx_mmap_SA/Dbtool/res/resource.rc new file mode 100644 index 0000000000..25710d5ca8 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/res/resource.rc @@ -0,0 +1,368 @@ +// Microsoft Visual C++ generated resource script. +// +#include "..\src\resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Neutral resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +IDB_BITMAP1 BITMAP "dbtool.bmp" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_LOGIN DIALOGEX 0, 0, 182, 78 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW +CAPTION "Miranda MMAP Secured Database" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "OK",IDOK,33,59,54,14 + PUSHBUTTON "Cancel",IDCANCEL,91,59,54,14 + CTEXT "Please enter password for",IDC_LOGININFO,6,4,169,8 + CTEXT "",IDC_DBNAME,5,14,169,8 + EDITTEXT IDC_USERPASS,15,33,132,14,ES_PASSWORD | ES_AUTOHSCROLL + CTEXT "EN",IDC_LANG,155,32,16,14,SS_CENTERIMAGE + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,26,181,1 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,53,181,1 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_LOGIN, DIALOG + BEGIN + LEFTMARGIN, 6 + RIGHTMARGIN, 175 + TOPMARGIN, 7 + BOTTOMMARGIN, 73 + HORZGUIDE, 68 + END +END +#endif // APSTUDIO_INVOKED + +#endif // Russian resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// RT_MANIFEST +// + +1 RT_MANIFEST "dbtool.exe.manifest" +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// English (U.K.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK +#pragma code_page(1252) +#endif //_WIN32 + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_WELCOME DIALOGEX 0, 0, 262, 143 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_DISABLED +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + CONTROL IDI_PROFILEYELLOW,IDC_WATERMARK,"Static",SS_BITMAP,0,0,63,143 + LTEXT "whiterect",IDC_STATIC,63,0,199,143 + LTEXT "Welcome to the Miranda Database Wizard",IDC_TITLE,77,12,178,24,0,WS_EX_TRANSPARENT + LTEXT "Using this Wizard you can compact your Miranda profile database to remove dead space created during normal usage, as well as repair a large number of issues that could affect the database.",IDC_STATIC,77,46,178,32,0,WS_EX_TRANSPARENT + LTEXT "To continue, click Next.",IDC_STATIC,77,85,178,8,0,WS_EX_TRANSPARENT + LTEXT "This programme is licenced under the terms of the GNU General Public License.",IDC_STATIC,77,122,178,16,WS_DISABLED +END + +IDD_WIZARD DIALOGEX 0, 0, 262, 174 +STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +CAPTION "Miranda Database Tool" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + PUSHBUTTON "< &Back",IDC_BACK,96,153,50,14 + DEFPUSHBUTTON "&Next >",IDOK,146,153,50,14 + PUSHBUTTON "Cancel",IDCANCEL,205,153,50,14 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-5,143,269,1 +END + +IDD_SELECTDB DIALOGEX 0, 0, 262, 143 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "whiterect",IDC_STATIC,2,0,259,32 + LTEXT "Select Miranda Profile",IDC_STATIC,11,6,206,8,WS_BORDER + ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 + LTEXT "You can choose the Miranda profile database to compact or repair.",IDC_STATIC,20,14,220,16 + LTEXT "Select the &profile database from the list below. If the database you wish to use is not listed here then click Other to browse your computer.",IDC_STATIC,10,35,242,16 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 + CONTROL "List1",IDC_DBLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,10,53,242,72 + LTEXT "&File:",IDC_STATIC,10,130,20,8 + EDITTEXT IDC_FILE,32,128,176,12,ES_AUTOHSCROLL + PUSHBUTTON "&Other...",IDC_OTHER,212,128,40,12 +END + +IDD_OPENERROR DIALOGEX 0, 0, 262, 143 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "whiterect",IDC_STATIC,0,0,261,32 + LTEXT "Error Opening Database",IDC_STATIC,11,6,206,8,WS_BORDER + ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 + LTEXT "There was an error opening the profile database given.",IDC_STATIC,20,14,197,16 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 + LTEXT "",IDC_ERRORTEXT,23,38,226,16,SS_NOPREFIX | WS_BORDER + LTEXT "Click Next to try opening the file again, or click Back to select a new profile database to manipulate.",IDC_STATIC,23,67,226,16 + LTEXT "The file may be in use by a currently running copy of Miranda. Exit any running Mirandas and click Next to retry.",IDC_INUSE,23,87,226,16,NOT WS_VISIBLE + LTEXT "",IDC_FILE,23,57,226,8,SS_NOPREFIX +END + +IDD_FILEACCESS DIALOGEX 0, 0, 262, 143 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "whiterect",IDC_STATIC,0,0,261,32 + LTEXT "File Access Options",IDC_STATIC,11,6,206,8,WS_BORDER + ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 + LTEXT "You can select low level options to determine how the database is processed.",IDC_STATIC,20,14,197,16 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 + CONTROL "Create backup",IDC_BACKUP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,69,226,10,WS_EX_CLIENTEDGE + LTEXT "Creates a backup copy of the database before any of the requested changes are made.",IDC_STBACKUP,37,80,212,16 + CONTROL "Aggressively find corruption",IDC_AGGRESSIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,100,226,10,WS_EX_CLIENTEDGE + LTEXT "Scans the database for data that is not linked to any other data. This requires more disk space and more time, so is only required if you suspect corruption.",IDC_STATIC,37,111,212,24 + CONTROL "Check consistency only",IDC_CHECKONLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,38,226,10,WS_EX_CLIENTEDGE + LTEXT "Just checks that the database is valid, without writing anything to the disk.",IDC_STATIC,37,49,212,16 +END + +IDD_CLEANING DIALOGEX 0, 0, 262, 143 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "whiterect",IDC_STATIC,0,0,261,32 + LTEXT "Cleaning Options",IDC_STATIC,11,6,206,8,WS_BORDER + ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 + LTEXT "You can choose to remove information from the database while it is being processed.",IDC_STATIC,20,14,220,16 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 + CONTROL "Erase all histories",IDC_ERASEHISTORY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,38,226,10,WS_EX_CLIENTEDGE + LTEXT "Removes all the saved history for all contacts in the database.",IDC_STATIC,37,49,212,8 + CONTROL "Mark all events read",IDC_MARKREAD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,62,226,10,WS_EX_CLIENTEDGE + LTEXT "Marks all the history events as read. This will rectify any problems with old messages always appearing in the message window log box.",IDC_STATIC,37,73,212,24 + CONTROL "Convert old Unicode messages to UTF8",IDC_CONVERTUTF, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,101,226,10,WS_EX_CLIENTEDGE + LTEXT "Converts history messages in pre-0.7 format (ANSI+UCS2) to the new UTF8 format supported by 0.7. Saves the database space in most cases (recommended).",IDC_STATIC,37,111,212,25 +END + +IDD_PROGRESS DIALOGEX 0, 0, 262, 143 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "whiterect",-1,0,0,261,32 + LTEXT "Working...",-1,11,6,206,8,WS_BORDER + ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 + LTEXT "Please wait while the requested operations are being performed.",-1,20,14,197,16 + CONTROL "",-1,"Static",SS_ETCHEDHORZ,-1,32,264,1 + CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,20,38,222,11 + LISTBOX IDC_STATUS,20,52,222,84,NOT LBS_NOTIFY | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | LBS_NOSEL | WS_VSCROLL | WS_TABSTOP +END + +IDD_FINISHED DIALOGEX 0, 0, 262, 143 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "whiterect",IDC_STATIC,0,0,262,32 + LTEXT "Finished!",IDC_STATIC,11,6,206,8,WS_BORDER + ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 + LTEXT "All tasks have been completed.",IDC_STATIC,20,14,197,16 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 + CONTROL "Launch Miranda with this profile",IDC_LAUNCHMIRANDA, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,87,239,10,WS_EX_CLIENTEDGE + LTEXT "Launches Miranda with the profile that was just worked on.",IDC_STATIC,37,98,225,8 + LTEXT "",IDC_DBFILE,23,68,239,8,SS_NOPREFIX | WS_BORDER + RTEXT "Backup:",IDC_STBACKUP,23,76,30,8 + LTEXT "",IDC_BACKUPFILE,69,76,193,8,SS_NOPREFIX + LTEXT "The processing of the database has been completed. Click Next to return to the start of the wizard to select another database to check, or click Finish to exit the wizard.",IDC_STATIC,23,38,220,24 +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_WELCOME, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 255 + VERTGUIDE, 77 + TOPMARGIN, 5 + BOTTOMMARGIN, 138 + END + + IDD_WIZARD, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 255 + TOPMARGIN, 7 + BOTTOMMARGIN, 167 + END + + IDD_SELECTDB, DIALOG + BEGIN + LEFTMARGIN, 23 + RIGHTMARGIN, 249 + TOPMARGIN, 38 + BOTTOMMARGIN, 136 + END + + IDD_OPENERROR, DIALOG + BEGIN + LEFTMARGIN, 23 + RIGHTMARGIN, 249 + TOPMARGIN, 38 + BOTTOMMARGIN, 136 + END + + IDD_FILEACCESS, DIALOG + BEGIN + LEFTMARGIN, 23 + RIGHTMARGIN, 249 + VERTGUIDE, 37 + TOPMARGIN, 38 + BOTTOMMARGIN, 136 + END + + IDD_CLEANING, DIALOG + BEGIN + LEFTMARGIN, 23 + RIGHTMARGIN, 249 + VERTGUIDE, 37 + TOPMARGIN, 38 + BOTTOMMARGIN, 136 + END + + IDD_PROGRESS, DIALOG + BEGIN + LEFTMARGIN, 20 + RIGHTMARGIN, 242 + TOPMARGIN, 38 + BOTTOMMARGIN, 136 + END + + IDD_FINISHED, DIALOG + BEGIN + LEFTMARGIN, 23 + VERTGUIDE, 37 + TOPMARGIN, 38 + BOTTOMMARGIN, 136 + END +END +#endif // APSTUDIO_INVOKED + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "..\\src\\resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include \r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_DBTOOL ICON "dbtool.ico" +IDI_PROFILEGREEN ICON "profileg.ico" +IDI_PROFILEYELLOW ICON "profiley.ico" +IDI_PROFILERED ICON "profiler.ico" +IDI_BAD ICON "delete.ico" + +#endif // Neutral resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/plugins/Dbx_mmap_SA/Dbtool/resource.h b/plugins/Dbx_mmap_SA/Dbtool/resource.h deleted file mode 100644 index f92176c33f..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/resource.h +++ /dev/null @@ -1,58 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by resource.rc -// -#define IDC_BACK 3 -#define IDD_WIZARD 101 -#define IDI_DBTOOL 102 -#define IDI_PROFILEGREEN 104 -#define IDR_DEFAULT1 104 -#define IDI_PROFILEYELLOW 105 -#define IDB_BITMAP1 105 -#define IDD_WELCOME 106 -#define IDI_PROFILERED 106 -#define IDD_SELECTDB 107 -#define IDD_OPENERROR 108 -#define IDD_FILEACCESS 109 -#define IDD_CLEANING 110 -#define IDD_PROGRESS 111 -#define IDD_FINISHED 112 -#define IDI_BAD 113 -#define IDD_LOGIN 113 -#define IDC_WATERMARK 1000 -#define IDC_TITLE 1001 -#define IDC_HDRLOGO 1002 -#define IDC_DBLIST 1003 -#define IDC_FILE 1004 -#define IDC_OTHER 1005 -#define IDC_ERRORTEXT 1006 -#define IDC_INUSE 1007 -#define IDC_BACKUP 1008 -#define IDC_AGGRESSIVE 1009 -#define IDC_ERASEHISTORY 1010 -#define IDC_CHECKONLY 1010 -#define IDC_MARKREAD 1011 -#define IDC_PROGRESS 1011 -#define IDC_STATUS 1012 -#define IDC_STBACKUP 1013 -#define IDC_LAUNCHMIRANDA 1015 -#define IDC_DBFILE 1016 -#define IDC_BACKUPFILE 1017 -#define IDC_CHECK1 1018 -#define IDC_CONVERTUTF 1018 -#define IDC_DBNAME 1019 -#define IDC_USERPASS 1021 -#define IDC_LANG 1022 -#define IDC_LOGININFO 1023 -#define IDC_STATIC -1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 114 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1024 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/Dbx_mmap_SA/Dbtool/resource.rc b/plugins/Dbx_mmap_SA/Dbtool/resource.rc deleted file mode 100644 index 7aa4cba249..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/resource.rc +++ /dev/null @@ -1,368 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Neutral resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU) -#ifdef _WIN32 -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Bitmap -// - -IDB_BITMAP1 BITMAP "res\\dbtool.bmp" - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_LOGIN DIALOGEX 0, 0, 182, 78 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW -CAPTION "Miranda MMAP Secured Database" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - DEFPUSHBUTTON "OK",IDOK,33,59,54,14 - PUSHBUTTON "Cancel",IDCANCEL,91,59,54,14 - CTEXT "Please enter password for",IDC_LOGININFO,6,4,169,8 - CTEXT "",IDC_DBNAME,5,14,169,8 - EDITTEXT IDC_USERPASS,15,33,132,14,ES_PASSWORD | ES_AUTOHSCROLL - CTEXT "EN",IDC_LANG,155,32,16,14,SS_CENTERIMAGE - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,26,181,1 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,53,181,1 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_LOGIN, DIALOG - BEGIN - LEFTMARGIN, 6 - RIGHTMARGIN, 175 - TOPMARGIN, 7 - BOTTOMMARGIN, 73 - HORZGUIDE, 68 - END -END -#endif // APSTUDIO_INVOKED - -#endif // Russian resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// RT_MANIFEST -// - -1 RT_MANIFEST "dbtool.exe.manifest" -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// English (U.K.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_WELCOME DIALOGEX 0, 0, 262, 143 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_DISABLED -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - CONTROL IDI_PROFILEYELLOW,IDC_WATERMARK,"Static",SS_BITMAP,0,0,63,143 - LTEXT "whiterect",IDC_STATIC,63,0,199,143 - LTEXT "Welcome to the Miranda Database Wizard",IDC_TITLE,77,12,178,24,0,WS_EX_TRANSPARENT - LTEXT "Using this Wizard you can compact your Miranda profile database to remove dead space created during normal usage, as well as repair a large number of issues that could affect the database.",IDC_STATIC,77,46,178,32,0,WS_EX_TRANSPARENT - LTEXT "To continue, click Next.",IDC_STATIC,77,85,178,8,0,WS_EX_TRANSPARENT - LTEXT "This programme is licenced under the terms of the GNU General Public License.",IDC_STATIC,77,122,178,16,WS_DISABLED -END - -IDD_WIZARD DIALOGEX 0, 0, 262, 174 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT -CAPTION "Miranda Database Tool" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - PUSHBUTTON "< &Back",IDC_BACK,96,153,50,14 - DEFPUSHBUTTON "&Next >",IDOK,146,153,50,14 - PUSHBUTTON "Cancel",IDCANCEL,205,153,50,14 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-5,143,269,1 -END - -IDD_SELECTDB DIALOGEX 0, 0, 262, 143 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "whiterect",IDC_STATIC,2,0,259,32 - LTEXT "Select Miranda Profile",IDC_STATIC,11,6,206,8,WS_BORDER - ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 - LTEXT "You can choose the Miranda profile database to compact or repair.",IDC_STATIC,20,14,220,16 - LTEXT "Select the &profile database from the list below. If the database you wish to use is not listed here then click Other to browse your computer.",IDC_STATIC,10,35,242,16 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 - CONTROL "List1",IDC_DBLIST,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,10,53,242,72 - LTEXT "&File:",IDC_STATIC,10,130,20,8 - EDITTEXT IDC_FILE,32,128,176,12,ES_AUTOHSCROLL - PUSHBUTTON "&Other...",IDC_OTHER,212,128,40,12 -END - -IDD_OPENERROR DIALOGEX 0, 0, 262, 143 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "whiterect",IDC_STATIC,0,0,261,32 - LTEXT "Error Opening Database",IDC_STATIC,11,6,206,8,WS_BORDER - ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 - LTEXT "There was an error opening the profile database given.",IDC_STATIC,20,14,197,16 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 - LTEXT "",IDC_ERRORTEXT,23,38,226,16,SS_NOPREFIX | WS_BORDER - LTEXT "Click Next to try opening the file again, or click Back to select a new profile database to manipulate.",IDC_STATIC,23,67,226,16 - LTEXT "The file may be in use by a currently running copy of Miranda. Exit any running Mirandas and click Next to retry.",IDC_INUSE,23,87,226,16,NOT WS_VISIBLE - LTEXT "",IDC_FILE,23,57,226,8,SS_NOPREFIX -END - -IDD_FILEACCESS DIALOGEX 0, 0, 262, 143 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "whiterect",IDC_STATIC,0,0,261,32 - LTEXT "File Access Options",IDC_STATIC,11,6,206,8,WS_BORDER - ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 - LTEXT "You can select low level options to determine how the database is processed.",IDC_STATIC,20,14,197,16 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 - CONTROL "Create backup",IDC_BACKUP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,69,226,10,WS_EX_CLIENTEDGE - LTEXT "Creates a backup copy of the database before any of the requested changes are made.",IDC_STBACKUP,37,80,212,16 - CONTROL "Aggressively find corruption",IDC_AGGRESSIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,100,226,10,WS_EX_CLIENTEDGE - LTEXT "Scans the database for data that is not linked to any other data. This requires more disk space and more time, so is only required if you suspect corruption.",IDC_STATIC,37,111,212,24 - CONTROL "Check consistency only",IDC_CHECKONLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,38,226,10,WS_EX_CLIENTEDGE - LTEXT "Just checks that the database is valid, without writing anything to the disk.",IDC_STATIC,37,49,212,16 -END - -IDD_CLEANING DIALOGEX 0, 0, 262, 143 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "whiterect",IDC_STATIC,0,0,261,32 - LTEXT "Cleaning Options",IDC_STATIC,11,6,206,8,WS_BORDER - ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 - LTEXT "You can choose to remove information from the database while it is being processed.",IDC_STATIC,20,14,220,16 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 - CONTROL "Erase all histories",IDC_ERASEHISTORY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,38,226,10,WS_EX_CLIENTEDGE - LTEXT "Removes all the saved history for all contacts in the database.",IDC_STATIC,37,49,212,8 - CONTROL "Mark all events read",IDC_MARKREAD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,62,226,10,WS_EX_CLIENTEDGE - LTEXT "Marks all the history events as read. This will rectify any problems with old messages always appearing in the message window log box.",IDC_STATIC,37,73,212,24 - CONTROL "Convert old Unicode messages to UTF8",IDC_CONVERTUTF, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,101,226,10,WS_EX_CLIENTEDGE - LTEXT "Converts history messages in pre-0.7 format (ANSI+UCS2) to the new UTF8 format supported by 0.7. Saves the database space in most cases (recommended).",IDC_STATIC,37,111,212,25 -END - -IDD_PROGRESS DIALOGEX 0, 0, 262, 143 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "whiterect",-1,0,0,261,32 - LTEXT "Working...",-1,11,6,206,8,WS_BORDER - ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 - LTEXT "Please wait while the requested operations are being performed.",-1,20,14,197,16 - CONTROL "",-1,"Static",SS_ETCHEDHORZ,-1,32,264,1 - CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,20,38,222,11 - LISTBOX IDC_STATUS,20,52,222,84,NOT LBS_NOTIFY | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | LBS_NOSEL | WS_VSCROLL | WS_TABSTOP -END - -IDD_FINISHED DIALOGEX 0, 0, 262, 143 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "whiterect",IDC_STATIC,0,0,262,32 - LTEXT "Finished!",IDC_STATIC,11,6,206,8,WS_BORDER - ICON IDI_DBTOOL,IDC_HDRLOGO,234,3,20,20 - LTEXT "All tasks have been completed.",IDC_STATIC,20,14,197,16 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-1,32,264,1 - CONTROL "Launch Miranda with this profile",IDC_LAUNCHMIRANDA, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,87,239,10,WS_EX_CLIENTEDGE - LTEXT "Launches Miranda with the profile that was just worked on.",IDC_STATIC,37,98,225,8 - LTEXT "",IDC_DBFILE,23,68,239,8,SS_NOPREFIX | WS_BORDER - RTEXT "Backup:",IDC_STBACKUP,23,76,30,8 - LTEXT "",IDC_BACKUPFILE,69,76,193,8,SS_NOPREFIX - LTEXT "The processing of the database has been completed. Click Next to return to the start of the wizard to select another database to check, or click Finish to exit the wizard.",IDC_STATIC,23,38,220,24 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_WELCOME, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 255 - VERTGUIDE, 77 - TOPMARGIN, 5 - BOTTOMMARGIN, 138 - END - - IDD_WIZARD, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 255 - TOPMARGIN, 7 - BOTTOMMARGIN, 167 - END - - IDD_SELECTDB, DIALOG - BEGIN - LEFTMARGIN, 23 - RIGHTMARGIN, 249 - TOPMARGIN, 38 - BOTTOMMARGIN, 136 - END - - IDD_OPENERROR, DIALOG - BEGIN - LEFTMARGIN, 23 - RIGHTMARGIN, 249 - TOPMARGIN, 38 - BOTTOMMARGIN, 136 - END - - IDD_FILEACCESS, DIALOG - BEGIN - LEFTMARGIN, 23 - RIGHTMARGIN, 249 - VERTGUIDE, 37 - TOPMARGIN, 38 - BOTTOMMARGIN, 136 - END - - IDD_CLEANING, DIALOG - BEGIN - LEFTMARGIN, 23 - RIGHTMARGIN, 249 - VERTGUIDE, 37 - TOPMARGIN, 38 - BOTTOMMARGIN, 136 - END - - IDD_PROGRESS, DIALOG - BEGIN - LEFTMARGIN, 20 - RIGHTMARGIN, 242 - TOPMARGIN, 38 - BOTTOMMARGIN, 136 - END - - IDD_FINISHED, DIALOG - BEGIN - LEFTMARGIN, 23 - VERTGUIDE, 37 - TOPMARGIN, 38 - BOTTOMMARGIN, 136 - END -END -#endif // APSTUDIO_INVOKED - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include \r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_DBTOOL ICON "res\\dbtool.ico" -IDI_PROFILEGREEN ICON "res\\profileg.ico" -IDI_PROFILEYELLOW ICON "res\\profiley.ico" -IDI_PROFILERED ICON "res\\profiler.ico" -IDI_BAD ICON "res\\delete.ico" - -#endif // Neutral resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp b/plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp deleted file mode 100644 index 9db3517816..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -void GetProfileDirectory(TCHAR* szMirandaDir, TCHAR* szPath, int cbPath) -{ - TCHAR szProfileDir[MAX_PATH], szExpandedProfileDir[MAX_PATH], szMirandaBootIni[MAX_PATH]; - - lstrcpy(szMirandaBootIni,szMirandaDir); - lstrcat(szMirandaBootIni,_T("\\mirandaboot.ini")); - GetPrivateProfileString(_T("Database"),_T("ProfileDir"),_T("./Profiles"),szProfileDir,SIZEOF(szProfileDir),szMirandaBootIni); - ExpandEnvironmentStrings(szProfileDir,szExpandedProfileDir,SIZEOF(szExpandedProfileDir)); - _tchdir(szMirandaDir); - if (!_tfullpath(szPath,szExpandedProfileDir,cbPath)) - lstrcpyn(szPath,szMirandaDir,cbPath); - if(szPath[lstrlen(szPath)-1]=='\\') - szPath[lstrlen(szPath)-1] = 0; -} - -static int AddDatabaseToList(HWND hwndList, TCHAR* filename, TCHAR* dir) -{ - LV_ITEM lvi; - int iNewItem; - TCHAR szSize[20], *pName, *pDot, szName[MAX_PATH]; - HANDLE hDbFile; - DBHeader dbhdr; - DWORD bytesRead; - DWORD totalSize,wasted=0; - int broken=0; - - lvi.mask=LVIF_PARAM; - lvi.iSubItem=0; - for(lvi.iItem=ListView_GetItemCount(hwndList)-1;lvi.iItem>=0;lvi.iItem--) { - ListView_GetItem(hwndList,&lvi); - if ( !_tcsicmp(( TCHAR* )lvi.lParam,filename)) return lvi.iItem; - } - hDbFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); - if ( hDbFile == INVALID_HANDLE_VALUE ) - return -1; - - ReadFile(hDbFile,&dbhdr,sizeof(dbhdr),&bytesRead,NULL); - totalSize=GetFileSize(hDbFile,NULL); - - broken = (bytesReaddbhdr.ofsFileEnd) - wasted+=totalSize-dbhdr.ofsFileEnd; - } - CloseHandle(hDbFile); - - pName = _tcsrchr(filename,'\\'); - if ( pName == NULL ) - pName = ( LPTSTR )filename; - else - pName++; - _tcscpy(szName,dir); - _tcscat(szName,pName); - pDot = _tcsrchr( szName, '.' ); - if ( pDot != NULL && !_tcsicmp( pDot, _T(".dat"))) - *pDot=0; - - lvi.iItem = 0; - lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; - lvi.iSubItem = 0; - lvi.lParam = ( LPARAM )_tcsdup(filename); - lvi.pszText = szName; - if (broken) - lvi.iImage = 3; - else if ( wasted < 1024*128 ) - lvi.iImage = 0; - else if ( wasted < 1024*256 + (DWORD)(totalSize > 2*1024*1024 ) ? 256 * 1024 : 0 ) - lvi.iImage=1; - else - lvi.iImage=2; - - iNewItem = ListView_InsertItem(hwndList, &lvi ); - _stprintf(szSize,_T("%.2lf MB"),totalSize/1048576.0); - ListView_SetItemText(hwndList,iNewItem,1,szSize); - if ( !broken ) { - _stprintf(szSize,_T("%.2lf MB"),wasted/1048576.0); - ListView_SetItemText(hwndList,iNewItem,2,szSize); - } - return iNewItem; -} - -void FindAdd(HWND hdlg, TCHAR *szProfileDir, TCHAR *szPrefix) -{ - HANDLE hFind; - WIN32_FIND_DATA fd; - TCHAR szSearchPath[MAX_PATH],szFilename[MAX_PATH]; - - lstrcpy(szSearchPath,szProfileDir); - lstrcat(szSearchPath,_T("\\*.*")); - - hFind=FindFirstFile(szSearchPath,&fd); - if (hFind!=INVALID_HANDLE_VALUE) { - do { - if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && _tcscmp(fd.cFileName, _T(".")) && _tcscmp(fd.cFileName, _T(".."))) { - wsprintf(szFilename,_T("%s\\%s\\%s.dat"),szProfileDir,fd.cFileName,fd.cFileName); - if (_taccess(szFilename, 0) == 0) - AddDatabaseToList(GetDlgItem(hdlg,IDC_DBLIST),szFilename,szPrefix); - } - } while(FindNextFile(hFind,&fd)); - FindClose(hFind); - } -} - -TCHAR *addstring(TCHAR *str, TCHAR *add) { - _tcscpy(str,add); - return str + _tcslen(add) + 1; -} - -INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - INT_PTR bReturn; - if ( DoMyControlProcessing( hdlg, message, wParam, lParam, &bReturn )) - return bReturn; - - switch ( message ) { - case WM_INITDIALOG: - { - TCHAR szMirandaPath[MAX_PATH]; - szMirandaPath[ 0 ] = 0; - { HIMAGELIST hIml; - hIml=ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), - (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 3, 3); - ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILEGREEN))); - ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILEYELLOW))); - ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILERED))); - ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_BAD))); - ListView_SetImageList(GetDlgItem(hdlg,IDC_DBLIST),hIml,LVSIL_SMALL); - } - ListView_SetExtendedListViewStyleEx(GetDlgItem(hdlg,IDC_DBLIST),LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT); - { LV_COLUMN lvc; - lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT; - lvc.cx = 205; - lvc.fmt = LVCFMT_LEFT; - lvc.pszText = TranslateT("Database"); - ListView_InsertColumn( GetDlgItem(hdlg,IDC_DBLIST), 0, &lvc ); - lvc.cx = 68; - lvc.fmt = LVCFMT_RIGHT; - lvc.pszText = TranslateT("Total size"); - ListView_InsertColumn(GetDlgItem(hdlg,IDC_DBLIST), 1, &lvc ); - lvc.pszText = TranslateT("Wasted"); - ListView_InsertColumn(GetDlgItem(hdlg,IDC_DBLIST), 2, &lvc ); - } - { - TCHAR *str2; - GetModuleFileName(NULL,szMirandaPath,SIZEOF(szMirandaPath)); - str2 = _tcsrchr(szMirandaPath,'\\'); - if ( str2 != NULL ) - *str2=0; - } - { - int i = 0; - HKEY hKey; - TCHAR szProfileDir[MAX_PATH]; - DWORD cbData = SIZEOF(szMirandaPath); - TCHAR szMirandaProfiles[MAX_PATH]; - - _tcscpy(szMirandaProfiles, szMirandaPath); - _tcscat(szMirandaProfiles, _T("\\Profiles")); - GetProfileDirectory(szMirandaPath,szProfileDir,SIZEOF(szProfileDir)); - - // search in profile dir (using ini file) - if ( lstrcmpi(szProfileDir,szMirandaProfiles)) - FindAdd(hdlg, szProfileDir, _T("[ini]\\")); - - FindAdd(hdlg, szMirandaProfiles, _T("[prf]\\")); - // search in current dir (as DBTOOL) - FindAdd(hdlg, szMirandaPath, _T("[ . ]\\")); - - // search in profile dir (using registry path + ini file) - if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\miranda32.exe"),0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) { - if(RegQueryValueEx(hKey,_T("Path"),NULL,NULL,(PBYTE)szMirandaPath,&cbData) == ERROR_SUCCESS) { - if ( lstrcmp(szProfileDir,szMirandaPath)) { - GetProfileDirectory(szMirandaPath,szProfileDir,SIZEOF(szProfileDir)); - FindAdd(hdlg, szProfileDir, _T("[reg]\\")); - } - } - RegCloseKey(hKey); - } - // select - if ( opts.filename[0] ) - i = AddDatabaseToList( GetDlgItem( hdlg, IDC_DBLIST ), opts.filename, _T("")); - if ( i == -1 ) - i = 0; - ListView_SetItemState( GetDlgItem(hdlg,IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED ); - } - if ( opts.hFile != NULL && opts.hFile != INVALID_HANDLE_VALUE ) { - CloseHandle( opts.hFile ); - opts.hFile = NULL; - } - TranslateDialogDefault( hdlg ); - return TRUE; - } - - case WZN_PAGECHANGING: - GetDlgItemText( hdlg, IDC_FILE, opts.filename, SIZEOF(opts.filename)); - break; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_FILE: - if(HIWORD(wParam)==EN_CHANGE) - EnableWindow(GetDlgItem(GetParent(hdlg),IDOK),GetWindowTextLength(GetDlgItem(hdlg,IDC_FILE))); - break; - case IDC_OTHER: - { OPENFILENAME ofn={0}; - TCHAR str[MAX_PATH]; - - // _T("Miranda Databases (*.dat)\0*.DAT\0All Files (*)\0*\0"); - TCHAR *filter, *tmp, *tmp1, *tmp2; - tmp1 = TranslateT("Miranda Databases (*.dat)"); - tmp2 = TranslateT("All Files"); - filter = tmp = (TCHAR*)_alloca((_tcslen(tmp1)+_tcslen(tmp2)+11)*sizeof(TCHAR)); - tmp = addstring(tmp, tmp1); - tmp = addstring(tmp, _T("*.DAT")); - tmp = addstring(tmp, tmp2); - tmp = addstring(tmp, _T("*")); - *tmp = 0; - - GetDlgItemText( hdlg, IDC_FILE, str, SIZEOF( str )); - ofn.lStructSize = sizeof(ofn); - ofn.hwndOwner = hdlg; - ofn.hInstance = NULL; - ofn.lpstrFilter = filter; - ofn.lpstrDefExt = _T("dat"); - ofn.lpstrFile = str; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - ofn.nMaxFile = SIZEOF(str); - ofn.nMaxFileTitle = MAX_PATH; - if ( GetOpenFileName( &ofn )) { - int i; - i = AddDatabaseToList( GetDlgItem(hdlg,IDC_DBLIST), str, _T("")); - if ( i == -1 ) - i=0; - ListView_SetItemState( GetDlgItem(hdlg,IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED ); - } - break; - } - case IDC_BACK: - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_WELCOME,(LPARAM)WelcomeDlgProc); - break; - case IDOK: - opts.hFile = CreateFile( opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); - if ( opts.hFile == INVALID_HANDLE_VALUE ) { - opts.hFile = NULL; - opts.error = GetLastError(); - SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, ( LPARAM )OpenErrorDlgProc ); - } - else SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc ); - break; - } - break; - case WM_NOTIFY: - switch(((LPNMHDR)lParam)->idFrom) { - case IDC_DBLIST: - switch(((LPNMLISTVIEW)lParam)->hdr.code) { - case LVN_ITEMCHANGED: - { LV_ITEM lvi; - lvi.iItem=ListView_GetNextItem(GetDlgItem(hdlg,IDC_DBLIST),-1,LVNI_SELECTED); - if(lvi.iItem==-1) break; - lvi.mask=LVIF_PARAM; - ListView_GetItem(GetDlgItem(hdlg,IDC_DBLIST),&lvi); - SetDlgItemText(hdlg,IDC_FILE,(TCHAR*)lvi.lParam); - SendMessage(hdlg,WM_COMMAND,MAKEWPARAM(IDC_FILE,EN_CHANGE),(LPARAM)GetDlgItem(hdlg,IDC_FILE)); - break; - } - } - break; - } - break; - case WM_DESTROY: - { LV_ITEM lvi; - lvi.mask=LVIF_PARAM; - for(lvi.iItem=ListView_GetItemCount(GetDlgItem(hdlg,IDC_DBLIST))-1;lvi.iItem>=0;lvi.iItem--) { - ListView_GetItem(GetDlgItem(hdlg,IDC_DBLIST),&lvi); - free((char*)lvi.lParam); - } - } - break; - } - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/settingschain.cpp b/plugins/Dbx_mmap_SA/Dbtool/settingschain.cpp deleted file mode 100644 index a6e7ecab3b..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/settingschain.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -static DWORD ofsThisSettings,ofsDestPrevSettings; - -int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime) -{ - DBContactSettings *dbcsNew,dbcsOld; - DWORD ofsDestThis; - int ret; - - if(firstTime) { - ofsDestPrevSettings=0; - ofsThisSettings=dbc->ofsFirstSettings; - dbc->ofsFirstSettings=0; - } - if(ofsThisSettings==0) - return ERROR_NO_MORE_ITEMS; - if (!SignatureValid(ofsThisSettings,DBCONTACTSETTINGS_SIGNATURE)) { - AddToStatus(STATUS_ERROR,TranslateT("Settings chain corrupted, further entries ignored")); - return ERROR_NO_MORE_ITEMS; - } - if(PeekSegment(ofsThisSettings,&dbcsOld,sizeof(dbcsOld))!=ERROR_SUCCESS) - return ERROR_NO_MORE_ITEMS; - if(dbcsOld.cbBlob>256*1024 || dbcsOld.cbBlob==0) { - AddToStatus(STATUS_ERROR,TranslateT("Infeasibly large settings blob: skipping")); - ofsThisSettings=dbcsOld.ofsNext; - return ERROR_SUCCESS; - } - dbcsNew=(DBContactSettings*)_alloca(offsetof(DBContactSettings,blob)+dbcsOld.cbBlob); - if ((ret=ReadSegment(ofsThisSettings,dbcsNew,offsetof(DBContactSettings,blob)+dbcsOld.cbBlob))!=ERROR_SUCCESS) { - if(ret!=ERROR_HANDLE_EOF) { //eof is OK because blank space at the end doesn't matter - return ERROR_NO_MORE_ITEMS; - } - } - if ((dbcsNew->ofsModuleName=ConvertModuleNameOfs(dbcsOld.ofsModuleName))==0) { - ofsThisSettings=dbcsOld.ofsNext; - return ERROR_SUCCESS; - } - if(dbcsNew->blob[0]==0) { - AddToStatus(STATUS_MESSAGE,TranslateT("Empty settings group at %08X: skipping"),ofsThisSettings); - ofsThisSettings=dbcsOld.ofsNext; - return ERROR_SUCCESS; - } - dbcsNew->ofsNext=0; - //TODO? validate all settings in blob/compact if necessary - if ((ofsDestThis=WriteSegment(WSOFS_END,dbcsNew,offsetof(DBContactSettings,blob)+dbcsNew->cbBlob))==WS_ERROR) { - return ERROR_HANDLE_DISK_FULL; - } - if(ofsDestPrevSettings) WriteSegment(ofsDestPrevSettings+offsetof(DBContactSettings,ofsNext),&ofsDestThis,sizeof(DWORD)); - else dbc->ofsFirstSettings=ofsDestThis; - ofsDestPrevSettings=ofsDestThis; - ofsThisSettings=dbcsOld.ofsNext; - return ERROR_SUCCESS; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/Version.h b/plugins/Dbx_mmap_SA/Dbtool/src/Version.h new file mode 100644 index 0000000000..1ee2b8a4cf --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/Version.h @@ -0,0 +1,9 @@ +#include "m_version.h" + +#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION +#define __VERSION_STRING MIRANDA_VERSION_STRING +#define __VERSION_DWORD MIRANDA_VERSION_DWORD +#define __INTERNAL_NAME "dbtool" +#define __FILENAME "dbtool.exe" +#define __DESCRIPTION "Miranda IM Database Tool" +#define __COPYRIGHT "© 2000-2011 Miranda IM project" diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/aggressive.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/aggressive.cpp new file mode 100644 index 0000000000..5ec62707f1 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/aggressive.cpp @@ -0,0 +1,59 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +#define BLOCKSIZE 65536 + +extern DWORD sourceFileSize; +extern DWORD spaceProcessed; +extern DWORD sp; +static DWORD ofsCurrent; + +int WorkAggressive(int firstTime) +{ + int blockBytes,i; + BYTE *buf; + + if(firstTime) { + if (!opts.bAggressive) return ERROR_NO_MORE_ITEMS; + AddToStatus(STATUS_MESSAGE,TranslateT("Performing aggressive pass")); + ofsCurrent=0; + spaceProcessed=0; + sp=0; + } + blockBytes=min(BLOCKSIZE+3,(int)(sourceFileSize-ofsCurrent)); + if(blockBytes<=0) return ERROR_NO_MORE_ITEMS; + buf = opts.pFile+ofsCurrent; + blockBytes-=3; + for(i=0;iend of file (plain offset) + |-->first contact (DBContact) + | |-->next contact (DBContact) + | | \--> ... + | |-->first settings (DBContactSettings) + | | |-->next settings (DBContactSettings) + | | | \--> ... + | | \-->module name (DBModuleName) + | \-->first/last/firstunread event + |-->user contact (DBContact) + | |-->next contact=NULL + | |-->first settings as above + | \-->first/last/firstunread event as above + \-->first module name (DBModuleName) + \-->next module name (DBModuleName) + \--> ... +*/ + +#define DB_RESIZE_GRANULARITY 16384 +#define DB_THIS_VERSION 0x00000700u +#define DB_SETTINGS_RESIZE_GRANULARITY 128 + +#include +struct DBHeader { + BYTE signature[16]; // 'Miranda ICQ DB',0,26 + + WORD checkWord; + WORD cryptorUID; + DWORD ofsFileEnd; //offset of the end of the database - place to write + //new structures + DWORD slackSpace; //a counter of the number of bytes that have been + //wasted so far due to deleting structures and/or + //re-making them at the end. We should compact when + //this gets above a threshold + DWORD contactCount; //number of contacts in the chain,excluding the user + DWORD ofsFirstContact; //offset to first struct DBContact in the chain + DWORD ofsUser; //offset to struct DBContact representing the user + DWORD ofsFirstModuleName; //offset to first struct DBModuleName in the chain +}; + +#define DBCONTACT_SIGNATURE 0x43DECADEu +struct DBContact { + DWORD signature; + DWORD ofsNext; //offset to the next contact in the chain. zero if + //this is the 'user' contact or the last contact + //in the chain + DWORD ofsFirstSettings; //offset to the first DBContactSettings in the + //chain for this contact. + DWORD eventCount; //number of events in the chain for this contact + DWORD ofsFirstEvent,ofsLastEvent; //offsets to the first and last DBEvent in + //the chain for this contact + DWORD ofsFirstUnreadEvent; //offset to the first (chronological) unread event + //in the chain, 0 if all are read + DWORD timestampFirstUnread; //timestamp of the event at ofsFirstUnreadEvent +}; + +#define DBMODULENAME_SIGNATURE 0x4DDECADEu +struct DBModuleName { + DWORD signature; + DWORD ofsNext; //offset to the next module name in the chain + BYTE cbName; //number of characters in this module name + char name[1]; //name, no nul terminator +}; + +#define DBCONTACTSETTINGS_SIGNATURE 0x53DECADEu +struct DBContactSettings { + DWORD signature; + DWORD ofsNext; //offset to the next contactsettings in the chain + DWORD ofsModuleName; //offset to the DBModuleName of the owner of these + //settings + DWORD cbBlob; //size of the blob in bytes. May be larger than the + //actual size for reducing the number of moves + //required using granularity in resizing + BYTE blob[1]; //the blob. a back-to-back sequence of DBSetting + //structs, the last has cbName=0 +}; + +/* not a valid structure, content is figured out on the fly +struct DBSetting { + BYTE cbName; //number of bytes in the name of this setting + //this =0 marks the end + char szName[...]; //setting name, excluding nul + BYTE dataType; //type of data. see m_database.h, db/contact/getsetting + union { //a load of types of data, length is defined by dataType + BYTE bVal; WORD wVal; DWORD dVal; + struct { + WORD cbString; + char szVal[...]; //excludes nul terminator + }; + struct { + WORD cbBlob; + BYTE blobVal[...]; + }; + }; +}; +*/ + +#define DBEVENT_SIGNATURE 0x45DECADEu +struct DBEvent { + DWORD signature; + DWORD ofsPrev,ofsNext; //offset to the previous and next events in the + //chain. Chain is sorted chronologically + DWORD ofsModuleName; //offset to a DBModuleName struct of the name of + //the owner of this event + DWORD timestamp; //seconds since 00:00:00 01/01/1970 + DWORD flags; //see m_database.h, db/event/add + WORD eventType; //module-defined event type + DWORD cbBlob; //number of bytes in the blob + BYTE blob[1]; //the blob. module-defined formatting +}; +#include + +//databasecorruption: called if any signatures are broken. very very fatal +void DatabaseCorruption(const char *szPart); +PBYTE DBRead(DWORD ofs,int bytesRequired,int *bytesAvail); //any preview result could be invalidated by the next call +void DBWrite(DWORD ofs,PVOID pData,int count); +void DBFlush(int setting); +void DBMoveChunk(DWORD ofsDest,DWORD ofsSource,int bytes); +DWORD CreateNewSpace(int bytes); +void DeleteSpace(DWORD ofs,int bytes); +void GetProfileDirectory(char *szPath,int cbPath); +int GetDefaultProfilePath(char *szPath,int cbPath,int *specified); +int ShouldShowProfileManager(void); + +#ifdef _DEBUG +#define MAXCACHEDREADSIZE 512 +#else +#define MAXCACHEDREADSIZE 2048 //technically 4096 would work, but I'm not going to push it +#endif + +#ifdef _DEBUG +//#define DBLOGGING +#endif +#ifdef DBLOGGING +void DBLog(const char *file,int line,const char *fmt,...); +#define logg() DBLog(__FILE__,__LINE__,"") +#define log0(s) DBLog(__FILE__,__LINE__,s) +#define log1(s,a) DBLog(__FILE__,__LINE__,s,a) +#define log2(s,a,b) DBLog(__FILE__,__LINE__,s,a,b) +#define log3(s,a,b,c) DBLog(__FILE__,__LINE__,s,a,b,c) +#define log4(s,a,b,c,d) DBLog(__FILE__,__LINE__,s,a,b,c,d) +#else +#define logg() +#define log0(s) +#define log1(s,a) +#define log2(s,a,b) +#define log3(s,a,b,c) +#define log4(s,a,b,c,d) +#endif \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/dbtool.h b/plugins/Dbx_mmap_SA/Dbtool/src/dbtool.h new file mode 100644 index 0000000000..7f89ecd7aa --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/dbtool.h @@ -0,0 +1,106 @@ +/* +Miranda Database Tool +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. +*/ + +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NON_CONFORMING_SWPRINTFS + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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. +#include "resource.h" + +#define WZM_GOTOPAGE (WM_USER+1) +#define WZN_PAGECHANGING (WM_USER+1221) +#define WZN_CANCELCLICKED (WM_USER+1222) + +struct DbToolOptions { + TCHAR filename[MAX_PATH]; + TCHAR workingFilename[MAX_PATH]; + TCHAR outputFilename[MAX_PATH]; + TCHAR backupFilename[MAX_PATH]; + HANDLE hFile; + HANDLE hOutFile; + HANDLE hMap; + BYTE *pFile; + DWORD error; + int bCheckOnly,bBackup,bAggressive; + int bEraseHistory,bMarkRead,bConvertUtf; +}; + +extern HINSTANCE hInst; +extern DbToolOptions opts; +extern DBHeader dbhdr; + +int DoMyControlProcessing(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam,INT_PTR *bReturn); + +INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK CleaningDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK ProgressDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK FinishedDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK OpenErrorDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); + +struct DBSignature { + char name[15]; + BYTE eof; +}; +static struct DBSignature dbSignature={"Miranda ICQ DB",0x1A}; +static struct DBSignature dbSignatureEncrypted={"Miranda ICQ SD",0x1A}; + +#define SIZEOF(X) (sizeof(X)/sizeof(X[0])) + +#define STATUS_MESSAGE 0 +#define STATUS_WARNING 1 +#define STATUS_ERROR 2 +#define STATUS_FATAL 3 +#define STATUS_SUCCESS 4 +#define STATUS_CLASSMASK 0x0f +int AddToStatus(DWORD flags, TCHAR* fmt,...); +void SetProgressBar(int perThou); + +int PeekSegment(DWORD ofs,PVOID buf,int cbBytes); +int ReadSegment(DWORD ofs,PVOID buf,int cbBytes); +#define WSOFS_END 0xFFFFFFFF +#define WS_ERROR 0xFFFFFFFF +DWORD WriteSegment(DWORD ofs,PVOID buf,int cbBytes); +int ReadWrittenSegment(DWORD ofs,PVOID buf,int cbBytes); +int SignatureValid(DWORD ofs,DWORD signature); +DWORD ConvertModuleNameOfs(DWORD ofsOld); +void FreeModuleChain(); +extern BOOL bEncrypted; + +bool is_utf8_string(const char* str); diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/disk.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/disk.cpp new file mode 100644 index 0000000000..1ac84a3dc6 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/disk.cpp @@ -0,0 +1,112 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +extern DWORD spaceProcessed,sourceFileSize; + +int SignatureValid(DWORD ofs,DWORD signature) +{ + DWORD sig; + + if(ofs+sizeof(sig)>=sourceFileSize) { + AddToStatus(STATUS_ERROR,TranslateT("Invalid offset found (database truncated?)")); + return 0; + } + + sig = *(DWORD*)(opts.pFile+ofs); + + return sig==signature; +} + +int PeekSegment(DWORD ofs,PVOID buf,int cbBytes) +{ + DWORD bytesRead; + + if(ofs>=sourceFileSize) { + AddToStatus(STATUS_ERROR,TranslateT("Invalid offset found")); + return ERROR_SEEK; + } + + if (ofs+cbBytes>sourceFileSize) + bytesRead = sourceFileSize - ofs; + else + bytesRead = cbBytes; + + if(bytesRead==0) { + AddToStatus(STATUS_ERROR,TranslateT("Error reading, database truncated? (%u)"),GetLastError()); + return ERROR_READ_FAULT; + } + + CopyMemory(buf, opts.pFile+ofs, bytesRead); + + if ((int)bytesReadsourceFileSize) { + AddToStatus(STATUS_WARNING,TranslateT("Can't write to working file, aggressive mode may be too aggressive now")); + ZeroMemory(opts.pFile+ofs,sourceFileSize-ofs); + } + else + ZeroMemory(opts.pFile+ofs,cbBytes); + } + spaceProcessed+=cbBytes; + return ERROR_SUCCESS; +} + +DWORD WriteSegment(DWORD ofs,PVOID buf,int cbBytes) +{ + DWORD bytesWritten; + if(opts.bCheckOnly) return 0xbfbfbfbf; + if(ofs==WSOFS_END) { + ofs=dbhdr.ofsFileEnd; + dbhdr.ofsFileEnd+=cbBytes; + } + SetFilePointer(opts.hOutFile,ofs,NULL,FILE_BEGIN); + WriteFile(opts.hOutFile,buf,cbBytes,&bytesWritten,NULL); + if ((int)bytesWritten dbhdr.ofsFileEnd ) + return ERROR_SEEK; + + SetFilePointer(opts.hOutFile,ofs,NULL,FILE_BEGIN); + ReadFile(opts.hOutFile,buf,cbBytes,&bytesRead,NULL); + if ((int)bytesReadcryptor = GetCryptor(); + strcpy(Modules[ModulesCount]->dllname, fd.cFileName); + Modules[ModulesCount]->hLib = hLib; + + _snprintf(buf,SIZEOF(buf),"%d.%d.%d.%d", HIBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), HIBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version))); + + mbstowcs(Name, Modules[ModulesCount]->cryptor->Name, 100); + mbstowcs(Version, buf, 100); + mbstowcs(DllName, Modules[ModulesCount]->dllname, 100); + + AddToStatus(STATUS_MESSAGE,TranslateT("Cryptor loaded: %s [%s] (%s)"), Name, Version, DllName); + + ModulesCount++; + }else{ + FreeLibrary(hLib); + } + } + if(ModulesCount >= 100) break; + if (!FindNextFileA(hFile, &fd)) break; + } + + AddToStatus(STATUS_MESSAGE,TranslateT("%d crypto modules loaded"), ModulesCount); +} + +void UnloadSecurity() +{ + int i; + + if(CryptoEngine) CryptoEngine->FreeKey(key); + + for(i = 0; i < ModulesCount; i++) + { + FreeLibrary(Modules[i]->hLib); + free(Modules[i]); + } +} + +void EncoderInit() +{ + encryptKey[encryptKeyLength] = 0; + key = CryptoEngine->GenerateKey(encryptKey); +} + +void EncodeCopyMemory(BYTE * dst, void * src, size_t size ) +{ + memcpy(dst, src, size); + CryptoEngine->EncryptMem(dst, (int)size, key); +} + +void DecodeCopyMemory(BYTE * dst, void * src, size_t size ) +{ + memcpy(dst, src, size); + CryptoEngine->DecryptMem(dst, (int)size, key); +} + + +void EncodeMemory(BYTE * mem, size_t size) +{ + CryptoEngine->EncryptMem(mem, (int)size, key); +} + +void DecodeMemory(BYTE * mem, size_t size) +{ + CryptoEngine->DecryptMem(mem, (int)size, key); +} + +int bCheckingPass = 0; + +int CheckPassword(WORD checkWord, WORD cryptorUID, char * szDBName) +{ + WORD ver; + int res; + + if(bCheckingPass) return 0; + bCheckingPass = 1; + + { + int i; + int Found = 0; + for(i = 0; i < ModulesCount; i++) { + if(cryptorUID == Modules[i]->cryptor->uid){ + CryptoEngine = Modules[i]->cryptor; + Found = 1; + break; + } + } + if (!Found){ + AddToStatus(STATUS_FATAL, TranslateT("Sorry, but your database encrypted with unknown module"), MB_OK); + bCheckingPass = 0; + return 0; + } + } + + { + wchar_t Name[100], Author[100]; + + mbstowcs(Name, CryptoEngine->Name, 100); + mbstowcs(Author, CryptoEngine->Author, 100); + + AddToStatus(STATUS_MESSAGE, TranslateT("Database encrypted with %s by %s"), Name, Author); + } + + while(1){ + res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LOGIN), NULL, (DLGPROC)DlgStdInProc, (LPARAM)szDBName); + if(res == IDCANCEL) + { + wrongPass = 0; + bCheckingPass = 0; + return 0; + } + if(encryptKeyLength < 1) continue; + EncoderInit(); + DecodeCopyMemory((BYTE*)&ver, &checkWord, sizeof(checkWord)); + if(ver == 0x5195) + { + wrongPass = 0; + bCheckingPass = 0; + return 1; + } + wrongPass++; + } + + bCheckingPass = 0; +} + + +UINT oldLangID = 0; +void LanguageChanged(HWND hDlg) +{ + UINT LangID = (UINT)GetKeyboardLayout(0); + char Lang[3] = {0}; + if (LangID != oldLangID) + { + oldLangID = LangID; + GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); + SetDlgItemTextA(hDlg, IDC_LANG, Lang); + } +} + +BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) +{ + switch(uMsg) + { + case WM_INITDIALOG: + { + HWND hwndCtrl; + TranslateDialogDefault(hDlg); + + if(lParam && !wrongPass) SetDlgItemTextA(hDlg, IDC_DBNAME, (LPCSTR)lParam); + if(wrongPass) + { + if (wrongPass > 2) + { + hwndCtrl = GetDlgItem(hDlg, IDC_USERPASS); + EnableWindow(hwndCtrl, FALSE); + hwndCtrl = GetDlgItem(hDlg, IDOK); + EnableWindow(hwndCtrl, FALSE); + + SetDlgItemText(hDlg, IDC_LOGININFO, TranslateT("Too many errors!")); + + } + else + { + SetDlgItemText(hDlg, IDC_LOGININFO, TranslateT("Password is not correct!")); + } + } + oldLangID = 0; + SetTimer(hDlg,1,200,NULL); + LanguageChanged(hDlg); + return TRUE; + } + + case WM_CTLCOLORSTATIC: + { + if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) + { + SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetBkMode((HDC)wParam, TRANSPARENT); + return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); + } + + return FALSE; + } + + case WM_COMMAND: + { + UINT uid = LOWORD(wParam); + + if(uid == IDOK){ + if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) + { + encryptKeyLength = GetDlgItemTextA(hDlg, IDC_USERPASS, encryptKey, 254); + EndDialog(hDlg,IDOK); + }else{ + + } + }else if(uid == IDCANCEL){ + EndDialog(hDlg,IDCANCEL); + } + } + case WM_TIMER: + { + LanguageChanged(hDlg); + return FALSE; + } + case WM_DESTROY: + { + KillTimer(hDlg, 1); + return FALSE; + } + } + + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/eventchain.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/eventchain.cpp new file mode 100644 index 0000000000..3c9e37668a --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/eventchain.cpp @@ -0,0 +1,363 @@ +/* +Miranda Database Tool +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" + +static BOOL backLookup; +static DWORD ofsThisEvent,ofsPrevEvent; +static DWORD ofsDestPrevEvent; +static DWORD eventCount; +static DWORD lastTimestamp; +static DWORD ofsFirstUnread,timestampFirstUnread; +static DWORD memsize = 0; +static DBEvent* memblock = NULL; +static DBEvent* dbePrevEvent = NULL; + +static void ConvertOldEvent( DBEvent*& dbei ) +{ + int msglen = (int)strlen(( char* )dbei->blob) + 1, msglenW = 0; + if ( msglen != (int) dbei->cbBlob ) { + int i, count = (( dbei->cbBlob - msglen ) / sizeof( WCHAR )); + WCHAR* p = ( WCHAR* )&dbei->blob[ msglen ]; + for ( i=0; i < count; i++ ) { + if ( p[i] == 0 ) { + msglenW = i; + break; + } } } + else { + if ( !is_utf8_string(( char* )dbei->blob)) + dbei->flags &= ~DBEF_UTF; + } + + if ( msglenW > 0 && msglenW <= 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) { + memsize = offsetof(DBEvent,blob)+dbei->cbBlob; + memblock = (DBEvent*)realloc(memblock, memsize); + dbei = memblock; + } + memcpy( &dbei->blob, utf8str, dbei->cbBlob ); + free(utf8str); +} } + +static void WriteOfsNextToPrevious(DWORD ofsPrev,DBContact *dbc,DWORD ofsNext) +{ + if(ofsPrev) + WriteSegment(ofsPrev+offsetof(DBEvent,ofsNext),&ofsNext,sizeof(DWORD)); + else + dbc->ofsFirstEvent=ofsNext; +} + +static void FinishUp(DWORD ofsLast,DBContact *dbc) +{ + WriteOfsNextToPrevious(ofsLast,dbc,0); + if(eventCount!=dbc->eventCount) + AddToStatus(STATUS_WARNING,TranslateT("Event count marked wrongly: correcting")); + dbc->eventCount=eventCount; + dbc->ofsLastEvent=ofsLast; + if(opts.bMarkRead) { + dbc->ofsFirstUnreadEvent=0; + dbc->timestampFirstUnread=0; + } + else { + dbc->ofsFirstUnreadEvent=ofsFirstUnread; + dbc->timestampFirstUnread=timestampFirstUnread; + } + if (memsize && memblock) { + free(memblock); + memsize = 0; + memblock = NULL; + } +} + +static DWORD WriteEvent(DBEvent *dbe) +{ + DWORD ofs = WriteSegment( WSOFS_END, dbe, offsetof(DBEvent,blob)+dbe->cbBlob ); + if ( ofs == WS_ERROR ) { + free( memblock ); + memblock = NULL; + memsize = 0; + return 0; + } + return ofs; +} + +int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime) +{ + DBEvent *dbeNew,dbeOld; + DBEvent *dbePrev = NULL; + DWORD ofsDestThis; + int isUnread=0; + + if(firstTime) { + dbePrevEvent = NULL; + ofsPrevEvent=0; + ofsDestPrevEvent=0; + ofsThisEvent=dbc->ofsFirstEvent; + eventCount=0; + backLookup=0; + lastTimestamp=0; + ofsFirstUnread=timestampFirstUnread=0; + if(opts.bEraseHistory) { + dbc->eventCount=0; + dbc->ofsFirstEvent=0; + dbc->ofsLastEvent=0; + dbc->ofsFirstUnreadEvent=0; + dbc->timestampFirstUnread=0; + return ERROR_NO_MORE_ITEMS; + } } + + if(ofsThisEvent==0) { + FinishUp(ofsDestPrevEvent,dbc); + return ERROR_NO_MORE_ITEMS; + } + if (!SignatureValid(ofsThisEvent,DBEVENT_SIGNATURE)) + { + DWORD ofsNew = 0; + DWORD ofsTmp = dbc->ofsLastEvent; + + if (!backLookup && ofsTmp) { + backLookup = 1; + while(SignatureValid(ofsTmp,DBEVENT_SIGNATURE)) + { + if(PeekSegment(ofsTmp,&dbeOld,sizeof(dbeOld))!=ERROR_SUCCESS) + break; + ofsNew = ofsTmp; + ofsTmp = dbeOld.ofsPrev; + } + } + if (ofsNew) { + AddToStatus(STATUS_WARNING,TranslateT("Event chain corrupted, trying to recover...")); + ofsThisEvent = ofsNew; + } else { + AddToStatus(STATUS_ERROR,TranslateT("Event chain corrupted, further entries ignored")); + FinishUp(ofsDestPrevEvent,dbc); + return ERROR_NO_MORE_ITEMS; + } + } + + if(PeekSegment(ofsThisEvent,&dbeOld,sizeof(dbeOld))!=ERROR_SUCCESS) { + FinishUp(ofsDestPrevEvent,dbc); + return ERROR_NO_MORE_ITEMS; + } + + if(firstTime) { + if (!(dbeOld.flags&DBEF_FIRST)) { + AddToStatus(STATUS_WARNING,TranslateT("First event not marked as such: correcting")); + dbeOld.flags|=DBEF_FIRST; + } + dbeOld.ofsPrev=ofsContact; + lastTimestamp=dbeOld.timestamp; + } + else if(dbeOld.flags&DBEF_FIRST) { + AddToStatus(STATUS_WARNING,TranslateT("Event marked as first which is not: correcting")); + dbeOld.flags&=~DBEF_FIRST; + } + + if(dbeOld.flags&~(DBEF_FIRST|DBEF_READ|DBEF_SENT|DBEF_RTL|DBEF_UTF)) { + AddToStatus(STATUS_WARNING,TranslateT("Extra flags found in event: removing")); + dbeOld.flags&=(DBEF_FIRST|DBEF_READ|DBEF_SENT|DBEF_RTL|DBEF_UTF); + } + + if (!(dbeOld.flags&(DBEF_READ|DBEF_SENT))) { + if(opts.bMarkRead) dbeOld.flags|=DBEF_READ; + else if(ofsFirstUnread==0) { + if(dbc->ofsFirstUnreadEvent!=ofsThisEvent || dbc->timestampFirstUnread!=dbeOld.timestamp) + AddToStatus(STATUS_WARNING,TranslateT("First unread event marked wrong: fixing")); + isUnread=1; + } } + + if(dbeOld.cbBlob>1024*1024 || dbeOld.cbBlob==0) { + AddToStatus(STATUS_ERROR,TranslateT("Infeasibly large event blob: skipping")); + ofsThisEvent=dbeOld.ofsNext; + return ERROR_SUCCESS; + } + + if ( dbePrevEvent && dbeOld.timestamp == lastTimestamp ) { + int len = offsetof(DBEvent,blob)+dbePrevEvent->cbBlob; + dbePrev = (DBEvent*)malloc(len); + memcpy(dbePrev, dbePrevEvent, len); + } + + if (offsetof(DBEvent,blob)+dbeOld.cbBlob > memsize) { + memsize = offsetof(DBEvent,blob)+dbeOld.cbBlob; + memblock = (DBEvent*)realloc(memblock, memsize); + } + dbeNew=memblock; + + if(ReadSegment(ofsThisEvent,dbeNew,offsetof(DBEvent,blob)+dbeOld.cbBlob)!=ERROR_SUCCESS) { + FinishUp(ofsDestPrevEvent,dbc); + return ERROR_NO_MORE_ITEMS; + } + + if ((dbeNew->ofsModuleName=ConvertModuleNameOfs(dbeOld.ofsModuleName))==0) { + ofsThisEvent=dbeOld.ofsNext; + return ERROR_SUCCESS; + } + + if (!firstTime && dbeOld.ofsPrev!=ofsPrevEvent) + AddToStatus(STATUS_WARNING,TranslateT("Event not backlinked correctly: fixing")); + + dbeNew->flags=dbeOld.flags; + dbeNew->ofsPrev=ofsDestPrevEvent; + dbeNew->ofsNext=0; + + if ( dbeOld.eventType == EVENTTYPE_MESSAGE && opts.bConvertUtf ) + ConvertOldEvent(dbeNew); + + if ( dbePrev ) + { + if ( dbePrev->cbBlob == dbeNew->cbBlob && + dbePrev->ofsModuleName == dbeNew->ofsModuleName && + dbePrev->eventType == dbeNew->eventType && + (dbePrev->flags & DBEF_SENT) == (dbeNew->flags & DBEF_SENT) && + !memcmp( dbePrev->blob, dbeNew->blob, dbeNew->cbBlob ) + ) { + AddToStatus(STATUS_WARNING,TranslateT("Duplicate event was found: skipping")); + if (dbc->eventCount) + dbc->eventCount--; + free(dbePrev); + // ofsDestPrevEvent is still the same! + ofsPrevEvent=ofsThisEvent; + ofsThisEvent=dbeOld.ofsNext; + return ERROR_SUCCESS; + } + free(dbePrev); + } + else if ( !firstTime && dbeNew->timestamp < lastTimestamp ) + { + DWORD found = 0; + DBEvent dbeTmp; + DWORD ofsTmp; + + if (opts.bCheckOnly) + { + if (!opts.bAggressive) + { + ofsTmp = dbeOld.ofsPrev; + while(PeekSegment(ofsTmp,&dbeTmp,sizeof(dbeTmp))==ERROR_SUCCESS) + { + if (dbeTmp.ofsPrev == ofsContact) { + found = 1; + break; + } + if (dbeTmp.timestamp < dbeNew->timestamp) { + found = 2; + break; + } + ofsTmp = dbeTmp.ofsPrev; + } + } + AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct")); + } + else + { + ofsTmp = ofsDestPrevEvent; + while(ReadWrittenSegment(ofsTmp,&dbeTmp,sizeof(dbeTmp))==ERROR_SUCCESS) + { + if (dbeTmp.ofsPrev == ofsContact) { + found = 1; + break; + } + if (dbeTmp.timestamp < dbeNew->timestamp) { + found = 2; + break; + } + ofsTmp = dbeTmp.ofsPrev; + } + if (found) + AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct: fixing")); + else + AddToStatus(STATUS_WARNING,TranslateT("Event position in chain is not correct: unable to fix")); + } + + // insert before FIRST + if (found == 1 && !opts.bCheckOnly) { + dbeNew->flags|=DBEF_FIRST; + dbeNew->ofsPrev=ofsContact; + dbeNew->ofsNext=dbc->ofsFirstEvent; + + ofsDestThis = WriteEvent(dbeNew); + if ( !ofsDestThis ) + return ERROR_HANDLE_DISK_FULL; + + if ( isUnread && timestampFirstUnread >= dbeNew->timestamp ) { + ofsFirstUnread=ofsDestThis; + timestampFirstUnread=dbeNew->timestamp; + } + // fix first event + WriteOfsNextToPrevious(0,dbc,ofsDestThis); + // fix next event + WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,ofsPrev),&ofsDestThis,sizeof(DWORD)); + dbeTmp.flags &=~DBEF_FIRST; + WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,flags),&dbeTmp.flags,sizeof(DWORD)); + } + else if (found == 2 && !opts.bCheckOnly) { + + dbeNew->ofsPrev=ofsTmp; + dbeNew->ofsNext=dbeTmp.ofsNext; + + ofsDestThis = WriteEvent(dbeNew); + if ( !ofsDestThis ) + return ERROR_HANDLE_DISK_FULL; + + if ( isUnread && timestampFirstUnread >= dbeNew->timestamp ) { + ofsFirstUnread=ofsDestThis; + timestampFirstUnread=dbeNew->timestamp; + } + // fix previous event + WriteOfsNextToPrevious(dbeNew->ofsPrev,dbc,ofsDestThis); + // fix next event + WriteSegment(dbeNew->ofsNext+offsetof(DBEvent,ofsPrev),&ofsDestThis,sizeof(DWORD)); + } + + if (found) { + eventCount++; + // ofsDestPrevEvent is still the same! + ofsPrevEvent=ofsThisEvent; + ofsThisEvent=dbeOld.ofsNext; + return ERROR_SUCCESS; + } + } + + lastTimestamp=dbeNew->timestamp; + dbePrevEvent = dbeNew; + + ofsDestThis = WriteEvent(dbeNew); + if ( !ofsDestThis ) + return ERROR_HANDLE_DISK_FULL; + + if ( isUnread ) { + ofsFirstUnread=ofsDestThis; + timestampFirstUnread=dbeOld.timestamp; + } + + eventCount++; + WriteOfsNextToPrevious(ofsDestPrevEvent,dbc,ofsDestThis); + + ofsDestPrevEvent=ofsDestThis; + ofsPrevEvent=ofsThisEvent; + ofsThisEvent=dbeOld.ofsNext; + return ERROR_SUCCESS; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/fileaccess.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/fileaccess.cpp new file mode 100644 index 0000000000..d904daf5b9 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/fileaccess.cpp @@ -0,0 +1,69 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +INT_PTR CALLBACK FileAccessDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + INT_PTR bReturn; + + if(DoMyControlProcessing(hdlg,message,wParam,lParam,&bReturn)) return bReturn; + switch(message) { + case WM_INITDIALOG: + CheckDlgButton(hdlg,IDC_CHECKONLY,opts.bCheckOnly); + CheckDlgButton(hdlg,IDC_BACKUP,opts.bBackup); + CheckDlgButton(hdlg,IDC_AGGRESSIVE,opts.bAggressive); + SendMessage(hdlg,WM_COMMAND,MAKEWPARAM(IDC_CHECKONLY,BN_CLICKED),0); + TranslateDialogDefault(hdlg); + return TRUE; + case WZN_PAGECHANGING: + opts.bCheckOnly=IsDlgButtonChecked(hdlg,IDC_CHECKONLY); + opts.bAggressive=IsDlgButtonChecked(hdlg,IDC_AGGRESSIVE); + if(opts.bCheckOnly) opts.bBackup=0; + else opts.bBackup=IsDlgButtonChecked(hdlg,IDC_BACKUP); + break; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_SELECTDB,(LPARAM)SelectDbDlgProc); + break; + case IDOK: + if(opts.bCheckOnly) { + if (!opts.hFile) { + opts.hFile = CreateFile( opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); + if ( opts.hFile == INVALID_HANDLE_VALUE ) { + opts.hFile = NULL; + opts.error = GetLastError(); + SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, ( LPARAM )OpenErrorDlgProc ); + break; + } + } + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressDlgProc); + } + else + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_CLEANING,(LPARAM)CleaningDlgProc); + break; + case IDC_CHECKONLY: + EnableWindow(GetDlgItem(hdlg,IDC_BACKUP),!IsDlgButtonChecked(hdlg,IDC_CHECKONLY)); + EnableWindow(GetDlgItem(hdlg,IDC_STBACKUP),!IsDlgButtonChecked(hdlg,IDC_CHECKONLY)); + break; + } + break; + } + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/finaltasks.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/finaltasks.cpp new file mode 100644 index 0000000000..2ed8b7183d --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/finaltasks.cpp @@ -0,0 +1,78 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +extern int errorCount; + +int WorkFinalTasks(int firstTime) +{ + FreeModuleChain(); + AddToStatus(STATUS_MESSAGE,TranslateT("Processing final tasks")); + dbhdr.slackSpace=0; + if(WriteSegment(0,&dbhdr,sizeof(dbhdr))==WS_ERROR) + return ERROR_WRITE_FAULT; + if (opts.hFile) { + CloseHandle(opts.hFile); + opts.hFile = NULL; + } + if ( opts.hOutFile ) { + CloseHandle(opts.hOutFile); + opts.hOutFile = NULL; + } + if (opts.pFile) { + UnmapViewOfFile(opts.pFile); + opts.pFile = NULL; + } + if (opts.hMap) { + CloseHandle(opts.hMap); + opts.hMap = NULL; + } + if(errorCount && !opts.bBackup && !opts.bCheckOnly) { + extern time_t ts; + time_t dlg_ts = time(NULL); + if ( IDYES == MessageBox( NULL, + TranslateT("Errors were encountered, however you selected not to backup the original database. It is strongly recommended that you do so in case important data was omitted. Do you wish to keep a backup of the original database?"), + TranslateT("Miranda Database Tool"), MB_YESNO )) + opts.bBackup = 1; + ts += time(NULL) - dlg_ts; + } + if(opts.bBackup) { + int i; + TCHAR dbPath[MAX_PATH],dbFile[MAX_PATH]; + _tcscpy( dbPath, opts.filename ); + TCHAR* str2 = _tcsrchr( dbPath, '\\' ); + if ( str2 != NULL ) { + _tcscpy( dbFile, str2+1 ); + *str2 = 0; + } + else { + _tcscpy( dbFile, dbPath ); + dbPath[0] = 0; + } + for(i=1;;i++) { + if(i==1) wsprintf(opts.backupFilename,TranslateT("%s\\Backup of %s"),dbPath,dbFile); + else wsprintf(opts.backupFilename,TranslateT("%s\\Backup (%d) of %s"),dbPath,i,dbFile); + if(_taccess(opts.backupFilename,0)==-1) break; + } + MoveFile(opts.filename,opts.backupFilename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to rename original file")); + } + else if (!opts.bCheckOnly) DeleteFile(opts.filename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to delete original file")); + if (!opts.bCheckOnly) MoveFile(opts.outputFilename,opts.filename) || AddToStatus(STATUS_WARNING,TranslateT("Unable to rename output file")); + return ERROR_NO_MORE_ITEMS; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/finished.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/finished.cpp new file mode 100644 index 0000000000..08d0f5c893 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/finished.cpp @@ -0,0 +1,82 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +#define WM_LAUNCHMIRANDA (WM_USER+1) +INT_PTR CALLBACK FinishedDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + INT_PTR bReturn; + + if(DoMyControlProcessing(hdlg,message,wParam,lParam,&bReturn)) return bReturn; + switch(message) { + case WM_INITDIALOG: + EnableWindow(GetDlgItem(GetParent(hdlg),IDC_BACK),FALSE); + SetDlgItemText(GetParent(hdlg),IDCANCEL,TranslateT("&Finish")); + SetWindowLongPtr(GetDlgItem(hdlg,IDC_DBFILE),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hdlg,IDC_DBFILE),GWL_STYLE)|SS_PATHELLIPSIS); + SetDlgItemText( hdlg, IDC_DBFILE, opts.filename ); + if(opts.bBackup) { + ShowWindow(GetDlgItem(hdlg,IDC_STBACKUP),TRUE); + SetWindowLongPtr(GetDlgItem(hdlg,IDC_BACKUPFILE),GWL_STYLE,GetWindowLongPtr(GetDlgItem(hdlg,IDC_BACKUPFILE),GWL_STYLE)|SS_PATHELLIPSIS); + SetDlgItemText(hdlg,IDC_BACKUPFILE,opts.backupFilename); + } + else ShowWindow(GetDlgItem(hdlg,IDC_STBACKUP),FALSE); + TranslateDialogDefault(hdlg); + return TRUE; + case WM_LAUNCHMIRANDA: + if(IsDlgButtonChecked(hdlg,IDC_LAUNCHMIRANDA)) { + TCHAR dbFile[MAX_PATH],dbPath[MAX_PATH],*str2; + _tcscpy(dbPath,opts.filename); + str2 = _tcsrchr(dbPath,'\\'); + if ( str2 == NULL ) { + _tcscpy( dbFile, dbPath ); + dbPath[ 0 ] = 0; + } + else { + _tcscpy( dbFile, str2+1 ); + *str2 = 0; + } + str2 = _tcsrchr( dbFile, '.' ); + if ( str2 != NULL ) + *str2 = 0; + _tcscat( dbPath, _T("\\miranda32.exe")); + if ( GetFileAttributes( dbPath ) == INVALID_FILE_ATTRIBUTES ) { + GetModuleFileName( NULL, dbPath, SIZEOF( dbPath )); + if (( str2 = _tcsrchr( dbPath, '\\' )) != NULL ) + *str2 = 0; + else + dbPath[0] = 0; + _tcscat( dbPath, _T("\\miranda32.exe")); + } + ShellExecute( hdlg, NULL, dbPath, dbFile, _T(""), SW_SHOW ); + } + break; + case WZN_CANCELCLICKED: + SendMessage(hdlg,WM_LAUNCHMIRANDA,0,0); + break; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDOK: + SendMessage(hdlg,WM_LAUNCHMIRANDA,0,0); + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_SELECTDB,(LPARAM)SelectDbDlgProc); + break; + } + break; + } + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/initialchecks.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/initialchecks.cpp new file mode 100644 index 0000000000..385d31cb92 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/initialchecks.cpp @@ -0,0 +1,98 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +BOOL bEncrypted; +extern DWORD sourceFileSize,spaceUsed; +int CheckPassword(WORD version, WORD cryptorUID, char * szDBName); +void InitSecurity(); + +int WorkInitialChecks(int firstTime) +{ + DWORD bytesRead; + + sourceFileSize=GetFileSize(opts.hFile,NULL); + if(sourceFileSize==0) { + AddToStatus(STATUS_WARNING,TranslateT("Database is newly created and has no data to process")); + AddToStatus(STATUS_SUCCESS,TranslateT("Processing completed successfully")); + return ERROR_INVALID_DATA; + } + ReadFile(opts.hFile,&dbhdr,sizeof(dbhdr),&bytesRead,NULL); + if(bytesRead")); + opts.hOutFile=INVALID_HANDLE_VALUE; + } + else { + _tcscpy(opts.outputFilename,opts.filename); + *_tcsrchr(opts.outputFilename,'.')=0; + _tcscat(opts.outputFilename,TranslateT(" (Output).dat")); + opts.hOutFile = CreateFile(opts.outputFilename,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_FLAG_SEQUENTIAL_SCAN,NULL); + if ( opts.hOutFile == INVALID_HANDLE_VALUE ) { + AddToStatus(STATUS_FATAL,TranslateT("Can't create output file (%u)"),GetLastError()); + return ERROR_ACCESS_DENIED; + } + } + + opts.hMap = CreateFileMapping(opts.hFile, NULL, opts.bAggressive?PAGE_WRITECOPY:PAGE_READONLY, 0, 0, NULL); + + if (opts.hMap) + opts.pFile = (BYTE*)MapViewOfFile(opts.hMap, opts.bAggressive?FILE_MAP_COPY:FILE_MAP_READ, 0, 0 ,0); + else { + AddToStatus(STATUS_FATAL,TranslateT("Can't create file mapping (%u)"),GetLastError()); + return ERROR_ACCESS_DENIED; + } + + if (!opts.pFile) { + AddToStatus(STATUS_FATAL,TranslateT("Can't create map view of file (%u)"),GetLastError()); + return ERROR_ACCESS_DENIED; + } + if(ReadSegment(0,&dbhdr,sizeof(dbhdr))!=ERROR_SUCCESS) return ERROR_READ_FAULT; + if(WriteSegment(0,&dbhdr,sizeof(dbhdr))==WS_ERROR) return ERROR_HANDLE_DISK_FULL; + spaceUsed=dbhdr.ofsFileEnd-dbhdr.slackSpace; + dbhdr.ofsFileEnd=sizeof(dbhdr); + return ERROR_NO_MORE_ITEMS; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/main.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/main.cpp new file mode 100644 index 0000000000..d505751bd5 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/main.cpp @@ -0,0 +1,33 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +HINSTANCE hInst; +int hLangpack=0; + +DbToolOptions opts = {0}; + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + hInst=hInstance; + InitCommonControls(); + LoadLangPackModule(); + DialogBox(hInst,MAKEINTRESOURCE(IDD_WIZARD),NULL,WizardDlgProc); + return 0; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/modulechain.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/modulechain.cpp new file mode 100644 index 0000000000..2b91059176 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/modulechain.cpp @@ -0,0 +1,146 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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 ModChainEntry { + DWORD ofsOld,ofsNew; + int size; + char name[257]; +} static *modChain=NULL; +static int modChainCount; +static DWORD ofsCurrent; +static int phase,iCurrentModName; +static DWORD ofsLast; +static int last_mod = 0; + +int WorkModuleChain(int firstTime) +{ + DBModuleName moduleName,*newModName; + + if(firstTime) { + AddToStatus(STATUS_MESSAGE,TranslateT("Processing module name chain")); + modChainCount=0; + last_mod = 0; + if(modChain!=NULL) free(modChain); + modChain = (ModChainEntry*)malloc(sizeof(ModChainEntry)); + phase=0; + ofsCurrent=dbhdr.ofsFirstModuleName; + } + switch(phase) { + case 0: + if(ofsCurrent==0) { + phase++; + return ERROR_SUCCESS; + } + if (!SignatureValid(ofsCurrent,DBMODULENAME_SIGNATURE)) { + AddToStatus(STATUS_ERROR,TranslateT("Module chain corrupted, further entries ignored")); + phase++; + return ERROR_SUCCESS; + } + if(PeekSegment(ofsCurrent,&moduleName,offsetof(DBModuleName,name))!=ERROR_SUCCESS) { + phase++; + return ERROR_SUCCESS; + } + if(moduleName.cbName>256) + AddToStatus(STATUS_WARNING,TranslateT("Unreasonably long module name, skipping")); + else { + modChain=(ModChainEntry*)realloc(modChain,sizeof(ModChainEntry)*++modChainCount); + + modChain[modChainCount-1].ofsOld=ofsCurrent; + modChain[modChainCount-1].size=offsetof(DBModuleName,name)+moduleName.cbName; + modChain[modChainCount-1].ofsNew=0; + + if (moduleName.cbName) + PeekSegment(ofsCurrent+offsetof(DBModuleName,name),&modChain[modChainCount-1].name,moduleName.cbName); + modChain[modChainCount-1].name[moduleName.cbName]=0; + } + ofsCurrent=moduleName.ofsNext; + break; + case 1: + ofsLast = 0; + iCurrentModName=0; + dbhdr.ofsFirstModuleName=0; + phase++; + case 2: + if(iCurrentModName>=modChainCount) { + DWORD dw = 0; + if(ofsLast) WriteSegment(ofsLast+offsetof(DBModuleName,ofsNext),&dw,sizeof(DWORD)); + return ERROR_NO_MORE_ITEMS; + } + if(modChain[iCurrentModName].ofsNew==0) { + newModName=(DBModuleName*)_alloca(modChain[iCurrentModName].size); + if(ReadSegment(modChain[iCurrentModName].ofsOld,newModName,modChain[iCurrentModName].size)!=ERROR_SUCCESS) + return ERROR_NO_MORE_ITEMS; + if ((modChain[iCurrentModName].ofsNew=WriteSegment(WSOFS_END,newModName,modChain[iCurrentModName].size))==WS_ERROR) + return ERROR_HANDLE_DISK_FULL; + { // check duplicated modulenames + int i, n=0; + for(i=iCurrentModName+1;iitemWidth=listWidth; + mis->itemHeight=fontHeight; + return TRUE; + } + case WM_DRAWITEM: + { LPDRAWITEMSTRUCT dis=(LPDRAWITEMSTRUCT)lParam; + TCHAR str[256]; + int bold=0; + HFONT hoFont; + if ((int)dis->itemID==-1) break; + SendMessage(dis->hwndItem,LB_GETTEXT,dis->itemID,(LPARAM)str); + switch(dis->itemData&STATUS_CLASSMASK) { + case STATUS_MESSAGE: + SetTextColor(dis->hDC,RGB(0,0,0)); + break; + case STATUS_WARNING: + SetTextColor(dis->hDC,RGB(192,128,0)); + break; + case STATUS_ERROR: + SetTextColor(dis->hDC,RGB(192,0,0)); + break; + case STATUS_FATAL: + bold=1; + SetTextColor(dis->hDC,RGB(192,0,0)); + break; + case STATUS_SUCCESS: + bold=1; + SetTextColor(dis->hDC,RGB(0,192,0)); + break; + } + if(bold) hoFont=(HFONT)SelectObject(dis->hDC,hBoldFont); + ExtTextOut(dis->hDC,dis->rcItem.left,dis->rcItem.top,ETO_CLIPPED|ETO_OPAQUE,&dis->rcItem,str,(UINT)_tcslen(str),NULL); + if(bold) SelectObject(dis->hDC,hoFont); + return TRUE; + } + case WM_PROCESSINGDONE: + SetProgressBar(1000); + EnableWindow(GetDlgItem(GetParent(hdlg),IDOK),TRUE); + if(manualAbort==1) + EndDialog(GetParent(hdlg),0); + else if(manualAbort==2) { + if(opts.bCheckOnly) + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_FILEACCESS,(LPARAM)FileAccessDlgProc); + else { + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_CLEANING,(LPARAM)CleaningDlgProc); + CloseHandle(opts.hOutFile); + opts.hOutFile = NULL; + } + break; + } + AddToStatus(STATUS_SUCCESS,TranslateT("Click Next to continue")); + break; + case WZN_CANCELCLICKED: + ResetEvent(hEventRun); + if(IsWindowEnabled(GetDlgItem(GetParent(hdlg),IDOK))) break; + if(MessageBox(hdlg,TranslateT("Processing has not yet completed, if you cancel now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to cancel?"),TranslateT("Miranda Database Tool"),MB_YESNO)==IDYES) { + manualAbort=1; + SetEvent(hEventAbort); + } + SetEvent(hEventRun); + SetWindowLongPtr(hdlg,DWLP_MSGRESULT,TRUE); + return TRUE; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + ResetEvent(hEventRun); + if (!IsWindowEnabled(GetDlgItem(GetParent(hdlg),IDOK))) { + if(MessageBox(hdlg,TranslateT("Processing has not yet completed, if you go back now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to go back?"),TranslateT("Miranda Database Tool"),MB_YESNO)==IDYES) { + manualAbort=2; + SetEvent(hEventAbort); + } + SetEvent(hEventRun); + break; + } + SetEvent(hEventRun); + if(opts.bCheckOnly) + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_FILEACCESS,(LPARAM)FileAccessDlgProc); + else + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_CLEANING,(LPARAM)CleaningDlgProc); + break; + case IDOK: + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_FINISHED,(LPARAM)FinishedDlgProc); + break; + } + break; + case WM_DESTROY: + if (hEventAbort) { + CloseHandle(hEventAbort); + hEventAbort = NULL; + } + if (hEventRun) { + CloseHandle(hEventRun); + hEventRun = NULL; + } + if (hBoldFont) { + DeleteObject(hBoldFont); + hBoldFont = NULL; + } + break; + } + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/resource.h b/plugins/Dbx_mmap_SA/Dbtool/src/resource.h new file mode 100644 index 0000000000..f92176c33f --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/resource.h @@ -0,0 +1,58 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by resource.rc +// +#define IDC_BACK 3 +#define IDD_WIZARD 101 +#define IDI_DBTOOL 102 +#define IDI_PROFILEGREEN 104 +#define IDR_DEFAULT1 104 +#define IDI_PROFILEYELLOW 105 +#define IDB_BITMAP1 105 +#define IDD_WELCOME 106 +#define IDI_PROFILERED 106 +#define IDD_SELECTDB 107 +#define IDD_OPENERROR 108 +#define IDD_FILEACCESS 109 +#define IDD_CLEANING 110 +#define IDD_PROGRESS 111 +#define IDD_FINISHED 112 +#define IDI_BAD 113 +#define IDD_LOGIN 113 +#define IDC_WATERMARK 1000 +#define IDC_TITLE 1001 +#define IDC_HDRLOGO 1002 +#define IDC_DBLIST 1003 +#define IDC_FILE 1004 +#define IDC_OTHER 1005 +#define IDC_ERRORTEXT 1006 +#define IDC_INUSE 1007 +#define IDC_BACKUP 1008 +#define IDC_AGGRESSIVE 1009 +#define IDC_ERASEHISTORY 1010 +#define IDC_CHECKONLY 1010 +#define IDC_MARKREAD 1011 +#define IDC_PROGRESS 1011 +#define IDC_STATUS 1012 +#define IDC_STBACKUP 1013 +#define IDC_LAUNCHMIRANDA 1015 +#define IDC_DBFILE 1016 +#define IDC_BACKUPFILE 1017 +#define IDC_CHECK1 1018 +#define IDC_CONVERTUTF 1018 +#define IDC_DBNAME 1019 +#define IDC_USERPASS 1021 +#define IDC_LANG 1022 +#define IDC_LOGININFO 1023 +#define IDC_STATIC -1 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 114 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1024 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/selectdb.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/selectdb.cpp new file mode 100644 index 0000000000..9db3517816 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/selectdb.cpp @@ -0,0 +1,303 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +void GetProfileDirectory(TCHAR* szMirandaDir, TCHAR* szPath, int cbPath) +{ + TCHAR szProfileDir[MAX_PATH], szExpandedProfileDir[MAX_PATH], szMirandaBootIni[MAX_PATH]; + + lstrcpy(szMirandaBootIni,szMirandaDir); + lstrcat(szMirandaBootIni,_T("\\mirandaboot.ini")); + GetPrivateProfileString(_T("Database"),_T("ProfileDir"),_T("./Profiles"),szProfileDir,SIZEOF(szProfileDir),szMirandaBootIni); + ExpandEnvironmentStrings(szProfileDir,szExpandedProfileDir,SIZEOF(szExpandedProfileDir)); + _tchdir(szMirandaDir); + if (!_tfullpath(szPath,szExpandedProfileDir,cbPath)) + lstrcpyn(szPath,szMirandaDir,cbPath); + if(szPath[lstrlen(szPath)-1]=='\\') + szPath[lstrlen(szPath)-1] = 0; +} + +static int AddDatabaseToList(HWND hwndList, TCHAR* filename, TCHAR* dir) +{ + LV_ITEM lvi; + int iNewItem; + TCHAR szSize[20], *pName, *pDot, szName[MAX_PATH]; + HANDLE hDbFile; + DBHeader dbhdr; + DWORD bytesRead; + DWORD totalSize,wasted=0; + int broken=0; + + lvi.mask=LVIF_PARAM; + lvi.iSubItem=0; + for(lvi.iItem=ListView_GetItemCount(hwndList)-1;lvi.iItem>=0;lvi.iItem--) { + ListView_GetItem(hwndList,&lvi); + if ( !_tcsicmp(( TCHAR* )lvi.lParam,filename)) return lvi.iItem; + } + hDbFile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); + if ( hDbFile == INVALID_HANDLE_VALUE ) + return -1; + + ReadFile(hDbFile,&dbhdr,sizeof(dbhdr),&bytesRead,NULL); + totalSize=GetFileSize(hDbFile,NULL); + + broken = (bytesReaddbhdr.ofsFileEnd) + wasted+=totalSize-dbhdr.ofsFileEnd; + } + CloseHandle(hDbFile); + + pName = _tcsrchr(filename,'\\'); + if ( pName == NULL ) + pName = ( LPTSTR )filename; + else + pName++; + _tcscpy(szName,dir); + _tcscat(szName,pName); + pDot = _tcsrchr( szName, '.' ); + if ( pDot != NULL && !_tcsicmp( pDot, _T(".dat"))) + *pDot=0; + + lvi.iItem = 0; + lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; + lvi.iSubItem = 0; + lvi.lParam = ( LPARAM )_tcsdup(filename); + lvi.pszText = szName; + if (broken) + lvi.iImage = 3; + else if ( wasted < 1024*128 ) + lvi.iImage = 0; + else if ( wasted < 1024*256 + (DWORD)(totalSize > 2*1024*1024 ) ? 256 * 1024 : 0 ) + lvi.iImage=1; + else + lvi.iImage=2; + + iNewItem = ListView_InsertItem(hwndList, &lvi ); + _stprintf(szSize,_T("%.2lf MB"),totalSize/1048576.0); + ListView_SetItemText(hwndList,iNewItem,1,szSize); + if ( !broken ) { + _stprintf(szSize,_T("%.2lf MB"),wasted/1048576.0); + ListView_SetItemText(hwndList,iNewItem,2,szSize); + } + return iNewItem; +} + +void FindAdd(HWND hdlg, TCHAR *szProfileDir, TCHAR *szPrefix) +{ + HANDLE hFind; + WIN32_FIND_DATA fd; + TCHAR szSearchPath[MAX_PATH],szFilename[MAX_PATH]; + + lstrcpy(szSearchPath,szProfileDir); + lstrcat(szSearchPath,_T("\\*.*")); + + hFind=FindFirstFile(szSearchPath,&fd); + if (hFind!=INVALID_HANDLE_VALUE) { + do { + if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && _tcscmp(fd.cFileName, _T(".")) && _tcscmp(fd.cFileName, _T(".."))) { + wsprintf(szFilename,_T("%s\\%s\\%s.dat"),szProfileDir,fd.cFileName,fd.cFileName); + if (_taccess(szFilename, 0) == 0) + AddDatabaseToList(GetDlgItem(hdlg,IDC_DBLIST),szFilename,szPrefix); + } + } while(FindNextFile(hFind,&fd)); + FindClose(hFind); + } +} + +TCHAR *addstring(TCHAR *str, TCHAR *add) { + _tcscpy(str,add); + return str + _tcslen(add) + 1; +} + +INT_PTR CALLBACK SelectDbDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + INT_PTR bReturn; + if ( DoMyControlProcessing( hdlg, message, wParam, lParam, &bReturn )) + return bReturn; + + switch ( message ) { + case WM_INITDIALOG: + { + TCHAR szMirandaPath[MAX_PATH]; + szMirandaPath[ 0 ] = 0; + { HIMAGELIST hIml; + hIml=ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), + (IsWinVerXPPlus() ? ILC_COLOR32 : ILC_COLOR16) | ILC_MASK, 3, 3); + ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILEGREEN))); + ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILEYELLOW))); + ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_PROFILERED))); + ImageList_AddIcon(hIml,LoadIcon(hInst,MAKEINTRESOURCE(IDI_BAD))); + ListView_SetImageList(GetDlgItem(hdlg,IDC_DBLIST),hIml,LVSIL_SMALL); + } + ListView_SetExtendedListViewStyleEx(GetDlgItem(hdlg,IDC_DBLIST),LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT); + { LV_COLUMN lvc; + lvc.mask = LVCF_WIDTH | LVCF_FMT | LVCF_TEXT; + lvc.cx = 205; + lvc.fmt = LVCFMT_LEFT; + lvc.pszText = TranslateT("Database"); + ListView_InsertColumn( GetDlgItem(hdlg,IDC_DBLIST), 0, &lvc ); + lvc.cx = 68; + lvc.fmt = LVCFMT_RIGHT; + lvc.pszText = TranslateT("Total size"); + ListView_InsertColumn(GetDlgItem(hdlg,IDC_DBLIST), 1, &lvc ); + lvc.pszText = TranslateT("Wasted"); + ListView_InsertColumn(GetDlgItem(hdlg,IDC_DBLIST), 2, &lvc ); + } + { + TCHAR *str2; + GetModuleFileName(NULL,szMirandaPath,SIZEOF(szMirandaPath)); + str2 = _tcsrchr(szMirandaPath,'\\'); + if ( str2 != NULL ) + *str2=0; + } + { + int i = 0; + HKEY hKey; + TCHAR szProfileDir[MAX_PATH]; + DWORD cbData = SIZEOF(szMirandaPath); + TCHAR szMirandaProfiles[MAX_PATH]; + + _tcscpy(szMirandaProfiles, szMirandaPath); + _tcscat(szMirandaProfiles, _T("\\Profiles")); + GetProfileDirectory(szMirandaPath,szProfileDir,SIZEOF(szProfileDir)); + + // search in profile dir (using ini file) + if ( lstrcmpi(szProfileDir,szMirandaProfiles)) + FindAdd(hdlg, szProfileDir, _T("[ini]\\")); + + FindAdd(hdlg, szMirandaProfiles, _T("[prf]\\")); + // search in current dir (as DBTOOL) + FindAdd(hdlg, szMirandaPath, _T("[ . ]\\")); + + // search in profile dir (using registry path + ini file) + if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\miranda32.exe"),0,KEY_QUERY_VALUE,&hKey) == ERROR_SUCCESS) { + if(RegQueryValueEx(hKey,_T("Path"),NULL,NULL,(PBYTE)szMirandaPath,&cbData) == ERROR_SUCCESS) { + if ( lstrcmp(szProfileDir,szMirandaPath)) { + GetProfileDirectory(szMirandaPath,szProfileDir,SIZEOF(szProfileDir)); + FindAdd(hdlg, szProfileDir, _T("[reg]\\")); + } + } + RegCloseKey(hKey); + } + // select + if ( opts.filename[0] ) + i = AddDatabaseToList( GetDlgItem( hdlg, IDC_DBLIST ), opts.filename, _T("")); + if ( i == -1 ) + i = 0; + ListView_SetItemState( GetDlgItem(hdlg,IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED ); + } + if ( opts.hFile != NULL && opts.hFile != INVALID_HANDLE_VALUE ) { + CloseHandle( opts.hFile ); + opts.hFile = NULL; + } + TranslateDialogDefault( hdlg ); + return TRUE; + } + + case WZN_PAGECHANGING: + GetDlgItemText( hdlg, IDC_FILE, opts.filename, SIZEOF(opts.filename)); + break; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_FILE: + if(HIWORD(wParam)==EN_CHANGE) + EnableWindow(GetDlgItem(GetParent(hdlg),IDOK),GetWindowTextLength(GetDlgItem(hdlg,IDC_FILE))); + break; + case IDC_OTHER: + { OPENFILENAME ofn={0}; + TCHAR str[MAX_PATH]; + + // _T("Miranda Databases (*.dat)\0*.DAT\0All Files (*)\0*\0"); + TCHAR *filter, *tmp, *tmp1, *tmp2; + tmp1 = TranslateT("Miranda Databases (*.dat)"); + tmp2 = TranslateT("All Files"); + filter = tmp = (TCHAR*)_alloca((_tcslen(tmp1)+_tcslen(tmp2)+11)*sizeof(TCHAR)); + tmp = addstring(tmp, tmp1); + tmp = addstring(tmp, _T("*.DAT")); + tmp = addstring(tmp, tmp2); + tmp = addstring(tmp, _T("*")); + *tmp = 0; + + GetDlgItemText( hdlg, IDC_FILE, str, SIZEOF( str )); + ofn.lStructSize = sizeof(ofn); + ofn.hwndOwner = hdlg; + ofn.hInstance = NULL; + ofn.lpstrFilter = filter; + ofn.lpstrDefExt = _T("dat"); + ofn.lpstrFile = str; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; + ofn.nMaxFile = SIZEOF(str); + ofn.nMaxFileTitle = MAX_PATH; + if ( GetOpenFileName( &ofn )) { + int i; + i = AddDatabaseToList( GetDlgItem(hdlg,IDC_DBLIST), str, _T("")); + if ( i == -1 ) + i=0; + ListView_SetItemState( GetDlgItem(hdlg,IDC_DBLIST), i, LVIS_SELECTED, LVIS_SELECTED ); + } + break; + } + case IDC_BACK: + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_WELCOME,(LPARAM)WelcomeDlgProc); + break; + case IDOK: + opts.hFile = CreateFile( opts.filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); + if ( opts.hFile == INVALID_HANDLE_VALUE ) { + opts.hFile = NULL; + opts.error = GetLastError(); + SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_OPENERROR, ( LPARAM )OpenErrorDlgProc ); + } + else SendMessage( GetParent(hdlg), WZM_GOTOPAGE, IDD_FILEACCESS, (LPARAM)FileAccessDlgProc ); + break; + } + break; + case WM_NOTIFY: + switch(((LPNMHDR)lParam)->idFrom) { + case IDC_DBLIST: + switch(((LPNMLISTVIEW)lParam)->hdr.code) { + case LVN_ITEMCHANGED: + { LV_ITEM lvi; + lvi.iItem=ListView_GetNextItem(GetDlgItem(hdlg,IDC_DBLIST),-1,LVNI_SELECTED); + if(lvi.iItem==-1) break; + lvi.mask=LVIF_PARAM; + ListView_GetItem(GetDlgItem(hdlg,IDC_DBLIST),&lvi); + SetDlgItemText(hdlg,IDC_FILE,(TCHAR*)lvi.lParam); + SendMessage(hdlg,WM_COMMAND,MAKEWPARAM(IDC_FILE,EN_CHANGE),(LPARAM)GetDlgItem(hdlg,IDC_FILE)); + break; + } + } + break; + } + break; + case WM_DESTROY: + { LV_ITEM lvi; + lvi.mask=LVIF_PARAM; + for(lvi.iItem=ListView_GetItemCount(GetDlgItem(hdlg,IDC_DBLIST))-1;lvi.iItem>=0;lvi.iItem--) { + ListView_GetItem(GetDlgItem(hdlg,IDC_DBLIST),&lvi); + free((char*)lvi.lParam); + } + } + break; + } + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/settingschain.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/settingschain.cpp new file mode 100644 index 0000000000..a6e7ecab3b --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/settingschain.cpp @@ -0,0 +1,72 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +static DWORD ofsThisSettings,ofsDestPrevSettings; + +int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime) +{ + DBContactSettings *dbcsNew,dbcsOld; + DWORD ofsDestThis; + int ret; + + if(firstTime) { + ofsDestPrevSettings=0; + ofsThisSettings=dbc->ofsFirstSettings; + dbc->ofsFirstSettings=0; + } + if(ofsThisSettings==0) + return ERROR_NO_MORE_ITEMS; + if (!SignatureValid(ofsThisSettings,DBCONTACTSETTINGS_SIGNATURE)) { + AddToStatus(STATUS_ERROR,TranslateT("Settings chain corrupted, further entries ignored")); + return ERROR_NO_MORE_ITEMS; + } + if(PeekSegment(ofsThisSettings,&dbcsOld,sizeof(dbcsOld))!=ERROR_SUCCESS) + return ERROR_NO_MORE_ITEMS; + if(dbcsOld.cbBlob>256*1024 || dbcsOld.cbBlob==0) { + AddToStatus(STATUS_ERROR,TranslateT("Infeasibly large settings blob: skipping")); + ofsThisSettings=dbcsOld.ofsNext; + return ERROR_SUCCESS; + } + dbcsNew=(DBContactSettings*)_alloca(offsetof(DBContactSettings,blob)+dbcsOld.cbBlob); + if ((ret=ReadSegment(ofsThisSettings,dbcsNew,offsetof(DBContactSettings,blob)+dbcsOld.cbBlob))!=ERROR_SUCCESS) { + if(ret!=ERROR_HANDLE_EOF) { //eof is OK because blank space at the end doesn't matter + return ERROR_NO_MORE_ITEMS; + } + } + if ((dbcsNew->ofsModuleName=ConvertModuleNameOfs(dbcsOld.ofsModuleName))==0) { + ofsThisSettings=dbcsOld.ofsNext; + return ERROR_SUCCESS; + } + if(dbcsNew->blob[0]==0) { + AddToStatus(STATUS_MESSAGE,TranslateT("Empty settings group at %08X: skipping"),ofsThisSettings); + ofsThisSettings=dbcsOld.ofsNext; + return ERROR_SUCCESS; + } + dbcsNew->ofsNext=0; + //TODO? validate all settings in blob/compact if necessary + if ((ofsDestThis=WriteSegment(WSOFS_END,dbcsNew,offsetof(DBContactSettings,blob)+dbcsNew->cbBlob))==WS_ERROR) { + return ERROR_HANDLE_DISK_FULL; + } + if(ofsDestPrevSettings) WriteSegment(ofsDestPrevSettings+offsetof(DBContactSettings,ofsNext),&ofsDestThis,sizeof(DWORD)); + else dbc->ofsFirstSettings=ofsDestThis; + ofsDestPrevSettings=ofsDestThis; + ofsThisSettings=dbcsOld.ofsNext; + return ERROR_SUCCESS; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/user.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/user.cpp new file mode 100644 index 0000000000..9922f1630f --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/user.cpp @@ -0,0 +1,71 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +static DBContact user; +static int phase; +static DWORD ofsUser; + +int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime); +int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime); + +int WorkUser(int firstTime) +{ + int first=0; + + if(firstTime) { + AddToStatus(STATUS_MESSAGE,TranslateT("Processing user data")); + if (!SignatureValid(dbhdr.ofsUser,DBCONTACT_SIGNATURE)) { + AddToStatus(STATUS_ERROR,TranslateT("User corrupted, this could cause major problems")); + return ERROR_NO_MORE_ITEMS; + } + if(ReadSegment(dbhdr.ofsUser,&user,sizeof(DBContact))!=ERROR_SUCCESS) + return ERROR_NO_MORE_ITEMS; + if(user.ofsNext) { + AddToStatus(STATUS_WARNING,TranslateT("More than one user contact: keeping only first")); + user.ofsNext=0; + } + if ((ofsUser=WriteSegment(WSOFS_END,&user,sizeof(DBContact)))==WS_ERROR) + return ERROR_HANDLE_DISK_FULL; + dbhdr.ofsUser=ofsUser; + phase=0; + first=1; + } + switch(phase) { + int ret; + + case 0: + ret=WorkSettingsChain(ofsUser,&user,first); + if(ret==ERROR_NO_MORE_ITEMS) { + phase++; first=1; + } + else if(ret) return ret; + else break; + case 1: + ret=WorkEventChain(ofsUser,&user,first); + if(ret==ERROR_NO_MORE_ITEMS) { + if(WriteSegment(ofsUser,&user,sizeof(DBContact))==WS_ERROR) + return ERROR_HANDLE_DISK_FULL; + return ERROR_NO_MORE_ITEMS; + } + else if(ret) return ret; + break; + } + return ERROR_SUCCESS; +} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/utf.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/utf.cpp new file mode 100644 index 0000000000..c56db053d8 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/utf.cpp @@ -0,0 +1,69 @@ +/* + +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 "dbtool.h" + +bool is_utf8_string(const char* str) +{ + int expect_bytes = 0, utf_found = 0; + + if (!str) return 0; + + while (*str) { + if ((*str & 0x80) == 0) { + /* Looks like an ASCII character */ + if (expect_bytes) + /* byte of UTF-8 character expected */ + return 0; + } + else { + /* Looks like byte of an UTF-8 character */ + if (expect_bytes) { + /* expect_bytes already set: first byte of UTF-8 char already seen */ + if ((*str & 0xC0) != 0x80) { + /* again first byte ?!?! */ + return 0; + } + } + else { + /* First byte of the UTF-8 character */ + /* count initial one bits and set expect_bytes to 1 less */ + char ch = *str; + while (ch & 0x80) { + expect_bytes++; + ch = (ch & 0x7f) << 1; + } + } + /* OK, next byte of UTF-8 character */ + /* Decrement number of expected bytes */ + if ( --expect_bytes == 0 ) + utf_found = 1; + } + str++; + } + + return (utf_found && expect_bytes == 0); +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/welcome.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/welcome.cpp new file mode 100644 index 0000000000..291281e70a --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/welcome.cpp @@ -0,0 +1,61 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + static HENHMETAFILE hEmfWatermark; + static HFONT hTitleFont; + INT_PTR bReturn; + + if(DoMyControlProcessing(hdlg,message,wParam,lParam,&bReturn)) return bReturn; + switch(message) { + case WM_INITDIALOG: + + { + NONCLIENTMETRICS ncm = {0}; + ncm.cbSize = sizeof(ncm); + SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); + LOGFONT TitleLogFont = ncm.lfMessageFont; + TitleLogFont.lfWeight = FW_BOLD; + lstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold")); + + HDC hdc = GetDC(NULL); + INT FontSize = 12; + TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72; + hTitleFont = CreateFontIndirect(&TitleLogFont); + ReleaseDC(NULL, hdc); + } + SendDlgItemMessage(hdlg,IDC_TITLE,WM_SETFONT,(WPARAM)hTitleFont,0); + EnableWindow(GetDlgItem(GetParent(hdlg),IDC_BACK),FALSE); + return FALSE; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDOK: + SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_SELECTDB,(LPARAM)SelectDbDlgProc); + break; + } + break; + case WM_DESTROY: + DeleteEnhMetaFile(hEmfWatermark); + DeleteObject(hTitleFont); + break; + } + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/wizard.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/wizard.cpp new file mode 100644 index 0000000000..8f3a9d5ca8 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/wizard.cpp @@ -0,0 +1,137 @@ +/* +Miranda Database Tool +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" + +static HFONT hBoldFont=NULL; +static HENHMETAFILE hEmfHeaderLogo=NULL; + +static BOOL CALLBACK MyControlsEnumChildren(HWND hwnd,LPARAM lParam) +{ + DWORD style=GetWindowLongPtr(hwnd,GWL_STYLE); + DWORD exstyle=GetWindowLongPtr(hwnd,GWL_EXSTYLE); + char szClass[64]; + int makeBold=0; + + GetClassNameA(hwnd,szClass,sizeof(szClass)); + if (!strcmp(szClass,"Static")) { + if (((style&SS_TYPEMASK)==SS_LEFT || (style&SS_TYPEMASK)==SS_CENTER || (style&SS_TYPEMASK)==SS_RIGHT) && exstyle&WS_EX_CLIENTEDGE) + makeBold=1; + } + else if (!strcmp(szClass,"Button")) { + if(exstyle&WS_EX_CLIENTEDGE) + makeBold=1; + } + if(makeBold) { + if(hBoldFont==NULL) { + LOGFONT lf; + hBoldFont=(HFONT)SendMessage(hwnd,WM_GETFONT,0,0); + GetObject(hBoldFont,sizeof(lf),&lf); + lf.lfWeight=FW_BOLD; + hBoldFont=CreateFontIndirect(&lf); + } + SendMessage(hwnd,WM_SETFONT,(WPARAM)hBoldFont,0); + SetWindowLongPtr(hwnd,GWL_EXSTYLE,exstyle&~WS_EX_CLIENTEDGE); + SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED); + } + return TRUE; +} + +int DoMyControlProcessing(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam,INT_PTR *bReturn) +{ + switch(message) { + case WM_INITDIALOG: + EnumChildWindows(hdlg,MyControlsEnumChildren,0); + + break; + case WM_CTLCOLORSTATIC: + if (GetWindowLongPtr((HWND)lParam, GWL_ID) == IDC_HDRLOGO){ + SetBkColor((HDC)wParam,RGB(255,255,255)); + *bReturn=(BOOL)GetStockObject(WHITE_BRUSH); + return TRUE; + } + if ((GetWindowLongPtr((HWND)lParam,GWL_STYLE)&0xFFFF)==0) { + TCHAR szText[256]; + GetWindowText((HWND)lParam,szText,SIZEOF(szText)); + if (!_tcscmp(szText,_T("whiterect"))) { + SetTextColor((HDC)wParam,RGB(255,255,255)); + SetBkColor((HDC)wParam,RGB(255,255,255)); + SetBkMode((HDC)wParam,OPAQUE); + *bReturn=(INT_PTR)GetStockObject(WHITE_BRUSH); + return TRUE; + } + else { + SetBkMode((HDC)wParam,TRANSPARENT); + *bReturn=(INT_PTR)GetStockObject(NULL_BRUSH); + return TRUE; + } + } + break; + } + return FALSE; +} + +INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + static HWND hdlgPage; + + switch(message) { + case WM_INITDIALOG: + SendMessage(hdlg,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_DBTOOL))); + hdlgPage=NULL; + SendMessage(hdlg,WZM_GOTOPAGE,IDD_WELCOME,(LPARAM)WelcomeDlgProc); + TranslateDialogDefault(hdlg); + return TRUE; + case WZM_GOTOPAGE: + if(hdlgPage!=NULL) DestroyWindow(hdlgPage); + EnableWindow(GetDlgItem(hdlg,IDC_BACK),TRUE); + EnableWindow(GetDlgItem(hdlg,IDOK),TRUE); + EnableWindow(GetDlgItem(hdlg,IDCANCEL),TRUE); + SetDlgItemText(hdlg,IDCANCEL,TranslateT("Cancel")); + hdlgPage=CreateDialog(hInst,MAKEINTRESOURCE(wParam),hdlg,(DLGPROC)lParam); + TranslateDialogDefault(hdlgPage); + SetWindowPos(hdlgPage,0,0,0,0,0,SWP_NOZORDER|SWP_NOSIZE); + ShowWindow(hdlgPage,SW_SHOW); + break; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + case IDOK: + SendMessage(hdlgPage,WZN_PAGECHANGING,wParam,0); + SendMessage(hdlgPage,message,wParam,lParam); + break; + case IDCANCEL: + if(SendMessage(hdlgPage,WZN_CANCELCLICKED,0,0)) break; + EndDialog(hdlg,0); + break; + } + break; + case WM_DESTROY: + if (opts.hFile) + CloseHandle(opts.hFile); + if (opts.hOutFile) + CloseHandle(opts.hOutFile); + DestroyWindow(hdlgPage); + if(hBoldFont!=NULL) DeleteObject(hBoldFont); + if(hEmfHeaderLogo!=NULL) DeleteEnhMetaFile(hEmfHeaderLogo); + break; + } + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/src/worker.cpp b/plugins/Dbx_mmap_SA/Dbtool/src/worker.cpp new file mode 100644 index 0000000000..dd73c83947 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Dbtool/src/worker.cpp @@ -0,0 +1,76 @@ +/* +Miranda Database Tool +Copyright (C) 2001-2005 Richard Hughes + +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" + +void ProcessingDone(void); +int WorkInitialChecks(int firstTime); +int WorkModuleChain(int firstTime); +int WorkUser(int firstTime); +int WorkContactChain(int firstTime); +int WorkAggressive(int firstTime); +int WorkFinalTasks(int firstTime); + +extern HANDLE hEventRun,hEventAbort; +extern int errorCount; +time_t ts; +DBHeader dbhdr; +DWORD spaceProcessed,sourceFileSize; +DWORD spaceUsed, sp; + +static int (*Workers[6])(int)= + {WorkInitialChecks,WorkModuleChain,WorkUser,WorkContactChain,WorkAggressive,WorkFinalTasks}; + +void __cdecl WorkerThread(void *unused) +{ + int task,ret,firstTime; + ts=time(NULL); + + AddToStatus(STATUS_MESSAGE,TranslateT("Database worker thread activated")); + SetFilePointer(opts.hFile,0,NULL,FILE_BEGIN); + spaceUsed=1; spaceProcessed=0; sp=0; + firstTime=0; + + for(task=0;;) { + if (spaceProcessed/(spaceUsed/1000+1) > sp) { + sp = spaceProcessed/(spaceUsed/1000+1); + SetProgressBar(sp); + } + WaitForSingleObject(hEventRun,INFINITE); + if(WaitForSingleObject(hEventAbort,0)==WAIT_OBJECT_0) { + AddToStatus(STATUS_FATAL,TranslateT("Processing aborted by user")); + break; + } + ret=Workers[task](firstTime); + firstTime=0; + if(ret==ERROR_NO_MORE_ITEMS) { + if (++task==sizeof(Workers)/sizeof(Workers[0])) { + AddToStatus(STATUS_MESSAGE,TranslateT("Elapsed time: %d sec"), time(NULL)-ts); + if(errorCount) + AddToStatus(STATUS_SUCCESS,TranslateT("All tasks completed but with errors (%d)"),errorCount); + else + AddToStatus(STATUS_SUCCESS,TranslateT("All tasks completed successfully")); + break; + } + firstTime=1; + } + else if(ret!=ERROR_SUCCESS) + break; + } + ProcessingDone(); +} diff --git a/plugins/Dbx_mmap_SA/Dbtool/user.cpp b/plugins/Dbx_mmap_SA/Dbtool/user.cpp deleted file mode 100644 index 9922f1630f..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/user.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -static DBContact user; -static int phase; -static DWORD ofsUser; - -int WorkSettingsChain(DWORD ofsContact,DBContact *dbc,int firstTime); -int WorkEventChain(DWORD ofsContact,DBContact *dbc,int firstTime); - -int WorkUser(int firstTime) -{ - int first=0; - - if(firstTime) { - AddToStatus(STATUS_MESSAGE,TranslateT("Processing user data")); - if (!SignatureValid(dbhdr.ofsUser,DBCONTACT_SIGNATURE)) { - AddToStatus(STATUS_ERROR,TranslateT("User corrupted, this could cause major problems")); - return ERROR_NO_MORE_ITEMS; - } - if(ReadSegment(dbhdr.ofsUser,&user,sizeof(DBContact))!=ERROR_SUCCESS) - return ERROR_NO_MORE_ITEMS; - if(user.ofsNext) { - AddToStatus(STATUS_WARNING,TranslateT("More than one user contact: keeping only first")); - user.ofsNext=0; - } - if ((ofsUser=WriteSegment(WSOFS_END,&user,sizeof(DBContact)))==WS_ERROR) - return ERROR_HANDLE_DISK_FULL; - dbhdr.ofsUser=ofsUser; - phase=0; - first=1; - } - switch(phase) { - int ret; - - case 0: - ret=WorkSettingsChain(ofsUser,&user,first); - if(ret==ERROR_NO_MORE_ITEMS) { - phase++; first=1; - } - else if(ret) return ret; - else break; - case 1: - ret=WorkEventChain(ofsUser,&user,first); - if(ret==ERROR_NO_MORE_ITEMS) { - if(WriteSegment(ofsUser,&user,sizeof(DBContact))==WS_ERROR) - return ERROR_HANDLE_DISK_FULL; - return ERROR_NO_MORE_ITEMS; - } - else if(ret) return ret; - break; - } - return ERROR_SUCCESS; -} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Dbtool/utf.cpp b/plugins/Dbx_mmap_SA/Dbtool/utf.cpp deleted file mode 100644 index c56db053d8..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/utf.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - -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 "dbtool.h" - -bool is_utf8_string(const char* str) -{ - int expect_bytes = 0, utf_found = 0; - - if (!str) return 0; - - while (*str) { - if ((*str & 0x80) == 0) { - /* Looks like an ASCII character */ - if (expect_bytes) - /* byte of UTF-8 character expected */ - return 0; - } - else { - /* Looks like byte of an UTF-8 character */ - if (expect_bytes) { - /* expect_bytes already set: first byte of UTF-8 char already seen */ - if ((*str & 0xC0) != 0x80) { - /* again first byte ?!?! */ - return 0; - } - } - else { - /* First byte of the UTF-8 character */ - /* count initial one bits and set expect_bytes to 1 less */ - char ch = *str; - while (ch & 0x80) { - expect_bytes++; - ch = (ch & 0x7f) << 1; - } - } - /* OK, next byte of UTF-8 character */ - /* Decrement number of expected bytes */ - if ( --expect_bytes == 0 ) - utf_found = 1; - } - str++; - } - - return (utf_found && expect_bytes == 0); -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/welcome.cpp b/plugins/Dbx_mmap_SA/Dbtool/welcome.cpp deleted file mode 100644 index 291281e70a..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/welcome.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -INT_PTR CALLBACK WelcomeDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - static HENHMETAFILE hEmfWatermark; - static HFONT hTitleFont; - INT_PTR bReturn; - - if(DoMyControlProcessing(hdlg,message,wParam,lParam,&bReturn)) return bReturn; - switch(message) { - case WM_INITDIALOG: - - { - NONCLIENTMETRICS ncm = {0}; - ncm.cbSize = sizeof(ncm); - SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); - LOGFONT TitleLogFont = ncm.lfMessageFont; - TitleLogFont.lfWeight = FW_BOLD; - lstrcpy(TitleLogFont.lfFaceName, TEXT("Verdana Bold")); - - HDC hdc = GetDC(NULL); - INT FontSize = 12; - TitleLogFont.lfHeight = 0 - GetDeviceCaps(hdc, LOGPIXELSY) * FontSize / 72; - hTitleFont = CreateFontIndirect(&TitleLogFont); - ReleaseDC(NULL, hdc); - } - SendDlgItemMessage(hdlg,IDC_TITLE,WM_SETFONT,(WPARAM)hTitleFont,0); - EnableWindow(GetDlgItem(GetParent(hdlg),IDC_BACK),FALSE); - return FALSE; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDOK: - SendMessage(GetParent(hdlg),WZM_GOTOPAGE,IDD_SELECTDB,(LPARAM)SelectDbDlgProc); - break; - } - break; - case WM_DESTROY: - DeleteEnhMetaFile(hEmfWatermark); - DeleteObject(hTitleFont); - break; - } - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/wizard.cpp b/plugins/Dbx_mmap_SA/Dbtool/wizard.cpp deleted file mode 100644 index 8f3a9d5ca8..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/wizard.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* -Miranda Database Tool -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" - -static HFONT hBoldFont=NULL; -static HENHMETAFILE hEmfHeaderLogo=NULL; - -static BOOL CALLBACK MyControlsEnumChildren(HWND hwnd,LPARAM lParam) -{ - DWORD style=GetWindowLongPtr(hwnd,GWL_STYLE); - DWORD exstyle=GetWindowLongPtr(hwnd,GWL_EXSTYLE); - char szClass[64]; - int makeBold=0; - - GetClassNameA(hwnd,szClass,sizeof(szClass)); - if (!strcmp(szClass,"Static")) { - if (((style&SS_TYPEMASK)==SS_LEFT || (style&SS_TYPEMASK)==SS_CENTER || (style&SS_TYPEMASK)==SS_RIGHT) && exstyle&WS_EX_CLIENTEDGE) - makeBold=1; - } - else if (!strcmp(szClass,"Button")) { - if(exstyle&WS_EX_CLIENTEDGE) - makeBold=1; - } - if(makeBold) { - if(hBoldFont==NULL) { - LOGFONT lf; - hBoldFont=(HFONT)SendMessage(hwnd,WM_GETFONT,0,0); - GetObject(hBoldFont,sizeof(lf),&lf); - lf.lfWeight=FW_BOLD; - hBoldFont=CreateFontIndirect(&lf); - } - SendMessage(hwnd,WM_SETFONT,(WPARAM)hBoldFont,0); - SetWindowLongPtr(hwnd,GWL_EXSTYLE,exstyle&~WS_EX_CLIENTEDGE); - SetWindowPos(hwnd,0,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_FRAMECHANGED); - } - return TRUE; -} - -int DoMyControlProcessing(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam,INT_PTR *bReturn) -{ - switch(message) { - case WM_INITDIALOG: - EnumChildWindows(hdlg,MyControlsEnumChildren,0); - - break; - case WM_CTLCOLORSTATIC: - if (GetWindowLongPtr((HWND)lParam, GWL_ID) == IDC_HDRLOGO){ - SetBkColor((HDC)wParam,RGB(255,255,255)); - *bReturn=(BOOL)GetStockObject(WHITE_BRUSH); - return TRUE; - } - if ((GetWindowLongPtr((HWND)lParam,GWL_STYLE)&0xFFFF)==0) { - TCHAR szText[256]; - GetWindowText((HWND)lParam,szText,SIZEOF(szText)); - if (!_tcscmp(szText,_T("whiterect"))) { - SetTextColor((HDC)wParam,RGB(255,255,255)); - SetBkColor((HDC)wParam,RGB(255,255,255)); - SetBkMode((HDC)wParam,OPAQUE); - *bReturn=(INT_PTR)GetStockObject(WHITE_BRUSH); - return TRUE; - } - else { - SetBkMode((HDC)wParam,TRANSPARENT); - *bReturn=(INT_PTR)GetStockObject(NULL_BRUSH); - return TRUE; - } - } - break; - } - return FALSE; -} - -INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - static HWND hdlgPage; - - switch(message) { - case WM_INITDIALOG: - SendMessage(hdlg,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_DBTOOL))); - hdlgPage=NULL; - SendMessage(hdlg,WZM_GOTOPAGE,IDD_WELCOME,(LPARAM)WelcomeDlgProc); - TranslateDialogDefault(hdlg); - return TRUE; - case WZM_GOTOPAGE: - if(hdlgPage!=NULL) DestroyWindow(hdlgPage); - EnableWindow(GetDlgItem(hdlg,IDC_BACK),TRUE); - EnableWindow(GetDlgItem(hdlg,IDOK),TRUE); - EnableWindow(GetDlgItem(hdlg,IDCANCEL),TRUE); - SetDlgItemText(hdlg,IDCANCEL,TranslateT("Cancel")); - hdlgPage=CreateDialog(hInst,MAKEINTRESOURCE(wParam),hdlg,(DLGPROC)lParam); - TranslateDialogDefault(hdlgPage); - SetWindowPos(hdlgPage,0,0,0,0,0,SWP_NOZORDER|SWP_NOSIZE); - ShowWindow(hdlgPage,SW_SHOW); - break; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - case IDOK: - SendMessage(hdlgPage,WZN_PAGECHANGING,wParam,0); - SendMessage(hdlgPage,message,wParam,lParam); - break; - case IDCANCEL: - if(SendMessage(hdlgPage,WZN_CANCELCLICKED,0,0)) break; - EndDialog(hdlg,0); - break; - } - break; - case WM_DESTROY: - if (opts.hFile) - CloseHandle(opts.hFile); - if (opts.hOutFile) - CloseHandle(opts.hOutFile); - DestroyWindow(hdlgPage); - if(hBoldFont!=NULL) DeleteObject(hBoldFont); - if(hEmfHeaderLogo!=NULL) DeleteEnhMetaFile(hEmfHeaderLogo); - break; - } - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Dbtool/worker.cpp b/plugins/Dbx_mmap_SA/Dbtool/worker.cpp deleted file mode 100644 index dd73c83947..0000000000 --- a/plugins/Dbx_mmap_SA/Dbtool/worker.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* -Miranda Database Tool -Copyright (C) 2001-2005 Richard Hughes - -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" - -void ProcessingDone(void); -int WorkInitialChecks(int firstTime); -int WorkModuleChain(int firstTime); -int WorkUser(int firstTime); -int WorkContactChain(int firstTime); -int WorkAggressive(int firstTime); -int WorkFinalTasks(int firstTime); - -extern HANDLE hEventRun,hEventAbort; -extern int errorCount; -time_t ts; -DBHeader dbhdr; -DWORD spaceProcessed,sourceFileSize; -DWORD spaceUsed, sp; - -static int (*Workers[6])(int)= - {WorkInitialChecks,WorkModuleChain,WorkUser,WorkContactChain,WorkAggressive,WorkFinalTasks}; - -void __cdecl WorkerThread(void *unused) -{ - int task,ret,firstTime; - ts=time(NULL); - - AddToStatus(STATUS_MESSAGE,TranslateT("Database worker thread activated")); - SetFilePointer(opts.hFile,0,NULL,FILE_BEGIN); - spaceUsed=1; spaceProcessed=0; sp=0; - firstTime=0; - - for(task=0;;) { - if (spaceProcessed/(spaceUsed/1000+1) > sp) { - sp = spaceProcessed/(spaceUsed/1000+1); - SetProgressBar(sp); - } - WaitForSingleObject(hEventRun,INFINITE); - if(WaitForSingleObject(hEventAbort,0)==WAIT_OBJECT_0) { - AddToStatus(STATUS_FATAL,TranslateT("Processing aborted by user")); - break; - } - ret=Workers[task](firstTime); - firstTime=0; - if(ret==ERROR_NO_MORE_ITEMS) { - if (++task==sizeof(Workers)/sizeof(Workers[0])) { - AddToStatus(STATUS_MESSAGE,TranslateT("Elapsed time: %d sec"), time(NULL)-ts); - if(errorCount) - AddToStatus(STATUS_SUCCESS,TranslateT("All tasks completed but with errors (%d)"),errorCount); - else - AddToStatus(STATUS_SUCCESS,TranslateT("All tasks completed successfully")); - break; - } - firstTime=1; - } - else if(ret!=ERROR_SUCCESS) - break; - } - ProcessingDone(); -} diff --git a/plugins/Dbx_mmap_SA/Import_SA/ICQserver.cpp b/plugins/Dbx_mmap_SA/Import_SA/ICQserver.cpp deleted file mode 100644 index 62666c7531..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/ICQserver.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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. - -*/ - -// ============== -// == INCLUDES == -// ============== - -#include "import.h" - -#include "ICQserver.h" - -// ==================== -// ==================== -// == IMPLEMENTATION == -// ==================== -// ==================== - -BOOL CALLBACK ICQserverPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,0,0); - SendMessage(GetParent(hdlg),WIZM_ENABLEBUTTON,1,0); - SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,2,0); - TranslateDialogDefault(hdlg); - ICQserverImport(); - return TRUE; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDOK: - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_FINISHED,(LPARAM)FinishedPageProc); - break; - case IDCANCEL: - PostMessage(GetParent(hdlg),WM_CLOSE,0,0); - break; - } - break; - } - return FALSE; -} - -static void ICQserverImport() -{ - // Clear last update stamp - DBDeleteContactSetting(NULL, szICQModuleName[ iICQAccount ], "SrvLastUpdate"); - DBDeleteContactSetting(NULL, szICQModuleName[ iICQAccount ], "SrvRecordCount"); - - // Enable contacts downloading - DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "UseServerCList", 1); - DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "AddServerNew", 1); - DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "UseServerNicks", 1); - DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "ServerAddRemove", 1); -} diff --git a/plugins/Dbx_mmap_SA/Import_SA/ICQserver.h b/plugins/Dbx_mmap_SA/Import_SA/ICQserver.h deleted file mode 100644 index 864890a978..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/ICQserver.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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. - -*/ - - - -#ifndef ICQSERVER_H -#define ICQSERVER_H - -#include - -// ====================== -// == GLOBAL FUNCTIONS == -// ====================== - -// ===================== -// == LOCAL FUNCTIONS == -// ===================== - -// Main function -static void ICQserverImport(); - -// GUI callbacks -INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); - - -// ====================== -// == GLOBAL VARIABLES == -// ====================== - -extern int cICQAccounts; -extern char ** szICQModuleName; -extern TCHAR ** tszICQAccountName; -extern int iICQAccount; - -// ===================== -// == LOCAL VARIABLES == -// ===================== - -// ============= -// == DEFINES == -// ============= - -#endif \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Import_SA/Version.rc b/plugins/Dbx_mmap_SA/Import_SA/Version.rc deleted file mode 100644 index 9ef5fda998..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/Version.rc +++ /dev/null @@ -1,42 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "afxres.h" -#include "version.h" - -#ifdef _WIN32 -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#endif //_WIN32 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION __FILEVERSION_STRING - PRODUCTVERSION __FILEVERSION_STRING - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x0L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "FileDescription", __DESCRIPTIONSHORT - VALUE "InternalName", __PLUGIN_NAME - VALUE "LegalCopyright", __COPYRIGHT - VALUE "OriginalFilename", __FILENAME - VALUE "ProductName", __PLUGIN_NAME - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END diff --git a/plugins/Dbx_mmap_SA/Import_SA/encryption.cpp b/plugins/Dbx_mmap_SA/Import_SA/encryption.cpp deleted file mode 100644 index ede73c006a..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/encryption.cpp +++ /dev/null @@ -1,310 +0,0 @@ -// (C) Artem Shpynov aka FYR and Igonin Vitaliy aka chaos.persei, 2007 - 2008 - -#include "import.h" - -typedef struct{ - void* (__stdcall *GenerateKey)(char* pwd); - void (__stdcall *FreeKey)(void* key); - void (__stdcall *EncryptMem)(BYTE* data, int size, void* key); - void (__stdcall *DecryptMem)(BYTE* data, int size, void* key); - - char* Name; - char* Info; - char* Author; - char* Site; - char* Email; - - DWORD Version; - - WORD uid; -} Cryptor; - -typedef struct{ - char dllname[255]; - HMODULE hLib; - Cryptor* cryptor; -} CryptoModule; - -BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - -char encryptKey[255]; -size_t encryptKeyLength; - -int wrongPass = 0; -void* key; - -Cryptor* CryptoEngine = NULL; - -int ModulesCount = 0; -CryptoModule* Modules[100]; - - -void zero_fill(BYTE * pBuf, size_t bufSize) -{ - size_t i; - for(i = 0; i < bufSize; i++) - pBuf[i] = 0; -} - -void InitSecurity() -{ - HMODULE hLib; - WIN32_FIND_DATAA fd; - HANDLE hFile; - - Cryptor* (__stdcall *GetCryptor)(); - - { - TCHAR szMirandaDir[MAX_PATH]; - TCHAR *str2; - - szMirandaDir[ 0 ] = 0; - - GetModuleFileName(NULL,szMirandaDir,SIZEOF(szMirandaDir)); - str2 = _tcsrchr(szMirandaDir,'\\'); - if ( str2 != NULL ) - *str2=0; - _tchdir(szMirandaDir); - } - - hFile = FindFirstFileA(".\\plugins\\cryptors\\*.dll", &fd); - - AddMessage(LPGEN("Scanning cryptors directory")); - - ModulesCount = 0; - while (hFile != INVALID_HANDLE_VALUE) - { - char tmp[MAX_PATH], buf[255]; - strcpy(tmp, ".\\plugins\\cryptors\\"); - strcat(tmp, fd.cFileName); - - hLib = LoadLibraryA(tmp); - if(hLib){ - GetCryptor = (Cryptor* (__stdcall *)()) GetProcAddress(hLib, "GetCryptor"); - if(GetCryptor){ - //TCHAR Name[100], Version[100], DllName[100]; - - - Modules[ModulesCount] = (CryptoModule*) malloc(sizeof(CryptoModule)); - Modules[ModulesCount]->cryptor = GetCryptor(); - strcpy(Modules[ModulesCount]->dllname, fd.cFileName); - Modules[ModulesCount]->hLib = hLib; - - _snprintf(buf,SIZEOF(buf),"%d.%d.%d.%d", HIBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), HIBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version))); - // Unsane: none -/* - - mbstowcs(Name, Modules[ModulesCount]->cryptor->Name, 100); - mbstowcs(Version, buf, 100); - mbstowcs(DllName, Modules[ModulesCount]->dllname, 100); - -*/ - AddMessage(LPGEN("Cryptor loaded: %s [%s] (%s)"), Modules[ModulesCount]->cryptor->Name, buf, Modules[ModulesCount]->dllname); - - ModulesCount++; - }else{ - FreeLibrary(hLib); - } - } - if(ModulesCount >= 100) break; - if (!FindNextFileA(hFile, &fd)) break; - } - - AddMessage(LPGEN("%d crypto modules loaded"), ModulesCount); -} - -void UnloadSecurity() -{ - int i; - - if(CryptoEngine) CryptoEngine->FreeKey(key); - - for(i = 0; i < ModulesCount; i++) - { - FreeLibrary(Modules[i]->hLib); - free(Modules[i]); - } -} - -void EncoderInit() -{ - encryptKey[encryptKeyLength] = 0; - key = CryptoEngine->GenerateKey(encryptKey); -} - -void EncodeCopyMemory(BYTE * dst, void * src, size_t size ) -{ - memcpy(dst, src, size); - CryptoEngine->EncryptMem(dst, (int)size, key); -} - -void DecodeCopyMemory(BYTE * dst, void * src, size_t size ) -{ - memcpy(dst, src, size); - CryptoEngine->DecryptMem(dst, (int)size, key); -} - - -void EncodeMemory(BYTE * mem, size_t size) -{ - CryptoEngine->EncryptMem(mem, (int)size, key); -} - -void DecodeMemory(BYTE * mem, size_t size) -{ - CryptoEngine->DecryptMem(mem, (int)size, key); -} - -int bCheckingPass = 0; - -int CheckPassword(WORD checkWord, WORD cryptorUID, TCHAR * szDBName) -{ - WORD ver; - int res; - - if(bCheckingPass) return 0; - bCheckingPass = 1; - - { - int i; - int Found = 0; - for(i = 0; i < ModulesCount; i++) { - if(cryptorUID == Modules[i]->cryptor->uid){ - CryptoEngine = Modules[i]->cryptor; - Found = 1; - break; - } - } - if (!Found){ - AddMessage(LPGEN("Sorry, but your database encrypted with unknown module"), MB_OK); - bCheckingPass = 0; - return 0; - } - } - - { - //wchar_t Name[100], Author[100]; - - // Unsane: none - AddMessage(LPGEN("Database encrypted with %s by %s"), CryptoEngine->Name, CryptoEngine->Author); - } - - while(1){ - res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LOGIN), NULL, (DLGPROC)DlgStdInProc, (LPARAM)szDBName); - if(res == IDCANCEL) - { - wrongPass = 0; - bCheckingPass = 0; - return 0; - } - if(encryptKeyLength < 1) continue; - EncoderInit(); - DecodeCopyMemory((BYTE*)&ver, &checkWord, sizeof(checkWord)); - if(ver == 0x5195) - { - wrongPass = 0; - bCheckingPass = 0; - return 1; - } - wrongPass++; - } - - bCheckingPass = 0; -} - - -UINT oldLangID = 0; -void LanguageChanged(HWND hDlg) -{ - UINT LangID = (UINT)GetKeyboardLayout(0); - char Lang[3] = {0}; - if (LangID != oldLangID) - { - oldLangID = LangID; - GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); - SetDlgItemTextA(hDlg, IDC_LANG, Lang); - } -} - -BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) -{ - HICON hIcon = 0; - TCHAR tszHeaderTxt[256]; - switch(uMsg) - { - case WM_INITDIALOG: - { - HWND hwndCtrl; - TranslateDialogDefault(hDlg); - - hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PASS)); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); - - if (!wrongPass) - { - mir_sntprintf(tszHeaderTxt, SIZEOF(tszHeaderTxt), _T("%s\n%s"), TranslateT("Please type in your password for"), lParam); - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), tszHeaderTxt); - } - else - { - if (wrongPass > 2) - { - hwndCtrl = GetDlgItem(hDlg, IDC_USERPASS); - EnableWindow(hwndCtrl, FALSE); - hwndCtrl = GetDlgItem(hDlg, IDOK); - EnableWindow(hwndCtrl, FALSE); - - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Too many errors!")); - } - else - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is not correct!")); - } - oldLangID = 0; - SetTimer(hDlg,1,200,NULL); - LanguageChanged(hDlg); - return TRUE; - } - - case WM_CTLCOLORSTATIC: - { - if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) - { - SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkMode((HDC)wParam, TRANSPARENT); - return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); - } - - return FALSE; - } - - case WM_COMMAND: - { - UINT uid = LOWORD(wParam); - - if(uid == IDOK){ - if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) - { - encryptKeyLength = GetDlgItemTextA(hDlg, IDC_USERPASS, encryptKey, 254); - EndDialog(hDlg,IDOK); - }else{ - - } - }else if(uid == IDCANCEL){ - EndDialog(hDlg,IDCANCEL); - } - } - case WM_TIMER: - { - LanguageChanged(hDlg); - return FALSE; - } - case WM_DESTROY: - { - KillTimer(hDlg, 1); - DestroyIcon(hIcon); - return FALSE; - } - } - - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Import_SA/import.h b/plugins/Dbx_mmap_SA/Import_SA/import.h deleted file mode 100644 index 1c50146a15..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/import.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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 _LOGGING 1 - -#define MIRANDA_VER 0x0A00 - -#define WINVER 0x0501 -#define _WIN32_WINNT 0x0501 -#define _WIN32_IE 0x0501 - -#include - -#include -#include // datetimepicker - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Unsane: none -#include "resource.h" - -// ** Global constants - -#define IMPORT_MODULE "MIMImport" // Module name -#define IMPORT_SERVICE "MIMImport/Import" // Service for menu item - -// Keys -#define IMP_KEY_FR "FirstRun" // First run - - -#define WIZM_GOTOPAGE (WM_USER+10) //wParam=resource id, lParam=dlgproc -#define WIZM_DISABLEBUTTON (WM_USER+11) //wParam=0:back, 1:next, 2:cancel -#define WIZM_SETCANCELTEXT (WM_USER+12) //lParam=(char*)newText -#define WIZM_ENABLEBUTTON (WM_USER+13) //wParam=0:back, 1:next, 2:cancel - -#define PROGM_SETPROGRESS (WM_USER+10) //wParam=0..100 -#define PROGM_ADDMESSAGE (WM_USER+11) //lParam=(char*)szText -#define SetProgress(n) SendMessage(hdlgProgress,PROGM_SETPROGRESS,n,0) - -#define ICQOSCPROTONAME "ICQ" -#define MSNPROTONAME "MSN" -#define YAHOOPROTONAME "YAHOO" -#define NSPPROTONAME "NET_SEND" -#define ICQCORPPROTONAME "ICQ Corp" -#define AIMPROTONAME "AIM" - -// Import type -#define IMPORT_CONTACTS 0 -#define IMPORT_ALL 1 -#define IMPORT_CUSTOM 2 - -// Custom import options -#define IOPT_ADDUNKNOWN 1 -#define IOPT_MSGSENT 2 -#define IOPT_MSGRECV 4 -#define IOPT_URLSENT 8 -#define IOPT_URLRECV 16 -#define IOPT_AUTHREQ 32 -#define IOPT_ADDED 64 -#define IOPT_FILESENT 128 -#define IOPT_FILERECV 256 -#define IOPT_OTHERSENT 512 -#define IOPT_OTHERRECV 1024 -#define IOPT_SYSTEM 2048 -#define IOPT_CONTACTS 4096 -#define IOPT_GROUPS 8192 - -extern HINSTANCE hInst; - -void AddMessage( const char* fmt, ... ); -void DecodeMemory(BYTE * mem, size_t size); -void DecodeCopyMemory(BYTE * dst, void * src, size_t size ); - -int CreateGroup(BYTE type, const char* name, HANDLE hContact); - -extern HWND hdlgProgress; - -extern DWORD nDupes, nContactsCount, nMessagesCount, nGroupsCount, nSkippedEvents, nSkippedContacts; diff --git a/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj b/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj index f2143c95e4..a7eec29388 100644 --- a/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj +++ b/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj @@ -73,7 +73,7 @@ Disabled ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;IMPORT_EXPORTS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL true @@ -81,7 +81,6 @@ import.h Level3 EditAndContinue - 4996;%(DisableSpecificWarnings) _DEBUG;%(PreprocessorDefinitions) @@ -105,14 +104,13 @@ Disabled ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - WIN64;_DEBUG;_WINDOWS;_USRDLL;IMPORT_EXPORTS;%(PreprocessorDefinitions) + WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL true Use import.h Level3 - 4996;%(DisableSpecificWarnings) _DEBUG;%(PreprocessorDefinitions) @@ -138,7 +136,7 @@ OnlyExplicitInline Size ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;IMPORT_EXPORTS;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true false true @@ -146,14 +144,12 @@ Use import.h Level3 - 4996;%(DisableSpecificWarnings) NDEBUG;%(PreprocessorDefinitions) ..\..\..\include;..\..\..\include\msapi - /ALIGN:4096 /ignore:4108 %(AdditionalOptions) comctl32.lib;%(AdditionalDependencies) type=%27Win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 processorArchitecture=%27X86%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27;%(AdditionalManifestDependencies) true @@ -175,7 +171,7 @@ OnlyExplicitInline Size ..\..\..\include;..\..\ExternalAPI;%(AdditionalIncludeDirectories) - WIN64;NDEBUG;_WINDOWS;_USRDLL;IMPORT_EXPORTS;%(PreprocessorDefinitions) + WIN64;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true false true @@ -183,14 +179,12 @@ Use import.h Level3 - 4996;%(DisableSpecificWarnings) NDEBUG;%(PreprocessorDefinitions) ..\..\..\include;..\..\..\include\msapi - /ALIGN:4096 /ignore:4108 %(AdditionalOptions) comctl32.lib;%(AdditionalDependencies) type=%27Win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 processorArchitecture=%27*%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27;%(AdditionalManifestDependencies) true @@ -207,35 +201,27 @@ - - - + + + Create - - - - + + + + - - - - - - + + + + + + - - - - - - - - - - + + diff --git a/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj.filters b/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj.filters index f1fec2b705..f5f6f3b161 100644 --- a/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/Import_SA/import_sa_10.vcxproj.filters @@ -13,78 +13,55 @@ {e10cb216-83c1-4eb2-95ec-09f1e42a2c96} ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe - - {8ad8cb39-e207-46f6-8fbf-1f5871148568} - - + 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 - - Documentation - - - Documentation - - - Documentation - - - Documentation - - - Resource Files - - - Resource Files - - - - + Resource Files - + Resource Files diff --git a/plugins/Dbx_mmap_SA/Import_SA/main.cpp b/plugins/Dbx_mmap_SA/Import_SA/main.cpp deleted file mode 100644 index d464f8bb55..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/main.cpp +++ /dev/null @@ -1,541 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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 "import.h" -#include "version.h" - -void FreeVariant( DBVARIANT* dbv ); -void WriteVariant( HANDLE hContact, const char* module, const char* var, DBVARIANT* dbv ); - -BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei); - -int nImportOption; -int nCustomOptions; -int hLangpack; - -int cICQAccounts = 0; -char ** szICQModuleName = NULL; -TCHAR ** tszICQAccountName = NULL; -int iICQAccount = 0; - -static HANDLE hHookModulesLoaded = NULL; -static HANDLE hHookOnExit = NULL; -static HANDLE hImportService = NULL; - -INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); - -HINSTANCE hInst; - -static HWND hwndWizard = NULL; - -PLUGININFOEX pluginInfo = { - sizeof(PLUGININFOEX), - __PLUGIN_NAME, - __VERSION_DWORD, - __DESCRIPTION, - __AUTHOR, - __AUTHOREMAIL, - __COPYRIGHT, - __AUTHORWEB, - UNICODE_AWARE, //{2D77A746-00A6-4343-BFC5-F808CDD772EA} - {0x2d77a746, 0xa6, 0x4343, { 0xbf, 0xc5, 0xf8, 0x8, 0xcd, 0xd7, 0x72, 0xea }} -}; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) -{ - hInst = hinstDLL; - return TRUE; -} - -static INT_PTR ImportCommand(WPARAM wParam,LPARAM lParam) -{ - if (IsWindow(hwndWizard)) { - SetForegroundWindow(hwndWizard); - SetFocus(hwndWizard); - } - else hwndWizard = CreateDialog(hInst, MAKEINTRESOURCE(IDD_WIZARD), NULL, WizardDlgProc); - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// MirandaPluginInfoEx - returns an information about a plugin - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) -{ - return &pluginInfo; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// MirandaInterfaces - returns the protocol interface to the core - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_IMPORT, MIID_LAST}; - -///////////////////////////////////////////////////////////////////////////////////////// -// Performs a primary set of actions upon plugin loading - -static int ModulesLoaded(WPARAM wParam, LPARAM lParam) -{ - int nProtocols = 0; - int n; - PROTOCOLDESCRIPTOR **ppProtos = NULL; - - if (DBGetContactSettingByte(NULL, IMPORT_MODULE, IMP_KEY_FR, 1)) - return 0; - - // Only autorun import wizard if at least one protocol is installed - CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&nProtocols, (LPARAM)&ppProtos); - for (n=0; n < nProtocols; n++) { - if (ppProtos[n]->type == PROTOTYPE_PROTOCOL) { - CallService(IMPORT_SERVICE, 0, 0); - DBWriteContactSettingByte(NULL, IMPORT_MODULE, IMP_KEY_FR, 1); - break; - } } - return 0; -} - -static int OnExit(WPARAM wParam, LPARAM lParam) -{ - if ( hwndWizard ) - SendMessage(hwndWizard, WM_CLOSE, 0, 0); - return 0; -} - -extern "C" __declspec(dllexport) int Load(void) -{ - - mir_getLP( &pluginInfo ); - - hImportService = CreateServiceFunction(IMPORT_SERVICE, ImportCommand); - { - CLISTMENUITEM mi; - ZeroMemory(&mi, sizeof(mi)); - mi.cbSize = sizeof(mi); - mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_IMPORT)); - mi.pszName = LPGEN("&Import..."); - mi.position = 500050000; - mi.pszService = IMPORT_SERVICE; - Menu_AddMainMenuItem(&mi); - } - hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); - hHookOnExit = HookEvent(ME_SYSTEM_OKTOEXIT, OnExit); - { - INITCOMMONCONTROLSEX icex; - icex.dwSize = sizeof(icex); - icex.dwICC = ICC_DATE_CLASSES; - InitCommonControlsEx(&icex); - } - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// -// Unload a plugin - -extern "C" __declspec(dllexport) int Unload(void) -{ - if (hHookModulesLoaded) - UnhookEvent(hHookModulesLoaded); - if (hHookOnExit) - UnhookEvent(hHookOnExit); - if (hImportService) - DestroyServiceFunction(hImportService); - - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -BOOL IsProtocolLoaded(char* pszProtocolName) -{ - return CallService(MS_PROTO_ISPROTOCOLLOADED, 0, (LPARAM)pszProtocolName) ? TRUE : FALSE; -} - -BOOL EnumICQAccounts() -{ - int count, i = 0; - PROTOACCOUNT ** accs; - - while (cICQAccounts) - { - cICQAccounts--; - free(szICQModuleName[cICQAccounts]); - free(tszICQAccountName[cICQAccounts]); - } - - ProtoEnumAccounts(&count, &accs); - szICQModuleName = (char**)realloc(szICQModuleName, count * sizeof(char**)); - tszICQAccountName = (TCHAR**)realloc(tszICQAccountName, count * sizeof(TCHAR**)); - while (i < count) - { - if ((0 == strcmp(ICQOSCPROTONAME, accs[i]->szProtoName)) && accs[i]->bIsEnabled) - { - szICQModuleName[cICQAccounts] = strdup(accs[i]->szModuleName); - tszICQAccountName[cICQAccounts] = _tcsdup(accs[i]->tszAccountName); - cICQAccounts++; - } - i++; - } - return cICQAccounts != 0; -} - -void FreeICQAccountsList() -{ - while (cICQAccounts) - { - cICQAccounts--; - free(szICQModuleName[cICQAccounts]); - free(tszICQAccountName[cICQAccounts]); - } - - if (szICQModuleName) - free(szICQModuleName); - if (tszICQAccountName) - free(tszICQAccountName); - - szICQModuleName = NULL; - tszICQAccountName = NULL; -} - -HANDLE HContactFromNumericID(char* pszProtoName, char* pszSetting, DWORD dwID) -{ - char* szProto; - HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - while (hContact != NULL) - { - if (DBGetContactSettingDword(hContact, pszProtoName, pszSetting, 0) == dwID) - { - szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - if (szProto != NULL && !strcmp(szProto, pszProtoName)) - return hContact; - } - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); - } - return INVALID_HANDLE_VALUE; -} - -HANDLE HContactFromID(char* pszProtoName, char* pszSetting, char* pszID) -{ - DBVARIANT dbv; - HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - while (hContact != NULL) { - char* szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); - if ( !lstrcmpA(szProto, pszProtoName)) { - if (DBGetContactSettingString(hContact, pszProtoName, pszSetting, &dbv) == 0) { - if (strcmp(pszID, dbv.pszVal) == 0) { - DBFreeVariant(&dbv); - return hContact; - } - DBFreeVariant(&dbv); - } - } - - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); - } - return INVALID_HANDLE_VALUE; -} - -HANDLE HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DWORD uin, int addUnknown) -{ - HANDLE hContact = HContactFromNumericID(szModuleName, "UIN", uin); - if (hContact == NULL) { - AddMessage( LPGEN("Ignored event from/to self")); - return INVALID_HANDLE_VALUE; - } - - if (hContact != INVALID_HANDLE_VALUE) - return hContact; - - if (!addUnknown) - return INVALID_HANDLE_VALUE; - - 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 ); - return hContact; -} - -HANDLE AddContact(HWND hdlgProgress, char* pszProtoName, char* pszUniqueSetting, - DBVARIANT* id, DBVARIANT* nick, DBVARIANT* 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); - if ( CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)pszProtoName) != 0) { - CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); - AddMessage( LPGEN("Failed to add %s contact %s"), pszProtoName, pszUserID ); - FreeVariant( id ); - FreeVariant( nick ); - FreeVariant( group ); - return INVALID_HANDLE_VALUE; - } - - WriteVariant( hContact, pszProtoName, pszUniqueSetting, id ); - - if ( group->type ) - CreateGroup( group->type, group->pszVal, hContact ); - - if ( nick->type && nick->pszVal[0] ) { - WriteVariant( hContact, "CList", "MyHandle", nick ); - if (nick->type == DBVT_UTF8) { - char *tmp = mir_utf8decodeA(nick->pszVal); - AddMessage( LPGEN("Added %s contact %s, '%s'"), pszProtoName, pszUserID, tmp ); - mir_free(tmp); - } - else AddMessage( LPGEN("Added %s contact %s, '%s'"), pszProtoName, pszUserID, nick->pszVal ); - } - else AddMessage( LPGEN("Added %s contact %s"), pszProtoName, pszUserID ); - - FreeVariant( id ); - FreeVariant( nick ); - FreeVariant( group ); - return hContact; -} - -// ------------------------------------------------ -// Creates a group with a specified name in the -// Miranda contact list. -// If contact is specified adds it to group -// ------------------------------------------------ -// Returns 1 if successful and 0 when it fails. -int CreateGroup(BYTE type, const char* name, HANDLE hContact) -{ - int groupId; - TCHAR *tmp, *tszGrpName; - char groupIdStr[11]; - size_t cbName; - - if (type == DBVT_UTF8) - tmp = mir_utf8decodeT( name ); - else if (type == DBVT_WCHAR) - tmp = mir_u2t(( wchar_t* )name ); - else - tmp = mir_a2t( name ); - - if ( tmp == NULL ) - return 0; - - cbName = _tcslen(tmp); - tszGrpName = (TCHAR *)_alloca(( cbName+2 )*sizeof( TCHAR )); - tszGrpName[0] = 1 | GROUPF_EXPANDED; - _tcscpy( tszGrpName+1, tmp ); - mir_free( tmp ); - - // Check for duplicate & find unused id - for (groupId = 0; ; groupId++) { - DBVARIANT dbv; - itoa(groupId, groupIdStr,10); - if (DBGetContactSettingTString(NULL, "CListGroups", groupIdStr, &dbv)) - break; - - 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); - } - - DBFreeVariant(&dbv); - return 0; - } - - DBFreeVariant(&dbv); - } - - DBWriteContactSettingTString( NULL, "CListGroups", groupIdStr, tszGrpName ); - - if (hContact) - DBWriteContactSettingTString( hContact, "CList", "Group", tszGrpName+1 ); - - return 1; -} - -// Returns TRUE if the event already exist in the database -BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) -{ - static DWORD dwPreviousTimeStamp = -1; - static HANDLE hPreviousContact = INVALID_HANDLE_VALUE; - static HANDLE hPreviousDbEvent = NULL; - - HANDLE hExistingDbEvent; - DWORD dwEventTimeStamp; - DBEVENTINFO dbeiExisting; - - // get last event - if (!(hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDLAST, (WPARAM)hContact, 0))) - return FALSE; - - ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); - dbeiExisting.cbSize = sizeof(dbeiExisting); - CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); - dwEventTimeStamp = dbeiExisting.timestamp; - - // compare with last timestamp - if (dbei.timestamp > dwEventTimeStamp) - { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dwEventTimeStamp; - return FALSE; - } - - if (hContact != hPreviousContact) - { - hPreviousContact = hContact; - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dwEventTimeStamp; - - // get first event - if (!(hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDFIRST, (WPARAM)hContact, 0))) - return FALSE; - - ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); - dbeiExisting.cbSize = sizeof(dbeiExisting); - CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); - dwEventTimeStamp = dbeiExisting.timestamp; - - // compare with first timestamp - if (dbei.timestamp <= dwEventTimeStamp) - { - // remember event - dwPreviousTimeStamp = dwEventTimeStamp; - hPreviousDbEvent = hExistingDbEvent; - - if ( dbei.timestamp != dwEventTimeStamp ) - return FALSE; - } - - } - // check for equal timestamps - if (dbei.timestamp == dwPreviousTimeStamp) - { - ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); - dbeiExisting.cbSize = sizeof(dbeiExisting); - CallService(MS_DB_EVENT_GET, (WPARAM)hPreviousDbEvent, (LPARAM)&dbeiExisting); - - if ((dbei.timestamp == dbeiExisting.timestamp) && - (dbei.eventType == dbeiExisting.eventType) && - (dbei.cbBlob == dbeiExisting.cbBlob) && - ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) - return TRUE; - - // find event with another timestamp - hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hPreviousDbEvent, 0); - while (hExistingDbEvent != NULL) - { - ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); - dbeiExisting.cbSize = sizeof(dbeiExisting); - CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); - - if (dbeiExisting.timestamp != dwPreviousTimeStamp) - { - // use found event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - break; - } - - hPreviousDbEvent = hExistingDbEvent; - hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hExistingDbEvent, 0); - } - } - - hExistingDbEvent = hPreviousDbEvent; - - if (dbei.timestamp <= dwPreviousTimeStamp) - { - // look back - 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 - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return FALSE; - } - - // Compare event with import candidate - if ((dbei.timestamp == dbeiExisting.timestamp) && - (dbei.eventType == dbeiExisting.eventType) && - (dbei.cbBlob == dbeiExisting.cbBlob) && - ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) - { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return TRUE; - } - - // Get previous event in chain - hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDPREV, (WPARAM)hExistingDbEvent, 0); - } - - } - else - { - // look forward - 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 - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return FALSE; - } - - // Compare event with import candidate - if ((dbei.timestamp == dbeiExisting.timestamp) && - (dbei.eventType == dbeiExisting.eventType) && - (dbei.cbBlob == dbeiExisting.cbBlob) && - ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) - { - // remember event - hPreviousDbEvent = hExistingDbEvent; - dwPreviousTimeStamp = dbeiExisting.timestamp; - return TRUE; - } - - // Get next event in chain - hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hExistingDbEvent, 0); - } - - } - // reset last event - hPreviousContact = INVALID_HANDLE_VALUE; - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/Import_SA/mirabilis.cpp b/plugins/Dbx_mmap_SA/Import_SA/mirabilis.cpp deleted file mode 100644 index 15b58f4e0a..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/mirabilis.cpp +++ /dev/null @@ -1,1492 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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. - -*/ - -// ============== -// == INCLUDES == -// ============== - -#include "import.h" -#include "mirabilis.h" - -BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei); -BOOL IsProtocolLoaded(char* pszProtocolName); -HANDLE HContactFromNumericID(char* pszProtoName, char* pszSetting, DWORD dwID); -HANDLE AddContact(HWND hdlgProgress, char* pszProtoName, char* pszUniqueSetting, DBVARIANT* id, DBVARIANT* nick, DBVARIANT* group); - -// ==================== -// ==================== -// == IMPLEMENTATION == -// ==================== -// ==================== - -static void SearchForDatabases(HWND hdlg, const TCHAR *dbPath, const TCHAR *type) -{ - HANDLE hFind; - WIN32_FIND_DATA fd; - TCHAR szSearchPath[MAX_PATH]; - TCHAR szRootName[MAX_PATH],*str2; - - int i; - - wsprintf(szSearchPath, _T("%s\\*.idx"), dbPath); - hFind=FindFirstFile(szSearchPath,&fd); - if(hFind!=INVALID_HANDLE_VALUE) { - do { - lstrcpy(szRootName,fd.cFileName); - str2=_tcsrchr(szRootName,'.'); - if(str2!=NULL) *str2=0; - if(lstrlen(szRootName)>3 && !lstrcmpi(szRootName+lstrlen(szRootName)-3,_T("tmp"))) - continue; - lstrcat(szRootName,type); - i=SendDlgItemMessage(hdlg,IDC_LIST,LB_ADDSTRING,0,(LPARAM)szRootName); - str2 = (TCHAR*)mir_alloc((lstrlen(dbPath) + 2+lstrlen(fd.cFileName))*sizeof(TCHAR)); - wsprintf(str2, _T("%s\\%s"), dbPath, fd.cFileName); - SendDlgItemMessage(hdlg,IDC_LIST,LB_SETITEMDATA,i,(LPARAM)str2); - } - while( FindNextFile( hFind, &fd )); - - FindClose(hFind); - } -} - -INT_PTR CALLBACK MirabilisPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - { - HKEY hKey; - LONG lResult; - int i; - TranslateDialogDefault(hdlg); - if (ERROR_SUCCESS != (lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Mirabilis\\ICQ\\DefaultPrefs"), 0, KEY_QUERY_VALUE, &hKey))) - lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Mirabilis\\ICQ\\DefaultPrefs"), 0, KEY_QUERY_VALUE, &hKey); - - if (lResult == ERROR_SUCCESS) { - TCHAR dbPath[MAX_PATH]; - DWORD cch; - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("New Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (99a)")); - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("99b Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (99b)")); - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2000a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (2000a)")); - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2000b Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (2000b)")); - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2001a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (2001a)")); - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2001b Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (2001b)")); - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2002a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (2002a)")); - cch=sizeof(dbPath); - if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2003a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) - SearchForDatabases(hdlg,dbPath,_T(" (2003a)")); - } - - for (i = 0; i < cICQAccounts; i++) - { - SendDlgItemMessage(hdlg, IDC_MIRABILISACCOUNT, CB_ADDSTRING, 0, (LPARAM)tszICQAccountName[i]); - } - SendDlgItemMessage(hdlg, IDC_MIRABILISACCOUNT, CB_SETCURSEL, 0, 0); - - SetTimer(hdlg,1,2000,NULL); - SendMessage(hdlg,WM_TIMER,0,0); - return TRUE; - } - case WM_TIMER: - { HANDLE hMirabilisMutex; - hMirabilisMutex=OpenMutexA(MUTEX_ALL_ACCESS,FALSE,"Mirabilis ICQ Mutex"); - if(hMirabilisMutex!=NULL) { - CloseHandle(hMirabilisMutex); - ShowWindow(GetDlgItem(hdlg,IDC_MIRABILISRUNNING),SW_SHOW); - } - else ShowWindow(GetDlgItem(hdlg,IDC_MIRABILISRUNNING),SW_HIDE); - } - break; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_IMPORTTYPE,(LPARAM)ImportTypePageProc); - break; - case IDOK: - { TCHAR filename[MAX_PATH]; - GetDlgItemText(hdlg,IDC_FILENAME,filename,SIZEOF(filename)); - if(_taccess(filename,4)) { - MessageBox(hdlg,TranslateT("The given file does not exist. Please check that you have entered the name correctly."),TranslateT("Mirabilis Import"),MB_OK); - break; - } - lstrcpy(importFile,filename); - iICQAccount = SendDlgItemMessage(hdlg, IDC_MIRABILISACCOUNT, CB_GETCURSEL, 0, 0); - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_OPTIONS,(LPARAM)MirabilisOptionsPageProc); - break; - } - case IDCANCEL: - PostMessage(GetParent(hdlg),WM_CLOSE,0,0); - break; - case IDC_LIST: - if(HIWORD(wParam)==LBN_SELCHANGE) { - int sel=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCURSEL,0,0); - if(sel==LB_ERR) break; - SetDlgItemText(hdlg,IDC_FILENAME,(TCHAR*)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETITEMDATA,sel,0)); - } - break; - case IDC_OTHER: - { OPENFILENAME ofn; - TCHAR str[MAX_PATH], text[256]; - int index; - - // TranslateTS doesnt translate \0 separated strings - index = mir_sntprintf(text, 64, _T("%s (*.idx)"), TranslateT("Mirabilis ICQ database indexes")) + 1; - _tcscpy(text + index, _T("*.idx")); index += 6; - index += mir_sntprintf(text + index, 64, _T("%s (*.*)"), TranslateT("All Files")) + 1; - _tcscpy(text + index, _T("*.*")); index += 4; - text[index] = 0; - - GetDlgItemText(hdlg,IDC_FILENAME,str,SIZEOF(str)); - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hdlg; - ofn.lpstrFilter = text; - ofn.lpstrFile = str; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT; - ofn.nMaxFile = SIZEOF(str); - ofn.lpstrDefExt = _T("idx"); - if(GetOpenFileName(&ofn)) - SetDlgItemText(hdlg,IDC_FILENAME,str); - break; - } - } - break; - - case WM_DESTROY: - { int i; - for(i=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCOUNT,0,0)-1;i>=0;i--) - mir_free((char*)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETITEMDATA,i,0)); - break; - } - } - return FALSE; -} - - -INT_PTR CALLBACK MirabilisOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - EnableWindow(GetDlgItem(hdlg, IDC_RADIO_ALL), TRUE); - EnableWindow(GetDlgItem(hdlg, IDC_STATIC_ALL), TRUE); - EnableWindow(GetDlgItem(hdlg, IDC_RADIO_CONTACTS), TRUE); - EnableWindow(GetDlgItem(hdlg, IDC_STATIC_CONTACTS), TRUE); - CheckDlgButton(hdlg, IDC_RADIO_ALL, BST_CHECKED); - return TRUE; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRABILISDB, (LPARAM)MirabilisPageProc); - break; - case IDOK: - if (IsDlgButtonChecked(hdlg, IDC_RADIO_ALL)) { - DoImport = MirabilisImport; - nImportOption = IMPORT_ALL; - nCustomOptions = IOPT_MSGSENT|IOPT_MSGRECV|IOPT_URLSENT|IOPT_URLRECV; - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc); - break; - } - if (IsDlgButtonChecked(hdlg, IDC_RADIO_CONTACTS)) { - DoImport = MirabilisImport; - nImportOption = IMPORT_CONTACTS; - nCustomOptions = 0; - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc); - break; - } - break; - case IDCANCEL: - PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); - break; - } - break; - } - - return FALSE; -} - -static int GetHighestIndexEntry(void) -{ - struct TIdxIndexEntry *entry; - DWORD ofs; - - ofs=*(PDWORD)(pIdx+12); - for (;;) { - entry=(struct TIdxIndexEntry*)(pIdx+ofs); - if(entry->entryIdLow==(DWORD)-2) return ((struct TIdxDatEntry*)entry)->entryId; - if(entry->ofsHigher>=0xF0000000) ofs=entry->ofsInHere; - else ofs=entry->ofsHigher; - } -} - -static int GetIdDatOfs(DWORD id) -{ - struct TIdxIndexEntry *entry; - DWORD ofs = *(PDWORD)(pIdx+12); - for (;;) { - entry=(struct TIdxIndexEntry*)(pIdx+ofs); - if(entry->entryIdLow==(DWORD)-2) { - if(entry->entryIdHigh==id) return ((struct TIdxDatEntry*)entry)->datOfs; - return 0; - } - if(identryIdLow) ofs=entry->ofsLower; - else if(entry->ofsHigher<0xF0000000 && id>=entry->entryIdHigh) ofs=entry->ofsHigher; - else ofs=entry->ofsInHere; - } - return 0; -} - -static int GetDatEntryType(DWORD ofs) -{ - return *(int*)(pDat+ofs+4); -} - -DWORD GetDBVersion() -{ - dwDBVersion = *(PDWORD)(pIdx+16); - - switch (dwDBVersion) { - case DBV99A: - AddMessage( LPGEN("This looks like a ICQ 99a database.")); - break; - case DBV99B: - AddMessage( LPGEN("This looks like a ICQ 99b database.")); - break; - case DBV2000A: - AddMessage( LPGEN("This looks like a ICQ 2000a database.")); - break; - case DBV2000B: - AddMessage( LPGEN("This looks like a ICQ 2000b database.")); - break; - case DBV2001A: - AddMessage( LPGEN("This looks like a ICQ 2001, 2002 or 2003a database.")); - break; - default: - AddMessage( LPGEN("This database is an unknown version.")); - return 0; - } - - return dwDBVersion; -} - -int GetEntryVersion(WORD wSeparatorValue) -{ - int nVersion; - - if (wSeparatorValue < ENTRYV99A) - nVersion = 0; // Cannot handle ICQ98 contacts - else if ((wSeparatorValue >= ENTRYV99A) && (wSeparatorValue < ENTRYV99B)) - nVersion = ENTRYV99A; - else if ((wSeparatorValue >= ENTRYV99B) && (wSeparatorValue < ENTRYV2000A)) - nVersion = ENTRYV99B; - else if ((wSeparatorValue >= ENTRYV2000A) && (wSeparatorValue < ENTRYV2000B)) - nVersion = ENTRYV2000A; - else if ((wSeparatorValue >= ENTRYV2000B) && (wSeparatorValue < ENTRYV2001A)) - nVersion = ENTRYV2000B; - else if ((wSeparatorValue >= ENTRYV2001A) && (wSeparatorValue < ENTRYV2001B)) - nVersion = ENTRYV2001A; - else if ((wSeparatorValue >= ENTRYV2001B) && (wSeparatorValue < ENTRYV2002A)) - nVersion = ENTRYV2001B; - else if (wSeparatorValue >= ENTRYV2002A) - nVersion = ENTRYV2002A; - else - nVersion = ENTRYVUNKNOWN; // Just in case... Skip undocumented contact versions - - return nVersion; -} - -DWORD ReadSubList(DWORD dwOffset) -{ - DWORD dwSubType, dwProperties, n; - - #ifdef _LOGGING - AddMessage( LPGEN("Attempting to parse sub list at offset %u."), dwOffset); - #endif - - // Check number of properties in sub list - dwProperties = *(PDWORD)(pDat+dwOffset); - dwOffset+=4; - - // Check sub list type - dwSubType = *(PBYTE)(pDat+dwOffset); - dwOffset+=1; - - switch (dwSubType){ - case 0x6B: - for(n=0;n 1) - return 6 + (char*)(pDat + dwOffset); - - break; - } - else - // Skip to next group - dwOffset += *(PWORD)(pDat + dwOffset + 4) + 12; - } - break; - - case DBV2000A: - case DBV2000B: - case DBV2001A: - for (n = 0; n < dwGroups; n++) { - if (tmpOfs = ReadPropertyBlock(dwOffset, "GroupID", &nSearchResult)) { - if (nSearchResult) { - if (dwGroupID == *(PDWORD)(pDat + tmpOfs + 1)) { - strGroupName = 3 + (char*)(pDat + ReadPropertyBlock(dwOffset, "GroupName", &nSearchResult)); - if (nSearchResult) { - if ((DWORD)*(strGroupName - 2) > 1) - return strGroupName; - break; - } } } } - - // Skip to next group - if ( dwOffset != ReadPropertyBlock(dwOffset, NULL, NULL)) - break; - } - break; - } - - // The GroupID was not found, or it was found - // but the group did not have a name, or there - // was an error during parsing. - return 0; -} - -// ------------------------------------------------ -// Scans a group list and adds all found groups to -// the Miranda contact list -// ------------------------------------------------ -// dwOffset must point to the number of entries in -// the following group list. -// Returns the number of added groups, or -1 if an error -// occurred - -int ImportGroups() -{ - DWORD dwGroups, n, tmpOfs, dwOffset; - int nImported = 0; - int nSearchResult, nFormat; - WORD wSeparatorValue; - - if (!(dwOffset = FindMyDetails())) { - AddMessage( LPGEN("ERROR: Failed to find owner information.")); - return -1; - } - - wSeparatorValue = *(PWORD)(pDat + dwOffset + 0x1c); - nFormat = GetEntryVersion(wSeparatorValue); - - dwGroupListOfs = dwOffset = FindGroupList(dwOffset); - if (!dwOffset) { - AddMessage( LPGEN("ERROR: Failed to find contact list groups.")); - #ifdef _LOGGING - { // If this is a debug build, dump MyDetails block to disk - FILE *stream; - DWORD dwSize; - dwOffset = FindMyDetails(); - dwSize = *(PDWORD)(pDat + dwOffset); - stream = fopen("import_grouplist_dump.bin", "w"); - fwrite(pDat + dwOffset, 1, dwSize, stream); - fclose(stream); - } - #endif - return -1; - } - - // Check number of groups - dwGroups = *(PDWORD)(pDat + dwOffset); - if (dwGroups > 0) - AddMessage( LPGEN("Importing groups.")); - else { - AddMessage( LPGEN("This database does not contain any contact groups.")); - return 0; - } - - dwOffset += 4; - - // Import all groups with a name - switch (nFormat) { - case ENTRYV99A: - case ENTRYV99B: - for (n = 0; n < dwGroups; n++) { - if (*(PWORD)(pDat+dwOffset+4) > 1) { - if ( CreateGroup(DBVT_ASCIIZ, (char*)(pDat + dwOffset) + 6, NULL )) - nImported++; - dwOffset += *(PWORD)(pDat + dwOffset + 4) + 12; - } } - break; - - case ENTRYV2000A: - case ENTRYV2000B: - case ENTRYV2001A: - case ENTRYV2001B: - case ENTRYV2002A: - for (n = 0; n < dwGroups; n++) { - if (tmpOfs = ReadPropertyBlock(dwOffset, "GroupName", &nSearchResult)) { - if (nSearchResult) { - if (CreateGroup( DBVT_ASCIIZ, (char*)(pDat + tmpOfs + 3), NULL )) - nImported++; - } } - - dwOffset = ReadPropertyBlock(dwOffset, NULL, NULL); - if (!dwOffset) { - AddMessage( LPGEN("ERROR: An error occurred while importing groups.")); - AddMessage( LPGEN("All groups may not have not been imported.")); - #ifdef _LOGGING - { // If this is a debug build, dump MyDetails block to disk - FILE *stream; - DWORD dwSize; - dwOffset = FindMyDetails(); - dwSize = *(PDWORD)(pDat + dwOffset); - stream = fopen("import_grouplist_dump.bin", "w"); - fwrite(pDat + dwOffset, 1, dwSize, stream); - fclose(stream); - } - #endif - return -1; - } } - break; - - default: - return -1; - } - - return nImported; -} - -// Imports the contact at offset dwOffset -// Returns the HANDLE of the Miranda contact -// or INVALID_HANDLE_VALUE on failure - -HANDLE ImportContact(DWORD dwOffset) -{ - int nContactVersion, nSearchResult; - BYTE Status; - WORD wSeparatorValue; - DWORD dwGroup, dwUIN = 0, tmpOfs = 0; - char *strNickname = 0, *strGroupName = 0; - - if (*(int*)(pDat + dwOffset + 4) != DATENTRY_CONTACT) - return INVALID_HANDLE_VALUE; - - if (*(int*)(pDat + dwOffset + 0x1e) != 'USER') - return INVALID_HANDLE_VALUE; - - #ifdef _LOGGING - { // If this is a debug build, dump contact to disk - FILE *stream; - DWORD dwSize; - dwSize = *(PDWORD)(pDat + dwOffset); - stream = fopen("import_last_contact.bin", "w"); - fwrite(pDat + dwOffset, 1, dwSize, stream); - fclose(stream); - } - #endif - - Status = *(pDat + dwOffset + 0x22); - wSeparatorValue = *(PWORD)(pDat + dwOffset + 0x1c); - nContactVersion = GetEntryVersion(wSeparatorValue); - - dwGroup = *(PDWORD)(pDat + dwOffset + 0x26); - if (dwGroup >= 1000) - strGroupName = GetGroupName(dwGroup); - - if (Status == 5) - return INVALID_HANDLE_VALUE; // Skip deleted contacts - - if ((Status != 2) && (Status != 3)) { - AddMessage( LPGEN("Skipping inactive contact.")); - return INVALID_HANDLE_VALUE; - } - - if ((nContactVersion < ENTRYV99A) || (nContactVersion == 0)) { - AddMessage( LPGEN("Skipping contact with unsupported version.")); - return INVALID_HANDLE_VALUE; - } - - switch(nContactVersion){ - case ENTRYV99A: - if (!(dwOffset = ReadWavList(dwOffset + 0x54))) return INVALID_HANDLE_VALUE; - if (!(dwOffset = ReadPropertyBlock(dwOffset + 0x26, NULL, NULL))) return INVALID_HANDLE_VALUE; - // Check for custom nickname - if (*(PWORD)(pDat + dwOffset) > 1) strNickname = (char*)(dwOffset + pDat + 2); - // Find UIN - dwOffset += *(PWORD)(pDat + dwOffset) + 2; // Custom nick name - dwOffset += *(PWORD)(pDat + dwOffset) + 2; // Nick name - dwOffset += *(PWORD)(pDat + dwOffset) + 2; // First name - dwOffset += *(PWORD)(pDat + dwOffset) + 2; // Last name - dwOffset += *(PWORD)(pDat + dwOffset) + 2; // E-mail - dwUIN = *(PDWORD)(pDat + dwOffset); // UIN - break; - - case ENTRYV99B: - case ENTRYV2000A: - case ENTRYV2000B: - if (!(dwOffset = ReadWavList(dwOffset + 0x2C))) return INVALID_HANDLE_VALUE; - tmpOfs = ReadPropertyBlockList(dwOffset + 0x02, "UIN", &nSearchResult); - if (nSearchResult) dwUIN = *(PDWORD)(pDat + tmpOfs + 1); - tmpOfs = ReadPropertyBlockList(dwOffset + 0x02, "MyDefinedHandle", &nSearchResult); - if (nSearchResult) strNickname = (char*)(tmpOfs + pDat + 3); - break; - - case ENTRYV2001A: - case ENTRYV2001B: - tmpOfs = ReadPropertyBlockList(dwOffset + 0x2C, "MyDefinedHandle", &nSearchResult); - if (nSearchResult) strNickname = (char*)(tmpOfs + pDat + 3); - tmpOfs = ReadPropertyBlockList(dwOffset + 0x2C, "UIN", &nSearchResult); - if (nSearchResult) dwUIN = *(PDWORD)(pDat + tmpOfs + 1); - break; - - case ENTRYV2002A: - tmpOfs = ReadPropertyBlockList(dwOffset + 0x32, "MyDefinedHandle", &nSearchResult); - if (nSearchResult) strNickname = (char*)(tmpOfs + pDat + 3); - tmpOfs = ReadPropertyBlockList(dwOffset + 0x32, "UIN", &nSearchResult); - if (nSearchResult) dwUIN = *(PDWORD)(pDat + tmpOfs + 1); - break; - } - - if (!dwUIN) { - AddMessage( LPGEN("Skipping unrecognizable contact.")); - return INVALID_HANDLE_VALUE; - } - - if (dwUIN < 10000) { - AddMessage( LPGEN("Skipping non-ICQ contact %u."), dwUIN ); - return INVALID_HANDLE_VALUE; - } - - if (HContactFromNumericID( szICQModuleName[ iICQAccount ], "UIN", dwUIN) == INVALID_HANDLE_VALUE) { - DBVARIANT id, nick, group; - id.type = DBVT_DWORD; id.dVal = dwUIN; - if ( strNickname != NULL && strlen(strNickname) > 0 ) - nick.type = DBVT_ASCIIZ, nick.pszVal = strNickname; - else - nick.type = DBVT_DELETED; - group.type = DBVT_ASCIIZ, group.pszVal = strGroupName; - return AddContact(hdlgProgress, szICQModuleName[ iICQAccount ], "UIN", &id, &nick, &group); - } - else { - if ((strNickname != NULL) && (strlen(strNickname) > 0)) - AddMessage( LPGEN("Skipping duplicate ICQ contact %u, %s"), dwUIN, strNickname); - else - AddMessage( LPGEN("Skipping duplicate ICQ contact %u"), dwUIN); - } - - // Failure - return INVALID_HANDLE_VALUE; -} - -BOOL ImportMessage(DWORD dwOffset) -{ - struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); - struct TDatEntryFooter *footer; - DBEVENTINFO dbei; - HANDLE hContact; - int nUCTOffset; - TIME_ZONE_INFORMATION TimeZoneInformation; - int nHistoryCount = 0; - - // Get timestamp offset. In ICQ, event timestamps are stored - // as UTC + (0-TZ offset). YES! That's the negation of the - // timezone offset, only God and Mirabilis knows why. - GetTimeZoneInformation(&TimeZoneInformation); - nUCTOffset = -TimeZoneInformation.Bias * 60; - - // Ignore messages in 'Deleted' folder - if (msg->filingStatus&FILING_DELETED) - return FALSE; - - // Skip messages from non-icq contacts - if (msg->uin < 10000) { - AddMessage( LPGEN("Ignoring msg from user %d at ofs %d."), msg->uin, dwOffset ); - return FALSE; - } - - // Ignore received messages? - if (( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_MSGRECV )) - return FALSE; - - // Ignores sent messages? - if ( !(msg->filingStatus & FILING_RECEIVED) && !( nCustomOptions & IOPT_MSGSENT )) - return FALSE; - - // Check if contact exists in Miranda database - hContact = HistoryImportFindContact(hdlgProgress, szICQModuleName[ iICQAccount ], msg->uin, nCustomOptions&IOPT_ADDUNKNOWN); - if (hContact == INVALID_HANDLE_VALUE) - return FALSE; // Contact couldn't be found/added - - // Convert the event to a Miranda dbevent - footer = (struct TDatEntryFooter*)(pDat + dwOffset + msg->textLen + offsetof(struct TDatMessage, text)); - ZeroMemory(&dbei, sizeof(dbei)); - dbei.cbSize = sizeof(dbei); - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.flags = footer->sent == 1 ? DBEF_SENT : DBEF_READ; - dbei.szModule = szICQModuleName[ iICQAccount ]; - // Convert timestamp - dbei.timestamp = footer->timestamp + nUCTOffset; - dbei.cbBlob = msg->textLen; - dbei.pBlob = (PBYTE)alloca(msg->textLen); - CopyMemory(dbei.pBlob, msg->text, dbei.cbBlob); - dbei.pBlob[dbei.cbBlob - 1] = 0; - - // Check for duplicate entries - if (IsDuplicateEvent(hContact, dbei)) { - nDupes++; - } - else { - if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) - nMessagesCount++; - } - - return TRUE; -} - -BOOL ImportExtendedMessage(DWORD dwOffset) -{ - struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); - struct TDatEntryFooter *footer; - DBEVENTINFO dbei; - HANDLE hContact; - int nUCTOffset; - TIME_ZONE_INFORMATION TimeZoneInformation; - int nHistoryCount = 0; - char* pszText = 0; - DWORD dwRichTextOffset = 0; - DWORD wRichTextLength = 0; - DWORD wLength = 0; - BOOL bFreeMe = FALSE; - - // Get timestamp offset. In ICQ, event timestamps are stored - // as UTC + (0-TZ offset). YES! That's the negation of the - // timezone offset, only God and Mirabilis knows why. - GetTimeZoneInformation(&TimeZoneInformation); - nUCTOffset = -TimeZoneInformation.Bias * 60; - - // Ignore messages in 'Deleted' folder - if (msg->filingStatus&FILING_DELETED) - return FALSE; - - // Skip messages from non-icq contacts - if (msg->uin < 10000) { - AddMessage( LPGEN("Ignoring msg from user %d at ofs %d."), msg->uin, dwOffset ); - return FALSE; - } - - // Ignore received messages? - if (( msg->filingStatus & FILING_RECEIVED) && !( nCustomOptions & IOPT_MSGRECV )) - return FALSE; - - // Ignore sent messages? - if ( !( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_MSGSENT )) - return FALSE; - - // Check if contact exists in Miranda database - hContact = HistoryImportFindContact(hdlgProgress, szICQModuleName[ iICQAccount ], msg->uin, nCustomOptions&IOPT_ADDUNKNOWN); - if (hContact == INVALID_HANDLE_VALUE) - return FALSE; // Contact couldn't be found/added - - // Find a piece of usable text content - if (msg->textLen <= 1) { - // Skip past the RTF segment - wRichTextLength = *(PWORD)(pDat + dwOffset + 0x2A + msg->textLen + 0x21); - dwRichTextOffset = dwOffset + 0x2A + msg->textLen + 0x23; - - // Use the UTF-8 text segment - wLength = *(PWORD)(pDat + dwRichTextOffset + wRichTextLength); - if (wLength <= 1) { - AddMessage( LPGEN("Ignoring msg with no text from %d ofs %d."), msg->uin, dwOffset ); - return FALSE; - } - pszText = _strdup((char *)pDat + dwRichTextOffset + wRichTextLength + 2); - bFreeMe = TRUE; - mir_utf8decode(pszText, NULL); - wLength = (DWORD)strlen(pszText)+1; - } - else { - // Use the ANSI text segment - wLength = msg->textLen; - pszText = (char *)(pDat + dwOffset + 0x2A); - } - - // Convert the event to a Miranda dbevent - footer = (struct TDatEntryFooter*)(pDat + dwOffset + msg->textLen + offsetof(struct TDatMessage, text)); - ZeroMemory(&dbei, sizeof(dbei)); - dbei.cbSize = sizeof(dbei); - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.flags = footer->sent == 1 ? DBEF_SENT : DBEF_READ; - dbei.szModule = szICQModuleName[ iICQAccount ]; - // Convert timestamp - dbei.timestamp = footer->timestamp + nUCTOffset; - dbei.cbBlob = wLength; - dbei.pBlob = (PBYTE)calloc(wLength,1); - CopyMemory(dbei.pBlob, pszText, dbei.cbBlob); - dbei.pBlob[dbei.cbBlob - 1] = 0; - - // Check for duplicate entries - if (IsDuplicateEvent(hContact, dbei)) { - nDupes++; - } - else { - if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) - nMessagesCount++; - } - - free(dbei.pBlob); - if (bFreeMe) - free(pszText); - - return TRUE; -} - -BOOL ImportURLMessage(DWORD dwOffset) -{ - struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); - struct TDatEntryFooter *footer; - DBEVENTINFO dbei; - HANDLE hContact; - int nUCTOffset; - TIME_ZONE_INFORMATION TimeZoneInformation; - int nHistoryCount = 0; - char *pSeparator; - - // Get timestamp offset. In ICQ, event timestamps are stored - // as UTC + (0-TZ offset). YES! That's the negation of the - // timezone offset, only God and Mirabilis knows why. - GetTimeZoneInformation(&TimeZoneInformation); - nUCTOffset = -TimeZoneInformation.Bias * 60; - - // Ignore URLs in 'Deleted' folder - if (msg->filingStatus&FILING_DELETED) - return FALSE; - - // Skip URLs from non-icq contacts - if (msg->uin < 10000) { - AddMessage( LPGEN("Ignoring msg from user %d at ofs %d."), msg->uin, dwOffset ); - return FALSE; - } - - // Ignore received URLs? - if (( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_URLRECV )) - return FALSE; - - // Ignores sent URLs? - if ( !( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_URLSENT )) - return FALSE; - - // Check if contact exists in Miranda database - hContact = HistoryImportFindContact(hdlgProgress, szICQModuleName[ iICQAccount ], msg->uin, nCustomOptions&IOPT_ADDUNKNOWN); - if (hContact == INVALID_HANDLE_VALUE) - return FALSE; // Contact couldn't be found/added - - // Convert the event to a Miranda dbevent - footer = (struct TDatEntryFooter*)(pDat + dwOffset + msg->textLen + offsetof(struct TDatMessage, text)); - ZeroMemory(&dbei, sizeof(dbei)); - dbei.cbSize = sizeof(dbei); - dbei.eventType = EVENTTYPE_URL; - dbei.flags = footer->sent == 1 ? DBEF_SENT : DBEF_READ; - dbei.szModule = szICQModuleName[ iICQAccount ]; - // Convert timestamp - dbei.timestamp = footer->timestamp + nUCTOffset; - dbei.cbBlob = msg->textLen; - dbei.pBlob = (PBYTE)alloca(msg->textLen); - CopyMemory(dbei.pBlob, msg->text, dbei.cbBlob); - dbei.pBlob[dbei.cbBlob - 1] = 0; - // Separate URL and description - pSeparator = strchr((char*)dbei.pBlob, 0xFE); - if (pSeparator != NULL) - *pSeparator = 0; - - // Check for duplicate entries - if (IsDuplicateEvent(hContact, dbei)) - nDupes++; - else if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) - nMessagesCount++; - - return TRUE; -} - -BOOL ImportEvent(DWORD dwOffset) -{ - struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); - - // Events have IDs > 2000 - if (msg->hdr.entryId < 2001) { - AddMessage( LPGEN("Skipping event with ID < 2001.")); - return FALSE; - } - - // Separate code paths based on the event signature - switch (msg->hdr.subType) { - - case SUBTYPE_MESSAGE: // All kinds of messages - switch (msg->type) { - case 1: // Normal message - if ((nCustomOptions&IOPT_MSGRECV) || (nCustomOptions&IOPT_MSGSENT)) { - return ImportMessage(dwOffset); - } - break; - - case 4: // URL - if ((nCustomOptions&IOPT_URLSENT) || (nCustomOptions&IOPT_URLRECV)) { - return ImportURLMessage(dwOffset); - } - break; - - case 6: // Request for authorization - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'Request for auth.' msg, ofs %d."), dwOffset ); - #endif - break; - - case 7: // Authorization request denied - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'Auth. denied' msg, ofs %d."), dwOffset ); - #endif - break; - - case 8: // Authorization request accepted - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'Auth. accepted' msg, ofs %d."), dwOffset ); - #endif - break; - - case 9: // System message - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'System message', ofs %d."), dwOffset ); - #endif - break; - - case 12: // You were added - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'You were added' msg, ofs %d."), dwOffset ); - #endif - break; - - case 13: // WWWPager ? - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'WWW Pager' msg, ofs %d."), dwOffset ); - #endif - break; - - case 14: // Email Express ? - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'Email Express' msg, ofs %d."), dwOffset ); - #endif - break; - - case 19: // Contact list - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'Contact' msg, ofs %d."), dwOffset ); - #endif - break; - - case 21: // Phonecall request? - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'Phonecall' msg (?), ofs %d."), dwOffset ); - #endif - break; - - case 26: // SMS request? - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'SMS' msg (?), ofs %d."), dwOffset ); - #endif - break; - - case 29: // Active list invitation ?? - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 29 msg, ofs %d."), dwOffset ); - #endif - break; - - case 30: // Birthday reminder - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 'Birthday' msg (?), ofs %d."), dwOffset ); - #endif - break; - - case 32: // Unknown (Tomer) - #ifdef _LOGGING - AddMessage( LPGEN("Skipping 32 msg, ofs %d."), dwOffset ); - #endif - break; - - default: - AddMessage( LPGEN("Skipping unknown 0xE0 subtype (%d), ofs %d."), msg->type, dwOffset ); - - #ifdef _LOGGING - { // If this is a debug build, dump entry to disk - FILE *stream; - DWORD dwSize = *(PDWORD)(pDat + dwOffset); - wsprintfA(str, "import_unknown_E0subtype_%u-%u.bin", msg->type, dwOffset); - stream = fopen(str, "w"); - fwrite(pDat + dwOffset, 1, dwSize, stream); - fclose(stream); - } - #endif - - return FALSE; - } - break; - - case SUBTYPE_CHATREQUEST: // 0xE1 - #ifdef _LOGGING - if (nImportOption != IMPORT_CONTACTS) - AddMessage( LPGEN("Skipping 'Chat request' msg, ofs %d."), dwOffset ); - #endif - break; - - case SUBTYPE_FILEREQUEST: // 0xE2 - #ifdef _LOGGING - if (nImportOption != IMPORT_CONTACTS) - AddMessage( LPGEN("Skipping file message offset %d."), dwOffset ); - #endif - break; - - case 0xE3: // External (IPhone, Battlecom) Maybe general voice calls? - #ifdef _LOGGING - if (nImportOption != IMPORT_CONTACTS) - AddMessage( LPGEN("Skipping message type 0xE3 at offset %d."), dwOffset ); - #endif - break; - - case 0xE4: // My details - break; - case 0xE5: // Contact - break; - case 0xE6: // Reminder - break; - case 0xE7: // Addressbook - break; - case 0xEC: // Voice message - break; - case 0xED: // Unknown, something to do with chatting and .CHT files - // if (importHistory) { - // wsprintf(str, "Skipping message type 0xED at offset %d.", dwOffset); - // AddMessage( LPGEN(str); - // } - break; - case 0xEE: // Note - break; - case 0xEF: // Event folder - break; - // case 0xF0: // Unknown - // if (importHistory) { - // wsprintf(str, "Skipping message type 0xF0 at offset %d.", dwOffset); - // AddMessage( LPGEN(str); - // } - // break; - case 0xF1: // Server list - break; - // case 0xF6: // Unknown - // if (importHistory) { - // wsprintf(str, "Skipping message type 0xF6 at offset %d.", dwOffset); - // AddMessage( LPGEN(str); - // } - // break; - case 0x50: // Extended message, ICQ 2000a+? - if (nImportOption != IMPORT_CONTACTS) { - return ImportExtendedMessage(dwOffset); - } - break; - - case 0xA0: // URL message type 2 - if (nImportOption != IMPORT_CONTACTS) { - if ((msg->filingStatus&FILING_RECEIVED) || (nCustomOptions&IOPT_URLRECV)) { - return ImportURLMessage(dwOffset); - } - } - break; - - default: - if (nImportOption != IMPORT_CONTACTS) { - AddMessage( LPGEN("Skipping unknown event type %d at offset %d."), msg->hdr.subType, dwOffset ); - -#ifdef _LOGGING - { // If this is a debug build, dump entry to disk - FILE *stream; - DWORD dwSize; - dwSize = *(PDWORD)(pDat + dwOffset); - wsprintfA(str, "import_unknown_eventtype_%u-%u.bin", msg->hdr.subType, dwOffset); - stream = fopen(str, "w"); - fwrite(pDat + dwOffset, 1, dwSize, stream); - fclose(stream); - } -#endif - - } - break; - } - - return FALSE; -} - - -static void MirabilisImport(HWND hdlgProgressWnd) -{ - HANDLE hIdx, hDat, hIdxMapping, hDatMapping; - DWORD i, ofs, highestIndexEntry; - TCHAR datFilename[MAX_PATH]; - MSG msg; - DWORD dwTimer; - - - int status = 0; - hdlgProgress = hdlgProgressWnd; - nDupes = nContactsCount = nMessagesCount = 0; - - SetProgress(0); - lstrcpy(datFilename, importFile); - { - TCHAR* str2; - str2 = _tcsrchr(datFilename,'.'); - if ( str2 != NULL ) - lstrcpy(str2, _T(".dat")); - } - - hIdx = CreateFile(importFile, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - if (hIdx == INVALID_HANDLE_VALUE) { - AddMessage( LPGEN("Failed to open index file")); - AddMessage( LPGEN("Import aborted")); - SetProgress(100); - return; - } - - hDat = CreateFile(datFilename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); - if (hDat == INVALID_HANDLE_VALUE) { - AddMessage( LPGEN("Failed to open database file")); - AddMessage( LPGEN("Import aborted")); - SetProgress(100); - return; - } - - // Creating file mappings - hIdxMapping = CreateFileMapping(hIdx, NULL, PAGE_READONLY, 0, 0, NULL); - hDatMapping = CreateFileMapping(hDat, NULL, PAGE_READONLY, 0, 0, NULL); - - // Mapping views of files - pIdx = (PBYTE)MapViewOfFile(hIdxMapping, FILE_MAP_READ, 0, 0, 0); - pDat = (PBYTE)MapViewOfFile(hDatMapping, FILE_MAP_READ, 0, 0, 0); - - // Is this a supported format? - if (GetDBVersion()) { - AddMessage( "" ); - - highestIndexEntry = GetHighestIndexEntry(); - - // Import groups - nGroupsCount = ImportGroups(); - if (nGroupsCount < 0) { - AddMessage( LPGEN("Group import was not completed.")); - nGroupsCount = 0; - } - AddMessage( "" ); - - // Start benchmark timer - dwTimer = time(NULL); - - if ( !IsProtocolLoaded( szICQModuleName[iICQAccount] )) { - AddMessage( LPGEN("ICQ account is not installed.")); - AddMessage( LPGEN("No ICQ contacts or history will be imported.")); - AddMessage( "" ); - } - else { - // Configure database for fast writing - CallService(MS_DB_SETSAFETYMODE, FALSE, 0); - - // Import contacts - AddMessage( LPGEN("Importing contacts")); - for (i = 2001; i <= highestIndexEntry; i++) { //event ids start at 2001 - if (!(i%10)) { - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - if (!(i%100)) - SetProgress(100 * (i - 2001) / (highestIndexEntry - 2001)); - - ofs = GetIdDatOfs(i); - if (ofs != 0) { - if (ImportContact(ofs) != INVALID_HANDLE_VALUE) - nContactsCount++; - } - } - AddMessage( "" ); - - // Import history - if (nImportOption != IMPORT_CONTACTS) { - AddMessage( LPGEN("Importing history (this may take a while)")); - for (i = 2001; i <= highestIndexEntry; i++) { //event ids start at 2001 - if (!(i%10)) { - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - if (!(i%100)) - SetProgress(100 * (i - 2001) / (highestIndexEntry - 2001)); - - ofs = GetIdDatOfs(i); - if (ofs != 0) ImportEvent(ofs); - } - AddMessage( "" ); - } - - // Restore database writing mode - CallService(MS_DB_SETSAFETYMODE, TRUE, 0); - } - - dwTimer = time(NULL) - dwTimer; - - AddMessage( LPGEN("Import completed in %d seconds."), dwTimer ); - SetProgress(100); - AddMessage( LPGEN("Added %d contacts and %d groups."), nContactsCount, nGroupsCount ); - if ( nImportOption != IMPORT_CONTACTS ) - AddMessage( LPGEN("Added %d events and skipped %d duplicates."), nMessagesCount, nDupes ); - } - - UnmapViewOfFile(pDat); - UnmapViewOfFile(pIdx); - CloseHandle(hDatMapping); - CloseHandle(hIdxMapping); - CloseHandle(hDat); - CloseHandle(hIdx); -} diff --git a/plugins/Dbx_mmap_SA/Import_SA/mirabilis.h b/plugins/Dbx_mmap_SA/Import_SA/mirabilis.h deleted file mode 100644 index 47f10141e1..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/mirabilis.h +++ /dev/null @@ -1,200 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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. - -*/ - - - -#ifndef MIRABILIS_H -#define MIRABILIS_H - -#include -#include -#include - -// ====================== -// == GLOBAL FUNCTIONS == -// ====================== - -HANDLE HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DWORD uin,int addUnknown); - -// ===================== -// == LOCAL FUNCTIONS == -// ===================== - - -// Main function -static void MirabilisImport(HWND hdlgProgressWnd); - -// GUI callbacks -INT_PTR CALLBACK ImportTypePageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK MirabilisPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK MirabilisOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); - -// Helper functions for entries -static int GetHighestIndexEntry(void); -static int GetIdDatOfs(DWORD id); -static int GetDatEntryType(DWORD ofs); -DWORD FindMyDetails(void); - -// Parsing functions -DWORD GetDBVersion(); -int GetEntryVersion(WORD wSeparatorValue); -DWORD ReadPropertyBlock(DWORD dwOffset, char* SearchWord, int* nSearchResult); -DWORD ReadSubList(DWORD dwOffset); -DWORD ReadPropertyBlock(DWORD dwOffset, char* SearchWord, int* nSearchResult); -DWORD ReadPropertyBlockList(DWORD dwOffset, char* SearchWord, int* nSearchResult); -DWORD ReadWavList(DWORD ofs); -DWORD FindGroupList(DWORD dwOffset); -char* GetGroupName(DWORD dwGroupID); -int ImportGroups(); -static HANDLE ImportContact(DWORD dwOffset); - -BOOL ImportEvent(DWORD dwOffset); -BOOL ImportMessage(DWORD dwOffset); -BOOL ImportExtendedMessage(DWORD dwOffset); -BOOL ImportURLMessage(DWORD dwOffset); - - - - -// ====================== -// == GLOBAL VARIABLES == -// ====================== - -extern TCHAR importFile[MAX_PATH]; -extern void (*DoImport)(HWND); -extern int nImportOption; -extern int nCustomOptions; - - -extern int cICQAccounts; -extern char ** szICQModuleName; -extern TCHAR ** tszICQAccountName; -extern int iICQAccount; - -// ===================== -// == LOCAL VARIABLES == -// ===================== - -static DWORD dwDBVersion; -static DWORD dwGroupListOfs; -static PBYTE pIdx,pDat; - -// ============= -// == DEFINES == -// ============= - -// Contact versions -// These numbers are not 100% accurate -#define ENTRYVUNKNOWN -1 -#define ENTRYV99A 200 -#define ENTRYV99B 300 -#define ENTRYV2000A 400 -#define ENTRYV2000B 455 -#define ENTRYV2001A 500 -#define ENTRYV2001B 515 -#define ENTRYV2002A 533 - -// Database versions -#define DBV99A 10 -#define DBV99B 14 -#define DBV2000A 17 -#define DBV2000B 18 -#define DBV2001A 19 // This is used by ICQ 2001a, 2001b & 2002a - -#define DATENTRY_UNFILED (DWORD)(-1) -#define DATENTRY_MESSAGE 0 -#define DATENTRY_CONTACT 1 -#define DATENTRY_IGNORED 2 -#define DATENTRY_SYSTEM 9 - -#define MAX_NON_ICQ_CONTACTS 100 - -#define SUBTYPE_NEWMESSAGE 0x50 -#define SUBTYPE_NEWURL 0xA0 - -#define SUBTYPE_MESSAGE 0xE0 //Message / URL Message / Request For Authorization / "Authorization" / System Request / "You Were Added" / Contacts List -#define SUBTYPE_CHATREQUEST 0xE1 -#define SUBTYPE_FILEREQUEST 0xE2 -#define SUBTYPE_MYDETAILS 0xE4 -#define SUBTYPE_CONTACTINFO 0xE5 -#define SUBTYPE_REMINDER 0xE6 -#define SUBTYPE_ADDRESSBOOK 0xE7 -#define SUBTYPE_VOICEMSG 0xEC //??? -#define SUBTYPE_NOTE 0xEE -#define SUBTYPE_EVENTFOLDER 0xEF -#define SUBTYPE_SERVERLIST 0xF1 //and objectionable word list -#define SUBTYPE_X1 0xF6 //(new to ICQ 99b???) - -#define FILING_RECEIVED 0x01 -#define FILING_DELETED 0x02 -#define FILING_MESSAGE 0x04 -#define MSGTYPE_MESSAGE 1 -#define MSGTYPE_URL 4 -#define MSGTYPE_CLIST 19 -#include - -struct TIdxDatEntry { - DWORD status; //-2=valid, else is an index entry - DWORD entryId; - DWORD ofsNext,ofsPrev; - DWORD datOfs; -}; - -struct TIdxIndexEntry { - DWORD entryIdLow; - DWORD entryIdHigh; - DWORD ofsLower; - DWORD ofsInHere; - DWORD ofsHigher; -}; - -struct TDatEntryHeader { - DWORD entrySize; //in bytes - DWORD entryType; //DATENTRY_* constant - DWORD entryId; //same as in index - BYTE subType; //SUBTYPE_* constant - BYTE signature[15]; -}; - -struct TDatEntryFooter { - DWORD unknown; - DWORD sent; //1 if sent, 0 if received - WORD separator; - DWORD timestamp; //unix time -}; - -struct TDatMessage { - struct TDatEntryHeader hdr; //hdr.entryType==DATENTRY_MESSAGE && hdr.subType==MSGTYPE_MESSAGE - WORD separator; - DWORD filingStatus; //FILING_* flags - WORD type; //MSGTYPE_* constant - DWORD uin; - WORD textLen; - char text[1]; //0xFE separates description & URL in URLs - //a struct TDatEntryFooter comes here -}; - -#include - -#endif diff --git a/plugins/Dbx_mmap_SA/Import_SA/miranda.cpp b/plugins/Dbx_mmap_SA/Import_SA/miranda.cpp deleted file mode 100644 index 8b6a9496f4..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/miranda.cpp +++ /dev/null @@ -1,1491 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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. - -*/ - -// ============== -// == INCLUDES == -// ============== - -#include "import.h" - -#include "mirandadb0700.h" - -// ====================== -// == GLOBAL FUNCTIONS == -// ====================== - -HANDLE HContactFromNumericID(char* pszProtoName, char* pszSetting, DWORD dwID); -HANDLE HContactFromID(char* pszProtoName, char* pszSetting, char* pszID); - -HANDLE AddContact(HWND hdlgProgress, char* pszProtoName, char* pszUniqueSetting, DBVARIANT* id, DBVARIANT* nick, DBVARIANT* group); - -BOOL IsProtocolLoaded(char* pszProtocolName); -BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei); - -INT_PTR CALLBACK ImportTypePageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK MirandaOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); - -// ===================== -// == LOCAL FUNCTIONS == -// ===================== - -void MirandaImport(HWND hdlgProgress); -int CheckFileFormat(HANDLE hFile); -static HANDLE ImportContact(HANDLE hDbFile, struct DBContact Contact); -static void ImportHistory(HANDLE hDbFile, struct DBContact Contact, PROTOCOLDESCRIPTOR **protocol, int protoCount); -static int ImportGroups(HANDLE hDbFile, struct DBHeader *pdbHeader); - -// Comment: The Find* functions only return a file offset. -// The Get* functions actually reads the requested -// data from the file and gives you a pointer to a structure -// containing the data. - -DWORD FindFirstContact(struct DBHeader* pDbHeader); -DWORD FindNextContact(struct DBContact* pDbContact); -DWORD FindNextEvent(HANDLE hDbFile, DWORD dwOffset); -DWORD FindOwnerContact(struct DBHeader* pDbHeader); - -int GetContactCount(struct DBHeader* pDbHeader); -BOOL GetContact(HANDLE hDbFile, DWORD dwOffset, struct DBContact* pDbContact); -BOOL GetSetting(HANDLE hDbFile, struct DBContact* pDbContact, char* pszModuleName, char* pszSettingName, DBVARIANT* pValue); -char* GetNextSetting(char* pDbSetting); -BOOL GetSettings(HANDLE hDbFile, DWORD dwOffset, struct DBContactSettings** pDbSettings); -struct DBContactSettings* GetSettingsGroupByModuleName(HANDLE hdbFile, struct DBContact* pDbContact, char* pszName); -DWORD GetBlobSize(struct DBContactSettings* pDbSettings); -int GetSettingByName(struct DBContactSettings* pDbSettings, char* pszSettingName, DBVARIANT* pValue); -int GetSettingValue(char* pBlob,DBVARIANT* pValue); - -BOOL GetEvent(HANDLE hDbFile, DWORD dwOffset, DBEVENTINFO* pDBEI); -char* GetName(HANDLE hDbFile, DWORD dwOffset); - - -// ====================== -// == GLOBAL VARIABLES == -// ====================== - -extern void (*DoImport)(HWND); -extern int nImportOption; -extern int nCustomOptions; - - -// ===================== -// == LOCAL VARIABLES == -// ===================== - -TCHAR importFile[MAX_PATH]; -HWND hdlgProgress; -DWORD dwFileSize; - -DWORD nDupes; -DWORD nContactsCount; -DWORD nMessagesCount; -DWORD nGroupsCount; -DWORD nSkippedEvents; -DWORD nSkippedContacts; - -time_t dwSinceDate = 0; - -// ============= -// == DEFINES == -// ============= - -#define EVENTTYPE_MESSAGE 0 -#define EVENTTYPE_URL 1 -#define EVENTTYPE_FILE 1002 - - -// Supported database versions -#define DB_INVALID 0x00000000 // Unknown or corrupted DAT -#define DB_000700 0x00000700 // Miranda 0.1.0.0 - 0.1.2.2+ - -// DAT file signature -struct DBSignature { - char name[15]; - BYTE eof; -}; - -static struct DBSignature dbSignature={"Miranda ICQ DB",0x1A}; - -// Unsane: Secured signature -static struct DBSignature dbSignatureEncrypted={"Miranda ICQ SD",0x1A}; - -// ==================== -// ==================== -// == IMPLEMENTATION == -// ==================== -// ==================== - -static void SearchForLists(HWND hdlg, const TCHAR *mirandaPath, const TCHAR *mirandaProf, const TCHAR *pattern, const TCHAR *type) -{ - HANDLE hFind; - WIN32_FIND_DATA fd; - TCHAR szSearchPath[MAX_PATH]; - TCHAR szRootName[MAX_PATH]; - TCHAR* str2; - int i; - - mir_sntprintf(szSearchPath, SIZEOF(szSearchPath), _T("%s\\%s"), mirandaPath, pattern); - hFind = FindFirstFile(szSearchPath, &fd); - if (hFind != INVALID_HANDLE_VALUE) - { - do - { - _tcscpy(szRootName, fd.cFileName); - str2 = _tcsrchr(szRootName, '.'); - if (str2 != NULL) *str2 = 0; - if (mirandaProf == NULL || _tcsicmp(mirandaProf, szRootName)) - { - _tcscat(szRootName, type); - i = SendDlgItemMessage(hdlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szRootName); - str2 = (TCHAR*)mir_alloc((_tcslen(mirandaPath) + 2 + _tcslen(fd.cFileName)) * sizeof(TCHAR)); - wsprintf(str2, _T("%s\\%s"), mirandaPath, fd.cFileName); - SendDlgItemMessage(hdlg, IDC_LIST, LB_SETITEMDATA, i, (LPARAM)str2); - } - } - while( FindNextFile( hFind, &fd )); - - FindClose( hFind ); - } -} - -INT_PTR CALLBACK MirandaPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - { - TCHAR *pfd, *pfd1, *pfd2, *pfn; - - REPLACEVARSDATA dat = {0}; - dat.cbSize = sizeof(dat); - dat.dwFlags = RVF_TCHAR; - - pfd = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_path%\\Profiles"), (LPARAM)&dat); - pfd1 = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_path%"), (LPARAM)&dat); - pfd2 = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_profile%"), (LPARAM)&dat); - pfn = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_profilename%"), (LPARAM)&dat); - - SearchForLists(hdlg, pfd2, pfn, _T("*.dat"), _T(" (Miranda IM v0.x)")); - // Unsane: check for exclude equal or used profiles - if (lstrcmpi(pfd1, pfd2)) - SearchForLists(hdlg, pfd1, NULL, _T("*.dat"), _T(" (Miranda IM v0.x)")); - if (lstrcmpi(pfd, pfd2)) - SearchForLists(hdlg, pfd, NULL, _T("*.dat"), _T(" (Miranda IM v0.x)")); - - mir_free(pfn); - mir_free(pfd2); - mir_free(pfd1); - mir_free(pfd); - return TRUE; - } - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_IMPORTTYPE,(LPARAM)ImportTypePageProc); - break; - - case IDOK: - { - TCHAR filename[MAX_PATH]; - - GetDlgItemText(hdlg, IDC_FILENAME, filename, SIZEOF(filename)); - if (_taccess(filename, 4)) { - MessageBox(hdlg, TranslateT("The given file does not exist. Please check that you have entered the name correctly."), TranslateT("Miranda Import"), MB_OK); - break; - } - lstrcpy(importFile, filename); - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_OPTIONS,(LPARAM)MirandaOptionsPageProc); - } - break; - - case IDCANCEL: - PostMessage(GetParent(hdlg),WM_CLOSE,0,0); - break; - - case IDC_LIST: - if(HIWORD(wParam)==LBN_SELCHANGE) { - int sel = SendDlgItemMessage(hdlg, IDC_LIST, LB_GETCURSEL, 0, 0); - if (sel == LB_ERR) break; - SetDlgItemText(hdlg, IDC_FILENAME, (TCHAR*)SendDlgItemMessage(hdlg, IDC_LIST, LB_GETITEMDATA, sel, 0)); - } - break; - - case IDC_OTHER: - { - OPENFILENAME ofn; - TCHAR str[MAX_PATH], text[256]; - TCHAR *pfd; - - pfd = Utils_ReplaceVarsT(_T("%miranda_profile%")); - - GetDlgItemText(hdlg, IDC_FILENAME, str, SIZEOF(str)); - ZeroMemory(&ofn, sizeof(ofn)); - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hdlg; - mir_sntprintf(text, SIZEOF(text), _T("%s (*.dat, *.bak)%c*.dat;*.bak%c%s (*.*)%c*.*%c%c"), TranslateT("Miranda IM database"), 0, 0, TranslateT("All Files"), 0, 0, 0); - ofn.lpstrFilter = text; - ofn.lpstrDefExt = _T("dat"); - ofn.lpstrFile = str; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT; - ofn.nMaxFile = SIZEOF(str); - ofn.lpstrInitialDir = pfd; - if (GetOpenFileName(&ofn)) - SetDlgItemText(hdlg, IDC_FILENAME, str); - - mir_free(pfd); - break; - } - } - break; - case WM_DESTROY: - { - int i; - - for(i=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCOUNT,0,0)-1;i>=0;i--) - mir_free((char*)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETITEMDATA,i,0)); - break; - } } - - return FALSE; -} - - -INT_PTR CALLBACK MirandaOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - EnableWindow(GetDlgItem(hdlg,IDC_RADIO_ALL), TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_STATIC_ALL), TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_RADIO_CONTACTS), TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_STATIC_CONTACTS), TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_RADIO_CUSTOM), TRUE); - EnableWindow(GetDlgItem(hdlg,IDC_STATIC_CUSTOM), TRUE); - CheckDlgButton(hdlg,IDC_RADIO_ALL,BST_UNCHECKED); - return TRUE; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_MIRANDADB,(LPARAM)MirandaPageProc); - break; - - case IDOK: - if(IsDlgButtonChecked(hdlg,IDC_RADIO_ALL)) { - nImportOption = IMPORT_ALL; - nCustomOptions = 0;//IOPT_MSGSENT|IOPT_MSGRECV|IOPT_URLSENT|IOPT_URLRECV; - DoImport = MirandaImport; - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); - break; - } - - if(IsDlgButtonChecked(hdlg,IDC_RADIO_CONTACTS)) { - nImportOption = IMPORT_CONTACTS; - nCustomOptions = 0; - DoImport = MirandaImport; - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); - break; - } - - if(IsDlgButtonChecked(hdlg,IDC_RADIO_CUSTOM)) { - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_ADVOPTIONS,(LPARAM)MirandaAdvOptionsPageProc); - break; - } - break; - - case IDCANCEL: - PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); - break; - } - break; - } - return FALSE; -} - -static const UINT InControls[]={IDC_IN_MSG,IDC_IN_URL,IDC_IN_FT,IDC_IN_OTHER}; -static const UINT OutControls[]={IDC_OUT_MSG,IDC_OUT_URL,IDC_OUT_FT,IDC_OUT_OTHER}; -static const UINT SysControls[]={IDC_CONTACTS, IDC_SYSTEM}; - -INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - { - struct tm *TM = NULL; - struct _SYSTEMTIME ST = {0}; - - dwSinceDate = DBGetContactSettingDword(NULL,IMPORT_MODULE,"ImportSinceTS",time(NULL)); - - TM = localtime(&dwSinceDate); - - ST.wYear = TM->tm_year + 1900; - ST.wMonth = TM->tm_mon + 1; - ST.wDay = TM->tm_mday; - - DateTime_SetSystemtime(GetDlgItem(hdlg,IDC_DATETIMEPICKER),GDT_VALID,&ST); - } - return TRUE; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_OPTIONS,(LPARAM)MirandaOptionsPageProc); - break; - - case IDOK: - DoImport = MirandaImport; - nImportOption = IMPORT_CUSTOM; - nCustomOptions = 0; - - if (IsDlgButtonChecked(hdlg,IDC_CONTACTS)) - nCustomOptions |= IOPT_CONTACTS | IOPT_GROUPS; - if (IsDlgButtonChecked(hdlg,IDC_SYSTEM)) - nCustomOptions |= IOPT_SYSTEM; - - // incoming - if (IsDlgButtonChecked(hdlg,IDC_IN_MSG)) - nCustomOptions |= IOPT_MSGRECV; - if (IsDlgButtonChecked(hdlg,IDC_IN_URL)) - nCustomOptions |= IOPT_URLRECV; - if (IsDlgButtonChecked(hdlg,IDC_IN_FT)) - nCustomOptions |= IOPT_FILERECV; - if (IsDlgButtonChecked(hdlg,IDC_IN_OTHER)) - nCustomOptions |= IOPT_OTHERRECV; - - // outgoing - if (IsDlgButtonChecked(hdlg,IDC_OUT_MSG)) - nCustomOptions |= IOPT_MSGSENT; - if (IsDlgButtonChecked(hdlg,IDC_OUT_URL)) - nCustomOptions |= IOPT_URLSENT; - if (IsDlgButtonChecked(hdlg,IDC_OUT_FT)) - nCustomOptions |= IOPT_FILESENT; - if (IsDlgButtonChecked(hdlg,IDC_OUT_OTHER)) - nCustomOptions |= IOPT_OTHERSENT; - - // since date - dwSinceDate = 0; - - if ( IsDlgButtonChecked( hdlg, IDC_SINCE )) { - struct _SYSTEMTIME ST = {0}; - - if (DateTime_GetSystemtime(GetDlgItem(hdlg,IDC_DATETIMEPICKER), &ST) == GDT_VALID) { - struct tm TM = {0}; - - TM.tm_mday = ST.wDay; - TM.tm_mon = ST.wMonth - 1; - TM.tm_year = ST.wYear - 1900; - - dwSinceDate = mktime(&TM); - - DBWriteContactSettingDword(NULL,IMPORT_MODULE,"ImportSinceTS",dwSinceDate); - } } - - if (nCustomOptions) - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); - break; - - case IDCANCEL: - PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); - break; - - case IDC_SINCE: - EnableWindow(GetDlgItem(hdlg, IDC_DATETIMEPICKER), IsDlgButtonChecked(hdlg, IDC_SINCE)); - break; - - if (HIWORD(wParam) != STN_CLICKED) - break; - - case IDC_ALL: - case IDC_INCOMING: - case IDC_OUTGOING: - { - int i; - - if (LOWORD(wParam) == IDC_ALL) - for (i = 0; i < sizeof(SysControls)/sizeof(SysControls[0]); i++) - CheckDlgButton(hdlg,SysControls[i], !IsDlgButtonChecked(hdlg,SysControls[i])); - - if (LOWORD(wParam) != IDC_OUTGOING) - for (i = 0; i < sizeof(InControls)/sizeof(InControls[0]); i++) - CheckDlgButton(hdlg,InControls[i], !IsDlgButtonChecked(hdlg,InControls[i])); - - if (LOWORD(wParam) != IDC_INCOMING) - for (i = 0; i < sizeof(OutControls)/sizeof(OutControls[0]); i++) - CheckDlgButton(hdlg,OutControls[i], !IsDlgButtonChecked(hdlg,OutControls[i])); - } - break; - - case IDC_MSG: - CheckDlgButton(hdlg,IDC_IN_MSG, !IsDlgButtonChecked(hdlg,IDC_IN_MSG)); - CheckDlgButton(hdlg,IDC_OUT_MSG, !IsDlgButtonChecked(hdlg,IDC_OUT_MSG)); - break; - - case IDC_URL: - CheckDlgButton(hdlg,IDC_IN_URL, !IsDlgButtonChecked(hdlg,IDC_IN_URL)); - CheckDlgButton(hdlg,IDC_OUT_URL, !IsDlgButtonChecked(hdlg,IDC_OUT_URL)); - break; - - case IDC_FT: - CheckDlgButton(hdlg,IDC_IN_FT, !IsDlgButtonChecked(hdlg,IDC_IN_FT)); - CheckDlgButton(hdlg,IDC_OUT_FT, !IsDlgButtonChecked(hdlg,IDC_OUT_FT)); - break; - - case IDC_OTHER: - CheckDlgButton(hdlg,IDC_IN_OTHER, !IsDlgButtonChecked(hdlg,IDC_IN_OTHER)); - CheckDlgButton(hdlg,IDC_OUT_OTHER, !IsDlgButtonChecked(hdlg,IDC_OUT_OTHER)); - break; - } - break; - } - return FALSE; -} - -#ifndef INVALID_SET_FILE_POINTER -#define INVALID_SET_FILE_POINTER ((DWORD)-1) -#endif - -// Read header from file, returns null on failure -struct DBHeader* GetHeader(HANDLE hDbFile) -{ - struct DBHeader* pdbHeader; - DWORD dwBytesRead; - - if (( pdbHeader = (DBHeader *)calloc(1, sizeof(struct DBHeader))) == NULL ) - return NULL; - - // Goto start of file - if (SetFilePointer(hDbFile, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - return FALSE; - - // Read header - if ( !ReadFile(hDbFile, pdbHeader, sizeof(struct DBHeader), &dwBytesRead, NULL ) || - dwBytesRead != sizeof(struct DBHeader)) - return NULL; - - // Return pointer to header - return pdbHeader; -} - -// Unsane: database crypted status -BOOL bEncrypted; -// Unsane: crypted database work fuction -int CheckPassword(WORD version, WORD cryptorUID, TCHAR * szDBName); -void InitSecurity(); - -int CheckFileFormat(HANDLE hDbFile) -{ - struct DBHeader* pdbHeader; - TCHAR* tszDbName; - - // Read header - if (( pdbHeader = GetHeader(hDbFile)) == NULL ) - return DB_INVALID; - - // Check header signature - bEncrypted = FALSE; - if (memcmp(pdbHeader->signature, &dbSignature, sizeof(pdbHeader->signature))) { - // Unsane: if not encrypted signature - if (memcmp(pdbHeader->signature, &dbSignatureEncrypted, sizeof(pdbHeader->signature))) { - AddMessage( LPGEN("Signature mismatch" )); - return DB_INVALID; - } - AddMessage(LPGEN("Database is Secured MMAP database")); - // Unsane: check password - InitSecurity(); - tszDbName = _tcsrchr(importFile, _T('\\')) + 1; - if (CheckPassword(pdbHeader->checkWord, pdbHeader->cryptorUID, tszDbName)) { - AddMessage(LPGEN("Secured MMAP: authorization successful")); - bEncrypted = TRUE; - } - else - { - AddMessage(LPGEN("You are not authorized for access to Database")); - return DB_INVALID; - } - } - - // Determine Miranda version - switch (pdbHeader->checkWord) { - case DB_000700: - AddMessage( LPGEN("This looks like a Miranda database, version 0.1.0.0 or above." )); - free(pdbHeader); - return DB_000700; - - default: - if (!bEncrypted){ - AddMessage( LPGEN("Version mismatch" )); - free(pdbHeader); - return DB_INVALID; - } - break; - } - return 1; -} - -// High level Miranda DB access functions -// Returns true if pValue points to the requested value - -BOOL GetSetting(HANDLE hDbFile, struct DBContact* pDbContact, char* pszModuleName, char* pszSettingName, DBVARIANT* pValue) -{ - struct DBContactSettings* pDbSettings; - if ( pDbSettings = GetSettingsGroupByModuleName(hDbFile, pDbContact, pszModuleName)) { - if ( GetSettingByName( pDbSettings, pszSettingName, pValue )) { - free(pDbSettings); - return TRUE; - } - #ifdef _LOGGING - AddMessage( LPGEN("Failed to find setting %s" ), pszSettingName ); - #endif - free(pDbSettings); - } -#ifdef _LOGGING - else AddMessage( LPGEN("Failed to find module %s" ), pszModuleName ); -#endif - - // Search failed - pValue->type = 0; - return FALSE; -} - -// ** -// ** CONTACT CHAIN -// ** - -// Return offset to first contact -DWORD FindFirstContact(struct DBHeader* pDbHeader) -{ - if (!pDbHeader) - return 0; - - return pDbHeader->ofsFirstContact; -} - -DWORD FindOwnerContact(struct DBHeader* pDbHeader) -{ - if (!pDbHeader) - return 0; - - return pDbHeader->ofsUser; -} - -// Return offset to next contact -DWORD FindNextContact(struct DBContact* pDbContact) -{ - if (!pDbContact) - return 0; - - if (pDbContact->signature != DBCONTACT_SIGNATURE) - return 0; - - return pDbContact->ofsNext; -} - - -// Read the contact at offset 'dwOffset' -// Returns true if successful and pDbContact points to the contact struct -// pDbContact must point to allocated struct -BOOL GetContact(HANDLE hDbFile, DWORD dwOffset, struct DBContact* pDbContact) -{ - DWORD dwBytesRead; - - // Early reject - if (dwOffset == 0 || dwOffset >= dwFileSize) - return FALSE; - - // ** Read and verify the struct - - if (SetFilePointer(hDbFile, (LONG)dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - return FALSE; - - if ((!ReadFile(hDbFile, pDbContact, sizeof(struct DBContact), &dwBytesRead, NULL)) || - (dwBytesRead != sizeof(struct DBContact))) - return FALSE; - - if ((pDbContact->signature != DBCONTACT_SIGNATURE) || - (pDbContact->ofsNext >= dwFileSize)) - return FALSE; // Contact corrupted - - return TRUE; -} - -// Return ptr to next setting in settings struct -char* GetNextSetting(char* pDbSetting) -{ - // Get next setting - pDbSetting = pDbSetting + *pDbSetting+1; // Skip name - switch( *(BYTE*)pDbSetting ) { - case DBVT_BYTE: - pDbSetting = pDbSetting+1+1; - break; - - case DBVT_WORD: - pDbSetting = pDbSetting+1+2; - break; - - case DBVT_DWORD: - pDbSetting = pDbSetting+1+4; - break; - - case DBVT_ASCIIZ: - case DBVT_UTF8: - case DBVT_BLOB: - case DBVTF_VARIABLELENGTH: - pDbSetting = pDbSetting + 3 + *(WORD*)(pDbSetting+1); - break; - - case DBVT_DELETED: - AddMessage( LPGEN("DEBUG: Deleted setting treated as 0-length setting")); - pDbSetting = pDbSetting+1; - break; - - default: - // Unknown datatype assert - AddMessage( LPGEN("ERROR: Faulty settings chain")); - return NULL; - } - - return pDbSetting; -} - - -// ** -// ** SETTINGS CHAIN -// ** - -// Return the settings at offset 'dwOffset' -BOOL GetSettingsGroup(HANDLE hDbFile, DWORD dwOffset, struct DBContactSettings** pDbSettings) -{ - DWORD dwBytesRead, dwBlobSize, dwHead; - struct DBContactSettings pSettings; - - // Early reject - if (dwOffset == 0 || dwOffset >= dwFileSize) - return FALSE; - - // ** Read and verify the struct - if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - return FALSE; - - dwHead = offsetof(struct DBContactSettings, blob); - if ((!ReadFile(hDbFile, &pSettings, dwHead, &dwBytesRead, NULL)) || - (dwBytesRead != dwHead)) - return FALSE; - - if (pSettings.signature != DBCONTACTSETTINGS_SIGNATURE) - return FALSE; // Setttings corrupted - - // ** Read the struct and the following blob - dwBlobSize = pSettings.cbBlob; - if (!(*pDbSettings = (DBContactSettings *)calloc(1, sizeof(struct DBContactSettings) + dwBlobSize))) - return FALSE; - - memcpy(*pDbSettings, &pSettings, dwHead ); - - if ((!ReadFile(hDbFile, (*pDbSettings)->blob, sizeof(struct DBContactSettings) - dwHead + dwBlobSize, &dwBytesRead, NULL)) || - (dwBytesRead != sizeof(struct DBContactSettings) - dwHead + dwBlobSize)) - { - free(*pDbSettings); - return FALSE; - } - - return TRUE; -} - -// pDbContact is a ptr to a struct DBContact -// Returns pointer to a struct DBContactSettings or NULL -struct DBContactSettings* GetSettingsGroupByModuleName(HANDLE hDbFile, struct DBContact* pDbContact, char* pszName) -{ - char* pszGroupName; - struct DBContactSettings* pSettingsGroup; - DWORD dwGroupOfs; - - // Get ptr to first settings group - if (!(dwGroupOfs = pDbContact->ofsFirstSettings)) - return NULL; // No settings exists in this contact - - // Loop over all settings groups - while (dwGroupOfs && dwGroupOfs < dwFileSize) { - pSettingsGroup = NULL; - - // Read and verify the struct - if (!GetSettingsGroup(hDbFile, dwGroupOfs, &pSettingsGroup)) - return NULL; // Bad struct - - // Struct OK, now get the name - if ((pszGroupName = GetName(hDbFile, pSettingsGroup->ofsModuleName))) { - - // Is it the right one? - if (strcmp(pszGroupName, pszName) == 0) { - #ifdef _LOGGING - AddMessage( LPGEN("Found module: %s"), pszGroupName ); - #endif - return pSettingsGroup; - } - #ifdef _LOGGING - else AddMessage( LPGEN("Ignoring module: %s"), pszGroupName ); - #endif - } - else AddMessage( LPGEN("Warning: Found module with no name")); - - dwGroupOfs = pSettingsGroup->ofsNext; - - if (pSettingsGroup) - free(pSettingsGroup); - } - - // Search failed - return NULL; -} - -// pDbSettings must point to a complete DBContactSettings struct in memory -int GetSettingByName(struct DBContactSettings* pDbSettings, char* pszSettingName, DBVARIANT* dbv) -{ - char pszName[256]; - // We need at least one setting to start with - char* pDbSetting = (char *)pDbSettings->blob; - if ( !pDbSetting ) - return FALSE; - - // ** pDbSettings now points to the first setting in this module - - // Loop over all settings - while (pDbSetting && *pDbSetting) { - memcpy(pszName, pDbSetting+1, *pDbSetting); - pszName[*pDbSetting] = 0; - - // Is this the right one? - if (strcmp(pszSettingName, pszName) == 0) { - return GetSettingValue(pDbSetting, dbv); - } - - #ifdef _LOGGING - AddMessage( LPGEN("Ignoring setting: %s"), pszName ); - #endif - pDbSetting = GetNextSetting(pDbSetting); - } - - // Search failed - return FALSE; -} - -// dwSettingpointer points to a valid DBSettings struct -int GetSettingValue(char* pBlob, DBVARIANT* dbv) -{ - #ifdef _LOGGING - { - char* pszName = calloc((*pBlob)+1, 1); - memcpy(pszName, pBlob+1, *pBlob); - AddMessage( LPGEN("Getting type %u value for setting: %s"), (BYTE)*(pBlob+(*pBlob)+1), pszName ); - free(pszName); - } - #endif - - // Skip name - pBlob = pBlob + (*pBlob)+1; - dbv->type = ( BYTE )*pBlob++; - - // Check what type it is - switch( dbv->type ) { - case DBVT_BYTE: - dbv->bVal = *pBlob; - return TRUE; - - case DBVT_WORD: - if (bEncrypted) - DecodeMemory((BYTE *)pBlob, sizeof(pBlob)); - dbv->wVal = *(WORD*)pBlob; - return TRUE; - - case DBVT_DWORD: - if (bEncrypted) - DecodeMemory((BYTE *)pBlob, sizeof(pBlob)); - dbv->dVal = *(DWORD*)pBlob; - return TRUE; - - case DBVT_ASCIIZ: - case DBVT_UTF8: - dbv->cchVal = *(WORD*)pBlob; - dbv->pszVal = (char *)calloc( dbv->cchVal+1, sizeof( char )); - if (bEncrypted) - DecodeCopyMemory((BYTE *)dbv->pszVal, pBlob+2, dbv->cchVal); - else - memcpy( dbv->pszVal, pBlob+2, dbv->cchVal ); - dbv->pszVal[ dbv->cchVal ] = 0; - - return TRUE; - - case DBVTF_VARIABLELENGTH: - case DBVT_BLOB: - dbv->cpbVal = *(WORD*)pBlob; - dbv->pbVal = (BYTE *)calloc( dbv->cpbVal+1, sizeof( char )); - if (bEncrypted) - DecodeCopyMemory((BYTE *)dbv->pszVal, pBlob+2, dbv->cchVal); - else - memcpy( dbv->pbVal, pBlob+2, dbv->cpbVal ); - dbv->pbVal[ dbv->cpbVal ] = 0; - return TRUE; - - case DBVT_DELETED: - AddMessage( LPGEN("DEBUG: Deleted setting treated as 0-length setting")); - - default: - dbv->type = DBVT_DELETED; - } - - return FALSE; -} - -void FreeVariant( DBVARIANT* dbv ) -{ - switch( dbv->type ) { - case DBVT_ASCIIZ: - case DBVT_UTF8: - if ( dbv->pszVal ) - free( dbv->pszVal ); - break; - - case DBVTF_VARIABLELENGTH: - case DBVT_BLOB: - if ( dbv->pbVal ) - free( dbv->pbVal ); - break; - } - - dbv->type = 0; -} - -void WriteVariant( HANDLE hContact, const char* module, const char* var, DBVARIANT* dbv ) -{ - DBCONTACTWRITESETTING dbw; - dbw.szModule = module; - dbw.szSetting = var; - dbw.value = *dbv; - CallService( MS_DB_CONTACT_WRITESETTING, (WPARAM)hContact, (LPARAM)&dbw ); -} - -// Returns true if pDBEI has been filled in with nice values -// Don't forget to free those pointers! -BOOL GetEvent(HANDLE hDbFile, DWORD dwOffset, DBEVENTINFO* pDBEI) -{ - DWORD dwBytesRead; - struct DBEvent pEvent; - static char pBlob[65536]; - - // Early reject - if (dwOffset == 0 || dwOffset >= dwFileSize) - return FALSE; - - // ** Read and verify the struct - if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - return FALSE; - - if (!ReadFile(hDbFile, &pEvent, offsetof(struct DBEvent, blob), &dwBytesRead, NULL) || - (dwBytesRead != offsetof(struct DBEvent, blob))) - return FALSE; - - if (pEvent.signature != DBEVENT_SIGNATURE) - return FALSE; // Event corrupted - - // ** Read the blob - if ((!ReadFile(hDbFile, pBlob, pEvent.cbBlob, &dwBytesRead, NULL)) || - (dwBytesRead != pEvent.cbBlob)) - { - return FALSE; - } - - // ** Copy the static part to the event info struct - pDBEI->timestamp = pEvent.timestamp; - pDBEI->eventType = pEvent.eventType; - pDBEI->cbSize = sizeof(DBEVENTINFO); - pDBEI->cbBlob = pEvent.cbBlob; - pDBEI->pBlob = (PBYTE)pBlob; - pDBEI->flags = (pEvent.flags & ~(DBEF_SENT+DBEF_READ)) + - ((pEvent.flags & DBEF_SENT) ? DBEF_SENT : DBEF_READ ); // Imported events are always marked READ - - if (!(pDBEI->szModule = GetName(hDbFile, pEvent.ofsModuleName))) { - return FALSE; - } - - // Unsane: encrypt dbevent - if (bEncrypted) - DecodeMemory(pDBEI->pBlob, pDBEI->cbBlob); - - return TRUE; -} - -// Returns a pointer to a string with the name -// from a DBModuleName struct if given a file offset -// Returns NULL on failure -char* GetName(HANDLE hDbFile, DWORD dwOffset) -{ - static DWORD dwLastOffset = 0; - static HANDLE hLastDbFile = NULL; - static char szName[256] = {0}; - - DWORD dwBytesRead; - struct DBModuleName pModule; - - // Early reject - if (dwOffset == 0 || dwOffset >= dwFileSize) - return FALSE; - - // Quick lookup - if (dwOffset == dwLastOffset && hDbFile == hLastDbFile) - return szName; - - // ** Read and verify the name struct - if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - return NULL; - - if ((!ReadFile(hDbFile, &pModule, offsetof(struct DBModuleName, name), &dwBytesRead, NULL)) || - (dwBytesRead != offsetof(struct DBModuleName, name))) - return NULL; - - if (pModule.signature != DBMODULENAME_SIGNATURE) { - AddMessage( LPGEN("Modulename corrupted")); - return NULL; // ModuleName corrupted - } - - // ** Name struct OK, now read name into string buffer - if ((!ReadFile(hDbFile, szName, pModule.cbName, &dwBytesRead, NULL)) || (dwBytesRead != pModule.cbName)) { - return NULL; - } - - // terminate string - szName[pModule.cbName] = 0; - - // update last offset - dwLastOffset = dwOffset; - hLastDbFile = hDbFile; - - return szName; -} - -DWORD FindNextEvent(HANDLE hDbFile, DWORD dwOffset) -{ - DWORD dwBytesRead; - struct DBEvent pEvent; - - // Early reject - if (dwOffset == 0 || dwOffset >= dwFileSize) - return FALSE; - - // ** Read and verify the struct - if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) - return FALSE; - - if ((!ReadFile(hDbFile, &pEvent, sizeof(struct DBEvent), &dwBytesRead, NULL)) || - (dwBytesRead != sizeof(struct DBEvent))) - return FALSE; - - if ( pEvent.signature != DBEVENT_SIGNATURE || pEvent.ofsNext > dwFileSize ) - return FALSE; // Event corrupted - - return pEvent.ofsNext; -} - -int ImportGroups(HANDLE hDbFile, struct DBHeader* pdbHeader) -{ - struct DBContactSettings* pDbSettings; - struct DBContact DbContact; - char* pSetting; - DWORD dwOffset; - int nGroups = 0; - - // Find owner data - dwOffset = pdbHeader->ofsUser; - if (!GetContact(hDbFile, dwOffset, &DbContact)) { - AddMessage( LPGEN("No owner found.")); - return -1; - } - - // Find the module with the groups, and import them all - if ( pDbSettings = GetSettingsGroupByModuleName( hDbFile, &DbContact, "CListGroups" )) { - /*if (bEncrypted) - DecodeMemory(pDbSettings->blob, pDbSettings->cbBlob);*/ - pSetting = (char *)pDbSettings->blob; - while ( pSetting && *pSetting ) { - DBVARIANT dbv; - if ( GetSettingValue( pSetting, &dbv )) { - if ( CreateGroup( dbv.type, dbv.pszVal+1, NULL )) - nGroups++; - FreeVariant( &dbv ); - } - pSetting = GetNextSetting(pSetting); - } - free(pDbSettings); - - /*if (bEncrypted) - EncodeMemory(pDbSettings->blob, pDbSettings->cbBlob);*/ - } - - return nGroups; -} - -HANDLE ImportContact(HANDLE hDbFile, struct DBContact Contact) -{ - HANDLE hContact; - DBVARIANT group, nick, dbv; - char* pszProtoName; - char* pszUniqueSetting; - char* pszUserName; - char id[ 40 ]; - - // Check what protocol this contact belongs to - if ( !GetSetting( hDbFile, &Contact, "Protocol", "p", &dbv )) { - AddMessage( LPGEN("Skipping contact with no protocol")); - return INVALID_HANDLE_VALUE; - } - - pszProtoName = NEWSTR_ALLOCA( dbv.pszVal ); - FreeVariant( &dbv ); - - if ( !IsProtocolLoaded( pszProtoName )) { - AddMessage( LPGEN("Skipping contact, %s not installed."), pszProtoName ); - return INVALID_HANDLE_VALUE; - } - - // Skip protocols with no unique id setting (some non IM protocols return NULL) - pszUniqueSetting = (char*)CallProtoService(pszProtoName, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); - if ( !pszUniqueSetting || (INT_PTR)pszUniqueSetting == CALLSERVICE_NOTFOUND ) { - AddMessage( LPGEN("Skipping non-IM contact (%s)"), pszProtoName ); - return INVALID_HANDLE_VALUE; - } - - if ( !GetSetting(hDbFile, &Contact, pszProtoName, pszUniqueSetting, &dbv )) { - AddMessage( LPGEN("Skipping %s contact, ID not found"), pszProtoName ); - return INVALID_HANDLE_VALUE; - } - - // Does the contact already exist? - if ( dbv.type == DBVT_DWORD ) { - pszUserName = _ltoa( dbv.dVal, id, 10 ); - hContact = HContactFromNumericID( pszProtoName, pszUniqueSetting, dbv.dVal ); - } - else { - pszUserName = NEWSTR_ALLOCA( dbv.pszVal ); - hContact = HContactFromID( pszProtoName, pszUniqueSetting, dbv.pszVal ); - } - - if ( hContact != INVALID_HANDLE_VALUE ) { - AddMessage( LPGEN("Skipping duplicate %s contact %s"), pszProtoName, pszUserName ); - FreeVariant( &dbv ); - return INVALID_HANDLE_VALUE; - } - // No, add contact and copy some important settings - GetSetting(hDbFile, &Contact, "CList", "Group", &group); - - if ( !GetSetting( hDbFile, &Contact, "CList", "MyHandle", &nick )) - GetSetting(hDbFile, &Contact, pszProtoName, "Nick", &nick ); - - hContact = AddContact( hdlgProgress, pszProtoName, pszUniqueSetting, &dbv, &nick, &group ); - - if ( hContact != INVALID_HANDLE_VALUE) { - - // Hidden? - if ( GetSetting( hDbFile, &Contact, "CList", "Hidden", &dbv )) { - WriteVariant( hContact, "CList", "Hidden", &dbv ); - FreeVariant( &dbv ); - } - // Ignore settings - if ( GetSetting( hDbFile, &Contact, "Ignore", "Mask1", &dbv )) { - WriteVariant( hContact, "Ignore", "Mask1", &dbv ); - FreeVariant( &dbv ); - } - - // Apparent mode - if ( GetSetting( hDbFile, &Contact, pszProtoName, "ApparentMode", &dbv )) { - WriteVariant( hContact, pszProtoName, "ApparentMode", &dbv ); - FreeVariant( &dbv ); - } - - // Nick - if ( GetSetting( hDbFile, &Contact, pszProtoName, "Nick", &dbv )) { - WriteVariant( hContact, pszProtoName, "Nick", &dbv ); - FreeVariant( &dbv ); - } - - // Myhandle - if ( GetSetting( hDbFile, &Contact, pszProtoName, "MyHandle", &dbv )) { - WriteVariant( hContact, pszProtoName, "MyHandle", &dbv ); - FreeVariant( &dbv ); - } - - // First name - if ( GetSetting( hDbFile, &Contact, pszProtoName, "FirstName", &dbv )) { - WriteVariant( hContact, pszProtoName, "FirstName", &dbv ); - FreeVariant( &dbv ); - } - - // Last name - if ( GetSetting( hDbFile, &Contact, pszProtoName, "LastName", &dbv )) { - WriteVariant( hContact, pszProtoName, "LastName", &dbv ); - FreeVariant( &dbv ); - } - - // About - if ( GetSetting( hDbFile, &Contact, pszProtoName, "About", &dbv )) { - WriteVariant( hContact, pszProtoName, "About", &dbv ); - FreeVariant( &dbv ); - } - } - else AddMessage( LPGEN("Unknown error while adding %s contact %s"), pszProtoName, pszUserName ); - - return hContact; -} - -// This function should always be called after contact import. That is -// why there are no messages for errors related to contacts. Those -// would only be a repetition of the messages printed during contact -// import. - -static void ImportHistory(HANDLE hDbFile, struct DBContact Contact, PROTOCOLDESCRIPTOR **protocol, int protoCount) -{ - HANDLE hContact = INVALID_HANDLE_VALUE; - DWORD dwOffset; - MSG msg; - DBVARIANT proto; - int i, skipAll, bIsVoidContact; - - // Is it contats history import? - if ( protoCount == 0 ) { - - // Check what protocol this contact belongs to - if ( GetSetting( hDbFile, &Contact, "Protocol", "p", &proto )) { - - // Protocol installed? - if ( IsProtocolLoaded( proto.pszVal )) { - // Is contact in database? - char* pszUniqueSetting = (char*)CallProtoService( proto.pszVal, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); - - // Skip protocols with no unique id setting (some non IM protocols return NULL) - if ( pszUniqueSetting && ( INT_PTR )pszUniqueSetting != CALLSERVICE_NOTFOUND ) { - DBVARIANT dbv; - if ( GetSetting( hDbFile, &Contact, proto.pszVal, pszUniqueSetting, &dbv )) { - if ( dbv.type == DBVT_DWORD ) - hContact = HContactFromNumericID( proto.pszVal, pszUniqueSetting, dbv.dVal ); - else - hContact = HContactFromID( proto.pszVal, pszUniqueSetting, dbv.pszVal ); - FreeVariant( &dbv ); - } } } - FreeVariant( &proto ); - } - } - else hContact = NULL; //system history import - - // OK to import this chain? - if (hContact == INVALID_HANDLE_VALUE) { - nSkippedContacts++; - return; - } - - i = skipAll = 0; - bIsVoidContact = CallService( MS_DB_EVENT_GETCOUNT, ( WPARAM )hContact, 0 ) == 0; - - // Get the start of the event chain - dwOffset = Contact.ofsFirstEvent; - while (dwOffset) { - int skip = 0; - - // Copy the event and import it - DBEVENTINFO dbei = { 0 }; - if (GetEvent(hDbFile, dwOffset, &dbei)) { - // check protocols during system history import - if (hContact == NULL) { - int i; - skipAll = 1; - - for(i = 0; i < protoCount; i++) - if (!strcmp(dbei.szModule, protocol[i]->szName)) { //&& protocol[i]->type == PROTOTYPE_PROTOCOL) - skipAll = 0; - break; - } - - skip = skipAll; - } - - // custom filtering - if (!skip && nImportOption == IMPORT_CUSTOM) { - BOOL sent = (dbei.flags&DBEF_SENT); - - if (dbei.timestamp < (DWORD)dwSinceDate) - skip = 1; - - if (!skip) { - if (hContact) { - skip = 1; - switch(dbei.eventType) { - case EVENTTYPE_MESSAGE: - if ((sent?IOPT_MSGSENT:IOPT_MSGRECV)&nCustomOptions) - skip = 0; - break; - case EVENTTYPE_FILE: - if ((sent?IOPT_FILESENT:IOPT_FILERECV)&nCustomOptions) - skip = 0; - break; - case EVENTTYPE_URL: - if ((sent?IOPT_URLSENT:IOPT_URLRECV)&nCustomOptions) - skip = 0; - break; - default: - if ((sent?IOPT_OTHERSENT:IOPT_OTHERRECV)&nCustomOptions) - skip = 0; - break; - } - } - else if ( !( nCustomOptions & IOPT_SYSTEM )) - skip = 1; - } - - if (skip) - nSkippedEvents++; - } - - if (!skip) { - // Check for duplicate entries - if ( !IsDuplicateEvent( hContact, dbei )) { - // Add dbevent - if (!bIsVoidContact) - dbei.flags &= ~DBEF_FIRST; - if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) - nMessagesCount++; - else - AddMessage( LPGEN("Failed to add message")); - } - else - nDupes++; - } - } - - if ( !( i%10 )) { - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } } - - // skip this chain if needed - if ( skipAll ) - break; - - // Get next event - dwOffset = FindNextEvent(hDbFile, dwOffset); - i++; - } -} - -static void MirandaImport(HWND hdlg) -{ - int nDBVersion; - int i; - int nNumberOfContacts = 0; - MSG msg; - DWORD dwTimer; - DWORD dwOffset; - HANDLE hFile; - char* pszModuleName = NULL; - struct DBHeader* pdbHeader = NULL; - struct DBContact Contact; - - // Just to keep the macros happy - hdlgProgress = hdlg; - - // Reset statistics - nSkippedEvents = 0; - nDupes = 0; - nContactsCount = 0; - nMessagesCount = 0; - nGroupsCount = 0; - nSkippedContacts = 0; - SetProgress(0); - - // Open database - hFile = CreateFile(importFile, - GENERIC_READ, // open for reading - 0, // do not share - NULL, // no security - OPEN_EXISTING, // existing file only - FILE_ATTRIBUTE_NORMAL, // normal file - NULL); // no attr. template - - // Read error - if (hFile == INVALID_HANDLE_VALUE) { - AddMessage( LPGEN("Could not open file.")); - SetProgress(100); - return; - } - - // Check filesize - dwFileSize = GetFileSize(hFile, NULL) ; - if ((dwFileSize == INVALID_FILE_SIZE) || (dwFileSize < sizeof(struct DBHeader))) { - AddMessage( LPGEN("This is not a valid Miranda IM database.")); - SetProgress(100); - CloseHandle(hFile); - return; - } - - // Check header and database version - nDBVersion = CheckFileFormat(hFile); - if (nDBVersion == DB_INVALID) { - AddMessage( LPGEN("This is not a valid Miranda IM database.")); - SetProgress(100); - CloseHandle(hFile); - return; - } - - // Load database header - if (!(pdbHeader = GetHeader(hFile))) { - AddMessage( LPGEN("Read failure.")); - SetProgress(100); - CloseHandle(hFile); - return; - } - - // Get number of contacts - nNumberOfContacts = pdbHeader->contactCount; - AddMessage( LPGEN("Number of contacts in database: %d"), nNumberOfContacts ); - AddMessage( "" ); - - // Configure database for fast writing - CallService(MS_DB_SETSAFETYMODE, FALSE, 0); - - // Start benchmark timer - dwTimer = time(NULL); - - // Import Groups - if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_GROUPS)) { - AddMessage( LPGEN("Importing groups.")); - nGroupsCount = ImportGroups(hFile, pdbHeader); - if (nGroupsCount == -1) - AddMessage( LPGEN("Group import failed.")); - - AddMessage( "" ); - } - // End of Import Groups - - // Import Contacts - if (nImportOption != IMPORT_CUSTOM || (nCustomOptions & IOPT_CONTACTS)) { - AddMessage( LPGEN("Importing contacts.")); - i = 1; - dwOffset = FindFirstContact(pdbHeader); - while (dwOffset && (dwOffset < dwFileSize)) { - if (!GetContact(hFile, dwOffset, &Contact)) { - AddMessage( LPGEN("ERROR: Chain broken, no valid contact at %d"), dwOffset ); - SetProgress(100); - break; - } - - if (ImportContact(hFile, Contact) != INVALID_HANDLE_VALUE) - nContactsCount++; - - // Update progress bar - SetProgress(100 * i / nNumberOfContacts); - i++; - - // Process queued messages - if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - // Get next contact in chain - dwOffset = FindNextContact(&Contact); - } - } - else AddMessage( LPGEN("Skipping new contacts import.")); - AddMessage( "" ); - // 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.")); - dwOffset = FindOwnerContact(pdbHeader); - if (!GetContact(hFile, dwOffset, &Contact)) { - AddMessage( LPGEN("ERROR: Chain broken, no valid contact at %d"), dwOffset ); - SetProgress(100); - } - else { - PROTOCOLDESCRIPTOR **protocol; - int protoCount; - - CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&protoCount, (LPARAM)&protocol); - - if (protoCount > 0) - ImportHistory(hFile, Contact, protocol, protoCount); - } - } - else AddMessage( LPGEN("Skipping system history import.")); - - AddMessage( "" ); - - // Import other contact messages - if (nImportOption == IMPORT_ALL || (nCustomOptions & 2046)) { // 2 - 1024 types - AddMessage( LPGEN("Importing history.")); - dwOffset = FindFirstContact(pdbHeader); - for(i=1; i <= nNumberOfContacts; i++) { - if (!GetContact(hFile, dwOffset, &Contact)) { - AddMessage( LPGEN("ERROR: Chain broken, no valid contact at %d"), dwOffset ); - SetProgress(100); - break; - } - - ImportHistory(hFile, Contact, NULL, 0); - - SetProgress(100 * i / nNumberOfContacts); - dwOffset = FindNextContact(&Contact); - } - } - else AddMessage( LPGEN("Skipping history import.")); - - AddMessage( "" ); - } - // End of Import History - - // Restore database writing mode - CallService(MS_DB_SETSAFETYMODE, TRUE, 0); - - // Clean up before exit - CloseHandle(hFile); - free(pdbHeader); - - // Stop timer - dwTimer = time(NULL) - dwTimer; - - // Print statistics - AddMessage( LPGEN("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."), - nContactsCount, nGroupsCount, nMessagesCount); - - if ( nImportOption != IMPORT_CONTACTS ) { - if (nSkippedContacts) - AddMessage( LPGEN("Skipped %d contacts."), nSkippedContacts ); - - AddMessage((nImportOption == IMPORT_CUSTOM) ? - LPGEN("Skipped %d duplicates and %d filtered events.") : LPGEN("Skipped %d duplicates."), - nDupes, nSkippedEvents); -} } diff --git a/plugins/Dbx_mmap_SA/Import_SA/mirandadb0700.h b/plugins/Dbx_mmap_SA/Import_SA/mirandadb0700.h deleted file mode 100644 index 07216ddbcf..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/mirandadb0700.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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. - -*/ - - - -//all offsets are relative to the start of the file -//offsets are 0 if there is nothing in the chain or this is the last in the -//chain - - - - -/* tree diagram - -DBHeader - |-->end of file (plain offset) - |-->first contact (DBContact) - | |-->next contact (DBContact) - | | \--> ... - | |-->first settings (DBContactSettings) - | | |-->next settings (DBContactSettings) - | | | \--> ... - | | \-->module name (DBModuleName) - | \-->first/last/firstunread event - |-->user contact (DBContact) - | |-->next contact=NULL - | |-->first settings as above - | \-->first/last/firstunread event as above - \-->first module name (DBModuleName) - \-->next module name (DBModuleName) - \--> ... -*/ - -#define DB_THIS_VERSION 0x00000700u - -#include -// Unsane: added "checkWord", "cryptorUID" and removed "version" fields -struct DBHeader { - BYTE signature[16]; // 'Miranda ICQ DB',0,26 - /* - DWORD version; //as 4 bytes, ie 1.2.3.10=0x0102030a - //this version is 0x00000700 - */ - - WORD checkWord; - WORD cryptorUID; - DWORD ofsFileEnd; //offset of the end of the database - place to write - //new structures - DWORD slackSpace; //a counter of the number of bytes that have been - //wasted so far due to deleting structures and/or - //re-making them at the end. We should compact when - //this gets above a threshold - DWORD contactCount; //number of contacts in the chain,excluding the user - DWORD ofsFirstContact; //offset to first struct DBContact in the chain - DWORD ofsUser; //offset to struct DBContact representing the user - DWORD ofsFirstModuleName; //offset to first struct DBModuleName in the chain -}; - -#define DBCONTACT_SIGNATURE 0x43DECADEu -struct DBContact { - DWORD signature; - DWORD ofsNext; //offset to the next contact in the chain. zero if - //this is the 'user' contact or the last contact - //in the chain - DWORD ofsFirstSettings; //offset to the first DBContactSettings in the - //chain for this contact. - DWORD eventCount; //number of events in the chain for this contact - DWORD ofsFirstEvent,ofsLastEvent; //offsets to the first and last DBEvent in - //the chain for this contact - DWORD ofsFirstUnreadEvent; //offset to the first (chronological) unread event - //in the chain, 0 if all are read - DWORD timestampFirstUnread; //timestamp of the event at ofsFirstUnreadEvent -}; - -#define DBMODULENAME_SIGNATURE 0x4DDECADEu -struct DBModuleName { - DWORD signature; - DWORD ofsNext; //offset to the next module name in the chain - BYTE cbName; //number of characters in this module name - char name[1]; //name, no nul terminator -}; - -#define DBCONTACTSETTINGS_SIGNATURE 0x53DECADEu -struct DBContactSettings { - DWORD signature; - DWORD ofsNext; //offset to the next contactsettings in the chain - DWORD ofsModuleName; //offset to the DBModuleName of the owner of these - //settings - DWORD cbBlob; //size of the blob in bytes. May be larger than the - //actual size for reducing the number of moves - //required using granularity in resizing - BYTE blob[1]; //the blob. a back-to-back sequence of DBSetting - //structs, the last has cbName=0 -}; - -/* not a valid structure, content is figured out on the fly -struct DBSetting { - BYTE cbName; //number of bytes in the name of this setting - //this =0 marks the end - char szName[...]; //setting name, excluding nul - BYTE dataType; //type of data. see m_database.h, db/contact/getsetting - union { //a load of types of data, length is defined by dataType - BYTE bVal; WORD wVal; DWORD dVal; - struct { - WORD cbString; - char szVal[...]; //excludes nul terminator - }; - struct { - WORD cbBlob; - BYTE blobVal[...]; - }; - }; -}; -*/ - -#define DBEVENT_SIGNATURE 0x45DECADEu -struct DBEvent { - DWORD signature; - DWORD ofsPrev,ofsNext; //offset to the previous and next events in the - //chain. Chain is sorted chronologically - DWORD ofsModuleName; //offset to a DBModuleName struct of the name of - //the owner of this event - DWORD timestamp; //seconds since 00:00:00 01/01/1970 - DWORD flags; //see m_database.h, db/event/add - WORD eventType; //module-defined event type - DWORD cbBlob; //number of bytes in the blob - BYTE blob[1]; //the blob. module-defined formatting -}; -#include diff --git a/plugins/Dbx_mmap_SA/Import_SA/mirandahistory.cpp b/plugins/Dbx_mmap_SA/Import_SA/mirandahistory.cpp deleted file mode 100644 index ba7a923df7..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/mirandahistory.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* -Miranda ICQ: the free icq client for MS Windows -Copyright (C) 2000-2 Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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 -#include -#include -#include "resource.h" -#include "import.h" - -BOOL CALLBACK MirandaPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -BOOL CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -BOOL CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); -extern char importFile[MAX_PATH]; -extern void (*DoImport)(HWND); -static void OldMirandaHistoryImport(HWND hdlgProgress); -HANDLE HContactFromUIN(DWORD uin); -HANDLE HistoryImportFindContact(HWND hdlgProgress,DWORD uin,int addUnknown); -static DWORD importOptions; - -BOOL CALLBACK MirandaHistoryPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - CheckDlgButton(hdlg,IDC_ADDUNKNOWN,BST_CHECKED); - CheckDlgButton(hdlg,IDC_MSGRECV,BST_CHECKED); - CheckDlgButton(hdlg,IDC_MSGSENT,BST_CHECKED); - CheckDlgButton(hdlg,IDC_URLRECV,BST_CHECKED); - CheckDlgButton(hdlg,IDC_URLSENT,BST_CHECKED); - CheckDlgButton(hdlg,IDC_AUTHREQ,BST_CHECKED); - CheckDlgButton(hdlg,IDC_ADDED,BST_CHECKED); - return TRUE; - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDC_BACK: - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_MIRANDADB,(LPARAM)MirandaPageProc); - break; - case IDOK: - importOptions=0; - if(IsDlgButtonChecked(hdlg,IDC_ADDUNKNOWN)) importOptions|=IOPT_ADDUNKNOWN; - if(IsDlgButtonChecked(hdlg,IDC_MSGSENT)) importOptions|=IOPT_MSGSENT; - if(IsDlgButtonChecked(hdlg,IDC_MSGRECV)) importOptions|=IOPT_MSGRECV; - if(IsDlgButtonChecked(hdlg,IDC_URLSENT)) importOptions|=IOPT_URLSENT; - if(IsDlgButtonChecked(hdlg,IDC_URLRECV)) importOptions|=IOPT_URLRECV; - if(IsDlgButtonChecked(hdlg,IDC_AUTHREQ)) importOptions|=IOPT_AUTHREQ; - if(IsDlgButtonChecked(hdlg,IDC_ADDED)) importOptions|=IOPT_ADDED; - DoImport=OldMirandaHistoryImport; - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); - break; - case IDCANCEL: - PostMessage(GetParent(hdlg),WM_CLOSE,0,0); - break; - } - break; - } - return FALSE; -} - -#define HISTORY_MSGRECV 1 -#define HISTORY_MSGSEND 2 -#define HISTORY_URLRECV 3 -#define HISTORY_URLSEND 4 -#define HISTORY_AUTHREQ 5 -#define HISTORY_ADDED 6 -#define issent(t) ((t)==HISTORY_MSGSEND || (t)==HISTORY_URLSEND) -static int historyTypeToOption[]={0,IOPT_MSGRECV,IOPT_MSGSENT,IOPT_URLRECV,IOPT_URLSENT,IOPT_AUTHREQ,IOPT_ADDED}; - -static PBYTE ReadHistoryLines(FILE *fp,int *cbBlob) -{ - char str[2048]; - char *blob; - int ofs; - *cbBlob=0; - blob=NULL; - while(fgets(str,sizeof(str),fp) && lstrcmp(str,"\xEE\xEE\xEE\xEE\r\n")) { - ofs=*cbBlob; - *cbBlob+=lstrlen(str); - blob=(char*)realloc(blob,*cbBlob+1); - lstrcpy(blob+ofs,str); - } - if (*cbBlob) { - (*cbBlob)--; - blob[*cbBlob-1]=0; - } - else { - *cbBlob=1; - blob=(char*)malloc(1); - blob[0]=0; - } - return (PBYTE)blob; -} - -static void OldMirandaHistoryImport(HWND hdlgProgress) -{ - int fileSize; - FILE *fp; - char str[2048],*eol,*timeofs; - HANDLE hContact; - int type; - DWORD uin; - struct tm tmEventTime; - DBEVENTINFO dbei; - - AddMessage("Old Miranda history import routines initialised"); - fp=fopen(importFile,"rb"); - AddMessage("Calibrating status support functions"); - fseek(fp,0,SEEK_END); - fileSize=ftell(fp); - fseek(fp,0,SEEK_SET); - SetProgress(0); - - ZeroMemory(&dbei,sizeof(dbei)); - dbei.cbSize=sizeof(dbei); - dbei.szModule=ICQOSCPROTONAME; - - while(!feof(fp)) { - SetProgress(100*ftell(fp)/fileSize); - if(fgets(str,sizeof(str),fp)==NULL) break; - eol=str+lstrlen(str)-1; - - while(*eol=='\r' || *eol=='\n' && eol!=str-1) - *(eol--)=0; - - if(lstrlen(str)<20) continue; - type=*eol; - uin=strtoul(str,NULL,10); - if(uin==0) continue; //skip MSN - timeofs=str+lstrlen(str)-20; - tmEventTime.tm_hour=atoi(timeofs); - timeofs=strchr(timeofs,':'); - if(timeofs==NULL) continue; - tmEventTime.tm_min=atoi(timeofs+1); - tmEventTime.tm_sec=0; - tmEventTime.tm_isdst=-1; - tmEventTime.tm_mday=atoi(timeofs+7); - tmEventTime.tm_mon=atoi(timeofs+10)-1; - tmEventTime.tm_year=atoi(timeofs+13)-1900; - dbei.timestamp=mktime(&tmEventTime)+_timezone; - if (!(importOptions&historyTypeToOption[type])) continue; - hContact=HistoryImportFindContact(hdlgProgress,uin,importOptions&IOPT_ADDUNKNOWN); - if(hContact==INVALID_HANDLE_VALUE) break; - dbei.flags=issent(type)?DBEF_SENT:DBEF_READ; - switch(type) { - case HISTORY_MSGRECV: - case HISTORY_MSGSEND: - dbei.eventType=EVENTTYPE_MESSAGE; - dbei.pBlob=ReadHistoryLines(fp,&dbei.cbBlob); - CallService(MS_DB_EVENT_ADD,(WPARAM)hContact,(LPARAM)&dbei); - break; - case HISTORY_URLRECV: - case HISTORY_URLSEND: - dbei.eventType=EVENTTYPE_URL; - dbei.pBlob=ReadHistoryLines(fp,&dbei.cbBlob); - { char *endOfUrl; - endOfUrl=strchr(dbei.pBlob,'\r'); - if(endOfUrl!=NULL) { - *endOfUrl=0; - dbei.cbBlob--; - MoveMemory(endOfUrl+1,endOfUrl+2,dbei.cbBlob-(endOfUrl-dbei.pBlob)); - } - } - CallService(MS_DB_EVENT_ADD,(WPARAM)hContact,(LPARAM)&dbei); - break; - case HISTORY_AUTHREQ: - dbei.eventType=EVENTTYPE_AUTHREQUEST; - dbei.pBlob=ReadHistoryLines(fp,&dbei.cbBlob); - dbei.pBlob=(PBYTE)realloc(dbei.pBlob,dbei.cbBlob+8); - MoveMemory(dbei.pBlob+8,dbei.pBlob,dbei.cbBlob); - *(PDWORD)dbei.pBlob=uin; - *(char*)(dbei.pBlob+4)=0; //leave nick, first, last, email blank - *(char*)(dbei.pBlob+5)=0; - *(char*)(dbei.pBlob+6)=0; - *(char*)(dbei.pBlob+7)=0; - dbei.cbBlob+=8; - CallService(MS_DB_EVENT_ADD,(WPARAM)(HANDLE)NULL,(LPARAM)&dbei); - break; - case HISTORY_ADDED: - dbei.eventType=EVENTTYPE_ADDED; - dbei.pBlob=(PBYTE)malloc(8); - dbei.cbBlob=8; - *(PDWORD)dbei.pBlob=uin; - *(char*)(dbei.pBlob+4)=0; //leave nick, first, last, email blank - *(char*)(dbei.pBlob+5)=0; - *(char*)(dbei.pBlob+6)=0; - *(char*)(dbei.pBlob+7)=0; - CallService(MS_DB_EVENT_ADD,(WPARAM)(HANDLE)NULL,(LPARAM)&dbei); - break; - } - } - AddMessage("Terminating cached I/O access"); - fclose(fp); - AddMessage("Import completed successfully"); - SetProgress(100); -} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Import_SA/progress.cpp b/plugins/Dbx_mmap_SA/Import_SA/progress.cpp deleted file mode 100644 index f3f4e9f08a..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/progress.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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 -#include -#include - -#include "import.h" - -#define PROGM_START (WM_USER+100) - -INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); - -void (*DoImport)(HWND); - -INT_PTR CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) -{ - switch(message) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,0,0); - SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,1,0); - SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,2,0); - SendDlgItemMessage(hdlg,IDC_PROGRESS,PBM_SETRANGE,0,MAKELPARAM(0,100)); - PostMessage(hdlg,PROGM_START,0,0); - return TRUE; - - case PROGM_SETPROGRESS: - SendDlgItemMessage(hdlg,IDC_PROGRESS,PBM_SETPOS,wParam,0); - break; - - case PROGM_ADDMESSAGE: - { - int i=SendDlgItemMessage(hdlg,IDC_STATUS,LB_ADDSTRING,0,lParam); - SendDlgItemMessage(hdlg,IDC_STATUS,LB_SETTOPINDEX,i,0); - } - break; - - case PROGM_START: - DoImport(hdlg); - SendMessage(GetParent(hdlg),WIZM_ENABLEBUTTON,1,0); - SendMessage(GetParent(hdlg),WIZM_ENABLEBUTTON,2,0); - break; - - case WM_COMMAND: - switch(LOWORD(wParam)) { - case IDOK: - PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_FINISHED,(LPARAM)FinishedPageProc); - break; - case IDCANCEL: - PostMessage(GetParent(hdlg),WM_CLOSE,0,0); - break; - } - break; - } - return FALSE; -} - -void AddMessage( const char* fmt, ... ) -{ - va_list args; - char msgBuf[ 4096 ]; - va_start( args, fmt ); - - mir_vsnprintf( msgBuf, sizeof(msgBuf), Translate(fmt), args ); - - #ifdef _LOGGING - { - FILE *stream; - stream = fopen("Import Debug.log", "a"); - fprintf(stream, "%s\n", msgBuf); - fclose(stream); - } - #endif - - - { TCHAR* str = mir_a2t( msgBuf ); - SendMessage( hdlgProgress, PROGM_ADDMESSAGE, 0, ( LPARAM )str ); - mir_free( str ); - } -} diff --git a/plugins/Dbx_mmap_SA/Import_SA/res/Version.rc b/plugins/Dbx_mmap_SA/Import_SA/res/Version.rc new file mode 100644 index 0000000000..a2005a9fdd --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/res/Version.rc @@ -0,0 +1,42 @@ +// Microsoft Visual C++ generated resource script. +// +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include "afxres.h" +#include "..\src\version.h" + +#ifdef _WIN32 +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL +#endif //_WIN32 + +VS_VERSION_INFO VERSIONINFO + FILEVERSION __FILEVERSION_STRING + PRODUCTVERSION __FILEVERSION_STRING + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "FileDescription", __DESCRIPTIONSHORT + VALUE "InternalName", __PLUGIN_NAME + VALUE "LegalCopyright", __COPYRIGHT + VALUE "OriginalFilename", __FILENAME + VALUE "ProductName", __PLUGIN_NAME + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/plugins/Dbx_mmap_SA/Import_SA/res/resource.rc b/plugins/Dbx_mmap_SA/Import_SA/res/resource.rc new file mode 100644 index 0000000000..b5e7e066e7 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/res/resource.rc @@ -0,0 +1,322 @@ +// Microsoft Visual C++ generated resource script. +// +#include "..\src\resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Ðóññêèé (Ðîññèÿ) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) +LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT +#pragma code_page(1251) + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_IMPORT ICON "import.ico" +IDI_PASS ICON "pass.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_LOGIN DIALOGEX 0, 0, 190, 86 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW +CAPTION "Miranda MMAP Secured Database" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 + CTEXT "EN",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP + EDITTEXT IDC_USERPASS,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL | WS_GROUP + DEFPUSHBUTTON "OK",IDOK,36,71,50,14 + PUSHBUTTON "Cancel",IDCANCEL,102,71,50,14 +END + +IDD_IMPORTTYPE DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "Choose how you would like to import:",IDC_STATIC,5,16,210,8 + CONTROL "From a Miranda IM database.",IDC_MIRANDA,"Button",BS_AUTORADIOBUTTON,11,31,204,10 + CONTROL "From a Mirabilis ICQ (99a - 2003a) database.",IDC_MIRABILIS, + "Button",BS_AUTORADIOBUTTON,11,46,204,10 + CONTROL "Use the Find/Add contacts tool to populate my contact list.",IDC_USEFINDADD, + "Button",BS_AUTORADIOBUTTON,11,61,204,10 +END + +IDD_WIZARDINTRO DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "This wizard will help you import contacts and message history from Mirabilis ICQ, as well as letting you import from other Miranda IM profiles.",IDC_STATIC,33,12,182,32 + ICON IDI_IMPORT,IDC_STATIC,5,12,20,20 + LTEXT "Click ""Next"" to choose the information you wish to import, or click ""Cancel"" to exit the wizard and continue using Miranda.",IDC_STATIC,33,49,182,25 + CTEXT "It is recommended that you create a backup of your current Miranda profile before importing.",IDC_STATIC,30,81,182,21 +END + +IDD_FINISHED DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "If you wish to import more information, click ""Next"" to return to the start of the wizard, otherwise click ""Finish"" to start using Miranda.",IDC_STATIC,5,20,210,16 + LTEXT "You will probably never need to use this wizard again, so you can save memory by not loading it every time you start Miranda. This will mean that the import menu item will no longer be available.",IDC_STATIC,5,41,210,24 + CONTROL "Do not load the import plugin at startup again",IDC_DONTLOADPLUGIN, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,97,210,10 + LTEXT "Import completed",IDC_STATIC,5,7,210,8 + LTEXT "If at a future date you wish to use the wizard again, you can make it load again by going to the Plugins section of the Options dialog box.",IDC_STATIC,5,69,210,24 +END + +IDD_MIRABILISDB DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "Miranda has found Mirabilis ICQ databases corresponding to the following ICQ numbers. Please select the one you wish to import, or click ""Other Database"" if your database is not listed.",IDC_STATIC,5,5,210,24 + LISTBOX IDC_LIST,5,31,210,36,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "&Other Database...",IDC_OTHER,149,69,66,14 + RTEXT "&Filename:",IDC_STATIC,5,88,34,8 + EDITTEXT IDC_FILENAME,42,86,173,12,ES_AUTOHSCROLL + CTEXT "Warning: Mirabilis ICQ running. Import may not be reliable.",IDC_MIRABILISRUNNING,5,101,210,8 + RTEXT "&Account:",IDC_STATIC,6,74,34,8 + COMBOBOX IDC_MIRABILISACCOUNT,42,71,102,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP +END + +IDD_MIRANDADB DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "Miranda has found Miranda profiles with the following names. Please select the one you wish to import, or click ""Other Profile"" if your profile is not listed, or if the list is empty.",IDC_STATIC,5,10,210,24 + LISTBOX IDC_LIST,5,36,210,36,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "&Other Profile...",IDC_OTHER,149,74,66,14 + RTEXT "&Filename:",IDC_STATIC,5,93,34,8 + EDITTEXT IDC_FILENAME,41,91,174,12,ES_AUTOHSCROLL +END + +IDD_PROGRESS DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "Now importing...",IDC_STATIC,5,11,62,8 + CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,5,24,210,10 + LISTBOX IDC_STATUS,5,38,210,61,NOT LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | LBS_NOSEL | WS_VSCROLL | WS_TABSTOP +END + +IDD_WIZARD DIALOGEX 0, 0, 220, 143 +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_CAPTION | WS_SYSMENU +CAPTION "Import Information Wizard" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + DEFPUSHBUTTON "&Next >",IDOK,120,124,45,13 + PUSHBUTTON "Cancel",IDCANCEL,170,124,45,13 + PUSHBUTTON "< &Back",IDC_BACK,75,124,45,13 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-7,115,234,1 +END + +IDD_OPTIONS DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + CONTROL "Import all contacts and all messages",IDC_RADIO_ALL, + "Button",BS_AUTORADIOBUTTON | BS_LEFT | BS_TOP | WS_TABSTOP,7,10,206,11 + CONTROL "Only import contacts",IDC_RADIO_CONTACTS,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,7,42,206,10 + CONTROL "Custom import",IDC_RADIO_CUSTOM,"Button",BS_AUTORADIOBUTTON | WS_DISABLED | WS_TABSTOP,7,74,206,10 + LTEXT "Select this if you want to import as much data as possible. This is the recommended option.",IDC_STATIC_ALL,26,20,187,16 + LTEXT "Select this if you want to import contacts but don't want to import any message history.",IDC_STATIC_CONTACTS,26,52,187,16 + LTEXT "Select this if you want to cutomize what to import.",IDC_STATIC_CUSTOM,26,84,187,16,WS_DISABLED +END + +IDD_ICQSERVER DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "Miranda has now been configured to automatically download the contacts in your server-side contact list the next time you connect to ICQ.",IDC_STATIC,7,9,206,31 + LTEXT "If you want to change the way Miranda handles server-side contacts at a later time, you can do this in the ""ICQ Contacts"" page in the Miranda options.",IDC_STATIC,7,44,206,37 +END + +IDD_ADVOPTIONS DIALOGEX 0, 0, 220, 114 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + CONTROL "New contacts && groups",IDC_CONTACTS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,16,100,10 + CONTROL "System history",IDC_SYSTEM,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,120,16,98,10 + LTEXT "Select items to import:",IDC_ALL,10,3,201,10,SS_NOTIFY + CTEXT "Incoming",IDC_INCOMING,2,34,86,10,SS_NOTIFY + CTEXT "Outgoing",IDC_OUTGOING,132,34,86,10,SS_NOTIFY + CONTROL "",IDC_IN_MSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,44,10,10 + CONTROL "",IDC_IN_URL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,56,10,10 + CONTROL "",IDC_IN_FT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,68,10,10 + CONTROL "",IDC_IN_OTHER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,80,10,10 + CONTROL "",IDC_OUT_MSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,44,10,10 + CONTROL "",IDC_OUT_URL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,56,10,10 + CONTROL "",IDC_OUT_FT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,68,10,10 + CONTROL "",IDC_OUT_OTHER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,80,10,10 + CONTROL "Only since:",IDC_SINCE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,99,100,10 + CONTROL "",IDC_DATETIMEPICKER,"SysDateTimePick32",DTS_RIGHTALIGN | WS_DISABLED | WS_TABSTOP,120,97,81,15 + CTEXT "Messages",IDC_MSG,54,44,112,8,SS_NOTIFY + CTEXT "URLs",IDC_URL,54,56,112,8,SS_NOTIFY + CTEXT "File Transfers",IDC_FT,54,68,112,8,SS_NOTIFY + CTEXT "Other",IDC_OTHER,54,80,112,8,SS_NOTIFY + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,0,93,222,1 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,0,31,223,1 +END + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "..\\src\\resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_LOGIN, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 175 + TOPMARGIN, 7 + BOTTOMMARGIN, 78 + END + + IDD_IMPORTTYPE, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 215 + TOPMARGIN, 5 + BOTTOMMARGIN, 109 + END + + IDD_WIZARDINTRO, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 215 + TOPMARGIN, 5 + BOTTOMMARGIN, 109 + END + + IDD_FINISHED, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 215 + TOPMARGIN, 5 + BOTTOMMARGIN, 109 + END + + IDD_MIRABILISDB, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 215 + TOPMARGIN, 5 + BOTTOMMARGIN, 109 + END + + IDD_MIRANDADB, DIALOG + BEGIN + LEFTMARGIN, 3 + RIGHTMARGIN, 216 + TOPMARGIN, 1 + BOTTOMMARGIN, 113 + END + + IDD_PROGRESS, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 215 + TOPMARGIN, 5 + BOTTOMMARGIN, 109 + END + + IDD_WIZARD, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 215 + TOPMARGIN, 7 + BOTTOMMARGIN, 137 + END + + IDD_OPTIONS, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 213 + TOPMARGIN, 7 + BOTTOMMARGIN, 111 + END + + IDD_ICQSERVER, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 213 + TOPMARGIN, 7 + BOTTOMMARGIN, 107 + END + + IDD_ADVOPTIONS, DIALOG + BEGIN + VERTGUIDE, 10 + VERTGUIDE, 45 + VERTGUIDE, 110 + VERTGUIDE, 120 + VERTGUIDE, 175 + TOPMARGIN, 3 + HORZGUIDE, 16 + HORZGUIDE, 34 + HORZGUIDE, 104 + END +END +#endif // APSTUDIO_INVOKED + + +#endif // Ðóññêèé (Ðîññèÿ) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/plugins/Dbx_mmap_SA/Import_SA/resource.h b/plugins/Dbx_mmap_SA/Import_SA/resource.h deleted file mode 100644 index 915ee8097b..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/resource.h +++ /dev/null @@ -1,68 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by resource.rc -// -#define IDC_BACK 3 -#define IDD_WIZARD 101 -#define IDD_OPTIONS 102 -#define IDD_ICQSERVER 104 -#define IDD_LOGIN 105 -#define IDD_IMPORTTYPE 106 -#define IDD_WIZARDINTRO 107 -#define IDD_FINISHED 108 -#define IDD_MIRABILISDB 109 -#define IDD_MIRANDADB 110 -#define IDD_PROGRESS 111 -#define IDD_ADVOPTIONS 112 -#define IDI_IMPORT 177 -#define IDI_PASS 178 -#define IDC_MIRABILIS 1000 -#define IDC_DONTLOADPLUGIN 1001 -#define IDC_MIRANDA 1002 -#define IDC_USEFINDADD 1003 -#define IDC_OTHER 1004 -#define IDC_LIST 1005 -#define IDC_FILENAME 1006 -#define IDC_PROGRESS 1007 -#define IDC_STATUS 1008 -#define IDC_MIRABILISRUNNING 1009 -#define IDC_MIRABILISACCOUNT 1010 -#define IDC_RADIO_ALL 1011 -#define IDC_RADIO_CONTACTS 1012 -#define IDC_RADIO_CUSTOM 1013 -#define IDC_STATIC_ALL 1014 -#define IDC_STATIC_CONTACTS 1015 -#define IDC_STATIC_CUSTOM 1016 -#define IDC_USERPASS 1017 -#define IDC_LANG 1018 -#define IDC_DATETIMEPICKER 1019 -#define IDC_IN_FT 1020 -#define IDC_CONTACTS 1021 -#define IDC_SYSTEM 1022 -#define IDC_SINCE 1023 -#define IDC_IN_MSG 1024 -#define IDC_IN_URL 1025 -#define IDC_OUT_FT 1026 -#define IDC_OUT_MSG 1027 -#define IDC_OUT_URL 1028 -#define IDC_IN_OTHER 1029 -#define IDC_OUT_OTHER 1030 -#define IDC_INCOMING 1031 -#define IDC_OUTGOING 1032 -#define IDC_ALL 1033 -#define IDC_MSG 1034 -#define IDC_URL 1035 -#define IDC_FT 1036 -#define IDC_HEADERBAR 1037 -#define IDC_STATIC -1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 106 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1038 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/Dbx_mmap_SA/Import_SA/resource.rc b/plugins/Dbx_mmap_SA/Import_SA/resource.rc deleted file mode 100644 index c37ea1cccf..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/resource.rc +++ /dev/null @@ -1,322 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Ðóññêèé (Ðîññèÿ) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT -#pragma code_page(1251) - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_IMPORT ICON "res/import.ico" -IDI_PASS ICON "res/pass.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_LOGIN DIALOGEX 0, 0, 190, 86 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW -CAPTION "Miranda MMAP Secured Database" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "EN",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_USERPASS,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL | WS_GROUP - DEFPUSHBUTTON "OK",IDOK,36,71,50,14 - PUSHBUTTON "Cancel",IDCANCEL,102,71,50,14 -END - -IDD_IMPORTTYPE DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Choose how you would like to import:",IDC_STATIC,5,16,210,8 - CONTROL "From a Miranda IM database.",IDC_MIRANDA,"Button",BS_AUTORADIOBUTTON,11,31,204,10 - CONTROL "From a Mirabilis ICQ (99a - 2003a) database.",IDC_MIRABILIS, - "Button",BS_AUTORADIOBUTTON,11,46,204,10 - CONTROL "Use the Find/Add contacts tool to populate my contact list.",IDC_USEFINDADD, - "Button",BS_AUTORADIOBUTTON,11,61,204,10 -END - -IDD_WIZARDINTRO DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "This wizard will help you import contacts and message history from Mirabilis ICQ, as well as letting you import from other Miranda IM profiles.",IDC_STATIC,33,12,182,32 - ICON IDI_IMPORT,IDC_STATIC,5,12,20,20 - LTEXT "Click ""Next"" to choose the information you wish to import, or click ""Cancel"" to exit the wizard and continue using Miranda.",IDC_STATIC,33,49,182,25 - CTEXT "It is recommended that you create a backup of your current Miranda profile before importing.",IDC_STATIC,30,81,182,21 -END - -IDD_FINISHED DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "If you wish to import more information, click ""Next"" to return to the start of the wizard, otherwise click ""Finish"" to start using Miranda.",IDC_STATIC,5,20,210,16 - LTEXT "You will probably never need to use this wizard again, so you can save memory by not loading it every time you start Miranda. This will mean that the import menu item will no longer be available.",IDC_STATIC,5,41,210,24 - CONTROL "Do not load the import plugin at startup again",IDC_DONTLOADPLUGIN, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,97,210,10 - LTEXT "Import completed",IDC_STATIC,5,7,210,8 - LTEXT "If at a future date you wish to use the wizard again, you can make it load again by going to the Plugins section of the Options dialog box.",IDC_STATIC,5,69,210,24 -END - -IDD_MIRABILISDB DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Miranda has found Mirabilis ICQ databases corresponding to the following ICQ numbers. Please select the one you wish to import, or click ""Other Database"" if your database is not listed.",IDC_STATIC,5,5,210,24 - LISTBOX IDC_LIST,5,31,210,36,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "&Other Database...",IDC_OTHER,149,69,66,14 - RTEXT "&Filename:",IDC_STATIC,5,88,34,8 - EDITTEXT IDC_FILENAME,42,86,173,12,ES_AUTOHSCROLL - CTEXT "Warning: Mirabilis ICQ running. Import may not be reliable.",IDC_MIRABILISRUNNING,5,101,210,8 - RTEXT "&Account:",IDC_STATIC,6,74,34,8 - COMBOBOX IDC_MIRABILISACCOUNT,42,71,102,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP -END - -IDD_MIRANDADB DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Miranda has found Miranda profiles with the following names. Please select the one you wish to import, or click ""Other Profile"" if your profile is not listed, or if the list is empty.",IDC_STATIC,5,10,210,24 - LISTBOX IDC_LIST,5,36,210,36,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "&Other Profile...",IDC_OTHER,149,74,66,14 - RTEXT "&Filename:",IDC_STATIC,5,93,34,8 - EDITTEXT IDC_FILENAME,41,91,174,12,ES_AUTOHSCROLL -END - -IDD_PROGRESS DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Now importing...",IDC_STATIC,5,11,62,8 - CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,5,24,210,10 - LISTBOX IDC_STATUS,5,38,210,61,NOT LBS_NOTIFY | LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL | LBS_NOSEL | WS_VSCROLL | WS_TABSTOP -END - -IDD_WIZARD DIALOGEX 0, 0, 220, 143 -STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_CAPTION | WS_SYSMENU -CAPTION "Import Information Wizard" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - DEFPUSHBUTTON "&Next >",IDOK,120,124,45,13 - PUSHBUTTON "Cancel",IDCANCEL,170,124,45,13 - PUSHBUTTON "< &Back",IDC_BACK,75,124,45,13 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,-7,115,234,1 -END - -IDD_OPTIONS DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - CONTROL "Import all contacts and all messages",IDC_RADIO_ALL, - "Button",BS_AUTORADIOBUTTON | BS_LEFT | BS_TOP | WS_TABSTOP,7,10,206,11 - CONTROL "Only import contacts",IDC_RADIO_CONTACTS,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,7,42,206,10 - CONTROL "Custom import",IDC_RADIO_CUSTOM,"Button",BS_AUTORADIOBUTTON | WS_DISABLED | WS_TABSTOP,7,74,206,10 - LTEXT "Select this if you want to import as much data as possible. This is the recommended option.",IDC_STATIC_ALL,26,20,187,16 - LTEXT "Select this if you want to import contacts but don't want to import any message history.",IDC_STATIC_CONTACTS,26,52,187,16 - LTEXT "Select this if you want to cutomize what to import.",IDC_STATIC_CUSTOM,26,84,187,16,WS_DISABLED -END - -IDD_ICQSERVER DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Miranda has now been configured to automatically download the contacts in your server-side contact list the next time you connect to ICQ.",IDC_STATIC,7,9,206,31 - LTEXT "If you want to change the way Miranda handles server-side contacts at a later time, you can do this in the ""ICQ Contacts"" page in the Miranda options.",IDC_STATIC,7,44,206,37 -END - -IDD_ADVOPTIONS DIALOGEX 0, 0, 220, 114 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | DS_CONTROL | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x0 -BEGIN - CONTROL "New contacts && groups",IDC_CONTACTS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,16,100,10 - CONTROL "System history",IDC_SYSTEM,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,120,16,98,10 - LTEXT "Select items to import:",IDC_ALL,10,3,201,10,SS_NOTIFY - CTEXT "Incoming",IDC_INCOMING,2,34,86,10,SS_NOTIFY - CTEXT "Outgoing",IDC_OUTGOING,132,34,86,10,SS_NOTIFY - CONTROL "",IDC_IN_MSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,44,10,10 - CONTROL "",IDC_IN_URL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,56,10,10 - CONTROL "",IDC_IN_FT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,68,10,10 - CONTROL "",IDC_IN_OTHER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,40,80,10,10 - CONTROL "",IDC_OUT_MSG,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,44,10,10 - CONTROL "",IDC_OUT_URL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,56,10,10 - CONTROL "",IDC_OUT_FT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,68,10,10 - CONTROL "",IDC_OUT_OTHER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,80,10,10 - CONTROL "Only since:",IDC_SINCE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,99,100,10 - CONTROL "",IDC_DATETIMEPICKER,"SysDateTimePick32",DTS_RIGHTALIGN | WS_DISABLED | WS_TABSTOP,120,97,81,15 - CTEXT "Messages",IDC_MSG,54,44,112,8,SS_NOTIFY - CTEXT "URLs",IDC_URL,54,56,112,8,SS_NOTIFY - CTEXT "File Transfers",IDC_FT,54,68,112,8,SS_NOTIFY - CTEXT "Other",IDC_OTHER,54,80,112,8,SS_NOTIFY - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,0,93,222,1 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDHORZ,0,31,223,1 -END - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_LOGIN, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 175 - TOPMARGIN, 7 - BOTTOMMARGIN, 78 - END - - IDD_IMPORTTYPE, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 215 - TOPMARGIN, 5 - BOTTOMMARGIN, 109 - END - - IDD_WIZARDINTRO, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 215 - TOPMARGIN, 5 - BOTTOMMARGIN, 109 - END - - IDD_FINISHED, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 215 - TOPMARGIN, 5 - BOTTOMMARGIN, 109 - END - - IDD_MIRABILISDB, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 215 - TOPMARGIN, 5 - BOTTOMMARGIN, 109 - END - - IDD_MIRANDADB, DIALOG - BEGIN - LEFTMARGIN, 3 - RIGHTMARGIN, 216 - TOPMARGIN, 1 - BOTTOMMARGIN, 113 - END - - IDD_PROGRESS, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 215 - TOPMARGIN, 5 - BOTTOMMARGIN, 109 - END - - IDD_WIZARD, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 215 - TOPMARGIN, 7 - BOTTOMMARGIN, 137 - END - - IDD_OPTIONS, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 213 - TOPMARGIN, 7 - BOTTOMMARGIN, 111 - END - - IDD_ICQSERVER, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 213 - TOPMARGIN, 7 - BOTTOMMARGIN, 107 - END - - IDD_ADVOPTIONS, DIALOG - BEGIN - VERTGUIDE, 10 - VERTGUIDE, 45 - VERTGUIDE, 110 - VERTGUIDE, 120 - VERTGUIDE, 175 - TOPMARGIN, 3 - HORZGUIDE, 16 - HORZGUIDE, 34 - HORZGUIDE, 104 - END -END -#endif // APSTUDIO_INVOKED - - -#endif // Ðóññêèé (Ðîññèÿ) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.cpp new file mode 100644 index 0000000000..62666c7531 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.cpp @@ -0,0 +1,73 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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. + +*/ + +// ============== +// == INCLUDES == +// ============== + +#include "import.h" + +#include "ICQserver.h" + +// ==================== +// ==================== +// == IMPLEMENTATION == +// ==================== +// ==================== + +BOOL CALLBACK ICQserverPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,0,0); + SendMessage(GetParent(hdlg),WIZM_ENABLEBUTTON,1,0); + SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,2,0); + TranslateDialogDefault(hdlg); + ICQserverImport(); + return TRUE; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDOK: + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_FINISHED,(LPARAM)FinishedPageProc); + break; + case IDCANCEL: + PostMessage(GetParent(hdlg),WM_CLOSE,0,0); + break; + } + break; + } + return FALSE; +} + +static void ICQserverImport() +{ + // Clear last update stamp + DBDeleteContactSetting(NULL, szICQModuleName[ iICQAccount ], "SrvLastUpdate"); + DBDeleteContactSetting(NULL, szICQModuleName[ iICQAccount ], "SrvRecordCount"); + + // Enable contacts downloading + DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "UseServerCList", 1); + DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "AddServerNew", 1); + DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "UseServerNicks", 1); + DBWriteContactSettingByte(NULL, szICQModuleName[ iICQAccount ], "ServerAddRemove", 1); +} diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.h b/plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.h new file mode 100644 index 0000000000..864890a978 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/ICQserver.h @@ -0,0 +1,62 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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. + +*/ + + + +#ifndef ICQSERVER_H +#define ICQSERVER_H + +#include + +// ====================== +// == GLOBAL FUNCTIONS == +// ====================== + +// ===================== +// == LOCAL FUNCTIONS == +// ===================== + +// Main function +static void ICQserverImport(); + +// GUI callbacks +INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); + + +// ====================== +// == GLOBAL VARIABLES == +// ====================== + +extern int cICQAccounts; +extern char ** szICQModuleName; +extern TCHAR ** tszICQAccountName; +extern int iICQAccount; + +// ===================== +// == LOCAL VARIABLES == +// ===================== + +// ============= +// == DEFINES == +// ============= + +#endif \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/encryption.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/encryption.cpp new file mode 100644 index 0000000000..ede73c006a --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/encryption.cpp @@ -0,0 +1,310 @@ +// (C) Artem Shpynov aka FYR and Igonin Vitaliy aka chaos.persei, 2007 - 2008 + +#include "import.h" + +typedef struct{ + void* (__stdcall *GenerateKey)(char* pwd); + void (__stdcall *FreeKey)(void* key); + void (__stdcall *EncryptMem)(BYTE* data, int size, void* key); + void (__stdcall *DecryptMem)(BYTE* data, int size, void* key); + + char* Name; + char* Info; + char* Author; + char* Site; + char* Email; + + DWORD Version; + + WORD uid; +} Cryptor; + +typedef struct{ + char dllname[255]; + HMODULE hLib; + Cryptor* cryptor; +} CryptoModule; + +BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + +char encryptKey[255]; +size_t encryptKeyLength; + +int wrongPass = 0; +void* key; + +Cryptor* CryptoEngine = NULL; + +int ModulesCount = 0; +CryptoModule* Modules[100]; + + +void zero_fill(BYTE * pBuf, size_t bufSize) +{ + size_t i; + for(i = 0; i < bufSize; i++) + pBuf[i] = 0; +} + +void InitSecurity() +{ + HMODULE hLib; + WIN32_FIND_DATAA fd; + HANDLE hFile; + + Cryptor* (__stdcall *GetCryptor)(); + + { + TCHAR szMirandaDir[MAX_PATH]; + TCHAR *str2; + + szMirandaDir[ 0 ] = 0; + + GetModuleFileName(NULL,szMirandaDir,SIZEOF(szMirandaDir)); + str2 = _tcsrchr(szMirandaDir,'\\'); + if ( str2 != NULL ) + *str2=0; + _tchdir(szMirandaDir); + } + + hFile = FindFirstFileA(".\\plugins\\cryptors\\*.dll", &fd); + + AddMessage(LPGEN("Scanning cryptors directory")); + + ModulesCount = 0; + while (hFile != INVALID_HANDLE_VALUE) + { + char tmp[MAX_PATH], buf[255]; + strcpy(tmp, ".\\plugins\\cryptors\\"); + strcat(tmp, fd.cFileName); + + hLib = LoadLibraryA(tmp); + if(hLib){ + GetCryptor = (Cryptor* (__stdcall *)()) GetProcAddress(hLib, "GetCryptor"); + if(GetCryptor){ + //TCHAR Name[100], Version[100], DllName[100]; + + + Modules[ModulesCount] = (CryptoModule*) malloc(sizeof(CryptoModule)); + Modules[ModulesCount]->cryptor = GetCryptor(); + strcpy(Modules[ModulesCount]->dllname, fd.cFileName); + Modules[ModulesCount]->hLib = hLib; + + _snprintf(buf,SIZEOF(buf),"%d.%d.%d.%d", HIBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(HIWORD(Modules[ModulesCount]->cryptor->Version)), HIBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version)), LOBYTE(LOWORD(Modules[ModulesCount]->cryptor->Version))); + // Unsane: none +/* + + mbstowcs(Name, Modules[ModulesCount]->cryptor->Name, 100); + mbstowcs(Version, buf, 100); + mbstowcs(DllName, Modules[ModulesCount]->dllname, 100); + +*/ + AddMessage(LPGEN("Cryptor loaded: %s [%s] (%s)"), Modules[ModulesCount]->cryptor->Name, buf, Modules[ModulesCount]->dllname); + + ModulesCount++; + }else{ + FreeLibrary(hLib); + } + } + if(ModulesCount >= 100) break; + if (!FindNextFileA(hFile, &fd)) break; + } + + AddMessage(LPGEN("%d crypto modules loaded"), ModulesCount); +} + +void UnloadSecurity() +{ + int i; + + if(CryptoEngine) CryptoEngine->FreeKey(key); + + for(i = 0; i < ModulesCount; i++) + { + FreeLibrary(Modules[i]->hLib); + free(Modules[i]); + } +} + +void EncoderInit() +{ + encryptKey[encryptKeyLength] = 0; + key = CryptoEngine->GenerateKey(encryptKey); +} + +void EncodeCopyMemory(BYTE * dst, void * src, size_t size ) +{ + memcpy(dst, src, size); + CryptoEngine->EncryptMem(dst, (int)size, key); +} + +void DecodeCopyMemory(BYTE * dst, void * src, size_t size ) +{ + memcpy(dst, src, size); + CryptoEngine->DecryptMem(dst, (int)size, key); +} + + +void EncodeMemory(BYTE * mem, size_t size) +{ + CryptoEngine->EncryptMem(mem, (int)size, key); +} + +void DecodeMemory(BYTE * mem, size_t size) +{ + CryptoEngine->DecryptMem(mem, (int)size, key); +} + +int bCheckingPass = 0; + +int CheckPassword(WORD checkWord, WORD cryptorUID, TCHAR * szDBName) +{ + WORD ver; + int res; + + if(bCheckingPass) return 0; + bCheckingPass = 1; + + { + int i; + int Found = 0; + for(i = 0; i < ModulesCount; i++) { + if(cryptorUID == Modules[i]->cryptor->uid){ + CryptoEngine = Modules[i]->cryptor; + Found = 1; + break; + } + } + if (!Found){ + AddMessage(LPGEN("Sorry, but your database encrypted with unknown module"), MB_OK); + bCheckingPass = 0; + return 0; + } + } + + { + //wchar_t Name[100], Author[100]; + + // Unsane: none + AddMessage(LPGEN("Database encrypted with %s by %s"), CryptoEngine->Name, CryptoEngine->Author); + } + + while(1){ + res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_LOGIN), NULL, (DLGPROC)DlgStdInProc, (LPARAM)szDBName); + if(res == IDCANCEL) + { + wrongPass = 0; + bCheckingPass = 0; + return 0; + } + if(encryptKeyLength < 1) continue; + EncoderInit(); + DecodeCopyMemory((BYTE*)&ver, &checkWord, sizeof(checkWord)); + if(ver == 0x5195) + { + wrongPass = 0; + bCheckingPass = 0; + return 1; + } + wrongPass++; + } + + bCheckingPass = 0; +} + + +UINT oldLangID = 0; +void LanguageChanged(HWND hDlg) +{ + UINT LangID = (UINT)GetKeyboardLayout(0); + char Lang[3] = {0}; + if (LangID != oldLangID) + { + oldLangID = LangID; + GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); + SetDlgItemTextA(hDlg, IDC_LANG, Lang); + } +} + +BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) +{ + HICON hIcon = 0; + TCHAR tszHeaderTxt[256]; + switch(uMsg) + { + case WM_INITDIALOG: + { + HWND hwndCtrl; + TranslateDialogDefault(hDlg); + + hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PASS)); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); + + if (!wrongPass) + { + mir_sntprintf(tszHeaderTxt, SIZEOF(tszHeaderTxt), _T("%s\n%s"), TranslateT("Please type in your password for"), lParam); + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), tszHeaderTxt); + } + else + { + if (wrongPass > 2) + { + hwndCtrl = GetDlgItem(hDlg, IDC_USERPASS); + EnableWindow(hwndCtrl, FALSE); + hwndCtrl = GetDlgItem(hDlg, IDOK); + EnableWindow(hwndCtrl, FALSE); + + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Too many errors!")); + } + else + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is not correct!")); + } + oldLangID = 0; + SetTimer(hDlg,1,200,NULL); + LanguageChanged(hDlg); + return TRUE; + } + + case WM_CTLCOLORSTATIC: + { + if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) + { + SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetBkMode((HDC)wParam, TRANSPARENT); + return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); + } + + return FALSE; + } + + case WM_COMMAND: + { + UINT uid = LOWORD(wParam); + + if(uid == IDOK){ + if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) + { + encryptKeyLength = GetDlgItemTextA(hDlg, IDC_USERPASS, encryptKey, 254); + EndDialog(hDlg,IDOK); + }else{ + + } + }else if(uid == IDCANCEL){ + EndDialog(hDlg,IDCANCEL); + } + } + case WM_TIMER: + { + LanguageChanged(hDlg); + return FALSE; + } + case WM_DESTROY: + { + KillTimer(hDlg, 1); + DestroyIcon(hIcon); + return FALSE; + } + } + + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/import.h b/plugins/Dbx_mmap_SA/Import_SA/src/import.h new file mode 100644 index 0000000000..0bba4a0d91 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/import.h @@ -0,0 +1,115 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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 _LOGGING 1 + +#define _CRT_SECURE_NO_WARNINGS +#define _CRT_NONSTDC_NO_DEPRECATE + +#define MIRANDA_VER 0x0A00 + +#define WINVER 0x0501 +#define _WIN32_WINNT 0x0501 +#define _WIN32_IE 0x0501 + +#include + +#include +#include // datetimepicker + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Unsane: none +#include "resource.h" + +// ** Global constants + +#define IMPORT_MODULE "MIMImport" // Module name +#define IMPORT_SERVICE "MIMImport/Import" // Service for menu item + +// Keys +#define IMP_KEY_FR "FirstRun" // First run + + +#define WIZM_GOTOPAGE (WM_USER+10) //wParam=resource id, lParam=dlgproc +#define WIZM_DISABLEBUTTON (WM_USER+11) //wParam=0:back, 1:next, 2:cancel +#define WIZM_SETCANCELTEXT (WM_USER+12) //lParam=(char*)newText +#define WIZM_ENABLEBUTTON (WM_USER+13) //wParam=0:back, 1:next, 2:cancel + +#define PROGM_SETPROGRESS (WM_USER+10) //wParam=0..100 +#define PROGM_ADDMESSAGE (WM_USER+11) //lParam=(char*)szText +#define SetProgress(n) SendMessage(hdlgProgress,PROGM_SETPROGRESS,n,0) + +#define ICQOSCPROTONAME "ICQ" +#define MSNPROTONAME "MSN" +#define YAHOOPROTONAME "YAHOO" +#define NSPPROTONAME "NET_SEND" +#define ICQCORPPROTONAME "ICQ Corp" +#define AIMPROTONAME "AIM" + +// Import type +#define IMPORT_CONTACTS 0 +#define IMPORT_ALL 1 +#define IMPORT_CUSTOM 2 + +// Custom import options +#define IOPT_ADDUNKNOWN 1 +#define IOPT_MSGSENT 2 +#define IOPT_MSGRECV 4 +#define IOPT_URLSENT 8 +#define IOPT_URLRECV 16 +#define IOPT_AUTHREQ 32 +#define IOPT_ADDED 64 +#define IOPT_FILESENT 128 +#define IOPT_FILERECV 256 +#define IOPT_OTHERSENT 512 +#define IOPT_OTHERRECV 1024 +#define IOPT_SYSTEM 2048 +#define IOPT_CONTACTS 4096 +#define IOPT_GROUPS 8192 + +extern HINSTANCE hInst; + +void AddMessage( const char* fmt, ... ); +void DecodeMemory(BYTE * mem, size_t size); +void DecodeCopyMemory(BYTE * dst, void * src, size_t size ); + +int CreateGroup(BYTE type, const char* name, HANDLE hContact); + +extern HWND hdlgProgress; + +extern DWORD nDupes, nContactsCount, nMessagesCount, nGroupsCount, nSkippedEvents, nSkippedContacts; diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/main.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/main.cpp new file mode 100644 index 0000000000..d464f8bb55 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/main.cpp @@ -0,0 +1,541 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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 "import.h" +#include "version.h" + +void FreeVariant( DBVARIANT* dbv ); +void WriteVariant( HANDLE hContact, const char* module, const char* var, DBVARIANT* dbv ); + +BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei); + +int nImportOption; +int nCustomOptions; +int hLangpack; + +int cICQAccounts = 0; +char ** szICQModuleName = NULL; +TCHAR ** tszICQAccountName = NULL; +int iICQAccount = 0; + +static HANDLE hHookModulesLoaded = NULL; +static HANDLE hHookOnExit = NULL; +static HANDLE hImportService = NULL; + +INT_PTR CALLBACK WizardDlgProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); + +HINSTANCE hInst; + +static HWND hwndWizard = NULL; + +PLUGININFOEX pluginInfo = { + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + __VERSION_DWORD, + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, //{2D77A746-00A6-4343-BFC5-F808CDD772EA} + {0x2d77a746, 0xa6, 0x4343, { 0xbf, 0xc5, 0xf8, 0x8, 0xcd, 0xd7, 0x72, 0xea }} +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst = hinstDLL; + return TRUE; +} + +static INT_PTR ImportCommand(WPARAM wParam,LPARAM lParam) +{ + if (IsWindow(hwndWizard)) { + SetForegroundWindow(hwndWizard); + SetFocus(hwndWizard); + } + else hwndWizard = CreateDialog(hInst, MAKEINTRESOURCE(IDD_WIZARD), NULL, WizardDlgProc); + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MirandaPluginInfoEx - returns an information about a plugin + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// MirandaInterfaces - returns the protocol interface to the core + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_IMPORT, MIID_LAST}; + +///////////////////////////////////////////////////////////////////////////////////////// +// Performs a primary set of actions upon plugin loading + +static int ModulesLoaded(WPARAM wParam, LPARAM lParam) +{ + int nProtocols = 0; + int n; + PROTOCOLDESCRIPTOR **ppProtos = NULL; + + if (DBGetContactSettingByte(NULL, IMPORT_MODULE, IMP_KEY_FR, 1)) + return 0; + + // Only autorun import wizard if at least one protocol is installed + CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&nProtocols, (LPARAM)&ppProtos); + for (n=0; n < nProtocols; n++) { + if (ppProtos[n]->type == PROTOTYPE_PROTOCOL) { + CallService(IMPORT_SERVICE, 0, 0); + DBWriteContactSettingByte(NULL, IMPORT_MODULE, IMP_KEY_FR, 1); + break; + } } + return 0; +} + +static int OnExit(WPARAM wParam, LPARAM lParam) +{ + if ( hwndWizard ) + SendMessage(hwndWizard, WM_CLOSE, 0, 0); + return 0; +} + +extern "C" __declspec(dllexport) int Load(void) +{ + + mir_getLP( &pluginInfo ); + + hImportService = CreateServiceFunction(IMPORT_SERVICE, ImportCommand); + { + CLISTMENUITEM mi; + ZeroMemory(&mi, sizeof(mi)); + mi.cbSize = sizeof(mi); + mi.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_IMPORT)); + mi.pszName = LPGEN("&Import..."); + mi.position = 500050000; + mi.pszService = IMPORT_SERVICE; + Menu_AddMainMenuItem(&mi); + } + hHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded); + hHookOnExit = HookEvent(ME_SYSTEM_OKTOEXIT, OnExit); + { + INITCOMMONCONTROLSEX icex; + icex.dwSize = sizeof(icex); + icex.dwICC = ICC_DATE_CLASSES; + InitCommonControlsEx(&icex); + } + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// +// Unload a plugin + +extern "C" __declspec(dllexport) int Unload(void) +{ + if (hHookModulesLoaded) + UnhookEvent(hHookModulesLoaded); + if (hHookOnExit) + UnhookEvent(hHookOnExit); + if (hImportService) + DestroyServiceFunction(hImportService); + + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +BOOL IsProtocolLoaded(char* pszProtocolName) +{ + return CallService(MS_PROTO_ISPROTOCOLLOADED, 0, (LPARAM)pszProtocolName) ? TRUE : FALSE; +} + +BOOL EnumICQAccounts() +{ + int count, i = 0; + PROTOACCOUNT ** accs; + + while (cICQAccounts) + { + cICQAccounts--; + free(szICQModuleName[cICQAccounts]); + free(tszICQAccountName[cICQAccounts]); + } + + ProtoEnumAccounts(&count, &accs); + szICQModuleName = (char**)realloc(szICQModuleName, count * sizeof(char**)); + tszICQAccountName = (TCHAR**)realloc(tszICQAccountName, count * sizeof(TCHAR**)); + while (i < count) + { + if ((0 == strcmp(ICQOSCPROTONAME, accs[i]->szProtoName)) && accs[i]->bIsEnabled) + { + szICQModuleName[cICQAccounts] = strdup(accs[i]->szModuleName); + tszICQAccountName[cICQAccounts] = _tcsdup(accs[i]->tszAccountName); + cICQAccounts++; + } + i++; + } + return cICQAccounts != 0; +} + +void FreeICQAccountsList() +{ + while (cICQAccounts) + { + cICQAccounts--; + free(szICQModuleName[cICQAccounts]); + free(tszICQAccountName[cICQAccounts]); + } + + if (szICQModuleName) + free(szICQModuleName); + if (tszICQAccountName) + free(tszICQAccountName); + + szICQModuleName = NULL; + tszICQAccountName = NULL; +} + +HANDLE HContactFromNumericID(char* pszProtoName, char* pszSetting, DWORD dwID) +{ + char* szProto; + HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + while (hContact != NULL) + { + if (DBGetContactSettingDword(hContact, pszProtoName, pszSetting, 0) == dwID) + { + szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if (szProto != NULL && !strcmp(szProto, pszProtoName)) + return hContact; + } + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); + } + return INVALID_HANDLE_VALUE; +} + +HANDLE HContactFromID(char* pszProtoName, char* pszSetting, char* pszID) +{ + DBVARIANT dbv; + HANDLE hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + while (hContact != NULL) { + char* szProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)hContact, 0); + if ( !lstrcmpA(szProto, pszProtoName)) { + if (DBGetContactSettingString(hContact, pszProtoName, pszSetting, &dbv) == 0) { + if (strcmp(pszID, dbv.pszVal) == 0) { + DBFreeVariant(&dbv); + return hContact; + } + DBFreeVariant(&dbv); + } + } + + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0); + } + return INVALID_HANDLE_VALUE; +} + +HANDLE HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DWORD uin, int addUnknown) +{ + HANDLE hContact = HContactFromNumericID(szModuleName, "UIN", uin); + if (hContact == NULL) { + AddMessage( LPGEN("Ignored event from/to self")); + return INVALID_HANDLE_VALUE; + } + + if (hContact != INVALID_HANDLE_VALUE) + return hContact; + + if (!addUnknown) + return INVALID_HANDLE_VALUE; + + 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 ); + return hContact; +} + +HANDLE AddContact(HWND hdlgProgress, char* pszProtoName, char* pszUniqueSetting, + DBVARIANT* id, DBVARIANT* nick, DBVARIANT* 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); + if ( CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)pszProtoName) != 0) { + CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); + AddMessage( LPGEN("Failed to add %s contact %s"), pszProtoName, pszUserID ); + FreeVariant( id ); + FreeVariant( nick ); + FreeVariant( group ); + return INVALID_HANDLE_VALUE; + } + + WriteVariant( hContact, pszProtoName, pszUniqueSetting, id ); + + if ( group->type ) + CreateGroup( group->type, group->pszVal, hContact ); + + if ( nick->type && nick->pszVal[0] ) { + WriteVariant( hContact, "CList", "MyHandle", nick ); + if (nick->type == DBVT_UTF8) { + char *tmp = mir_utf8decodeA(nick->pszVal); + AddMessage( LPGEN("Added %s contact %s, '%s'"), pszProtoName, pszUserID, tmp ); + mir_free(tmp); + } + else AddMessage( LPGEN("Added %s contact %s, '%s'"), pszProtoName, pszUserID, nick->pszVal ); + } + else AddMessage( LPGEN("Added %s contact %s"), pszProtoName, pszUserID ); + + FreeVariant( id ); + FreeVariant( nick ); + FreeVariant( group ); + return hContact; +} + +// ------------------------------------------------ +// Creates a group with a specified name in the +// Miranda contact list. +// If contact is specified adds it to group +// ------------------------------------------------ +// Returns 1 if successful and 0 when it fails. +int CreateGroup(BYTE type, const char* name, HANDLE hContact) +{ + int groupId; + TCHAR *tmp, *tszGrpName; + char groupIdStr[11]; + size_t cbName; + + if (type == DBVT_UTF8) + tmp = mir_utf8decodeT( name ); + else if (type == DBVT_WCHAR) + tmp = mir_u2t(( wchar_t* )name ); + else + tmp = mir_a2t( name ); + + if ( tmp == NULL ) + return 0; + + cbName = _tcslen(tmp); + tszGrpName = (TCHAR *)_alloca(( cbName+2 )*sizeof( TCHAR )); + tszGrpName[0] = 1 | GROUPF_EXPANDED; + _tcscpy( tszGrpName+1, tmp ); + mir_free( tmp ); + + // Check for duplicate & find unused id + for (groupId = 0; ; groupId++) { + DBVARIANT dbv; + itoa(groupId, groupIdStr,10); + if (DBGetContactSettingTString(NULL, "CListGroups", groupIdStr, &dbv)) + break; + + 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); + } + + DBFreeVariant(&dbv); + return 0; + } + + DBFreeVariant(&dbv); + } + + DBWriteContactSettingTString( NULL, "CListGroups", groupIdStr, tszGrpName ); + + if (hContact) + DBWriteContactSettingTString( hContact, "CList", "Group", tszGrpName+1 ); + + return 1; +} + +// Returns TRUE if the event already exist in the database +BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei) +{ + static DWORD dwPreviousTimeStamp = -1; + static HANDLE hPreviousContact = INVALID_HANDLE_VALUE; + static HANDLE hPreviousDbEvent = NULL; + + HANDLE hExistingDbEvent; + DWORD dwEventTimeStamp; + DBEVENTINFO dbeiExisting; + + // get last event + if (!(hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDLAST, (WPARAM)hContact, 0))) + return FALSE; + + ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); + dbeiExisting.cbSize = sizeof(dbeiExisting); + CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); + dwEventTimeStamp = dbeiExisting.timestamp; + + // compare with last timestamp + if (dbei.timestamp > dwEventTimeStamp) + { + // remember event + hPreviousDbEvent = hExistingDbEvent; + dwPreviousTimeStamp = dwEventTimeStamp; + return FALSE; + } + + if (hContact != hPreviousContact) + { + hPreviousContact = hContact; + // remember event + hPreviousDbEvent = hExistingDbEvent; + dwPreviousTimeStamp = dwEventTimeStamp; + + // get first event + if (!(hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDFIRST, (WPARAM)hContact, 0))) + return FALSE; + + ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); + dbeiExisting.cbSize = sizeof(dbeiExisting); + CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); + dwEventTimeStamp = dbeiExisting.timestamp; + + // compare with first timestamp + if (dbei.timestamp <= dwEventTimeStamp) + { + // remember event + dwPreviousTimeStamp = dwEventTimeStamp; + hPreviousDbEvent = hExistingDbEvent; + + if ( dbei.timestamp != dwEventTimeStamp ) + return FALSE; + } + + } + // check for equal timestamps + if (dbei.timestamp == dwPreviousTimeStamp) + { + ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); + dbeiExisting.cbSize = sizeof(dbeiExisting); + CallService(MS_DB_EVENT_GET, (WPARAM)hPreviousDbEvent, (LPARAM)&dbeiExisting); + + if ((dbei.timestamp == dbeiExisting.timestamp) && + (dbei.eventType == dbeiExisting.eventType) && + (dbei.cbBlob == dbeiExisting.cbBlob) && + ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) + return TRUE; + + // find event with another timestamp + hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hPreviousDbEvent, 0); + while (hExistingDbEvent != NULL) + { + ZeroMemory(&dbeiExisting, sizeof(dbeiExisting)); + dbeiExisting.cbSize = sizeof(dbeiExisting); + CallService(MS_DB_EVENT_GET, (WPARAM)hExistingDbEvent, (LPARAM)&dbeiExisting); + + if (dbeiExisting.timestamp != dwPreviousTimeStamp) + { + // use found event + hPreviousDbEvent = hExistingDbEvent; + dwPreviousTimeStamp = dbeiExisting.timestamp; + break; + } + + hPreviousDbEvent = hExistingDbEvent; + hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hExistingDbEvent, 0); + } + } + + hExistingDbEvent = hPreviousDbEvent; + + if (dbei.timestamp <= dwPreviousTimeStamp) + { + // look back + 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 + hPreviousDbEvent = hExistingDbEvent; + dwPreviousTimeStamp = dbeiExisting.timestamp; + return FALSE; + } + + // Compare event with import candidate + if ((dbei.timestamp == dbeiExisting.timestamp) && + (dbei.eventType == dbeiExisting.eventType) && + (dbei.cbBlob == dbeiExisting.cbBlob) && + ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) + { + // remember event + hPreviousDbEvent = hExistingDbEvent; + dwPreviousTimeStamp = dbeiExisting.timestamp; + return TRUE; + } + + // Get previous event in chain + hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDPREV, (WPARAM)hExistingDbEvent, 0); + } + + } + else + { + // look forward + 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 + hPreviousDbEvent = hExistingDbEvent; + dwPreviousTimeStamp = dbeiExisting.timestamp; + return FALSE; + } + + // Compare event with import candidate + if ((dbei.timestamp == dbeiExisting.timestamp) && + (dbei.eventType == dbeiExisting.eventType) && + (dbei.cbBlob == dbeiExisting.cbBlob) && + ((dbei.flags&DBEF_SENT) == (dbeiExisting.flags&DBEF_SENT))) + { + // remember event + hPreviousDbEvent = hExistingDbEvent; + dwPreviousTimeStamp = dbeiExisting.timestamp; + return TRUE; + } + + // Get next event in chain + hExistingDbEvent = (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hExistingDbEvent, 0); + } + + } + // reset last event + hPreviousContact = INVALID_HANDLE_VALUE; + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.cpp new file mode 100644 index 0000000000..15b58f4e0a --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.cpp @@ -0,0 +1,1492 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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. + +*/ + +// ============== +// == INCLUDES == +// ============== + +#include "import.h" +#include "mirabilis.h" + +BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei); +BOOL IsProtocolLoaded(char* pszProtocolName); +HANDLE HContactFromNumericID(char* pszProtoName, char* pszSetting, DWORD dwID); +HANDLE AddContact(HWND hdlgProgress, char* pszProtoName, char* pszUniqueSetting, DBVARIANT* id, DBVARIANT* nick, DBVARIANT* group); + +// ==================== +// ==================== +// == IMPLEMENTATION == +// ==================== +// ==================== + +static void SearchForDatabases(HWND hdlg, const TCHAR *dbPath, const TCHAR *type) +{ + HANDLE hFind; + WIN32_FIND_DATA fd; + TCHAR szSearchPath[MAX_PATH]; + TCHAR szRootName[MAX_PATH],*str2; + + int i; + + wsprintf(szSearchPath, _T("%s\\*.idx"), dbPath); + hFind=FindFirstFile(szSearchPath,&fd); + if(hFind!=INVALID_HANDLE_VALUE) { + do { + lstrcpy(szRootName,fd.cFileName); + str2=_tcsrchr(szRootName,'.'); + if(str2!=NULL) *str2=0; + if(lstrlen(szRootName)>3 && !lstrcmpi(szRootName+lstrlen(szRootName)-3,_T("tmp"))) + continue; + lstrcat(szRootName,type); + i=SendDlgItemMessage(hdlg,IDC_LIST,LB_ADDSTRING,0,(LPARAM)szRootName); + str2 = (TCHAR*)mir_alloc((lstrlen(dbPath) + 2+lstrlen(fd.cFileName))*sizeof(TCHAR)); + wsprintf(str2, _T("%s\\%s"), dbPath, fd.cFileName); + SendDlgItemMessage(hdlg,IDC_LIST,LB_SETITEMDATA,i,(LPARAM)str2); + } + while( FindNextFile( hFind, &fd )); + + FindClose(hFind); + } +} + +INT_PTR CALLBACK MirabilisPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + { + HKEY hKey; + LONG lResult; + int i; + TranslateDialogDefault(hdlg); + if (ERROR_SUCCESS != (lResult = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Mirabilis\\ICQ\\DefaultPrefs"), 0, KEY_QUERY_VALUE, &hKey))) + lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Mirabilis\\ICQ\\DefaultPrefs"), 0, KEY_QUERY_VALUE, &hKey); + + if (lResult == ERROR_SUCCESS) { + TCHAR dbPath[MAX_PATH]; + DWORD cch; + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("New Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (99a)")); + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("99b Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (99b)")); + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2000a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (2000a)")); + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2000b Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (2000b)")); + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2001a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (2001a)")); + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2001b Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (2001b)")); + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2002a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (2002a)")); + cch=sizeof(dbPath); + if(ERROR_SUCCESS==RegQueryValueEx(hKey,_T("2003a Database"),NULL,NULL,(LPBYTE)dbPath,&cch)) + SearchForDatabases(hdlg,dbPath,_T(" (2003a)")); + } + + for (i = 0; i < cICQAccounts; i++) + { + SendDlgItemMessage(hdlg, IDC_MIRABILISACCOUNT, CB_ADDSTRING, 0, (LPARAM)tszICQAccountName[i]); + } + SendDlgItemMessage(hdlg, IDC_MIRABILISACCOUNT, CB_SETCURSEL, 0, 0); + + SetTimer(hdlg,1,2000,NULL); + SendMessage(hdlg,WM_TIMER,0,0); + return TRUE; + } + case WM_TIMER: + { HANDLE hMirabilisMutex; + hMirabilisMutex=OpenMutexA(MUTEX_ALL_ACCESS,FALSE,"Mirabilis ICQ Mutex"); + if(hMirabilisMutex!=NULL) { + CloseHandle(hMirabilisMutex); + ShowWindow(GetDlgItem(hdlg,IDC_MIRABILISRUNNING),SW_SHOW); + } + else ShowWindow(GetDlgItem(hdlg,IDC_MIRABILISRUNNING),SW_HIDE); + } + break; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_IMPORTTYPE,(LPARAM)ImportTypePageProc); + break; + case IDOK: + { TCHAR filename[MAX_PATH]; + GetDlgItemText(hdlg,IDC_FILENAME,filename,SIZEOF(filename)); + if(_taccess(filename,4)) { + MessageBox(hdlg,TranslateT("The given file does not exist. Please check that you have entered the name correctly."),TranslateT("Mirabilis Import"),MB_OK); + break; + } + lstrcpy(importFile,filename); + iICQAccount = SendDlgItemMessage(hdlg, IDC_MIRABILISACCOUNT, CB_GETCURSEL, 0, 0); + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_OPTIONS,(LPARAM)MirabilisOptionsPageProc); + break; + } + case IDCANCEL: + PostMessage(GetParent(hdlg),WM_CLOSE,0,0); + break; + case IDC_LIST: + if(HIWORD(wParam)==LBN_SELCHANGE) { + int sel=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCURSEL,0,0); + if(sel==LB_ERR) break; + SetDlgItemText(hdlg,IDC_FILENAME,(TCHAR*)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETITEMDATA,sel,0)); + } + break; + case IDC_OTHER: + { OPENFILENAME ofn; + TCHAR str[MAX_PATH], text[256]; + int index; + + // TranslateTS doesnt translate \0 separated strings + index = mir_sntprintf(text, 64, _T("%s (*.idx)"), TranslateT("Mirabilis ICQ database indexes")) + 1; + _tcscpy(text + index, _T("*.idx")); index += 6; + index += mir_sntprintf(text + index, 64, _T("%s (*.*)"), TranslateT("All Files")) + 1; + _tcscpy(text + index, _T("*.*")); index += 4; + text[index] = 0; + + GetDlgItemText(hdlg,IDC_FILENAME,str,SIZEOF(str)); + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = hdlg; + ofn.lpstrFilter = text; + ofn.lpstrFile = str; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT; + ofn.nMaxFile = SIZEOF(str); + ofn.lpstrDefExt = _T("idx"); + if(GetOpenFileName(&ofn)) + SetDlgItemText(hdlg,IDC_FILENAME,str); + break; + } + } + break; + + case WM_DESTROY: + { int i; + for(i=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCOUNT,0,0)-1;i>=0;i--) + mir_free((char*)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETITEMDATA,i,0)); + break; + } + } + return FALSE; +} + + +INT_PTR CALLBACK MirabilisOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + EnableWindow(GetDlgItem(hdlg, IDC_RADIO_ALL), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_STATIC_ALL), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_RADIO_CONTACTS), TRUE); + EnableWindow(GetDlgItem(hdlg, IDC_STATIC_CONTACTS), TRUE); + CheckDlgButton(hdlg, IDC_RADIO_ALL, BST_CHECKED); + return TRUE; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRABILISDB, (LPARAM)MirabilisPageProc); + break; + case IDOK: + if (IsDlgButtonChecked(hdlg, IDC_RADIO_ALL)) { + DoImport = MirabilisImport; + nImportOption = IMPORT_ALL; + nCustomOptions = IOPT_MSGSENT|IOPT_MSGRECV|IOPT_URLSENT|IOPT_URLRECV; + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc); + break; + } + if (IsDlgButtonChecked(hdlg, IDC_RADIO_CONTACTS)) { + DoImport = MirabilisImport; + nImportOption = IMPORT_CONTACTS; + nCustomOptions = 0; + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)ProgressPageProc); + break; + } + break; + case IDCANCEL: + PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); + break; + } + break; + } + + return FALSE; +} + +static int GetHighestIndexEntry(void) +{ + struct TIdxIndexEntry *entry; + DWORD ofs; + + ofs=*(PDWORD)(pIdx+12); + for (;;) { + entry=(struct TIdxIndexEntry*)(pIdx+ofs); + if(entry->entryIdLow==(DWORD)-2) return ((struct TIdxDatEntry*)entry)->entryId; + if(entry->ofsHigher>=0xF0000000) ofs=entry->ofsInHere; + else ofs=entry->ofsHigher; + } +} + +static int GetIdDatOfs(DWORD id) +{ + struct TIdxIndexEntry *entry; + DWORD ofs = *(PDWORD)(pIdx+12); + for (;;) { + entry=(struct TIdxIndexEntry*)(pIdx+ofs); + if(entry->entryIdLow==(DWORD)-2) { + if(entry->entryIdHigh==id) return ((struct TIdxDatEntry*)entry)->datOfs; + return 0; + } + if(identryIdLow) ofs=entry->ofsLower; + else if(entry->ofsHigher<0xF0000000 && id>=entry->entryIdHigh) ofs=entry->ofsHigher; + else ofs=entry->ofsInHere; + } + return 0; +} + +static int GetDatEntryType(DWORD ofs) +{ + return *(int*)(pDat+ofs+4); +} + +DWORD GetDBVersion() +{ + dwDBVersion = *(PDWORD)(pIdx+16); + + switch (dwDBVersion) { + case DBV99A: + AddMessage( LPGEN("This looks like a ICQ 99a database.")); + break; + case DBV99B: + AddMessage( LPGEN("This looks like a ICQ 99b database.")); + break; + case DBV2000A: + AddMessage( LPGEN("This looks like a ICQ 2000a database.")); + break; + case DBV2000B: + AddMessage( LPGEN("This looks like a ICQ 2000b database.")); + break; + case DBV2001A: + AddMessage( LPGEN("This looks like a ICQ 2001, 2002 or 2003a database.")); + break; + default: + AddMessage( LPGEN("This database is an unknown version.")); + return 0; + } + + return dwDBVersion; +} + +int GetEntryVersion(WORD wSeparatorValue) +{ + int nVersion; + + if (wSeparatorValue < ENTRYV99A) + nVersion = 0; // Cannot handle ICQ98 contacts + else if ((wSeparatorValue >= ENTRYV99A) && (wSeparatorValue < ENTRYV99B)) + nVersion = ENTRYV99A; + else if ((wSeparatorValue >= ENTRYV99B) && (wSeparatorValue < ENTRYV2000A)) + nVersion = ENTRYV99B; + else if ((wSeparatorValue >= ENTRYV2000A) && (wSeparatorValue < ENTRYV2000B)) + nVersion = ENTRYV2000A; + else if ((wSeparatorValue >= ENTRYV2000B) && (wSeparatorValue < ENTRYV2001A)) + nVersion = ENTRYV2000B; + else if ((wSeparatorValue >= ENTRYV2001A) && (wSeparatorValue < ENTRYV2001B)) + nVersion = ENTRYV2001A; + else if ((wSeparatorValue >= ENTRYV2001B) && (wSeparatorValue < ENTRYV2002A)) + nVersion = ENTRYV2001B; + else if (wSeparatorValue >= ENTRYV2002A) + nVersion = ENTRYV2002A; + else + nVersion = ENTRYVUNKNOWN; // Just in case... Skip undocumented contact versions + + return nVersion; +} + +DWORD ReadSubList(DWORD dwOffset) +{ + DWORD dwSubType, dwProperties, n; + + #ifdef _LOGGING + AddMessage( LPGEN("Attempting to parse sub list at offset %u."), dwOffset); + #endif + + // Check number of properties in sub list + dwProperties = *(PDWORD)(pDat+dwOffset); + dwOffset+=4; + + // Check sub list type + dwSubType = *(PBYTE)(pDat+dwOffset); + dwOffset+=1; + + switch (dwSubType){ + case 0x6B: + for(n=0;n 1) + return 6 + (char*)(pDat + dwOffset); + + break; + } + else + // Skip to next group + dwOffset += *(PWORD)(pDat + dwOffset + 4) + 12; + } + break; + + case DBV2000A: + case DBV2000B: + case DBV2001A: + for (n = 0; n < dwGroups; n++) { + if (tmpOfs = ReadPropertyBlock(dwOffset, "GroupID", &nSearchResult)) { + if (nSearchResult) { + if (dwGroupID == *(PDWORD)(pDat + tmpOfs + 1)) { + strGroupName = 3 + (char*)(pDat + ReadPropertyBlock(dwOffset, "GroupName", &nSearchResult)); + if (nSearchResult) { + if ((DWORD)*(strGroupName - 2) > 1) + return strGroupName; + break; + } } } } + + // Skip to next group + if ( dwOffset != ReadPropertyBlock(dwOffset, NULL, NULL)) + break; + } + break; + } + + // The GroupID was not found, or it was found + // but the group did not have a name, or there + // was an error during parsing. + return 0; +} + +// ------------------------------------------------ +// Scans a group list and adds all found groups to +// the Miranda contact list +// ------------------------------------------------ +// dwOffset must point to the number of entries in +// the following group list. +// Returns the number of added groups, or -1 if an error +// occurred + +int ImportGroups() +{ + DWORD dwGroups, n, tmpOfs, dwOffset; + int nImported = 0; + int nSearchResult, nFormat; + WORD wSeparatorValue; + + if (!(dwOffset = FindMyDetails())) { + AddMessage( LPGEN("ERROR: Failed to find owner information.")); + return -1; + } + + wSeparatorValue = *(PWORD)(pDat + dwOffset + 0x1c); + nFormat = GetEntryVersion(wSeparatorValue); + + dwGroupListOfs = dwOffset = FindGroupList(dwOffset); + if (!dwOffset) { + AddMessage( LPGEN("ERROR: Failed to find contact list groups.")); + #ifdef _LOGGING + { // If this is a debug build, dump MyDetails block to disk + FILE *stream; + DWORD dwSize; + dwOffset = FindMyDetails(); + dwSize = *(PDWORD)(pDat + dwOffset); + stream = fopen("import_grouplist_dump.bin", "w"); + fwrite(pDat + dwOffset, 1, dwSize, stream); + fclose(stream); + } + #endif + return -1; + } + + // Check number of groups + dwGroups = *(PDWORD)(pDat + dwOffset); + if (dwGroups > 0) + AddMessage( LPGEN("Importing groups.")); + else { + AddMessage( LPGEN("This database does not contain any contact groups.")); + return 0; + } + + dwOffset += 4; + + // Import all groups with a name + switch (nFormat) { + case ENTRYV99A: + case ENTRYV99B: + for (n = 0; n < dwGroups; n++) { + if (*(PWORD)(pDat+dwOffset+4) > 1) { + if ( CreateGroup(DBVT_ASCIIZ, (char*)(pDat + dwOffset) + 6, NULL )) + nImported++; + dwOffset += *(PWORD)(pDat + dwOffset + 4) + 12; + } } + break; + + case ENTRYV2000A: + case ENTRYV2000B: + case ENTRYV2001A: + case ENTRYV2001B: + case ENTRYV2002A: + for (n = 0; n < dwGroups; n++) { + if (tmpOfs = ReadPropertyBlock(dwOffset, "GroupName", &nSearchResult)) { + if (nSearchResult) { + if (CreateGroup( DBVT_ASCIIZ, (char*)(pDat + tmpOfs + 3), NULL )) + nImported++; + } } + + dwOffset = ReadPropertyBlock(dwOffset, NULL, NULL); + if (!dwOffset) { + AddMessage( LPGEN("ERROR: An error occurred while importing groups.")); + AddMessage( LPGEN("All groups may not have not been imported.")); + #ifdef _LOGGING + { // If this is a debug build, dump MyDetails block to disk + FILE *stream; + DWORD dwSize; + dwOffset = FindMyDetails(); + dwSize = *(PDWORD)(pDat + dwOffset); + stream = fopen("import_grouplist_dump.bin", "w"); + fwrite(pDat + dwOffset, 1, dwSize, stream); + fclose(stream); + } + #endif + return -1; + } } + break; + + default: + return -1; + } + + return nImported; +} + +// Imports the contact at offset dwOffset +// Returns the HANDLE of the Miranda contact +// or INVALID_HANDLE_VALUE on failure + +HANDLE ImportContact(DWORD dwOffset) +{ + int nContactVersion, nSearchResult; + BYTE Status; + WORD wSeparatorValue; + DWORD dwGroup, dwUIN = 0, tmpOfs = 0; + char *strNickname = 0, *strGroupName = 0; + + if (*(int*)(pDat + dwOffset + 4) != DATENTRY_CONTACT) + return INVALID_HANDLE_VALUE; + + if (*(int*)(pDat + dwOffset + 0x1e) != 'USER') + return INVALID_HANDLE_VALUE; + + #ifdef _LOGGING + { // If this is a debug build, dump contact to disk + FILE *stream; + DWORD dwSize; + dwSize = *(PDWORD)(pDat + dwOffset); + stream = fopen("import_last_contact.bin", "w"); + fwrite(pDat + dwOffset, 1, dwSize, stream); + fclose(stream); + } + #endif + + Status = *(pDat + dwOffset + 0x22); + wSeparatorValue = *(PWORD)(pDat + dwOffset + 0x1c); + nContactVersion = GetEntryVersion(wSeparatorValue); + + dwGroup = *(PDWORD)(pDat + dwOffset + 0x26); + if (dwGroup >= 1000) + strGroupName = GetGroupName(dwGroup); + + if (Status == 5) + return INVALID_HANDLE_VALUE; // Skip deleted contacts + + if ((Status != 2) && (Status != 3)) { + AddMessage( LPGEN("Skipping inactive contact.")); + return INVALID_HANDLE_VALUE; + } + + if ((nContactVersion < ENTRYV99A) || (nContactVersion == 0)) { + AddMessage( LPGEN("Skipping contact with unsupported version.")); + return INVALID_HANDLE_VALUE; + } + + switch(nContactVersion){ + case ENTRYV99A: + if (!(dwOffset = ReadWavList(dwOffset + 0x54))) return INVALID_HANDLE_VALUE; + if (!(dwOffset = ReadPropertyBlock(dwOffset + 0x26, NULL, NULL))) return INVALID_HANDLE_VALUE; + // Check for custom nickname + if (*(PWORD)(pDat + dwOffset) > 1) strNickname = (char*)(dwOffset + pDat + 2); + // Find UIN + dwOffset += *(PWORD)(pDat + dwOffset) + 2; // Custom nick name + dwOffset += *(PWORD)(pDat + dwOffset) + 2; // Nick name + dwOffset += *(PWORD)(pDat + dwOffset) + 2; // First name + dwOffset += *(PWORD)(pDat + dwOffset) + 2; // Last name + dwOffset += *(PWORD)(pDat + dwOffset) + 2; // E-mail + dwUIN = *(PDWORD)(pDat + dwOffset); // UIN + break; + + case ENTRYV99B: + case ENTRYV2000A: + case ENTRYV2000B: + if (!(dwOffset = ReadWavList(dwOffset + 0x2C))) return INVALID_HANDLE_VALUE; + tmpOfs = ReadPropertyBlockList(dwOffset + 0x02, "UIN", &nSearchResult); + if (nSearchResult) dwUIN = *(PDWORD)(pDat + tmpOfs + 1); + tmpOfs = ReadPropertyBlockList(dwOffset + 0x02, "MyDefinedHandle", &nSearchResult); + if (nSearchResult) strNickname = (char*)(tmpOfs + pDat + 3); + break; + + case ENTRYV2001A: + case ENTRYV2001B: + tmpOfs = ReadPropertyBlockList(dwOffset + 0x2C, "MyDefinedHandle", &nSearchResult); + if (nSearchResult) strNickname = (char*)(tmpOfs + pDat + 3); + tmpOfs = ReadPropertyBlockList(dwOffset + 0x2C, "UIN", &nSearchResult); + if (nSearchResult) dwUIN = *(PDWORD)(pDat + tmpOfs + 1); + break; + + case ENTRYV2002A: + tmpOfs = ReadPropertyBlockList(dwOffset + 0x32, "MyDefinedHandle", &nSearchResult); + if (nSearchResult) strNickname = (char*)(tmpOfs + pDat + 3); + tmpOfs = ReadPropertyBlockList(dwOffset + 0x32, "UIN", &nSearchResult); + if (nSearchResult) dwUIN = *(PDWORD)(pDat + tmpOfs + 1); + break; + } + + if (!dwUIN) { + AddMessage( LPGEN("Skipping unrecognizable contact.")); + return INVALID_HANDLE_VALUE; + } + + if (dwUIN < 10000) { + AddMessage( LPGEN("Skipping non-ICQ contact %u."), dwUIN ); + return INVALID_HANDLE_VALUE; + } + + if (HContactFromNumericID( szICQModuleName[ iICQAccount ], "UIN", dwUIN) == INVALID_HANDLE_VALUE) { + DBVARIANT id, nick, group; + id.type = DBVT_DWORD; id.dVal = dwUIN; + if ( strNickname != NULL && strlen(strNickname) > 0 ) + nick.type = DBVT_ASCIIZ, nick.pszVal = strNickname; + else + nick.type = DBVT_DELETED; + group.type = DBVT_ASCIIZ, group.pszVal = strGroupName; + return AddContact(hdlgProgress, szICQModuleName[ iICQAccount ], "UIN", &id, &nick, &group); + } + else { + if ((strNickname != NULL) && (strlen(strNickname) > 0)) + AddMessage( LPGEN("Skipping duplicate ICQ contact %u, %s"), dwUIN, strNickname); + else + AddMessage( LPGEN("Skipping duplicate ICQ contact %u"), dwUIN); + } + + // Failure + return INVALID_HANDLE_VALUE; +} + +BOOL ImportMessage(DWORD dwOffset) +{ + struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); + struct TDatEntryFooter *footer; + DBEVENTINFO dbei; + HANDLE hContact; + int nUCTOffset; + TIME_ZONE_INFORMATION TimeZoneInformation; + int nHistoryCount = 0; + + // Get timestamp offset. In ICQ, event timestamps are stored + // as UTC + (0-TZ offset). YES! That's the negation of the + // timezone offset, only God and Mirabilis knows why. + GetTimeZoneInformation(&TimeZoneInformation); + nUCTOffset = -TimeZoneInformation.Bias * 60; + + // Ignore messages in 'Deleted' folder + if (msg->filingStatus&FILING_DELETED) + return FALSE; + + // Skip messages from non-icq contacts + if (msg->uin < 10000) { + AddMessage( LPGEN("Ignoring msg from user %d at ofs %d."), msg->uin, dwOffset ); + return FALSE; + } + + // Ignore received messages? + if (( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_MSGRECV )) + return FALSE; + + // Ignores sent messages? + if ( !(msg->filingStatus & FILING_RECEIVED) && !( nCustomOptions & IOPT_MSGSENT )) + return FALSE; + + // Check if contact exists in Miranda database + hContact = HistoryImportFindContact(hdlgProgress, szICQModuleName[ iICQAccount ], msg->uin, nCustomOptions&IOPT_ADDUNKNOWN); + if (hContact == INVALID_HANDLE_VALUE) + return FALSE; // Contact couldn't be found/added + + // Convert the event to a Miranda dbevent + footer = (struct TDatEntryFooter*)(pDat + dwOffset + msg->textLen + offsetof(struct TDatMessage, text)); + ZeroMemory(&dbei, sizeof(dbei)); + dbei.cbSize = sizeof(dbei); + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.flags = footer->sent == 1 ? DBEF_SENT : DBEF_READ; + dbei.szModule = szICQModuleName[ iICQAccount ]; + // Convert timestamp + dbei.timestamp = footer->timestamp + nUCTOffset; + dbei.cbBlob = msg->textLen; + dbei.pBlob = (PBYTE)alloca(msg->textLen); + CopyMemory(dbei.pBlob, msg->text, dbei.cbBlob); + dbei.pBlob[dbei.cbBlob - 1] = 0; + + // Check for duplicate entries + if (IsDuplicateEvent(hContact, dbei)) { + nDupes++; + } + else { + if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) + nMessagesCount++; + } + + return TRUE; +} + +BOOL ImportExtendedMessage(DWORD dwOffset) +{ + struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); + struct TDatEntryFooter *footer; + DBEVENTINFO dbei; + HANDLE hContact; + int nUCTOffset; + TIME_ZONE_INFORMATION TimeZoneInformation; + int nHistoryCount = 0; + char* pszText = 0; + DWORD dwRichTextOffset = 0; + DWORD wRichTextLength = 0; + DWORD wLength = 0; + BOOL bFreeMe = FALSE; + + // Get timestamp offset. In ICQ, event timestamps are stored + // as UTC + (0-TZ offset). YES! That's the negation of the + // timezone offset, only God and Mirabilis knows why. + GetTimeZoneInformation(&TimeZoneInformation); + nUCTOffset = -TimeZoneInformation.Bias * 60; + + // Ignore messages in 'Deleted' folder + if (msg->filingStatus&FILING_DELETED) + return FALSE; + + // Skip messages from non-icq contacts + if (msg->uin < 10000) { + AddMessage( LPGEN("Ignoring msg from user %d at ofs %d."), msg->uin, dwOffset ); + return FALSE; + } + + // Ignore received messages? + if (( msg->filingStatus & FILING_RECEIVED) && !( nCustomOptions & IOPT_MSGRECV )) + return FALSE; + + // Ignore sent messages? + if ( !( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_MSGSENT )) + return FALSE; + + // Check if contact exists in Miranda database + hContact = HistoryImportFindContact(hdlgProgress, szICQModuleName[ iICQAccount ], msg->uin, nCustomOptions&IOPT_ADDUNKNOWN); + if (hContact == INVALID_HANDLE_VALUE) + return FALSE; // Contact couldn't be found/added + + // Find a piece of usable text content + if (msg->textLen <= 1) { + // Skip past the RTF segment + wRichTextLength = *(PWORD)(pDat + dwOffset + 0x2A + msg->textLen + 0x21); + dwRichTextOffset = dwOffset + 0x2A + msg->textLen + 0x23; + + // Use the UTF-8 text segment + wLength = *(PWORD)(pDat + dwRichTextOffset + wRichTextLength); + if (wLength <= 1) { + AddMessage( LPGEN("Ignoring msg with no text from %d ofs %d."), msg->uin, dwOffset ); + return FALSE; + } + pszText = _strdup((char *)pDat + dwRichTextOffset + wRichTextLength + 2); + bFreeMe = TRUE; + mir_utf8decode(pszText, NULL); + wLength = (DWORD)strlen(pszText)+1; + } + else { + // Use the ANSI text segment + wLength = msg->textLen; + pszText = (char *)(pDat + dwOffset + 0x2A); + } + + // Convert the event to a Miranda dbevent + footer = (struct TDatEntryFooter*)(pDat + dwOffset + msg->textLen + offsetof(struct TDatMessage, text)); + ZeroMemory(&dbei, sizeof(dbei)); + dbei.cbSize = sizeof(dbei); + dbei.eventType = EVENTTYPE_MESSAGE; + dbei.flags = footer->sent == 1 ? DBEF_SENT : DBEF_READ; + dbei.szModule = szICQModuleName[ iICQAccount ]; + // Convert timestamp + dbei.timestamp = footer->timestamp + nUCTOffset; + dbei.cbBlob = wLength; + dbei.pBlob = (PBYTE)calloc(wLength,1); + CopyMemory(dbei.pBlob, pszText, dbei.cbBlob); + dbei.pBlob[dbei.cbBlob - 1] = 0; + + // Check for duplicate entries + if (IsDuplicateEvent(hContact, dbei)) { + nDupes++; + } + else { + if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) + nMessagesCount++; + } + + free(dbei.pBlob); + if (bFreeMe) + free(pszText); + + return TRUE; +} + +BOOL ImportURLMessage(DWORD dwOffset) +{ + struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); + struct TDatEntryFooter *footer; + DBEVENTINFO dbei; + HANDLE hContact; + int nUCTOffset; + TIME_ZONE_INFORMATION TimeZoneInformation; + int nHistoryCount = 0; + char *pSeparator; + + // Get timestamp offset. In ICQ, event timestamps are stored + // as UTC + (0-TZ offset). YES! That's the negation of the + // timezone offset, only God and Mirabilis knows why. + GetTimeZoneInformation(&TimeZoneInformation); + nUCTOffset = -TimeZoneInformation.Bias * 60; + + // Ignore URLs in 'Deleted' folder + if (msg->filingStatus&FILING_DELETED) + return FALSE; + + // Skip URLs from non-icq contacts + if (msg->uin < 10000) { + AddMessage( LPGEN("Ignoring msg from user %d at ofs %d."), msg->uin, dwOffset ); + return FALSE; + } + + // Ignore received URLs? + if (( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_URLRECV )) + return FALSE; + + // Ignores sent URLs? + if ( !( msg->filingStatus & FILING_RECEIVED ) && !( nCustomOptions & IOPT_URLSENT )) + return FALSE; + + // Check if contact exists in Miranda database + hContact = HistoryImportFindContact(hdlgProgress, szICQModuleName[ iICQAccount ], msg->uin, nCustomOptions&IOPT_ADDUNKNOWN); + if (hContact == INVALID_HANDLE_VALUE) + return FALSE; // Contact couldn't be found/added + + // Convert the event to a Miranda dbevent + footer = (struct TDatEntryFooter*)(pDat + dwOffset + msg->textLen + offsetof(struct TDatMessage, text)); + ZeroMemory(&dbei, sizeof(dbei)); + dbei.cbSize = sizeof(dbei); + dbei.eventType = EVENTTYPE_URL; + dbei.flags = footer->sent == 1 ? DBEF_SENT : DBEF_READ; + dbei.szModule = szICQModuleName[ iICQAccount ]; + // Convert timestamp + dbei.timestamp = footer->timestamp + nUCTOffset; + dbei.cbBlob = msg->textLen; + dbei.pBlob = (PBYTE)alloca(msg->textLen); + CopyMemory(dbei.pBlob, msg->text, dbei.cbBlob); + dbei.pBlob[dbei.cbBlob - 1] = 0; + // Separate URL and description + pSeparator = strchr((char*)dbei.pBlob, 0xFE); + if (pSeparator != NULL) + *pSeparator = 0; + + // Check for duplicate entries + if (IsDuplicateEvent(hContact, dbei)) + nDupes++; + else if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) + nMessagesCount++; + + return TRUE; +} + +BOOL ImportEvent(DWORD dwOffset) +{ + struct TDatMessage *msg = (struct TDatMessage*)(pDat + dwOffset); + + // Events have IDs > 2000 + if (msg->hdr.entryId < 2001) { + AddMessage( LPGEN("Skipping event with ID < 2001.")); + return FALSE; + } + + // Separate code paths based on the event signature + switch (msg->hdr.subType) { + + case SUBTYPE_MESSAGE: // All kinds of messages + switch (msg->type) { + case 1: // Normal message + if ((nCustomOptions&IOPT_MSGRECV) || (nCustomOptions&IOPT_MSGSENT)) { + return ImportMessage(dwOffset); + } + break; + + case 4: // URL + if ((nCustomOptions&IOPT_URLSENT) || (nCustomOptions&IOPT_URLRECV)) { + return ImportURLMessage(dwOffset); + } + break; + + case 6: // Request for authorization + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'Request for auth.' msg, ofs %d."), dwOffset ); + #endif + break; + + case 7: // Authorization request denied + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'Auth. denied' msg, ofs %d."), dwOffset ); + #endif + break; + + case 8: // Authorization request accepted + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'Auth. accepted' msg, ofs %d."), dwOffset ); + #endif + break; + + case 9: // System message + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'System message', ofs %d."), dwOffset ); + #endif + break; + + case 12: // You were added + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'You were added' msg, ofs %d."), dwOffset ); + #endif + break; + + case 13: // WWWPager ? + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'WWW Pager' msg, ofs %d."), dwOffset ); + #endif + break; + + case 14: // Email Express ? + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'Email Express' msg, ofs %d."), dwOffset ); + #endif + break; + + case 19: // Contact list + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'Contact' msg, ofs %d."), dwOffset ); + #endif + break; + + case 21: // Phonecall request? + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'Phonecall' msg (?), ofs %d."), dwOffset ); + #endif + break; + + case 26: // SMS request? + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'SMS' msg (?), ofs %d."), dwOffset ); + #endif + break; + + case 29: // Active list invitation ?? + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 29 msg, ofs %d."), dwOffset ); + #endif + break; + + case 30: // Birthday reminder + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 'Birthday' msg (?), ofs %d."), dwOffset ); + #endif + break; + + case 32: // Unknown (Tomer) + #ifdef _LOGGING + AddMessage( LPGEN("Skipping 32 msg, ofs %d."), dwOffset ); + #endif + break; + + default: + AddMessage( LPGEN("Skipping unknown 0xE0 subtype (%d), ofs %d."), msg->type, dwOffset ); + + #ifdef _LOGGING + { // If this is a debug build, dump entry to disk + FILE *stream; + DWORD dwSize = *(PDWORD)(pDat + dwOffset); + wsprintfA(str, "import_unknown_E0subtype_%u-%u.bin", msg->type, dwOffset); + stream = fopen(str, "w"); + fwrite(pDat + dwOffset, 1, dwSize, stream); + fclose(stream); + } + #endif + + return FALSE; + } + break; + + case SUBTYPE_CHATREQUEST: // 0xE1 + #ifdef _LOGGING + if (nImportOption != IMPORT_CONTACTS) + AddMessage( LPGEN("Skipping 'Chat request' msg, ofs %d."), dwOffset ); + #endif + break; + + case SUBTYPE_FILEREQUEST: // 0xE2 + #ifdef _LOGGING + if (nImportOption != IMPORT_CONTACTS) + AddMessage( LPGEN("Skipping file message offset %d."), dwOffset ); + #endif + break; + + case 0xE3: // External (IPhone, Battlecom) Maybe general voice calls? + #ifdef _LOGGING + if (nImportOption != IMPORT_CONTACTS) + AddMessage( LPGEN("Skipping message type 0xE3 at offset %d."), dwOffset ); + #endif + break; + + case 0xE4: // My details + break; + case 0xE5: // Contact + break; + case 0xE6: // Reminder + break; + case 0xE7: // Addressbook + break; + case 0xEC: // Voice message + break; + case 0xED: // Unknown, something to do with chatting and .CHT files + // if (importHistory) { + // wsprintf(str, "Skipping message type 0xED at offset %d.", dwOffset); + // AddMessage( LPGEN(str); + // } + break; + case 0xEE: // Note + break; + case 0xEF: // Event folder + break; + // case 0xF0: // Unknown + // if (importHistory) { + // wsprintf(str, "Skipping message type 0xF0 at offset %d.", dwOffset); + // AddMessage( LPGEN(str); + // } + // break; + case 0xF1: // Server list + break; + // case 0xF6: // Unknown + // if (importHistory) { + // wsprintf(str, "Skipping message type 0xF6 at offset %d.", dwOffset); + // AddMessage( LPGEN(str); + // } + // break; + case 0x50: // Extended message, ICQ 2000a+? + if (nImportOption != IMPORT_CONTACTS) { + return ImportExtendedMessage(dwOffset); + } + break; + + case 0xA0: // URL message type 2 + if (nImportOption != IMPORT_CONTACTS) { + if ((msg->filingStatus&FILING_RECEIVED) || (nCustomOptions&IOPT_URLRECV)) { + return ImportURLMessage(dwOffset); + } + } + break; + + default: + if (nImportOption != IMPORT_CONTACTS) { + AddMessage( LPGEN("Skipping unknown event type %d at offset %d."), msg->hdr.subType, dwOffset ); + +#ifdef _LOGGING + { // If this is a debug build, dump entry to disk + FILE *stream; + DWORD dwSize; + dwSize = *(PDWORD)(pDat + dwOffset); + wsprintfA(str, "import_unknown_eventtype_%u-%u.bin", msg->hdr.subType, dwOffset); + stream = fopen(str, "w"); + fwrite(pDat + dwOffset, 1, dwSize, stream); + fclose(stream); + } +#endif + + } + break; + } + + return FALSE; +} + + +static void MirabilisImport(HWND hdlgProgressWnd) +{ + HANDLE hIdx, hDat, hIdxMapping, hDatMapping; + DWORD i, ofs, highestIndexEntry; + TCHAR datFilename[MAX_PATH]; + MSG msg; + DWORD dwTimer; + + + int status = 0; + hdlgProgress = hdlgProgressWnd; + nDupes = nContactsCount = nMessagesCount = 0; + + SetProgress(0); + lstrcpy(datFilename, importFile); + { + TCHAR* str2; + str2 = _tcsrchr(datFilename,'.'); + if ( str2 != NULL ) + lstrcpy(str2, _T(".dat")); + } + + hIdx = CreateFile(importFile, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + if (hIdx == INVALID_HANDLE_VALUE) { + AddMessage( LPGEN("Failed to open index file")); + AddMessage( LPGEN("Import aborted")); + SetProgress(100); + return; + } + + hDat = CreateFile(datFilename, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); + if (hDat == INVALID_HANDLE_VALUE) { + AddMessage( LPGEN("Failed to open database file")); + AddMessage( LPGEN("Import aborted")); + SetProgress(100); + return; + } + + // Creating file mappings + hIdxMapping = CreateFileMapping(hIdx, NULL, PAGE_READONLY, 0, 0, NULL); + hDatMapping = CreateFileMapping(hDat, NULL, PAGE_READONLY, 0, 0, NULL); + + // Mapping views of files + pIdx = (PBYTE)MapViewOfFile(hIdxMapping, FILE_MAP_READ, 0, 0, 0); + pDat = (PBYTE)MapViewOfFile(hDatMapping, FILE_MAP_READ, 0, 0, 0); + + // Is this a supported format? + if (GetDBVersion()) { + AddMessage( "" ); + + highestIndexEntry = GetHighestIndexEntry(); + + // Import groups + nGroupsCount = ImportGroups(); + if (nGroupsCount < 0) { + AddMessage( LPGEN("Group import was not completed.")); + nGroupsCount = 0; + } + AddMessage( "" ); + + // Start benchmark timer + dwTimer = time(NULL); + + if ( !IsProtocolLoaded( szICQModuleName[iICQAccount] )) { + AddMessage( LPGEN("ICQ account is not installed.")); + AddMessage( LPGEN("No ICQ contacts or history will be imported.")); + AddMessage( "" ); + } + else { + // Configure database for fast writing + CallService(MS_DB_SETSAFETYMODE, FALSE, 0); + + // Import contacts + AddMessage( LPGEN("Importing contacts")); + for (i = 2001; i <= highestIndexEntry; i++) { //event ids start at 2001 + if (!(i%10)) { + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + if (!(i%100)) + SetProgress(100 * (i - 2001) / (highestIndexEntry - 2001)); + + ofs = GetIdDatOfs(i); + if (ofs != 0) { + if (ImportContact(ofs) != INVALID_HANDLE_VALUE) + nContactsCount++; + } + } + AddMessage( "" ); + + // Import history + if (nImportOption != IMPORT_CONTACTS) { + AddMessage( LPGEN("Importing history (this may take a while)")); + for (i = 2001; i <= highestIndexEntry; i++) { //event ids start at 2001 + if (!(i%10)) { + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + + if (!(i%100)) + SetProgress(100 * (i - 2001) / (highestIndexEntry - 2001)); + + ofs = GetIdDatOfs(i); + if (ofs != 0) ImportEvent(ofs); + } + AddMessage( "" ); + } + + // Restore database writing mode + CallService(MS_DB_SETSAFETYMODE, TRUE, 0); + } + + dwTimer = time(NULL) - dwTimer; + + AddMessage( LPGEN("Import completed in %d seconds."), dwTimer ); + SetProgress(100); + AddMessage( LPGEN("Added %d contacts and %d groups."), nContactsCount, nGroupsCount ); + if ( nImportOption != IMPORT_CONTACTS ) + AddMessage( LPGEN("Added %d events and skipped %d duplicates."), nMessagesCount, nDupes ); + } + + UnmapViewOfFile(pDat); + UnmapViewOfFile(pIdx); + CloseHandle(hDatMapping); + CloseHandle(hIdxMapping); + CloseHandle(hDat); + CloseHandle(hIdx); +} diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.h b/plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.h new file mode 100644 index 0000000000..47f10141e1 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/mirabilis.h @@ -0,0 +1,200 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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. + +*/ + + + +#ifndef MIRABILIS_H +#define MIRABILIS_H + +#include +#include +#include + +// ====================== +// == GLOBAL FUNCTIONS == +// ====================== + +HANDLE HistoryImportFindContact(HWND hdlgProgress, char* szModuleName, DWORD uin,int addUnknown); + +// ===================== +// == LOCAL FUNCTIONS == +// ===================== + + +// Main function +static void MirabilisImport(HWND hdlgProgressWnd); + +// GUI callbacks +INT_PTR CALLBACK ImportTypePageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK MirabilisPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK MirabilisOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); + +// Helper functions for entries +static int GetHighestIndexEntry(void); +static int GetIdDatOfs(DWORD id); +static int GetDatEntryType(DWORD ofs); +DWORD FindMyDetails(void); + +// Parsing functions +DWORD GetDBVersion(); +int GetEntryVersion(WORD wSeparatorValue); +DWORD ReadPropertyBlock(DWORD dwOffset, char* SearchWord, int* nSearchResult); +DWORD ReadSubList(DWORD dwOffset); +DWORD ReadPropertyBlock(DWORD dwOffset, char* SearchWord, int* nSearchResult); +DWORD ReadPropertyBlockList(DWORD dwOffset, char* SearchWord, int* nSearchResult); +DWORD ReadWavList(DWORD ofs); +DWORD FindGroupList(DWORD dwOffset); +char* GetGroupName(DWORD dwGroupID); +int ImportGroups(); +static HANDLE ImportContact(DWORD dwOffset); + +BOOL ImportEvent(DWORD dwOffset); +BOOL ImportMessage(DWORD dwOffset); +BOOL ImportExtendedMessage(DWORD dwOffset); +BOOL ImportURLMessage(DWORD dwOffset); + + + + +// ====================== +// == GLOBAL VARIABLES == +// ====================== + +extern TCHAR importFile[MAX_PATH]; +extern void (*DoImport)(HWND); +extern int nImportOption; +extern int nCustomOptions; + + +extern int cICQAccounts; +extern char ** szICQModuleName; +extern TCHAR ** tszICQAccountName; +extern int iICQAccount; + +// ===================== +// == LOCAL VARIABLES == +// ===================== + +static DWORD dwDBVersion; +static DWORD dwGroupListOfs; +static PBYTE pIdx,pDat; + +// ============= +// == DEFINES == +// ============= + +// Contact versions +// These numbers are not 100% accurate +#define ENTRYVUNKNOWN -1 +#define ENTRYV99A 200 +#define ENTRYV99B 300 +#define ENTRYV2000A 400 +#define ENTRYV2000B 455 +#define ENTRYV2001A 500 +#define ENTRYV2001B 515 +#define ENTRYV2002A 533 + +// Database versions +#define DBV99A 10 +#define DBV99B 14 +#define DBV2000A 17 +#define DBV2000B 18 +#define DBV2001A 19 // This is used by ICQ 2001a, 2001b & 2002a + +#define DATENTRY_UNFILED (DWORD)(-1) +#define DATENTRY_MESSAGE 0 +#define DATENTRY_CONTACT 1 +#define DATENTRY_IGNORED 2 +#define DATENTRY_SYSTEM 9 + +#define MAX_NON_ICQ_CONTACTS 100 + +#define SUBTYPE_NEWMESSAGE 0x50 +#define SUBTYPE_NEWURL 0xA0 + +#define SUBTYPE_MESSAGE 0xE0 //Message / URL Message / Request For Authorization / "Authorization" / System Request / "You Were Added" / Contacts List +#define SUBTYPE_CHATREQUEST 0xE1 +#define SUBTYPE_FILEREQUEST 0xE2 +#define SUBTYPE_MYDETAILS 0xE4 +#define SUBTYPE_CONTACTINFO 0xE5 +#define SUBTYPE_REMINDER 0xE6 +#define SUBTYPE_ADDRESSBOOK 0xE7 +#define SUBTYPE_VOICEMSG 0xEC //??? +#define SUBTYPE_NOTE 0xEE +#define SUBTYPE_EVENTFOLDER 0xEF +#define SUBTYPE_SERVERLIST 0xF1 //and objectionable word list +#define SUBTYPE_X1 0xF6 //(new to ICQ 99b???) + +#define FILING_RECEIVED 0x01 +#define FILING_DELETED 0x02 +#define FILING_MESSAGE 0x04 +#define MSGTYPE_MESSAGE 1 +#define MSGTYPE_URL 4 +#define MSGTYPE_CLIST 19 +#include + +struct TIdxDatEntry { + DWORD status; //-2=valid, else is an index entry + DWORD entryId; + DWORD ofsNext,ofsPrev; + DWORD datOfs; +}; + +struct TIdxIndexEntry { + DWORD entryIdLow; + DWORD entryIdHigh; + DWORD ofsLower; + DWORD ofsInHere; + DWORD ofsHigher; +}; + +struct TDatEntryHeader { + DWORD entrySize; //in bytes + DWORD entryType; //DATENTRY_* constant + DWORD entryId; //same as in index + BYTE subType; //SUBTYPE_* constant + BYTE signature[15]; +}; + +struct TDatEntryFooter { + DWORD unknown; + DWORD sent; //1 if sent, 0 if received + WORD separator; + DWORD timestamp; //unix time +}; + +struct TDatMessage { + struct TDatEntryHeader hdr; //hdr.entryType==DATENTRY_MESSAGE && hdr.subType==MSGTYPE_MESSAGE + WORD separator; + DWORD filingStatus; //FILING_* flags + WORD type; //MSGTYPE_* constant + DWORD uin; + WORD textLen; + char text[1]; //0xFE separates description & URL in URLs + //a struct TDatEntryFooter comes here +}; + +#include + +#endif diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/miranda.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/miranda.cpp new file mode 100644 index 0000000000..8b6a9496f4 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/miranda.cpp @@ -0,0 +1,1491 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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. + +*/ + +// ============== +// == INCLUDES == +// ============== + +#include "import.h" + +#include "mirandadb0700.h" + +// ====================== +// == GLOBAL FUNCTIONS == +// ====================== + +HANDLE HContactFromNumericID(char* pszProtoName, char* pszSetting, DWORD dwID); +HANDLE HContactFromID(char* pszProtoName, char* pszSetting, char* pszID); + +HANDLE AddContact(HWND hdlgProgress, char* pszProtoName, char* pszUniqueSetting, DBVARIANT* id, DBVARIANT* nick, DBVARIANT* group); + +BOOL IsProtocolLoaded(char* pszProtocolName); +BOOL IsDuplicateEvent(HANDLE hContact, DBEVENTINFO dbei); + +INT_PTR CALLBACK ImportTypePageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK MirandaOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); + +// ===================== +// == LOCAL FUNCTIONS == +// ===================== + +void MirandaImport(HWND hdlgProgress); +int CheckFileFormat(HANDLE hFile); +static HANDLE ImportContact(HANDLE hDbFile, struct DBContact Contact); +static void ImportHistory(HANDLE hDbFile, struct DBContact Contact, PROTOCOLDESCRIPTOR **protocol, int protoCount); +static int ImportGroups(HANDLE hDbFile, struct DBHeader *pdbHeader); + +// Comment: The Find* functions only return a file offset. +// The Get* functions actually reads the requested +// data from the file and gives you a pointer to a structure +// containing the data. + +DWORD FindFirstContact(struct DBHeader* pDbHeader); +DWORD FindNextContact(struct DBContact* pDbContact); +DWORD FindNextEvent(HANDLE hDbFile, DWORD dwOffset); +DWORD FindOwnerContact(struct DBHeader* pDbHeader); + +int GetContactCount(struct DBHeader* pDbHeader); +BOOL GetContact(HANDLE hDbFile, DWORD dwOffset, struct DBContact* pDbContact); +BOOL GetSetting(HANDLE hDbFile, struct DBContact* pDbContact, char* pszModuleName, char* pszSettingName, DBVARIANT* pValue); +char* GetNextSetting(char* pDbSetting); +BOOL GetSettings(HANDLE hDbFile, DWORD dwOffset, struct DBContactSettings** pDbSettings); +struct DBContactSettings* GetSettingsGroupByModuleName(HANDLE hdbFile, struct DBContact* pDbContact, char* pszName); +DWORD GetBlobSize(struct DBContactSettings* pDbSettings); +int GetSettingByName(struct DBContactSettings* pDbSettings, char* pszSettingName, DBVARIANT* pValue); +int GetSettingValue(char* pBlob,DBVARIANT* pValue); + +BOOL GetEvent(HANDLE hDbFile, DWORD dwOffset, DBEVENTINFO* pDBEI); +char* GetName(HANDLE hDbFile, DWORD dwOffset); + + +// ====================== +// == GLOBAL VARIABLES == +// ====================== + +extern void (*DoImport)(HWND); +extern int nImportOption; +extern int nCustomOptions; + + +// ===================== +// == LOCAL VARIABLES == +// ===================== + +TCHAR importFile[MAX_PATH]; +HWND hdlgProgress; +DWORD dwFileSize; + +DWORD nDupes; +DWORD nContactsCount; +DWORD nMessagesCount; +DWORD nGroupsCount; +DWORD nSkippedEvents; +DWORD nSkippedContacts; + +time_t dwSinceDate = 0; + +// ============= +// == DEFINES == +// ============= + +#define EVENTTYPE_MESSAGE 0 +#define EVENTTYPE_URL 1 +#define EVENTTYPE_FILE 1002 + + +// Supported database versions +#define DB_INVALID 0x00000000 // Unknown or corrupted DAT +#define DB_000700 0x00000700 // Miranda 0.1.0.0 - 0.1.2.2+ + +// DAT file signature +struct DBSignature { + char name[15]; + BYTE eof; +}; + +static struct DBSignature dbSignature={"Miranda ICQ DB",0x1A}; + +// Unsane: Secured signature +static struct DBSignature dbSignatureEncrypted={"Miranda ICQ SD",0x1A}; + +// ==================== +// ==================== +// == IMPLEMENTATION == +// ==================== +// ==================== + +static void SearchForLists(HWND hdlg, const TCHAR *mirandaPath, const TCHAR *mirandaProf, const TCHAR *pattern, const TCHAR *type) +{ + HANDLE hFind; + WIN32_FIND_DATA fd; + TCHAR szSearchPath[MAX_PATH]; + TCHAR szRootName[MAX_PATH]; + TCHAR* str2; + int i; + + mir_sntprintf(szSearchPath, SIZEOF(szSearchPath), _T("%s\\%s"), mirandaPath, pattern); + hFind = FindFirstFile(szSearchPath, &fd); + if (hFind != INVALID_HANDLE_VALUE) + { + do + { + _tcscpy(szRootName, fd.cFileName); + str2 = _tcsrchr(szRootName, '.'); + if (str2 != NULL) *str2 = 0; + if (mirandaProf == NULL || _tcsicmp(mirandaProf, szRootName)) + { + _tcscat(szRootName, type); + i = SendDlgItemMessage(hdlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)szRootName); + str2 = (TCHAR*)mir_alloc((_tcslen(mirandaPath) + 2 + _tcslen(fd.cFileName)) * sizeof(TCHAR)); + wsprintf(str2, _T("%s\\%s"), mirandaPath, fd.cFileName); + SendDlgItemMessage(hdlg, IDC_LIST, LB_SETITEMDATA, i, (LPARAM)str2); + } + } + while( FindNextFile( hFind, &fd )); + + FindClose( hFind ); + } +} + +INT_PTR CALLBACK MirandaPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + { + TCHAR *pfd, *pfd1, *pfd2, *pfn; + + REPLACEVARSDATA dat = {0}; + dat.cbSize = sizeof(dat); + dat.dwFlags = RVF_TCHAR; + + pfd = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_path%\\Profiles"), (LPARAM)&dat); + pfd1 = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_path%"), (LPARAM)&dat); + pfd2 = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_profile%"), (LPARAM)&dat); + pfn = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)_T("%miranda_profilename%"), (LPARAM)&dat); + + SearchForLists(hdlg, pfd2, pfn, _T("*.dat"), _T(" (Miranda IM v0.x)")); + // Unsane: check for exclude equal or used profiles + if (lstrcmpi(pfd1, pfd2)) + SearchForLists(hdlg, pfd1, NULL, _T("*.dat"), _T(" (Miranda IM v0.x)")); + if (lstrcmpi(pfd, pfd2)) + SearchForLists(hdlg, pfd, NULL, _T("*.dat"), _T(" (Miranda IM v0.x)")); + + mir_free(pfn); + mir_free(pfd2); + mir_free(pfd1); + mir_free(pfd); + return TRUE; + } + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_IMPORTTYPE,(LPARAM)ImportTypePageProc); + break; + + case IDOK: + { + TCHAR filename[MAX_PATH]; + + GetDlgItemText(hdlg, IDC_FILENAME, filename, SIZEOF(filename)); + if (_taccess(filename, 4)) { + MessageBox(hdlg, TranslateT("The given file does not exist. Please check that you have entered the name correctly."), TranslateT("Miranda Import"), MB_OK); + break; + } + lstrcpy(importFile, filename); + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_OPTIONS,(LPARAM)MirandaOptionsPageProc); + } + break; + + case IDCANCEL: + PostMessage(GetParent(hdlg),WM_CLOSE,0,0); + break; + + case IDC_LIST: + if(HIWORD(wParam)==LBN_SELCHANGE) { + int sel = SendDlgItemMessage(hdlg, IDC_LIST, LB_GETCURSEL, 0, 0); + if (sel == LB_ERR) break; + SetDlgItemText(hdlg, IDC_FILENAME, (TCHAR*)SendDlgItemMessage(hdlg, IDC_LIST, LB_GETITEMDATA, sel, 0)); + } + break; + + case IDC_OTHER: + { + OPENFILENAME ofn; + TCHAR str[MAX_PATH], text[256]; + TCHAR *pfd; + + pfd = Utils_ReplaceVarsT(_T("%miranda_profile%")); + + GetDlgItemText(hdlg, IDC_FILENAME, str, SIZEOF(str)); + ZeroMemory(&ofn, sizeof(ofn)); + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = hdlg; + mir_sntprintf(text, SIZEOF(text), _T("%s (*.dat, *.bak)%c*.dat;*.bak%c%s (*.*)%c*.*%c%c"), TranslateT("Miranda IM database"), 0, 0, TranslateT("All Files"), 0, 0, 0); + ofn.lpstrFilter = text; + ofn.lpstrDefExt = _T("dat"); + ofn.lpstrFile = str; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT; + ofn.nMaxFile = SIZEOF(str); + ofn.lpstrInitialDir = pfd; + if (GetOpenFileName(&ofn)) + SetDlgItemText(hdlg, IDC_FILENAME, str); + + mir_free(pfd); + break; + } + } + break; + case WM_DESTROY: + { + int i; + + for(i=SendDlgItemMessage(hdlg,IDC_LIST,LB_GETCOUNT,0,0)-1;i>=0;i--) + mir_free((char*)SendDlgItemMessage(hdlg,IDC_LIST,LB_GETITEMDATA,i,0)); + break; + } } + + return FALSE; +} + + +INT_PTR CALLBACK MirandaOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + EnableWindow(GetDlgItem(hdlg,IDC_RADIO_ALL), TRUE); + EnableWindow(GetDlgItem(hdlg,IDC_STATIC_ALL), TRUE); + EnableWindow(GetDlgItem(hdlg,IDC_RADIO_CONTACTS), TRUE); + EnableWindow(GetDlgItem(hdlg,IDC_STATIC_CONTACTS), TRUE); + EnableWindow(GetDlgItem(hdlg,IDC_RADIO_CUSTOM), TRUE); + EnableWindow(GetDlgItem(hdlg,IDC_STATIC_CUSTOM), TRUE); + CheckDlgButton(hdlg,IDC_RADIO_ALL,BST_UNCHECKED); + return TRUE; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_MIRANDADB,(LPARAM)MirandaPageProc); + break; + + case IDOK: + if(IsDlgButtonChecked(hdlg,IDC_RADIO_ALL)) { + nImportOption = IMPORT_ALL; + nCustomOptions = 0;//IOPT_MSGSENT|IOPT_MSGRECV|IOPT_URLSENT|IOPT_URLRECV; + DoImport = MirandaImport; + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); + break; + } + + if(IsDlgButtonChecked(hdlg,IDC_RADIO_CONTACTS)) { + nImportOption = IMPORT_CONTACTS; + nCustomOptions = 0; + DoImport = MirandaImport; + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); + break; + } + + if(IsDlgButtonChecked(hdlg,IDC_RADIO_CUSTOM)) { + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_ADVOPTIONS,(LPARAM)MirandaAdvOptionsPageProc); + break; + } + break; + + case IDCANCEL: + PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); + break; + } + break; + } + return FALSE; +} + +static const UINT InControls[]={IDC_IN_MSG,IDC_IN_URL,IDC_IN_FT,IDC_IN_OTHER}; +static const UINT OutControls[]={IDC_OUT_MSG,IDC_OUT_URL,IDC_OUT_FT,IDC_OUT_OTHER}; +static const UINT SysControls[]={IDC_CONTACTS, IDC_SYSTEM}; + +INT_PTR CALLBACK MirandaAdvOptionsPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + { + struct tm *TM = NULL; + struct _SYSTEMTIME ST = {0}; + + dwSinceDate = DBGetContactSettingDword(NULL,IMPORT_MODULE,"ImportSinceTS",time(NULL)); + + TM = localtime(&dwSinceDate); + + ST.wYear = TM->tm_year + 1900; + ST.wMonth = TM->tm_mon + 1; + ST.wDay = TM->tm_mday; + + DateTime_SetSystemtime(GetDlgItem(hdlg,IDC_DATETIMEPICKER),GDT_VALID,&ST); + } + return TRUE; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_OPTIONS,(LPARAM)MirandaOptionsPageProc); + break; + + case IDOK: + DoImport = MirandaImport; + nImportOption = IMPORT_CUSTOM; + nCustomOptions = 0; + + if (IsDlgButtonChecked(hdlg,IDC_CONTACTS)) + nCustomOptions |= IOPT_CONTACTS | IOPT_GROUPS; + if (IsDlgButtonChecked(hdlg,IDC_SYSTEM)) + nCustomOptions |= IOPT_SYSTEM; + + // incoming + if (IsDlgButtonChecked(hdlg,IDC_IN_MSG)) + nCustomOptions |= IOPT_MSGRECV; + if (IsDlgButtonChecked(hdlg,IDC_IN_URL)) + nCustomOptions |= IOPT_URLRECV; + if (IsDlgButtonChecked(hdlg,IDC_IN_FT)) + nCustomOptions |= IOPT_FILERECV; + if (IsDlgButtonChecked(hdlg,IDC_IN_OTHER)) + nCustomOptions |= IOPT_OTHERRECV; + + // outgoing + if (IsDlgButtonChecked(hdlg,IDC_OUT_MSG)) + nCustomOptions |= IOPT_MSGSENT; + if (IsDlgButtonChecked(hdlg,IDC_OUT_URL)) + nCustomOptions |= IOPT_URLSENT; + if (IsDlgButtonChecked(hdlg,IDC_OUT_FT)) + nCustomOptions |= IOPT_FILESENT; + if (IsDlgButtonChecked(hdlg,IDC_OUT_OTHER)) + nCustomOptions |= IOPT_OTHERSENT; + + // since date + dwSinceDate = 0; + + if ( IsDlgButtonChecked( hdlg, IDC_SINCE )) { + struct _SYSTEMTIME ST = {0}; + + if (DateTime_GetSystemtime(GetDlgItem(hdlg,IDC_DATETIMEPICKER), &ST) == GDT_VALID) { + struct tm TM = {0}; + + TM.tm_mday = ST.wDay; + TM.tm_mon = ST.wMonth - 1; + TM.tm_year = ST.wYear - 1900; + + dwSinceDate = mktime(&TM); + + DBWriteContactSettingDword(NULL,IMPORT_MODULE,"ImportSinceTS",dwSinceDate); + } } + + if (nCustomOptions) + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); + break; + + case IDCANCEL: + PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); + break; + + case IDC_SINCE: + EnableWindow(GetDlgItem(hdlg, IDC_DATETIMEPICKER), IsDlgButtonChecked(hdlg, IDC_SINCE)); + break; + + if (HIWORD(wParam) != STN_CLICKED) + break; + + case IDC_ALL: + case IDC_INCOMING: + case IDC_OUTGOING: + { + int i; + + if (LOWORD(wParam) == IDC_ALL) + for (i = 0; i < sizeof(SysControls)/sizeof(SysControls[0]); i++) + CheckDlgButton(hdlg,SysControls[i], !IsDlgButtonChecked(hdlg,SysControls[i])); + + if (LOWORD(wParam) != IDC_OUTGOING) + for (i = 0; i < sizeof(InControls)/sizeof(InControls[0]); i++) + CheckDlgButton(hdlg,InControls[i], !IsDlgButtonChecked(hdlg,InControls[i])); + + if (LOWORD(wParam) != IDC_INCOMING) + for (i = 0; i < sizeof(OutControls)/sizeof(OutControls[0]); i++) + CheckDlgButton(hdlg,OutControls[i], !IsDlgButtonChecked(hdlg,OutControls[i])); + } + break; + + case IDC_MSG: + CheckDlgButton(hdlg,IDC_IN_MSG, !IsDlgButtonChecked(hdlg,IDC_IN_MSG)); + CheckDlgButton(hdlg,IDC_OUT_MSG, !IsDlgButtonChecked(hdlg,IDC_OUT_MSG)); + break; + + case IDC_URL: + CheckDlgButton(hdlg,IDC_IN_URL, !IsDlgButtonChecked(hdlg,IDC_IN_URL)); + CheckDlgButton(hdlg,IDC_OUT_URL, !IsDlgButtonChecked(hdlg,IDC_OUT_URL)); + break; + + case IDC_FT: + CheckDlgButton(hdlg,IDC_IN_FT, !IsDlgButtonChecked(hdlg,IDC_IN_FT)); + CheckDlgButton(hdlg,IDC_OUT_FT, !IsDlgButtonChecked(hdlg,IDC_OUT_FT)); + break; + + case IDC_OTHER: + CheckDlgButton(hdlg,IDC_IN_OTHER, !IsDlgButtonChecked(hdlg,IDC_IN_OTHER)); + CheckDlgButton(hdlg,IDC_OUT_OTHER, !IsDlgButtonChecked(hdlg,IDC_OUT_OTHER)); + break; + } + break; + } + return FALSE; +} + +#ifndef INVALID_SET_FILE_POINTER +#define INVALID_SET_FILE_POINTER ((DWORD)-1) +#endif + +// Read header from file, returns null on failure +struct DBHeader* GetHeader(HANDLE hDbFile) +{ + struct DBHeader* pdbHeader; + DWORD dwBytesRead; + + if (( pdbHeader = (DBHeader *)calloc(1, sizeof(struct DBHeader))) == NULL ) + return NULL; + + // Goto start of file + if (SetFilePointer(hDbFile, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + return FALSE; + + // Read header + if ( !ReadFile(hDbFile, pdbHeader, sizeof(struct DBHeader), &dwBytesRead, NULL ) || + dwBytesRead != sizeof(struct DBHeader)) + return NULL; + + // Return pointer to header + return pdbHeader; +} + +// Unsane: database crypted status +BOOL bEncrypted; +// Unsane: crypted database work fuction +int CheckPassword(WORD version, WORD cryptorUID, TCHAR * szDBName); +void InitSecurity(); + +int CheckFileFormat(HANDLE hDbFile) +{ + struct DBHeader* pdbHeader; + TCHAR* tszDbName; + + // Read header + if (( pdbHeader = GetHeader(hDbFile)) == NULL ) + return DB_INVALID; + + // Check header signature + bEncrypted = FALSE; + if (memcmp(pdbHeader->signature, &dbSignature, sizeof(pdbHeader->signature))) { + // Unsane: if not encrypted signature + if (memcmp(pdbHeader->signature, &dbSignatureEncrypted, sizeof(pdbHeader->signature))) { + AddMessage( LPGEN("Signature mismatch" )); + return DB_INVALID; + } + AddMessage(LPGEN("Database is Secured MMAP database")); + // Unsane: check password + InitSecurity(); + tszDbName = _tcsrchr(importFile, _T('\\')) + 1; + if (CheckPassword(pdbHeader->checkWord, pdbHeader->cryptorUID, tszDbName)) { + AddMessage(LPGEN("Secured MMAP: authorization successful")); + bEncrypted = TRUE; + } + else + { + AddMessage(LPGEN("You are not authorized for access to Database")); + return DB_INVALID; + } + } + + // Determine Miranda version + switch (pdbHeader->checkWord) { + case DB_000700: + AddMessage( LPGEN("This looks like a Miranda database, version 0.1.0.0 or above." )); + free(pdbHeader); + return DB_000700; + + default: + if (!bEncrypted){ + AddMessage( LPGEN("Version mismatch" )); + free(pdbHeader); + return DB_INVALID; + } + break; + } + return 1; +} + +// High level Miranda DB access functions +// Returns true if pValue points to the requested value + +BOOL GetSetting(HANDLE hDbFile, struct DBContact* pDbContact, char* pszModuleName, char* pszSettingName, DBVARIANT* pValue) +{ + struct DBContactSettings* pDbSettings; + if ( pDbSettings = GetSettingsGroupByModuleName(hDbFile, pDbContact, pszModuleName)) { + if ( GetSettingByName( pDbSettings, pszSettingName, pValue )) { + free(pDbSettings); + return TRUE; + } + #ifdef _LOGGING + AddMessage( LPGEN("Failed to find setting %s" ), pszSettingName ); + #endif + free(pDbSettings); + } +#ifdef _LOGGING + else AddMessage( LPGEN("Failed to find module %s" ), pszModuleName ); +#endif + + // Search failed + pValue->type = 0; + return FALSE; +} + +// ** +// ** CONTACT CHAIN +// ** + +// Return offset to first contact +DWORD FindFirstContact(struct DBHeader* pDbHeader) +{ + if (!pDbHeader) + return 0; + + return pDbHeader->ofsFirstContact; +} + +DWORD FindOwnerContact(struct DBHeader* pDbHeader) +{ + if (!pDbHeader) + return 0; + + return pDbHeader->ofsUser; +} + +// Return offset to next contact +DWORD FindNextContact(struct DBContact* pDbContact) +{ + if (!pDbContact) + return 0; + + if (pDbContact->signature != DBCONTACT_SIGNATURE) + return 0; + + return pDbContact->ofsNext; +} + + +// Read the contact at offset 'dwOffset' +// Returns true if successful and pDbContact points to the contact struct +// pDbContact must point to allocated struct +BOOL GetContact(HANDLE hDbFile, DWORD dwOffset, struct DBContact* pDbContact) +{ + DWORD dwBytesRead; + + // Early reject + if (dwOffset == 0 || dwOffset >= dwFileSize) + return FALSE; + + // ** Read and verify the struct + + if (SetFilePointer(hDbFile, (LONG)dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + return FALSE; + + if ((!ReadFile(hDbFile, pDbContact, sizeof(struct DBContact), &dwBytesRead, NULL)) || + (dwBytesRead != sizeof(struct DBContact))) + return FALSE; + + if ((pDbContact->signature != DBCONTACT_SIGNATURE) || + (pDbContact->ofsNext >= dwFileSize)) + return FALSE; // Contact corrupted + + return TRUE; +} + +// Return ptr to next setting in settings struct +char* GetNextSetting(char* pDbSetting) +{ + // Get next setting + pDbSetting = pDbSetting + *pDbSetting+1; // Skip name + switch( *(BYTE*)pDbSetting ) { + case DBVT_BYTE: + pDbSetting = pDbSetting+1+1; + break; + + case DBVT_WORD: + pDbSetting = pDbSetting+1+2; + break; + + case DBVT_DWORD: + pDbSetting = pDbSetting+1+4; + break; + + case DBVT_ASCIIZ: + case DBVT_UTF8: + case DBVT_BLOB: + case DBVTF_VARIABLELENGTH: + pDbSetting = pDbSetting + 3 + *(WORD*)(pDbSetting+1); + break; + + case DBVT_DELETED: + AddMessage( LPGEN("DEBUG: Deleted setting treated as 0-length setting")); + pDbSetting = pDbSetting+1; + break; + + default: + // Unknown datatype assert + AddMessage( LPGEN("ERROR: Faulty settings chain")); + return NULL; + } + + return pDbSetting; +} + + +// ** +// ** SETTINGS CHAIN +// ** + +// Return the settings at offset 'dwOffset' +BOOL GetSettingsGroup(HANDLE hDbFile, DWORD dwOffset, struct DBContactSettings** pDbSettings) +{ + DWORD dwBytesRead, dwBlobSize, dwHead; + struct DBContactSettings pSettings; + + // Early reject + if (dwOffset == 0 || dwOffset >= dwFileSize) + return FALSE; + + // ** Read and verify the struct + if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + return FALSE; + + dwHead = offsetof(struct DBContactSettings, blob); + if ((!ReadFile(hDbFile, &pSettings, dwHead, &dwBytesRead, NULL)) || + (dwBytesRead != dwHead)) + return FALSE; + + if (pSettings.signature != DBCONTACTSETTINGS_SIGNATURE) + return FALSE; // Setttings corrupted + + // ** Read the struct and the following blob + dwBlobSize = pSettings.cbBlob; + if (!(*pDbSettings = (DBContactSettings *)calloc(1, sizeof(struct DBContactSettings) + dwBlobSize))) + return FALSE; + + memcpy(*pDbSettings, &pSettings, dwHead ); + + if ((!ReadFile(hDbFile, (*pDbSettings)->blob, sizeof(struct DBContactSettings) - dwHead + dwBlobSize, &dwBytesRead, NULL)) || + (dwBytesRead != sizeof(struct DBContactSettings) - dwHead + dwBlobSize)) + { + free(*pDbSettings); + return FALSE; + } + + return TRUE; +} + +// pDbContact is a ptr to a struct DBContact +// Returns pointer to a struct DBContactSettings or NULL +struct DBContactSettings* GetSettingsGroupByModuleName(HANDLE hDbFile, struct DBContact* pDbContact, char* pszName) +{ + char* pszGroupName; + struct DBContactSettings* pSettingsGroup; + DWORD dwGroupOfs; + + // Get ptr to first settings group + if (!(dwGroupOfs = pDbContact->ofsFirstSettings)) + return NULL; // No settings exists in this contact + + // Loop over all settings groups + while (dwGroupOfs && dwGroupOfs < dwFileSize) { + pSettingsGroup = NULL; + + // Read and verify the struct + if (!GetSettingsGroup(hDbFile, dwGroupOfs, &pSettingsGroup)) + return NULL; // Bad struct + + // Struct OK, now get the name + if ((pszGroupName = GetName(hDbFile, pSettingsGroup->ofsModuleName))) { + + // Is it the right one? + if (strcmp(pszGroupName, pszName) == 0) { + #ifdef _LOGGING + AddMessage( LPGEN("Found module: %s"), pszGroupName ); + #endif + return pSettingsGroup; + } + #ifdef _LOGGING + else AddMessage( LPGEN("Ignoring module: %s"), pszGroupName ); + #endif + } + else AddMessage( LPGEN("Warning: Found module with no name")); + + dwGroupOfs = pSettingsGroup->ofsNext; + + if (pSettingsGroup) + free(pSettingsGroup); + } + + // Search failed + return NULL; +} + +// pDbSettings must point to a complete DBContactSettings struct in memory +int GetSettingByName(struct DBContactSettings* pDbSettings, char* pszSettingName, DBVARIANT* dbv) +{ + char pszName[256]; + // We need at least one setting to start with + char* pDbSetting = (char *)pDbSettings->blob; + if ( !pDbSetting ) + return FALSE; + + // ** pDbSettings now points to the first setting in this module + + // Loop over all settings + while (pDbSetting && *pDbSetting) { + memcpy(pszName, pDbSetting+1, *pDbSetting); + pszName[*pDbSetting] = 0; + + // Is this the right one? + if (strcmp(pszSettingName, pszName) == 0) { + return GetSettingValue(pDbSetting, dbv); + } + + #ifdef _LOGGING + AddMessage( LPGEN("Ignoring setting: %s"), pszName ); + #endif + pDbSetting = GetNextSetting(pDbSetting); + } + + // Search failed + return FALSE; +} + +// dwSettingpointer points to a valid DBSettings struct +int GetSettingValue(char* pBlob, DBVARIANT* dbv) +{ + #ifdef _LOGGING + { + char* pszName = calloc((*pBlob)+1, 1); + memcpy(pszName, pBlob+1, *pBlob); + AddMessage( LPGEN("Getting type %u value for setting: %s"), (BYTE)*(pBlob+(*pBlob)+1), pszName ); + free(pszName); + } + #endif + + // Skip name + pBlob = pBlob + (*pBlob)+1; + dbv->type = ( BYTE )*pBlob++; + + // Check what type it is + switch( dbv->type ) { + case DBVT_BYTE: + dbv->bVal = *pBlob; + return TRUE; + + case DBVT_WORD: + if (bEncrypted) + DecodeMemory((BYTE *)pBlob, sizeof(pBlob)); + dbv->wVal = *(WORD*)pBlob; + return TRUE; + + case DBVT_DWORD: + if (bEncrypted) + DecodeMemory((BYTE *)pBlob, sizeof(pBlob)); + dbv->dVal = *(DWORD*)pBlob; + return TRUE; + + case DBVT_ASCIIZ: + case DBVT_UTF8: + dbv->cchVal = *(WORD*)pBlob; + dbv->pszVal = (char *)calloc( dbv->cchVal+1, sizeof( char )); + if (bEncrypted) + DecodeCopyMemory((BYTE *)dbv->pszVal, pBlob+2, dbv->cchVal); + else + memcpy( dbv->pszVal, pBlob+2, dbv->cchVal ); + dbv->pszVal[ dbv->cchVal ] = 0; + + return TRUE; + + case DBVTF_VARIABLELENGTH: + case DBVT_BLOB: + dbv->cpbVal = *(WORD*)pBlob; + dbv->pbVal = (BYTE *)calloc( dbv->cpbVal+1, sizeof( char )); + if (bEncrypted) + DecodeCopyMemory((BYTE *)dbv->pszVal, pBlob+2, dbv->cchVal); + else + memcpy( dbv->pbVal, pBlob+2, dbv->cpbVal ); + dbv->pbVal[ dbv->cpbVal ] = 0; + return TRUE; + + case DBVT_DELETED: + AddMessage( LPGEN("DEBUG: Deleted setting treated as 0-length setting")); + + default: + dbv->type = DBVT_DELETED; + } + + return FALSE; +} + +void FreeVariant( DBVARIANT* dbv ) +{ + switch( dbv->type ) { + case DBVT_ASCIIZ: + case DBVT_UTF8: + if ( dbv->pszVal ) + free( dbv->pszVal ); + break; + + case DBVTF_VARIABLELENGTH: + case DBVT_BLOB: + if ( dbv->pbVal ) + free( dbv->pbVal ); + break; + } + + dbv->type = 0; +} + +void WriteVariant( HANDLE hContact, const char* module, const char* var, DBVARIANT* dbv ) +{ + DBCONTACTWRITESETTING dbw; + dbw.szModule = module; + dbw.szSetting = var; + dbw.value = *dbv; + CallService( MS_DB_CONTACT_WRITESETTING, (WPARAM)hContact, (LPARAM)&dbw ); +} + +// Returns true if pDBEI has been filled in with nice values +// Don't forget to free those pointers! +BOOL GetEvent(HANDLE hDbFile, DWORD dwOffset, DBEVENTINFO* pDBEI) +{ + DWORD dwBytesRead; + struct DBEvent pEvent; + static char pBlob[65536]; + + // Early reject + if (dwOffset == 0 || dwOffset >= dwFileSize) + return FALSE; + + // ** Read and verify the struct + if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + return FALSE; + + if (!ReadFile(hDbFile, &pEvent, offsetof(struct DBEvent, blob), &dwBytesRead, NULL) || + (dwBytesRead != offsetof(struct DBEvent, blob))) + return FALSE; + + if (pEvent.signature != DBEVENT_SIGNATURE) + return FALSE; // Event corrupted + + // ** Read the blob + if ((!ReadFile(hDbFile, pBlob, pEvent.cbBlob, &dwBytesRead, NULL)) || + (dwBytesRead != pEvent.cbBlob)) + { + return FALSE; + } + + // ** Copy the static part to the event info struct + pDBEI->timestamp = pEvent.timestamp; + pDBEI->eventType = pEvent.eventType; + pDBEI->cbSize = sizeof(DBEVENTINFO); + pDBEI->cbBlob = pEvent.cbBlob; + pDBEI->pBlob = (PBYTE)pBlob; + pDBEI->flags = (pEvent.flags & ~(DBEF_SENT+DBEF_READ)) + + ((pEvent.flags & DBEF_SENT) ? DBEF_SENT : DBEF_READ ); // Imported events are always marked READ + + if (!(pDBEI->szModule = GetName(hDbFile, pEvent.ofsModuleName))) { + return FALSE; + } + + // Unsane: encrypt dbevent + if (bEncrypted) + DecodeMemory(pDBEI->pBlob, pDBEI->cbBlob); + + return TRUE; +} + +// Returns a pointer to a string with the name +// from a DBModuleName struct if given a file offset +// Returns NULL on failure +char* GetName(HANDLE hDbFile, DWORD dwOffset) +{ + static DWORD dwLastOffset = 0; + static HANDLE hLastDbFile = NULL; + static char szName[256] = {0}; + + DWORD dwBytesRead; + struct DBModuleName pModule; + + // Early reject + if (dwOffset == 0 || dwOffset >= dwFileSize) + return FALSE; + + // Quick lookup + if (dwOffset == dwLastOffset && hDbFile == hLastDbFile) + return szName; + + // ** Read and verify the name struct + if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + return NULL; + + if ((!ReadFile(hDbFile, &pModule, offsetof(struct DBModuleName, name), &dwBytesRead, NULL)) || + (dwBytesRead != offsetof(struct DBModuleName, name))) + return NULL; + + if (pModule.signature != DBMODULENAME_SIGNATURE) { + AddMessage( LPGEN("Modulename corrupted")); + return NULL; // ModuleName corrupted + } + + // ** Name struct OK, now read name into string buffer + if ((!ReadFile(hDbFile, szName, pModule.cbName, &dwBytesRead, NULL)) || (dwBytesRead != pModule.cbName)) { + return NULL; + } + + // terminate string + szName[pModule.cbName] = 0; + + // update last offset + dwLastOffset = dwOffset; + hLastDbFile = hDbFile; + + return szName; +} + +DWORD FindNextEvent(HANDLE hDbFile, DWORD dwOffset) +{ + DWORD dwBytesRead; + struct DBEvent pEvent; + + // Early reject + if (dwOffset == 0 || dwOffset >= dwFileSize) + return FALSE; + + // ** Read and verify the struct + if (SetFilePointer(hDbFile, dwOffset, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER) + return FALSE; + + if ((!ReadFile(hDbFile, &pEvent, sizeof(struct DBEvent), &dwBytesRead, NULL)) || + (dwBytesRead != sizeof(struct DBEvent))) + return FALSE; + + if ( pEvent.signature != DBEVENT_SIGNATURE || pEvent.ofsNext > dwFileSize ) + return FALSE; // Event corrupted + + return pEvent.ofsNext; +} + +int ImportGroups(HANDLE hDbFile, struct DBHeader* pdbHeader) +{ + struct DBContactSettings* pDbSettings; + struct DBContact DbContact; + char* pSetting; + DWORD dwOffset; + int nGroups = 0; + + // Find owner data + dwOffset = pdbHeader->ofsUser; + if (!GetContact(hDbFile, dwOffset, &DbContact)) { + AddMessage( LPGEN("No owner found.")); + return -1; + } + + // Find the module with the groups, and import them all + if ( pDbSettings = GetSettingsGroupByModuleName( hDbFile, &DbContact, "CListGroups" )) { + /*if (bEncrypted) + DecodeMemory(pDbSettings->blob, pDbSettings->cbBlob);*/ + pSetting = (char *)pDbSettings->blob; + while ( pSetting && *pSetting ) { + DBVARIANT dbv; + if ( GetSettingValue( pSetting, &dbv )) { + if ( CreateGroup( dbv.type, dbv.pszVal+1, NULL )) + nGroups++; + FreeVariant( &dbv ); + } + pSetting = GetNextSetting(pSetting); + } + free(pDbSettings); + + /*if (bEncrypted) + EncodeMemory(pDbSettings->blob, pDbSettings->cbBlob);*/ + } + + return nGroups; +} + +HANDLE ImportContact(HANDLE hDbFile, struct DBContact Contact) +{ + HANDLE hContact; + DBVARIANT group, nick, dbv; + char* pszProtoName; + char* pszUniqueSetting; + char* pszUserName; + char id[ 40 ]; + + // Check what protocol this contact belongs to + if ( !GetSetting( hDbFile, &Contact, "Protocol", "p", &dbv )) { + AddMessage( LPGEN("Skipping contact with no protocol")); + return INVALID_HANDLE_VALUE; + } + + pszProtoName = NEWSTR_ALLOCA( dbv.pszVal ); + FreeVariant( &dbv ); + + if ( !IsProtocolLoaded( pszProtoName )) { + AddMessage( LPGEN("Skipping contact, %s not installed."), pszProtoName ); + return INVALID_HANDLE_VALUE; + } + + // Skip protocols with no unique id setting (some non IM protocols return NULL) + pszUniqueSetting = (char*)CallProtoService(pszProtoName, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); + if ( !pszUniqueSetting || (INT_PTR)pszUniqueSetting == CALLSERVICE_NOTFOUND ) { + AddMessage( LPGEN("Skipping non-IM contact (%s)"), pszProtoName ); + return INVALID_HANDLE_VALUE; + } + + if ( !GetSetting(hDbFile, &Contact, pszProtoName, pszUniqueSetting, &dbv )) { + AddMessage( LPGEN("Skipping %s contact, ID not found"), pszProtoName ); + return INVALID_HANDLE_VALUE; + } + + // Does the contact already exist? + if ( dbv.type == DBVT_DWORD ) { + pszUserName = _ltoa( dbv.dVal, id, 10 ); + hContact = HContactFromNumericID( pszProtoName, pszUniqueSetting, dbv.dVal ); + } + else { + pszUserName = NEWSTR_ALLOCA( dbv.pszVal ); + hContact = HContactFromID( pszProtoName, pszUniqueSetting, dbv.pszVal ); + } + + if ( hContact != INVALID_HANDLE_VALUE ) { + AddMessage( LPGEN("Skipping duplicate %s contact %s"), pszProtoName, pszUserName ); + FreeVariant( &dbv ); + return INVALID_HANDLE_VALUE; + } + // No, add contact and copy some important settings + GetSetting(hDbFile, &Contact, "CList", "Group", &group); + + if ( !GetSetting( hDbFile, &Contact, "CList", "MyHandle", &nick )) + GetSetting(hDbFile, &Contact, pszProtoName, "Nick", &nick ); + + hContact = AddContact( hdlgProgress, pszProtoName, pszUniqueSetting, &dbv, &nick, &group ); + + if ( hContact != INVALID_HANDLE_VALUE) { + + // Hidden? + if ( GetSetting( hDbFile, &Contact, "CList", "Hidden", &dbv )) { + WriteVariant( hContact, "CList", "Hidden", &dbv ); + FreeVariant( &dbv ); + } + // Ignore settings + if ( GetSetting( hDbFile, &Contact, "Ignore", "Mask1", &dbv )) { + WriteVariant( hContact, "Ignore", "Mask1", &dbv ); + FreeVariant( &dbv ); + } + + // Apparent mode + if ( GetSetting( hDbFile, &Contact, pszProtoName, "ApparentMode", &dbv )) { + WriteVariant( hContact, pszProtoName, "ApparentMode", &dbv ); + FreeVariant( &dbv ); + } + + // Nick + if ( GetSetting( hDbFile, &Contact, pszProtoName, "Nick", &dbv )) { + WriteVariant( hContact, pszProtoName, "Nick", &dbv ); + FreeVariant( &dbv ); + } + + // Myhandle + if ( GetSetting( hDbFile, &Contact, pszProtoName, "MyHandle", &dbv )) { + WriteVariant( hContact, pszProtoName, "MyHandle", &dbv ); + FreeVariant( &dbv ); + } + + // First name + if ( GetSetting( hDbFile, &Contact, pszProtoName, "FirstName", &dbv )) { + WriteVariant( hContact, pszProtoName, "FirstName", &dbv ); + FreeVariant( &dbv ); + } + + // Last name + if ( GetSetting( hDbFile, &Contact, pszProtoName, "LastName", &dbv )) { + WriteVariant( hContact, pszProtoName, "LastName", &dbv ); + FreeVariant( &dbv ); + } + + // About + if ( GetSetting( hDbFile, &Contact, pszProtoName, "About", &dbv )) { + WriteVariant( hContact, pszProtoName, "About", &dbv ); + FreeVariant( &dbv ); + } + } + else AddMessage( LPGEN("Unknown error while adding %s contact %s"), pszProtoName, pszUserName ); + + return hContact; +} + +// This function should always be called after contact import. That is +// why there are no messages for errors related to contacts. Those +// would only be a repetition of the messages printed during contact +// import. + +static void ImportHistory(HANDLE hDbFile, struct DBContact Contact, PROTOCOLDESCRIPTOR **protocol, int protoCount) +{ + HANDLE hContact = INVALID_HANDLE_VALUE; + DWORD dwOffset; + MSG msg; + DBVARIANT proto; + int i, skipAll, bIsVoidContact; + + // Is it contats history import? + if ( protoCount == 0 ) { + + // Check what protocol this contact belongs to + if ( GetSetting( hDbFile, &Contact, "Protocol", "p", &proto )) { + + // Protocol installed? + if ( IsProtocolLoaded( proto.pszVal )) { + // Is contact in database? + char* pszUniqueSetting = (char*)CallProtoService( proto.pszVal, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); + + // Skip protocols with no unique id setting (some non IM protocols return NULL) + if ( pszUniqueSetting && ( INT_PTR )pszUniqueSetting != CALLSERVICE_NOTFOUND ) { + DBVARIANT dbv; + if ( GetSetting( hDbFile, &Contact, proto.pszVal, pszUniqueSetting, &dbv )) { + if ( dbv.type == DBVT_DWORD ) + hContact = HContactFromNumericID( proto.pszVal, pszUniqueSetting, dbv.dVal ); + else + hContact = HContactFromID( proto.pszVal, pszUniqueSetting, dbv.pszVal ); + FreeVariant( &dbv ); + } } } + FreeVariant( &proto ); + } + } + else hContact = NULL; //system history import + + // OK to import this chain? + if (hContact == INVALID_HANDLE_VALUE) { + nSkippedContacts++; + return; + } + + i = skipAll = 0; + bIsVoidContact = CallService( MS_DB_EVENT_GETCOUNT, ( WPARAM )hContact, 0 ) == 0; + + // Get the start of the event chain + dwOffset = Contact.ofsFirstEvent; + while (dwOffset) { + int skip = 0; + + // Copy the event and import it + DBEVENTINFO dbei = { 0 }; + if (GetEvent(hDbFile, dwOffset, &dbei)) { + // check protocols during system history import + if (hContact == NULL) { + int i; + skipAll = 1; + + for(i = 0; i < protoCount; i++) + if (!strcmp(dbei.szModule, protocol[i]->szName)) { //&& protocol[i]->type == PROTOTYPE_PROTOCOL) + skipAll = 0; + break; + } + + skip = skipAll; + } + + // custom filtering + if (!skip && nImportOption == IMPORT_CUSTOM) { + BOOL sent = (dbei.flags&DBEF_SENT); + + if (dbei.timestamp < (DWORD)dwSinceDate) + skip = 1; + + if (!skip) { + if (hContact) { + skip = 1; + switch(dbei.eventType) { + case EVENTTYPE_MESSAGE: + if ((sent?IOPT_MSGSENT:IOPT_MSGRECV)&nCustomOptions) + skip = 0; + break; + case EVENTTYPE_FILE: + if ((sent?IOPT_FILESENT:IOPT_FILERECV)&nCustomOptions) + skip = 0; + break; + case EVENTTYPE_URL: + if ((sent?IOPT_URLSENT:IOPT_URLRECV)&nCustomOptions) + skip = 0; + break; + default: + if ((sent?IOPT_OTHERSENT:IOPT_OTHERRECV)&nCustomOptions) + skip = 0; + break; + } + } + else if ( !( nCustomOptions & IOPT_SYSTEM )) + skip = 1; + } + + if (skip) + nSkippedEvents++; + } + + if (!skip) { + // Check for duplicate entries + if ( !IsDuplicateEvent( hContact, dbei )) { + // Add dbevent + if (!bIsVoidContact) + dbei.flags &= ~DBEF_FIRST; + if (CallService(MS_DB_EVENT_ADD, (WPARAM)hContact, (LPARAM)&dbei)) + nMessagesCount++; + else + AddMessage( LPGEN("Failed to add message")); + } + else + nDupes++; + } + } + + if ( !( i%10 )) { + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } + + // skip this chain if needed + if ( skipAll ) + break; + + // Get next event + dwOffset = FindNextEvent(hDbFile, dwOffset); + i++; + } +} + +static void MirandaImport(HWND hdlg) +{ + int nDBVersion; + int i; + int nNumberOfContacts = 0; + MSG msg; + DWORD dwTimer; + DWORD dwOffset; + HANDLE hFile; + char* pszModuleName = NULL; + struct DBHeader* pdbHeader = NULL; + struct DBContact Contact; + + // Just to keep the macros happy + hdlgProgress = hdlg; + + // Reset statistics + nSkippedEvents = 0; + nDupes = 0; + nContactsCount = 0; + nMessagesCount = 0; + nGroupsCount = 0; + nSkippedContacts = 0; + SetProgress(0); + + // Open database + hFile = CreateFile(importFile, + GENERIC_READ, // open for reading + 0, // do not share + NULL, // no security + OPEN_EXISTING, // existing file only + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no attr. template + + // Read error + if (hFile == INVALID_HANDLE_VALUE) { + AddMessage( LPGEN("Could not open file.")); + SetProgress(100); + return; + } + + // Check filesize + dwFileSize = GetFileSize(hFile, NULL) ; + if ((dwFileSize == INVALID_FILE_SIZE) || (dwFileSize < sizeof(struct DBHeader))) { + AddMessage( LPGEN("This is not a valid Miranda IM database.")); + SetProgress(100); + CloseHandle(hFile); + return; + } + + // Check header and database version + nDBVersion = CheckFileFormat(hFile); + if (nDBVersion == DB_INVALID) { + AddMessage( LPGEN("This is not a valid Miranda IM database.")); + SetProgress(100); + CloseHandle(hFile); + return; + } + + // Load database header + if (!(pdbHeader = GetHeader(hFile))) { + AddMessage( LPGEN("Read failure.")); + SetProgress(100); + CloseHandle(hFile); + return; + } + + // Get number of contacts + nNumberOfContacts = pdbHeader->contactCount; + AddMessage( LPGEN("Number of contacts in database: %d"), nNumberOfContacts ); + AddMessage( "" ); + + // Configure database for fast writing + CallService(MS_DB_SETSAFETYMODE, FALSE, 0); + + // Start benchmark timer + dwTimer = time(NULL); + + // Import Groups + if (nImportOption == IMPORT_ALL || (nCustomOptions & IOPT_GROUPS)) { + AddMessage( LPGEN("Importing groups.")); + nGroupsCount = ImportGroups(hFile, pdbHeader); + if (nGroupsCount == -1) + AddMessage( LPGEN("Group import failed.")); + + AddMessage( "" ); + } + // End of Import Groups + + // Import Contacts + if (nImportOption != IMPORT_CUSTOM || (nCustomOptions & IOPT_CONTACTS)) { + AddMessage( LPGEN("Importing contacts.")); + i = 1; + dwOffset = FindFirstContact(pdbHeader); + while (dwOffset && (dwOffset < dwFileSize)) { + if (!GetContact(hFile, dwOffset, &Contact)) { + AddMessage( LPGEN("ERROR: Chain broken, no valid contact at %d"), dwOffset ); + SetProgress(100); + break; + } + + if (ImportContact(hFile, Contact) != INVALID_HANDLE_VALUE) + nContactsCount++; + + // Update progress bar + SetProgress(100 * i / nNumberOfContacts); + i++; + + // Process queued messages + if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + // Get next contact in chain + dwOffset = FindNextContact(&Contact); + } + } + else AddMessage( LPGEN("Skipping new contacts import.")); + AddMessage( "" ); + // 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.")); + dwOffset = FindOwnerContact(pdbHeader); + if (!GetContact(hFile, dwOffset, &Contact)) { + AddMessage( LPGEN("ERROR: Chain broken, no valid contact at %d"), dwOffset ); + SetProgress(100); + } + else { + PROTOCOLDESCRIPTOR **protocol; + int protoCount; + + CallService(MS_PROTO_ENUMPROTOCOLS, (WPARAM)&protoCount, (LPARAM)&protocol); + + if (protoCount > 0) + ImportHistory(hFile, Contact, protocol, protoCount); + } + } + else AddMessage( LPGEN("Skipping system history import.")); + + AddMessage( "" ); + + // Import other contact messages + if (nImportOption == IMPORT_ALL || (nCustomOptions & 2046)) { // 2 - 1024 types + AddMessage( LPGEN("Importing history.")); + dwOffset = FindFirstContact(pdbHeader); + for(i=1; i <= nNumberOfContacts; i++) { + if (!GetContact(hFile, dwOffset, &Contact)) { + AddMessage( LPGEN("ERROR: Chain broken, no valid contact at %d"), dwOffset ); + SetProgress(100); + break; + } + + ImportHistory(hFile, Contact, NULL, 0); + + SetProgress(100 * i / nNumberOfContacts); + dwOffset = FindNextContact(&Contact); + } + } + else AddMessage( LPGEN("Skipping history import.")); + + AddMessage( "" ); + } + // End of Import History + + // Restore database writing mode + CallService(MS_DB_SETSAFETYMODE, TRUE, 0); + + // Clean up before exit + CloseHandle(hFile); + free(pdbHeader); + + // Stop timer + dwTimer = time(NULL) - dwTimer; + + // Print statistics + AddMessage( LPGEN("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."), + nContactsCount, nGroupsCount, nMessagesCount); + + if ( nImportOption != IMPORT_CONTACTS ) { + if (nSkippedContacts) + AddMessage( LPGEN("Skipped %d contacts."), nSkippedContacts ); + + AddMessage((nImportOption == IMPORT_CUSTOM) ? + LPGEN("Skipped %d duplicates and %d filtered events.") : LPGEN("Skipped %d duplicates."), + nDupes, nSkippedEvents); +} } diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/mirandadb0700.h b/plugins/Dbx_mmap_SA/Import_SA/src/mirandadb0700.h new file mode 100644 index 0000000000..07216ddbcf --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/mirandadb0700.h @@ -0,0 +1,148 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001,2002,2003,2004 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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. + +*/ + + + +//all offsets are relative to the start of the file +//offsets are 0 if there is nothing in the chain or this is the last in the +//chain + + + + +/* tree diagram + +DBHeader + |-->end of file (plain offset) + |-->first contact (DBContact) + | |-->next contact (DBContact) + | | \--> ... + | |-->first settings (DBContactSettings) + | | |-->next settings (DBContactSettings) + | | | \--> ... + | | \-->module name (DBModuleName) + | \-->first/last/firstunread event + |-->user contact (DBContact) + | |-->next contact=NULL + | |-->first settings as above + | \-->first/last/firstunread event as above + \-->first module name (DBModuleName) + \-->next module name (DBModuleName) + \--> ... +*/ + +#define DB_THIS_VERSION 0x00000700u + +#include +// Unsane: added "checkWord", "cryptorUID" and removed "version" fields +struct DBHeader { + BYTE signature[16]; // 'Miranda ICQ DB',0,26 + /* + DWORD version; //as 4 bytes, ie 1.2.3.10=0x0102030a + //this version is 0x00000700 + */ + + WORD checkWord; + WORD cryptorUID; + DWORD ofsFileEnd; //offset of the end of the database - place to write + //new structures + DWORD slackSpace; //a counter of the number of bytes that have been + //wasted so far due to deleting structures and/or + //re-making them at the end. We should compact when + //this gets above a threshold + DWORD contactCount; //number of contacts in the chain,excluding the user + DWORD ofsFirstContact; //offset to first struct DBContact in the chain + DWORD ofsUser; //offset to struct DBContact representing the user + DWORD ofsFirstModuleName; //offset to first struct DBModuleName in the chain +}; + +#define DBCONTACT_SIGNATURE 0x43DECADEu +struct DBContact { + DWORD signature; + DWORD ofsNext; //offset to the next contact in the chain. zero if + //this is the 'user' contact or the last contact + //in the chain + DWORD ofsFirstSettings; //offset to the first DBContactSettings in the + //chain for this contact. + DWORD eventCount; //number of events in the chain for this contact + DWORD ofsFirstEvent,ofsLastEvent; //offsets to the first and last DBEvent in + //the chain for this contact + DWORD ofsFirstUnreadEvent; //offset to the first (chronological) unread event + //in the chain, 0 if all are read + DWORD timestampFirstUnread; //timestamp of the event at ofsFirstUnreadEvent +}; + +#define DBMODULENAME_SIGNATURE 0x4DDECADEu +struct DBModuleName { + DWORD signature; + DWORD ofsNext; //offset to the next module name in the chain + BYTE cbName; //number of characters in this module name + char name[1]; //name, no nul terminator +}; + +#define DBCONTACTSETTINGS_SIGNATURE 0x53DECADEu +struct DBContactSettings { + DWORD signature; + DWORD ofsNext; //offset to the next contactsettings in the chain + DWORD ofsModuleName; //offset to the DBModuleName of the owner of these + //settings + DWORD cbBlob; //size of the blob in bytes. May be larger than the + //actual size for reducing the number of moves + //required using granularity in resizing + BYTE blob[1]; //the blob. a back-to-back sequence of DBSetting + //structs, the last has cbName=0 +}; + +/* not a valid structure, content is figured out on the fly +struct DBSetting { + BYTE cbName; //number of bytes in the name of this setting + //this =0 marks the end + char szName[...]; //setting name, excluding nul + BYTE dataType; //type of data. see m_database.h, db/contact/getsetting + union { //a load of types of data, length is defined by dataType + BYTE bVal; WORD wVal; DWORD dVal; + struct { + WORD cbString; + char szVal[...]; //excludes nul terminator + }; + struct { + WORD cbBlob; + BYTE blobVal[...]; + }; + }; +}; +*/ + +#define DBEVENT_SIGNATURE 0x45DECADEu +struct DBEvent { + DWORD signature; + DWORD ofsPrev,ofsNext; //offset to the previous and next events in the + //chain. Chain is sorted chronologically + DWORD ofsModuleName; //offset to a DBModuleName struct of the name of + //the owner of this event + DWORD timestamp; //seconds since 00:00:00 01/01/1970 + DWORD flags; //see m_database.h, db/event/add + WORD eventType; //module-defined event type + DWORD cbBlob; //number of bytes in the blob + BYTE blob[1]; //the blob. module-defined formatting +}; +#include diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/mirandahistory.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/mirandahistory.cpp new file mode 100644 index 0000000000..ba7a923df7 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/mirandahistory.cpp @@ -0,0 +1,208 @@ +/* +Miranda ICQ: the free icq client for MS Windows +Copyright (C) 2000-2 Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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 +#include +#include +#include "resource.h" +#include "import.h" + +BOOL CALLBACK MirandaPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +BOOL CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +BOOL CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); +extern char importFile[MAX_PATH]; +extern void (*DoImport)(HWND); +static void OldMirandaHistoryImport(HWND hdlgProgress); +HANDLE HContactFromUIN(DWORD uin); +HANDLE HistoryImportFindContact(HWND hdlgProgress,DWORD uin,int addUnknown); +static DWORD importOptions; + +BOOL CALLBACK MirandaHistoryPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + CheckDlgButton(hdlg,IDC_ADDUNKNOWN,BST_CHECKED); + CheckDlgButton(hdlg,IDC_MSGRECV,BST_CHECKED); + CheckDlgButton(hdlg,IDC_MSGSENT,BST_CHECKED); + CheckDlgButton(hdlg,IDC_URLRECV,BST_CHECKED); + CheckDlgButton(hdlg,IDC_URLSENT,BST_CHECKED); + CheckDlgButton(hdlg,IDC_AUTHREQ,BST_CHECKED); + CheckDlgButton(hdlg,IDC_ADDED,BST_CHECKED); + return TRUE; + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDC_BACK: + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_MIRANDADB,(LPARAM)MirandaPageProc); + break; + case IDOK: + importOptions=0; + if(IsDlgButtonChecked(hdlg,IDC_ADDUNKNOWN)) importOptions|=IOPT_ADDUNKNOWN; + if(IsDlgButtonChecked(hdlg,IDC_MSGSENT)) importOptions|=IOPT_MSGSENT; + if(IsDlgButtonChecked(hdlg,IDC_MSGRECV)) importOptions|=IOPT_MSGRECV; + if(IsDlgButtonChecked(hdlg,IDC_URLSENT)) importOptions|=IOPT_URLSENT; + if(IsDlgButtonChecked(hdlg,IDC_URLRECV)) importOptions|=IOPT_URLRECV; + if(IsDlgButtonChecked(hdlg,IDC_AUTHREQ)) importOptions|=IOPT_AUTHREQ; + if(IsDlgButtonChecked(hdlg,IDC_ADDED)) importOptions|=IOPT_ADDED; + DoImport=OldMirandaHistoryImport; + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_PROGRESS,(LPARAM)ProgressPageProc); + break; + case IDCANCEL: + PostMessage(GetParent(hdlg),WM_CLOSE,0,0); + break; + } + break; + } + return FALSE; +} + +#define HISTORY_MSGRECV 1 +#define HISTORY_MSGSEND 2 +#define HISTORY_URLRECV 3 +#define HISTORY_URLSEND 4 +#define HISTORY_AUTHREQ 5 +#define HISTORY_ADDED 6 +#define issent(t) ((t)==HISTORY_MSGSEND || (t)==HISTORY_URLSEND) +static int historyTypeToOption[]={0,IOPT_MSGRECV,IOPT_MSGSENT,IOPT_URLRECV,IOPT_URLSENT,IOPT_AUTHREQ,IOPT_ADDED}; + +static PBYTE ReadHistoryLines(FILE *fp,int *cbBlob) +{ + char str[2048]; + char *blob; + int ofs; + *cbBlob=0; + blob=NULL; + while(fgets(str,sizeof(str),fp) && lstrcmp(str,"\xEE\xEE\xEE\xEE\r\n")) { + ofs=*cbBlob; + *cbBlob+=lstrlen(str); + blob=(char*)realloc(blob,*cbBlob+1); + lstrcpy(blob+ofs,str); + } + if (*cbBlob) { + (*cbBlob)--; + blob[*cbBlob-1]=0; + } + else { + *cbBlob=1; + blob=(char*)malloc(1); + blob[0]=0; + } + return (PBYTE)blob; +} + +static void OldMirandaHistoryImport(HWND hdlgProgress) +{ + int fileSize; + FILE *fp; + char str[2048],*eol,*timeofs; + HANDLE hContact; + int type; + DWORD uin; + struct tm tmEventTime; + DBEVENTINFO dbei; + + AddMessage("Old Miranda history import routines initialised"); + fp=fopen(importFile,"rb"); + AddMessage("Calibrating status support functions"); + fseek(fp,0,SEEK_END); + fileSize=ftell(fp); + fseek(fp,0,SEEK_SET); + SetProgress(0); + + ZeroMemory(&dbei,sizeof(dbei)); + dbei.cbSize=sizeof(dbei); + dbei.szModule=ICQOSCPROTONAME; + + while(!feof(fp)) { + SetProgress(100*ftell(fp)/fileSize); + if(fgets(str,sizeof(str),fp)==NULL) break; + eol=str+lstrlen(str)-1; + + while(*eol=='\r' || *eol=='\n' && eol!=str-1) + *(eol--)=0; + + if(lstrlen(str)<20) continue; + type=*eol; + uin=strtoul(str,NULL,10); + if(uin==0) continue; //skip MSN + timeofs=str+lstrlen(str)-20; + tmEventTime.tm_hour=atoi(timeofs); + timeofs=strchr(timeofs,':'); + if(timeofs==NULL) continue; + tmEventTime.tm_min=atoi(timeofs+1); + tmEventTime.tm_sec=0; + tmEventTime.tm_isdst=-1; + tmEventTime.tm_mday=atoi(timeofs+7); + tmEventTime.tm_mon=atoi(timeofs+10)-1; + tmEventTime.tm_year=atoi(timeofs+13)-1900; + dbei.timestamp=mktime(&tmEventTime)+_timezone; + if (!(importOptions&historyTypeToOption[type])) continue; + hContact=HistoryImportFindContact(hdlgProgress,uin,importOptions&IOPT_ADDUNKNOWN); + if(hContact==INVALID_HANDLE_VALUE) break; + dbei.flags=issent(type)?DBEF_SENT:DBEF_READ; + switch(type) { + case HISTORY_MSGRECV: + case HISTORY_MSGSEND: + dbei.eventType=EVENTTYPE_MESSAGE; + dbei.pBlob=ReadHistoryLines(fp,&dbei.cbBlob); + CallService(MS_DB_EVENT_ADD,(WPARAM)hContact,(LPARAM)&dbei); + break; + case HISTORY_URLRECV: + case HISTORY_URLSEND: + dbei.eventType=EVENTTYPE_URL; + dbei.pBlob=ReadHistoryLines(fp,&dbei.cbBlob); + { char *endOfUrl; + endOfUrl=strchr(dbei.pBlob,'\r'); + if(endOfUrl!=NULL) { + *endOfUrl=0; + dbei.cbBlob--; + MoveMemory(endOfUrl+1,endOfUrl+2,dbei.cbBlob-(endOfUrl-dbei.pBlob)); + } + } + CallService(MS_DB_EVENT_ADD,(WPARAM)hContact,(LPARAM)&dbei); + break; + case HISTORY_AUTHREQ: + dbei.eventType=EVENTTYPE_AUTHREQUEST; + dbei.pBlob=ReadHistoryLines(fp,&dbei.cbBlob); + dbei.pBlob=(PBYTE)realloc(dbei.pBlob,dbei.cbBlob+8); + MoveMemory(dbei.pBlob+8,dbei.pBlob,dbei.cbBlob); + *(PDWORD)dbei.pBlob=uin; + *(char*)(dbei.pBlob+4)=0; //leave nick, first, last, email blank + *(char*)(dbei.pBlob+5)=0; + *(char*)(dbei.pBlob+6)=0; + *(char*)(dbei.pBlob+7)=0; + dbei.cbBlob+=8; + CallService(MS_DB_EVENT_ADD,(WPARAM)(HANDLE)NULL,(LPARAM)&dbei); + break; + case HISTORY_ADDED: + dbei.eventType=EVENTTYPE_ADDED; + dbei.pBlob=(PBYTE)malloc(8); + dbei.cbBlob=8; + *(PDWORD)dbei.pBlob=uin; + *(char*)(dbei.pBlob+4)=0; //leave nick, first, last, email blank + *(char*)(dbei.pBlob+5)=0; + *(char*)(dbei.pBlob+6)=0; + *(char*)(dbei.pBlob+7)=0; + CallService(MS_DB_EVENT_ADD,(WPARAM)(HANDLE)NULL,(LPARAM)&dbei); + break; + } + } + AddMessage("Terminating cached I/O access"); + fclose(fp); + AddMessage("Import completed successfully"); + SetProgress(100); +} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/progress.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/progress.cpp new file mode 100644 index 0000000000..f3f4e9f08a --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/progress.cpp @@ -0,0 +1,100 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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 +#include +#include + +#include "import.h" + +#define PROGM_START (WM_USER+100) + +INT_PTR CALLBACK FinishedPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam); + +void (*DoImport)(HWND); + +INT_PTR CALLBACK ProgressPageProc(HWND hdlg,UINT message,WPARAM wParam,LPARAM lParam) +{ + switch(message) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,0,0); + SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,1,0); + SendMessage(GetParent(hdlg),WIZM_DISABLEBUTTON,2,0); + SendDlgItemMessage(hdlg,IDC_PROGRESS,PBM_SETRANGE,0,MAKELPARAM(0,100)); + PostMessage(hdlg,PROGM_START,0,0); + return TRUE; + + case PROGM_SETPROGRESS: + SendDlgItemMessage(hdlg,IDC_PROGRESS,PBM_SETPOS,wParam,0); + break; + + case PROGM_ADDMESSAGE: + { + int i=SendDlgItemMessage(hdlg,IDC_STATUS,LB_ADDSTRING,0,lParam); + SendDlgItemMessage(hdlg,IDC_STATUS,LB_SETTOPINDEX,i,0); + } + break; + + case PROGM_START: + DoImport(hdlg); + SendMessage(GetParent(hdlg),WIZM_ENABLEBUTTON,1,0); + SendMessage(GetParent(hdlg),WIZM_ENABLEBUTTON,2,0); + break; + + case WM_COMMAND: + switch(LOWORD(wParam)) { + case IDOK: + PostMessage(GetParent(hdlg),WIZM_GOTOPAGE,IDD_FINISHED,(LPARAM)FinishedPageProc); + break; + case IDCANCEL: + PostMessage(GetParent(hdlg),WM_CLOSE,0,0); + break; + } + break; + } + return FALSE; +} + +void AddMessage( const char* fmt, ... ) +{ + va_list args; + char msgBuf[ 4096 ]; + va_start( args, fmt ); + + mir_vsnprintf( msgBuf, sizeof(msgBuf), Translate(fmt), args ); + + #ifdef _LOGGING + { + FILE *stream; + stream = fopen("Import Debug.log", "a"); + fprintf(stream, "%s\n", msgBuf); + fclose(stream); + } + #endif + + + { TCHAR* str = mir_a2t( msgBuf ); + SendMessage( hdlgProgress, PROGM_ADDMESSAGE, 0, ( LPARAM )str ); + mir_free( str ); + } +} diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/resource.h b/plugins/Dbx_mmap_SA/Import_SA/src/resource.h new file mode 100644 index 0000000000..915ee8097b --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/resource.h @@ -0,0 +1,68 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by resource.rc +// +#define IDC_BACK 3 +#define IDD_WIZARD 101 +#define IDD_OPTIONS 102 +#define IDD_ICQSERVER 104 +#define IDD_LOGIN 105 +#define IDD_IMPORTTYPE 106 +#define IDD_WIZARDINTRO 107 +#define IDD_FINISHED 108 +#define IDD_MIRABILISDB 109 +#define IDD_MIRANDADB 110 +#define IDD_PROGRESS 111 +#define IDD_ADVOPTIONS 112 +#define IDI_IMPORT 177 +#define IDI_PASS 178 +#define IDC_MIRABILIS 1000 +#define IDC_DONTLOADPLUGIN 1001 +#define IDC_MIRANDA 1002 +#define IDC_USEFINDADD 1003 +#define IDC_OTHER 1004 +#define IDC_LIST 1005 +#define IDC_FILENAME 1006 +#define IDC_PROGRESS 1007 +#define IDC_STATUS 1008 +#define IDC_MIRABILISRUNNING 1009 +#define IDC_MIRABILISACCOUNT 1010 +#define IDC_RADIO_ALL 1011 +#define IDC_RADIO_CONTACTS 1012 +#define IDC_RADIO_CUSTOM 1013 +#define IDC_STATIC_ALL 1014 +#define IDC_STATIC_CONTACTS 1015 +#define IDC_STATIC_CUSTOM 1016 +#define IDC_USERPASS 1017 +#define IDC_LANG 1018 +#define IDC_DATETIMEPICKER 1019 +#define IDC_IN_FT 1020 +#define IDC_CONTACTS 1021 +#define IDC_SYSTEM 1022 +#define IDC_SINCE 1023 +#define IDC_IN_MSG 1024 +#define IDC_IN_URL 1025 +#define IDC_OUT_FT 1026 +#define IDC_OUT_MSG 1027 +#define IDC_OUT_URL 1028 +#define IDC_IN_OTHER 1029 +#define IDC_OUT_OTHER 1030 +#define IDC_INCOMING 1031 +#define IDC_OUTGOING 1032 +#define IDC_ALL 1033 +#define IDC_MSG 1034 +#define IDC_URL 1035 +#define IDC_FT 1036 +#define IDC_HEADERBAR 1037 +#define IDC_STATIC -1 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 106 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1038 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/version.h b/plugins/Dbx_mmap_SA/Import_SA/src/version.h new file mode 100644 index 0000000000..8c2338d9f4 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/version.h @@ -0,0 +1,14 @@ +#include + +#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION +#define __VERSION_STRING MIRANDA_VERSION_STRING +#define __VERSION_DWORD MIRANDA_VERSION_DWORD +#define __PLUGIN_NAME "Import secured contacts and messages " +#define __INTERNAL_NAME "Import_sa" +#define __FILENAME "Import_sa.dll" +#define __DESCRIPTION "Imports contacts and messages from Mirabilis ICQ and Miranda IM. Enhanced modification with encrypted database support." +#define __DESCRIPTIONSHORT "Miranda IM Secured Import Plugin." +#define __AUTHOR "Miranda team" +#define __AUTHOREMAIL "info@miranda-im.org" +#define __AUTHORWEB "http://nightly.miranda.im/" +#define __COPYRIGHT "© 2000-2011 Martin Oberg, Richard Hughes, Dmitry Kuzkin, George Hazan" diff --git a/plugins/Dbx_mmap_SA/Import_SA/src/wizard.cpp b/plugins/Dbx_mmap_SA/Import_SA/src/wizard.cpp new file mode 100644 index 0000000000..0584cba073 --- /dev/null +++ b/plugins/Dbx_mmap_SA/Import_SA/src/wizard.cpp @@ -0,0 +1,215 @@ +/* + +Import plugin for Miranda IM + +Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede + +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 "import.h" + +INT_PTR CALLBACK WizardIntroPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK FinishedPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK MirabilisPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK MirandaPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK ICQserverPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); + +extern HINSTANCE hInst; +BOOL IsProtocolLoaded(char* pszProtocolName); +BOOL EnumICQAccounts(); +void FreeICQAccountsList(); + +INT_PTR CALLBACK ImportTypePageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch( message ) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + CheckDlgButton(hdlg, IDC_MIRANDA, BST_CHECKED); + + // Disable Mirabilis import if ICQ isn't loaded. + if (!EnumICQAccounts()) + EnableWindow(GetDlgItem(hdlg, IDC_MIRABILIS), FALSE); + + return TRUE; + + case WM_COMMAND: + switch( LOWORD( wParam )) { + case IDC_BACK: + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_WIZARDINTRO, (LPARAM)WizardIntroPageProc); + break; + + case IDOK: + if (IsDlgButtonChecked(hdlg, IDC_MIRANDA)) + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRANDADB, (LPARAM)MirandaPageProc); + else if (IsDlgButtonChecked(hdlg, IDC_MIRABILIS)) + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRABILISDB, (LPARAM)MirabilisPageProc); + else if (IsDlgButtonChecked(hdlg, IDC_USEFINDADD)) { + CallService(MS_FINDADD_FINDADD, 0, 0); + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_FINISHED, (LPARAM)FinishedPageProc); + } + break; + + case IDCANCEL: + PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); + break; + } } + + return FALSE; +} + +INT_PTR CALLBACK WizardIntroPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch( message ) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 0, 0); + return TRUE; + + case WM_COMMAND: + switch( LOWORD( wParam )) { + case IDOK: + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_IMPORTTYPE, (LPARAM)ImportTypePageProc); + break; + + case IDCANCEL: + PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); + break; + } } + + return FALSE; +} + +INT_PTR CALLBACK FinishedPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch( message ) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 0, 0); + SendMessage(GetParent(hdlg), WIZM_SETCANCELTEXT, 0, (LPARAM)TranslateT("Finish")); + CheckDlgButton(hdlg, IDC_DONTLOADPLUGIN, BST_UNCHECKED); + return TRUE; + + case WM_COMMAND: + switch( LOWORD( wParam )) { + case IDOK: + PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_IMPORTTYPE, (LPARAM)ImportTypePageProc); + break; + + case IDCANCEL: + if ( IsDlgButtonChecked( hdlg, IDC_DONTLOADPLUGIN )) { + char sModuleFileName[MAX_PATH]; + char *pszFileName; + + GetModuleFileNameA(hInst, sModuleFileName, sizeof(sModuleFileName)); + pszFileName = strrchr(sModuleFileName, '\\' ); + if (pszFileName == NULL) + pszFileName = sModuleFileName; + else + pszFileName++; + + // We must lower case here because if a DLL is loaded in two + // processes, its file name from GetModuleFileName in one process may + // differ in case from its file name in the other process. This will + // prevent the plugin from disabling/enabling correctly (this fix relies + // on the plugin loader to ignore case) + CharLowerA(pszFileName); + DBWriteContactSettingByte(NULL, "PluginDisable", pszFileName, 1); + } + PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); + break; + } + break; + } + + return FALSE; +} + +INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) +{ + static HWND hwndPage; + + switch ( message ) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + hwndPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_WIZARDINTRO), hdlg, WizardIntroPageProc); + SetWindowPos(hwndPage, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE); + ShowWindow(hwndPage, SW_SHOW); + ShowWindow(hdlg, SW_SHOW); + SendMessage(hdlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_IMPORT))); + return TRUE; + + case WIZM_GOTOPAGE: + DestroyWindow(hwndPage); + EnableWindow(GetDlgItem(hdlg, IDC_BACK), TRUE); + EnableWindow(GetDlgItem(hdlg, IDOK), TRUE); + EnableWindow(GetDlgItem(hdlg, IDCANCEL), TRUE); + SetDlgItemText(hdlg, IDCANCEL, TranslateT("Cancel")); + hwndPage = CreateDialog(hInst, MAKEINTRESOURCE(wParam), hdlg, (DLGPROC)lParam); + SetWindowPos(hwndPage, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE); + ShowWindow(hwndPage, SW_SHOW); + break; + + case WIZM_DISABLEBUTTON: + switch ( wParam ) { + case 0: + EnableWindow(GetDlgItem(hdlg, IDC_BACK), FALSE); + break; + + case 1: + EnableWindow(GetDlgItem(hdlg, IDOK), FALSE); + break; + + case 2: + EnableWindow(GetDlgItem(hdlg, IDCANCEL), FALSE); + break; + } + break; + + case WIZM_ENABLEBUTTON: + switch ( wParam ) { + case 0: + EnableWindow(GetDlgItem(hdlg, IDC_BACK), TRUE); + break; + + case 1: + EnableWindow(GetDlgItem(hdlg, IDOK), TRUE); + break; + + case 2: + EnableWindow(GetDlgItem(hdlg, IDCANCEL), TRUE); + break; + } + break; + + case WIZM_SETCANCELTEXT: + SetDlgItemText(hdlg, IDCANCEL, (TCHAR*)lParam); + break; + + case WM_COMMAND: + SendMessage(hwndPage, WM_COMMAND, wParam, lParam); + break; + + case WM_CLOSE: + DestroyWindow(hwndPage); + DestroyWindow(hdlg); + + FreeICQAccountsList(); + break; + } + + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/Import_SA/version.h b/plugins/Dbx_mmap_SA/Import_SA/version.h deleted file mode 100644 index 8c2338d9f4..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/version.h +++ /dev/null @@ -1,14 +0,0 @@ -#include - -#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION -#define __VERSION_STRING MIRANDA_VERSION_STRING -#define __VERSION_DWORD MIRANDA_VERSION_DWORD -#define __PLUGIN_NAME "Import secured contacts and messages " -#define __INTERNAL_NAME "Import_sa" -#define __FILENAME "Import_sa.dll" -#define __DESCRIPTION "Imports contacts and messages from Mirabilis ICQ and Miranda IM. Enhanced modification with encrypted database support." -#define __DESCRIPTIONSHORT "Miranda IM Secured Import Plugin." -#define __AUTHOR "Miranda team" -#define __AUTHOREMAIL "info@miranda-im.org" -#define __AUTHORWEB "http://nightly.miranda.im/" -#define __COPYRIGHT "© 2000-2011 Martin Oberg, Richard Hughes, Dmitry Kuzkin, George Hazan" diff --git a/plugins/Dbx_mmap_SA/Import_SA/wizard.cpp b/plugins/Dbx_mmap_SA/Import_SA/wizard.cpp deleted file mode 100644 index 0584cba073..0000000000 --- a/plugins/Dbx_mmap_SA/Import_SA/wizard.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - -Import plugin for Miranda IM - -Copyright (C) 2001-2005 Martin Öberg, Richard Hughes, Roland Rabien & Tristan Van de Vreede - -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 "import.h" - -INT_PTR CALLBACK WizardIntroPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK FinishedPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK MirabilisPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK MirandaPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK ICQserverPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam); - -extern HINSTANCE hInst; -BOOL IsProtocolLoaded(char* pszProtocolName); -BOOL EnumICQAccounts(); -void FreeICQAccountsList(); - -INT_PTR CALLBACK ImportTypePageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch( message ) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - CheckDlgButton(hdlg, IDC_MIRANDA, BST_CHECKED); - - // Disable Mirabilis import if ICQ isn't loaded. - if (!EnumICQAccounts()) - EnableWindow(GetDlgItem(hdlg, IDC_MIRABILIS), FALSE); - - return TRUE; - - case WM_COMMAND: - switch( LOWORD( wParam )) { - case IDC_BACK: - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_WIZARDINTRO, (LPARAM)WizardIntroPageProc); - break; - - case IDOK: - if (IsDlgButtonChecked(hdlg, IDC_MIRANDA)) - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRANDADB, (LPARAM)MirandaPageProc); - else if (IsDlgButtonChecked(hdlg, IDC_MIRABILIS)) - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_MIRABILISDB, (LPARAM)MirabilisPageProc); - else if (IsDlgButtonChecked(hdlg, IDC_USEFINDADD)) { - CallService(MS_FINDADD_FINDADD, 0, 0); - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_FINISHED, (LPARAM)FinishedPageProc); - } - break; - - case IDCANCEL: - PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); - break; - } } - - return FALSE; -} - -INT_PTR CALLBACK WizardIntroPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch( message ) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 0, 0); - return TRUE; - - case WM_COMMAND: - switch( LOWORD( wParam )) { - case IDOK: - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_IMPORTTYPE, (LPARAM)ImportTypePageProc); - break; - - case IDCANCEL: - PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); - break; - } } - - return FALSE; -} - -INT_PTR CALLBACK FinishedPageProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch( message ) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - SendMessage(GetParent(hdlg), WIZM_DISABLEBUTTON, 0, 0); - SendMessage(GetParent(hdlg), WIZM_SETCANCELTEXT, 0, (LPARAM)TranslateT("Finish")); - CheckDlgButton(hdlg, IDC_DONTLOADPLUGIN, BST_UNCHECKED); - return TRUE; - - case WM_COMMAND: - switch( LOWORD( wParam )) { - case IDOK: - PostMessage(GetParent(hdlg), WIZM_GOTOPAGE, IDD_IMPORTTYPE, (LPARAM)ImportTypePageProc); - break; - - case IDCANCEL: - if ( IsDlgButtonChecked( hdlg, IDC_DONTLOADPLUGIN )) { - char sModuleFileName[MAX_PATH]; - char *pszFileName; - - GetModuleFileNameA(hInst, sModuleFileName, sizeof(sModuleFileName)); - pszFileName = strrchr(sModuleFileName, '\\' ); - if (pszFileName == NULL) - pszFileName = sModuleFileName; - else - pszFileName++; - - // We must lower case here because if a DLL is loaded in two - // processes, its file name from GetModuleFileName in one process may - // differ in case from its file name in the other process. This will - // prevent the plugin from disabling/enabling correctly (this fix relies - // on the plugin loader to ignore case) - CharLowerA(pszFileName); - DBWriteContactSettingByte(NULL, "PluginDisable", pszFileName, 1); - } - PostMessage(GetParent(hdlg), WM_CLOSE, 0, 0); - break; - } - break; - } - - return FALSE; -} - -INT_PTR CALLBACK WizardDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static HWND hwndPage; - - switch ( message ) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - hwndPage = CreateDialog(hInst, MAKEINTRESOURCE(IDD_WIZARDINTRO), hdlg, WizardIntroPageProc); - SetWindowPos(hwndPage, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE); - ShowWindow(hwndPage, SW_SHOW); - ShowWindow(hdlg, SW_SHOW); - SendMessage(hdlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_IMPORT))); - return TRUE; - - case WIZM_GOTOPAGE: - DestroyWindow(hwndPage); - EnableWindow(GetDlgItem(hdlg, IDC_BACK), TRUE); - EnableWindow(GetDlgItem(hdlg, IDOK), TRUE); - EnableWindow(GetDlgItem(hdlg, IDCANCEL), TRUE); - SetDlgItemText(hdlg, IDCANCEL, TranslateT("Cancel")); - hwndPage = CreateDialog(hInst, MAKEINTRESOURCE(wParam), hdlg, (DLGPROC)lParam); - SetWindowPos(hwndPage, 0, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOSIZE); - ShowWindow(hwndPage, SW_SHOW); - break; - - case WIZM_DISABLEBUTTON: - switch ( wParam ) { - case 0: - EnableWindow(GetDlgItem(hdlg, IDC_BACK), FALSE); - break; - - case 1: - EnableWindow(GetDlgItem(hdlg, IDOK), FALSE); - break; - - case 2: - EnableWindow(GetDlgItem(hdlg, IDCANCEL), FALSE); - break; - } - break; - - case WIZM_ENABLEBUTTON: - switch ( wParam ) { - case 0: - EnableWindow(GetDlgItem(hdlg, IDC_BACK), TRUE); - break; - - case 1: - EnableWindow(GetDlgItem(hdlg, IDOK), TRUE); - break; - - case 2: - EnableWindow(GetDlgItem(hdlg, IDCANCEL), TRUE); - break; - } - break; - - case WIZM_SETCANCELTEXT: - SetDlgItemText(hdlg, IDCANCEL, (TCHAR*)lParam); - break; - - case WM_COMMAND: - SendMessage(hwndPage, WM_COMMAND, wParam, lParam); - break; - - case WM_CLOSE: - DestroyWindow(hwndPage); - DestroyWindow(hdlg); - - FreeICQAccountsList(); - break; - } - - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/commonheaders.h b/plugins/Dbx_mmap_SA/commonheaders.h deleted file mode 100644 index a098644dad..0000000000 --- a/plugins/Dbx_mmap_SA/commonheaders.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - -Miranda IM: the free IM client for Microsoft* Windows* - -Copyright 2000-2003 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 _WIN32_WINNT 0x0501 -#include "m_stdhdr.h" - -//windows headers - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//miranda headers -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//non-official miranda-plugins sdk -#include "m_folders.h" - -//own headers -#include "dbintf_sa.h" -#include "..\Db3x_mmap\database.h" -#include "resource.h" -#include "version.h" - -extern HINSTANCE g_hInst; -extern HANDLE hSetPwdMenu; - -#ifdef __GNUC__ -#define mir_i64(x) (x##LL) -#else -#define mir_i64(x) (x##i64) -#endif - -//global procedures -//int InitSkin(); -void EncodeCopyMemory(void * dst, void * src, size_t size ); -void DecodeCopyMemory(void * dst, void * src, size_t size ); -void EncodeDBWrite(DWORD ofs, void * src, size_t size); -void DecodeDBWrite(DWORD ofs, void * src, size_t size); - -BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam); -BOOL CALLBACK DlgStdNewPass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam); -BOOL CALLBACK DlgChangePass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam); -void xModifyMenu(HANDLE hMenu,long flags,const TCHAR* name, HICON hIcon); - -extern DBSignature dbSignature, dbSignatureSecured; - -extern LIST g_Dbs; - -int InitPreset(); -void UninitPreset(); - -typedef struct{ - void* (__stdcall *GenerateKey)(char* pwd); - void (__stdcall *FreeKey)(void* key); - void (__stdcall *EncryptMem)(BYTE* data, int size, void* key); - void (__stdcall *DecryptMem)(BYTE* data, int size, void* key); - - char* Name; - char* Info; - char* Author; - char* Site; - char* Email; - - DWORD Version; - - WORD uid; -} Cryptor; - -typedef struct{ - TCHAR dllname[MAX_PATH]; - HMODULE hLib; - Cryptor* cryptor; -} CryptoModule; - -extern Cryptor* CryptoEngine; -extern void* key; diff --git a/plugins/Dbx_mmap_SA/db3x_mmap.rc b/plugins/Dbx_mmap_SA/db3x_mmap.rc deleted file mode 100644 index 60d38275d8..0000000000 --- a/plugins/Dbx_mmap_SA/db3x_mmap.rc +++ /dev/null @@ -1,275 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Ðóññêèé (Ðîññèÿ) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT -#pragma code_page(1251) - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_LOGIN DIALOGEX 0, 0, 190, 86 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW -CAPTION "Login to Miranda IM" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "EN",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_USERPASS,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL | WS_GROUP - DEFPUSHBUTTON "OK",IDOK,36,64,50,14 - PUSHBUTTON "Cancel",IDCANCEL,102,64,50,14 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,55,190,1 -END - -IDD_NEWPASS DIALOGEX 0, 0, 190, 102 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW -CAPTION "New password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "EN",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_USERPASS1,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_USERPASS2,21,54,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "OK",IDOK,36,84,50,14 - PUSHBUTTON "Cancel",IDCANCEL,100,84,50,14 - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,77,190,1 -END - -IDD_CHANGEPASS DIALOGEX 0, 0, 190, 148 -STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_TOOLWINDOW -CAPTION "Change password" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 - CTEXT "EN",IDC_LANG,158,42,13,13,SS_CENTERIMAGE | NOT WS_GROUP - EDITTEXT IDC_OLDPASS,21,42,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_NEWPASS1,21,77,128,14,ES_PASSWORD | ES_AUTOHSCROLL - EDITTEXT IDC_NEWPASS2,21,98,128,14,ES_PASSWORD | ES_AUTOHSCROLL - DEFPUSHBUTTON "Change",IDOK,11,127,50,14 - PUSHBUTTON "Remove",IDREMOVE,69,127,50,14 - PUSHBUTTON "Cancel",IDCANCEL,126,127,50,14 - LTEXT "New password",IDC_NEWPASSINFO,11,66,163,10,0,WS_EX_TRANSPARENT - CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,119,190,1 - LTEXT "Old password",IDC_NEWPASSINFO2,11,31,140,10,0,WS_EX_TRANSPARENT -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_CHANGEPASS, DIALOG - BEGIN - TOPMARGIN, 7 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_ICON2 ICON "icos\\logo.ico" -IDI_ICON3 ICON "icos\\pass.ico" -#endif // Ðóññêèé (Ðîññèÿ) resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// Àíãëèéñêèé (ÑØÀ) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_INSTALLINI DIALOGEX 0, 0, 212, 102 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT -CAPTION "Install Database Settings" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - DEFPUSHBUTTON "Yes",IDOK,26,83,50,14 - PUSHBUTTON "No",IDCANCEL,81,83,50,14 - LTEXT "A file containing new database settings has been placed in the Miranda IM directory.",IDC_STATIC,5,5,202,16 - LTEXT "Do you want to import the settings now?",IDC_STATIC,5,69,202,8 - PUSHBUTTON "No to all",IDC_NOTOALL,136,83,50,14 - LTEXT "",IDC_ININAME,5,24,143,16,SS_NOPREFIX | SS_CENTERIMAGE - PUSHBUTTON "&View contents",IDC_VIEWINI,149,25,58,14 - LTEXT "Security systems to prevent malicious changes are in place and you will be warned before changes that are not known to be safe.",IDC_SECURITYINFO,5,43,202,24 -END - -IDD_WARNINICHANGE DIALOGEX 0, 0, 187, 113 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT -CAPTION "Database Setting Change" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Database settings are being imported from",IDC_STATIC,5,5,177,8 - CONTROL "",IDC_ININAME,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,5,13,177,8 - LTEXT "This file wishes to change the setting",IDC_STATIC,5,24,177,8 - CONTROL "",IDC_SETTINGNAME,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,12,33,170,8 - LTEXT "to the value",IDC_STATIC,5,42,177,8 - CONTROL "",IDC_NEWVALUE,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,12,51,170,8 - LTEXT "",IDC_SECURITYINFO,5,60,177,8 - LTEXT "Do you want to allow this change?",IDC_STATIC,5,71,177,8 - CONTROL "&Allow all further changes to this section",IDC_WARNNOMORE, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,80,169,10 - DEFPUSHBUTTON "&Yes",IDYES,5,94,50,14 - PUSHBUTTON "&No",IDNO,59,94,50,14 - PUSHBUTTON "Cancel Import",IDCANCEL,123,94,59,14 -END - -IDD_INIIMPORTDONE DIALOGEX 0, 0, 186, 73 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT -CAPTION "Database Import Complete" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "The import has completed from",IDC_STATIC,5,5,176,8 - CONTROL "",IDC_ININAME,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,5,13,176,8 - LTEXT "What do you want to do with the file now?",IDC_STATIC,5,24,176,8 - PUSHBUTTON "&Recycle",IDC_RECYCLE,5,36,50,14 - PUSHBUTTON "&Delete",IDC_DELETE,68,36,50,14 - EDITTEXT IDC_NEWNAME,5,55,117,12,ES_AUTOHSCROLL - PUSHBUTTON "&Move/Rename",IDC_MOVE,124,54,57,14 - PUSHBUTTON "&Leave",IDC_LEAVE,131,36,50,14 -END - -IDD_OPTIONS DIALOGEX 0, 0, 318, 188 -STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_CHILD -FONT 8, "MS Shell Dlg", 0, 0, 0x0 -BEGIN - GROUPBOX "Database encryption",IDC_ENC,4,87,307,96,0,WS_EX_RIGHT - CONTROL "",IDC_MODULES,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,6,3,305,80 - LTEXT "Info:",IDC_STATIC,9,97,35,8,0,WS_EX_RIGHT - EDITTEXT IDC_INFO,49,97,256,21,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | ES_WANTRETURN | NOT WS_BORDER | WS_VSCROLL - LTEXT "Author:",IDC_STATIC,9,123,35,8,0,WS_EX_RIGHT - EDITTEXT IDC_AUTHOR,49,123,256,12,ES_AUTOHSCROLL | ES_READONLY | ES_WANTRETURN | NOT WS_BORDER - LTEXT "Site:",IDC_STATIC,9,135,35,8,0,WS_EX_RIGHT - CONTROL "",IDC_SITE,"Hyperlink",WS_TABSTOP,49,135,256,12 - LTEXT "Email:",IDC_STATIC,9,147,35,8,0,WS_EX_RIGHT - CONTROL "",IDC_EMAIL,"Hyperlink",WS_TABSTOP,49,147,256,12 - LTEXT "Unique ID:",IDC_STATIC,9,166,35,8,0,WS_EX_RIGHT - EDITTEXT IDC_UID,49,166,256,12,ES_AUTOHSCROLL | ES_READONLY | ES_WANTRETURN | NOT WS_BORDER -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_INSTALLINI, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 207 - TOPMARGIN, 5 - BOTTOMMARGIN, 97 - END - - IDD_WARNINICHANGE, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 182 - TOPMARGIN, 5 - BOTTOMMARGIN, 108 - END - - IDD_INIIMPORTDONE, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 181 - TOPMARGIN, 5 - BOTTOMMARGIN, 68 - END - - IDD_OPTIONS, DIALOG - BEGIN - LEFTMARGIN, 6 - RIGHTMARGIN, 311 - VERTGUIDE, 9 - VERTGUIDE, 44 - VERTGUIDE, 49 - VERTGUIDE, 193 - VERTGUIDE, 248 - VERTGUIDE, 305 - TOPMARGIN, 7 - BOTTOMMARGIN, 181 - END -END -#endif // APSTUDIO_INVOKED - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include \0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -#endif // Àíãëèéñêèé (ÑØÀ) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj index 725dd669e7..096c15d901 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj @@ -81,7 +81,6 @@ commonheaders.h Level3 EditAndContinue - 4996;%(DisableSpecificWarnings) false @@ -109,7 +108,6 @@ Use commonheaders.h Level3 - 4996;%(DisableSpecificWarnings) false @@ -139,7 +137,6 @@ Use commonheaders.h Level3 - 4996;%(DisableSpecificWarnings) NDEBUG;%(PreprocessorDefinitions) @@ -170,7 +167,6 @@ Use commonheaders.h Level3 - 4996;%(DisableSpecificWarnings) NDEBUG;%(PreprocessorDefinitions) @@ -189,37 +185,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + Create - + - - - - - - + + + + + + - - - - - - + + diff --git a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters index 84aae9636b..f7ebe6ae7e 100644 --- a/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters +++ b/plugins/Dbx_mmap_SA/db3x_mmap_sa_10.vcxproj.filters @@ -18,80 +18,72 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Mmap files - + Mmap files - + Mmap files - + Mmap files - + Mmap files - + Source Files - + Mmap files - + Mmap files - + Mmap files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Mmap files - + Resource Files - + Resource Files - - - Resource Files - - - Resource Files - - \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/dbintf_sa.cpp b/plugins/Dbx_mmap_SA/dbintf_sa.cpp deleted file mode 100644 index b85b3481cb..0000000000 --- a/plugins/Dbx_mmap_SA/dbintf_sa.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright 2012 Miranda NG 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 NeedBytes(n) if(bytesRemaining<(n)) pBlob=(PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining) -#define MoveAlong(n) {int x=n; pBlob+=(x); ofsBlobPtr+=(x); bytesRemaining-=(x);} -#define VLT(n) ((n==DBVT_UTF8)?DBVT_ASCIIZ:n) - -extern CDdxMmapSA* g_Db; - -int InitDialogs(void); - -DBSignature dbSignatureSecured = {"Miranda ICQ SD",0x1A}; - -CDdxMmapSA::CDdxMmapSA(const TCHAR* tszFileName) : - CDdxMmap(tszFileName) -{ -} - -int CDdxMmapSA::Load(bool bSkipInit) -{ - if ( CDdxMmap::Load(bSkipInit) != ERROR_SUCCESS) - return 1; - - if ( CheckDbHeaders()) - return 1; - - if (!bSkipInit) { - TCHAR* p = _tcsrchr(m_tszProfileName, '\\'); - if (!p) - return 1; - - g_Db = this; - if (m_bEncoding && !CheckPassword( LOWORD(m_dbHeader.version), p+1)) - return 1; - - InitDialogs(); - } - - return 0; -} - -int CDdxMmapSA::CheckDbHeaders() -{ - if ( memcmp(m_dbHeader.signature, &dbSignatureSecured, sizeof(m_dbHeader.signature)) == 0) - m_bEncoding = true; - else { - m_bEncoding = false; - if ( memcmp(m_dbHeader.signature,&dbSignature,sizeof(m_dbHeader.signature))) - return 1; - if ( LOWORD(m_dbHeader.version) != 0x0700) - return 2; - } - if (m_dbHeader.ofsUser == 0) - return 3; - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// - -static DWORD __inline GetSettingValueLength(PBYTE pSetting) -{ - if(pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1); - return pSetting[0]; -} - -void CDdxMmapSA::EncodeContactSettings(HANDLE hContact) -{ - if (!hContact) - hContact = (HANDLE)m_dbHeader.ofsUser; - - DBContact *contact = (DBContact *)DBRead((DWORD)hContact, sizeof(DBContact), NULL); - if (contact->ofsFirstSettings) { - DBContactSettings *setting = (struct DBContactSettings *)DBRead(contact->ofsFirstSettings, sizeof(struct DBContactSettings), NULL); - DWORD offset = contact->ofsFirstSettings; - while( true ) { - DWORD ofsBlobPtr; - PBYTE pBlob; - int bytesRemaining; - DWORD len; - - ofsBlobPtr = offset + offsetof(struct DBContactSettings,blob); - pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); - while(pBlob[0]) { - NeedBytes(1); - NeedBytes(1+pBlob[0]); - MoveAlong(1+pBlob[0]); - - NeedBytes(5); - - switch(pBlob[0]) { - case DBVT_DELETED: break; - case DBVT_BYTE: break; - case DBVT_WORD: - CryptoEngine->EncryptMem(pBlob+1, 2, key); - break; - - case DBVT_DWORD: - CryptoEngine->EncryptMem(pBlob+1, 4, key); - break; - - case DBVT_UTF8: - case DBVT_ASCIIZ: - case DBVT_BLOB: - NeedBytes(3+*(PWORD)(pBlob+1)); - len = *(PWORD)(pBlob+1); - - CryptoEngine->EncryptMem(pBlob+3, len, key); - break; - } - NeedBytes(3); - MoveAlong(1+GetSettingValueLength(pBlob)); - NeedBytes(1); - } - - if (!setting->ofsNext) - break; - - offset = setting->ofsNext; - setting = (struct DBContactSettings *)DBRead(setting->ofsNext, sizeof(struct DBContactSettings), NULL); - } - } -} - -void CDdxMmapSA::DecodeContactSettings(HANDLE hContact) -{ - if (!hContact) - hContact = (HANDLE)m_dbHeader.ofsUser; - - DBContact *contact = (DBContact *)DBRead((DWORD)hContact, sizeof(DBContact), NULL); - if (contact->ofsFirstSettings){ - DBContactSettings *setting = (struct DBContactSettings *)DBRead(contact->ofsFirstSettings, sizeof(struct DBContactSettings), NULL); - DWORD offset = contact->ofsFirstSettings; - while (true) { - DWORD ofsBlobPtr; - PBYTE pBlob; - int bytesRemaining; - DWORD len; - ofsBlobPtr = offset + offsetof(struct DBContactSettings,blob); - pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); - while(pBlob[0]) { - NeedBytes(1); - NeedBytes(1+pBlob[0]); - //CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]] = 0; - MoveAlong(1+pBlob[0]); - - NeedBytes(5); - - switch(pBlob[0]) { - case DBVT_DELETED: break; - case DBVT_BYTE: break; - case DBVT_WORD: - CryptoEngine->DecryptMem(pBlob+1, 2, key); - break; - - case DBVT_DWORD: - CryptoEngine->DecryptMem(pBlob+1, 4, key); - break; - - case DBVT_UTF8: - case DBVT_ASCIIZ: - case DBVT_BLOB: - NeedBytes(3+*(PWORD)(pBlob+1)); - len = *(PWORD)(pBlob+1); - - CryptoEngine->DecryptMem(pBlob+3, len, key); - break; - } - NeedBytes(3); - MoveAlong(1+GetSettingValueLength(pBlob)); - NeedBytes(1); - } - - if (!setting->ofsNext) - break; - - offset = setting->ofsNext; - setting = (struct DBContactSettings *)DBRead(setting->ofsNext, sizeof(struct DBContactSettings), NULL); - } - } -} - -void CDdxMmapSA::EncodeEvent(HANDLE hEvent) -{ - DBEvent *dbe = (DBEvent*)DBRead((DWORD)hEvent,sizeof(DBEvent),NULL); - if (dbe->signature = DBEVENT_SIGNATURE) - CryptoEngine->EncryptMem(DBRead((DWORD)hEvent + offsetof(DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key); -} - -void CDdxMmapSA::DecodeEvent(HANDLE hEvent) -{ - DBEvent *dbe = (DBEvent*)DBRead((DWORD)hEvent,sizeof(DBEvent),NULL); - if (dbe->signature = DBEVENT_SIGNATURE) - CryptoEngine->DecryptMem(DBRead((DWORD)hEvent + offsetof(DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key); -} - -void CDdxMmapSA::EncodeContactEvents(HANDLE hContact) -{ - HANDLE hEvent = FindFirstEvent(hContact); - while (hEvent != 0) { - EncodeEvent(hEvent); - hEvent = FindNextEvent(hEvent); - } -} - -void CDdxMmapSA::DecodeContactEvents(HANDLE hContact) -{ - HANDLE hEvent = FindFirstEvent(hContact); - while (hEvent != 0) { - DecodeEvent(hEvent); - hEvent = FindNextEvent(hEvent); - } -} diff --git a/plugins/Dbx_mmap_SA/dbintf_sa.h b/plugins/Dbx_mmap_SA/dbintf_sa.h deleted file mode 100644 index 265d2a32e0..0000000000 --- a/plugins/Dbx_mmap_SA/dbintf_sa.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright 2012 Miranda NG 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 - -#include "..\Db3x_mmap\dbintf.h" - -struct CDdxMmapSA : public CDdxMmap -{ - CDdxMmapSA(const TCHAR* tszFileName); - - int CheckPassword(WORD checkWord, TCHAR *szDBName); - int CheckDbHeaders(void); - - void ChangePwd(); - void EncryptDB(); - void DecryptDB(); - void RecryptDB(); - - int Load(bool bSkipInit); - - bool m_bEncoding, bEncProcess; - -protected: - virtual void EncodeCopyMemory(void *dst, void *src, size_t size); - virtual void DecodeCopyMemory(void *dst, void *src, size_t size); - virtual void EncodeDBWrite(DWORD ofs, void *src, int size); - virtual void DecodeDBWrite(DWORD ofs, void *src, int size); - -protected: - int CheckProto(HANDLE hContact, const char *proto); - - void EncoderInit(); - void EncodeContactEvents(HANDLE hContact); - void EncodeEvent(HANDLE hEvent); - void DecodeEvent(HANDLE hEvent); - void DecodeContactEvents(HANDLE hContact); - - void DecodeContactSettings(HANDLE hContact); - void EncodeContactSettings(HANDLE hContact); - - void WritePlainHeader(); - void WriteCryptHeader(); - - void EncodeAll(); - void DecodeAll(); - -public: - char encryptKey[255]; - size_t encryptKeyLength; -}; diff --git a/plugins/Dbx_mmap_SA/dbpreset.cpp b/plugins/Dbx_mmap_SA/dbpreset.cpp deleted file mode 100644 index 564bbf3c40..0000000000 --- a/plugins/Dbx_mmap_SA/dbpreset.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/* - -Miranda IM: the free IM client for Microsoft* Windows* - -Copyright 2000-2003 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. -*/ -// Miranda Memory-Mapped Secured DataBase -// (C) Artem Shpynov aka FYR, Igonin Vitaliy aka chaos.persei, Victor Pavlychko aka nullbie, 2007 - 2008 - -#include "commonheaders.h" - -/* Public API */ -int DBPreset_QuerySetting (const char *szModule, const char *szSetting, DBVARIANT *dbv, BOOL isStatic); -int DBPreset_CompareSetting (const char *szModule, const char *szSetting, DBVARIANT *dbv); - -/* Preset cache item */ -typedef struct -{ - DWORD dwHash; - char *szModule; - char *szSetting; - DBVARIANT dbv; -} DBPresetItem; - -static DBPresetItem * DBPresetItem_Create (char *szModule, char *szSetting, BYTE bType); -static void DBPresetItem_Destroy (DBPresetItem *item); -static void DBPresetItem_Hash (DBPresetItem *item); -static int DBPresetItem_Cmp (DBPresetItem *item1, DBPresetItem *item2); - -SortedList *lstPresets = NULL; - -int InitPreset() -{ - char szIniPath[MAX_PATH]; - char szLine[2048]; - int lineLength; - char szSection[128]; - FILE *fp; - - GetModuleFileNameA(GetModuleHandle(NULL), szIniPath, SIZEOF(szIniPath)); - strcpy(strrchr(szIniPath, '\\')+1, "dbpreset.ini"); - - fp = fopen(szIniPath,"rt"); - - // no preset - if (!fp) return 0; - - lstPresets = List_Create(0, 50); - lstPresets->sortFunc = (FSortFunc)DBPresetItem_Cmp; - - while(!feof(fp)) - { - if (fgets(szLine,sizeof(szLine),fp) == NULL) break; - lineLength = lstrlenA(szLine); - while(lineLength && (BYTE)(szLine[lineLength-1]) <= ' ') szLine[--lineLength] = '\0'; - if (szLine[0] == ';' || szLine[0] <= ' ') continue; - if (szLine[0] == '[') - { - char *szEnd = strchr(szLine+1,']'); - if (szEnd == NULL) continue; - if (szLine[1] == '!') - szSection[0] = '\0'; - else - lstrcpynA(szSection, szLine+1, (int)min(sizeof(szSection), szEnd-szLine)); - } else - { - char *szValue; - char szName[128]; - DBPresetItem *item; - - if (szSection[0] == '\0') continue; - szValue = strchr(szLine,' = '); - if (szValue == NULL) continue; - lstrcpynA(szName, szLine, (int)min(sizeof(szName), szValue-szLine+1)); - szValue++; - - switch(szValue[0]) - { - case 'b': - case 'B': - item = DBPresetItem_Create(szSection, szName, DBVT_BYTE); - item->dbv.bVal = (BYTE)strtol(szValue+1,NULL,0); - List_InsertPtr(lstPresets, item); - break; - case 'w': - case 'W': - item = DBPresetItem_Create(szSection, szName, DBVT_WORD); - item->dbv.wVal = (WORD)strtol(szValue+1,NULL,0); - List_InsertPtr(lstPresets, item); - break; - case 'd': - case 'D': - item = DBPresetItem_Create(szSection, szName, DBVT_DWORD); - item->dbv.dVal = (DWORD)strtoul(szValue+1,NULL,0); - List_InsertPtr(lstPresets, item); - break; - case 's': - case 'S': - item = DBPresetItem_Create(szSection, szName, DBVT_ASCIIZ); - item->dbv.pszVal = mir_strdup(szValue+1); - List_InsertPtr(lstPresets, item); - break; - case 'u': - case 'U': - item = DBPresetItem_Create(szSection, szName, DBVT_UTF8); - item->dbv.pszVal = mir_strdup(szValue+1); - List_InsertPtr(lstPresets, item); - break; - case 'n': - case 'N': - { - PBYTE buf; - int len; - char *pszValue,*pszEnd; - - buf = (PBYTE)mir_alloc(lstrlenA(szValue+1)); - for (len = 0,pszValue = szValue+1;;len++) { - buf[len] = (BYTE)strtol(pszValue,&pszEnd,0x10); - if (pszValue == pszEnd) break; - pszValue = pszEnd; - } - - item = DBPresetItem_Create(szSection, szName, DBVT_BLOB); - item->dbv.pbVal = buf; - item->dbv.cpbVal = len; - List_InsertPtr(lstPresets, item); - break; - } - } - } - } - fclose(fp); - - return 0; -} - -void UninitPreset() -{ - int i; - if (!lstPresets) return; - for (i = 0; i < lstPresets->realCount; ++i) - DBPresetItem_Destroy((DBPresetItem *)lstPresets->items[i]); - List_Destroy(lstPresets); -} - -int DBPreset_QuerySetting(const char *szModule, const char *szSetting, DBVARIANT *dbv, BOOL isStatic) -{ - DBPresetItem *item; - DBPresetItem search = {0}; - - if (!lstPresets) return FALSE; - - search.szModule = (char *)szModule; - search.szSetting = (char *)szSetting; - DBPresetItem_Hash(&search); - item = (DBPresetItem *)List_Find(lstPresets, &search); - - if (!item) return FALSE; - - dbv->type = item->dbv.type; - switch (item->dbv.type) - { - case DBVT_BYTE: dbv->bVal = item->dbv.bVal; return TRUE; - case DBVT_WORD: dbv->wVal = item->dbv.wVal; return TRUE; - case DBVT_DWORD: dbv->dVal = item->dbv.dVal; return TRUE; - - case DBVT_UTF8: - case DBVT_ASCIIZ: - if (isStatic && dbv->pszVal) - lstrcpynA(dbv->pszVal, item->dbv.pszVal, dbv->cchVal); - else if (!isStatic) - dbv->pszVal = mir_strdup(item->dbv.pszVal); - return TRUE; - - default: - return FALSE; - } - - return FALSE; -} - -int DBPreset_CompareSetting(const char *szModule, const char *szSetting, DBVARIANT *dbv) -{ - DBPresetItem *item; - DBPresetItem search = {0}; - - if (!lstPresets) return FALSE; - - search.szModule = (char *)szModule; - search.szSetting = (char *)szSetting; - DBPresetItem_Hash(&search); - item = (DBPresetItem *)List_Find(lstPresets, &search); - - if (!item) return FALSE; - if (item->dbv.type != item->dbv.type) return FALSE; - switch (item->dbv.type) - { - case DBVT_BYTE: return dbv->bVal == item->dbv.bVal ? TRUE : FALSE; - case DBVT_WORD: return dbv->wVal == item->dbv.wVal ? TRUE : FALSE; - case DBVT_DWORD: return dbv->dVal == item->dbv.dVal ? TRUE : FALSE; - case DBVT_UTF8: - case DBVT_ASCIIZ: return strcmp(dbv->pszVal, item->dbv.pszVal) ? FALSE : TRUE; - } - - return FALSE; -} - -static DBPresetItem *DBPresetItem_Create(char *szModule, char *szSetting, BYTE bType) -{ - DBPresetItem *item = (DBPresetItem *)mir_alloc(sizeof(DBPresetItem)); - item->szModule = mir_strdup(szModule); - item->szSetting = mir_strdup(szSetting); - DBPresetItem_Hash(item); - item->dbv.type = bType; - return item; -} - -static void DBPresetItem_Destroy(DBPresetItem *item) -{ - if (!item) return; - if (item->szModule) - { - mir_free(item->szModule); - item->szModule = NULL; - } - if (item->szSetting) - { - mir_free(item->szSetting); - item->szSetting = NULL; - } - - switch (item->dbv.type) - { - case DBVT_ASCIIZ: - case DBVT_UTF8: - case DBVT_WCHAR: - { - if (item->dbv.pszVal) - mir_free(item->dbv.pszVal); - item->dbv.pszVal = 0; - break; - } - case DBVT_BLOB: - { - if (item->dbv.pbVal) - mir_free(item->dbv.pbVal); - item->dbv.pbVal = 0; - break; - } - } - item->dbv.type = 0; -} - -static void DBPresetItem_Hash(DBPresetItem *item) -{ - int i; - int shift = 0; - item->dwHash = 0; - for (i = 0;item->szModule[i];i++) - { - item->dwHash ^= item->szModule[i]<24) item->dwHash ^= (item->szModule[i]>>(32-shift))&0x7F; - shift = (shift+5)&0x1F; - } - for (i = 0;item->szSetting[i];i++) - { - item->dwHash ^= item->szSetting[i]<24) item->dwHash ^= (item->szSetting[i]>>(32-shift))&0x7F; - shift = (shift+5)&0x1F; - } -} - -static int DBPresetItem_Cmp(DBPresetItem *item1, DBPresetItem *item2) -{ - int cmp; - if (item1->dwHash < item2->dwHash) return -1; - if (item1->dwHash > item2->dwHash) return 1; - if (cmp = strcmp(item1->szModule, item2->szModule)) return cmp; - return strcmp(item1->szSetting, item2->szSetting); -} diff --git a/plugins/Dbx_mmap_SA/dbx_mmap_sa-translation.txt b/plugins/Dbx_mmap_SA/dbx_mmap_sa-translation.txt deleted file mode 100644 index a89cd1b8ea..0000000000 --- a/plugins/Dbx_mmap_SA/dbx_mmap_sa-translation.txt +++ /dev/null @@ -1,383 +0,0 @@ -; Common strings that belong to many files -;[%d crypto modules loaded] -;[&Next >] -;[< &Back] -;[Added %d contacts and %d groups.] -;[All Files] -;[Cancel] -;[Change Password] -;[Change password] -;[Cryptor loaded: %s [%s] (%s)] -;[Database] -;[Database encrypted with %s by %s] -;[Database is Secured MMAP database] -;[EN] -;[Import completed in %d seconds.] -;[Importing groups.] -;[Miranda Database Tool] -;[Miranda MMAP Secured Database] -;[OK] -;[Password is not correct!] -;[Please type in your password for] -;[Progress1] -;[Scanning cryptors directory] -;[Secured MMAP: authorization successful] -;[Sorry, but your database encrypted with unknown module] -;[The given file does not exist. Please check that you have entered the name correctly.] -;[Too many errors!] -;[You are not authorized for access to Database] - -; ../../plugins/Dbx_mmap_SA/Dbtool/aggressive.cpp -;[Aggressive: random junk at %08X: skipping] -;[Aggressive: unlinked data at %08X: can't automatically place] -;[Performing aggressive pass] - -; ../../plugins/Dbx_mmap_SA/Dbtool/contactchain.cpp -;[Contact chain corrupted, further entries ignored] -;[Contact count marked wrongly: correcting] -;[Processing contact chain] - -; ../../plugins/Dbx_mmap_SA/Dbtool/disk.cpp -;[Can't write to output file - disk full? (%u)] -;[Can't write to working file, aggressive mode may be too aggressive now] -;[Error reading, database truncated? (%u)] -;[Invalid offset found] -;[Invalid offset found (database truncated?)] - -; ../../plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp -;[Duplicate event was found: skipping] -;[Event chain corrupted, further entries ignored] -;[Event chain corrupted, trying to recover...] -;[Event count marked wrongly: correcting] -;[Event marked as first which is not: correcting] -;[Event not backlinked correctly: fixing] -;[Event position in chain is not correct] -;[Event position in chain is not correct: fixing] -;[Event position in chain is not correct: unable to fix] -;[Extra flags found in event: removing] -;[First event not marked as such: correcting] -;[First unread event marked wrong: fixing] -;[Infeasibly large event blob: skipping] - -; ../../plugins/Dbx_mmap_SA/Dbtool/finaltasks.cpp -;[%s\\Backup (%d) of %s] -;[%s\\Backup of %s] -;[Errors were encountered, however you selected not to backup the original database. It is strongly recommended that you do so in case important data was omitted. Do you wish to keep a backup of the original database?] -;[Processing final tasks] -;[Unable to delete original file] -;[Unable to rename original file] -;[Unable to rename output file] - -; ../../plugins/Dbx_mmap_SA/Dbtool/finished.cpp -;[&Finish] - -; ../../plugins/Dbx_mmap_SA/Dbtool/initialchecks.cpp -;[ (Output).dat] -;[] -;[Can't create file mapping (%u)] -;[Can't create map view of file (%u)] -;[Can't create output file (%u)] -;[Database is corrupted and too small to contain any recoverable data] -;[Database is marked as belonging to an unknown version of Miranda] -;[Database is newly created and has no data to process] -;[Database signature is corrupted, automatic repair is impossible] -;[Processing completed successfully] -;[your database] - -; ../../plugins/Dbx_mmap_SA/Dbtool/modulechain.cpp -;[Invalid module name offset, skipping data] -;[Module chain corrupted, further entries ignored] -;[Module name '%s' is not unique: %d duplicates found)] -;[Processing module name chain] -;[Unreasonably long module name, skipping] - -; ../../plugins/Dbx_mmap_SA/Dbtool/progress.cpp -;[Click Next to continue] -;[Processing has not yet completed, if you cancel now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to cancel?] -;[Processing has not yet completed, if you go back now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to go back?] - -; ../../plugins/Dbx_mmap_SA/Dbtool/resource.rc -;[&File:] -;[&Other...] -;[Aggressively find corruption] -;[All tasks have been completed.] -;[Backup:] -;[Check consistency only] -;[Cleaning Options] -;[Click Next to try opening the file again, or click Back to select a new profile database to manipulate.] -;[Convert old Unicode messages to UTF8] -;[Converts history messages in pre-0.7 format (ANSI+UCS2) to the new UTF8 format supported by 0.7. Saves the database space in most cases (recommended).] -;[Create backup] -;[Creates a backup copy of the database before any of the requested changes are made.] -;[Erase all histories] -;[Error Opening Database] -;[File Access Options] -;[Finished!] -;[Just checks that the database is valid, without writing anything to the disk.] -;[Launch Miranda with this profile] -;[Launches Miranda with the profile that was just worked on.] -;[Mark all events read] -;[Marks all the history events as read. This will rectify any problems with old messages always appearing in the message window log box.] -;[Please enter password for] -;[Please wait while the requested operations are being performed.] -;[Removes all the saved history for all contacts in the database.] -;[Scans the database for data that is not linked to any other data. This requires more disk space and more time, so is only required if you suspect corruption.] -;[Select Miranda Profile] -;[Select the &profile database from the list below. If the database you wish to use is not listed here then click Other to browse your computer.] -;[The file may be in use by a currently running copy of Miranda. Exit any running Mirandas and click Next to retry.] -;[The processing of the database has been completed. Click Next to return to the start of the wizard to select another database to check, or click Finish to exit the wizard.] -;[There was an error opening the profile database given.] -;[This programme is licenced under the terms of the GNU General Public License.] -;[To continue, click Next.] -;[Using this Wizard you can compact your Miranda profile database to remove dead space created during normal usage, as well as repair a large number of issues that could affect the database.] -;[Welcome to the Miranda Database Wizard] -;[Working...] -;[You can choose the Miranda profile database to compact or repair.] -;[You can choose to remove information from the database while it is being processed.] -;[You can select low level options to determine how the database is processed.] -;[whiterect] - -; ../../plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp -;[Miranda Databases (*.dat)] -;[Total size] -;[Wasted] - -; ../../plugins/Dbx_mmap_SA/Dbtool/settingschain.cpp -;[Empty settings group at %08X: skipping] -;[Infeasibly large settings blob: skipping] -;[Settings chain corrupted, further entries ignored] - -; ../../plugins/Dbx_mmap_SA/Dbtool/user.cpp -;[More than one user contact: keeping only first] -;[Processing user data] -;[User corrupted, this could cause major problems] - -; ../../plugins/Dbx_mmap_SA/Dbtool/worker.cpp -;[All tasks completed but with errors (%d)] -;[All tasks completed successfully] -;[Database worker thread activated] -;[Elapsed time: %d sec] -;[Processing aborted by user] - -; ../../plugins/Dbx_mmap_SA/Import_SA/main.cpp -;[&Import...] -;[Added %s contact %s] -;[Added %s contact %s, '%s'] -;[Added contact %u (found in history)] -;[Failed to add %s contact %s] -;[Ignored event from/to self] -;[Skipping duplicate group %s.] - -; ../../plugins/Dbx_mmap_SA/Import_SA/mirabilis.cpp -;[Added %d events and skipped %d duplicates.] -;[All groups may not have not been imported.] -;[Attempting to parse group list, type %d.] -;[Attempting to parse property block at offset %u.] -;[Attempting to parse property block list at offset %u.] -;[Attempting to parse sub list at offset %u.] -;[Attempting to parse wav file list at offset %u.] -;[ERROR: An error occurred while importing groups.] -;[ERROR: Failed to find contact list groups.] -;[ERROR: Failed to find owner information.] -;[Error: Unknown datatype (%u) at offset %u.] -;[Error: Unknown sub list type (%u) at offset %u.] -;[Failed to open database file] -;[Failed to open index file] -;[Failed to read Property block.] -;[Group import was not completed.] -;[ICQ account is not installed.] -;[Ignoring msg from user %d at ofs %d.] -;[Ignoring msg with no text from %d ofs %d.] -;[Import aborted] -;[Importing contacts] -;[Importing history (this may take a while)] -;[Mirabilis ICQ database indexes] -;[Mirabilis Import] -;[No ICQ contacts or history will be imported.] -;[Skipping 'Auth. accepted' msg, ofs %d.] -;[Skipping 'Auth. denied' msg, ofs %d.] -;[Skipping 'Birthday' msg (?), ofs %d.] -;[Skipping 'Chat request' msg, ofs %d.] -;[Skipping 'Contact' msg, ofs %d.] -;[Skipping 'Email Express' msg, ofs %d.] -;[Skipping 'Phonecall' msg (?), ofs %d.] -;[Skipping 'Request for auth.' msg, ofs %d.] -;[Skipping 'SMS' msg (?), ofs %d.] -;[Skipping 'System message', ofs %d.] -;[Skipping 'WWW Pager' msg, ofs %d.] -;[Skipping 'You were added' msg, ofs %d.] -;[Skipping 29 msg, ofs %d.] -;[Skipping 32 msg, ofs %d.] -;[Skipping contact with unsupported version.] -;[Skipping duplicate ICQ contact %u] -;[Skipping duplicate ICQ contact %u, %s] -;[Skipping event with ID < 2001.] -;[Skipping file message offset %d.] -;[Skipping inactive contact.] -;[Skipping message type 0xE3 at offset %d.] -;[Skipping non-ICQ contact %u.] -;[Skipping unknown 0xE0 subtype (%d), ofs %d.] -;[Skipping unknown event type %d at offset %d.] -;[Skipping unrecognizable contact.] -;[This database does not contain any contact groups.] -;[This database is an unknown version.] -;[This looks like a ICQ 2000a database.] -;[This looks like a ICQ 2000b database.] -;[This looks like a ICQ 2001, 2002 or 2003a database.] -;[This looks like a ICQ 99a database.] -;[This looks like a ICQ 99b database.] -;[default] - -; ../../plugins/Dbx_mmap_SA/Import_SA/miranda.cpp -;[Added %d contacts, %d groups and %d events.] -;[Could not open file.] -;[DEBUG: Deleted setting treated as 0-length setting] -;[ERROR: Chain broken, no valid contact at %d] -;[ERROR: Faulty settings chain] -;[Failed to add message] -;[Failed to find module %s] -;[Failed to find setting %s] -;[Found module: %s] -;[Getting type %u value for setting: %s] -;[Group import failed.] -;[Ignoring module: %s] -;[Ignoring setting: %s] -;[Importing contacts.] -;[Importing history.] -;[Importing system history.] -;[Miranda IM database] -;[Miranda Import] -;[Modulename corrupted] -;[No owner found.] -;[Number of contacts in database: %d] -;[Read failure.] -;[Signature mismatch] -;[Skipped %d contacts.] -;[Skipped %d duplicates and %d filtered events.] -;[Skipped %d duplicates.] -;[Skipping %s contact, ID not found] -;[Skipping contact with no protocol] -;[Skipping contact, %s not installed.] -;[Skipping duplicate %s contact %s] -;[Skipping history import.] -;[Skipping new contacts import.] -;[Skipping non-IM contact (%s)] -;[Skipping system history import.] -;[This is not a valid Miranda IM database.] -;[This looks like a Miranda database, version 0.1.0.0 or above.] -;[Unknown error while adding %s contact %s] -;[Version mismatch] -;[Warning: Found module with no name] - -; ../../plugins/Dbx_mmap_SA/Import_SA/resource.rc -;[&Account:] -;[&Filename:] -;[&Other Database...] -;[&Other Profile...] -;[Choose how you would like to import:] -;[Click \"Next\" to choose the information you wish to import, or click \"Cancel\" to exit the wizard and continue using Miranda.] -;[Custom import] -;[Do not load the import plugin at startup again] -;[File Transfers] -;[From a Mirabilis ICQ (99a - 2003a) database.] -;[From a Miranda IM database.] -;[If at a future date you wish to use the wizard again, you can make it load again by going to the Plugins section of the Options dialog box.] -;[If you want to change the way Miranda handles server-side contacts at a later time, you can do this in the \"ICQ Contacts\" page in the Miranda options.] -;[If you wish to import more information, click \"Next\" to return to the start of the wizard, otherwise click \"Finish\" to start using Miranda.] -;[Import Information Wizard] -;[Import all contacts and all messages] -;[Import completed] -;[Incoming] -;[It is recommended that you create a backup of your current Miranda profile before importing.] -;[Messages] -;[Miranda has found Mirabilis ICQ databases corresponding to the following ICQ numbers. Please select the one you wish to import, or click \"Other Database\" if your database is not listed.] -;[Miranda has found Miranda profiles with the following names. Please select the one you wish to import, or click \"Other Profile\" if your profile is not listed, or if the list is empty.] -;[Miranda has now been configured to automatically download the contacts in your server-side contact list the next time you connect to ICQ.] -;[New contacts && groups] -;[Now importing...] -;[Only import contacts] -;[Only since:] -;[Other] -;[Outgoing] -;[Select items to import:] -;[Select this if you want to cutomize what to import.] -;[Select this if you want to import as much data as possible. This is the recommended option.] -;[Select this if you want to import contacts but don't want to import any message history.] -;[System history] -;[This wizard will help you import contacts and message history from Mirabilis ICQ, as well as letting you import from other Miranda IM profiles.] -;[URLs] -;[Use the Find/Add contacts tool to populate my contact list.] -;[Warning: Mirabilis ICQ running. Import may not be reliable.] -;[You will probably never need to use this wizard again, so you can save memory by not loading it every time you start Miranda. This will mean that the import menu item will no longer be available.] - -; ../../plugins/Dbx_mmap_SA/Import_SA/wizard.cpp -;[Finish] - -; ../../plugins/Dbx_mmap_SA/database.cpp -;[Database Error] -;[Database Panic] -;[Database failure. Miranda will now shutdown.] -;[Disk is full. Miranda will now shutdown.] -;[Miranda has detected corruption in your database. This corruption maybe fixed by DBTool. Please download it from http://www.miranda-im.org. Miranda will now shutdown.] - -; ../../plugins/Dbx_mmap_SA/db3x_mmap.rc -;[&Allow all further changes to this section] -;[&Delete] -;[&Leave] -;[&Move/Rename] -;[&No] -;[&Recycle] -;[&View contents] -;[&Yes] -;[A file containing new database settings has been placed in the Miranda IM directory.] -;[Author:] -;[Cancel Import] -;[Change] -;[Database Import Complete] -;[Database Setting Change] -;[Database encryption] -;[Database settings are being imported from] -;[Do you want to allow this change?] -;[Do you want to import the settings now?] -;[Email:] -;[Info:] -;[Install Database Settings] -;[Login to Miranda IM] -;[New password] -;[No] -;[No to all] -;[Old password] -;[Remove] -;[Security systems to prevent malicious changes are in place and you will be warned before changes that are not known to be safe.] -;[Site:] -;[The import has completed from] -;[This file wishes to change the setting] -;[Unique ID:] -;[What do you want to do with the file now?] -;[Yes] -;[to the value] - -; ../../plugins/Dbx_mmap_SA/dialogs.cpp -;[Database Features] -;[Dll] -;[Name] -;[Password is too short!] -;[Passwords do not match!] -;[Please enter your new password] -;[Services] -;[Set password] -;[Version] -;[Wrong password!] - -; ../../plugins/Dbx_mmap_SA/init.cpp -;[Running mmap_sa is forbidden under license violating products, sorry] -;[Warning!] - -; ../../plugins/Dbx_mmap_SA/security.cpp -;[Crypto module hasn't been chosen, using first one found] -;[Crypto modules not found] -;[DB is already secured!] -;[Error] -;[Notice] -;[Set Password] -;[current database] diff --git a/plugins/Dbx_mmap_SA/dialogs.cpp b/plugins/Dbx_mmap_SA/dialogs.cpp deleted file mode 100644 index 8445b69ef7..0000000000 --- a/plugins/Dbx_mmap_SA/dialogs.cpp +++ /dev/null @@ -1,543 +0,0 @@ -#include "commonheaders.h" -#include -#include -#include -#include - -#define MS_DB_CHANGEPASSWORD "DB/ChangePassword" - -extern LIST arCryptors; - -CDdxMmapSA* g_Db; -HANDLE hSetPwdMenu; - -INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -BOOL ShowDlgItem(HWND hwndDlg, int iIDCtrl, BOOL bShow) -{ - HWND hwndCtrl = GetDlgItem(hwndDlg, iIDCtrl); - if (!hwndCtrl) return FALSE; - - // Avoid flickering - if (bShow && IsWindowVisible(hwndCtrl)) - return TRUE; - - return ShowWindow(hwndCtrl, (bShow ? SW_SHOW : SW_HIDE)); -} - -BOOL EnableDlgItem(HWND hwndDlg, int iIDCtrl, BOOL bEnable) -{ - HWND hwndCtrl = GetDlgItem(hwndDlg, iIDCtrl); - if (!hwndCtrl) return FALSE; - - // Avoid flickering - if (IsWindowEnabled(hwndCtrl) == bEnable) - return (bEnable == FALSE); - - return EnableWindow(hwndCtrl, bEnable); -} - -BOOL IsDlgItemEnabled(HWND hwndDlg, int iIDCtrl) -{ - HWND hwndCtrl = GetDlgItem(hwndDlg, iIDCtrl); - if (!hwndCtrl) return FALSE; - return IsWindowEnabled(hwndCtrl); -} - -static int OptionsInit(WPARAM wParam, LPARAM lParam) -{ - OPTIONSDIALOGPAGE odp = { 0 }; - odp.cbSize = sizeof(odp); - odp.position = -790000000; - odp.hInstance = g_hInst; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); - odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR; - odp.ptszTitle = LPGENT("Database Features"); - odp.ptszGroup = LPGENT("Services"); - odp.pfnDlgProc = DlgProcOptions; - Options_AddPage(wParam, &odp); - return 0; -} - -INT_PTR ChangePassword(WPARAM wParam, LPARAM lParam) -{ - if (g_Db->m_bEncoding) - g_Db->ChangePwd(); - else - g_Db->EncryptDB(); - - return 0; -} - -void xModifyMenu(HANDLE hMenu,long flags,const TCHAR* name, HICON hIcon) -{ - CLISTMENUITEM menu; - ZeroMemory(&menu,sizeof(menu)); - menu.cbSize = sizeof(menu); - menu.flags = CMIM_FLAGS | CMIF_TCHAR; - menu.flags |= name ? CMIM_NAME : 0; - menu.flags |= hIcon ? CMIM_ICON : 0; - menu.flags |= flags; - menu.ptszName = (TCHAR*)name; - menu.hIcon = hIcon; - - CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)hMenu,(LPARAM)&menu); -} - -int InitMenus(WPARAM, LPARAM) -{ - HookEvent(ME_OPT_INITIALISE, OptionsInit); - - TCHAR szFile[MAX_PATH]; - GetModuleFileName(g_hInst, szFile, MAX_PATH); - - SKINICONDESC sid = {0}; - sid.cbSize = sizeof(sid); - sid.ptszDefaultFile = szFile; - sid.flags = SIDF_ALL_TCHAR; - sid.ptszSection = LPGENT("Database"); - sid.ptszDescription = LPGENT("Database"); - sid.pszName = "database"; - sid.iDefaultIndex = -IDI_ICON2; - Skin_AddIcon(&sid); - - sid.ptszDescription = LPGENT("Change Password"); - sid.pszName = "password"; - sid.iDefaultIndex = -IDI_ICON3; - HANDLE hIcon = Skin_AddIcon(&sid); - - // main menu item - CLISTMENUITEM menu = {0}; - menu.cbSize = sizeof(menu); - menu.flags = CMIM_ALL | CMIF_TCHAR | CMIF_ICONFROMICOLIB; - menu.icolibItem = hIcon; - menu.ptszName = (g_Db->m_bEncoding) ? LPGENT("Change password") : LPGENT("Set password"); - menu.ptszPopupName = LPGENT("Database"); - menu.pszService = MS_DB_CHANGEPASSWORD; - menu.position = 500100000; - hSetPwdMenu = Menu_AddMainMenuItem(&menu); - return 0; -} - -int InitDialogs() -{ - HookEvent(ME_SYSTEM_MODULESLOADED, InitMenus); - CreateServiceFunction(MS_DB_CHANGEPASSWORD, ChangePassword); - return 0; -} - -int ImageList_AddIcon_IconLibLoaded(HIMAGELIST hIml, char* name) -{ - HICON hIcon = (HICON)CallService(MS_SKIN2_GETICON, (WPARAM)NULL, (LPARAM)name); - int res = ImageList_AddIcon(hIml, hIcon); - return res; -} - -INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - HWND hwndList = GetDlgItem(hwndDlg, IDC_MODULES); - LVCOLUMN col; - LVITEM item; - int i, iRow, iIndex; - NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; - WORD uid; - HIMAGELIST hIml; - - switch ( msg ) { - case WM_INITDIALOG: - hIml = ImageList_Create(16, 16, ILC_MASK | (IsWinVerXPPlus()? ILC_COLOR32 : ILC_COLOR16), 2, 0); - TranslateDialogDefault( hwndDlg ); - - ImageList_AddIcon_IconLibLoaded( hIml, "core_main_29" ); - ImageList_AddIcon_IconLibLoaded( hIml, "core_main_30" ); - ListView_SetImageList( hwndList, hIml, LVSIL_SMALL ); - - col.pszText = NULL; - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 50; - ListView_InsertColumn(hwndList, 1, &col); - - col.pszText = TranslateT("Dll"); - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.fmt = LVCFMT_LEFT; - col.cx = 1000; - ListView_InsertColumn(hwndList, 2, &col); - - col.pszText = TranslateT("Name"); - col.cx = 1000; - ListView_InsertColumn(hwndList, 3, &col); - - col.pszText = TranslateT("Version"); - col.cx = 1000; - ListView_InsertColumn(hwndList, 4, &col); - - ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES); - - uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); - - for (i = 0; i < arCryptors.getCount(); i++) { - TCHAR buf[100]; - - item.mask = LVIF_TEXT; - item.iItem = i; - item.iSubItem = 0; - item.pszText = NULL; - iRow = ListView_InsertItem(hwndList, &item); - - ListView_SetItemText(hwndList, iRow, 1, arCryptors[i]->dllname); - _tcsncpy(buf, _A2T(arCryptors[i]->cryptor->Name), SIZEOF(buf)); - ListView_SetItemText(hwndList, iRow, 2, buf); - mir_sntprintf(buf,SIZEOF(buf),_T("%d.%d.%d.%d"), HIBYTE(HIWORD(arCryptors[i]->cryptor->Version)), LOBYTE(HIWORD(arCryptors[i]->cryptor->Version)), HIBYTE(LOWORD(arCryptors[i]->cryptor->Version)), LOBYTE(LOWORD(arCryptors[i]->cryptor->Version))); - ListView_SetItemText(hwndList, iRow, 3, buf); - - if (uid == arCryptors[i]->cryptor->uid && g_Db->m_bEncoding) - ListView_SetCheckState(hwndList, i, 1); - - item.mask = LVIF_IMAGE; - item.iItem = iRow; - item.iSubItem = 0; - item.iImage = ( CryptoEngine == arCryptors[i]->cryptor && g_Db->m_bEncoding ) ? 0 : 1; - ListView_SetItem( hwndList, &item ); - } - - ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); - ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); - return TRUE; - - case WM_COMMAND: - if ( HIWORD(wParam) == STN_CLICKED ) { - switch (LOWORD(wParam)) { - case IDC_EMAIL: - case IDC_SITE: - { - char buf[512]; - char * p = &buf[7]; - lstrcpyA(buf,"mailto:"); - if ( GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), p, SIZEOF(buf) - 7)) { - CallService(MS_UTILS_OPENURL,0,(LPARAM) (LOWORD(wParam) == IDC_EMAIL ? buf : p)); - } - break; - } } } - break; - - case WM_NOTIFY: - if ( hdr && hdr->hdr.code == LVN_ITEMCHANGED && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) { - iIndex = hdr->iItem; - if (hdr->uNewState & 0x2000){ - for (i = 0; i < arCryptors.getCount(); i++) { - if (i != iIndex) ListView_SetCheckState(hwndList, i, 0); - } - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - if (hdr->uNewState & 0x1000){ - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } - if (hdr->uNewState & LVIS_SELECTED){ - SetDlgItemTextA(hwndDlg, IDC_AUTHOR, arCryptors[iIndex]->cryptor->Author); - { - TCHAR* info_t = mir_a2t((char*)(arCryptors[iIndex]->cryptor->Info)); - SetDlgItemText(hwndDlg, IDC_INFO, TranslateTS(info_t)); - mir_free(info_t); - } - SetDlgItemTextA(hwndDlg, IDC_SITE, arCryptors[iIndex]->cryptor->Site); - SetDlgItemTextA(hwndDlg, IDC_EMAIL, arCryptors[iIndex]->cryptor->Email); - SetDlgItemTextA(hwndDlg, IDC_ENC, arCryptors[iIndex]->cryptor->Name); - SetDlgItemInt(hwndDlg, IDC_UID, arCryptors[iIndex]->cryptor->uid, 0); - } else { - SetDlgItemTextA(hwndDlg, IDC_AUTHOR, ""); - SetDlgItemTextA(hwndDlg, IDC_INFO, ""); - SetDlgItemTextA(hwndDlg, IDC_SITE, ""); - SetDlgItemTextA(hwndDlg, IDC_EMAIL, ""); - SetDlgItemTextA(hwndDlg, IDC_ENC, ""); - SetDlgItemTextA(hwndDlg, IDC_UID, ""); - } - - break; - } - if (((LPNMHDR)lParam)->code == PSN_APPLY ) { - int alg = -1; - for (i = 0; i < arCryptors.getCount(); i++) { - if (ListView_GetCheckState(hwndList, i)) { - alg = i; - break; - } - } - - if (alg > -1){ - if (!g_Db->m_bEncoding){ - DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[alg]->cryptor->uid); - g_Db->EncryptDB(); - } - else { - if (arCryptors[alg]->cryptor->uid != DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", -1)) { - DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[alg]->cryptor->uid); - g_Db->RecryptDB(); - } - } - } - else if (g_Db->m_bEncoding) - g_Db->DecryptDB(); - - uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); - - for (i = 0; i < arCryptors.getCount(); i++) { - if (uid == arCryptors[i]->cryptor->uid && g_Db->m_bEncoding) - ListView_SetCheckState(hwndList, i, 1); - - item.mask = LVIF_IMAGE; - item.iItem = i; - item.iSubItem = 0; - item.iImage = ( CryptoEngine == arCryptors[i]->cryptor && g_Db->m_bEncoding ) ? 0 : 1; - - ListView_SetItem( hwndList, &item ); - } - - return TRUE; - - } - break; - } - - return FALSE; -} - -UINT oldLangID = 0; -void LanguageChanged(HWND hDlg) -{ - UINT LangID = (UINT)GetKeyboardLayout(0); - char Lang[3] = {0}; - if (LangID != oldLangID) - { - oldLangID = LangID; - GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); - Lang[0] = toupper(Lang[0]); - Lang[1] = tolower(Lang[1]); - SetDlgItemTextA(hDlg, IDC_LANG, Lang); - } -} - -extern BOOL wrongPass; - -BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) -{ - HICON hIcon = 0; - TCHAR tszHeaderTxt[256]; - - switch(uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hDlg); - - hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON2)); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); - - if (!wrongPass) { - mir_sntprintf(tszHeaderTxt, SIZEOF(tszHeaderTxt), _T("%s\n%s"), TranslateT("Please type in your password for"), (TCHAR*)lParam); - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), tszHeaderTxt); - } - else { - if (wrongPass > 2) { - HWND hwndCtrl = GetDlgItem(hDlg, IDC_USERPASS); - EnableWindow(hwndCtrl, FALSE); - hwndCtrl = GetDlgItem(hDlg, IDOK); - EnableWindow(hwndCtrl, FALSE); - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Too many errors!")); - } - else SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is not correct!")); - } - oldLangID = 0; - SetTimer(hDlg,1,200,NULL); - LanguageChanged(hDlg); - return TRUE; - - case WM_CTLCOLORSTATIC: - if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) { - SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkMode((HDC)wParam, TRANSPARENT); - return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); - } - return FALSE; - - case WM_COMMAND: - switch( LOWORD(wParam)) { - case IDOK: - if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) { - g_Db->encryptKeyLength = GetDlgItemTextA(hDlg, IDC_USERPASS, g_Db->encryptKey, 254); - EndDialog(hDlg,IDOK); - } - break; - - case IDCANCEL: - EndDialog(hDlg,IDCANCEL); - } - break; - - case WM_TIMER: - LanguageChanged(hDlg); - return FALSE; - - case WM_DESTROY: - KillTimer(hDlg, 1); - DestroyIcon(hIcon); - } - - return FALSE; -} - -BOOL CALLBACK DlgStdNewPass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) -{ - HICON hIcon = 0; - - switch(uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hDlg); - - hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON2)); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); - - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Please enter your new password")); - - oldLangID = 0; - SetTimer(hDlg,1,200,NULL); - LanguageChanged(hDlg); - return TRUE; - - case WM_CTLCOLORSTATIC: - if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) { - SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkMode((HDC)wParam, TRANSPARENT); - return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); - } - return FALSE; - - case WM_COMMAND: - { - UINT uid = LOWORD(wParam); - if (uid == IDOK) { - if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) { - char pass1[255], pass2[255]; - if (GetDlgItemTextA(hDlg, IDC_USERPASS1, pass1, 254) < 3){ - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is too short!")); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); - SetDlgItemTextA(hDlg,IDC_USERPASS1,""); - SetDlgItemTextA(hDlg,IDC_USERPASS2,""); - } - else { - GetDlgItemTextA(hDlg, IDC_USERPASS2, pass2, 254); - if (!strcmp(pass1, pass2)) { - g_Db->encryptKeyLength = strlen(pass1); - strcpy(g_Db->encryptKey, pass1); - EndDialog(hDlg,IDOK); - } - else { - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Passwords do not match!")); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); - SetDlgItemTextA(hDlg,IDC_USERPASS1,""); - SetDlgItemTextA(hDlg,IDC_USERPASS2,""); - } - } - } - } - else if (uid == IDCANCEL) - EndDialog(hDlg,IDCANCEL); - } - break; - - case WM_TIMER: - LanguageChanged(hDlg); - return FALSE; - - case WM_DESTROY: - KillTimer(hDlg, 1); - DestroyIcon(hIcon); - return FALSE; - } - return FALSE; -} - -char* newPass; - -BOOL CALLBACK DlgChangePass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) -{ - HICON hIcon = 0; - - switch(uMsg) { - case WM_INITDIALOG: - TranslateDialogDefault(hDlg); - - hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON2)); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Change password")); - - newPass = (char*)lParam; - oldLangID = 0; - SetTimer(hDlg,1,200,NULL); - LanguageChanged(hDlg); - - return TRUE; - - case WM_CTLCOLORSTATIC: - if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) { - SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); - SetBkMode((HDC)wParam, TRANSPARENT); - return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); - } - - return FALSE; - - case WM_COMMAND: - { - UINT uid = LOWORD(wParam); - if (uid == IDOK) { - char pass1[255], pass2[255], oldpass[255]; - GetDlgItemTextA(hDlg, IDC_OLDPASS, oldpass, 254); - if (strcmp(oldpass, g_Db->encryptKey)) { - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Wrong password!")); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); - break; - } - if (GetDlgItemTextA(hDlg, IDC_NEWPASS1, pass1, 254) < 3){ - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is too short!")); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); - - } - else { - GetDlgItemTextA(hDlg, IDC_NEWPASS2, pass2, 254); - if (!strcmp(pass1, pass2)) { - strcpy(newPass, pass1); - EndDialog(hDlg,IDOK); - } - else { - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Passwords do not match!")); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); - } - } - } - else if (uid == IDCANCEL) - EndDialog(hDlg,IDCANCEL); - else if (uid == IDREMOVE) { - char oldpass[255]; - GetDlgItemTextA(hDlg, IDC_OLDPASS, oldpass, 254); - if (strcmp(oldpass, g_Db->encryptKey)) { - SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Wrong password!")); - SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); - break; - } - EndDialog(hDlg, IDREMOVE); - } - } - break; - - case WM_TIMER: - LanguageChanged(hDlg); - return FALSE; - - case WM_DESTROY: - KillTimer(hDlg, 1); - return FALSE; - } - return FALSE; -} diff --git a/plugins/Dbx_mmap_SA/docs/dbx_mmap_sa-translation.txt b/plugins/Dbx_mmap_SA/docs/dbx_mmap_sa-translation.txt new file mode 100644 index 0000000000..a89cd1b8ea --- /dev/null +++ b/plugins/Dbx_mmap_SA/docs/dbx_mmap_sa-translation.txt @@ -0,0 +1,383 @@ +; Common strings that belong to many files +;[%d crypto modules loaded] +;[&Next >] +;[< &Back] +;[Added %d contacts and %d groups.] +;[All Files] +;[Cancel] +;[Change Password] +;[Change password] +;[Cryptor loaded: %s [%s] (%s)] +;[Database] +;[Database encrypted with %s by %s] +;[Database is Secured MMAP database] +;[EN] +;[Import completed in %d seconds.] +;[Importing groups.] +;[Miranda Database Tool] +;[Miranda MMAP Secured Database] +;[OK] +;[Password is not correct!] +;[Please type in your password for] +;[Progress1] +;[Scanning cryptors directory] +;[Secured MMAP: authorization successful] +;[Sorry, but your database encrypted with unknown module] +;[The given file does not exist. Please check that you have entered the name correctly.] +;[Too many errors!] +;[You are not authorized for access to Database] + +; ../../plugins/Dbx_mmap_SA/Dbtool/aggressive.cpp +;[Aggressive: random junk at %08X: skipping] +;[Aggressive: unlinked data at %08X: can't automatically place] +;[Performing aggressive pass] + +; ../../plugins/Dbx_mmap_SA/Dbtool/contactchain.cpp +;[Contact chain corrupted, further entries ignored] +;[Contact count marked wrongly: correcting] +;[Processing contact chain] + +; ../../plugins/Dbx_mmap_SA/Dbtool/disk.cpp +;[Can't write to output file - disk full? (%u)] +;[Can't write to working file, aggressive mode may be too aggressive now] +;[Error reading, database truncated? (%u)] +;[Invalid offset found] +;[Invalid offset found (database truncated?)] + +; ../../plugins/Dbx_mmap_SA/Dbtool/eventchain.cpp +;[Duplicate event was found: skipping] +;[Event chain corrupted, further entries ignored] +;[Event chain corrupted, trying to recover...] +;[Event count marked wrongly: correcting] +;[Event marked as first which is not: correcting] +;[Event not backlinked correctly: fixing] +;[Event position in chain is not correct] +;[Event position in chain is not correct: fixing] +;[Event position in chain is not correct: unable to fix] +;[Extra flags found in event: removing] +;[First event not marked as such: correcting] +;[First unread event marked wrong: fixing] +;[Infeasibly large event blob: skipping] + +; ../../plugins/Dbx_mmap_SA/Dbtool/finaltasks.cpp +;[%s\\Backup (%d) of %s] +;[%s\\Backup of %s] +;[Errors were encountered, however you selected not to backup the original database. It is strongly recommended that you do so in case important data was omitted. Do you wish to keep a backup of the original database?] +;[Processing final tasks] +;[Unable to delete original file] +;[Unable to rename original file] +;[Unable to rename output file] + +; ../../plugins/Dbx_mmap_SA/Dbtool/finished.cpp +;[&Finish] + +; ../../plugins/Dbx_mmap_SA/Dbtool/initialchecks.cpp +;[ (Output).dat] +;[] +;[Can't create file mapping (%u)] +;[Can't create map view of file (%u)] +;[Can't create output file (%u)] +;[Database is corrupted and too small to contain any recoverable data] +;[Database is marked as belonging to an unknown version of Miranda] +;[Database is newly created and has no data to process] +;[Database signature is corrupted, automatic repair is impossible] +;[Processing completed successfully] +;[your database] + +; ../../plugins/Dbx_mmap_SA/Dbtool/modulechain.cpp +;[Invalid module name offset, skipping data] +;[Module chain corrupted, further entries ignored] +;[Module name '%s' is not unique: %d duplicates found)] +;[Processing module name chain] +;[Unreasonably long module name, skipping] + +; ../../plugins/Dbx_mmap_SA/Dbtool/progress.cpp +;[Click Next to continue] +;[Processing has not yet completed, if you cancel now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to cancel?] +;[Processing has not yet completed, if you go back now then the changes that have currently been made will be rolled back and the original database will be restored. Do you still want to go back?] + +; ../../plugins/Dbx_mmap_SA/Dbtool/resource.rc +;[&File:] +;[&Other...] +;[Aggressively find corruption] +;[All tasks have been completed.] +;[Backup:] +;[Check consistency only] +;[Cleaning Options] +;[Click Next to try opening the file again, or click Back to select a new profile database to manipulate.] +;[Convert old Unicode messages to UTF8] +;[Converts history messages in pre-0.7 format (ANSI+UCS2) to the new UTF8 format supported by 0.7. Saves the database space in most cases (recommended).] +;[Create backup] +;[Creates a backup copy of the database before any of the requested changes are made.] +;[Erase all histories] +;[Error Opening Database] +;[File Access Options] +;[Finished!] +;[Just checks that the database is valid, without writing anything to the disk.] +;[Launch Miranda with this profile] +;[Launches Miranda with the profile that was just worked on.] +;[Mark all events read] +;[Marks all the history events as read. This will rectify any problems with old messages always appearing in the message window log box.] +;[Please enter password for] +;[Please wait while the requested operations are being performed.] +;[Removes all the saved history for all contacts in the database.] +;[Scans the database for data that is not linked to any other data. This requires more disk space and more time, so is only required if you suspect corruption.] +;[Select Miranda Profile] +;[Select the &profile database from the list below. If the database you wish to use is not listed here then click Other to browse your computer.] +;[The file may be in use by a currently running copy of Miranda. Exit any running Mirandas and click Next to retry.] +;[The processing of the database has been completed. Click Next to return to the start of the wizard to select another database to check, or click Finish to exit the wizard.] +;[There was an error opening the profile database given.] +;[This programme is licenced under the terms of the GNU General Public License.] +;[To continue, click Next.] +;[Using this Wizard you can compact your Miranda profile database to remove dead space created during normal usage, as well as repair a large number of issues that could affect the database.] +;[Welcome to the Miranda Database Wizard] +;[Working...] +;[You can choose the Miranda profile database to compact or repair.] +;[You can choose to remove information from the database while it is being processed.] +;[You can select low level options to determine how the database is processed.] +;[whiterect] + +; ../../plugins/Dbx_mmap_SA/Dbtool/selectdb.cpp +;[Miranda Databases (*.dat)] +;[Total size] +;[Wasted] + +; ../../plugins/Dbx_mmap_SA/Dbtool/settingschain.cpp +;[Empty settings group at %08X: skipping] +;[Infeasibly large settings blob: skipping] +;[Settings chain corrupted, further entries ignored] + +; ../../plugins/Dbx_mmap_SA/Dbtool/user.cpp +;[More than one user contact: keeping only first] +;[Processing user data] +;[User corrupted, this could cause major problems] + +; ../../plugins/Dbx_mmap_SA/Dbtool/worker.cpp +;[All tasks completed but with errors (%d)] +;[All tasks completed successfully] +;[Database worker thread activated] +;[Elapsed time: %d sec] +;[Processing aborted by user] + +; ../../plugins/Dbx_mmap_SA/Import_SA/main.cpp +;[&Import...] +;[Added %s contact %s] +;[Added %s contact %s, '%s'] +;[Added contact %u (found in history)] +;[Failed to add %s contact %s] +;[Ignored event from/to self] +;[Skipping duplicate group %s.] + +; ../../plugins/Dbx_mmap_SA/Import_SA/mirabilis.cpp +;[Added %d events and skipped %d duplicates.] +;[All groups may not have not been imported.] +;[Attempting to parse group list, type %d.] +;[Attempting to parse property block at offset %u.] +;[Attempting to parse property block list at offset %u.] +;[Attempting to parse sub list at offset %u.] +;[Attempting to parse wav file list at offset %u.] +;[ERROR: An error occurred while importing groups.] +;[ERROR: Failed to find contact list groups.] +;[ERROR: Failed to find owner information.] +;[Error: Unknown datatype (%u) at offset %u.] +;[Error: Unknown sub list type (%u) at offset %u.] +;[Failed to open database file] +;[Failed to open index file] +;[Failed to read Property block.] +;[Group import was not completed.] +;[ICQ account is not installed.] +;[Ignoring msg from user %d at ofs %d.] +;[Ignoring msg with no text from %d ofs %d.] +;[Import aborted] +;[Importing contacts] +;[Importing history (this may take a while)] +;[Mirabilis ICQ database indexes] +;[Mirabilis Import] +;[No ICQ contacts or history will be imported.] +;[Skipping 'Auth. accepted' msg, ofs %d.] +;[Skipping 'Auth. denied' msg, ofs %d.] +;[Skipping 'Birthday' msg (?), ofs %d.] +;[Skipping 'Chat request' msg, ofs %d.] +;[Skipping 'Contact' msg, ofs %d.] +;[Skipping 'Email Express' msg, ofs %d.] +;[Skipping 'Phonecall' msg (?), ofs %d.] +;[Skipping 'Request for auth.' msg, ofs %d.] +;[Skipping 'SMS' msg (?), ofs %d.] +;[Skipping 'System message', ofs %d.] +;[Skipping 'WWW Pager' msg, ofs %d.] +;[Skipping 'You were added' msg, ofs %d.] +;[Skipping 29 msg, ofs %d.] +;[Skipping 32 msg, ofs %d.] +;[Skipping contact with unsupported version.] +;[Skipping duplicate ICQ contact %u] +;[Skipping duplicate ICQ contact %u, %s] +;[Skipping event with ID < 2001.] +;[Skipping file message offset %d.] +;[Skipping inactive contact.] +;[Skipping message type 0xE3 at offset %d.] +;[Skipping non-ICQ contact %u.] +;[Skipping unknown 0xE0 subtype (%d), ofs %d.] +;[Skipping unknown event type %d at offset %d.] +;[Skipping unrecognizable contact.] +;[This database does not contain any contact groups.] +;[This database is an unknown version.] +;[This looks like a ICQ 2000a database.] +;[This looks like a ICQ 2000b database.] +;[This looks like a ICQ 2001, 2002 or 2003a database.] +;[This looks like a ICQ 99a database.] +;[This looks like a ICQ 99b database.] +;[default] + +; ../../plugins/Dbx_mmap_SA/Import_SA/miranda.cpp +;[Added %d contacts, %d groups and %d events.] +;[Could not open file.] +;[DEBUG: Deleted setting treated as 0-length setting] +;[ERROR: Chain broken, no valid contact at %d] +;[ERROR: Faulty settings chain] +;[Failed to add message] +;[Failed to find module %s] +;[Failed to find setting %s] +;[Found module: %s] +;[Getting type %u value for setting: %s] +;[Group import failed.] +;[Ignoring module: %s] +;[Ignoring setting: %s] +;[Importing contacts.] +;[Importing history.] +;[Importing system history.] +;[Miranda IM database] +;[Miranda Import] +;[Modulename corrupted] +;[No owner found.] +;[Number of contacts in database: %d] +;[Read failure.] +;[Signature mismatch] +;[Skipped %d contacts.] +;[Skipped %d duplicates and %d filtered events.] +;[Skipped %d duplicates.] +;[Skipping %s contact, ID not found] +;[Skipping contact with no protocol] +;[Skipping contact, %s not installed.] +;[Skipping duplicate %s contact %s] +;[Skipping history import.] +;[Skipping new contacts import.] +;[Skipping non-IM contact (%s)] +;[Skipping system history import.] +;[This is not a valid Miranda IM database.] +;[This looks like a Miranda database, version 0.1.0.0 or above.] +;[Unknown error while adding %s contact %s] +;[Version mismatch] +;[Warning: Found module with no name] + +; ../../plugins/Dbx_mmap_SA/Import_SA/resource.rc +;[&Account:] +;[&Filename:] +;[&Other Database...] +;[&Other Profile...] +;[Choose how you would like to import:] +;[Click \"Next\" to choose the information you wish to import, or click \"Cancel\" to exit the wizard and continue using Miranda.] +;[Custom import] +;[Do not load the import plugin at startup again] +;[File Transfers] +;[From a Mirabilis ICQ (99a - 2003a) database.] +;[From a Miranda IM database.] +;[If at a future date you wish to use the wizard again, you can make it load again by going to the Plugins section of the Options dialog box.] +;[If you want to change the way Miranda handles server-side contacts at a later time, you can do this in the \"ICQ Contacts\" page in the Miranda options.] +;[If you wish to import more information, click \"Next\" to return to the start of the wizard, otherwise click \"Finish\" to start using Miranda.] +;[Import Information Wizard] +;[Import all contacts and all messages] +;[Import completed] +;[Incoming] +;[It is recommended that you create a backup of your current Miranda profile before importing.] +;[Messages] +;[Miranda has found Mirabilis ICQ databases corresponding to the following ICQ numbers. Please select the one you wish to import, or click \"Other Database\" if your database is not listed.] +;[Miranda has found Miranda profiles with the following names. Please select the one you wish to import, or click \"Other Profile\" if your profile is not listed, or if the list is empty.] +;[Miranda has now been configured to automatically download the contacts in your server-side contact list the next time you connect to ICQ.] +;[New contacts && groups] +;[Now importing...] +;[Only import contacts] +;[Only since:] +;[Other] +;[Outgoing] +;[Select items to import:] +;[Select this if you want to cutomize what to import.] +;[Select this if you want to import as much data as possible. This is the recommended option.] +;[Select this if you want to import contacts but don't want to import any message history.] +;[System history] +;[This wizard will help you import contacts and message history from Mirabilis ICQ, as well as letting you import from other Miranda IM profiles.] +;[URLs] +;[Use the Find/Add contacts tool to populate my contact list.] +;[Warning: Mirabilis ICQ running. Import may not be reliable.] +;[You will probably never need to use this wizard again, so you can save memory by not loading it every time you start Miranda. This will mean that the import menu item will no longer be available.] + +; ../../plugins/Dbx_mmap_SA/Import_SA/wizard.cpp +;[Finish] + +; ../../plugins/Dbx_mmap_SA/database.cpp +;[Database Error] +;[Database Panic] +;[Database failure. Miranda will now shutdown.] +;[Disk is full. Miranda will now shutdown.] +;[Miranda has detected corruption in your database. This corruption maybe fixed by DBTool. Please download it from http://www.miranda-im.org. Miranda will now shutdown.] + +; ../../plugins/Dbx_mmap_SA/db3x_mmap.rc +;[&Allow all further changes to this section] +;[&Delete] +;[&Leave] +;[&Move/Rename] +;[&No] +;[&Recycle] +;[&View contents] +;[&Yes] +;[A file containing new database settings has been placed in the Miranda IM directory.] +;[Author:] +;[Cancel Import] +;[Change] +;[Database Import Complete] +;[Database Setting Change] +;[Database encryption] +;[Database settings are being imported from] +;[Do you want to allow this change?] +;[Do you want to import the settings now?] +;[Email:] +;[Info:] +;[Install Database Settings] +;[Login to Miranda IM] +;[New password] +;[No] +;[No to all] +;[Old password] +;[Remove] +;[Security systems to prevent malicious changes are in place and you will be warned before changes that are not known to be safe.] +;[Site:] +;[The import has completed from] +;[This file wishes to change the setting] +;[Unique ID:] +;[What do you want to do with the file now?] +;[Yes] +;[to the value] + +; ../../plugins/Dbx_mmap_SA/dialogs.cpp +;[Database Features] +;[Dll] +;[Name] +;[Password is too short!] +;[Passwords do not match!] +;[Please enter your new password] +;[Services] +;[Set password] +;[Version] +;[Wrong password!] + +; ../../plugins/Dbx_mmap_SA/init.cpp +;[Running mmap_sa is forbidden under license violating products, sorry] +;[Warning!] + +; ../../plugins/Dbx_mmap_SA/security.cpp +;[Crypto module hasn't been chosen, using first one found] +;[Crypto modules not found] +;[DB is already secured!] +;[Error] +;[Notice] +;[Set Password] +;[current database] diff --git a/plugins/Dbx_mmap_SA/icos/backup.ico b/plugins/Dbx_mmap_SA/icos/backup.ico deleted file mode 100644 index 2bd78218d8..0000000000 Binary files a/plugins/Dbx_mmap_SA/icos/backup.ico and /dev/null differ diff --git a/plugins/Dbx_mmap_SA/icos/logo.ico b/plugins/Dbx_mmap_SA/icos/logo.ico deleted file mode 100644 index 908883520a..0000000000 Binary files a/plugins/Dbx_mmap_SA/icos/logo.ico and /dev/null differ diff --git a/plugins/Dbx_mmap_SA/icos/pass.ico b/plugins/Dbx_mmap_SA/icos/pass.ico deleted file mode 100644 index d3075f98cf..0000000000 Binary files a/plugins/Dbx_mmap_SA/icos/pass.ico and /dev/null differ diff --git a/plugins/Dbx_mmap_SA/icos/restart.ico b/plugins/Dbx_mmap_SA/icos/restart.ico deleted file mode 100644 index 70335391a0..0000000000 Binary files a/plugins/Dbx_mmap_SA/icos/restart.ico and /dev/null differ diff --git a/plugins/Dbx_mmap_SA/init.cpp b/plugins/Dbx_mmap_SA/init.cpp deleted file mode 100644 index 2566e14471..0000000000 --- a/plugins/Dbx_mmap_SA/init.cpp +++ /dev/null @@ -1,168 +0,0 @@ -/* - -Miranda IM: the free IM client for Microsoft* Windows* - -Copyright 2000-2003 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" - -void InitSecurity(void); -void UnloadSecurity(void); - -int hLangpack; - -HINSTANCE g_hInst = NULL; - -PLUGININFOEX pluginInfo = { - sizeof(PLUGININFOEX), - __PLUGIN_NAME, - __VERSION_DWORD, - "Provides Miranda database support: global settings, contacts, history, settings per contact. Enhanced modification with Encryption support.", - "Miranda-IM project, modification by FYR and chaos.persei, nullbie, Billy_Bons", - "chaos.persei@gmail.com; ashpynov@gmail.com; bio@msx.ru; ghazan@miranda.im", - "Copyright 2000-2011 Miranda IM project, FYR, chaos.persei, induction, nullbie", - "http://dbmmapmod.googlecode.com/", - UNICODE_AWARE, - // {28FF9B91-3E4D-4f1c-B47C-C641B037FF40} - { 0x28ff9b91, 0x3e4d, 0x4f1c, { 0xb4, 0x7c, 0xc6, 0x41, 0xb0, 0x37, 0xff, 0x40 } } -}; - -LIST g_Dbs(1, (LIST::FTSortFunc)HandleKeySort); - -///////////////////////////////////////////////////////////////////////////////////////// - -// returns 0 if the profile is created, EMKPRF* -static int makeDatabase(const TCHAR *profile, int *error) -{ - CDdxMmapSA *tmp = new CDdxMmapSA(profile); - if (tmp->Create() == ERROR_SUCCESS) { - tmp->CreateDbHeaders(); - delete tmp; - return 0; - } - delete tmp; - if (error != NULL) *error = EMKPRF_CREATEFAILED; - return 1; -} - -// returns 0 if the given profile has a valid header -static int grokHeader(const TCHAR *profile, int *error) -{ - CDdxMmapSA *tmp = new CDdxMmapSA(profile); - if (tmp->Load(true) != ERROR_SUCCESS) { - delete tmp; - if (error != NULL) *error = EGROKPRF_CANTREAD; - return 1; - } - - int chk = tmp->CheckDbHeaders(); - delete tmp; - if ( chk == 0 ) { - // all the internal tests passed, hurrah - if (error != NULL) *error = 0; - return 0; - } - - // didn't pass at all, or some did. - switch ( chk ) { - case 1: - // "Miranda ICQ DB" wasn't present - if (error != NULL) *error = EGROKPRF_UNKHEADER; - break; - - case 2: - // header was present, but version information newer - if (error != NULL) *error = EGROKPRF_VERNEWER; - break; - - case 3: - // header/version OK, internal data missing - if (error != NULL) *error = EGROKPRF_DAMAGED; - break; - } - - return 1; -} - -// returns 0 if all the APIs are injected otherwise, 1 -static MIDatabase* LoadDatabase(const TCHAR *profile) -{ - // set the memory, lists & UTF8 manager - mir_getLP( &pluginInfo ); - - CDdxMmapSA* db = new CDdxMmapSA(profile); - if (db->Load(false) != ERROR_SUCCESS) { - delete db; - return NULL; - } - - g_Dbs.insert(db); - return db; -} - -static int UnloadDatabase(MIDatabase* db) -{ - g_Dbs.remove((CDdxMmapSA*)db); - delete (CDdxMmapSA*)db; - return 0; -} - -static DATABASELINK dblink = -{ - sizeof(DATABASELINK), - "db3x secure mmap driver", - _T("db3x secure mmap database support"), - makeDatabase, - grokHeader, - LoadDatabase, - UnloadDatabase -}; - -///////////////////////////////////////////////////////////////////////////////////////// - -extern "C" __declspec(dllexport) PLUGININFOEX * MirandaPluginInfoEx(DWORD mirandaVersion) -{ - return &pluginInfo; -} - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_DATABASE, MIID_LAST}; - -extern "C" __declspec(dllexport) int Load(void) -{ - InitSecurity(); - InitPreset(); - - RegisterDatabasePlugin(&dblink); - return 0; -} - -extern "C" __declspec(dllexport) int Unload(void) -{ - g_Dbs.destroy(); - UnloadSecurity(); - UninitPreset(); - return 0; -} - -BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID reserved) -{ - g_hInst = hInstDLL; - return TRUE; -} diff --git a/plugins/Dbx_mmap_SA/options.h b/plugins/Dbx_mmap_SA/options.h deleted file mode 100644 index efabf3eba5..0000000000 --- a/plugins/Dbx_mmap_SA/options.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - -Miranda IM: the free IM client for Microsoft* Windows* - -Copyright 2000-2003 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 -#include -#include "resource.h" - -typedef enum { BT_DISABLED = 0, BT_START = 1, BT_EXIT = 2, BT_PERIODIC = 4} BackupType; -typedef enum { PT_DAYS, PT_HOURS, PT_MINUTES} PeriodType; - -typedef struct Options_tag { - int backup_types; - unsigned int period; - PeriodType period_type; - char folder[MAX_PATH]; - unsigned int num_backups; - BOOL disable_progress; -} Options; \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/res/db3x_mmap.rc b/plugins/Dbx_mmap_SA/res/db3x_mmap.rc new file mode 100644 index 0000000000..0323c374c9 --- /dev/null +++ b/plugins/Dbx_mmap_SA/res/db3x_mmap.rc @@ -0,0 +1,275 @@ +// Microsoft Visual C++ generated resource script. +// +#include "..\src\resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// Ðóññêèé (Ðîññèÿ) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) +LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT +#pragma code_page(1251) + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_LOGIN DIALOGEX 0, 0, 190, 86 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW +CAPTION "Login to Miranda IM" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 + CTEXT "EN",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP + EDITTEXT IDC_USERPASS,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL | WS_GROUP + DEFPUSHBUTTON "OK",IDOK,36,64,50,14 + PUSHBUTTON "Cancel",IDCANCEL,102,64,50,14 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,55,190,1 +END + +IDD_NEWPASS DIALOGEX 0, 0, 190, 102 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOPMOST | WS_EX_TOOLWINDOW +CAPTION "New password" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 + CTEXT "EN",IDC_LANG,158,34,13,13,SS_CENTERIMAGE | NOT WS_GROUP + EDITTEXT IDC_USERPASS1,21,34,128,14,ES_PASSWORD | ES_AUTOHSCROLL + EDITTEXT IDC_USERPASS2,21,54,128,14,ES_PASSWORD | ES_AUTOHSCROLL + DEFPUSHBUTTON "OK",IDOK,36,84,50,14 + PUSHBUTTON "Cancel",IDCANCEL,100,84,50,14 + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,77,190,1 +END + +IDD_CHANGEPASS DIALOGEX 0, 0, 190, 148 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Change password" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "",IDC_HEADERBAR,"MHeaderbarCtrl",0x0,0,0,190,26 + CTEXT "EN",IDC_LANG,158,42,13,13,SS_CENTERIMAGE | NOT WS_GROUP + EDITTEXT IDC_OLDPASS,21,42,128,14,ES_PASSWORD | ES_AUTOHSCROLL + EDITTEXT IDC_NEWPASS1,21,77,128,14,ES_PASSWORD | ES_AUTOHSCROLL + EDITTEXT IDC_NEWPASS2,21,98,128,14,ES_PASSWORD | ES_AUTOHSCROLL + DEFPUSHBUTTON "Change",IDOK,11,127,50,14 + PUSHBUTTON "Remove",IDREMOVE,69,127,50,14 + PUSHBUTTON "Cancel",IDCANCEL,126,127,50,14 + LTEXT "New password",IDC_NEWPASSINFO,11,66,163,10,0,WS_EX_TRANSPARENT + CONTROL "",IDC_STATIC,"Static",SS_ETCHEDFRAME,0,119,190,1 + LTEXT "Old password",IDC_NEWPASSINFO2,11,31,140,10,0,WS_EX_TRANSPARENT +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_CHANGEPASS, DIALOG + BEGIN + TOPMARGIN, 7 + END +END +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_ICON2 ICON "logo.ico" +IDI_ICON3 ICON "pass.ico" +#endif // Ðóññêèé (Ðîññèÿ) resources +///////////////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////////////////////////////////// +// Àíãëèéñêèé (ÑØÀ) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_INSTALLINI DIALOGEX 0, 0, 212, 102 +STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +CAPTION "Install Database Settings" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + DEFPUSHBUTTON "Yes",IDOK,26,83,50,14 + PUSHBUTTON "No",IDCANCEL,81,83,50,14 + LTEXT "A file containing new database settings has been placed in the Miranda IM directory.",IDC_STATIC,5,5,202,16 + LTEXT "Do you want to import the settings now?",IDC_STATIC,5,69,202,8 + PUSHBUTTON "No to all",IDC_NOTOALL,136,83,50,14 + LTEXT "",IDC_ININAME,5,24,143,16,SS_NOPREFIX | SS_CENTERIMAGE + PUSHBUTTON "&View contents",IDC_VIEWINI,149,25,58,14 + LTEXT "Security systems to prevent malicious changes are in place and you will be warned before changes that are not known to be safe.",IDC_SECURITYINFO,5,43,202,24 +END + +IDD_WARNINICHANGE DIALOGEX 0, 0, 187, 113 +STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +CAPTION "Database Setting Change" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "Database settings are being imported from",IDC_STATIC,5,5,177,8 + CONTROL "",IDC_ININAME,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,5,13,177,8 + LTEXT "This file wishes to change the setting",IDC_STATIC,5,24,177,8 + CONTROL "",IDC_SETTINGNAME,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,12,33,170,8 + LTEXT "to the value",IDC_STATIC,5,42,177,8 + CONTROL "",IDC_NEWVALUE,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,12,51,170,8 + LTEXT "",IDC_SECURITYINFO,5,60,177,8 + LTEXT "Do you want to allow this change?",IDC_STATIC,5,71,177,8 + CONTROL "&Allow all further changes to this section",IDC_WARNNOMORE, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,80,169,10 + DEFPUSHBUTTON "&Yes",IDYES,5,94,50,14 + PUSHBUTTON "&No",IDNO,59,94,50,14 + PUSHBUTTON "Cancel Import",IDCANCEL,123,94,59,14 +END + +IDD_INIIMPORTDONE DIALOGEX 0, 0, 186, 73 +STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +CAPTION "Database Import Complete" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + LTEXT "The import has completed from",IDC_STATIC,5,5,176,8 + CONTROL "",IDC_ININAME,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,5,13,176,8 + LTEXT "What do you want to do with the file now?",IDC_STATIC,5,24,176,8 + PUSHBUTTON "&Recycle",IDC_RECYCLE,5,36,50,14 + PUSHBUTTON "&Delete",IDC_DELETE,68,36,50,14 + EDITTEXT IDC_NEWNAME,5,55,117,12,ES_AUTOHSCROLL + PUSHBUTTON "&Move/Rename",IDC_MOVE,124,54,57,14 + PUSHBUTTON "&Leave",IDC_LEAVE,131,36,50,14 +END + +IDD_OPTIONS DIALOGEX 0, 0, 318, 188 +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + GROUPBOX "Database encryption",IDC_ENC,4,87,307,96,0,WS_EX_RIGHT + CONTROL "",IDC_MODULES,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_ALIGNLEFT | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,6,3,305,80 + LTEXT "Info:",IDC_STATIC,9,97,35,8,0,WS_EX_RIGHT + EDITTEXT IDC_INFO,49,97,256,21,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | ES_WANTRETURN | NOT WS_BORDER | WS_VSCROLL + LTEXT "Author:",IDC_STATIC,9,123,35,8,0,WS_EX_RIGHT + EDITTEXT IDC_AUTHOR,49,123,256,12,ES_AUTOHSCROLL | ES_READONLY | ES_WANTRETURN | NOT WS_BORDER + LTEXT "Site:",IDC_STATIC,9,135,35,8,0,WS_EX_RIGHT + CONTROL "",IDC_SITE,"Hyperlink",WS_TABSTOP,49,135,256,12 + LTEXT "Email:",IDC_STATIC,9,147,35,8,0,WS_EX_RIGHT + CONTROL "",IDC_EMAIL,"Hyperlink",WS_TABSTOP,49,147,256,12 + LTEXT "Unique ID:",IDC_STATIC,9,166,35,8,0,WS_EX_RIGHT + EDITTEXT IDC_UID,49,166,256,12,ES_AUTOHSCROLL | ES_READONLY | ES_WANTRETURN | NOT WS_BORDER +END + + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_INSTALLINI, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 207 + TOPMARGIN, 5 + BOTTOMMARGIN, 97 + END + + IDD_WARNINICHANGE, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 182 + TOPMARGIN, 5 + BOTTOMMARGIN, 108 + END + + IDD_INIIMPORTDONE, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 181 + TOPMARGIN, 5 + BOTTOMMARGIN, 68 + END + + IDD_OPTIONS, DIALOG + BEGIN + LEFTMARGIN, 6 + RIGHTMARGIN, 311 + VERTGUIDE, 9 + VERTGUIDE, 44 + VERTGUIDE, 49 + VERTGUIDE, 193 + VERTGUIDE, 248 + VERTGUIDE, 305 + TOPMARGIN, 7 + BOTTOMMARGIN, 181 + END +END +#endif // APSTUDIO_INVOKED + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "..\\src\\resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include \0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + +#endif // Àíãëèéñêèé (ÑØÀ) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/plugins/Dbx_mmap_SA/res/logo.ico b/plugins/Dbx_mmap_SA/res/logo.ico new file mode 100644 index 0000000000..908883520a Binary files /dev/null and b/plugins/Dbx_mmap_SA/res/logo.ico differ diff --git a/plugins/Dbx_mmap_SA/res/pass.ico b/plugins/Dbx_mmap_SA/res/pass.ico new file mode 100644 index 0000000000..d3075f98cf Binary files /dev/null and b/plugins/Dbx_mmap_SA/res/pass.ico differ diff --git a/plugins/Dbx_mmap_SA/res/version.rc b/plugins/Dbx_mmap_SA/res/version.rc new file mode 100644 index 0000000000..a7dc60bbf0 --- /dev/null +++ b/plugins/Dbx_mmap_SA/res/version.rc @@ -0,0 +1,42 @@ +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include +#include "..\src\version.h" + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION __FILEVERSION_STRING + PRODUCTVERSION __FILEVERSION_STRING + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "041904b0" + BEGIN + VALUE "FileDescription", "Miranda IM Mmap DataBase Engine 3x" + VALUE "FileVersion", __VERSION_STRING + VALUE "LegalCopyright", "Copyright (C) 2000-2007" + VALUE "OriginalFilename", "dbx_mmap.dll" + VALUE "ProductName", "Miranda IM Mmap DataBase Engine 3x" + VALUE "ProductVersion", __VERSION_STRING + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x419, 1200 + END +END diff --git a/plugins/Dbx_mmap_SA/resource.h b/plugins/Dbx_mmap_SA/resource.h deleted file mode 100644 index 7b13f6957d..0000000000 --- a/plugins/Dbx_mmap_SA/resource.h +++ /dev/null @@ -1,54 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by db3x_mmap.rc -// -#define IDC_NOTOALL 3 -#define IDREMOVE 3 -#define IDD_OPTIONS 101 -#define IDD_INSTALLINI 235 -#define IDD_WARNINICHANGE 236 -#define IDD_INIIMPORTDONE 237 -#define IDD_LOGIN 269 -#define IDD_NEWPASS 270 -#define IDI_ICON2 271 -#define IDI_ICON3 272 -#define IDC_LANG 274 -#define IDD_CHANGEPASS 275 -#define IDC_ININAME 1333 -#define IDC_VIEWINI 1334 -#define IDC_SECURITYINFO 1335 -#define IDC_SETTINGNAME 1336 -#define IDC_NEWVALUE 1337 -#define IDC_WARNNOMORE 1338 -#define IDC_DELETE 1339 -#define IDC_RECYCLE 1340 -#define IDC_NEWNAME 1341 -#define IDC_MOVE 1342 -#define IDC_LEAVE 1343 -#define IDC_HEADERBAR 1657 -#define IDC_USERPASS 1658 -#define IDC_ENC 1659 -#define IDC_USERPASS1 1659 -#define IDC_OLDPASS 1660 -#define IDC_USERPASS2 1661 -#define IDC_NEWPASSINFO 1679 -#define IDC_MODULES 1680 -#define IDC_NEWPASSINFO2 1680 -#define IDC_INFO 1682 -#define IDC_AUTHOR 1683 -#define IDC_NEWPASS1 1683 -#define IDC_SITE 1684 -#define IDC_NEWPASS2 1684 -#define IDC_EMAIL 1685 -#define IDC_UID 1686 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 276 -#define _APS_NEXT_COMMAND_VALUE 40018 -#define _APS_NEXT_CONTROL_VALUE 1685 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/Dbx_mmap_SA/security.cpp b/plugins/Dbx_mmap_SA/security.cpp deleted file mode 100644 index 4ecf5f745b..0000000000 --- a/plugins/Dbx_mmap_SA/security.cpp +++ /dev/null @@ -1,392 +0,0 @@ -// (C) Artem Shpynov aka FYR and Igonin Vitaliy aka chaos.persei, 2007 - 2008 - -#include "commonheaders.h" - -int wrongPass = 0; -void* key; - -Cryptor* CryptoEngine = NULL; - -LIST arCryptors(1); - -void zero_fill(BYTE * pBuf, size_t bufSize) -{ - size_t i; - for (i = 0; i < bufSize; i++) - pBuf[i] = 0; -} - -void InitSecurity() -{ - Cryptor* (__stdcall *GetCryptor)(); - - TCHAR tszPath[MAX_PATH]; - GetModuleFileName(g_hInst, tszPath, SIZEOF(tszPath)); - TCHAR *p = _tcsrchr(tszPath, '\\')+1; _tcscpy(p, _T("cryptors\\*.dll")); - - WIN32_FIND_DATA fd; - HANDLE hFile = FindFirstFile(tszPath, &fd); - while (hFile != INVALID_HANDLE_VALUE) { - mir_sntprintf(p, MAX_PATH - (p-tszPath), _T("cryptors\\%s"), fd.cFileName); - HMODULE hLib = LoadLibrary(tszPath); - if (hLib){ - GetCryptor = (Cryptor* (__stdcall *)()) GetProcAddress(hLib, "GetCryptor"); - if (GetCryptor){ - CryptoModule* newItem = (CryptoModule*) malloc(sizeof(CryptoModule)); - newItem->cryptor = GetCryptor(); - _tcsncpy(newItem->dllname, fd.cFileName, MAX_PATH); - newItem->hLib = hLib; - arCryptors.insert(newItem); - } - else FreeLibrary(hLib); - } - if (!FindNextFile(hFile, &fd)) - break; - } -} - -void UnloadSecurity() -{ - if (CryptoEngine) - CryptoEngine->FreeKey(key); - - for (int i = 0; i < arCryptors.getCount(); i++) { - FreeLibrary(arCryptors[i]->hLib); - free(arCryptors[i]); - } - arCryptors.destroy(); -} - -void CDdxMmapSA::EncoderInit() -{ - if (!m_bEncoding) return; - - encryptKey[encryptKeyLength] = 0; - key = CryptoEngine->GenerateKey(encryptKey); -} - -void CDdxMmapSA::EncodeCopyMemory(void * dst, void * src, size_t size ) -{ - memcpy(dst, src, size); - - if (!m_bEncoding) - return; - - CryptoEngine->EncryptMem((BYTE *)dst, (int)size, key); -} - -void CDdxMmapSA::DecodeCopyMemory(void * dst, void * src, size_t size ) -{ - memcpy(dst, src, size); - - if (!m_bEncoding) - return; - - CryptoEngine->DecryptMem((BYTE *)dst, (int)size, key); -} - -void CDdxMmapSA::EncodeDBWrite(DWORD ofs, void *src, int size) -{ - if (m_bEncoding) - { - BYTE * buf; - - buf = (BYTE*)GlobalAlloc(GPTR, sizeof(BYTE)*size); - EncodeCopyMemory(buf, src, size); - DBWrite(ofs, buf, (int)size); - GlobalFree(buf); - } - else - { - DBWrite(ofs, src, (int)size); - } -} - -void CDdxMmapSA::DecodeDBWrite(DWORD ofs, void *src, int size) -{ - if (m_bEncoding) { - BYTE *buf = (BYTE*)GlobalAlloc(GPTR, sizeof(BYTE)*size); - DecodeCopyMemory(buf, src, size); - DBWrite(ofs, buf, (int)size); - GlobalFree(buf); - } - else DBWrite(ofs, src, (int)size); -} - -int bCheckingPass = 0; - -int CDdxMmapSA::CheckPassword(WORD checkWord, TCHAR *szDBName) -{ - if (bCheckingPass) - return 0; - - bCheckingPass = 1; - - int Found = 0; - for (int i = 0; i < arCryptors.getCount(); i++) { - if ( HIWORD(m_dbHeader.version) == arCryptors[i]->cryptor->uid){ - CryptoEngine = arCryptors[i]->cryptor; - Found = 1; - break; - } - } - if (!Found){ - MessageBoxA(0, "Sorry, but your database encrypted with unknown module", "Error", MB_OK); - bCheckingPass = 0; - return 0; - } - - while(1) { - int res = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_LOGIN), NULL, (DLGPROC)DlgStdInProc, (LPARAM)szDBName); - if (res == IDCANCEL) { - wrongPass = 0; - bCheckingPass = 0; - return 0; - } - if (encryptKeyLength < 1) - continue; - - EncoderInit(); - - WORD ver; - DecodeCopyMemory(&ver, &checkWord, sizeof(checkWord)); - if (ver == 0x5195) { - wrongPass = 0; - bCheckingPass = 0; - return 1; - } - wrongPass++; - } - - bCheckingPass = 0; -} - -int SelectEncoder() -{ - WORD uid; - int i; - - if (arCryptors.getCount() == 0){ - MessageBox(0, TranslateT("Crypto modules not found"), TranslateT("Error"), MB_OK); - return 1; - } - - uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); - - if (uid == 0){ - MessageBox(0, TranslateT("Crypto module hasn't been chosen, using first one found"), TranslateT("Notice"), MB_OK); - DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[0]->cryptor->uid); - CryptoEngine = arCryptors[0]->cryptor; - } - else{ - int Found = 0; - for (i = 0; i < arCryptors.getCount(); i++) { - if (arCryptors[i]->cryptor->uid == uid){ - CryptoEngine = arCryptors[i]->cryptor; - Found = 1; - break; - } - } - if (!Found){ - MessageBox(0, TranslateT("Crypto module hasn't been chosen, using first one found"), TranslateT("Notice"), MB_OK); - DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[0]->cryptor->uid); - CryptoEngine = arCryptors[0]->cryptor; - } - } - - return 0; -} - -void CDdxMmapSA::EncodeAll() -{ - HANDLE hContact; - - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - if (hContact){ - do { - EncodeContactEvents(hContact); - EncodeContactSettings(hContact); - } - while(hContact = FindNextContact(hContact)); - } - - EncodeContactEvents(NULL); - EncodeContactSettings(NULL); -} - -void CDdxMmapSA::DecodeAll() -{ - HANDLE hContact; - - hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); - if (hContact){ - do{ - DecodeContactEvents(hContact); - DecodeContactSettings(hContact); - }while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)); - } - DecodeContactEvents(NULL); - DecodeContactSettings(NULL); -} - -void CDdxMmapSA::WritePlainHeader() -{ - DWORD bytesWritten; - - memcpy(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature)); - SetFilePointer(m_hDbFile,0,NULL,FILE_BEGIN); - WriteFile(m_hDbFile,m_dbHeader.signature,sizeof(m_dbHeader.signature),&bytesWritten,NULL); - - m_dbHeader.version = MAKELONG(0x0700, 0x0000); //no encryption - WriteFile(m_hDbFile,&m_dbHeader.version, sizeof(m_dbHeader.version),&bytesWritten,NULL); -} - -void CDdxMmapSA::WriteCryptHeader() -{ - DWORD bytesWritten; - - memcpy(m_dbHeader.signature, &dbSignatureSecured, sizeof(m_dbHeader.signature)); - SetFilePointer(m_hDbFile,0,NULL,FILE_BEGIN); - WriteFile(m_hDbFile,m_dbHeader.signature,sizeof(m_dbHeader.signature),&bytesWritten,NULL); - - WORD checkWord = 0x5195, cryptWord; - EncodeCopyMemory(&cryptWord, &checkWord, sizeof(checkWord)); - m_dbHeader.version = MAKELONG(cryptWord, CryptoEngine->uid); - WriteFile(m_hDbFile,&m_dbHeader.version, sizeof(m_dbHeader.version),&bytesWritten,NULL); -} - -void CDdxMmapSA::EncryptDB() -{ - int action = 0; - if (bEncProcess) - return; - - if (memcmp(m_dbHeader.signature, &dbSignatureSecured, sizeof(m_dbHeader.signature)) == 0){ - MessageBox(0, TranslateT("DB is already secured!"), TranslateT("Error"), MB_OK); - return; - } - - if (SelectEncoder()) { - return; - } - - bEncProcess = 1; - - action = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_NEWPASS), NULL, (DLGPROC)DlgStdNewPass, (LPARAM)NULL); - if (action != IDOK || !strlen(encryptKey)) { - bEncProcess = 0; - db_set_b(NULL, "SecureMMAP", "CryptoModule", 0); - return; - } - - EnterCriticalSection(&m_csDbAccess); - - m_bEncoding = 1; - EncoderInit(); - - EncodeAll(); - - LeaveCriticalSection(&m_csDbAccess); - - WriteCryptHeader(); - - xModifyMenu(hSetPwdMenu, 0, LPGENT("Change Password"), 0); - - bEncProcess = 0; -} - -void CDdxMmapSA::DecryptDB() -{ - char oldKey[255]; - strcpy(oldKey, encryptKey); - - if ( !CheckPassword( HIWORD(m_dbHeader.version), TranslateT("current database"))) { - strcpy(encryptKey, oldKey); - encryptKeyLength = strlen(oldKey); - return; - } - - WritePlainHeader(); - - EnterCriticalSection(&m_csDbAccess); - DecodeAll(); - LeaveCriticalSection(&m_csDbAccess); - - m_bEncoding = 0; - - zero_fill((BYTE *)encryptKey, sizeof encryptKey); - - xModifyMenu(hSetPwdMenu, 0, LPGENT("Set Password"), 0); - - DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); - - CryptoEngine->FreeKey(key); - - CryptoEngine = NULL; -} - -void CDdxMmapSA::RecryptDB() -{ - EnterCriticalSection(&m_csDbAccess); - - DecodeAll(); - - CryptoEngine->FreeKey(key); - - SelectEncoder(); - - m_bEncoding = 1; - - EncoderInit(); - - EncodeAll(); - - WriteCryptHeader(); - - LeaveCriticalSection(&m_csDbAccess); -} - -void CDdxMmapSA::ChangePwd() -{ - char newpass[255] = {0}; - - int action = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHANGEPASS), NULL, (DLGPROC)DlgChangePass, (LPARAM)newpass); - - if (action == IDCANCEL || (action == IDOK && !strlen(newpass))) - return; - - EnterCriticalSection(&m_csDbAccess); - - DecodeAll(); - - CryptoEngine->FreeKey(key); - - if (action == IDREMOVE){ - WritePlainHeader(); - - m_bEncoding = 0; - CryptoEngine = NULL; - DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); - - zero_fill((BYTE *)encryptKey, sizeof encryptKey); - - xModifyMenu(hSetPwdMenu, 0, LPGENT("Set Password"), 0); - } - - if (action == IDOK){ - strcpy(encryptKey, newpass); - encryptKeyLength = strlen(newpass); - - m_bEncoding = 1; - - EncoderInit(); - - EncodeAll(); - - WriteCryptHeader(); - } - - zero_fill((BYTE *)newpass, sizeof newpass); - - LeaveCriticalSection(&m_csDbAccess); -} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/src/commonheaders.h b/plugins/Dbx_mmap_SA/src/commonheaders.h new file mode 100644 index 0000000000..27c7036adf --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/commonheaders.h @@ -0,0 +1,119 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2003 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 _CRT_SECURE_NO_WARNINGS + +#define MIRANDA_VER 0x0A00 + +#define _WIN32_WINNT 0x0501 +#include "m_stdhdr.h" + +//windows headers + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//miranda headers +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//non-official miranda-plugins sdk +#include "m_folders.h" + +//own headers +#include "dbintf_sa.h" +#include "..\Db3x_mmap\src\database.h" +#include "resource.h" +#include "version.h" + +extern HINSTANCE g_hInst; +extern HANDLE hSetPwdMenu; + +#ifdef __GNUC__ +#define mir_i64(x) (x##LL) +#else +#define mir_i64(x) (x##i64) +#endif + +//global procedures +//int InitSkin(); +void EncodeCopyMemory(void * dst, void * src, size_t size ); +void DecodeCopyMemory(void * dst, void * src, size_t size ); +void EncodeDBWrite(DWORD ofs, void * src, size_t size); +void DecodeDBWrite(DWORD ofs, void * src, size_t size); + +BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam); +BOOL CALLBACK DlgStdNewPass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam); +BOOL CALLBACK DlgChangePass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam); +void xModifyMenu(HANDLE hMenu,long flags,const TCHAR* name, HICON hIcon); + +extern DBSignature dbSignature, dbSignatureSecured; + +extern LIST g_Dbs; + +int InitPreset(); +void UninitPreset(); + +typedef struct{ + void* (__stdcall *GenerateKey)(char* pwd); + void (__stdcall *FreeKey)(void* key); + void (__stdcall *EncryptMem)(BYTE* data, int size, void* key); + void (__stdcall *DecryptMem)(BYTE* data, int size, void* key); + + char* Name; + char* Info; + char* Author; + char* Site; + char* Email; + + DWORD Version; + + WORD uid; +} Cryptor; + +typedef struct{ + TCHAR dllname[MAX_PATH]; + HMODULE hLib; + Cryptor* cryptor; +} CryptoModule; + +extern Cryptor* CryptoEngine; +extern void* key; diff --git a/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp b/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp new file mode 100644 index 0000000000..b85b3481cb --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/dbintf_sa.cpp @@ -0,0 +1,234 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright 2012 Miranda NG 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 NeedBytes(n) if(bytesRemaining<(n)) pBlob=(PBYTE)DBRead(ofsBlobPtr,(n),&bytesRemaining) +#define MoveAlong(n) {int x=n; pBlob+=(x); ofsBlobPtr+=(x); bytesRemaining-=(x);} +#define VLT(n) ((n==DBVT_UTF8)?DBVT_ASCIIZ:n) + +extern CDdxMmapSA* g_Db; + +int InitDialogs(void); + +DBSignature dbSignatureSecured = {"Miranda ICQ SD",0x1A}; + +CDdxMmapSA::CDdxMmapSA(const TCHAR* tszFileName) : + CDdxMmap(tszFileName) +{ +} + +int CDdxMmapSA::Load(bool bSkipInit) +{ + if ( CDdxMmap::Load(bSkipInit) != ERROR_SUCCESS) + return 1; + + if ( CheckDbHeaders()) + return 1; + + if (!bSkipInit) { + TCHAR* p = _tcsrchr(m_tszProfileName, '\\'); + if (!p) + return 1; + + g_Db = this; + if (m_bEncoding && !CheckPassword( LOWORD(m_dbHeader.version), p+1)) + return 1; + + InitDialogs(); + } + + return 0; +} + +int CDdxMmapSA::CheckDbHeaders() +{ + if ( memcmp(m_dbHeader.signature, &dbSignatureSecured, sizeof(m_dbHeader.signature)) == 0) + m_bEncoding = true; + else { + m_bEncoding = false; + if ( memcmp(m_dbHeader.signature,&dbSignature,sizeof(m_dbHeader.signature))) + return 1; + if ( LOWORD(m_dbHeader.version) != 0x0700) + return 2; + } + if (m_dbHeader.ofsUser == 0) + return 3; + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// + +static DWORD __inline GetSettingValueLength(PBYTE pSetting) +{ + if(pSetting[0]&DBVTF_VARIABLELENGTH) return 2+*(PWORD)(pSetting+1); + return pSetting[0]; +} + +void CDdxMmapSA::EncodeContactSettings(HANDLE hContact) +{ + if (!hContact) + hContact = (HANDLE)m_dbHeader.ofsUser; + + DBContact *contact = (DBContact *)DBRead((DWORD)hContact, sizeof(DBContact), NULL); + if (contact->ofsFirstSettings) { + DBContactSettings *setting = (struct DBContactSettings *)DBRead(contact->ofsFirstSettings, sizeof(struct DBContactSettings), NULL); + DWORD offset = contact->ofsFirstSettings; + while( true ) { + DWORD ofsBlobPtr; + PBYTE pBlob; + int bytesRemaining; + DWORD len; + + ofsBlobPtr = offset + offsetof(struct DBContactSettings,blob); + pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); + while(pBlob[0]) { + NeedBytes(1); + NeedBytes(1+pBlob[0]); + MoveAlong(1+pBlob[0]); + + NeedBytes(5); + + switch(pBlob[0]) { + case DBVT_DELETED: break; + case DBVT_BYTE: break; + case DBVT_WORD: + CryptoEngine->EncryptMem(pBlob+1, 2, key); + break; + + case DBVT_DWORD: + CryptoEngine->EncryptMem(pBlob+1, 4, key); + break; + + case DBVT_UTF8: + case DBVT_ASCIIZ: + case DBVT_BLOB: + NeedBytes(3+*(PWORD)(pBlob+1)); + len = *(PWORD)(pBlob+1); + + CryptoEngine->EncryptMem(pBlob+3, len, key); + break; + } + NeedBytes(3); + MoveAlong(1+GetSettingValueLength(pBlob)); + NeedBytes(1); + } + + if (!setting->ofsNext) + break; + + offset = setting->ofsNext; + setting = (struct DBContactSettings *)DBRead(setting->ofsNext, sizeof(struct DBContactSettings), NULL); + } + } +} + +void CDdxMmapSA::DecodeContactSettings(HANDLE hContact) +{ + if (!hContact) + hContact = (HANDLE)m_dbHeader.ofsUser; + + DBContact *contact = (DBContact *)DBRead((DWORD)hContact, sizeof(DBContact), NULL); + if (contact->ofsFirstSettings){ + DBContactSettings *setting = (struct DBContactSettings *)DBRead(contact->ofsFirstSettings, sizeof(struct DBContactSettings), NULL); + DWORD offset = contact->ofsFirstSettings; + while (true) { + DWORD ofsBlobPtr; + PBYTE pBlob; + int bytesRemaining; + DWORD len; + ofsBlobPtr = offset + offsetof(struct DBContactSettings,blob); + pBlob = (PBYTE)DBRead(ofsBlobPtr,1,&bytesRemaining); + while(pBlob[0]) { + NeedBytes(1); + NeedBytes(1+pBlob[0]); + //CopyMemory(szSetting,pBlob+1,pBlob[0]); szSetting[pBlob[0]] = 0; + MoveAlong(1+pBlob[0]); + + NeedBytes(5); + + switch(pBlob[0]) { + case DBVT_DELETED: break; + case DBVT_BYTE: break; + case DBVT_WORD: + CryptoEngine->DecryptMem(pBlob+1, 2, key); + break; + + case DBVT_DWORD: + CryptoEngine->DecryptMem(pBlob+1, 4, key); + break; + + case DBVT_UTF8: + case DBVT_ASCIIZ: + case DBVT_BLOB: + NeedBytes(3+*(PWORD)(pBlob+1)); + len = *(PWORD)(pBlob+1); + + CryptoEngine->DecryptMem(pBlob+3, len, key); + break; + } + NeedBytes(3); + MoveAlong(1+GetSettingValueLength(pBlob)); + NeedBytes(1); + } + + if (!setting->ofsNext) + break; + + offset = setting->ofsNext; + setting = (struct DBContactSettings *)DBRead(setting->ofsNext, sizeof(struct DBContactSettings), NULL); + } + } +} + +void CDdxMmapSA::EncodeEvent(HANDLE hEvent) +{ + DBEvent *dbe = (DBEvent*)DBRead((DWORD)hEvent,sizeof(DBEvent),NULL); + if (dbe->signature = DBEVENT_SIGNATURE) + CryptoEngine->EncryptMem(DBRead((DWORD)hEvent + offsetof(DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key); +} + +void CDdxMmapSA::DecodeEvent(HANDLE hEvent) +{ + DBEvent *dbe = (DBEvent*)DBRead((DWORD)hEvent,sizeof(DBEvent),NULL); + if (dbe->signature = DBEVENT_SIGNATURE) + CryptoEngine->DecryptMem(DBRead((DWORD)hEvent + offsetof(DBEvent,blob), dbe->cbBlob, NULL), dbe->cbBlob, key); +} + +void CDdxMmapSA::EncodeContactEvents(HANDLE hContact) +{ + HANDLE hEvent = FindFirstEvent(hContact); + while (hEvent != 0) { + EncodeEvent(hEvent); + hEvent = FindNextEvent(hEvent); + } +} + +void CDdxMmapSA::DecodeContactEvents(HANDLE hContact) +{ + HANDLE hEvent = FindFirstEvent(hContact); + while (hEvent != 0) { + DecodeEvent(hEvent); + hEvent = FindNextEvent(hEvent); + } +} diff --git a/plugins/Dbx_mmap_SA/src/dbintf_sa.h b/plugins/Dbx_mmap_SA/src/dbintf_sa.h new file mode 100644 index 0000000000..8c6c9c04dc --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/dbintf_sa.h @@ -0,0 +1,71 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright 2012 Miranda NG 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 + +#include "..\Db3x_mmap\src\dbintf.h" + +struct CDdxMmapSA : public CDdxMmap +{ + CDdxMmapSA(const TCHAR* tszFileName); + + int CheckPassword(WORD checkWord, TCHAR *szDBName); + int CheckDbHeaders(void); + + void ChangePwd(); + void EncryptDB(); + void DecryptDB(); + void RecryptDB(); + + int Load(bool bSkipInit); + + bool m_bEncoding, bEncProcess; + +protected: + virtual void EncodeCopyMemory(void *dst, void *src, size_t size); + virtual void DecodeCopyMemory(void *dst, void *src, size_t size); + virtual void EncodeDBWrite(DWORD ofs, void *src, int size); + virtual void DecodeDBWrite(DWORD ofs, void *src, int size); + +protected: + int CheckProto(HANDLE hContact, const char *proto); + + void EncoderInit(); + void EncodeContactEvents(HANDLE hContact); + void EncodeEvent(HANDLE hEvent); + void DecodeEvent(HANDLE hEvent); + void DecodeContactEvents(HANDLE hContact); + + void DecodeContactSettings(HANDLE hContact); + void EncodeContactSettings(HANDLE hContact); + + void WritePlainHeader(); + void WriteCryptHeader(); + + void EncodeAll(); + void DecodeAll(); + +public: + char encryptKey[255]; + size_t encryptKeyLength; +}; diff --git a/plugins/Dbx_mmap_SA/src/dbpreset.cpp b/plugins/Dbx_mmap_SA/src/dbpreset.cpp new file mode 100644 index 0000000000..564bbf3c40 --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/dbpreset.cpp @@ -0,0 +1,296 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2003 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. +*/ +// Miranda Memory-Mapped Secured DataBase +// (C) Artem Shpynov aka FYR, Igonin Vitaliy aka chaos.persei, Victor Pavlychko aka nullbie, 2007 - 2008 + +#include "commonheaders.h" + +/* Public API */ +int DBPreset_QuerySetting (const char *szModule, const char *szSetting, DBVARIANT *dbv, BOOL isStatic); +int DBPreset_CompareSetting (const char *szModule, const char *szSetting, DBVARIANT *dbv); + +/* Preset cache item */ +typedef struct +{ + DWORD dwHash; + char *szModule; + char *szSetting; + DBVARIANT dbv; +} DBPresetItem; + +static DBPresetItem * DBPresetItem_Create (char *szModule, char *szSetting, BYTE bType); +static void DBPresetItem_Destroy (DBPresetItem *item); +static void DBPresetItem_Hash (DBPresetItem *item); +static int DBPresetItem_Cmp (DBPresetItem *item1, DBPresetItem *item2); + +SortedList *lstPresets = NULL; + +int InitPreset() +{ + char szIniPath[MAX_PATH]; + char szLine[2048]; + int lineLength; + char szSection[128]; + FILE *fp; + + GetModuleFileNameA(GetModuleHandle(NULL), szIniPath, SIZEOF(szIniPath)); + strcpy(strrchr(szIniPath, '\\')+1, "dbpreset.ini"); + + fp = fopen(szIniPath,"rt"); + + // no preset + if (!fp) return 0; + + lstPresets = List_Create(0, 50); + lstPresets->sortFunc = (FSortFunc)DBPresetItem_Cmp; + + while(!feof(fp)) + { + if (fgets(szLine,sizeof(szLine),fp) == NULL) break; + lineLength = lstrlenA(szLine); + while(lineLength && (BYTE)(szLine[lineLength-1]) <= ' ') szLine[--lineLength] = '\0'; + if (szLine[0] == ';' || szLine[0] <= ' ') continue; + if (szLine[0] == '[') + { + char *szEnd = strchr(szLine+1,']'); + if (szEnd == NULL) continue; + if (szLine[1] == '!') + szSection[0] = '\0'; + else + lstrcpynA(szSection, szLine+1, (int)min(sizeof(szSection), szEnd-szLine)); + } else + { + char *szValue; + char szName[128]; + DBPresetItem *item; + + if (szSection[0] == '\0') continue; + szValue = strchr(szLine,' = '); + if (szValue == NULL) continue; + lstrcpynA(szName, szLine, (int)min(sizeof(szName), szValue-szLine+1)); + szValue++; + + switch(szValue[0]) + { + case 'b': + case 'B': + item = DBPresetItem_Create(szSection, szName, DBVT_BYTE); + item->dbv.bVal = (BYTE)strtol(szValue+1,NULL,0); + List_InsertPtr(lstPresets, item); + break; + case 'w': + case 'W': + item = DBPresetItem_Create(szSection, szName, DBVT_WORD); + item->dbv.wVal = (WORD)strtol(szValue+1,NULL,0); + List_InsertPtr(lstPresets, item); + break; + case 'd': + case 'D': + item = DBPresetItem_Create(szSection, szName, DBVT_DWORD); + item->dbv.dVal = (DWORD)strtoul(szValue+1,NULL,0); + List_InsertPtr(lstPresets, item); + break; + case 's': + case 'S': + item = DBPresetItem_Create(szSection, szName, DBVT_ASCIIZ); + item->dbv.pszVal = mir_strdup(szValue+1); + List_InsertPtr(lstPresets, item); + break; + case 'u': + case 'U': + item = DBPresetItem_Create(szSection, szName, DBVT_UTF8); + item->dbv.pszVal = mir_strdup(szValue+1); + List_InsertPtr(lstPresets, item); + break; + case 'n': + case 'N': + { + PBYTE buf; + int len; + char *pszValue,*pszEnd; + + buf = (PBYTE)mir_alloc(lstrlenA(szValue+1)); + for (len = 0,pszValue = szValue+1;;len++) { + buf[len] = (BYTE)strtol(pszValue,&pszEnd,0x10); + if (pszValue == pszEnd) break; + pszValue = pszEnd; + } + + item = DBPresetItem_Create(szSection, szName, DBVT_BLOB); + item->dbv.pbVal = buf; + item->dbv.cpbVal = len; + List_InsertPtr(lstPresets, item); + break; + } + } + } + } + fclose(fp); + + return 0; +} + +void UninitPreset() +{ + int i; + if (!lstPresets) return; + for (i = 0; i < lstPresets->realCount; ++i) + DBPresetItem_Destroy((DBPresetItem *)lstPresets->items[i]); + List_Destroy(lstPresets); +} + +int DBPreset_QuerySetting(const char *szModule, const char *szSetting, DBVARIANT *dbv, BOOL isStatic) +{ + DBPresetItem *item; + DBPresetItem search = {0}; + + if (!lstPresets) return FALSE; + + search.szModule = (char *)szModule; + search.szSetting = (char *)szSetting; + DBPresetItem_Hash(&search); + item = (DBPresetItem *)List_Find(lstPresets, &search); + + if (!item) return FALSE; + + dbv->type = item->dbv.type; + switch (item->dbv.type) + { + case DBVT_BYTE: dbv->bVal = item->dbv.bVal; return TRUE; + case DBVT_WORD: dbv->wVal = item->dbv.wVal; return TRUE; + case DBVT_DWORD: dbv->dVal = item->dbv.dVal; return TRUE; + + case DBVT_UTF8: + case DBVT_ASCIIZ: + if (isStatic && dbv->pszVal) + lstrcpynA(dbv->pszVal, item->dbv.pszVal, dbv->cchVal); + else if (!isStatic) + dbv->pszVal = mir_strdup(item->dbv.pszVal); + return TRUE; + + default: + return FALSE; + } + + return FALSE; +} + +int DBPreset_CompareSetting(const char *szModule, const char *szSetting, DBVARIANT *dbv) +{ + DBPresetItem *item; + DBPresetItem search = {0}; + + if (!lstPresets) return FALSE; + + search.szModule = (char *)szModule; + search.szSetting = (char *)szSetting; + DBPresetItem_Hash(&search); + item = (DBPresetItem *)List_Find(lstPresets, &search); + + if (!item) return FALSE; + if (item->dbv.type != item->dbv.type) return FALSE; + switch (item->dbv.type) + { + case DBVT_BYTE: return dbv->bVal == item->dbv.bVal ? TRUE : FALSE; + case DBVT_WORD: return dbv->wVal == item->dbv.wVal ? TRUE : FALSE; + case DBVT_DWORD: return dbv->dVal == item->dbv.dVal ? TRUE : FALSE; + case DBVT_UTF8: + case DBVT_ASCIIZ: return strcmp(dbv->pszVal, item->dbv.pszVal) ? FALSE : TRUE; + } + + return FALSE; +} + +static DBPresetItem *DBPresetItem_Create(char *szModule, char *szSetting, BYTE bType) +{ + DBPresetItem *item = (DBPresetItem *)mir_alloc(sizeof(DBPresetItem)); + item->szModule = mir_strdup(szModule); + item->szSetting = mir_strdup(szSetting); + DBPresetItem_Hash(item); + item->dbv.type = bType; + return item; +} + +static void DBPresetItem_Destroy(DBPresetItem *item) +{ + if (!item) return; + if (item->szModule) + { + mir_free(item->szModule); + item->szModule = NULL; + } + if (item->szSetting) + { + mir_free(item->szSetting); + item->szSetting = NULL; + } + + switch (item->dbv.type) + { + case DBVT_ASCIIZ: + case DBVT_UTF8: + case DBVT_WCHAR: + { + if (item->dbv.pszVal) + mir_free(item->dbv.pszVal); + item->dbv.pszVal = 0; + break; + } + case DBVT_BLOB: + { + if (item->dbv.pbVal) + mir_free(item->dbv.pbVal); + item->dbv.pbVal = 0; + break; + } + } + item->dbv.type = 0; +} + +static void DBPresetItem_Hash(DBPresetItem *item) +{ + int i; + int shift = 0; + item->dwHash = 0; + for (i = 0;item->szModule[i];i++) + { + item->dwHash ^= item->szModule[i]<24) item->dwHash ^= (item->szModule[i]>>(32-shift))&0x7F; + shift = (shift+5)&0x1F; + } + for (i = 0;item->szSetting[i];i++) + { + item->dwHash ^= item->szSetting[i]<24) item->dwHash ^= (item->szSetting[i]>>(32-shift))&0x7F; + shift = (shift+5)&0x1F; + } +} + +static int DBPresetItem_Cmp(DBPresetItem *item1, DBPresetItem *item2) +{ + int cmp; + if (item1->dwHash < item2->dwHash) return -1; + if (item1->dwHash > item2->dwHash) return 1; + if (cmp = strcmp(item1->szModule, item2->szModule)) return cmp; + return strcmp(item1->szSetting, item2->szSetting); +} diff --git a/plugins/Dbx_mmap_SA/src/dialogs.cpp b/plugins/Dbx_mmap_SA/src/dialogs.cpp new file mode 100644 index 0000000000..8445b69ef7 --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/dialogs.cpp @@ -0,0 +1,543 @@ +#include "commonheaders.h" +#include +#include +#include +#include + +#define MS_DB_CHANGEPASSWORD "DB/ChangePassword" + +extern LIST arCryptors; + +CDdxMmapSA* g_Db; +HANDLE hSetPwdMenu; + +INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +BOOL ShowDlgItem(HWND hwndDlg, int iIDCtrl, BOOL bShow) +{ + HWND hwndCtrl = GetDlgItem(hwndDlg, iIDCtrl); + if (!hwndCtrl) return FALSE; + + // Avoid flickering + if (bShow && IsWindowVisible(hwndCtrl)) + return TRUE; + + return ShowWindow(hwndCtrl, (bShow ? SW_SHOW : SW_HIDE)); +} + +BOOL EnableDlgItem(HWND hwndDlg, int iIDCtrl, BOOL bEnable) +{ + HWND hwndCtrl = GetDlgItem(hwndDlg, iIDCtrl); + if (!hwndCtrl) return FALSE; + + // Avoid flickering + if (IsWindowEnabled(hwndCtrl) == bEnable) + return (bEnable == FALSE); + + return EnableWindow(hwndCtrl, bEnable); +} + +BOOL IsDlgItemEnabled(HWND hwndDlg, int iIDCtrl) +{ + HWND hwndCtrl = GetDlgItem(hwndDlg, iIDCtrl); + if (!hwndCtrl) return FALSE; + return IsWindowEnabled(hwndCtrl); +} + +static int OptionsInit(WPARAM wParam, LPARAM lParam) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + odp.cbSize = sizeof(odp); + odp.position = -790000000; + odp.hInstance = g_hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); + odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR; + odp.ptszTitle = LPGENT("Database Features"); + odp.ptszGroup = LPGENT("Services"); + odp.pfnDlgProc = DlgProcOptions; + Options_AddPage(wParam, &odp); + return 0; +} + +INT_PTR ChangePassword(WPARAM wParam, LPARAM lParam) +{ + if (g_Db->m_bEncoding) + g_Db->ChangePwd(); + else + g_Db->EncryptDB(); + + return 0; +} + +void xModifyMenu(HANDLE hMenu,long flags,const TCHAR* name, HICON hIcon) +{ + CLISTMENUITEM menu; + ZeroMemory(&menu,sizeof(menu)); + menu.cbSize = sizeof(menu); + menu.flags = CMIM_FLAGS | CMIF_TCHAR; + menu.flags |= name ? CMIM_NAME : 0; + menu.flags |= hIcon ? CMIM_ICON : 0; + menu.flags |= flags; + menu.ptszName = (TCHAR*)name; + menu.hIcon = hIcon; + + CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)hMenu,(LPARAM)&menu); +} + +int InitMenus(WPARAM, LPARAM) +{ + HookEvent(ME_OPT_INITIALISE, OptionsInit); + + TCHAR szFile[MAX_PATH]; + GetModuleFileName(g_hInst, szFile, MAX_PATH); + + SKINICONDESC sid = {0}; + sid.cbSize = sizeof(sid); + sid.ptszDefaultFile = szFile; + sid.flags = SIDF_ALL_TCHAR; + sid.ptszSection = LPGENT("Database"); + sid.ptszDescription = LPGENT("Database"); + sid.pszName = "database"; + sid.iDefaultIndex = -IDI_ICON2; + Skin_AddIcon(&sid); + + sid.ptszDescription = LPGENT("Change Password"); + sid.pszName = "password"; + sid.iDefaultIndex = -IDI_ICON3; + HANDLE hIcon = Skin_AddIcon(&sid); + + // main menu item + CLISTMENUITEM menu = {0}; + menu.cbSize = sizeof(menu); + menu.flags = CMIM_ALL | CMIF_TCHAR | CMIF_ICONFROMICOLIB; + menu.icolibItem = hIcon; + menu.ptszName = (g_Db->m_bEncoding) ? LPGENT("Change password") : LPGENT("Set password"); + menu.ptszPopupName = LPGENT("Database"); + menu.pszService = MS_DB_CHANGEPASSWORD; + menu.position = 500100000; + hSetPwdMenu = Menu_AddMainMenuItem(&menu); + return 0; +} + +int InitDialogs() +{ + HookEvent(ME_SYSTEM_MODULESLOADED, InitMenus); + CreateServiceFunction(MS_DB_CHANGEPASSWORD, ChangePassword); + return 0; +} + +int ImageList_AddIcon_IconLibLoaded(HIMAGELIST hIml, char* name) +{ + HICON hIcon = (HICON)CallService(MS_SKIN2_GETICON, (WPARAM)NULL, (LPARAM)name); + int res = ImageList_AddIcon(hIml, hIcon); + return res; +} + +INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HWND hwndList = GetDlgItem(hwndDlg, IDC_MODULES); + LVCOLUMN col; + LVITEM item; + int i, iRow, iIndex; + NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; + WORD uid; + HIMAGELIST hIml; + + switch ( msg ) { + case WM_INITDIALOG: + hIml = ImageList_Create(16, 16, ILC_MASK | (IsWinVerXPPlus()? ILC_COLOR32 : ILC_COLOR16), 2, 0); + TranslateDialogDefault( hwndDlg ); + + ImageList_AddIcon_IconLibLoaded( hIml, "core_main_29" ); + ImageList_AddIcon_IconLibLoaded( hIml, "core_main_30" ); + ListView_SetImageList( hwndList, hIml, LVSIL_SMALL ); + + col.pszText = NULL; + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 50; + ListView_InsertColumn(hwndList, 1, &col); + + col.pszText = TranslateT("Dll"); + col.mask = LVCF_TEXT | LVCF_WIDTH; + col.fmt = LVCFMT_LEFT; + col.cx = 1000; + ListView_InsertColumn(hwndList, 2, &col); + + col.pszText = TranslateT("Name"); + col.cx = 1000; + ListView_InsertColumn(hwndList, 3, &col); + + col.pszText = TranslateT("Version"); + col.cx = 1000; + ListView_InsertColumn(hwndList, 4, &col); + + ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT | LVS_EX_SUBITEMIMAGES); + + uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); + + for (i = 0; i < arCryptors.getCount(); i++) { + TCHAR buf[100]; + + item.mask = LVIF_TEXT; + item.iItem = i; + item.iSubItem = 0; + item.pszText = NULL; + iRow = ListView_InsertItem(hwndList, &item); + + ListView_SetItemText(hwndList, iRow, 1, arCryptors[i]->dllname); + _tcsncpy(buf, _A2T(arCryptors[i]->cryptor->Name), SIZEOF(buf)); + ListView_SetItemText(hwndList, iRow, 2, buf); + mir_sntprintf(buf,SIZEOF(buf),_T("%d.%d.%d.%d"), HIBYTE(HIWORD(arCryptors[i]->cryptor->Version)), LOBYTE(HIWORD(arCryptors[i]->cryptor->Version)), HIBYTE(LOWORD(arCryptors[i]->cryptor->Version)), LOBYTE(LOWORD(arCryptors[i]->cryptor->Version))); + ListView_SetItemText(hwndList, iRow, 3, buf); + + if (uid == arCryptors[i]->cryptor->uid && g_Db->m_bEncoding) + ListView_SetCheckState(hwndList, i, 1); + + item.mask = LVIF_IMAGE; + item.iItem = iRow; + item.iSubItem = 0; + item.iImage = ( CryptoEngine == arCryptors[i]->cryptor && g_Db->m_bEncoding ) ? 0 : 1; + ListView_SetItem( hwndList, &item ); + } + + ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 2, LVSCW_AUTOSIZE); + ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); + return TRUE; + + case WM_COMMAND: + if ( HIWORD(wParam) == STN_CLICKED ) { + switch (LOWORD(wParam)) { + case IDC_EMAIL: + case IDC_SITE: + { + char buf[512]; + char * p = &buf[7]; + lstrcpyA(buf,"mailto:"); + if ( GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), p, SIZEOF(buf) - 7)) { + CallService(MS_UTILS_OPENURL,0,(LPARAM) (LOWORD(wParam) == IDC_EMAIL ? buf : p)); + } + break; + } } } + break; + + case WM_NOTIFY: + if ( hdr && hdr->hdr.code == LVN_ITEMCHANGED && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) { + iIndex = hdr->iItem; + if (hdr->uNewState & 0x2000){ + for (i = 0; i < arCryptors.getCount(); i++) { + if (i != iIndex) ListView_SetCheckState(hwndList, i, 0); + } + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + if (hdr->uNewState & 0x1000){ + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + if (hdr->uNewState & LVIS_SELECTED){ + SetDlgItemTextA(hwndDlg, IDC_AUTHOR, arCryptors[iIndex]->cryptor->Author); + { + TCHAR* info_t = mir_a2t((char*)(arCryptors[iIndex]->cryptor->Info)); + SetDlgItemText(hwndDlg, IDC_INFO, TranslateTS(info_t)); + mir_free(info_t); + } + SetDlgItemTextA(hwndDlg, IDC_SITE, arCryptors[iIndex]->cryptor->Site); + SetDlgItemTextA(hwndDlg, IDC_EMAIL, arCryptors[iIndex]->cryptor->Email); + SetDlgItemTextA(hwndDlg, IDC_ENC, arCryptors[iIndex]->cryptor->Name); + SetDlgItemInt(hwndDlg, IDC_UID, arCryptors[iIndex]->cryptor->uid, 0); + } else { + SetDlgItemTextA(hwndDlg, IDC_AUTHOR, ""); + SetDlgItemTextA(hwndDlg, IDC_INFO, ""); + SetDlgItemTextA(hwndDlg, IDC_SITE, ""); + SetDlgItemTextA(hwndDlg, IDC_EMAIL, ""); + SetDlgItemTextA(hwndDlg, IDC_ENC, ""); + SetDlgItemTextA(hwndDlg, IDC_UID, ""); + } + + break; + } + if (((LPNMHDR)lParam)->code == PSN_APPLY ) { + int alg = -1; + for (i = 0; i < arCryptors.getCount(); i++) { + if (ListView_GetCheckState(hwndList, i)) { + alg = i; + break; + } + } + + if (alg > -1){ + if (!g_Db->m_bEncoding){ + DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[alg]->cryptor->uid); + g_Db->EncryptDB(); + } + else { + if (arCryptors[alg]->cryptor->uid != DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", -1)) { + DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[alg]->cryptor->uid); + g_Db->RecryptDB(); + } + } + } + else if (g_Db->m_bEncoding) + g_Db->DecryptDB(); + + uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); + + for (i = 0; i < arCryptors.getCount(); i++) { + if (uid == arCryptors[i]->cryptor->uid && g_Db->m_bEncoding) + ListView_SetCheckState(hwndList, i, 1); + + item.mask = LVIF_IMAGE; + item.iItem = i; + item.iSubItem = 0; + item.iImage = ( CryptoEngine == arCryptors[i]->cryptor && g_Db->m_bEncoding ) ? 0 : 1; + + ListView_SetItem( hwndList, &item ); + } + + return TRUE; + + } + break; + } + + return FALSE; +} + +UINT oldLangID = 0; +void LanguageChanged(HWND hDlg) +{ + UINT LangID = (UINT)GetKeyboardLayout(0); + char Lang[3] = {0}; + if (LangID != oldLangID) + { + oldLangID = LangID; + GetLocaleInfoA(MAKELCID((LangID & 0xffffffff), SORT_DEFAULT), LOCALE_SABBREVLANGNAME, Lang, 2); + Lang[0] = toupper(Lang[0]); + Lang[1] = tolower(Lang[1]); + SetDlgItemTextA(hDlg, IDC_LANG, Lang); + } +} + +extern BOOL wrongPass; + +BOOL CALLBACK DlgStdInProc(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) +{ + HICON hIcon = 0; + TCHAR tszHeaderTxt[256]; + + switch(uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hDlg); + + hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON2)); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); + + if (!wrongPass) { + mir_sntprintf(tszHeaderTxt, SIZEOF(tszHeaderTxt), _T("%s\n%s"), TranslateT("Please type in your password for"), (TCHAR*)lParam); + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), tszHeaderTxt); + } + else { + if (wrongPass > 2) { + HWND hwndCtrl = GetDlgItem(hDlg, IDC_USERPASS); + EnableWindow(hwndCtrl, FALSE); + hwndCtrl = GetDlgItem(hDlg, IDOK); + EnableWindow(hwndCtrl, FALSE); + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Too many errors!")); + } + else SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is not correct!")); + } + oldLangID = 0; + SetTimer(hDlg,1,200,NULL); + LanguageChanged(hDlg); + return TRUE; + + case WM_CTLCOLORSTATIC: + if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) { + SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetBkMode((HDC)wParam, TRANSPARENT); + return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); + } + return FALSE; + + case WM_COMMAND: + switch( LOWORD(wParam)) { + case IDOK: + if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) { + g_Db->encryptKeyLength = GetDlgItemTextA(hDlg, IDC_USERPASS, g_Db->encryptKey, 254); + EndDialog(hDlg,IDOK); + } + break; + + case IDCANCEL: + EndDialog(hDlg,IDCANCEL); + } + break; + + case WM_TIMER: + LanguageChanged(hDlg); + return FALSE; + + case WM_DESTROY: + KillTimer(hDlg, 1); + DestroyIcon(hIcon); + } + + return FALSE; +} + +BOOL CALLBACK DlgStdNewPass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) +{ + HICON hIcon = 0; + + switch(uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hDlg); + + hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON2)); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); + + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Please enter your new password")); + + oldLangID = 0; + SetTimer(hDlg,1,200,NULL); + LanguageChanged(hDlg); + return TRUE; + + case WM_CTLCOLORSTATIC: + if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) { + SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetBkMode((HDC)wParam, TRANSPARENT); + return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); + } + return FALSE; + + case WM_COMMAND: + { + UINT uid = LOWORD(wParam); + if (uid == IDOK) { + if (!GetWindowLongPtr(hDlg,GWLP_USERDATA)) { + char pass1[255], pass2[255]; + if (GetDlgItemTextA(hDlg, IDC_USERPASS1, pass1, 254) < 3){ + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is too short!")); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); + SetDlgItemTextA(hDlg,IDC_USERPASS1,""); + SetDlgItemTextA(hDlg,IDC_USERPASS2,""); + } + else { + GetDlgItemTextA(hDlg, IDC_USERPASS2, pass2, 254); + if (!strcmp(pass1, pass2)) { + g_Db->encryptKeyLength = strlen(pass1); + strcpy(g_Db->encryptKey, pass1); + EndDialog(hDlg,IDOK); + } + else { + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Passwords do not match!")); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); + SetDlgItemTextA(hDlg,IDC_USERPASS1,""); + SetDlgItemTextA(hDlg,IDC_USERPASS2,""); + } + } + } + } + else if (uid == IDCANCEL) + EndDialog(hDlg,IDCANCEL); + } + break; + + case WM_TIMER: + LanguageChanged(hDlg); + return FALSE; + + case WM_DESTROY: + KillTimer(hDlg, 1); + DestroyIcon(hIcon); + return FALSE; + } + return FALSE; +} + +char* newPass; + +BOOL CALLBACK DlgChangePass(HWND hDlg, UINT uMsg,WPARAM wParam,LPARAM lParam) +{ + HICON hIcon = 0; + + switch(uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hDlg); + + hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_ICON2)); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_SETICON, 0, (LPARAM)hIcon); + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Change password")); + + newPass = (char*)lParam; + oldLangID = 0; + SetTimer(hDlg,1,200,NULL); + LanguageChanged(hDlg); + + return TRUE; + + case WM_CTLCOLORSTATIC: + if ((HWND)lParam == GetDlgItem(hDlg, IDC_LANG)) { + SetTextColor((HDC)wParam, GetSysColor(COLOR_HIGHLIGHTTEXT)); + SetBkMode((HDC)wParam, TRANSPARENT); + return (BOOL)GetSysColorBrush(COLOR_HIGHLIGHT); + } + + return FALSE; + + case WM_COMMAND: + { + UINT uid = LOWORD(wParam); + if (uid == IDOK) { + char pass1[255], pass2[255], oldpass[255]; + GetDlgItemTextA(hDlg, IDC_OLDPASS, oldpass, 254); + if (strcmp(oldpass, g_Db->encryptKey)) { + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Wrong password!")); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); + break; + } + if (GetDlgItemTextA(hDlg, IDC_NEWPASS1, pass1, 254) < 3){ + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Password is too short!")); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); + + } + else { + GetDlgItemTextA(hDlg, IDC_NEWPASS2, pass2, 254); + if (!strcmp(pass1, pass2)) { + strcpy(newPass, pass1); + EndDialog(hDlg,IDOK); + } + else { + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Passwords do not match!")); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); + } + } + } + else if (uid == IDCANCEL) + EndDialog(hDlg,IDCANCEL); + else if (uid == IDREMOVE) { + char oldpass[255]; + GetDlgItemTextA(hDlg, IDC_OLDPASS, oldpass, 254); + if (strcmp(oldpass, g_Db->encryptKey)) { + SetWindowText(GetDlgItem(hDlg, IDC_HEADERBAR), TranslateT("Wrong password!")); + SendMessage(GetDlgItem(hDlg, IDC_HEADERBAR), WM_NCPAINT, 0, 0); + break; + } + EndDialog(hDlg, IDREMOVE); + } + } + break; + + case WM_TIMER: + LanguageChanged(hDlg); + return FALSE; + + case WM_DESTROY: + KillTimer(hDlg, 1); + return FALSE; + } + return FALSE; +} diff --git a/plugins/Dbx_mmap_SA/src/init.cpp b/plugins/Dbx_mmap_SA/src/init.cpp new file mode 100644 index 0000000000..2566e14471 --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/init.cpp @@ -0,0 +1,168 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2003 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" + +void InitSecurity(void); +void UnloadSecurity(void); + +int hLangpack; + +HINSTANCE g_hInst = NULL; + +PLUGININFOEX pluginInfo = { + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + __VERSION_DWORD, + "Provides Miranda database support: global settings, contacts, history, settings per contact. Enhanced modification with Encryption support.", + "Miranda-IM project, modification by FYR and chaos.persei, nullbie, Billy_Bons", + "chaos.persei@gmail.com; ashpynov@gmail.com; bio@msx.ru; ghazan@miranda.im", + "Copyright 2000-2011 Miranda IM project, FYR, chaos.persei, induction, nullbie", + "http://dbmmapmod.googlecode.com/", + UNICODE_AWARE, + // {28FF9B91-3E4D-4f1c-B47C-C641B037FF40} + { 0x28ff9b91, 0x3e4d, 0x4f1c, { 0xb4, 0x7c, 0xc6, 0x41, 0xb0, 0x37, 0xff, 0x40 } } +}; + +LIST g_Dbs(1, (LIST::FTSortFunc)HandleKeySort); + +///////////////////////////////////////////////////////////////////////////////////////// + +// returns 0 if the profile is created, EMKPRF* +static int makeDatabase(const TCHAR *profile, int *error) +{ + CDdxMmapSA *tmp = new CDdxMmapSA(profile); + if (tmp->Create() == ERROR_SUCCESS) { + tmp->CreateDbHeaders(); + delete tmp; + return 0; + } + delete tmp; + if (error != NULL) *error = EMKPRF_CREATEFAILED; + return 1; +} + +// returns 0 if the given profile has a valid header +static int grokHeader(const TCHAR *profile, int *error) +{ + CDdxMmapSA *tmp = new CDdxMmapSA(profile); + if (tmp->Load(true) != ERROR_SUCCESS) { + delete tmp; + if (error != NULL) *error = EGROKPRF_CANTREAD; + return 1; + } + + int chk = tmp->CheckDbHeaders(); + delete tmp; + if ( chk == 0 ) { + // all the internal tests passed, hurrah + if (error != NULL) *error = 0; + return 0; + } + + // didn't pass at all, or some did. + switch ( chk ) { + case 1: + // "Miranda ICQ DB" wasn't present + if (error != NULL) *error = EGROKPRF_UNKHEADER; + break; + + case 2: + // header was present, but version information newer + if (error != NULL) *error = EGROKPRF_VERNEWER; + break; + + case 3: + // header/version OK, internal data missing + if (error != NULL) *error = EGROKPRF_DAMAGED; + break; + } + + return 1; +} + +// returns 0 if all the APIs are injected otherwise, 1 +static MIDatabase* LoadDatabase(const TCHAR *profile) +{ + // set the memory, lists & UTF8 manager + mir_getLP( &pluginInfo ); + + CDdxMmapSA* db = new CDdxMmapSA(profile); + if (db->Load(false) != ERROR_SUCCESS) { + delete db; + return NULL; + } + + g_Dbs.insert(db); + return db; +} + +static int UnloadDatabase(MIDatabase* db) +{ + g_Dbs.remove((CDdxMmapSA*)db); + delete (CDdxMmapSA*)db; + return 0; +} + +static DATABASELINK dblink = +{ + sizeof(DATABASELINK), + "db3x secure mmap driver", + _T("db3x secure mmap database support"), + makeDatabase, + grokHeader, + LoadDatabase, + UnloadDatabase +}; + +///////////////////////////////////////////////////////////////////////////////////////// + +extern "C" __declspec(dllexport) PLUGININFOEX * MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_DATABASE, MIID_LAST}; + +extern "C" __declspec(dllexport) int Load(void) +{ + InitSecurity(); + InitPreset(); + + RegisterDatabasePlugin(&dblink); + return 0; +} + +extern "C" __declspec(dllexport) int Unload(void) +{ + g_Dbs.destroy(); + UnloadSecurity(); + UninitPreset(); + return 0; +} + +BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID reserved) +{ + g_hInst = hInstDLL; + return TRUE; +} diff --git a/plugins/Dbx_mmap_SA/src/options.h b/plugins/Dbx_mmap_SA/src/options.h new file mode 100644 index 0000000000..efabf3eba5 --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/options.h @@ -0,0 +1,38 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2003 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 +#include +#include "resource.h" + +typedef enum { BT_DISABLED = 0, BT_START = 1, BT_EXIT = 2, BT_PERIODIC = 4} BackupType; +typedef enum { PT_DAYS, PT_HOURS, PT_MINUTES} PeriodType; + +typedef struct Options_tag { + int backup_types; + unsigned int period; + PeriodType period_type; + char folder[MAX_PATH]; + unsigned int num_backups; + BOOL disable_progress; +} Options; \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/src/resource.h b/plugins/Dbx_mmap_SA/src/resource.h new file mode 100644 index 0000000000..7b13f6957d --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/resource.h @@ -0,0 +1,54 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by db3x_mmap.rc +// +#define IDC_NOTOALL 3 +#define IDREMOVE 3 +#define IDD_OPTIONS 101 +#define IDD_INSTALLINI 235 +#define IDD_WARNINICHANGE 236 +#define IDD_INIIMPORTDONE 237 +#define IDD_LOGIN 269 +#define IDD_NEWPASS 270 +#define IDI_ICON2 271 +#define IDI_ICON3 272 +#define IDC_LANG 274 +#define IDD_CHANGEPASS 275 +#define IDC_ININAME 1333 +#define IDC_VIEWINI 1334 +#define IDC_SECURITYINFO 1335 +#define IDC_SETTINGNAME 1336 +#define IDC_NEWVALUE 1337 +#define IDC_WARNNOMORE 1338 +#define IDC_DELETE 1339 +#define IDC_RECYCLE 1340 +#define IDC_NEWNAME 1341 +#define IDC_MOVE 1342 +#define IDC_LEAVE 1343 +#define IDC_HEADERBAR 1657 +#define IDC_USERPASS 1658 +#define IDC_ENC 1659 +#define IDC_USERPASS1 1659 +#define IDC_OLDPASS 1660 +#define IDC_USERPASS2 1661 +#define IDC_NEWPASSINFO 1679 +#define IDC_MODULES 1680 +#define IDC_NEWPASSINFO2 1680 +#define IDC_INFO 1682 +#define IDC_AUTHOR 1683 +#define IDC_NEWPASS1 1683 +#define IDC_SITE 1684 +#define IDC_NEWPASS2 1684 +#define IDC_EMAIL 1685 +#define IDC_UID 1686 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 276 +#define _APS_NEXT_COMMAND_VALUE 40018 +#define _APS_NEXT_CONTROL_VALUE 1685 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/Dbx_mmap_SA/src/security.cpp b/plugins/Dbx_mmap_SA/src/security.cpp new file mode 100644 index 0000000000..4ecf5f745b --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/security.cpp @@ -0,0 +1,392 @@ +// (C) Artem Shpynov aka FYR and Igonin Vitaliy aka chaos.persei, 2007 - 2008 + +#include "commonheaders.h" + +int wrongPass = 0; +void* key; + +Cryptor* CryptoEngine = NULL; + +LIST arCryptors(1); + +void zero_fill(BYTE * pBuf, size_t bufSize) +{ + size_t i; + for (i = 0; i < bufSize; i++) + pBuf[i] = 0; +} + +void InitSecurity() +{ + Cryptor* (__stdcall *GetCryptor)(); + + TCHAR tszPath[MAX_PATH]; + GetModuleFileName(g_hInst, tszPath, SIZEOF(tszPath)); + TCHAR *p = _tcsrchr(tszPath, '\\')+1; _tcscpy(p, _T("cryptors\\*.dll")); + + WIN32_FIND_DATA fd; + HANDLE hFile = FindFirstFile(tszPath, &fd); + while (hFile != INVALID_HANDLE_VALUE) { + mir_sntprintf(p, MAX_PATH - (p-tszPath), _T("cryptors\\%s"), fd.cFileName); + HMODULE hLib = LoadLibrary(tszPath); + if (hLib){ + GetCryptor = (Cryptor* (__stdcall *)()) GetProcAddress(hLib, "GetCryptor"); + if (GetCryptor){ + CryptoModule* newItem = (CryptoModule*) malloc(sizeof(CryptoModule)); + newItem->cryptor = GetCryptor(); + _tcsncpy(newItem->dllname, fd.cFileName, MAX_PATH); + newItem->hLib = hLib; + arCryptors.insert(newItem); + } + else FreeLibrary(hLib); + } + if (!FindNextFile(hFile, &fd)) + break; + } +} + +void UnloadSecurity() +{ + if (CryptoEngine) + CryptoEngine->FreeKey(key); + + for (int i = 0; i < arCryptors.getCount(); i++) { + FreeLibrary(arCryptors[i]->hLib); + free(arCryptors[i]); + } + arCryptors.destroy(); +} + +void CDdxMmapSA::EncoderInit() +{ + if (!m_bEncoding) return; + + encryptKey[encryptKeyLength] = 0; + key = CryptoEngine->GenerateKey(encryptKey); +} + +void CDdxMmapSA::EncodeCopyMemory(void * dst, void * src, size_t size ) +{ + memcpy(dst, src, size); + + if (!m_bEncoding) + return; + + CryptoEngine->EncryptMem((BYTE *)dst, (int)size, key); +} + +void CDdxMmapSA::DecodeCopyMemory(void * dst, void * src, size_t size ) +{ + memcpy(dst, src, size); + + if (!m_bEncoding) + return; + + CryptoEngine->DecryptMem((BYTE *)dst, (int)size, key); +} + +void CDdxMmapSA::EncodeDBWrite(DWORD ofs, void *src, int size) +{ + if (m_bEncoding) + { + BYTE * buf; + + buf = (BYTE*)GlobalAlloc(GPTR, sizeof(BYTE)*size); + EncodeCopyMemory(buf, src, size); + DBWrite(ofs, buf, (int)size); + GlobalFree(buf); + } + else + { + DBWrite(ofs, src, (int)size); + } +} + +void CDdxMmapSA::DecodeDBWrite(DWORD ofs, void *src, int size) +{ + if (m_bEncoding) { + BYTE *buf = (BYTE*)GlobalAlloc(GPTR, sizeof(BYTE)*size); + DecodeCopyMemory(buf, src, size); + DBWrite(ofs, buf, (int)size); + GlobalFree(buf); + } + else DBWrite(ofs, src, (int)size); +} + +int bCheckingPass = 0; + +int CDdxMmapSA::CheckPassword(WORD checkWord, TCHAR *szDBName) +{ + if (bCheckingPass) + return 0; + + bCheckingPass = 1; + + int Found = 0; + for (int i = 0; i < arCryptors.getCount(); i++) { + if ( HIWORD(m_dbHeader.version) == arCryptors[i]->cryptor->uid){ + CryptoEngine = arCryptors[i]->cryptor; + Found = 1; + break; + } + } + if (!Found){ + MessageBoxA(0, "Sorry, but your database encrypted with unknown module", "Error", MB_OK); + bCheckingPass = 0; + return 0; + } + + while(1) { + int res = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_LOGIN), NULL, (DLGPROC)DlgStdInProc, (LPARAM)szDBName); + if (res == IDCANCEL) { + wrongPass = 0; + bCheckingPass = 0; + return 0; + } + if (encryptKeyLength < 1) + continue; + + EncoderInit(); + + WORD ver; + DecodeCopyMemory(&ver, &checkWord, sizeof(checkWord)); + if (ver == 0x5195) { + wrongPass = 0; + bCheckingPass = 0; + return 1; + } + wrongPass++; + } + + bCheckingPass = 0; +} + +int SelectEncoder() +{ + WORD uid; + int i; + + if (arCryptors.getCount() == 0){ + MessageBox(0, TranslateT("Crypto modules not found"), TranslateT("Error"), MB_OK); + return 1; + } + + uid = DBGetContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); + + if (uid == 0){ + MessageBox(0, TranslateT("Crypto module hasn't been chosen, using first one found"), TranslateT("Notice"), MB_OK); + DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[0]->cryptor->uid); + CryptoEngine = arCryptors[0]->cryptor; + } + else{ + int Found = 0; + for (i = 0; i < arCryptors.getCount(); i++) { + if (arCryptors[i]->cryptor->uid == uid){ + CryptoEngine = arCryptors[i]->cryptor; + Found = 1; + break; + } + } + if (!Found){ + MessageBox(0, TranslateT("Crypto module hasn't been chosen, using first one found"), TranslateT("Notice"), MB_OK); + DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", arCryptors[0]->cryptor->uid); + CryptoEngine = arCryptors[0]->cryptor; + } + } + + return 0; +} + +void CDdxMmapSA::EncodeAll() +{ + HANDLE hContact; + + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + if (hContact){ + do { + EncodeContactEvents(hContact); + EncodeContactSettings(hContact); + } + while(hContact = FindNextContact(hContact)); + } + + EncodeContactEvents(NULL); + EncodeContactSettings(NULL); +} + +void CDdxMmapSA::DecodeAll() +{ + HANDLE hContact; + + hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDFIRST, 0, 0); + if (hContact){ + do{ + DecodeContactEvents(hContact); + DecodeContactSettings(hContact); + }while(hContact = (HANDLE)CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM)hContact, 0)); + } + DecodeContactEvents(NULL); + DecodeContactSettings(NULL); +} + +void CDdxMmapSA::WritePlainHeader() +{ + DWORD bytesWritten; + + memcpy(m_dbHeader.signature, &dbSignature, sizeof(m_dbHeader.signature)); + SetFilePointer(m_hDbFile,0,NULL,FILE_BEGIN); + WriteFile(m_hDbFile,m_dbHeader.signature,sizeof(m_dbHeader.signature),&bytesWritten,NULL); + + m_dbHeader.version = MAKELONG(0x0700, 0x0000); //no encryption + WriteFile(m_hDbFile,&m_dbHeader.version, sizeof(m_dbHeader.version),&bytesWritten,NULL); +} + +void CDdxMmapSA::WriteCryptHeader() +{ + DWORD bytesWritten; + + memcpy(m_dbHeader.signature, &dbSignatureSecured, sizeof(m_dbHeader.signature)); + SetFilePointer(m_hDbFile,0,NULL,FILE_BEGIN); + WriteFile(m_hDbFile,m_dbHeader.signature,sizeof(m_dbHeader.signature),&bytesWritten,NULL); + + WORD checkWord = 0x5195, cryptWord; + EncodeCopyMemory(&cryptWord, &checkWord, sizeof(checkWord)); + m_dbHeader.version = MAKELONG(cryptWord, CryptoEngine->uid); + WriteFile(m_hDbFile,&m_dbHeader.version, sizeof(m_dbHeader.version),&bytesWritten,NULL); +} + +void CDdxMmapSA::EncryptDB() +{ + int action = 0; + if (bEncProcess) + return; + + if (memcmp(m_dbHeader.signature, &dbSignatureSecured, sizeof(m_dbHeader.signature)) == 0){ + MessageBox(0, TranslateT("DB is already secured!"), TranslateT("Error"), MB_OK); + return; + } + + if (SelectEncoder()) { + return; + } + + bEncProcess = 1; + + action = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_NEWPASS), NULL, (DLGPROC)DlgStdNewPass, (LPARAM)NULL); + if (action != IDOK || !strlen(encryptKey)) { + bEncProcess = 0; + db_set_b(NULL, "SecureMMAP", "CryptoModule", 0); + return; + } + + EnterCriticalSection(&m_csDbAccess); + + m_bEncoding = 1; + EncoderInit(); + + EncodeAll(); + + LeaveCriticalSection(&m_csDbAccess); + + WriteCryptHeader(); + + xModifyMenu(hSetPwdMenu, 0, LPGENT("Change Password"), 0); + + bEncProcess = 0; +} + +void CDdxMmapSA::DecryptDB() +{ + char oldKey[255]; + strcpy(oldKey, encryptKey); + + if ( !CheckPassword( HIWORD(m_dbHeader.version), TranslateT("current database"))) { + strcpy(encryptKey, oldKey); + encryptKeyLength = strlen(oldKey); + return; + } + + WritePlainHeader(); + + EnterCriticalSection(&m_csDbAccess); + DecodeAll(); + LeaveCriticalSection(&m_csDbAccess); + + m_bEncoding = 0; + + zero_fill((BYTE *)encryptKey, sizeof encryptKey); + + xModifyMenu(hSetPwdMenu, 0, LPGENT("Set Password"), 0); + + DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); + + CryptoEngine->FreeKey(key); + + CryptoEngine = NULL; +} + +void CDdxMmapSA::RecryptDB() +{ + EnterCriticalSection(&m_csDbAccess); + + DecodeAll(); + + CryptoEngine->FreeKey(key); + + SelectEncoder(); + + m_bEncoding = 1; + + EncoderInit(); + + EncodeAll(); + + WriteCryptHeader(); + + LeaveCriticalSection(&m_csDbAccess); +} + +void CDdxMmapSA::ChangePwd() +{ + char newpass[255] = {0}; + + int action = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_CHANGEPASS), NULL, (DLGPROC)DlgChangePass, (LPARAM)newpass); + + if (action == IDCANCEL || (action == IDOK && !strlen(newpass))) + return; + + EnterCriticalSection(&m_csDbAccess); + + DecodeAll(); + + CryptoEngine->FreeKey(key); + + if (action == IDREMOVE){ + WritePlainHeader(); + + m_bEncoding = 0; + CryptoEngine = NULL; + DBWriteContactSettingWord(NULL, "SecureMMAP", "CryptoModule", 0); + + zero_fill((BYTE *)encryptKey, sizeof encryptKey); + + xModifyMenu(hSetPwdMenu, 0, LPGENT("Set Password"), 0); + } + + if (action == IDOK){ + strcpy(encryptKey, newpass); + encryptKeyLength = strlen(newpass); + + m_bEncoding = 1; + + EncoderInit(); + + EncodeAll(); + + WriteCryptHeader(); + } + + zero_fill((BYTE *)newpass, sizeof newpass); + + LeaveCriticalSection(&m_csDbAccess); +} \ No newline at end of file diff --git a/plugins/Dbx_mmap_SA/src/version.h b/plugins/Dbx_mmap_SA/src/version.h new file mode 100644 index 0000000000..57928c3905 --- /dev/null +++ b/plugins/Dbx_mmap_SA/src/version.h @@ -0,0 +1,6 @@ +#include "m_version.h" + +#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION +#define __VERSION_STRING MIRANDA_VERSION_STRING +#define __VERSION_DWORD MIRANDA_VERSION_DWORD +#define __PLUGIN_NAME "Miranda NG secure database driver" diff --git a/plugins/Dbx_mmap_SA/version.h b/plugins/Dbx_mmap_SA/version.h deleted file mode 100644 index 57928c3905..0000000000 --- a/plugins/Dbx_mmap_SA/version.h +++ /dev/null @@ -1,6 +0,0 @@ -#include "m_version.h" - -#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION -#define __VERSION_STRING MIRANDA_VERSION_STRING -#define __VERSION_DWORD MIRANDA_VERSION_DWORD -#define __PLUGIN_NAME "Miranda NG secure database driver" diff --git a/plugins/Dbx_mmap_SA/version.rc b/plugins/Dbx_mmap_SA/version.rc deleted file mode 100644 index d2567f55ae..0000000000 --- a/plugins/Dbx_mmap_SA/version.rc +++ /dev/null @@ -1,42 +0,0 @@ -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include -#include "version.h" - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION __FILEVERSION_STRING - PRODUCTVERSION __FILEVERSION_STRING - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "041904b0" - BEGIN - VALUE "FileDescription", "Miranda IM Mmap DataBase Engine 3x" - VALUE "FileVersion", __VERSION_STRING - VALUE "LegalCopyright", "Copyright (C) 2000-2007" - VALUE "OriginalFilename", "dbx_mmap.dll" - VALUE "ProductName", "Miranda IM Mmap DataBase Engine 3x" - VALUE "ProductVersion", __VERSION_STRING - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x419, 1200 - END -END -- cgit v1.2.3