From 66a1f3d1140ff16d776d0ce36f0655b0ef81c5fa Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 20 May 2015 11:14:46 +0000 Subject: grrrrrrrrrm git-svn-id: http://svn.miranda-ng.org/main/trunk@13715 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/commonheaders.h | 107 ++++++++++++ src/core/miranda.cpp | 422 +++++++++++++++++++++++++++++++++++++++++++++++ src/core/miranda.h | 199 ++++++++++++++++++++++ src/core/modules.cpp | 184 +++++++++++++++++++++ src/core/stdafx.cpp | 19 +++ 5 files changed, 931 insertions(+) create mode 100644 src/core/commonheaders.h create mode 100644 src/core/miranda.cpp create mode 100644 src/core/miranda.h create mode 100644 src/core/modules.cpp create mode 100644 src/core/stdafx.cpp diff --git a/src/core/commonheaders.h b/src/core/commonheaders.h new file mode 100644 index 0000000000..3c60da9b96 --- /dev/null +++ b/src/core/commonheaders.h @@ -0,0 +1,107 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda 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 _ALPHA_BASE_ 1 // defined for CVS builds +#define _ALPHA_FUSE_ 1 // defined for fuse powered core + +#define INCL_WINSOCK_API_TYPEDEFS 1 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef _DEBUG +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "miranda.h" +#include "stdplug.h" + +#include +#include +#include + +typedef struct GlobalLogSettingsBase GlobalLogSettings; +#include + +#include "../resource.h" \ No newline at end of file diff --git a/src/core/miranda.cpp b/src/core/miranda.cpp new file mode 100644 index 0000000000..b5b65f8d40 --- /dev/null +++ b/src/core/miranda.cpp @@ -0,0 +1,422 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda 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" + +#define MMI_SIZE_V1 (4*sizeof(void*)) +#define MMI_SIZE_V2 (7*sizeof(void*)) + +int LoadDefaultModules(void); +void UnloadNewPluginsModule(void); +void UnloadDefaultModules(void); + +pfnDrawThemeTextEx drawThemeTextEx; +pfnSetWindowThemeAttribute setWindowThemeAttribute; +pfnBufferedPaintInit bufferedPaintInit; +pfnBufferedPaintUninit bufferedPaintUninit; +pfnBeginBufferedPaint beginBufferedPaint; +pfnEndBufferedPaint endBufferedPaint; +pfnGetBufferedPaintBits getBufferedPaintBits; + +pfnDwmExtendFrameIntoClientArea dwmExtendFrameIntoClientArea; +pfnDwmIsCompositionEnabled dwmIsCompositionEnabled; + +ITaskbarList3 * pTaskbarInterface; + +HANDLE hOkToExitEvent, hModulesLoadedEvent; +HANDLE hShutdownEvent, hPreShutdownEvent; +static HANDLE hWaitObjects[MAXIMUM_WAIT_OBJECTS-1]; +static char *pszWaitServices[MAXIMUM_WAIT_OBJECTS-1]; +static int waitObjectCount = 0; +HANDLE hMirandaShutdown; +HINSTANCE hInst; +DWORD hMainThreadId; +int hLangpack = 0; +bool bModulesLoadedFired = false; + +///////////////////////////////////////////////////////////////////////////////////////// +// exception handling + +static INT_PTR srvGetExceptionFilter(WPARAM, LPARAM) +{ + return (INT_PTR)GetExceptionFilter(); +} + +static INT_PTR srvSetExceptionFilter(WPARAM, LPARAM lParam) +{ + return (INT_PTR)SetExceptionFilter((pfnExceptionFilter)lParam); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +typedef LONG(WINAPI *pNtQIT)(HANDLE, LONG, PVOID, ULONG, PULONG); +#define ThreadQuerySetWin32StartAddress 9 + +INT_PTR MirandaIsTerminated(WPARAM, LPARAM) +{ + return WaitForSingleObject(hMirandaShutdown, 0) == WAIT_OBJECT_0; +} + +static void __cdecl compactHeapsThread(void*) +{ + Thread_SetName("compactHeapsThread"); + + while (!Miranda_Terminated()) { + HANDLE hHeaps[256]; + DWORD hc; + SleepEx((1000 * 60) * 5, TRUE); // every 5 minutes + hc = GetProcessHeaps(255, (PHANDLE)&hHeaps); + if (hc != 0 && hc < 256) { + DWORD j; + for (j = 0; j < hc; j++) + HeapCompact(hHeaps[j], 0); + } + } //while +} + +void(*SetIdleCallback) (void) = NULL; + +static INT_PTR SystemSetIdleCallback(WPARAM, LPARAM lParam) +{ + if (lParam && SetIdleCallback == NULL) { + SetIdleCallback = (void(*)(void))lParam; + return 1; + } + return 0; +} + +static DWORD dwEventTime = 0; +void checkIdle(MSG * msg) +{ + switch (msg->message) { + case WM_MOUSEACTIVATE: + case WM_MOUSEMOVE: + case WM_CHAR: + dwEventTime = GetTickCount(); + } +} + +static INT_PTR SystemGetIdle(WPARAM, LPARAM lParam) +{ + if (lParam) *(DWORD*)lParam = dwEventTime; + return 0; +} + +static int SystemShutdownProc(WPARAM, LPARAM) +{ + UnloadDefaultModules(); + return 0; +} + +#define MIRANDA_PROCESS_WAIT_TIMEOUT 60000 +#define MIRANDA_PROCESS_WAIT_RESOLUTION 1000 +#define MIRANDA_PROCESS_WAIT_STEPS (MIRANDA_PROCESS_WAIT_TIMEOUT/MIRANDA_PROCESS_WAIT_RESOLUTION) +static INT_PTR CALLBACK WaitForProcessDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwnd); + SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); + SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETRANGE, 0, MAKELPARAM(0, MIRANDA_PROCESS_WAIT_STEPS)); + SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETSTEP, 1, 0); + SetTimer(hwnd, 1, MIRANDA_PROCESS_WAIT_RESOLUTION, NULL); + break; + + case WM_TIMER: + if (SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_STEPIT, 0, 0) == MIRANDA_PROCESS_WAIT_STEPS) + EndDialog(hwnd, 0); + if (WaitForSingleObject((HANDLE)GetWindowLongPtr(hwnd, GWLP_USERDATA), 1) != WAIT_TIMEOUT) { + SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETPOS, MIRANDA_PROCESS_WAIT_STEPS, 0); + EndDialog(hwnd, 0); + } + break; + + case WM_COMMAND: + if (LOWORD(wParam) == IDCANCEL) { + SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETPOS, MIRANDA_PROCESS_WAIT_STEPS, 0); + EndDialog(hwnd, 1); + } + break; + } + return FALSE; +} + +INT_PTR CheckRestart() +{ + LPCTSTR tszPID = CmdLine_GetOption(_T("restart")); + if (tszPID) { + HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, _ttol(tszPID)); + if (hProcess) { + INT_PTR result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_WAITRESTART), NULL, WaitForProcessDlgProc, (LPARAM)hProcess); + CloseHandle(hProcess); + return result; + } + } + return 0; +} + +static void crtErrorHandler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned, uintptr_t) +{} + + +int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int) +{ + hInst = hInstance; + hMainThreadId = GetCurrentThreadId(); + + _set_invalid_parameter_handler(&crtErrorHandler); +#ifdef _DEBUG + _CrtSetReportMode(_CRT_ASSERT, 0); +#endif + + CmdLine_Parse(cmdLine); + setlocale(LC_ALL, ""); + +#ifdef _DEBUG + if (CmdLine_GetOption(_T("memdebug"))) + _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + + HMODULE hDwmApi, hThemeAPI; + if (IsWinVerVistaPlus()) { + hDwmApi = LoadLibrary(_T("dwmapi.dll")); + if (hDwmApi) { + dwmExtendFrameIntoClientArea = (pfnDwmExtendFrameIntoClientArea)GetProcAddress(hDwmApi, "DwmExtendFrameIntoClientArea"); + dwmIsCompositionEnabled = (pfnDwmIsCompositionEnabled)GetProcAddress(hDwmApi, "DwmIsCompositionEnabled"); + } + hThemeAPI = LoadLibrary(_T("uxtheme.dll")); + if (hThemeAPI) { + drawThemeTextEx = (pfnDrawThemeTextEx)GetProcAddress(hThemeAPI, "DrawThemeTextEx"); + setWindowThemeAttribute = (pfnSetWindowThemeAttribute)GetProcAddress(hThemeAPI, "SetWindowThemeAttribute"); + bufferedPaintInit = (pfnBufferedPaintInit)GetProcAddress(hThemeAPI, "BufferedPaintInit"); + bufferedPaintUninit = (pfnBufferedPaintUninit)GetProcAddress(hThemeAPI, "BufferedPaintUninit"); + beginBufferedPaint = (pfnBeginBufferedPaint)GetProcAddress(hThemeAPI, "BeginBufferedPaint"); + endBufferedPaint = (pfnEndBufferedPaint)GetProcAddress(hThemeAPI, "EndBufferedPaint"); + getBufferedPaintBits = (pfnGetBufferedPaintBits)GetProcAddress(hThemeAPI, "GetBufferedPaintBits"); + } + } + else hDwmApi = hThemeAPI = 0; + + if (bufferedPaintInit) + bufferedPaintInit(); + + OleInitialize(NULL); + + if (IsWinVer7Plus()) + CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_ALL, IID_ITaskbarList3, (void**)&pTaskbarInterface); + + int result = 0; + if (LoadDefaultModules()) { + SetEvent(hMirandaShutdown); + NotifyEventHooks(hPreShutdownEvent, 0, 0); + NotifyEventHooks(hShutdownEvent, 0, 0); + UnloadDefaultModules(); + + result = 1; + } + else { + InitPathVar(); + NotifyEventHooks(hModulesLoadedEvent, 0, 0); + bModulesLoadedFired = true; + + // ensure that the kernel hooks the SystemShutdownProc() after all plugins + HookEvent(ME_SYSTEM_SHUTDOWN, SystemShutdownProc); + + forkthread(compactHeapsThread, 0, NULL); + CreateServiceFunction(MS_SYSTEM_SETIDLECALLBACK, SystemSetIdleCallback); + CreateServiceFunction(MS_SYSTEM_GETIDLE, SystemGetIdle); + dwEventTime = GetTickCount(); + DWORD myPid = GetCurrentProcessId(); + + bool messageloop = true; + while (messageloop) { + MSG msg; + BOOL dying = FALSE; + DWORD rc = MsgWaitForMultipleObjectsEx(waitObjectCount, hWaitObjects, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE); + if (rc < WAIT_OBJECT_0 + waitObjectCount) { + rc -= WAIT_OBJECT_0; + CallService(pszWaitServices[rc], (WPARAM)hWaitObjects[rc], 0); + } + // + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + if (msg.message != WM_QUIT) { + HWND h = GetForegroundWindow(); + DWORD pid = 0; + checkIdle(&msg); + if (h != NULL && GetWindowThreadProcessId(h, &pid) && pid == myPid && GetClassLongPtr(h, GCW_ATOM) == 32770) + if (h != NULL && IsDialogMessage(h, &msg)) /* Wine fix. */ + continue; + + TranslateMessage(&msg); + DispatchMessage(&msg); + if (SetIdleCallback != NULL) + SetIdleCallback(); + } + else if (!dying) { + dying++; + SetEvent(hMirandaShutdown); + NotifyEventHooks(hPreShutdownEvent, 0, 0); + + // this spins and processes the msg loop, objects and APC. + Thread_Wait(); + NotifyEventHooks(hShutdownEvent, 0, 0); + // if the hooks generated any messages, it'll get processed before the second WM_QUIT + PostQuitMessage(0); + } + else if (dying) + messageloop = false; + } + } + } + + UnloadNewPluginsModule(); + UnloadCoreModule(); + CloseHandle(hMirandaShutdown); + FreeLibrary(hDwmApi); + FreeLibrary(hThemeAPI); + + if (pTaskbarInterface) + pTaskbarInterface->Release(); + + OleUninitialize(); + + if (bufferedPaintUninit) + bufferedPaintUninit(); + return result; +} + +static INT_PTR OkToExit(WPARAM, LPARAM) +{ + return NotifyEventHooks(hOkToExitEvent, 0, 0) == 0; +} + +static INT_PTR GetMirandaVersion(WPARAM, LPARAM) +{ + TCHAR filename[MAX_PATH]; + GetModuleFileName(NULL, filename, SIZEOF(filename)); + + DWORD unused, verInfoSize = GetFileVersionInfoSize(filename, &unused); + PVOID pVerInfo = _alloca(verInfoSize); + GetFileVersionInfo(filename, 0, verInfoSize, pVerInfo); + + UINT blockSize; + VS_FIXEDFILEINFO *vsffi; + VerQueryValue(pVerInfo, _T("\\"), (PVOID*)&vsffi, &blockSize); + DWORD ver = (((vsffi->dwProductVersionMS >> 16) & 0xFF) << 24) | + ((vsffi->dwProductVersionMS & 0xFF) << 16) | + (((vsffi->dwProductVersionLS >> 16) & 0xFF) << 8) | + (vsffi->dwProductVersionLS & 0xFF); + return (INT_PTR)ver; +} + +static INT_PTR GetMirandaFileVersion(WPARAM, LPARAM lParam) +{ + TCHAR filename[MAX_PATH]; + GetModuleFileName(NULL, filename, SIZEOF(filename)); + + DWORD unused, verInfoSize = GetFileVersionInfoSize(filename, &unused); + PVOID pVerInfo = _alloca(verInfoSize); + GetFileVersionInfo(filename, 0, verInfoSize, pVerInfo); + + UINT blockSize; + VS_FIXEDFILEINFO *vsffi; + VerQueryValue(pVerInfo, _T("\\"), (PVOID*)&vsffi, &blockSize); + + WORD* p = (WORD*)lParam; + p[0] = HIWORD(vsffi->dwProductVersionMS); + p[1] = LOWORD(vsffi->dwProductVersionMS); + p[2] = HIWORD(vsffi->dwProductVersionLS); + p[3] = LOWORD(vsffi->dwProductVersionLS); + return 0; +} + +static INT_PTR GetMirandaVersionText(WPARAM wParam, LPARAM lParam) +{ + TCHAR filename[MAX_PATH], *productVersion; + GetModuleFileName(NULL, filename, SIZEOF(filename)); + + DWORD unused, verInfoSize = GetFileVersionInfoSize(filename, &unused); + PVOID pVerInfo = _alloca(verInfoSize); + GetFileVersionInfo(filename, 0, verInfoSize, pVerInfo); + + UINT blockSize; + VerQueryValue(pVerInfo, _T("\\StringFileInfo\\000004b0\\ProductVersion"), (LPVOID*)&productVersion, &blockSize); + strncpy((char*)lParam, _T2A(productVersion), wParam); +#if defined(_WIN64) + strcat_s((char*)lParam, wParam, " x64"); +#endif + return 0; +} + +INT_PTR WaitOnHandle(WPARAM wParam, LPARAM lParam) +{ + if (waitObjectCount >= MAXIMUM_WAIT_OBJECTS - 1) + return 1; + + hWaitObjects[waitObjectCount] = (HANDLE)wParam; + pszWaitServices[waitObjectCount] = (char*)lParam; + waitObjectCount++; + return 0; +} + +static INT_PTR RemoveWait(WPARAM wParam, LPARAM) +{ + int i; + + for (i = 0; i < waitObjectCount; i++) + if (hWaitObjects[i] == (HANDLE)wParam) + break; + + if (i == waitObjectCount) + return 1; + + waitObjectCount--; + memmove(&hWaitObjects[i], &hWaitObjects[i + 1], sizeof(HANDLE)*(waitObjectCount - i)); + memmove(&pszWaitServices[i], &pszWaitServices[i + 1], sizeof(char*)*(waitObjectCount - i)); + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// + +int LoadSystemModule(void) +{ + hMirandaShutdown = CreateEvent(NULL, TRUE, FALSE, NULL); + + hShutdownEvent = CreateHookableEvent(ME_SYSTEM_SHUTDOWN); + hPreShutdownEvent = CreateHookableEvent(ME_SYSTEM_PRESHUTDOWN); + hModulesLoadedEvent = CreateHookableEvent(ME_SYSTEM_MODULESLOADED); + hOkToExitEvent = CreateHookableEvent(ME_SYSTEM_OKTOEXIT); + + CreateServiceFunction(MS_SYSTEM_TERMINATED, MirandaIsTerminated); + CreateServiceFunction(MS_SYSTEM_OKTOEXIT, OkToExit); + CreateServiceFunction(MS_SYSTEM_GETVERSION, GetMirandaVersion); + CreateServiceFunction(MS_SYSTEM_GETFILEVERSION, GetMirandaFileVersion); + CreateServiceFunction(MS_SYSTEM_GETVERSIONTEXT, GetMirandaVersionText); + CreateServiceFunction(MS_SYSTEM_WAITONHANDLE, WaitOnHandle); + CreateServiceFunction(MS_SYSTEM_REMOVEWAIT, RemoveWait); + CreateServiceFunction(MS_SYSTEM_GETEXCEPTFILTER, srvGetExceptionFilter); + CreateServiceFunction(MS_SYSTEM_SETEXCEPTFILTER, srvSetExceptionFilter); + return 0; +} diff --git a/src/core/miranda.h b/src/core/miranda.h new file mode 100644 index 0000000000..2609052789 --- /dev/null +++ b/src/core/miranda.h @@ -0,0 +1,199 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda 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. +*/ + +typedef HRESULT (STDAPICALLTYPE *pfnDrawThemeTextEx)(HTHEME, HDC, int, int, LPCWSTR, int, DWORD, LPRECT, const struct _DTTOPTS *); +typedef HRESULT (STDAPICALLTYPE *pfnSetWindowThemeAttribute)(HWND, enum WINDOWTHEMEATTRIBUTETYPE, PVOID, DWORD); +typedef HRESULT (STDAPICALLTYPE *pfnBufferedPaintInit)(void); +typedef HRESULT (STDAPICALLTYPE *pfnBufferedPaintUninit)(void); +typedef HANDLE (STDAPICALLTYPE *pfnBeginBufferedPaint)(HDC, RECT *, BP_BUFFERFORMAT, BP_PAINTPARAMS *, HDC *); +typedef HRESULT (STDAPICALLTYPE *pfnEndBufferedPaint)(HANDLE, BOOL); +typedef HRESULT (STDAPICALLTYPE *pfnGetBufferedPaintBits)(HANDLE, RGBQUAD **, int *); + +extern pfnDrawThemeTextEx drawThemeTextEx; +extern pfnSetWindowThemeAttribute setWindowThemeAttribute; +extern pfnBufferedPaintInit bufferedPaintInit; +extern pfnBufferedPaintUninit bufferedPaintUninit; +extern pfnBeginBufferedPaint beginBufferedPaint; +extern pfnEndBufferedPaint endBufferedPaint; +extern pfnGetBufferedPaintBits getBufferedPaintBits; + +extern ITaskbarList3 * pTaskbarInterface; + +typedef HRESULT (STDAPICALLTYPE *pfnDwmExtendFrameIntoClientArea)(HWND hwnd, const MARGINS *margins); +typedef HRESULT (STDAPICALLTYPE *pfnDwmIsCompositionEnabled)(BOOL *); + +extern pfnDwmExtendFrameIntoClientArea dwmExtendFrameIntoClientArea; +extern pfnDwmIsCompositionEnabled dwmIsCompositionEnabled; + +/**** database.cpp *********************************************************************/ + +extern MIDatabase* currDb; +extern DATABASELINK* currDblink; +extern LIST arDbPlugins; + +int InitIni(void); +void UninitIni(void); + +/**** extraicons.cpp *******************************************************************/ + +void KillModuleExtraIcons(int hLangpack); + +/**** fontService.cpp ******************************************************************/ + +void KillModuleFonts(int hLangpack); +void KillModuleColours(int hLangpack); +void KillModuleEffects(int hLangpack); +void KillModuleHotkeys(int hLangpack); +void KillModuleSounds(int hLangpack); + +/**** miranda.cpp **********************************************************************/ + +extern HINSTANCE hInst; +extern DWORD hMainThreadId; +extern HANDLE hOkToExitEvent, hModulesLoadedEvent, hevLoadModule, hevUnloadModule; +extern TCHAR mirandabootini[MAX_PATH]; + +/**** newplugins.cpp *******************************************************************/ + +char* GetPluginNameByInstance(HINSTANCE hInstance); +int GetPluginFakeId(const MUUID &uuid, int hLangpack); +int LoadStdPlugins(void); + +/**** path.cpp *************************************************************************/ + +void InitPathVar(void); + +/**** srmm.cpp *************************************************************************/ + +void KillModuleSrmmIcons(int hLangpack); + +/**** utf.cpp **************************************************************************/ + +__forceinline char* Utf8DecodeA(const char* src) +{ + char* tmp = mir_strdup(src); + Utf8Decode(tmp, NULL); + return tmp; +} + +#pragma optimize("", on) + +/**** options.cpp **********************************************************************/ + +HTREEITEM FindNamedTreeItemAtRoot(HWND hwndTree, const TCHAR* name); + +/**** skin2icons.cpp *******************************************************************/ + +void KillModuleIcons(int hLangpack); + +/**** skinicons.cpp ********************************************************************/ + +HICON LoadIconEx(HINSTANCE hInstance, LPCTSTR lpIconName, BOOL bShared); +int ImageList_AddIcon_NotShared(HIMAGELIST hIml, LPCTSTR szResource); +int ImageList_ReplaceIcon_NotShared(HIMAGELIST hIml, int iIndex, HINSTANCE hInstance, LPCTSTR szResource); + +int ImageList_AddIcon_IconLibLoaded(HIMAGELIST hIml, int iconId); +int ImageList_AddIcon_ProtoIconLibLoaded(HIMAGELIST hIml, const char *szProto, int iconId); +int ImageList_ReplaceIcon_IconLibLoaded(HIMAGELIST hIml, int nIndex, HICON hIcon); + +#define Safe_DestroyIcon(hIcon) if (hIcon) DestroyIcon(hIcon) + +/**** clistmenus.cpp ********************************************************************/ + +extern HANDLE hMainMenuObject, hContactMenuObject, hStatusMenuObject; +extern HANDLE hPreBuildMainMenuEvent, hPreBuildContactMenuEvent; +extern HANDLE hShutdownEvent, hPreShutdownEvent; + +extern const int statusModeList[ MAX_STATUS_COUNT ]; +extern const int skinIconStatusList[ MAX_STATUS_COUNT ]; +extern const int skinIconStatusFlags[ MAX_STATUS_COUNT ]; + +int TryProcessDoubleClick(MCONTACT hContact); + +void KillModuleMenus(int hLangpack); + +/**** protocols.cpp *********************************************************************/ + +#define OFFSET_PROTOPOS 200 +#define OFFSET_VISIBLE 400 +#define OFFSET_ENABLED 600 +#define OFFSET_NAME 800 + +extern LIST accounts; + +PROTOACCOUNT* Proto_CreateAccount(const char *szModuleName, const char *szBaseProto, const TCHAR *tszAccountName); + +PROTOACCOUNT* __fastcall Proto_GetAccount(const char *accName); +PROTOACCOUNT* __fastcall Proto_GetAccount(MCONTACT hContact); + +bool __fastcall Proto_IsAccountEnabled(PROTOACCOUNT *pa); +bool __fastcall Proto_IsAccountLocked(PROTOACCOUNT *pa); + +PROTO_INTERFACE* AddDefaultAccount(const char *szProtoName); +int FreeDefaultAccount(PROTO_INTERFACE* ppi); + +BOOL ActivateAccount(PROTOACCOUNT *pa); +void EraseAccount(const char *pszProtoName); +void DeactivateAccount(PROTOACCOUNT *pa, bool bIsDynamic, bool bErase); +void UnloadAccount(PROTOACCOUNT *pa, bool bIsDynamic, bool bErase); +void OpenAccountOptions(PROTOACCOUNT *pa); + +void LoadDbAccounts(void); +void WriteDbAccounts(void); + +INT_PTR CallProtoServiceInt(MCONTACT hContact, const char* szModule, const char* szService, WPARAM wParam, LPARAM lParam); + +/**** utils.cpp ************************************************************************/ + +void HotkeyToName(TCHAR *buf, int size, BYTE shift, BYTE key); +WORD GetHotkeyValue(INT_PTR idHotkey); +int AssertInsideScreen(RECT &rc); + +HBITMAP ConvertIconToBitmap(HICON hIcon, HIMAGELIST hIml, int iconId); + +class StrConvA +{ +private: + char* m_body; + +public: + StrConvA(const wchar_t* pSrc) : + m_body(mir_u2a(pSrc)) {} + + ~StrConvA() { mir_free(m_body); } + operator const char* () const { return m_body; } + operator const wchar_t* () const { return (wchar_t*)m_body; } // type cast to fake the interface definition + operator const LPARAM () const { return (LPARAM)m_body; } +}; + +/////////////////////////////////////////////////////////////////////////////// + +extern "C" +{ + MIR_CORE_DLL(int) Langpack_MarkPluginLoaded(PLUGININFOEX* pInfo); + MIR_CORE_DLL(int) GetSubscribersCount(HANDLE hHook); + MIR_CORE_DLL(void) db_setCurrent(MIDatabase* _db); + + MIR_CORE_DLL(PROTOCOLDESCRIPTOR*) Proto_RegisterModule(PROTOCOLDESCRIPTOR *pd); +}; diff --git a/src/core/modules.cpp b/src/core/modules.cpp new file mode 100644 index 0000000000..21824566ed --- /dev/null +++ b/src/core/modules.cpp @@ -0,0 +1,184 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda 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" + +#include "../modules/plugins/plugins.h" +#include "../modules/langpack/langpack.h" +#include "../modules/chat/chat.h" + +INT_PTR CheckRestart(); // core: IDD_WAITRESTART + +int LoadSystemModule(void); // core: m_system.h services +int LoadNewPluginsModuleInfos(void); // core: preloading plugins +int LoadNewPluginsModule(void); // core: N.O. plugins +int LoadNetlibModule(void); // core: network +int LoadSslModule(void); +int LoadLangpackModule(void); // core: translation +int LoadProtocolsModule(void); // core: protocol manager +int LoadAccountsModule(void); // core: account manager +int LoadIgnoreModule(void); // protocol filter: ignore +int LoadDbintfModule(void); +int LoadEventsModule(void); +int LoadSrmmModule(void); + +int LoadContactsModule(void); +int LoadContactListModule(void);// ui: clist +int LoadDatabaseModule(void); +int LoadMetacontacts(void); +int LoadOptionsModule(void); // ui: options dialog +int LoadFindAddModule(void); // ui: search/add users +int LoadSkinIcons(void); +int LoadSkinSounds(void); +int LoadSkinHotkeys(void); +int LoadUserInfoModule(void); // ui: user info +int LoadVisibilityModule(void); // ui: visibility control + +int LoadPluginOptionsModule(void); // ui: plugin viewer +int LoadAddContactModule(void); // ui: authcontrol contacts +int LoadUtilsModule(void); // ui: utils (has a few window classes, like HyperLink) +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); +int LoadDefaultServiceModePlugin(void); +int LoadErrorsModule(void); + +void UnloadAccountsModule(void); +void UnloadClcModule(void); +void UnloadContactListModule(void); +void UnloadDatabase(void); +void UnloadErrorsModule(void); +void UnloadEventsModule(void); +void UnloadExtraIconsModule(void); +void UnloadIcoLibModule(void); +void UnloadMetacontacts(void); +void UnloadNetlibModule(void); +void UnloadNewPlugins(void); +void UnloadProtocolsModule(void); +void UnloadSkinSounds(void); +void UnloadSkinHotkeys(void); +void UnloadSrmmModule(void); +void UnloadUtilsModule(void); + +int LoadIcoTabsModule(); +int LoadHeaderbarModule(); +int LoadDescButtonModule(); + +int LoadDefaultModules(void) +{ + // load order is very important for these + if (LoadSystemModule()) return 1; + if (LoadLangpackModule()) return 1; // langpack will be a system module in the new order so this is moved here + if (CheckRestart()) return 1; + if (LoadUtilsModule()) return 1; //order not important for this, but no dependencies and no point in pluginising + if (LoadIcoTabsModule()) return 1; + if (LoadHeaderbarModule()) return 1; + if (LoadDbintfModule()) return 1; + if (LoadEventsModule()) return 1; + + // load database drivers & service plugins without executing their Load() + if (LoadNewPluginsModuleInfos()) return 1; + + switch (LoadDefaultServiceModePlugin()) { + case SERVICE_CONTINUE: // continue loading Miranda normally + case SERVICE_ONLYDB: // load database and go to the message cycle + break; + case SERVICE_MONOPOLY: // unload database and go to the message cycle + return 0; + default: // smth went wrong, terminating + return 1; + } + + // the database will select which db plugin to use, or fail if no profile is selected + if (LoadDatabaseModule()) return 1; + + // database is available here + if (LoadButtonModule()) return 1; + 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; + if (LoadSrmmModule()) return 1; + if (LoadChatModule()) return 1; + if (LoadDescButtonModule()) return 1; + if (LoadOptionsModule()) return 1; + if (LoadNetlibModule()) return 1; + if (LoadSslModule()) return 1; + if (LoadProtocolsModule()) return 1; + LoadDbAccounts(); // retrieves the account array from a database + if (LoadContactsModule()) return 1; + if (LoadContactListModule()) return 1; // prepare contact list interface + if (LoadAddContactModule()) return 1; + if (LoadMetacontacts()) return 1; + + if (LoadNewPluginsModule()) return 1; // will call Load(void) on everything, clist will load first + + Langpack_SortDuplicates(); + + if (LoadAccountsModule()) return 1; + + //order becomes less important below here + if (LoadFindAddModule()) return 1; + if (LoadIgnoreModule()) return 1; + if (LoadVisibilityModule()) return 1; + if (LoadStdPlugins()) return 1; + return 0; +} + +void UnloadDefaultModules(void) +{ + UnloadChatModule(); + UnloadAccountsModule(); + UnloadMetacontacts(); + UnloadNewPlugins(); + UnloadProtocolsModule(); + UnloadSkinSounds(); + UnloadSkinHotkeys(); + UnloadSrmmModule(); + // UnloadErrorsModule(); + UnloadIcoLibModule(); + UnloadUtilsModule(); + UnloadExtraIconsModule(); + UnloadClcModule(); + UnloadContactListModule(); + UnloadEventsModule(); + UnloadNetlibModule(); +} diff --git a/src/core/stdafx.cpp b/src/core/stdafx.cpp new file mode 100644 index 0000000000..288f19664b --- /dev/null +++ b/src/core/stdafx.cpp @@ -0,0 +1,19 @@ +/* + +Copyright (C) 2012-15 Miranda NG team (http://miranda-ng.org) + +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 version 2 +of the License. + +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, see . +*/ + +#include "commonheaders.h" \ No newline at end of file -- cgit v1.2.3