From 09a1a03baff001ef9aef7310f918e79c8c1f6e97 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 22 Sep 2013 19:18:39 +0000 Subject: minor code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@6187 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/BasicHistory/src/BinaryExport.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'plugins/BasicHistory/src/BinaryExport.cpp') diff --git a/plugins/BasicHistory/src/BinaryExport.cpp b/plugins/BasicHistory/src/BinaryExport.cpp index 76239cb098..0e1636af2f 100644 --- a/plugins/BasicHistory/src/BinaryExport.cpp +++ b/plugins/BasicHistory/src/BinaryExport.cpp @@ -65,11 +65,9 @@ bool BinaryExport::ReadString(std::wstring &str) int size = 1024; int pos = 0; int totalSize = 0; - while(1) - { + while(true) { buf.resize(size); - if (IMP_FILE.peek() == 0) - { + if (IMP_FILE.peek() == 0) { IMP_FILE.get(); break; } @@ -96,6 +94,7 @@ bool BinaryExport::ReadString(std::wstring &str) if (totalSize == 0) return true; + int sizeW = MultiByteToWideChar(codepage, 0, (char*)buf.c_str(), totalSize, NULL, 0); str.resize(sizeW); MultiByteToWideChar(codepage, 0, (char*)buf.c_str(), totalSize, (wchar_t*)str.c_str(), sizeW); @@ -133,8 +132,7 @@ void BinaryExport::WriteGroup(bool isMe, const std::wstring &time, const std::ws void BinaryExport::WriteMessage(bool isMe, const std::wstring &longDate, const std::wstring &shortDate, const std::wstring &user, const std::wstring &message, const DBEVENTINFO& dbei) { - if (dbei.timestamp >= lTime) - { + if (dbei.timestamp >= lTime) { BinaryFileMessageHeader header; header.eventType = dbei.eventType; header.flags = dbei.flags & (~(0x800)); @@ -150,8 +148,10 @@ bool ReadHeader(BinaryFileHeader& header, std::istream* stream) stream->read((char*)&header, sizeof(BinaryFileHeader)); if (!stream->good()) return false; + if (memcmp(header.signature, "BHBF", 4) != 0) return false; + if (header.version != 0 || header.codepage == 12000 || header.codepage == 12001) return false; @@ -163,6 +163,7 @@ int BinaryExport::IsContactInFile(const std::vector& contacts) BinaryFileHeader header; if (!ReadHeader(header, IImport::stream)) return -2; + codepage = header.codepage; std::wstring filterName; std::wstring myName; @@ -188,14 +189,11 @@ int BinaryExport::IsContactInFile(const std::vector& contacts) return -2; IMP_FILE.seekg(0, std::ios_base::beg); - for(int i = 0; i < (int)contacts.size(); ++i) - { + for (int i = 0; i < (int)contacts.size(); ++i) { std::wstring pn = GetProtocolName(contacts[i]); std::wstring id = GetContactId(contacts[i]); if (pn == proto1 && id == id1) - { return i; - } } return -1; @@ -206,11 +204,11 @@ bool BinaryExport::GetEventList(std::vector& eventList BinaryFileHeader header; if (!ReadHeader(header, IImport::stream)) return false; + codepage = header.codepage; IMP_FILE.seekg(header.dataStart, std::ios_base::beg); BinaryFileMessageHeader messageHeader; - while(1) - { + while(true) { IMP_FILE.read((char*)&messageHeader, sizeof(BinaryFileMessageHeader)); if (IMP_FILE.eof()) break; -- cgit v1.2.3