summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-02-02 13:27:14 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-02-02 13:27:14 +0300
commita7a6991d945a508d0f21ab34fd2f76ca15b95248 (patch)
treebf01e4414cea21d2494272d0d150afaae0438fa5
parent7253436a88270d83009626a1a5021658de85e8e8 (diff)
StatusManager:
- fixes #1129 (Status Manager broked. When I change profile - not happend) - all standard memory allocation routines replaced with mir_* (more effective) - classes used to allocate memory instead of manual code
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/aaa_msgoptions.cpp18
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp11
-rw-r--r--plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp21
-rw-r--r--plugins/StatusManager/src/KeepStatus/keepstatus.cpp18
-rw-r--r--plugins/StatusManager/src/KeepStatus/ks_options.cpp2
-rw-r--r--plugins/StatusManager/src/StartupStatus/ss_options.cpp39
-rw-r--r--plugins/StatusManager/src/StartupStatus/ss_profiles.cpp41
-rw-r--r--plugins/StatusManager/src/StartupStatus/startupstatus.cpp7
-rw-r--r--plugins/StatusManager/src/StartupStatus/startupstatus.h98
-rw-r--r--plugins/StatusManager/src/commonstatus.cpp23
-rw-r--r--plugins/StatusManager/src/commonstatus.h8
-rw-r--r--plugins/StatusManager/src/confirmdialog.cpp16
-rw-r--r--plugins/StatusManager/src/version.h2
13 files changed, 139 insertions, 165 deletions
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/aaa_msgoptions.cpp b/plugins/StatusManager/src/AdvancedAutoAway/aaa_msgoptions.cpp
index f9b04fba79..ef10baf786 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/aaa_msgoptions.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/aaa_msgoptions.cpp
@@ -68,7 +68,7 @@ INT_PTR CALLBACK DlgProcAutoAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L
break;
}
- settings = (AAMSGSETTING**)malloc(sizeof(AAMSGSETTING*));
+ settings = (AAMSGSETTING**)mir_alloc(sizeof(AAMSGSETTING*));
count = 0;
for (int i = 0; i < _countof(statusModeList); i++) {
if (!(protoModeMsgFlags & Proto_Status2Flag(statusModeList[i])))
@@ -76,13 +76,13 @@ INT_PTR CALLBACK DlgProcAutoAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L
int j = SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)pcli->pfnGetStatusModeDescription(statusModeList[i], 0));
SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETITEMDATA, j, statusModeList[i]);
- settings = (AAMSGSETTING**)realloc(settings, (count + 1) * sizeof(AAMSGSETTING*));
- settings[count] = (AAMSGSETTING*)malloc(sizeof(AAMSGSETTING));
+ settings = (AAMSGSETTING**)mir_realloc(settings, (count + 1) * sizeof(AAMSGSETTING*));
+ settings[count] = (AAMSGSETTING*)mir_alloc(sizeof(AAMSGSETTING));
settings[count]->status = statusModeList[i];
DBVARIANT dbv;
if (!db_get(0, AAAMODULENAME, StatusModeToDbSetting(statusModeList[i], SETTING_STATUSMSG), &dbv)) {
- settings[count]->msg = (char*)malloc(mir_strlen(dbv.pszVal) + 1);
+ settings[count]->msg = (char*)mir_alloc(mir_strlen(dbv.pszVal) + 1);
mir_strcpy(settings[count]->msg, dbv.pszVal);
db_free(&dbv);
}
@@ -121,9 +121,9 @@ INT_PTR CALLBACK DlgProcAutoAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L
int len = SendDlgItemMessage(hwndDlg, IDC_STATUSMSG, WM_GETTEXTLENGTH, 0, 0);
if (last != -1) {
if (settings[last]->msg == nullptr)
- settings[last]->msg = (char*)malloc(len + 1);
+ settings[last]->msg = (char*)mir_alloc(len + 1);
else
- settings[last]->msg = (char*)realloc(settings[last]->msg, len + 1);
+ settings[last]->msg = (char*)mir_realloc(settings[last]->msg, len + 1);
GetDlgItemTextA(hwndDlg, IDC_STATUSMSG, settings[last]->msg, (len + 1));
}
@@ -173,10 +173,10 @@ INT_PTR CALLBACK DlgProcAutoAwayMsgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L
case WM_DESTROY:
for (int i = 0; i < count; i++) {
- free(settings[i]->msg);
- free(settings[i]);
+ mir_free(settings[i]->msg);
+ mir_free(settings[i]);
}
- free(settings);
+ mir_free(settings);
break;
}
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
index 9e979e1230..db1fc2fea2 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/aaa_options.cpp
@@ -119,12 +119,7 @@ static void SetDialogStatus(HWND hwndDlg, SMProto *sameSetting)
/////////////////////////////////////////////////////////////////////////////////////////
// Rules dialog window procedure
-int AAACompareSettings(const SMProto *p1, const SMProto *p2)
-{
- return mir_strcmp(p1->m_szName, p2->m_szName);
-}
-
-static TProtoSettings optionSettings(10, AAACompareSettings);
+static TProtoSettings optionSettings;
static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -140,7 +135,7 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM
// copy the settings
optionSettings = protoList;
- sameSetting = (SMProto*)malloc(sizeof(SMProto));
+ sameSetting = (SMProto*)mir_alloc(sizeof(SMProto));
LoadAutoAwaySetting(*sameSetting, SETTING_ALL);
// fill list from currentProtoSettings
@@ -348,7 +343,7 @@ static INT_PTR CALLBACK DlgProcAutoAwayRulesOpts(HWND hwndDlg, UINT msg, WPARAM
case WM_DESTROY:
optionSettings.destroy();
- free(sameSetting);
+ mir_free(sameSetting);
break;
}
return FALSE;
diff --git a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
index b37830b90f..64eb4c3f30 100644
--- a/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
+++ b/plugins/StatusManager/src/AdvancedAutoAway/advancedautoaway.cpp
@@ -187,20 +187,15 @@ static int changeState(SMProto &setting, STATES newState)
if (setting.curState != SET_ORGSTATUS && setting.curState != ACTIVE && setting.statusChanged) {
/* change the awaymessage */
if (setting.m_szMsg != nullptr) {
- free(setting.m_szMsg);
+ mir_free(setting.m_szMsg);
setting.m_szMsg = nullptr;
}
- if (db_get_b(0, AAAMODULENAME, StatusModeToDbSetting(setting.m_status, SETTING_MSGCUSTOM), FALSE)) {
- DBVARIANT dbv;
- if (!db_get_ws(0, AAAMODULENAME, StatusModeToDbSetting(setting.m_status, SETTING_STATUSMSG), &dbv)) {
- setting.m_szMsg = wcsdup(dbv.ptszVal);
- db_free(&dbv);
- }
- }
+ if (db_get_b(0, AAAMODULENAME, StatusModeToDbSetting(setting.m_status, SETTING_MSGCUSTOM), FALSE))
+ setting.m_szMsg = db_get_wsa(0, AAAMODULENAME, StatusModeToDbSetting(setting.m_status, SETTING_STATUSMSG));
}
else if (setting.m_szMsg != nullptr) {
- free(setting.m_szMsg);
+ mir_free(setting.m_szMsg);
setting.m_szMsg = nullptr;
}
@@ -324,14 +319,10 @@ static VOID CALLBACK AutoAwayTimer(HWND, UINT, UINT_PTR, DWORD)
}
if (confirm || statusChanged) {
- TProtoSettings ps = protoList;
- for (int i = 0; i < ps.getCount(); i++) {
- if (ps[i].m_szMsg)
- ps[i].m_szMsg = wcsdup(ps[i].m_szMsg);
-
+ TProtoSettings ps(protoList);
+ for (int i = 0; i < ps.getCount(); i++)
if (ps[i].m_status == ID_STATUS_DISABLED)
ps[i].m_szName = "";
- }
if (confirm)
confirmDialog = ShowConfirmDialogEx(&ps, db_get_w(0, AAAMODULENAME, SETTING_CONFIRMDELAY, 5));
diff --git a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
index bbdc6587c7..31e95c3d0b 100644
--- a/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
+++ b/plugins/StatusManager/src/KeepStatus/keepstatus.cpp
@@ -130,14 +130,14 @@ int KSLoadOptions()
static PROTOCOLSETTINGEX** GetCurrentProtoSettingsCopy()
{
mir_cslock lck(GenStatusCS);
- PROTOCOLSETTINGEX **ps = (PROTOCOLSETTINGEX**)malloc(protoList.getCount() * sizeof(PROTOCOLSETTINGEX *));
+ PROTOCOLSETTINGEX **ps = (PROTOCOLSETTINGEX**)mir_alloc(protoList.getCount() * sizeof(PROTOCOLSETTINGEX *));
if (ps == nullptr) {
return nullptr;
}
for (int i = 0; i < protoList.getCount(); i++) {
- ps[i] = (PROTOCOLSETTINGEX*)calloc(1, sizeof(PROTOCOLSETTINGEX));
+ ps[i] = (PROTOCOLSETTINGEX*)mir_calloc(sizeof(PROTOCOLSETTINGEX));
if (ps[i] == nullptr) {
- free(ps);
+ mir_free(ps);
return nullptr;
}
@@ -156,10 +156,10 @@ static void FreeProtoSettings(PROTOCOLSETTINGEX** ps)
{
for (int i = 0; i < protoList.getCount(); i++) {
if (ps[i]->m_szMsg != nullptr)
- free(ps[i]->m_szMsg);
- free(ps[i]);
+ mir_free(ps[i]->m_szMsg);
+ mir_free(ps[i]);
}
- free(ps);
+ mir_free(ps);
}
int SMProto::AssignStatus(int iStatus, int iLastStatus, wchar_t *pwszMsg)
@@ -187,13 +187,13 @@ int SMProto::AssignStatus(int iStatus, int iLastStatus, wchar_t *pwszMsg)
if (pwszMsg != nullptr && mir_wstrcmp(pwszMsg, m_szMsg)) {
if (m_szMsg != nullptr)
- free(m_szMsg);
+ mir_free(m_szMsg);
- m_szMsg = wcsdup(pwszMsg);
+ m_szMsg = mir_wstrdup(pwszMsg);
}
else if (pwszMsg != m_szMsg) {
if (m_szMsg != nullptr)
- free(m_szMsg);
+ mir_free(m_szMsg);
m_szMsg = nullptr;
}
diff --git a/plugins/StatusManager/src/KeepStatus/ks_options.cpp b/plugins/StatusManager/src/KeepStatus/ks_options.cpp
index 7fb763b926..8931d9c01e 100644
--- a/plugins/StatusManager/src/KeepStatus/ks_options.cpp
+++ b/plugins/StatusManager/src/KeepStatus/ks_options.cpp
@@ -136,7 +136,7 @@ static INT_PTR CALLBACK DlgProcKSBasicOpts(HWND hwndDlg, UINT msg, WPARAM wParam
int len = SendDlgItemMessage(hwndDlg, IDC_PINGHOST, WM_GETTEXTLENGTH, 0, 0);
if (len > 0) {
- host = (char*)malloc(len + 1);
+ host = (char*)mir_alloc(len + 1);
if (host != nullptr) {
memset(host, '\0', len + 1);
GetDlgItemTextA(hwndDlg, IDC_PINGHOST, host, len + 1);
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);
diff --git a/plugins/StatusManager/src/commonstatus.cpp b/plugins/StatusManager/src/commonstatus.cpp
index 02f85a1d0b..702d2cea26 100644
--- a/plugins/StatusManager/src/commonstatus.cpp
+++ b/plugins/StatusManager/src/commonstatus.cpp
@@ -29,7 +29,7 @@ int CompareProtoSettings(const SMProto *p1, const SMProto *p2)
return mir_strcmp(p1->m_szName, p2->m_szName);
}
-OBJLIST<SMProto> protoList(10, CompareProtoSettings);
+TProtoSettings protoList;
/////////////////////////////////////////////////////////////////////////////////////////
@@ -40,9 +40,28 @@ SMProto::SMProto(PROTOACCOUNT *pa)
m_status = m_lastStatus = CallProtoService(pa->szModuleName, PS_GETSTATUS, 0, 0);
}
+SMProto::SMProto(const SMProto &p)
+{
+ memcpy(this, &p, sizeof(SMProto));
+ m_szMsg = mir_wstrdup(p.m_szMsg);
+}
+
SMProto::~SMProto()
{
- free(m_szMsg);
+ mir_free(m_szMsg);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+TProtoSettings::TProtoSettings()
+ : OBJLIST<SMProto>(10, CompareProtoSettings)
+{}
+
+TProtoSettings::TProtoSettings(const TProtoSettings &p)
+ : OBJLIST<SMProto>(p.getCount(), CompareProtoSettings)
+{
+ for (int i = 0; i < p.getCount(); i++)
+ insert(new SMProto(p[i]));
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/plugins/StatusManager/src/commonstatus.h b/plugins/StatusManager/src/commonstatus.h
index 54e64f003c..488d28bfb6 100644
--- a/plugins/StatusManager/src/commonstatus.h
+++ b/plugins/StatusManager/src/commonstatus.h
@@ -101,6 +101,7 @@ typedef enum
struct SMProto : public PROTOCOLSETTINGEX, public MZeroedObject
{
SMProto(PROTOACCOUNT *pa);
+ SMProto(const SMProto&);
~SMProto();
// AdvancedAutoAway settings
@@ -125,7 +126,12 @@ struct SMProto : public PROTOCOLSETTINGEX, public MZeroedObject
int lastStatusAckTime; // the time the last status ack was received
};
-typedef OBJLIST<SMProto> TProtoSettings;
+struct TProtoSettings : public OBJLIST<SMProto>
+{
+ TProtoSettings();
+ TProtoSettings(const TProtoSettings&);
+};
+
extern TProtoSettings protoList;
int CompareProtoSettings(const SMProto *p1, const SMProto *p2);
diff --git a/plugins/StatusManager/src/confirmdialog.cpp b/plugins/StatusManager/src/confirmdialog.cpp
index 3b9b20694a..0d3ce3e2a3 100644
--- a/plugins/StatusManager/src/confirmdialog.cpp
+++ b/plugins/StatusManager/src/confirmdialog.cpp
@@ -29,16 +29,16 @@ static int timeOut;
struct TConfirmSetting : public PROTOCOLSETTINGEX
{
- TConfirmSetting(const PROTOCOLSETTINGEX& x)
+ TConfirmSetting(const PROTOCOLSETTINGEX &x)
{
memcpy(this, &x, sizeof(PROTOCOLSETTINGEX));
if (m_szMsg)
- m_szMsg = wcsdup(m_szMsg);
+ m_szMsg = mir_wstrdup(m_szMsg);
}
~TConfirmSetting()
{
- free(m_szMsg);
+ mir_free(m_szMsg);
}
};
@@ -80,7 +80,7 @@ static INT_PTR CALLBACK StatusMessageDlgProc(HWND hwndDlg, UINT msg, WPARAM wPar
{
int len = SendDlgItemMessage(hwndDlg, IDC_STSMSG, WM_GETTEXTLENGTH, 0, 0);
if (len > 0) {
- protoSetting->m_szMsg = (wchar_t*)realloc(protoSetting->m_szMsg, sizeof(wchar_t)*(len + 1));
+ protoSetting->m_szMsg = (wchar_t*)mir_realloc(protoSetting->m_szMsg, sizeof(wchar_t)*(len + 1));
if (protoSetting->m_szMsg != nullptr)
GetDlgItemText(hwndDlg, IDC_STSMSG, protoSetting->m_szMsg, len + 1);
}
@@ -239,15 +239,11 @@ static INT_PTR CALLBACK ConfirmDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP
{
int profile = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0);
for (int i = 0; i < confirmSettings->getCount(); i++)
- if ((*confirmSettings)[i].m_szMsg != nullptr) {
- free((*confirmSettings)[i].m_szMsg);
- (*confirmSettings)[i].m_szMsg = nullptr;
- }
+ replaceStrW((*confirmSettings)[i].m_szMsg, nullptr);
CallService(MS_SS_GETPROFILE, (WPARAM)profile, (LPARAM)confirmSettings);
for (int i = 0; i < confirmSettings->getCount(); i++)
- if ((*confirmSettings)[i].m_szMsg != nullptr) // we free this later, copy to our memory space
- (*confirmSettings)[i].m_szMsg = wcsdup((*confirmSettings)[i].m_szMsg);
+ (*confirmSettings)[i].m_szMsg = mir_wstrdup((*confirmSettings)[i].m_szMsg);
SetStatusList(hwndDlg);
}
diff --git a/plugins/StatusManager/src/version.h b/plugins/StatusManager/src/version.h
index b0d2ac3d74..a16d737182 100644
--- a/plugins/StatusManager/src/version.h
+++ b/plugins/StatusManager/src/version.h
@@ -2,7 +2,7 @@
#define __MAJOR_VERSION 1
#define __MINOR_VERSION 1
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 2
// other stuff for Version resource
#include <stdver.h>