mirror of https://github.com/odrling/Aegisub
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:
parent
2d1df509f4
commit
d04995bac8
|
@ -78,17 +78,10 @@ TextFileWriter::~TextFileWriter() {
|
|||
void TextFileWriter::Open() {
|
||||
// Open file
|
||||
if (open) return;
|
||||
#ifdef WIN32
|
||||
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);
|
||||
file.open(wxFNCONV(filename),std::ios::out | std::ios::binary | std::ios::trunc);
|
||||
if (!file.is_open()) {
|
||||
throw _T("Failed opening file for writing.");
|
||||
}
|
||||
#endif
|
||||
open = true;
|
||||
|
||||
// Set encoding
|
||||
|
@ -100,11 +93,7 @@ void TextFileWriter::Open() {
|
|||
// Close file
|
||||
void TextFileWriter::Close() {
|
||||
if (!open) return;
|
||||
#ifdef WIN32
|
||||
fclose(file);
|
||||
#else
|
||||
file.close();
|
||||
#endif
|
||||
open = false;
|
||||
if (customConv) delete conv;
|
||||
}
|
||||
|
@ -133,11 +122,7 @@ void TextFileWriter::WriteLineToFile(wxString line,bool addLineBreak) {
|
|||
if (!buf.data())
|
||||
return;
|
||||
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));
|
||||
#endif
|
||||
}
|
||||
|
||||
// 8-bit
|
||||
|
@ -146,11 +131,7 @@ void TextFileWriter::WriteLineToFile(wxString line,bool addLineBreak) {
|
|||
if (!buf.data())
|
||||
return;
|
||||
size_t len = strlen(buf.data());
|
||||
#ifdef WIN32
|
||||
fwrite(buf.data(), 1, len, file);
|
||||
#else
|
||||
file.write(buf.data(),len);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,7 @@
|
|||
///////////
|
||||
// Headers
|
||||
#include <wx/wxprec.h>
|
||||
#ifdef WIN32
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <fstream>
|
||||
|
||||
|
||||
/////////
|
||||
|
@ -52,11 +50,8 @@ class TextFileWriter {
|
|||
private:
|
||||
wxString filename;
|
||||
wxString encoding;
|
||||
#ifdef WIN32
|
||||
FILE *file;
|
||||
#else
|
||||
std::ofstream file;
|
||||
#endif
|
||||
|
||||
wxMBConv *conv;
|
||||
bool customConv;
|
||||
bool open;
|
||||
|
|
Loading…
Reference in New Issue