diff --git a/core/ass_attachment.cpp b/core/ass_attachment.cpp index ba7ccaf85..f3816c4b5 100644 --- a/core/ass_attachment.cpp +++ b/core/ass_attachment.cpp @@ -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; } diff --git a/core/ass_attachment.h b/core/ass_attachment.h index e60f58507..daf4c5511 100644 --- a/core/ass_attachment.h +++ b/core/ass_attachment.h @@ -60,7 +60,7 @@ public: AttachData(); ~AttachData(); - const DataVec &GetData(); + DataVec &GetData(); void AddData(wxString data); void Finish(); }; diff --git a/core/ass_file.cpp b/core/ass_file.cpp index d5d73bdab..2f668e001 100644 --- a/core/ass_file.cpp +++ b/core/ass_file.cpp @@ -500,6 +500,45 @@ void AssFile::InsertStyle (AssStyle *style) { } +//////////////////// +// Insert attachment +void AssFile::InsertAttachment (AssAttachment *attach) { + // Search for insertion point + std::list::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) { diff --git a/core/ass_file.h b/core/ass_file.h index f516f1df9..dd0a2dc52 100644 --- a/core/ass_file.h +++ b/core/ass_file.h @@ -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 diff --git a/core/changelog.txt b/core/changelog.txt index 14e55d223..db1a30281 100644 --- a/core/changelog.txt +++ b/core/changelog.txt @@ -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 =========================== diff --git a/core/dialog_attachments.cpp b/core/dialog_attachments.cpp index de6d122d7..de62e2a9e 100644 --- a/core/dialog_attachments.cpp +++ b/core/dialog_attachments.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #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;iImport(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;