Use agi::io::Save in TextFileWriter

Originally committed to SVN as r4772.
This commit is contained in:
Thomas Goyne 2010-09-08 20:03:48 +00:00
parent 2662a69b2e
commit ac2bac6d00
5 changed files with 19 additions and 21 deletions

View File

@ -799,6 +799,10 @@ bool FrameMain::SaveSubtitles(bool saveas,bool withCharset) {
ass->Save(filename,true,true,charset);
UpdateTitle();
}
catch (const agi::Exception& err) {
wxMessageBox(lagi_wxString(err.GetMessage()), "Error", wxOK | wxICON_ERROR, NULL);
return false;
}
catch (const wchar_t *err) {
wxMessageBox(wxString(err), _T("Error"), wxOK | wxICON_ERROR, NULL);
return false;

View File

@ -1388,16 +1388,15 @@ void FrameMain::OnAutoSave(wxTimerEvent &) {
dstpath.SetFullName(name + L".AUTOSAVE.ass");
}
wxFileName temp = dstpath;
temp.SetName(dstpath.GetName() + ".temp");
ass->Save(temp.GetFullPath(),false,false);
wxRenameFile(temp.GetFullPath(), dstpath.GetFullPath());
ass->Save(dstpath.GetFullPath(),false,false);
// Set status bar
StatusTimeout(_("File backup saved as \"") + dstpath.GetFullPath() + _T("\"."));
}
}
catch (const agi::Exception& err) {
StatusTimeout(lagi_wxString("Exception when attempting to autosave file: " + err.GetMessage()));
}
catch (wxString err) {
StatusTimeout(_T("Exception when attempting to autosave file: ") + err);
}

View File

@ -152,7 +152,7 @@ void HunspellSpellChecker::AddWord(wxString word) {
writer.WriteLineToFile(wxString::Format(L"%i", dic.Count()));
for (unsigned int i=0;i<dic.Count();i++) writer.WriteLineToFile(dic[i]);
}
catch (const wchar_t*) {
catch (const agi::Exception&) {
// Failed to open file
}
}

View File

@ -40,6 +40,8 @@
#include <fstream>
#endif
#include <libaegisub/io.h>
#include "charset_conv.h"
#include "compat.h"
#include "main.h"
@ -51,16 +53,8 @@
/// @param encoding
///
TextFileWriter::TextFileWriter(wxString const& filename, wxString encoding)
: conv() {
#ifdef WIN32
file.open(filename.wc_str(),std::ios::out | std::ios::binary | std::ios::trunc);
#else
file.open(wxFNCONV(filename),std::ios::out | std::ios::binary | std::ios::trunc);
#endif
if (!file.is_open()) {
throw L"Failed opening file for writing.";
}
: file(new agi::io::Save(STD_STR(filename)))
, conv() {
if (encoding.empty()) encoding = lagi_wxString(OPT_GET("App/Save Charset")->GetString());
if (encoding.Lower() != wxSTRING_ENCODING)
conv.reset(new agi::charset::IconvWrapper(wxSTRING_ENCODING, encoding.c_str(), true));
@ -98,9 +92,9 @@ void TextFileWriter::WriteLineToFile(wxString line, bool addLineBreak) {
if (conv.get()) {
std::string buf = conv->Convert(std::string(data, len));
file.write(buf.data(), buf.size());
file->Get().write(buf.data(), buf.size());
}
else {
file.write(data, len);
file->Get().write(data, len);
}
}

View File

@ -47,6 +47,9 @@ namespace agi {
namespace charset {
class IconvWrapper;
}
namespace io {
class Save;
}
}
@ -56,10 +59,8 @@ namespace agi {
///
/// DOCME
class TextFileWriter {
private:
/// DOCME
std::ofstream file;
std::auto_ptr<agi::io::Save> file;
/// DOCME
std::auto_ptr<agi::charset::IconvWrapper> conv;