summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-03-22 22:23:07 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-03-22 22:23:07 +0300
commite3c36ee5c83cfed67ae94bb230ae11e420dbca2e (patch)
tree6621350dd956305da8405eb6c108a957342d5211
parent86785de4047fa87ca9b92914067949798c2e632f (diff)
mir_app: massive fix for account processing in service mode
-rw-r--r--src/mir_app/src/clistcore.cpp6
-rw-r--r--src/mir_app/src/clistmod.cpp13
-rw-r--r--src/mir_app/src/miranda.h5
-rw-r--r--src/mir_app/src/modules.cpp42
-rw-r--r--src/mir_app/src/newplugins.cpp60
-rw-r--r--src/mir_app/src/plugins.h2
-rw-r--r--src/mir_app/src/proto_accs.cpp24
-rw-r--r--src/mir_app/src/proto_opts.cpp9
8 files changed, 89 insertions, 72 deletions
diff --git a/src/mir_app/src/clistcore.cpp b/src/mir_app/src/clistcore.cpp
index 19b99a15dd..7abfb01cc0 100644
--- a/src/mir_app/src/clistcore.cpp
+++ b/src/mir_app/src/clistcore.cpp
@@ -31,8 +31,6 @@ CLIST_INTERFACE cli = { 0 };
static wchar_t szTip[MAX_TIP_SIZE+1];
-int LoadContactListModule2(void);
-int LoadCLCModule(void);
void BuildProtoMenus(void);
static int interfaceInited = 0;
@@ -203,10 +201,6 @@ MIR_APP_DLL(CLIST_INTERFACE*) Clist_GetInterface(void)
cli.pfnGetContactIcon = fnGetContactIcon;
cli.pfnGetAverageMode = fnGetAverageMode;
cli.pfnInitAutoRebuild = fnInitAutoRebuild;
-
- int rc = LoadContactListModule2();
- if (rc == 0)
- rc = LoadCLCModule();
interfaceInited = 1;
}
diff --git a/src/mir_app/src/clistmod.cpp b/src/mir_app/src/clistmod.cpp
index 87c616de47..5e2ee7c22f 100644
--- a/src/mir_app/src/clistmod.cpp
+++ b/src/mir_app/src/clistmod.cpp
@@ -33,8 +33,6 @@ void UninitGroupServices(void);
int ContactSettingChanged(WPARAM wParam, LPARAM lParam);
int ContactAdded(WPARAM hContact, LPARAM);
int ContactDeleted(WPARAM hContact, LPARAM);
-INT_PTR GetContactDisplayName(WPARAM wParam, LPARAM lParam);
-INT_PTR InvalidateDisplayName(WPARAM wParam, LPARAM lParam);
int InitGroupServices(void);
INT_PTR Docking_IsDocked(WPARAM wParam, LPARAM lParam);
int LoadCLUIModule(void);
@@ -429,18 +427,7 @@ int LoadContactListModule2(void)
InitGroupServices();
cli.pfnInitTray();
- hCListImages = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 13, 0);
HookEvent(ME_SKIN_ICONSCHANGED, CListIconsChanged);
-
- ImageList_AddIcon_NotShared(hCListImages, MAKEINTRESOURCE(IDI_BLANK));
-
- // now all core skin icons are loaded via icon lib. so lets release them
- for (auto &it : skinIconStatusList)
- ImageList_AddIcon_IconLibLoaded(hCListImages, it);
-
- // see IMAGE_GROUP... in clist.h if you add more images above here
- ImageList_AddIcon_IconLibLoaded(hCListImages, SKINICON_OTHER_GROUPOPEN);
- ImageList_AddIcon_IconLibLoaded(hCListImages, SKINICON_OTHER_GROUPSHUT);
return 0;
}
diff --git a/src/mir_app/src/miranda.h b/src/mir_app/src/miranda.h
index 639bb077ef..e7c1a868c5 100644
--- a/src/mir_app/src/miranda.h
+++ b/src/mir_app/src/miranda.h
@@ -67,14 +67,15 @@ extern HINSTANCE g_hInst;
extern DWORD hMainThreadId;
extern HANDLE hOkToExitEvent, hModulesLoadedEvent, hevLoadModule, hevUnloadModule;
extern wchar_t mirandabootini[MAX_PATH];
-extern struct pluginEntry *plugin_crshdmp, *plugin_service, *plugin_ssl;
-
+extern struct pluginEntry *plugin_crshdmp, *plugin_service, *plugin_ssl, *plugin_clist;
+extern bool bModulesLoadedFired;
/**** newplugins.cpp *******************************************************************/
char* GetPluginNameByLangpack(int _hLang);
char* GetPluginNameByInstance(HINSTANCE hInstance);
int LoadStdPlugins(void);
+int LaunchServicePlugin(pluginEntry *p);
/**** path.cpp *************************************************************************/
diff --git a/src/mir_app/src/modules.cpp b/src/mir_app/src/modules.cpp
index 2c6ab808ec..2c51f52b04 100644
--- a/src/mir_app/src/modules.cpp
+++ b/src/mir_app/src/modules.cpp
@@ -41,6 +41,7 @@ int LoadIgnoreModule(void); // protocol filter: ignore
int LoadDbintfModule(void);
int LoadSrmmModule(void);
int LoadHelpModule(void);
+int LoadProtocolPlugins(void);
int LoadContactsModule(void);
int LoadDatabaseModule(void);
@@ -58,7 +59,6 @@ int LoadCLCModule(void); // window class: CLC control
int LoadButtonModule(void); // window class: button class
int LoadFontserviceModule(void); // ui: font manager
int LoadIcoLibModule(void); // ui: icons manager
-int LoadServiceModePlugin(void);
void UnloadAccountsModule(void);
void UnloadClcModule(void);
@@ -95,12 +95,10 @@ int LoadDefaultModules(void)
if (LoadNewPluginsModuleInfos()) return 1;
if (GetPrivateProfileInt(L"Interface", L"DpiAware", 0, mirandabootini) == 1) {
- typedef BOOL (WINAPI * SetProcessDPIAware_t)(void);
-
+ typedef BOOL (WINAPI *SetProcessDPIAware_t)(void);
SetProcessDPIAware_t pfn = (SetProcessDPIAware_t)GetProcAddress(GetModuleHandleW(L"user32"), "SetProcessDPIAware");
- if (pfn != nullptr) {
+ if (pfn != nullptr)
pfn();
- }
}
switch (SetServiceModePlugin(CmdLine_GetOption(L"svc"))) {
@@ -121,20 +119,6 @@ int LoadDefaultModules(void)
if (LoadIcoLibModule()) return 1;
if (LoadSkinIcons()) return 1;
- // if (LoadErrorsModule()) return 1;
-
- switch (LoadServiceModePlugin()) {
- case SERVICE_CONTINUE: // continue loading Miranda normally
- break;
- case SERVICE_ONLYDB: // load database and go to the message cycle
- return 0;
- case SERVICE_MONOPOLY: // unload database and go to the message cycle
- UnloadDatabase();
- return 0;
- default: // smth went wrong, terminating
- return 1;
- }
-
if (LoadSkinSounds()) return 1;
if (LoadSkinHotkeys()) return 1;
if (LoadFontserviceModule()) return 1;
@@ -146,6 +130,26 @@ int LoadDefaultModules(void)
if (LoadNetlibModule()) return 1;
if (LoadSslModule()) return 1;
if (LoadProtocolsModule()) return 1;
+
+ // check if a service plugin is scheduled to execution
+ if (plugin_service != nullptr) {
+ if (LoadProtocolPlugins()) return 1;
+
+ switch (LaunchServicePlugin(plugin_service)) {
+ case SERVICE_CONTINUE: // continue loading Miranda normally
+ break;
+ case SERVICE_ONLYDB: // load database and go to the message cycle
+ return 0;
+ case SERVICE_MONOPOLY: // unload database and go to the message cycle
+ UnloadDatabase();
+ return 0;
+ default: // smth went wrong, terminating
+ return 1;
+ }
+
+ plugin_service = nullptr;
+ }
+
LoadDbAccounts(); // retrieves the account array from a database
if (LoadContactsModule()) return 1;
if (LoadMetacontacts()) return 1;
diff --git a/src/mir_app/src/newplugins.cpp b/src/mir_app/src/newplugins.cpp
index a888fa81ad..7645959c91 100644
--- a/src/mir_app/src/newplugins.cpp
+++ b/src/mir_app/src/newplugins.cpp
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
+#include "clc.h"
#include "plugins.h"
#include "profilemanager.h"
#include "langpack.h"
@@ -31,9 +32,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void LoadExtraIconsModule();
-extern bool bModulesLoadedFired;
-
-static int sttComparePluginsByName(const pluginEntry* p1, const pluginEntry* p2)
+static int sttComparePluginsByName(const pluginEntry *p1, const pluginEntry *p2)
{
return mir_wstrcmpi(p1->pluginname, p2->pluginname);
}
@@ -59,7 +58,7 @@ static int sttFakeID = -100;
static HANDLE hPluginListHeap = nullptr;
static int askAboutIgnoredPlugins;
-pluginEntry *plugin_crshdmp, *plugin_service, *plugin_ssl;
+pluginEntry *plugin_crshdmp, *plugin_service, *plugin_ssl, *plugin_clist;
#define PLUGINDISABLELIST "PluginDisable"
@@ -250,7 +249,7 @@ static bool validInterfaceList(MUUID *piface)
return true;
}
-static int checkPI(BASIC_PLUGIN_INFO* bpi, PLUGININFOEX* pi)
+static int checkPI(BASIC_PLUGIN_INFO *bpi, PLUGININFOEX *pi)
{
if (pi == nullptr)
return FALSE;
@@ -487,7 +486,7 @@ pluginEntry* OpenPlugin(wchar_t *tszFileName, wchar_t *dir, wchar_t *path)
// didn't have basic APIs or DB exports - failed.
p->bFailed = true;
}
- else if (hasMuuid(pIds, MIID_DATABASE))
+ else if (hasMuuid(pIds, MIID_PROTOCOL))
p->bIsProtocol = true;
return p;
}
@@ -615,18 +614,37 @@ LBL_Error:
/////////////////////////////////////////////////////////////////////////////////////////
// Contact list plugins support
+int LoadContactListModule2(void);
+int LoadCLCModule(void);
+
static bool loadClistModule(wchar_t* exe, pluginEntry *p)
{
BASIC_PLUGIN_INFO bpi;
if (checkAPI(exe, &bpi, mirandaVersion, CHECKAPI_CLIST)) {
p->bpi = bpi;
p->bIsLast = p->bOk = p->bHasBasicApi = true;
+
+ hCListImages = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 13, 0);
+ ImageList_AddIcon_NotShared(hCListImages, MAKEINTRESOURCE(IDI_BLANK));
+
+ // now all core skin icons are loaded via icon lib. so lets release them
+ for (auto &it : skinIconStatusList)
+ ImageList_AddIcon_IconLibLoaded(hCListImages, it);
+
+ // see IMAGE_GROUP... in clist.h if you add more images above here
+ ImageList_AddIcon_IconLibLoaded(hCListImages, SKINICON_OTHER_GROUPOPEN);
+ ImageList_AddIcon_IconLibLoaded(hCListImages, SKINICON_OTHER_GROUPSHUT);
+
RegisterModule(p->bpi.hInst);
if (bpi.clistlink() == 0) {
p->bpi = bpi;
p->bLoaded = true;
pluginDefault[0].pImpl = p;
+ int rc = LoadContactListModule2();
+ if (rc == 0)
+ rc = LoadCLCModule();
+
LoadExtraIconsModule();
return true;
}
@@ -674,7 +692,7 @@ int UnloadPlugin(wchar_t* buf, int bufLen)
/////////////////////////////////////////////////////////////////////////////////////////
// Service plugins functions
-static int LaunchServicePlugin(pluginEntry *p)
+int LaunchServicePlugin(pluginEntry *p)
{
// plugin load failed - terminating Miranda
if (!p->bLoaded) {
@@ -712,11 +730,6 @@ MIR_APP_DLL(int) SetServiceModePlugin(const wchar_t *wszPluginName)
return SERVICE_CONTINUE;
}
-int LoadServiceModePlugin()
-{
- return (plugin_service == nullptr) ? SERVICE_CONTINUE : LaunchServicePlugin(plugin_service);
-}
-
void EnsureCheckerLoaded(bool bEnable)
{
for (auto &p : pluginList) {
@@ -772,6 +785,23 @@ void UnloadNewPlugins(void)
Plugin_Uninit(it);
}
+int LoadProtocolPlugins(void)
+{
+ /* now loop thru and load all the other plugins, do this in one pass */
+ for (int i = 0; i < pluginList.getCount(); i++) {
+ pluginEntry *p = pluginList[i];
+ if (!p->bIsProtocol)
+ continue;
+
+ if (!TryLoadPlugin(p, false)) {
+ Plugin_Uninit(p);
+ i--;
+ }
+ }
+
+ return 0;
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// Loads all plugins
@@ -793,10 +823,10 @@ int LoadNewPluginsModule(void)
Plugin_Uninit(plugin_crshdmp);
// first load the clist cos alot of plugins need that to be present at Load(void)
- pluginEntry* clist = getCListModule(exe);
+ plugin_clist = getCListModule(exe);
/* the loop above will try and get one clist DLL to work, if all fail then just bail now */
- if (clist == nullptr) {
+ if (plugin_clist == nullptr) {
// result = 0, no clist_* can be found
if (clistPlugins.getCount())
MessageBox(nullptr, TranslateT("Unable to start any of the installed contact list plugins, I even ignored your preferences for which contact list couldn't load any."), L"Miranda NG", MB_OK | MB_ICONERROR);
@@ -807,7 +837,7 @@ int LoadNewPluginsModule(void)
/* enable and disable as needed */
for (auto &p : clistPlugins)
- SetPluginOnWhiteList(p->pluginname, clist != p ? 0 : 1);
+ SetPluginOnWhiteList(p->pluginname, plugin_clist != p ? 0 : 1);
/* now loop thru and load all the other plugins, do this in one pass */
for (int i = 0; i < pluginList.getCount(); i++) {
diff --git a/src/mir_app/src/plugins.h b/src/mir_app/src/plugins.h
index 2f4ec318e7..d860df1a67 100644
--- a/src/mir_app/src/plugins.h
+++ b/src/mir_app/src/plugins.h
@@ -24,7 +24,7 @@ struct BASIC_PLUGIN_INFO
Miranda_Plugin_Unload Unload;
Miranda_Plugin_InfoEx InfoEx;
CList_Initialise clistlink;
- PLUGININFOEX * pluginInfo; // must be freed if hInst = = nullptr then its a copy
+ PLUGININFOEX *pluginInfo; // must be freed if hInst = = nullptr then its a copy
MUUID *Interfaces; // array of supported interfaces
};
diff --git a/src/mir_app/src/proto_accs.cpp b/src/mir_app/src/proto_accs.cpp
index 6132d25bcc..a6bf3d8e18 100644
--- a/src/mir_app/src/proto_accs.cpp
+++ b/src/mir_app/src/proto_accs.cpp
@@ -31,7 +31,7 @@ void BuildProtoMenus();
HICON Proto_GetIcon(PROTO_INTERFACE *ppro, int iconIndex);
-static BOOL bModuleInitialized = FALSE;
+static bool bModuleInitialized = false;
static HANDLE hHooks[4];
static int CompareAccounts(const PROTOACCOUNT* p1, const PROTOACCOUNT* p2)
@@ -53,8 +53,8 @@ static int EnumDbModules(const char *szModuleName, void*)
pa->szModuleName = mir_strdup(szModuleName);
pa->szProtoName = szProtoName.detach();
pa->tszAccountName = mir_a2u(szModuleName);
- pa->bIsVisible = TRUE;
- pa->bIsEnabled = FALSE;
+ pa->bIsVisible = true;
+ pa->bIsEnabled = false;
pa->iOrder = accounts.getCount();
accounts.insert(pa);
}
@@ -74,13 +74,17 @@ void LoadDbAccounts(void)
if (szModuleName == nullptr)
continue;
- PROTOACCOUNT *pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
+ PROTOACCOUNT *pa = Proto_GetAccount(szModuleName);
if (pa == nullptr) {
+ pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
+ pa->cbSize = sizeof(*pa);
+ pa->szModuleName = szModuleName;
+ accounts.insert(pa);
+ }
+ else {
mir_free(szModuleName);
- continue;
+ szModuleName = pa->szModuleName;
}
- pa->cbSize = sizeof(*pa);
- pa->szModuleName = szModuleName;
_itoa(OFFSET_VISIBLE + i, buf, 10);
pa->bIsVisible = db_get_dw(0, "Protocols", buf, 1) != 0;
@@ -106,8 +110,6 @@ void LoadDbAccounts(void)
if (!pa->tszAccountName)
pa->tszAccountName = mir_a2u(szModuleName);
-
- accounts.insert(pa);
}
if (CheckProtocolOrder())
@@ -249,7 +251,7 @@ static int UninitializeStaticAccounts(WPARAM, LPARAM)
int LoadAccountsModule(void)
{
- bModuleInitialized = TRUE;
+ bModuleInitialized = true;
for (auto &pa : accounts) {
pa->bDynDisabled = !Proto_IsProtocolLoaded(pa->szProtoName);
@@ -260,7 +262,7 @@ int LoadAccountsModule(void)
continue;
if (!ActivateAccount(pa))
- pa->bDynDisabled = TRUE;
+ pa->bDynDisabled = true;
}
hHooks[0] = HookEvent(ME_SYSTEM_MODULESLOADED, InitializeStaticAccounts);
diff --git a/src/mir_app/src/proto_opts.cpp b/src/mir_app/src/proto_opts.cpp
index c28a042e9e..6996a88c57 100644
--- a/src/mir_app/src/proto_opts.cpp
+++ b/src/mir_app/src/proto_opts.cpp
@@ -59,9 +59,6 @@ int UnloadPlugin(wchar_t* buf, int bufLen);
PROTOACCOUNT* Proto_CreateAccount(const char *szModuleName, const char *szBaseProto, const wchar_t *tszAccountName)
{
PROTOACCOUNT *pa = (PROTOACCOUNT*)mir_calloc(sizeof(PROTOACCOUNT));
- if (pa == nullptr)
- return nullptr;
-
pa->cbSize = sizeof(PROTOACCOUNT);
pa->bIsEnabled = pa->bIsVisible = true;
pa->iOrder = accounts.getCount();
@@ -86,7 +83,8 @@ PROTOACCOUNT* Proto_CreateAccount(const char *szModuleName, const char *szBasePr
accounts.insert(pa);
if (ActivateAccount(pa)) {
- pa->ppro->OnEvent(EV_PROTO_ONLOAD, 0, 0);
+ if (bModulesLoadedFired)
+ pa->ppro->OnEvent(EV_PROTO_ONLOAD, 0, 0);
if (!db_get_b(0, "CList", "MoveProtoMenus", true))
pa->ppro->OnEvent(EV_PROTO_ONMENU, 0, 0);
}
@@ -547,7 +545,8 @@ public:
pa->bIsEnabled = !pa->bIsEnabled;
if (pa->bIsEnabled) {
if (ActivateAccount(pa)) {
- pa->ppro->OnEvent(EV_PROTO_ONLOAD, 0, 0);
+ if (bModulesLoadedFired)
+ pa->ppro->OnEvent(EV_PROTO_ONLOAD, 0, 0);
if (!db_get_b(0, "CList", "MoveProtoMenus", TRUE))
pa->ppro->OnEvent(EV_PROTO_ONMENU, 0, 0);
}