diff --git a/core/ass_attachment.cpp b/core/ass_attachment.cpp index ff877e617..ba7ccaf85 100644 --- a/core/ass_attachment.cpp +++ b/core/ass_attachment.cpp @@ -36,6 +36,7 @@ //////////// // Includes +#include #include "ass_attachment.h" @@ -146,6 +147,22 @@ const wxString AssAttachment::GetEntryData() { } +///////////////////// +// Extract as a file +void AssAttachment::Extract(wxString filename) { + // Open file + wxFileOutputStream fp(filename); + fp.Write(&data->GetData()[0],data->GetData().size()); +} + + +///////////////////////////// +// Read a file as attachment +void AssAttachment::Import(wxString filename) { +} + + + /////////////////// Attachment ////////////////// /////////////// diff --git a/core/ass_attachment.h b/core/ass_attachment.h index 1a568123f..e60f58507 100644 --- a/core/ass_attachment.h +++ b/core/ass_attachment.h @@ -79,6 +79,9 @@ public: void AddData(wxString data); void Finish(); + void Extract(wxString filename); + void Import(wxString filename); + const wxString GetEntryData(); ASS_EntryType GetType() { return ENTRY_ATTACHMENT; } AssEntry *Clone(); diff --git a/core/dialog_attachments.cpp b/core/dialog_attachments.cpp index 73615fa47..de6d122d7 100644 --- a/core/dialog_attachments.cpp +++ b/core/dialog_attachments.cpp @@ -37,10 +37,13 @@ /////////// // Headers #include +#include +#include #include "dialog_attachments.h" #include "ass_file.h" #include "ass_attachment.h" #include "utils.h" +#include "options.h" /////////////// @@ -120,6 +123,31 @@ void DialogAttachments::OnAttachFont(wxCommandEvent &event) { /////////// // Extract void DialogAttachments::OnExtract(wxCommandEvent &event) { + // Check if there's a selection + int i = listView->GetFirstSelected(); + + // Get path + if (i != -1) { + wxString path; + bool fullPath = false; + + // 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"))); + fullPath = true; + } + if (path.IsEmpty()) return; + + // Loop through items in list + while (i != -1) { + AssAttachment *attach = (AssAttachment*) listView->GetItemData(i); + wxString filename = path; + if (!fullPath) filename += attach->filename; + attach->Extract(filename); + i = listView->GetNextSelected(i); + } + } }