diff options
Diffstat (limited to 'plugins/StatusManager/src/StartupStatus')
4 files changed, 76 insertions, 109 deletions
diff --git a/plugins/StatusManager/src/StartupStatus/ss_options.cpp b/plugins/StatusManager/src/StartupStatus/ss_options.cpp index dc7acf304e..569aef54e2 100644 --- a/plugins/StatusManager/src/StartupStatus/ss_options.cpp +++ b/plugins/StatusManager/src/StartupStatus/ss_options.cpp @@ -53,7 +53,7 @@ static char* GetCMDLArguments(TProtoSettings& protoSettings) return nullptr; char *cmdl, *pnt; - pnt = cmdl = (char*)malloc(mir_strlen(protoSettings[0].m_szName) + mir_strlen(GetStatusDesc(protoSettings[0].m_status)) + 4); + pnt = cmdl = (char*)mir_alloc(mir_strlen(protoSettings[0].m_szName) + mir_strlen(GetStatusDesc(protoSettings[0].m_status)) + 4); for (int i = 0; i < protoSettings.getCount(); i++) { *pnt++ = '/'; @@ -65,7 +65,7 @@ static char* GetCMDLArguments(TProtoSettings& protoSettings) if (i != protoSettings.getCount() - 1) { *pnt++ = ' '; *pnt++ = '\0'; - cmdl = (char*)realloc(cmdl, mir_strlen(cmdl) + mir_strlen(protoSettings[i + 1].m_szName) + mir_strlen(GetStatusDesc(protoSettings[i + 1].m_status)) + 4); + cmdl = (char*)mir_realloc(cmdl, mir_strlen(cmdl) + mir_strlen(protoSettings[i + 1].m_szName) + mir_strlen(GetStatusDesc(protoSettings[i + 1].m_status)) + 4); pnt = cmdl + mir_strlen(cmdl); } } @@ -73,7 +73,7 @@ static char* GetCMDLArguments(TProtoSettings& protoSettings) if (db_get_b(0, SSMODULENAME, SETTING_SHOWDIALOG, FALSE) == TRUE) { *pnt++ = ' '; *pnt++ = '\0'; - cmdl = (char*)realloc(cmdl, mir_strlen(cmdl) + 12); + cmdl = (char*)mir_realloc(cmdl, mir_strlen(cmdl) + 12); pnt = cmdl + mir_strlen(cmdl); mir_strcpy(pnt, "/showdialog"); pnt += 11; @@ -88,14 +88,14 @@ static char* GetCMDL(TProtoSettings& protoSettings) char path[MAX_PATH]; GetModuleFileNameA(nullptr, path, MAX_PATH); - char* cmdl = (char*)malloc(mir_strlen(path) + 4); + char* cmdl = (char*)mir_alloc(mir_strlen(path) + 4); mir_snprintf(cmdl, mir_strlen(path) + 4, "\"%s\" ", path); char* args = GetCMDLArguments(protoSettings); if (args) { - cmdl = (char*)realloc(cmdl, mir_strlen(cmdl) + mir_strlen(args) + 1); + cmdl = (char*)mir_realloc(cmdl, mir_strlen(cmdl) + mir_strlen(args) + 1); mir_strcat(cmdl, args); - free(args); + mir_free(args); } return cmdl; } @@ -168,8 +168,8 @@ HRESULT CreateLink(TProtoSettings& protoSettings) ppf->Release(); } psl->Release(); - free(args); - free(desc); + mir_free(args); + mir_free(desc); } return hres; @@ -186,7 +186,7 @@ INT_PTR CALLBACK CmdlOptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA optionsProtoSettings = (TProtoSettings*)lParam; char* cmdl = GetCMDL(*optionsProtoSettings); SetDlgItemTextA(hwndDlg, IDC_CMDL, cmdl); - free(cmdl); + mir_free(cmdl); } break; @@ -397,11 +397,8 @@ static INT_PTR CALLBACK StartupStatusOptDlgProc(HWND hwndDlg, UINT msg, WPARAM w int defProfile = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0); - TProtoSettings ps = protoList; + TProtoSettings ps(protoList); GetProfile(defProfile, ps); - for (int i = 0; i < ps.getCount(); i++) - if (ps[i].m_szMsg != nullptr) - ps[i].m_szMsg = wcsdup(ps[i].m_szMsg); CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_CMDLOPTIONS), hwndDlg, CmdlOptionsDlgProc, (LPARAM)&ps); break; @@ -664,7 +661,6 @@ public: for (int i = 0; i < profileCount; i++) { PROFILEOPTIONS *ppo = new PROFILEOPTIONS; - ppo->ps = protoList; TProtoSettings &ar = ppo->ps; if (GetProfile(i, ar) == -1) { @@ -675,10 +671,6 @@ public: ppo->tszName = mir_wstrdup(TranslateT("unknown")); } else { - for (int j = 0; j < ar.getCount(); j++) - if (ar[j].m_szMsg != nullptr) - ar[j].m_szMsg = wcsdup(ar[j].m_szMsg); - ppo->tszName = db_get_wsa(0, SSMODULENAME, OptName(i, SETTING_PROFILENAME)); if (ppo->tszName == nullptr) { if (i == defProfile) @@ -805,12 +797,12 @@ public: int len; SMProto* ps = (SMProto*)lstAccount.GetItemData(lstAccount.GetCurSel()); if (ps->m_szMsg != nullptr) - free(ps->m_szMsg); + mir_free(ps->m_szMsg); ps->m_szMsg = nullptr; if (chkCustom.GetState()) { len = edtStatusMsg.SendMsg(WM_GETTEXTLENGTH, 0, 0); - ps->m_szMsg = (wchar_t*)calloc(sizeof(wchar_t), len + 1); + ps->m_szMsg = (wchar_t*)mir_calloc(sizeof(wchar_t) * (len + 1)); GetDlgItemText(m_hwnd, IDC_STATUSMSG, ps->m_szMsg, (len + 1)); } SetStatusMsg(); @@ -829,11 +821,11 @@ public: SMProto* ps = (SMProto*)lstAccount.GetItemData(lstAccount.GetCurSel()); if (ps->m_szMsg != nullptr) { if (*ps->m_szMsg) - free(ps->m_szMsg); + mir_free(ps->m_szMsg); ps->m_szMsg = nullptr; } int len = edtStatusMsg.SendMsg(WM_GETTEXTLENGTH, 0, 0); - ps->m_szMsg = (wchar_t*)calloc(sizeof(wchar_t), len + 1); + ps->m_szMsg = (wchar_t*)mir_calloc(sizeof(wchar_t) * (len + 1)); GetDlgItemText(m_hwnd, IDC_STATUSMSG, ps->m_szMsg, (len + 1)); } @@ -852,7 +844,7 @@ public: void onChange_Option(CCtrlCheck*) { int sel = cmbProfile.GetItemData(cmbProfile.GetCurSel()); - PROFILEOPTIONS& po = arProfiles[sel]; + PROFILEOPTIONS &po = arProfiles[sel]; po.createMmi = chkCreateMMI.GetState(); po.inSubMenu = chkInSubmenu.GetState(); po.createTtb = chkCreateTTB.GetState(); @@ -871,7 +863,6 @@ public: PROFILEOPTIONS* ppo = new PROFILEOPTIONS; ppo->tszName = mir_wstrdup(tszName); - ppo->ps = protoList; arProfiles.insert(ppo); ReinitProfiles(); diff --git a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp index 0e151abb99..d8251c28f2 100644 --- a/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp +++ b/plugins/StatusManager/src/StartupStatus/ss_profiles.cpp @@ -123,42 +123,25 @@ INT_PTR GetProfileCount(WPARAM wParam, LPARAM) return count; } -wchar_t* GetStatusMessage(int profile, char *szProto) +wchar_t* GetStatusMessage(int profile, const char *szProto) { char dbSetting[80]; - DBVARIANT dbv; + mir_snprintf(dbSetting, "%d_%s_%s", profile, szProto, SETTING_PROFILE_STSMSG); for (int i = 0; i < pceCount; i++) { if ((pce[i].profile == profile) && (!mir_strcmp(pce[i].szProto, szProto))) { - mir_snprintf(dbSetting, "%d_%s_%s", profile, szProto, SETTING_PROFILE_STSMSG); - if (!db_get_ws(0, SSMODULENAME, dbSetting, &dbv)) { // reload from db - pce[i].msg = (wchar_t*)realloc(pce[i].msg, sizeof(wchar_t)*(mir_wstrlen(dbv.ptszVal) + 1)); - if (pce[i].msg != nullptr) { - mir_wstrcpy(pce[i].msg, dbv.ptszVal); - } - db_free(&dbv); - } - else { - if (pce[i].msg != nullptr) { - free(pce[i].msg); - pce[i].msg = nullptr; - } - } + replaceStrW(pce[i].msg, db_get_wsa(0, SSMODULENAME, dbSetting)); return pce[i].msg; } } - pce = (PROFILECE*)realloc(pce, (pceCount + 1)*sizeof(PROFILECE)); + + pce = (PROFILECE*)mir_realloc(pce, (pceCount + 1)*sizeof(PROFILECE)); if (pce == nullptr) return nullptr; pce[pceCount].profile = profile; pce[pceCount].szProto = _strdup(szProto); - pce[pceCount].msg = nullptr; - mir_snprintf(dbSetting, "%d_%s_%s", profile, szProto, SETTING_PROFILE_STSMSG); - if (!db_get_ws(0, SSMODULENAME, dbSetting, &dbv)) { - pce[pceCount].msg = wcsdup(dbv.ptszVal); - db_free(&dbv); - } + pce[pceCount].msg = db_get_wsa(0, SSMODULENAME, dbSetting); pceCount++; return pce[pceCount - 1].msg; @@ -183,7 +166,7 @@ void FillStatus(SMProto &ps, int profile) ps.m_szMsg = GetStatusMessage(profile, ps.m_szName); if (ps.m_szMsg) - ps.m_szMsg = wcsdup(ps.m_szMsg); + ps.m_szMsg = mir_wstrdup(ps.m_szMsg); } int GetProfile(int profile, TProtoSettings &arSettings) @@ -212,7 +195,7 @@ INT_PTR LoadAndSetProfile(WPARAM iProfileNo, LPARAM) { // wParam == profile no. int profile = (int)iProfileNo; - TProtoSettings profileSettings(10, CompareProtoSettings); + TProtoSettings profileSettings(protoList); if (!GetProfile(profile, profileSettings)) { profile = (profile >= 0) ? profile : db_get_w(0, SSMODULENAME, SETTING_DEFAULTPROFILE, 0); @@ -264,7 +247,7 @@ static int UnregisterHotKeys() UnregisterHotKey(hMessageWindow, (int)hkInfo[i].id); GlobalDeleteAtom(hkInfo[i].id); } - free(hkInfo); + mir_free(hkInfo); } DestroyWindow(hMessageWindow); @@ -287,7 +270,7 @@ static int RegisterHotKeys() continue; WORD wHotKey = db_get_w(0, SSMODULENAME, OptName(i, SETTING_HOTKEY), 0); - hkInfo = (HKINFO*)realloc(hkInfo, (hkiCount + 1)*sizeof(HKINFO)); + hkInfo = (HKINFO*)mir_realloc(hkInfo, (hkiCount + 1)*sizeof(HKINFO)); if (hkInfo == nullptr) return -1; @@ -341,8 +324,8 @@ int DeinitProfilesModule() { if (pce) { for (int i = 0; i < pceCount; i++) - free(pce[i].szProto); - free(pce); + mir_free(pce[i].szProto); + mir_free(pce); pce = nullptr; } pceCount = 0; diff --git a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp index d84781c1be..f4d6df4150 100644 --- a/plugins/StatusManager/src/StartupStatus/startupstatus.cpp +++ b/plugins/StatusManager/src/StartupStatus/startupstatus.cpp @@ -123,12 +123,7 @@ static void SetLastStatusMessages(TProtoSettings &ps) char dbSetting[128]; mir_snprintf(dbSetting, "%s%s", PREFIX_LASTMSG, ps[i].m_szName); - - DBVARIANT dbv; - if (ps[i].m_szMsg == nullptr && !db_get_ws(0, SSMODULENAME, dbSetting, &dbv)) { - ps[i].m_szMsg = wcsdup(dbv.ptszVal); // remember this won't be freed - db_free(&dbv); - } + ps[i].m_szMsg = db_get_wsa(0, SSMODULENAME, dbSetting); } } diff --git a/plugins/StatusManager/src/StartupStatus/startupstatus.h b/plugins/StatusManager/src/StartupStatus/startupstatus.h index e680962e17..47d6bd3d0e 100644 --- a/plugins/StatusManager/src/StartupStatus/startupstatus.h +++ b/plugins/StatusManager/src/StartupStatus/startupstatus.h @@ -31,7 +31,7 @@ struct PROFILECE struct PROFILEOPTIONS : public MZeroedObject { __inline PROFILEOPTIONS() : - ps(10, CompareProtoSettings) + ps(protoList) {} __inline ~PROFILEOPTIONS() @@ -54,70 +54,70 @@ typedef struct { int profile; } HKINFO; -#define UM_REINITPROFILES WM_USER + 1 -#define UM_ADDPROFILE WM_USER + 5 -#define UM_REINITDOCKED WM_USER + 7 -#define UM_REINITWINSTATE WM_USER + 8 -#define UM_REINITWINSIZE WM_USER + 9 +#define UM_REINITPROFILES WM_USER + 1 +#define UM_ADDPROFILE WM_USER + 5 +#define UM_REINITDOCKED WM_USER + 7 +#define UM_REINITWINSTATE WM_USER + 8 +#define UM_REINITWINSIZE WM_USER + 9 #define CLUIINTM_REDRAW (WM_USER+100) -#define MODULE_CLIST "CList" -#define MODULE_CLUI "CLUI" -#define SETTING_STATUS "Status" +#define MODULE_CLIST "CList" +#define MODULE_CLUI "CLUI" +#define SETTING_STATUS "Status" -#define SETTING_SETWINSTATE "SetState" -#define SETTING_WINSTATE "State" +#define SETTING_SETWINSTATE "SetState" +#define SETTING_WINSTATE "State" -#define SETTING_SETDOCKED "SetDocked" -#define SETTING_DOCKED "Docked" +#define SETTING_SETDOCKED "SetDocked" +#define SETTING_DOCKED "Docked" -#define SETTING_SHOWDIALOG "ShowDialog" -#define SETTING_OFFLINECLOSE "OfflineOnClose" -#define SETTING_SETPROFILE "SetStatusOnStartup" -#define SETTING_AUTODIAL "AutoDial" -#define SETTING_AUTOHANGUP "AutoHangup" +#define SETTING_SHOWDIALOG "ShowDialog" +#define SETTING_OFFLINECLOSE "OfflineOnClose" +#define SETTING_SETPROFILE "SetStatusOnStartup" +#define SETTING_AUTODIAL "AutoDial" +#define SETTING_AUTOHANGUP "AutoHangup" -#define SETTING_TOOLWINDOW "ToolWindow" +#define SETTING_TOOLWINDOW "ToolWindow" -#define SETTING_OVERRIDE "AllowOverride" +#define SETTING_OVERRIDE "AllowOverride" -#define SETTING_SETWINLOCATION "SetWinLoc" -#define SETTING_XPOS "x" -#define SETTING_YPOS "y" +#define SETTING_SETWINLOCATION "SetWinLoc" +#define SETTING_XPOS "x" +#define SETTING_YPOS "y" -#define SETTING_SETWINSIZE "SetWinSize" -#define SETTING_WIDTH "Width" -#define SETTING_HEIGHT "Height" -#define SETTING_AUTOSIZE "AutoSize" +#define SETTING_SETWINSIZE "SetWinSize" +#define SETTING_WIDTH "Width" +#define SETTING_HEIGHT "Height" +#define SETTING_AUTOSIZE "AutoSize" -#define SETTING_PROFILECOUNT "ProfileCount" -#define SETTING_DEFAULTPROFILE "DefaultProfile" -#define SETTING_PROFILENAME "ProfileName" -#define SETTING_CREATETTBBUTTON "CreateTTBButton" -#define SETTING_PROFILE_STSMSG "StatusMsg" -#define SETTING_SHOWCONFIRMDIALOG "profile_ShowDialog" -#define SETTING_CREATEMMITEM "CreateMMItem" -#define SETTING_INSUBMENU "InSubMenu" -#define SETTING_REGHOTKEY "RegHotKey" -#define SETTING_HOTKEY "HotKey" -#define SETTING_PROFILENO "ProfileNo" +#define SETTING_PROFILECOUNT "ProfileCount" +#define SETTING_DEFAULTPROFILE "DefaultProfile" +#define SETTING_PROFILENAME "ProfileName" +#define SETTING_CREATETTBBUTTON "CreateTTBButton" +#define SETTING_PROFILE_STSMSG "StatusMsg" +#define SETTING_SHOWCONFIRMDIALOG "profile_ShowDialog" +#define SETTING_CREATEMMITEM "CreateMMItem" +#define SETTING_INSUBMENU "InSubMenu" +#define SETTING_REGHOTKEY "RegHotKey" +#define SETTING_HOTKEY "HotKey" +#define SETTING_PROFILENO "ProfileNo" -#define SETTING_SETPROFILEDELAY "SetStatusDelay" -#define SETTING_DLGTIMEOUT "DialogTimeout" +#define SETTING_SETPROFILEDELAY "SetStatusDelay" +#define SETTING_DLGTIMEOUT "DialogTimeout" -#define SHORTCUT_DESC L"Miranda NG" -#define SHORTCUT_FILENAME L"\\Miranda NG.lnk" +#define SHORTCUT_DESC L"Miranda NG" +#define SHORTCUT_FILENAME L"\\Miranda NG.lnk" -#define DOCKED_NONE 0 -#define DOCKED_LEFT 1 -#define DOCKED_RIGHT 2 +#define DOCKED_NONE 0 +#define DOCKED_LEFT 1 +#define DOCKED_RIGHT 2 #define MS_SS_MENUSETPROFILEPREFIX "StartupStatus/SetProfile_" // options int StartupStatusOptionsInit(WPARAM wparam,LPARAM lparam); -char* OptName(int i, const char* setting); +char* OptName(int i, const char *setting); // startupstatus void StartupStatusLoad(); @@ -125,12 +125,10 @@ void StartupStatusUnload(); int SSLoadMainOptions(); -void GetCurrentProtoSettings(TProtoSettings&); - // profile void FillStatus(SMProto &ps, int profile); -int GetProfile(int profileID, TProtoSettings& arSettings ); -wchar_t *GetStatusMessage(int profile, char *szProto); +int GetProfile(int profileID, TProtoSettings &arSettings); +wchar_t* GetStatusMessage(int profile, const char *szProto); INT_PTR LoadAndSetProfile(WPARAM wParam, LPARAM lParam); INT_PTR GetProfileCount(WPARAM wParam, LPARAM lParam); |