Use libaegisub io code in AssAttachment rather than wx's

Originally committed to SVN as r6039.
This commit is contained in:
Thomas Goyne 2011-12-22 21:15:37 +00:00
parent 00bc0c7ef8
commit 96aa9e2629
5 changed files with 19 additions and 19 deletions

View file

@ -40,7 +40,7 @@ DEFINE_SIMPLE_EXCEPTION_NOINNER(IOAccessRead, IOError, "io/read")
DEFINE_SIMPLE_EXCEPTION_NOINNER(IOAccessWrite, IOError, "io/write") DEFINE_SIMPLE_EXCEPTION_NOINNER(IOAccessWrite, IOError, "io/write")
*/ */
std::ifstream* Open(const std::string &file); std::ifstream* Open(const std::string &file, bool binary = false);
class Save { class Save {
std::ofstream *fp; std::ofstream *fp;

View file

@ -36,7 +36,7 @@
namespace agi { namespace agi {
namespace io { namespace io {
std::ifstream* Open(const std::string &file) { std::ifstream* Open(const std::string &file, bool) {
LOG_D("agi/io/open/file") << file; LOG_D("agi/io/open/file") << file;
acs::CheckFileRead(file); acs::CheckFileRead(file);

View file

@ -37,11 +37,11 @@ namespace agi {
using agi::charset::ConvertW; using agi::charset::ConvertW;
std::ifstream* Open(const std::string &file) { std::ifstream* Open(const std::string &file, bool binary) {
LOG_D("agi/io/open/file") << file; LOG_D("agi/io/open/file") << file;
acs::CheckFileRead(file); acs::CheckFileRead(file);
std::ifstream *stream = new std::ifstream(ConvertW(file).c_str()); std::ifstream *stream = new std::ifstream(ConvertW(file).c_str(), std::ios::in | (binary ? std::ios::binary : 0));
if (stream->fail()) { if (stream->fail()) {
delete stream; delete stream;

View file

@ -38,13 +38,19 @@
#ifndef AGI_PRE #ifndef AGI_PRE
#include <wx/filename.h> #include <wx/filename.h>
#include <wx/wfstream.h>
#include <istream>
#endif #endif
#include "ass_attachment.h" #include "ass_attachment.h"
#include "compat.h"
#include <libaegisub/io.h>
#include <libaegisub/scoped_ptr.h>
AssAttachment::AssAttachment(wxString name) AssAttachment::AssAttachment(wxString name)
: data(new std::vector<unsigned char>) : data(new std::vector<char>)
, filename(name) , filename(name)
{ {
wxFileName fname(filename); wxFileName fname(filename);
@ -113,21 +119,15 @@ const wxString AssAttachment::GetEntryData() const {
} }
void AssAttachment::Extract(wxString filename) { void AssAttachment::Extract(wxString filename) {
wxFileOutputStream fp(filename); agi::io::Save(STD_STR(filename)).Get().write(&(*data)[0], data->size());
if (!fp.Ok()) return;
fp.Write(&(*data)[0], data->size());
} }
void AssAttachment::Import(wxString filename) { void AssAttachment::Import(wxString filename) {
// Open file and get size agi::scoped_ptr<std::istream> file(agi::io::Open(STD_STR(filename)));
wxFileInputStream fp(filename); file->seekg(0, std::ios::end);
if (!fp.Ok()) throw "Failed opening file"; data->resize(file->tellg());
int size = fp.SeekI(0,wxFromEnd); file->seekg(0, std::ios::beg);
fp.SeekI(0,wxFromStart); file->read(&(*data)[0], data->size());
// Set size and read
data->resize(size);
fp.Read(&(*data)[0],size);
} }
wxString AssAttachment::GetFileName(bool raw) { wxString AssAttachment::GetFileName(bool raw) {

View file

@ -45,7 +45,7 @@
/// @brief DOCME /// @brief DOCME
class AssAttachment : public AssEntry { class AssAttachment : public AssEntry {
/// Decoded file data /// Decoded file data
std::tr1::shared_ptr<std::vector<unsigned char> > data; std::tr1::shared_ptr<std::vector<char> > data;
/// Encoded data which has been read from the script but not yet decoded /// Encoded data which has been read from the script but not yet decoded
wxString buffer; wxString buffer;