diff options
author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-09-07 20:03:07 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-09-07 20:03:07 +0300 |
commit | b25e8d1955f51b15d566b7e73199b044cfe0efa3 (patch) | |
tree | 370cf29bb5bc17df959b7c1f0c6c347a9f0db20b /messages.cpp | |
parent | 461183308684de712dc674382a86f87707a19a2a (diff) |
bugfixes
Diffstat (limited to 'messages.cpp')
-rw-r--r-- | messages.cpp | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/messages.cpp b/messages.cpp index 27c31fb..08b7666 100644 --- a/messages.cpp +++ b/messages.cpp @@ -132,7 +132,7 @@ int RecvMsgSvc(WPARAM w, LPARAM l) wstring path = tmp2; path.append(_T("\\encrypted_data.asc")); DeleteFile(path.c_str()); - wfstream f(path.c_str(), std::ios::out); + fstream f(path.c_str(), std::ios::out); f<<tmp; mir_free(tmp); f.close(); @@ -298,21 +298,27 @@ int RecvMsgSvc(WPARAM w, LPARAM l) wstring path = tmp2; mir_free(tmp2); path += _T("\\decrypted_data"); - fstream f(path.c_str(), std::ios::in | std::ios::binary); - while(f.is_open()) + fstream f(path.c_str(), std::ios::in | std::ios::ate); + if(f.is_open()) { - char tmp[256]; - f.getline(tmp, 255); - if(strlen(tmp) == 0) - break; - TCHAR *tmp2; - tmp2 = mir_utf8decodeW(tmp); - str.append(tmp2).append(_T("\n")); + std::ifstream::pos_type size = f.tellg(); + char *tmp = new char [(std::ifstream::pos_type)size+(std::ifstream::pos_type)1]; + f.seekg(0, std::ios::beg); + f.read(tmp, size); + tmp[size] = '\0'; + TCHAR *tmp2 = mir_utf8decodeW(tmp); + if(!tmp2) + { + str.append(_T("Miranda failed to decode this utf8 message, showing it as is:\n")); + tmp2 = mir_a2t(tmp); + str.append(tmp2); + } + delete [] tmp; + str.append(tmp2); mir_free(tmp2); } f.close(); DeleteFile(path.c_str()); - str.erase(str.find_last_of(_T("\n")), 1); if(str.empty()) { string str = pre->szMessage; @@ -401,11 +407,8 @@ int SendMsgSvc(WPARAM w, LPARAM l) cmd += _T("\""); { char *tmp; -// if(unicode) - tmp = mir_utf8encodeW(str.c_str()); -// else -// tmp = mir_t2a(str.c_str()); - wfstream f(path.c_str(), std::ios::out); + tmp = mir_utf8encodeW(str.c_str()); + fstream f(path.c_str(), std::ios::out); f<<tmp; mir_free(tmp); f.close(); @@ -459,17 +462,17 @@ int SendMsgSvc(WPARAM w, LPARAM l) } DeleteFile(path.c_str()); path.append(_T(".asc")); - wfstream f(path.c_str(), std::ios::in); + wfstream f(path.c_str(), std::ios::in | std::ios::ate); str.clear(); - while(!f.eof() && f.is_open()) + if(f.is_open()) { - TCHAR tmp[128]; - f.getline(tmp, 128); + std::ifstream::pos_type size = f.tellg(); + TCHAR *tmp = new TCHAR [(std::ifstream::pos_type)size+(std::ifstream::pos_type)1]; + f.seekg(0, std::ios::beg); + f.read(tmp, size); + tmp[size]= '\0'; str.append(tmp); - if(bJabberAPI && bIsMiranda09) - str.append(_T("\n")); - else - str.append(_T("\r\n")); + delete [] tmp; } f.close(); DeleteFile(path.c_str()); |