Fixed text_file_writer.h on Linux and made it use fstream on Win32 as well.

Originally committed to SVN as r1284.
This commit is contained in:
Rodrigo Braz Monteiro 2007-06-21 21:04:50 +00:00
parent 2d1df509f4
commit d04995bac8
2 changed files with 3 additions and 27 deletions

View file

@ -78,17 +78,10 @@ TextFileWriter::~TextFileWriter() {
void TextFileWriter::Open() { void TextFileWriter::Open() {
// Open file // Open file
if (open) return; if (open) return;
#ifdef WIN32 file.open(wxFNCONV(filename),std::ios::out | std::ios::binary | std::ios::trunc);
file = _tfopen(filename.c_str(), _T("wb"));
if (!file) {
throw _T("Failed opening file for writing.");
}
#else
file.open(filename.mb_str(wxConvLocal),std::ios::out | std::ios::binary | std::ios::trunc);
if (!file.is_open()) { if (!file.is_open()) {
throw _T("Failed opening file for writing."); throw _T("Failed opening file for writing.");
} }
#endif
open = true; open = true;
// Set encoding // Set encoding
@ -100,11 +93,7 @@ void TextFileWriter::Open() {
// Close file // Close file
void TextFileWriter::Close() { void TextFileWriter::Close() {
if (!open) return; if (!open) return;
#ifdef WIN32
fclose(file);
#else
file.close(); file.close();
#endif
open = false; open = false;
if (customConv) delete conv; if (customConv) delete conv;
} }
@ -133,11 +122,7 @@ void TextFileWriter::WriteLineToFile(wxString line,bool addLineBreak) {
if (!buf.data()) if (!buf.data())
return; return;
size_t len = wcslen(buf.data()); size_t len = wcslen(buf.data());
#ifdef WIN32
fwrite(buf.data(), sizeof(wchar_t), len, file);
#else
file.write((const char*)buf.data(),len*sizeof(wchar_t)); file.write((const char*)buf.data(),len*sizeof(wchar_t));
#endif
} }
// 8-bit // 8-bit
@ -146,11 +131,7 @@ void TextFileWriter::WriteLineToFile(wxString line,bool addLineBreak) {
if (!buf.data()) if (!buf.data())
return; return;
size_t len = strlen(buf.data()); size_t len = strlen(buf.data());
#ifdef WIN32
fwrite(buf.data(), 1, len, file);
#else
file.write(buf.data(),len); file.write(buf.data(),len);
#endif
} }
} }

View file

@ -41,9 +41,7 @@
/////////// ///////////
// Headers // Headers
#include <wx/wxprec.h> #include <wx/wxprec.h>
#ifdef WIN32 #include <fstream>
#include <stdio.h>
#endif
///////// /////////
@ -52,11 +50,8 @@ class TextFileWriter {
private: private:
wxString filename; wxString filename;
wxString encoding; wxString encoding;
#ifdef WIN32
FILE *file;
#else
std::ofstream file; std::ofstream file;
#endif
wxMBConv *conv; wxMBConv *conv;
bool customConv; bool customConv;
bool open; bool open;