summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Discord/src/guilds.cpp18
-rw-r--r--protocols/JabberG/src/jabber_caps.cpp25
2 files changed, 6 insertions, 37 deletions
diff --git a/protocols/Discord/src/guilds.cpp b/protocols/Discord/src/guilds.cpp
index fdaab2cefe..b149059972 100644
--- a/protocols/Discord/src/guilds.cpp
+++ b/protocols/Discord/src/guilds.cpp
@@ -456,17 +456,10 @@ void CDiscordGuild::ProcessRole(const JSONNode &role)
void CDiscordGuild::LoadFromFile()
{
- int fileNo = _wopen(GetCacheFile(), O_TEXT | O_RDONLY);
- if (fileNo == -1)
+ JSONNode cached;
+ if (!file2json(GetCacheFile(), cached))
return;
- int fSize = ::filelength(fileNo);
- ptrA json((char*)mir_alloc(fSize + 1));
- read(fileNo, json, fSize);
- json[fSize] = 0;
- close(fileNo);
-
- JSONNode cached = JSONNode::parse(json);
for (auto &it : cached) {
SnowFlake userId = getId(it["id"]);
auto *pUser = FindUser(userId);
@@ -491,10 +484,5 @@ void CDiscordGuild ::SaveToFile()
CMStringW wszFileName(GetCacheFile());
CreatePathToFileW(wszFileName);
- int fileNo = _wopen(wszFileName, O_CREAT | O_TRUNC | O_TEXT | O_WRONLY);
- if (fileNo != -1) {
- std::string json = members.write_formatted();
- write(fileNo, json.c_str(), (int)json.size());
- close(fileNo);
- }
+ json2file(members, wszFileName);
}
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"));
}