diff options
-rw-r--r-- | plugins/NewStory/src/history.cpp | 86 | ||||
-rw-r--r-- | plugins/NewStory/src/history_array.cpp | 9 |
2 files changed, 48 insertions, 47 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index a1e901ee04..f7ca4cc22f 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -542,7 +542,7 @@ public: UpdateTitle(); - ADDEVENTS tmp = { m_hContact, db_event_first(m_hContact), -1 }; + ADDEVENTS tmp = { m_hContact, 0, -1 }; m_histControl.SendMsg(NSM_ADDEVENTS, WPARAM(&tmp), 0); m_histControl.SendMsg(WM_KEYDOWN, VK_END, 0); @@ -707,59 +707,57 @@ public: // export events bool bAppendOnly = false; - if (auto *pCursor = DB::Events(m_hContact)) { - while (MEVENT hDbEvent = pCursor->FetchNext()) { - DBEVENTINFO dbei = {}; - int nSize = db_event_getBlobSize(hDbEvent); - if (nSize > 0) { - dbei.cbBlob = nSize; - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 2); - dbei.pBlob[dbei.cbBlob] = 0; - dbei.pBlob[dbei.cbBlob + 1] = 0; - // Double null terminate, this should prevent most errors - // where the blob received has an invalid format - } - - if (!db_event_get(hDbEvent, &dbei)) { - if (bAppendOnly) { - SetFilePointer(hFile, -3, nullptr, FILE_END); - WriteFile(hFile, ",", 1, &dwBytesWritten, nullptr); - } + DB::ECPTR pCursor(DB::Events(m_hContact)); + while (MEVENT hDbEvent = pCursor.FetchNext()) { + DBEVENTINFO dbei = {}; + int nSize = db_event_getBlobSize(hDbEvent); + if (nSize > 0) { + dbei.cbBlob = nSize; + dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 2); + dbei.pBlob[dbei.cbBlob] = 0; + dbei.pBlob[dbei.cbBlob + 1] = 0; + // Double null terminate, this should prevent most errors + // where the blob received has an invalid format + } - JSONNode pRoot2; - pRoot2.push_back(JSONNode("type", dbei.eventType)); + if (!db_event_get(hDbEvent, &dbei)) { + if (bAppendOnly) { + SetFilePointer(hFile, -3, nullptr, FILE_END); + WriteFile(hFile, ",", 1, &dwBytesWritten, nullptr); + } - if (mir_strcmp(dbei.szModule, proto)) - pRoot2.push_back(JSONNode("module", dbei.szModule)); + JSONNode pRoot2; + pRoot2.push_back(JSONNode("type", dbei.eventType)); - pRoot2.push_back(JSONNode("timestamp", dbei.timestamp)); + if (mir_strcmp(dbei.szModule, proto)) + pRoot2.push_back(JSONNode("module", dbei.szModule)); - wchar_t szTemp[500]; - TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, dbei.timestamp, L"I", szTemp, _countof(szTemp), 0); - pRoot2.push_back(JSONNode("isotime", T2Utf(szTemp).get())); + pRoot2.push_back(JSONNode("timestamp", dbei.timestamp)); - std::string flags; - if (dbei.flags & DBEF_SENT) - flags += "m"; - if (dbei.flags & DBEF_READ) - flags += "r"; - pRoot2.push_back(JSONNode("flags", flags)); + wchar_t szTemp[500]; + TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, dbei.timestamp, L"I", szTemp, _countof(szTemp), 0); + pRoot2.push_back(JSONNode("isotime", T2Utf(szTemp).get())); - ptrW msg(DbEvent_GetTextW(&dbei, CP_ACP)); - if (msg) - pRoot2.push_back(JSONNode("body", T2Utf(msg).get())); + std::string flags; + if (dbei.flags & DBEF_SENT) + flags += "m"; + if (dbei.flags & DBEF_READ) + flags += "r"; + pRoot2.push_back(JSONNode("flags", flags)); - output = pRoot2.write_formatted(); - output += "\n]}"; + ptrW msg(DbEvent_GetTextW(&dbei, CP_ACP)); + if (msg) + pRoot2.push_back(JSONNode("body", T2Utf(msg).get())); - WriteFile(hFile, output.c_str(), (int)output.size(), &dwBytesWritten, nullptr); - if (dbei.pBlob) - mir_free(dbei.pBlob); - } + output = pRoot2.write_formatted(); + output += "\n]}"; - bAppendOnly = true; + WriteFile(hFile, output.c_str(), (int)output.size(), &dwBytesWritten, nullptr); + if (dbei.pBlob) + mir_free(dbei.pBlob); } - delete pCursor; + + bAppendOnly = true; } // Close the file diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 07d29edb85..dfa1da0064 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -248,13 +248,16 @@ bool HistoryArray::addEvent(MCONTACT hContact, MEVENT hEvent, int count) int numItems = getCount(); auto *pPrev = (numItems == 0) ? nullptr : get(numItems - 1); - for (int i = 0; hEvent && i < count; i++) { + DB::ECPTR pCursor(DB::Events(hContact, hEvent)); + for (int i = 0; i < count; i++) { + hEvent = pCursor.FetchNext(); + if (!hEvent) + break; + auto &p = allocateItem(); p.hContact = hContact; p.hEvent = hEvent; p.pPrev = pPrev; pPrev = &p; - - hEvent = db_event_next(hContact, hEvent); } return true; |