diff options
author | George Hazan <ghazan@miranda.im> | 2017-03-07 19:55:19 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-03-07 19:55:19 +0300 |
commit | b087c0c0087bcc47122823e6b9e3188101bb9f4d (patch) | |
tree | 09f87a23d9156acd2021bf527621857a76932664 | |
parent | f95e7a84fc77ec0c535970a68b2600f15dc1e12d (diff) |
let this crap with the binary data format finally die
-rw-r--r-- | plugins/TabSRMM/src/globals.cpp | 3 | ||||
-rw-r--r-- | plugins/TabSRMM/src/msgs.h | 6 | ||||
-rw-r--r-- | plugins/TabSRMM/src/utils.cpp | 69 |
3 files changed, 63 insertions, 15 deletions
diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index 4b022093c7..ac23004e1c 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -35,7 +35,7 @@ bool g_bShutdown = false; CGlobals PluginConfig;
-static TContainerSettings _cnt_default = { false, CNT_FLAGS_DEFAULT, CNT_FLAGSEX_DEFAULT, 255, CInfoPanel::DEGRADE_THRESHOLD, 60, 60, L"%n (%s)", 1, 0 };
+static TContainerSettings _cnt_default = { CNT_FLAGS_DEFAULT, CNT_FLAGSEX_DEFAULT, 255, CInfoPanel::DEGRADE_THRESHOLD, 60, 60, L"%n (%s)", 1, 0 };
wchar_t* CGlobals::m_default_container_name = L"default";
@@ -196,7 +196,6 @@ void CGlobals::reloadSettings(bool fReloadSkins) m_cRichBorders = M.GetDword(FONTMODULE, "cRichBorders", 0);
::memcpy(&globalContainerSettings, &_cnt_default, sizeof(TContainerSettings));
- globalContainerSettings.iSplitterX = db_get_dw(0, CHAT_MODULE, "SplitterX", 150);
Utils::ReadContainerSettingsFromDB(0, &globalContainerSettings);
globalContainerSettings.fPrivate = false;
if (fReloadSkins)
diff --git a/plugins/TabSRMM/src/msgs.h b/plugins/TabSRMM/src/msgs.h index ddcd017fa4..4d0fac44b9 100644 --- a/plugins/TabSRMM/src/msgs.h +++ b/plugins/TabSRMM/src/msgs.h @@ -156,18 +156,16 @@ struct TLogTheme struct TContainerSettings
{
- BOOL fPrivate;
DWORD dwFlags;
DWORD dwFlagsEx;
DWORD dwTransparency;
DWORD panelheight;
- int iSplitterY;
+ int iSplitterX, iSplitterY;
wchar_t szTitleFormat[TITLE_FORMATLEN + 2];
WORD avatarMode;
WORD ownAvatarMode;
WORD autoCloseSeconds;
- int iSplitterX;
- BYTE reserved[10];
+ bool fPrivate;
};
struct ButtonItem;
diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index d7027d59e4..26eef54d49 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -494,29 +494,80 @@ LRESULT CALLBACK Utils::PopupDlgProcError(HWND hWnd, UINT message, WPARAM wParam // @param cs TContainerSettings* target structure
// @return 0 on success, 1 failure (blob does not exist OR is not a valid private setting structure
+struct TOldContainerSettings
+{
+ BOOL fPrivate;
+ DWORD dwFlags;
+ DWORD dwFlagsEx;
+ DWORD dwTransparency;
+ DWORD panelheight;
+ int iSplitterY;
+ wchar_t szTitleFormat[32];
+ WORD avatarMode;
+ WORD ownAvatarMode;
+ WORD autoCloseSeconds;
+ BYTE reserved[10];
+};
+
int Utils::ReadContainerSettingsFromDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey)
{
memcpy(cs, &PluginConfig.globalContainerSettings, sizeof(TContainerSettings));
- DBVARIANT dbv = { 0 };
- if (0 == db_get(hContact, SRMSGMOD_T, szKey ? szKey : CNT_KEYNAME, &dbv)) {
- if (dbv.type == DBVT_BLOB && dbv.cpbVal > 0 && dbv.cpbVal <= sizeof(TContainerSettings)) {
- ::memcpy((void*)cs, (void*)dbv.pbVal, dbv.cpbVal);
- ::db_free(&dbv);
- return 0;
+ CMStringA szSetting(szKey ? szKey : CNT_KEYNAME);
+ cs->iSplitterX = db_get_dw(0, SRMSGMOD_T, szSetting + "_SplitterX", -1);
+ if (cs->iSplitterX == -1) { // nothing? try the old format
+ DBVARIANT dbv = { 0 };
+ if (0 == db_get(hContact, SRMSGMOD_T, szSetting, &dbv)) {
+ TOldContainerSettings oldBin = {};
+ if (dbv.type == DBVT_BLOB && dbv.cpbVal > 0 && dbv.cpbVal <= sizeof(oldBin)) {
+ ::memcpy(&oldBin, (void*)dbv.pbVal, dbv.cpbVal);
+ cs->dwFlags = oldBin.dwFlags;
+ cs->dwFlagsEx = oldBin.dwFlagsEx;
+ cs->dwTransparency = oldBin.dwTransparency;
+ cs->panelheight = oldBin.panelheight;
+ if (szKey == nullptr)
+ cs->iSplitterX = db_get_dw(0, CHAT_MODULE, "SplitterX", 150);
+ cs->iSplitterY = oldBin.iSplitterY;
+ wcsncpy_s(cs->szTitleFormat, oldBin.szTitleFormat, _TRUNCATE);
+ cs->avatarMode = oldBin.avatarMode;
+ cs->ownAvatarMode = oldBin.ownAvatarMode;
+ cs->autoCloseSeconds = oldBin.autoCloseSeconds;
+ WriteContainerSettingsToDB(hContact, cs, szKey);
+ db_unset(hContact, SRMSGMOD_T, szSetting);
+ ::db_free(&dbv);
+ return 0;
+ }
}
cs->fPrivate = false;
db_free(&dbv);
return 1;
}
- cs->fPrivate = false;
- return 1;
+ cs->dwFlags = db_get_dw(hContact, SRMSGMOD_T, szSetting + "_Flags", 0);
+ cs->dwFlagsEx = db_get_dw(hContact, SRMSGMOD_T, szSetting + "_FlagsEx", 0);
+ cs->dwTransparency = db_get_dw(hContact, SRMSGMOD_T, szSetting + "_Transparency", 0);
+ cs->panelheight = db_get_dw(hContact, SRMSGMOD_T, szSetting + "_PanelY", 0);
+ cs->iSplitterY = db_get_dw(hContact, SRMSGMOD_T, szSetting + "_SplitterY", 0);
+ cs->avatarMode = db_get_w(hContact, SRMSGMOD_T, szSetting + "_AvatarMode", 0);
+ cs->ownAvatarMode = db_get_w(hContact, SRMSGMOD_T, szSetting + "_OwnAvatarMode", 0);
+ cs->autoCloseSeconds = db_get_w(hContact, SRMSGMOD_T, szSetting + "_AutoCloseSecs", 0);
+ db_get_wstatic(hContact, SRMSGMOD_T, szSetting + "_Format", cs->szTitleFormat, _countof(cs->szTitleFormat));
+ return 0;
}
int Utils::WriteContainerSettingsToDB(const MCONTACT hContact, TContainerSettings *cs, const char *szKey)
{
- ::db_set_blob(hContact, SRMSGMOD_T, szKey ? szKey : CNT_KEYNAME, cs, sizeof(TContainerSettings));
+ CMStringA szSetting(szKey ? szKey : CNT_KEYNAME);
+ db_set_dw(hContact, SRMSGMOD_T, szSetting + "_Flags", cs->dwFlags);
+ db_set_dw(hContact, SRMSGMOD_T, szSetting + "_FlagsEx", cs->dwFlagsEx);
+ db_set_dw(hContact, SRMSGMOD_T, szSetting + "_Transparency", cs->dwTransparency);
+ db_set_dw(hContact, SRMSGMOD_T, szSetting + "_PanelY", cs->panelheight);
+ db_set_dw(hContact, SRMSGMOD_T, szSetting + "_SplitterX", cs->iSplitterX);
+ db_set_dw(hContact, SRMSGMOD_T, szSetting + "_SplitterY", cs->iSplitterY);
+ db_set_ws(hContact, SRMSGMOD_T, szSetting + "_Format", cs->szTitleFormat);
+ db_set_w(hContact, SRMSGMOD_T, szSetting + "_AvatarMode", cs->avatarMode);
+ db_set_w(hContact, SRMSGMOD_T, szSetting + "_OwnAvatarMode", cs->ownAvatarMode);
+ db_set_w(hContact, SRMSGMOD_T, szSetting + "_AutoCloseSecs", cs->autoCloseSeconds);
return 0;
}
|