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")
*/
std::ifstream* Open(const std::string &file);
std::ifstream* Open(const std::string &file, bool binary = false);
class Save {
std::ofstream *fp;

View file

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

View file

@ -37,11 +37,11 @@ namespace agi {
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;
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()) {
delete stream;

View file

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

View file

@ -45,7 +45,7 @@
/// @brief DOCME
class AssAttachment : public AssEntry {
/// 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
wxString buffer;