Finished attachment support

Originally committed to SVN as r446.
This commit is contained in:
Rodrigo Braz Monteiro 2006-07-01 04:08:01 +00:00
parent 797280d7c8
commit d6c3e6492a
6 changed files with 86 additions and 3 deletions

View File

@ -152,6 +152,7 @@ const wxString AssAttachment::GetEntryData() {
void AssAttachment::Extract(wxString filename) {
// Open file
wxFileOutputStream fp(filename);
if (!fp.Ok()) return;
fp.Write(&data->GetData()[0],data->GetData().size());
}
@ -159,6 +160,18 @@ void AssAttachment::Extract(wxString filename) {
/////////////////////////////
// Read a file as attachment
void AssAttachment::Import(wxString filename) {
// Data
DataVec &datavec = data->GetData();
// Open file and get size
wxFileInputStream fp(filename);
if (!fp.Ok()) throw _T("Failed opening file");
int size = fp.SeekI(0,wxFromEnd);
fp.SeekI(0,wxFromStart);
// Set size and read
datavec.resize(size);
fp.Read(&datavec[0],size);
}
@ -179,7 +192,7 @@ AttachData::~AttachData() {
////////////
// Get data
const DataVec &AttachData::GetData() {
DataVec &AttachData::GetData() {
return data;
}

View File

@ -60,7 +60,7 @@ public:
AttachData();
~AttachData();
const DataVec &GetData();
DataVec &GetData();
void AddData(wxString data);
void Finish();
};

View File

@ -500,6 +500,45 @@ void AssFile::InsertStyle (AssStyle *style) {
}
////////////////////
// Insert attachment
void AssFile::InsertAttachment (AssAttachment *attach) {
// Search for insertion point
std::list<AssEntry*>::iterator insPoint=Line.end(),cur;
for (cur=Line.begin();cur!=Line.end();cur++) {
// Check if it's another attachment
AssAttachment *att = AssEntry::GetAsAttachment(*cur);
if (att) {
if (attach->group == att->group) insPoint = cur;
}
// See if it's the start of group
else if ((*cur)->GetType() == ENTRY_BASE) {
AssEntry *entry = (AssEntry*) (*cur);
if (entry->GetEntryData() == attach->group) insPoint = cur;
}
}
// Found point, insert there
if (insPoint != Line.end()) {
insPoint++;
attach->StartMS = (*insPoint)->StartMS;
Line.insert(insPoint,attach);
}
// Otherwise, create the [Fonts] group and insert
else {
bool IsSSA=false;
int StartMS = Line.back()->StartMS;
AddLine(_T(""),Line.back()->group,StartMS,IsSSA);
AddLine(attach->group,attach->group,StartMS,IsSSA);
attach->StartMS = StartMS;
Line.push_back(attach);
AddLine(_T(""),attach->group,StartMS,IsSSA);
}
}
////////////////////
// Gets script info
wxString AssFile::GetScriptInfo(const wxString _key) {

View File

@ -49,6 +49,7 @@
class FrameRate;
class AssDialogue;
class AssStyle;
class AssAttachment;
class AssDialogueBlock;
class AssDialogueBlockOverride;
class AssDialogueBlockPlain;
@ -83,6 +84,7 @@ public:
void CompressForStack(bool compress); // Compress/decompress for storage on stack
void LoadDefault(bool noline=true); // Loads default file. Pass true to prevent it from adding a default line too
void InsertStyle(AssStyle *style); // Inserts a style to file
void InsertAttachment(AssAttachment *attach); // Inserts an attachment
wxArrayString GetStyles(); // Gets a list of all styles available
AssStyle *GetStyle(wxString name); // Gets style by its name

View File

@ -87,6 +87,7 @@ Please visit http://aegisub.net to download latest version
- Right-clicking on the header of the subtitles grid will now bring up a popup menu that allows you to disable columns. (AMZ)
- Saving back to SRT directly (that is, via "save", not "export" or "save as") is now allowed, as long as no data will be lost. (AMZ)
- Aegisub now supports file attachments, which are stored decoded (to save memory) and are not part of the undo stack (for the same reason). Previously, they were simply left ignored in the file as unknown lines. (AMZ)
- Implemented an Attached files list, where you can attach new fonts, extract them, or remove them from the script file. (AMZ)
= 1.09 beta - 2006.01.16 ===========================

View File

@ -39,6 +39,7 @@
#include <wx/listctrl.h>
#include <wx/dirdlg.h>
#include <wx/filedlg.h>
#include <wx/filename.h>
#include "dialog_attachments.h"
#include "ass_file.h"
#include "ass_attachment.h"
@ -117,6 +118,33 @@ END_EVENT_TABLE()
///////////////
// Attach font
void DialogAttachments::OnAttachFont(wxCommandEvent &event) {
// Pick file
wxArrayString filenames;
wxArrayString paths;
{
wxFileDialog diag (this,_("Choose file to be attached"), Options.AsText(_T("Fonts Collector Destination")), _T(""), _T("Font Files (*.ttf)|*.ttf"), wxOPEN | wxFILE_MUST_EXIST | wxMULTIPLE);
diag.ShowModal();
diag.GetFilenames(filenames);
diag.GetPaths(paths);
}
// Create attachments
for (size_t i=0;i<filenames.Count();i++) {
//wxFileName file(filenames[i]);
AssAttachment *newAttach = new AssAttachment(filenames[i]);
try {
newAttach->Import(paths[i]);
}
catch (...) {
delete newAttach;
return;
}
newAttach->group = _T("[Fonts]");
AssFile::top->InsertAttachment(newAttach);
}
// Update
UpdateList();
}
@ -134,7 +162,7 @@ void DialogAttachments::OnExtract(wxCommandEvent &event) {
// Multiple or single?
if (listView->GetNextSelected(i) != -1) path = wxDirSelector(_("Select the path to save the files to:"),Options.AsText(_T("Fonts Collector Destination"))) + _T("/");
else {
path = wxFileSelector(_("Select the path to save the file to:"),Options.AsText(_T("Fonts Collector Destination")));
path = wxFileSelector(_("Select the path to save the file to:"),Options.AsText(_T("Fonts Collector Destination")),((AssAttachment*) listView->GetItemData(i))->filename);
fullPath = true;
}
if (path.IsEmpty()) return;