summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_caps.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-01-17 18:05:48 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-01-17 18:05:48 +0300
commit78034bcd615e739ad51a1b4bc570b6f1927932fc (patch)
tree3584b0810f26158351a509d815ab61bdc00f8f52 /protocols/JabberG/src/jabber_caps.cpp
parent88da7ba66825d1e04f64ef36db9cbac1d7fec582 (diff)
json2file + file2json = helpers to load json from file and write it back
Diffstat (limited to 'protocols/JabberG/src/jabber_caps.cpp')
-rw-r--r--protocols/JabberG/src/jabber_caps.cpp25
1 files changed, 3 insertions, 22 deletions
diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp
index 3f25928b12..7c665053b6 100644
--- a/protocols/JabberG/src/jabber_caps.cpp
+++ b/protocols/JabberG/src/jabber_caps.cpp
@@ -573,21 +573,8 @@ static const char *str2buf(const std::string &str)
void CJabberClientCapsManager::Load()
{
- int fileId = _wopen(VARSW(L"%miranda_userdata%\\jabberCaps.json"), _O_BINARY | _O_RDONLY);
- if (fileId == -1)
- return;
-
- size_t dwFileLength = _filelength(fileId), dwReadLen;
- ptrA szBuf((char *)mir_alloc(dwFileLength + 1));
- dwReadLen = _read(fileId, szBuf, (unsigned)dwFileLength);
- _close(fileId);
- if (dwFileLength != dwReadLen)
- return;
-
- szBuf[dwFileLength] = 0;
-
- JSONNode root = JSONNode::parse(szBuf);
- if (!root)
+ JSONNode root;
+ if (!file2json(VARSW(L"%miranda_userdata%\\jabberCaps.json"), root))
return;
for (auto &node : root) {
@@ -646,11 +633,5 @@ void CJabberClientCapsManager::Save()
root << node;
}
- std::string szBody = root.write_formatted();
-
- int fileId = _wopen(VARSW(L"%miranda_userdata%\\jabberCaps.json"), _O_CREAT | _O_TRUNC | _O_WRONLY, _S_IREAD | _S_IWRITE);
- if (fileId != -1) {
- _write(fileId, szBody.c_str(), (unsigned)szBody.length());
- _close(fileId);
- }
+ json2file(root, VARSW(L"%miranda_userdata%\\jabberCaps.json"));
}