forked from mia/Aegisub
Use agi::io::Save in TextFileWriter
Originally committed to SVN as r4772.
This commit is contained in:
parent
2662a69b2e
commit
ac2bac6d00
5 changed files with 19 additions and 21 deletions
|
@ -799,6 +799,10 @@ bool FrameMain::SaveSubtitles(bool saveas,bool withCharset) {
|
||||||
ass->Save(filename,true,true,charset);
|
ass->Save(filename,true,true,charset);
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
}
|
}
|
||||||
|
catch (const agi::Exception& err) {
|
||||||
|
wxMessageBox(lagi_wxString(err.GetMessage()), "Error", wxOK | wxICON_ERROR, NULL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
catch (const wchar_t *err) {
|
catch (const wchar_t *err) {
|
||||||
wxMessageBox(wxString(err), _T("Error"), wxOK | wxICON_ERROR, NULL);
|
wxMessageBox(wxString(err), _T("Error"), wxOK | wxICON_ERROR, NULL);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1388,16 +1388,15 @@ void FrameMain::OnAutoSave(wxTimerEvent &) {
|
||||||
dstpath.SetFullName(name + L".AUTOSAVE.ass");
|
dstpath.SetFullName(name + L".AUTOSAVE.ass");
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFileName temp = dstpath;
|
ass->Save(dstpath.GetFullPath(),false,false);
|
||||||
temp.SetName(dstpath.GetName() + ".temp");
|
|
||||||
|
|
||||||
ass->Save(temp.GetFullPath(),false,false);
|
|
||||||
wxRenameFile(temp.GetFullPath(), dstpath.GetFullPath());
|
|
||||||
|
|
||||||
// Set status bar
|
// Set status bar
|
||||||
StatusTimeout(_("File backup saved as \"") + dstpath.GetFullPath() + _T("\"."));
|
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) {
|
catch (wxString err) {
|
||||||
StatusTimeout(_T("Exception when attempting to autosave file: ") + err);
|
StatusTimeout(_T("Exception when attempting to autosave file: ") + err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ void HunspellSpellChecker::AddWord(wxString word) {
|
||||||
writer.WriteLineToFile(wxString::Format(L"%i", dic.Count()));
|
writer.WriteLineToFile(wxString::Format(L"%i", dic.Count()));
|
||||||
for (unsigned int i=0;i<dic.Count();i++) writer.WriteLineToFile(dic[i]);
|
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
|
// Failed to open file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <libaegisub/io.h>
|
||||||
|
|
||||||
#include "charset_conv.h"
|
#include "charset_conv.h"
|
||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
@ -51,16 +53,8 @@
|
||||||
/// @param encoding
|
/// @param encoding
|
||||||
///
|
///
|
||||||
TextFileWriter::TextFileWriter(wxString const& filename, wxString encoding)
|
TextFileWriter::TextFileWriter(wxString const& filename, wxString encoding)
|
||||||
: conv() {
|
: file(new agi::io::Save(STD_STR(filename)))
|
||||||
#ifdef WIN32
|
, conv() {
|
||||||
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.";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encoding.empty()) encoding = lagi_wxString(OPT_GET("App/Save Charset")->GetString());
|
if (encoding.empty()) encoding = lagi_wxString(OPT_GET("App/Save Charset")->GetString());
|
||||||
if (encoding.Lower() != wxSTRING_ENCODING)
|
if (encoding.Lower() != wxSTRING_ENCODING)
|
||||||
conv.reset(new agi::charset::IconvWrapper(wxSTRING_ENCODING, encoding.c_str(), true));
|
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()) {
|
if (conv.get()) {
|
||||||
std::string buf = conv->Convert(std::string(data, len));
|
std::string buf = conv->Convert(std::string(data, len));
|
||||||
file.write(buf.data(), buf.size());
|
file->Get().write(buf.data(), buf.size());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
file.write(data, len);
|
file->Get().write(data, len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,9 @@ namespace agi {
|
||||||
namespace charset {
|
namespace charset {
|
||||||
class IconvWrapper;
|
class IconvWrapper;
|
||||||
}
|
}
|
||||||
|
namespace io {
|
||||||
|
class Save;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,10 +59,8 @@ namespace agi {
|
||||||
///
|
///
|
||||||
/// DOCME
|
/// DOCME
|
||||||
class TextFileWriter {
|
class TextFileWriter {
|
||||||
private:
|
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
std::ofstream file;
|
std::auto_ptr<agi::io::Save> file;
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
std::auto_ptr<agi::charset::IconvWrapper> conv;
|
std::auto_ptr<agi::charset::IconvWrapper> conv;
|
||||||
|
|
Loading…
Reference in a new issue