diff options
-rw-r--r-- | log.cpp | 8 | ||||
-rw-r--r-- | messages.cpp | 51 | ||||
-rw-r--r-- | options.cpp | 16 | ||||
-rw-r--r-- | utilities.cpp | 13 |
4 files changed, 48 insertions, 40 deletions
@@ -22,7 +22,7 @@ logtofile& logtofile::operator<<(TCHAR *buf) if(bDebugLog) { char *tmp = mir_utf8encodeW(buf); - log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log.open(path, std::ios::app |std::ios::ate); log<<tmp; log.close(); mir_free(tmp); @@ -35,7 +35,7 @@ logtofile& logtofile::operator<<(char *buf) if(bDebugLog) { char *tmp = mir_utf8encode(buf); - log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log.open(path, std::ios::app |std::ios::ate); log<<tmp; log.close(); mir_free(tmp); @@ -48,7 +48,7 @@ logtofile& logtofile::operator<<(string buf) if(bDebugLog) { char *tmp = mir_utf8encode(buf.c_str()); - log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log.open(path, std::ios::app |std::ios::ate); log<<tmp; log.close(); mir_free(tmp); @@ -61,7 +61,7 @@ logtofile& logtofile::operator<<(wstring buf) if(bDebugLog) { char *tmp = mir_utf8encodeW(buf.c_str()); - log.open(path, std::ios::app |std::ios::ate |std::ios::binary); + log.open(path, std::ios::app |std::ios::ate); log<<tmp; log.close(); mir_free(tmp); 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()); diff --git a/options.cpp b/options.cpp index 00b4b7e..72a0b77 100644 --- a/options.cpp +++ b/options.cpp @@ -330,8 +330,6 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA { break; } - wfstream f(tmp, std::ios::out); - delete [] tmp; wstring str; { TCHAR *tmp = UniGetContactSettingUtf(user_data[item_num+1], szGPGModuleName, "GPGPubKey", _T("")); @@ -343,6 +341,8 @@ static BOOL CALLBACK DlgProcGpgOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA { str.erase(s, 1); } + wfstream f(tmp, std::ios::out); + delete [] tmp; f<<str.c_str(); f.close(); } @@ -1032,19 +1032,21 @@ static BOOL CALLBACK DlgProcLoadPublicKey(HWND hwndDlg,UINT msg,WPARAM wParam,LP { break; } - wfstream f(tmp, std::ios::in); + wfstream f(tmp, std::ios::in | std::ios::ate); delete [] tmp; if(!f.is_open()) { MessageBox(0, _T("Failed to open file"), _T("Error"), MB_OK); break; } - while(!f.eof() && f.is_open()) + if(f.is_open()) { - tmp = new TCHAR [1024]; - f.getline(tmp, 1024, '\n'); + 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'; key_buf.append(tmp); - key_buf.append(_T("\n")); delete [] tmp; } f.close(); diff --git a/utilities.cpp b/utilities.cpp index 8320d93..322541a 100644 --- a/utilities.cpp +++ b/utilities.cpp @@ -476,14 +476,17 @@ static JABBER_HANDLER_FUNC SendHandler(IJabberInterface *ji, HXML node, void *pU } DeleteFile(path_out.c_str()); path_out += _T(".asc"); - f.open(path_out.c_str(), std::ios::in); + f.open(path_out.c_str(), std::ios::in | std::ios::ate); wstring data; - 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'; data.append(tmp); - data.append(_T("\n")); + delete [] tmp; } DeleteFile(path_out.c_str()); if(data.find(_T("-----BEGIN PGP MESSAGE-----")) != wstring::npos && data.find(_T("-----END PGP MESSAGE-----")) != wstring::npos) |