Extracting attachments implemented
Originally committed to SVN as r445.
This commit is contained in:
parent
509f33490e
commit
797280d7c8
3 changed files with 48 additions and 0 deletions
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
////////////
|
////////////
|
||||||
// Includes
|
// Includes
|
||||||
|
#include <wx/wfstream.h>
|
||||||
#include "ass_attachment.h"
|
#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 //////////////////
|
/////////////////// Attachment //////////////////
|
||||||
///////////////
|
///////////////
|
||||||
|
|
|
@ -79,6 +79,9 @@ public:
|
||||||
void AddData(wxString data);
|
void AddData(wxString data);
|
||||||
void Finish();
|
void Finish();
|
||||||
|
|
||||||
|
void Extract(wxString filename);
|
||||||
|
void Import(wxString filename);
|
||||||
|
|
||||||
const wxString GetEntryData();
|
const wxString GetEntryData();
|
||||||
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
|
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }
|
||||||
AssEntry *Clone();
|
AssEntry *Clone();
|
||||||
|
|
|
@ -37,10 +37,13 @@
|
||||||
///////////
|
///////////
|
||||||
// Headers
|
// Headers
|
||||||
#include <wx/listctrl.h>
|
#include <wx/listctrl.h>
|
||||||
|
#include <wx/dirdlg.h>
|
||||||
|
#include <wx/filedlg.h>
|
||||||
#include "dialog_attachments.h"
|
#include "dialog_attachments.h"
|
||||||
#include "ass_file.h"
|
#include "ass_file.h"
|
||||||
#include "ass_attachment.h"
|
#include "ass_attachment.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
@ -120,6 +123,31 @@ void DialogAttachments::OnAttachFont(wxCommandEvent &event) {
|
||||||
///////////
|
///////////
|
||||||
// Extract
|
// Extract
|
||||||
void DialogAttachments::OnExtract(wxCommandEvent &event) {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue