From 34e423793fe14fe60a1e463e724523bc1f471cd3 Mon Sep 17 00:00:00 2001 From: aunsane Date: Thu, 23 Feb 2017 16:39:28 +0300 Subject: Tox: - added compatibility check - version bump --- protocols/Tox/src/api_main.cpp | 5 +++ protocols/Tox/src/main.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ protocols/Tox/src/stdafx.h | 5 +++ protocols/Tox/src/tox.cpp | 67 ------------------------------------- protocols/Tox/src/tox_proto.h | 5 ++- protocols/Tox/src/version.h | 2 +- 6 files changed, 91 insertions(+), 69 deletions(-) create mode 100644 protocols/Tox/src/main.cpp delete mode 100644 protocols/Tox/src/tox.cpp diff --git a/protocols/Tox/src/api_main.cpp b/protocols/Tox/src/api_main.cpp index a63bc729b8..3d46576925 100644 --- a/protocols/Tox/src/api_main.cpp +++ b/protocols/Tox/src/api_main.cpp @@ -2,6 +2,11 @@ /* MAIN FUNCTIONS */ +bool tox_version_is_compatible(uint32_t major, uint32_t minor, uint32_t patch) +{ + return CreateFunction(__FUNCTION__)(major, minor, patch); +} + struct Tox_Options *tox_options_new(TOX_ERR_OPTIONS_NEW *error) { return CreateFunction(__FUNCTION__)(error); diff --git a/protocols/Tox/src/main.cpp b/protocols/Tox/src/main.cpp new file mode 100644 index 0000000000..d315f7605f --- /dev/null +++ b/protocols/Tox/src/main.cpp @@ -0,0 +1,76 @@ +#include "stdafx.h" + +int hLangpack; +CHAT_MANAGER *pci; +CLIST_INTERFACE *pcli; +HINSTANCE g_hInstance; +HMODULE g_hToxLibrary = NULL; + +PLUGININFOEX pluginInfo = +{ + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // {00272A3E-F5FA-4090-8B67-3E62AC1EE0B4} + {0x272a3e, 0xf5fa, 0x4090, {0x8b, 0x67, 0x3e, 0x62, 0xac, 0x1e, 0xe0, 0xb4}} +}; + +DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) +{ + g_hInstance = hInstance; + + return TRUE; +} + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) +{ + return &pluginInfo; +} + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; + +extern "C" int __declspec(dllexport) Load(void) +{ + g_hToxLibrary = LoadLibrary(TOX_LIBRARY); + if (g_hToxLibrary == NULL) + return 1; + + if (!TOX_VERSION_IS_ABI_COMPATIBLE()) + { + wchar_t message[100]; + mir_snwprintf(message, TranslateT("Current version of plugin is support tox api version %i.%i.%i which is incompatible with %s"), TOX_VERSION_MAJOR, TOX_VERSION_MINOR, TOX_VERSION_PATCH, TOX_LIBRARY); + CToxProto::ShowNotification(message, MB_ICONERROR); + FreeLibrary(g_hToxLibrary); + return 2; + } + + pci = Chat_GetInterface(); + pcli = Clist_GetInterface(); + mir_getLP(&pluginInfo); + + PROTOCOLDESCRIPTOR pd = { 0 }; + pd.cbSize = sizeof(pd); + pd.szName = "TOX"; + pd.type = PROTOTYPE_PROTOCOL; + pd.fnInit = (pfnInitProto)CToxProto::InitAccount; + pd.fnUninit = (pfnUninitProto)CToxProto::UninitAccount; + Proto_RegisterModule(&pd); + + HookEvent(ME_SYSTEM_MODULESLOADED, &CToxProto::OnModulesLoaded); + + return 0; +} + +extern "C" int __declspec(dllexport) Unload(void) +{ + if (g_hToxLibrary) + FreeLibrary(g_hToxLibrary); + + return 0; +} \ No newline at end of file diff --git a/protocols/Tox/src/stdafx.h b/protocols/Tox/src/stdafx.h index 6b2c083543..dee3d7f817 100644 --- a/protocols/Tox/src/stdafx.h +++ b/protocols/Tox/src/stdafx.h @@ -70,6 +70,10 @@ extern HINSTANCE g_hInstance; #define MODULE "Tox" +#define TOX_API_VER_MAJOR 0 +#define TOX_API_VER_MINOR 1 +#define TOX_API_VER_PATCH 5 + #define TOX_ERROR -1 #define TOX_MAX_CONNECT_RETRIES 300 @@ -103,6 +107,7 @@ enum TOX_DB_EVENT #define TOX_MAX_AVATAR_SIZE 1 << 16 // 2 ^ 16 bytes +#define TOX_LIBRARY L"libtox.dll" extern HMODULE g_hToxLibrary; template diff --git a/protocols/Tox/src/tox.cpp b/protocols/Tox/src/tox.cpp deleted file mode 100644 index 0ee2774aa4..0000000000 --- a/protocols/Tox/src/tox.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "stdafx.h" - -int hLangpack; -CHAT_MANAGER *pci; -CLIST_INTERFACE *pcli; -HINSTANCE g_hInstance; -HMODULE g_hToxLibrary = NULL; - -PLUGININFOEX pluginInfo = -{ - sizeof(PLUGININFOEX), - __PLUGIN_NAME, - PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), - __DESCRIPTION, - __AUTHOR, - __AUTHOREMAIL, - __COPYRIGHT, - __AUTHORWEB, - UNICODE_AWARE, - // {00272A3E-F5FA-4090-8B67-3E62AC1EE0B4} - {0x272a3e, 0xf5fa, 0x4090, {0x8b, 0x67, 0x3e, 0x62, 0xac, 0x1e, 0xe0, 0xb4}} -}; - -DWORD WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID) -{ - g_hInstance = hInstance; - - return TRUE; -} - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) -{ - return &pluginInfo; -} - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PROTOCOL, MIID_LAST }; - -extern "C" int __declspec(dllexport) Load(void) -{ - g_hToxLibrary = LoadLibrary(L"libtox.dll"); - if (g_hToxLibrary == NULL) - return 0; - - pci = Chat_GetInterface(); - pcli = Clist_GetInterface(); - mir_getLP(&pluginInfo); - - PROTOCOLDESCRIPTOR pd = { 0 }; - pd.cbSize = sizeof(pd); - pd.szName = "TOX"; - pd.type = PROTOTYPE_PROTOCOL; - pd.fnInit = (pfnInitProto)CToxProto::InitAccount; - pd.fnUninit = (pfnUninitProto)CToxProto::UninitAccount; - Proto_RegisterModule(&pd); - - HookEvent(ME_SYSTEM_MODULESLOADED, &CToxProto::OnModulesLoaded); - - return 0; -} - -extern "C" int __declspec(dllexport) Unload(void) -{ - if (g_hToxLibrary) - FreeLibrary(g_hToxLibrary); - - return 0; -} \ No newline at end of file diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 65ab3c2c15..953452d01b 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -65,6 +65,9 @@ public: static int OnModulesLoaded(WPARAM, LPARAM); + // utils + static void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); + private: CToxThread *toxThread; mir_cs profileLock; @@ -287,7 +290,7 @@ private: static wchar_t* ToxErrorToString(TOX_ERR_NEW error); static wchar_t* ToxErrorToString(TOX_ERR_FRIEND_SEND_MESSAGE error); - static void ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); + static void ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); static bool IsFileExists(const wchar_t* path); diff --git a/protocols/Tox/src/version.h b/protocols/Tox/src/version.h index 95e8e40b34..3fd62a1c86 100644 --- a/protocols/Tox/src/version.h +++ b/protocols/Tox/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 1 -#define __BUILD_NUM 21 +#define __BUILD_NUM 22 #include -- cgit v1.2.3