From ffcd96c8ebd7365d1a92486b5b6efaf30e61d72c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 26 Jul 2012 18:55:37 +0000 Subject: - local core command-line parser banished with shame; - plugins' linked lists replaced with the usual lists; - numerous perversions in the core eliminated; - missing file added git-svn-id: http://svn.miranda-ng.org/main/trunk@1200 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/database/database.cpp | 117 ++++++---------- src/modules/database/profilemanager.cpp | 233 +++++++++++++++----------------- src/modules/plugins/newplugins.cpp | 108 ++++----------- src/modules/plugins/plugins.h | 3 +- 4 files changed, 177 insertions(+), 284 deletions(-) (limited to 'src') diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp index 65bb98fb6d..05c44ff19d 100644 --- a/src/modules/database/database.cpp +++ b/src/modules/database/database.cpp @@ -30,7 +30,8 @@ TCHAR g_profileDir[MAX_PATH], g_profileName[MAX_PATH]; bool fileExist(TCHAR* fname) { - if (fname[0] == 0) return false; + if (*fname == 0) + return false; FILE* fp = _tfopen(fname, _T("r+")); bool res = fp != NULL; @@ -56,10 +57,8 @@ bool IsInsideRootDir(TCHAR* profiledir, bool exact) if (exact) res = _tcsicmp(profiledir, pfd); else - { - size_t len = _tcslen(pfd); - res = _tcsnicmp(profiledir, pfd, len); - } + res = _tcsnicmp(profiledir, pfd, _tcslen(pfd)); + mir_free(pfd); return res == 0; } @@ -130,73 +129,41 @@ static void getDefaultProfile(TCHAR *szProfile, size_t cch, TCHAR *profiledir) } // returns 1 if something that looks like a profile is there -static int getProfileCmdLineArgs(TCHAR *szProfile, size_t cch) +void getProfileCmdLine(TCHAR *szProfile, size_t cch, TCHAR *profiledir) { - TCHAR *szCmdLine = GetCommandLine(); - TCHAR *szEndOfParam; - TCHAR szThisParam[1024]; - int firstParam = 1; - - while (szCmdLine[0]) - { - if (szCmdLine[0] == '"') - { - szEndOfParam = _tcschr(szCmdLine+1, '"'); - if (szEndOfParam == NULL) break; - lstrcpyn(szThisParam, szCmdLine+1, min(SIZEOF(szThisParam), szEndOfParam - szCmdLine)); - szCmdLine = szEndOfParam + 1; - } - else - { - szEndOfParam = szCmdLine + _tcscspn(szCmdLine, _T(" \t")); - lstrcpyn(szThisParam, szCmdLine, min(SIZEOF(szThisParam), szEndOfParam - szCmdLine+1)); - szCmdLine = szEndOfParam; - } - while (*szCmdLine && *szCmdLine <= ' ') szCmdLine++; - if (firstParam) { firstParam = 0; continue; } //first param is executable name - if (szThisParam[0] == '/' || szThisParam[0] == '-') continue; //no switches supported - - TCHAR* res = Utils_ReplaceVarsT(szThisParam); - if (res == NULL) return 0; - _tcsncpy(szProfile, res, cch); szProfile[cch-1] = 0; - mir_free(res); - return 1; + LPCTSTR ptszProfileName = CmdLine_GetOption( _T("profile")); + if (ptszProfileName == NULL) { + szProfile[0] = 0; + return; } - return 0; -} -void getProfileCmdLine(TCHAR *szProfile, size_t cch, TCHAR *profiledir) -{ TCHAR buf[MAX_PATH]; - if (getProfileCmdLineArgs(buf, SIZEOF(buf))) - { - TCHAR *p, profileName[MAX_PATH], newProfileDir[MAX_PATH]; - - p = _tcsrchr(buf, '\\'); if (p) ++p; else p = buf; - - if ( !isValidProfileName(buf) && *p) - _tcscat(buf, _T(".dat")); - - _tcscpy(profileName, p); - p = _tcsrchr(profileName, '.'); if (p) *p = 0; - - mir_sntprintf(newProfileDir, cch, _T("%s\\%s\\"), profiledir, profileName); - PathToAbsoluteT(buf, szProfile, newProfileDir); - - if (_tcschr(buf, '\\')) - { - _tcscpy(profiledir, szProfile); - if (profileName[0]) - { - p = _tcsrchr(profiledir, '\\'); *p = 0; - p = _tcsrchr(profiledir, '\\'); - if (p && _tcsicmp(p + 1, profileName) == 0) - *p = 0; - } - else - szProfile[0] = 0; - + _tcsncpy(buf, ptszProfileName, SIZEOF(buf)); + + TCHAR *p = _tcsrchr(buf, '\\'); if (p) ++p; else p = buf; + if ( !isValidProfileName(buf) && *p) + _tcscat(buf, _T(".dat")); + + TCHAR profileName[MAX_PATH], newProfileDir[MAX_PATH]; + _tcscpy(profileName, p); + if ( !isValidProfileName(profileName) && *p) + _tcscat(profileName, _T(".dat")); + + _tcscpy(profileName, p); + p = _tcsrchr(profileName, '.'); if (p) *p = 0; + + mir_sntprintf(newProfileDir, cch, _T("%s\\%s\\"), profiledir, profileName); + PathToAbsoluteT(buf, szProfile, newProfileDir); + + if ( _tcschr(buf, '\\')) { + _tcscpy(profiledir, szProfile); + if (profileName[0]) { + p = _tcsrchr(profiledir, '\\'); *p = 0; + p = _tcsrchr(profiledir, '\\'); + if (p && _tcsicmp(p + 1, profileName) == 0) + *p = 0; } + else szProfile[0] = 0; } } @@ -209,8 +176,7 @@ static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) mir_sntprintf(pfd, SIZEOF(pfd), _T("%s"), path); mir_free(path); } - else - mir_sntprintf(pfd, SIZEOF(pfd), _T("%s\\*.dat"), profiledir); + else mir_sntprintf(pfd, SIZEOF(pfd), _T("%s\\*.dat"), profiledir); WIN32_FIND_DATA ffd; HANDLE hFind = FindFirstFile(pfd, &ffd); @@ -226,8 +192,7 @@ static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) mir_sntprintf(path2, SIZEOF(path2), _T("%s\\%s"), profiledir, profile); CreateDirectoryTreeT(path2); mir_sntprintf(path2, SIZEOF(path2), _T("%s\\%s\\%s"), profiledir, profile, ffd.cFileName); - if (_taccess(path2, 0) == 0) - { + if (_taccess(path2, 0) == 0) { const TCHAR tszMoveMsg[] = _T("Miranda is trying upgrade your profile structure.\n") _T("It cannot move profile %s to the new location %s\n") @@ -237,8 +202,7 @@ static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) mir_sntprintf(buf, SIZEOF(buf), TranslateTS(tszMoveMsg), path, path2); MessageBox(NULL, buf, _T("Miranda NG"), MB_ICONERROR | MB_OK); } - else if (MoveFile(path, path2) == 0) - { + else if (MoveFile(path, path2) == 0) { const TCHAR tszMoveMsg[] = _T("Miranda is trying upgrade your profile structure.\n") _T("It cannot move profile %s to the new location %s automatically\n") @@ -320,16 +284,13 @@ static int getProfileAutoRun(TCHAR *szProfile) static int getProfile(TCHAR *szProfile, size_t cch) { getProfilePath(g_profileDir, SIZEOF(g_profileDir)); - if (IsInsideRootDir(g_profileDir, true)) - { + if (IsInsideRootDir(g_profileDir, true)) if (WritePrivateProfileString(_T("Database"), _T("ProfileDir"), _T(""), mirandabootini)) getProfilePath(g_profileDir, SIZEOF(g_profileDir)); - } getDefaultProfile(szProfile, cch, g_profileDir); getProfileCmdLine(szProfile, cch, g_profileDir); - if (IsInsideRootDir(g_profileDir, true)) - { + if (IsInsideRootDir(g_profileDir, true)) { MessageBox(NULL, _T("Profile cannot be placed into Miranda root folder.\n") _T("Please move Miranda profile to some other location."), diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp index 4303aeddf9..2d9b003e9a 100644 --- a/src/modules/database/profilemanager.cpp +++ b/src/modules/database/profilemanager.cpp @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "..\..\core\commonheaders.h" +#include "..\plugins\plugins.h" #include "profilemanager.h" #include @@ -67,8 +68,7 @@ struct ProfileEnumData { extern TCHAR mirandabootini[MAX_PATH]; -char **GetServiceModePluginsList(void); -void SetServiceModePlugin(int idx); +void SetServiceModePlugin(pluginEntry* p); static void ThemeDialogBackground(HWND hwnd) { @@ -383,8 +383,7 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, break; case WM_TIMER: - if (WaitForSingleObject(dat->hFileNotify, 0) == WAIT_OBJECT_0) - { + if (WaitForSingleObject(dat->hFileNotify, 0) == WAIT_OBJECT_0) { ListView_DeleteAllItems(hwndList); ProfileEnumData ped = { hwndDlg, dat->pd->szProfile }; findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped); @@ -399,8 +398,7 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, break; case WM_SHOWWINDOW: - if (wParam) - { + if (wParam) { SetWindowText(dat->hwndOK, TranslateT("&Run")); EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1); } @@ -435,21 +433,18 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, break; } - case WM_NOTIFY: { LPNMHDR hdr = (LPNMHDR) lParam; if (hdr && hdr->code == PSN_INFOCHANGED) break; - if (hdr && hdr->idFrom == IDC_PROFILELIST) - { - switch (hdr->code) - { - case LVN_ITEMCHANGED: - EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1); + if (hdr && hdr->idFrom == IDC_PROFILELIST) { + switch (hdr->code) { + case LVN_ITEMCHANGED: + EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1); - case NM_DBLCLK: + case NM_DBLCLK: { LVITEM item = {0}; TCHAR profile[MAX_PATH]; @@ -476,7 +471,7 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, return TRUE; } - case LVN_KEYDOWN: + case LVN_KEYDOWN: { LPNMLVKEYDOWN hdrk = (LPNMLVKEYDOWN) lParam; if (hdrk->wVKey == VK_DELETE) @@ -486,7 +481,8 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, } } break; - } } + } + } return FALSE; } @@ -497,36 +493,31 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, switch (msg) { case WM_INITDIALOG: - { - struct DlgProfData * prof = (struct DlgProfData *)lParam; - PROPSHEETHEADER *psh = prof->psh; TranslateDialogDefault(hwndDlg); - SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_USERDETAILS), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); - SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_USERDETAILS), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0)); - dat = (struct DetailsData*)mir_alloc(sizeof(struct DetailsData)); - dat->prof = prof; - prof->hwndOK = GetDlgItem(hwndDlg, IDOK); - EnableWindow(prof->hwndOK, FALSE); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - { + struct DlgProfData * prof = (struct DlgProfData *)lParam; + PROPSHEETHEADER *psh = prof->psh; + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_USERDETAILS), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_USERDETAILS), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0)); + dat = (struct DetailsData*)mir_alloc(sizeof(struct DetailsData)); + dat->prof = prof; + prof->hwndOK = GetDlgItem(hwndDlg, IDOK); + EnableWindow(prof->hwndOK, FALSE); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + TCHAR buf[512]; mir_sntprintf(buf, SIZEOF(buf), _T("%s: %s\n%s"), TranslateT("Miranda Profiles from"), prof->pd->szProfileDir, TranslateT("Select or create your Miranda NG user profile")); SetDlgItemText(hwndDlg, IDC_NAME, buf); - } - - { OPTIONSDIALOGPAGE *odp; - int i; - TCITEM tci; dat->currentPage = 0; dat->pageCount = psh->nPages; dat->opd = (struct DetailsPageData*)mir_calloc(sizeof(struct DetailsPageData)*dat->pageCount); - odp = (OPTIONSDIALOGPAGE*)psh->ppsp; + OPTIONSDIALOGPAGE *odp = (OPTIONSDIALOGPAGE*)psh->ppsp; + TCITEM tci; tci.mask = TCIF_TEXT; - for (i=0; i < dat->pageCount; i++) { + for (int i=0; i < dat->pageCount; i++) { dat->opd[i].pTemplate = (DLGTEMPLATE *)LockResource(LoadResource(odp[i].hInstance, FindResourceA(odp[i].hInstance, odp[i].pszTemplate, MAKEINTRESOURCEA(5)))); dat->opd[i].dlgProc = odp[i].pfnDlgProc; dat->opd[i].hInst = odp[i].hInstance; @@ -536,53 +527,47 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, if (dat->prof->pd->noProfiles || shouldAutoCreate(dat->prof->pd->szProfile)) dat->currentPage = 1; TabCtrl_InsertItem(GetDlgItem(hwndDlg, IDC_TABS), i, &tci); - } } + } + + GetWindowRect(GetDlgItem(hwndDlg, IDC_TABS), &dat->rcDisplay); + TabCtrl_AdjustRect(GetDlgItem(hwndDlg, IDC_TABS), FALSE, &dat->rcDisplay); - GetWindowRect(GetDlgItem(hwndDlg, IDC_TABS), &dat->rcDisplay); - TabCtrl_AdjustRect(GetDlgItem(hwndDlg, IDC_TABS), FALSE, &dat->rcDisplay); - { POINT pt = {0, 0}; ClientToScreen(hwndDlg, &pt); OffsetRect(&dat->rcDisplay, -pt.x, -pt.y); - } - TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), dat->currentPage); - dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof); - ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); - SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE); - { PSHNOTIFY pshn; + TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_TABS), dat->currentPage); + dat->opd[dat->currentPage].hwnd = CreateDialogIndirectParam(dat->opd[dat->currentPage].hInst, dat->opd[dat->currentPage].pTemplate, hwndDlg, dat->opd[dat->currentPage].dlgProc, (LPARAM)dat->prof); + ThemeDialogBackground(dat->opd[dat->currentPage].hwnd); + SetWindowPos(dat->opd[dat->currentPage].hwnd, HWND_TOP, dat->rcDisplay.left, dat->rcDisplay.top, 0, 0, SWP_NOSIZE); + + PSHNOTIFY pshn; pshn.hdr.code = PSN_INFOCHANGED; pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; pshn.hdr.idFrom = 0; pshn.lParam = (LPARAM)0; SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); - } - // service mode combobox - { - char **list = GetServiceModePluginsList(); - if ( !list) { + + // service mode combobox + if (servicePlugins.getCount() == 0) { ShowWindow(GetDlgItem(hwndDlg, IDC_SM_LABEL), FALSE); ShowWindow(GetDlgItem(hwndDlg, IDC_SM_COMBO), FALSE); - } else { - int i=0; - LRESULT index; + } + else { HWND hwndCombo = GetDlgItem(hwndDlg, IDC_SM_COMBO); - index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T("")); + LRESULT index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)_T("")); SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)-1); SendMessage(hwndCombo, CB_SETCURSEL, 0, 0); - while (list[i]) { - TCHAR *str = Langpack_PcharToTchar(list[i]); - index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)str); - mir_free(str); + for (int i=0; i < servicePlugins.getCount(); i++) { + pluginEntry* p = servicePlugins[i]; + index = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateTS(p->pluginname)); SendMessage(hwndCombo, CB_SETITEMDATA, index, (LPARAM)i); - i++; } - mir_free(list); } + ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); } - ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); return TRUE; - } + case WM_CTLCOLORSTATIC: switch (GetDlgCtrlID((HWND)lParam)) { case IDC_WHITERECT: @@ -596,37 +581,39 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, return TRUE; case PSM_FORCECHANGED: - { PSHNOTIFY pshn; - int i; - - pshn.hdr.code = PSN_INFOCHANGED; - pshn.hdr.idFrom = 0; - pshn.lParam = (LPARAM)0; - for (i=0; i < dat->pageCount; i++) { - pshn.hdr.hwndFrom = dat->opd[i].hwnd; - if (dat->opd[i].hwnd != NULL) - SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); + { + PSHNOTIFY pshn; + pshn.hdr.code = PSN_INFOCHANGED; + pshn.hdr.idFrom = 0; + pshn.lParam = (LPARAM)0; + for (int i=0; i < dat->pageCount; i++) { + pshn.hdr.hwndFrom = dat->opd[i].hwnd; + if (dat->opd[i].hwnd != NULL) + SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); + } } break; - } + case WM_NOTIFY: switch(wParam) { case IDC_TABS: switch(((LPNMHDR)lParam)->code) { case TCN_SELCHANGING: - { PSHNOTIFY pshn; - if (dat->currentPage == -1 || dat->opd[dat->currentPage].hwnd == NULL) - break; - pshn.hdr.code = PSN_KILLACTIVE; - pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; - pshn.hdr.idFrom = 0; - pshn.lParam = 0; - if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) { - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); - return TRUE; + { + PSHNOTIFY pshn; + if (dat->currentPage == -1 || dat->opd[dat->currentPage].hwnd == NULL) + break; + pshn.hdr.code = PSN_KILLACTIVE; + pshn.hdr.hwndFrom = dat->opd[dat->currentPage].hwnd; + pshn.hdr.idFrom = 0; + pshn.lParam = 0; + if (SendMessage(dat->opd[dat->currentPage].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn)) { + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, TRUE); + return TRUE; + } } break; - } + case TCN_SELCHANGE: if (dat->currentPage != -1 && dat->opd[dat->currentPage].hwnd != NULL) ShowWindow(dat->opd[ dat->currentPage ].hwnd, SW_HIDE); @@ -655,13 +642,15 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, case WM_COMMAND: switch(LOWORD(wParam)) { case IDCANCEL: - { int i; + { PSHNOTIFY pshn; pshn.hdr.idFrom = 0; pshn.lParam = 0; pshn.hdr.code = PSN_RESET; - for (i=0;ipageCount;i++) { - if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed) continue; + for (int i=0; i < dat->pageCount; i++) { + if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed) + continue; + pshn.hdr.hwndFrom = dat->opd[i].hwnd; SendMessage(dat->opd[i].hwnd, WM_NOTIFY, 0, (LPARAM)&pshn); } @@ -678,7 +667,6 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, case IDOK: { - int i; PSHNOTIFY pshn; pshn.hdr.idFrom = 0; pshn.lParam = (LPARAM)0; @@ -690,7 +678,7 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, } pshn.hdr.code = PSN_APPLY; - for (i=0; i < dat->pageCount; i++) { + for (int i=0; i < dat->pageCount; i++) { if (dat->opd[i].hwnd == NULL || !dat->opd[i].changed) continue; @@ -703,10 +691,12 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, dat->currentPage = i; ShowWindow(dat->opd[dat->currentPage].hwnd, SW_SHOW); return 0; - } } + } + } EndDialog(hwndDlg, 1); break; - } } + } + } break; case WM_DESTROY: @@ -714,14 +704,14 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam, LRESULT curSel = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETCURSEL, 0, 0); if (curSel != CB_ERR) { int idx = SendDlgItemMessage(hwndDlg, IDC_SM_COMBO, CB_GETITEMDATA, (WPARAM)curSel, 0); - SetServiceModePlugin(idx); + SetServiceModePlugin(servicePlugins[idx]); } } DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, 0)); DestroyIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); DeleteObject(dat->hBoldFont); - { int i; - for (i=0; i < dat->pageCount; i++) + { + for (int i=0; i < dat->pageCount; i++) if (dat->opd[i].hwnd != NULL) DestroyWindow(dat->opd[i].hwnd); } @@ -738,22 +728,21 @@ static int AddProfileManagerPage(struct DetailsPageInit * opi, OPTIONSDIALOGPAGE return 1; opi->odp = (OPTIONSDIALOGPAGE*)mir_realloc(opi->odp, sizeof(OPTIONSDIALOGPAGE)*(opi->pageCount+1)); - { - OPTIONSDIALOGPAGE* p = opi->odp + opi->pageCount++; - p->cbSize = sizeof(OPTIONSDIALOGPAGE); - p->hInstance = odp->hInstance; - p->pfnDlgProc = odp->pfnDlgProc; - p->position = odp->position; - p->ptszTitle = Langpack_PcharToTchar(odp->pszTitle); - p->pszGroup = NULL; - p->groupPosition = odp->groupPosition; - p->hGroupIcon = odp->hGroupIcon; - p->hIcon = odp->hIcon; - if ((DWORD_PTR)odp->pszTemplate & 0xFFFF0000) - p->pszTemplate = mir_strdup(odp->pszTemplate); - else - p->pszTemplate = odp->pszTemplate; - } + + OPTIONSDIALOGPAGE* p = opi->odp + opi->pageCount++; + p->cbSize = sizeof(OPTIONSDIALOGPAGE); + p->hInstance = odp->hInstance; + p->pfnDlgProc = odp->pfnDlgProc; + p->position = odp->position; + p->ptszTitle = Langpack_PcharToTchar(odp->pszTitle); + p->pszGroup = NULL; + p->groupPosition = odp->groupPosition; + p->hGroupIcon = odp->hGroupIcon; + p->hIcon = odp->hIcon; + if ((DWORD_PTR)odp->pszTemplate & 0xFFFF0000) + p->pszTemplate = mir_strdup(odp->pszTemplate); + else + p->pszTemplate = odp->pszTemplate; return 0; } @@ -763,20 +752,18 @@ int getProfileManager(PROFILEMANAGERDATA * pd) opi.pageCount = 0; opi.odp = NULL; - { - OPTIONSDIALOGPAGE odp = { 0 }; - odp.cbSize = sizeof(odp); - odp.pszTitle = LPGEN("My Profiles"); - odp.pfnDlgProc = DlgProfileSelect; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROFILE_SELECTION); - odp.hInstance = hInst; - AddProfileManagerPage(&opi, &odp); - - odp.pszTitle = LPGEN("New Profile"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROFILE_NEW); - odp.pfnDlgProc = DlgProfileNew; - AddProfileManagerPage(&opi, &odp); - } + OPTIONSDIALOGPAGE odp = { 0 }; + odp.cbSize = sizeof(odp); + odp.pszTitle = LPGEN("My Profiles"); + odp.pfnDlgProc = DlgProfileSelect; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROFILE_SELECTION); + odp.hInstance = hInst; + AddProfileManagerPage(&opi, &odp); + + odp.pszTitle = LPGEN("New Profile"); + odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROFILE_NEW); + odp.pfnDlgProc = DlgProfileNew; + AddProfileManagerPage(&opi, &odp); PROPSHEETHEADER psh = { 0 }; psh.dwSize = sizeof(psh); diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp index 3a1b02e664..dd8c93840a 100644 --- a/src/modules/plugins/newplugins.cpp +++ b/src/modules/plugins/newplugins.cpp @@ -31,23 +31,15 @@ static int sttComparePluginsByName(const pluginEntry* p1, const pluginEntry* p2) { return lstrcmp(p1->pluginname, p2->pluginname); } -LIST pluginList(10, sttComparePluginsByName); +LIST + pluginList(10, sttComparePluginsByName), + servicePlugins(5, sttComparePluginsByName), + clistPlugins(5, sttComparePluginsByName); ///////////////////////////////////////////////////////////////////////////////////////// #define MAX_MIR_VER ULONG_MAX -struct PluginUUIDList { - MUUID uuid; - DWORD maxVersion; -} -static const pluginBannedList[] = -{ - {{0x7f65393b, 0x7771, 0x4f3f, { 0xa9, 0xeb, 0x5d, 0xba, 0xf2, 0xb3, 0x61, 0xf1 }}, MAX_MIR_VER}, // png2dib - {{0xe00f1643, 0x263c, 0x4599, { 0xb8, 0x4b, 0x05, 0x3e, 0x5c, 0x51, 0x1d, 0x28 }}, MAX_MIR_VER}, // loadavatars (unicode) - {{0xc9e01eb0, 0xa119, 0x42d2, { 0xb3, 0x40, 0xe8, 0x67, 0x8f, 0x5f, 0xea, 0xd9 }}, MAX_MIR_VER}, // loadavatars (ansi) -}; - MuuidReplacement pluginDefault[] = { { MIID_UIUSERINFO, _T("stduserinfo"), NULL }, // 0 @@ -72,11 +64,11 @@ static BOOL bModuleInitialized = FALSE; TCHAR mirandabootini[MAX_PATH]; static DWORD mirandaVersion; -static int serviceModeIdx = -1, sttFakeID = -100; +static int sttFakeID = -100; static HANDLE hPluginListHeap = NULL; static int askAboutIgnoredPlugins; -static pluginEntry *pluginListSM, *pluginListUI, *pluginList_freeimg, *pluginList_crshdmp; +static pluginEntry *pluginList_freeimg, *pluginList_crshdmp, *serviceModePlugin = NULL; int InitIni(void); void UninitIni(void); @@ -166,7 +158,6 @@ int GetPluginFakeId(const MUUID &uuid, int hLangpack) return 0; } - MUUID miid_last = MIID_LAST; MUUID miid_chat = MIID_CHAT; MUUID miid_srmm = MIID_SRMM; @@ -185,18 +176,6 @@ static bool validInterfaceList(MUUID *piface) return true; } -static int isPluginBanned(MUUID u1, DWORD dwVersion) -{ - for (int i=0; i < SIZEOF(pluginBannedList); i++) { - if ( equalUUID(pluginBannedList[i].uuid, u1)) { - if (dwVersion < pluginBannedList[i].maxVersion) - return 1; - return 0; - } - } - return 0; -} - /* * historyeditor added by nightwish - plugin is problematic and can ruin database as it does not understand UTF-8 message * storage @@ -227,7 +206,7 @@ static int checkPI(BASIC_PLUGIN_INFO* bpi, PLUGININFOEX* pi) if (bpi->InfoEx == NULL || pi->cbSize != sizeof(PLUGININFOEX)) return FALSE; - if ( !validInterfaceList(bpi->Interfaces) || isPluginBanned(pi->uuid, pi->version)) + if ( !validInterfaceList(bpi->Interfaces)) return FALSE; if (pi->shortName == NULL || pi->description == NULL || pi->author == NULL || @@ -425,8 +404,7 @@ pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path) // plugin declared that it's a contact list. mark it for the future load else if ( hasMuuid(pIds, miid_clist)) { // keep a note of this plugin for later - if (pluginListUI != NULL) p->nextclass = pluginListUI; - pluginListUI = p; + clistPlugins.insert(p); p->pclass |= PCLASS_CLIST; } // plugin declared that it's a service mode plugin. @@ -438,9 +416,7 @@ pluginEntry* OpenPlugin(TCHAR *tszFileName, TCHAR *dir, TCHAR *path) p->bpi = bpi; if ( hasMuuid(bpi, miid_servicemode)) { p->pclass |= (PCLASS_SERVICE); - if (pluginListSM != NULL) - p->nextclass = pluginListSM; - pluginListSM = p; + servicePlugins.insert(p); } } else @@ -567,7 +543,8 @@ LBL_Error: static pluginEntry* getCListModule(TCHAR *exe, TCHAR *slice, int useWhiteList) { - for (pluginEntry *p = pluginListUI; p != NULL; p = p->nextclass) { + for (int i=0; i < clistPlugins.getCount(); i++) { + pluginEntry *p = clistPlugins[i]; mir_sntprintf(slice, &exe[MAX_PATH] - slice, _T("\\Plugins\\%s"), p->pluginname); CharLower(p->pluginname); if (useWhiteList && !isPluginOnWhiteList(p->pluginname)) @@ -607,55 +584,25 @@ int UnloadPlugin(TCHAR* buf, int bufLen) // // Service plugins functions -char **GetServiceModePluginsList(void) -{ - int i=0; - char **list = NULL; - pluginEntry * p = pluginListSM; - while (p != NULL) { - i++; - p = p->nextclass; - } - if (i) { - list = (char**)mir_calloc((i + 1) * sizeof(char*)); - p = pluginListSM; - i=0; - while (p != NULL) { - list[i++] = p->bpi.pluginInfo->shortName; - p = p->nextclass; - } - } - return list; -} - -void SetServiceModePlugin(int idx) +void SetServiceModePlugin(pluginEntry *p) { - serviceModeIdx = idx; + serviceModePlugin = p; } int LoadServiceModePlugin(void) { - int i=0; - pluginEntry* p = pluginListSM; - - if (serviceModeIdx < 0) + if (serviceModePlugin == NULL) return 0; - while (p != NULL) { - if (serviceModeIdx == i++) { - if (p->bpi.Load() == 0) { - p->pclass |= PCLASS_LOADED; - if (CallService(MS_SERVICEMODE_LAUNCH, 0, 0) != CALLSERVICE_NOTFOUND) - return 1; + if (serviceModePlugin->bpi.Load() == 0) { + serviceModePlugin->pclass |= PCLASS_LOADED; + if (CallService(MS_SERVICEMODE_LAUNCH, 0, 0) != CALLSERVICE_NOTFOUND) + return 1; - MessageBox(NULL, TranslateT("Unable to load plugin in Service Mode!"), p->pluginname, 0); - return -1; - } - Plugin_Uninit(p); - return -1; - } - p = p->nextclass; + MessageBox(NULL, TranslateT("Unable to load plugin in Service Mode!"), serviceModePlugin->pluginname, 0); + return -1; } + Plugin_Uninit(serviceModePlugin); return -1; } @@ -719,7 +666,7 @@ int LoadNewPluginsModule(void) /* the loop above will try and get one clist DLL to work, if all fail then just bail now */ if (clist == NULL) { // result = 0, no clist_* can be found - if (pluginListUI) + if (clistPlugins.getCount()) MessageBox(NULL, TranslateT("Unable to start any of the installed contact list plugins, I even ignored your preferences for which contact list couldn't load any."), _T("Miranda NG"), MB_OK | MB_ICONINFORMATION); else MessageBox(NULL, TranslateT("Can't find a contact list plugin! you need clist_classic or any other clist plugin.") , _T("Miranda NG"), MB_OK | MB_ICONINFORMATION); @@ -727,13 +674,10 @@ int LoadNewPluginsModule(void) } /* enable and disable as needed */ - p = pluginListUI; - while (p != NULL) { - SetPluginOnWhiteList(p->pluginname, clist != p ? 0 : 1); - p = p->nextclass; - } - /* now loop thru and load all the other plugins, do this in one pass */ + for (i=0; i < clistPlugins.getCount(); i++) + SetPluginOnWhiteList(p->pluginname, clist != clistPlugins[i] ? 0 : 1); + /* now loop thru and load all the other plugins, do this in one pass */ for (i=0; i < pluginList.getCount(); i++) { p = pluginList[i]; if ( !TryLoadPlugin(p, false)) { @@ -828,5 +772,7 @@ void UnloadNewPluginsModule(void) hPluginListHeap = 0; pluginList.destroy(); + servicePlugins.destroy(); + clistPlugins.destroy(); UninitIni(); } diff --git a/src/modules/plugins/plugins.h b/src/modules/plugins/plugins.h index e0466ccc35..d7b4d9adce 100644 --- a/src/modules/plugins/plugins.h +++ b/src/modules/plugins/plugins.h @@ -44,10 +44,9 @@ struct pluginEntry unsigned int pclass; // PCLASS_* int hLangpack; BASIC_PLUGIN_INFO bpi; - pluginEntry* nextclass; }; -extern LIST pluginList; +extern LIST pluginList, servicePlugins, clistPlugins; extern MUUID miid_last; int PluginOptionsInit(WPARAM, LPARAM); -- cgit v1.2.3