Fixed another file attachment bug

Originally committed to SVN as r475.
This commit is contained in:
Rodrigo Braz Monteiro 2006-07-08 02:30:18 +00:00
parent 85035b4dca
commit 2347f9dbd8
3 changed files with 29 additions and 5 deletions

View file

@ -45,7 +45,8 @@
// Constructor // Constructor
AssAttachment::AssAttachment(wxString _name) { AssAttachment::AssAttachment(wxString _name) {
// Parse name // Parse name
wxFileName fname(_name); filename = _name;
wxFileName fname(GetFileName());
wxString ext = fname.GetExt().Lower(); wxString ext = fname.GetExt().Lower();
wxString name; wxString name;
if (ext == _T("ttf")) { if (ext == _T("ttf")) {
@ -186,6 +187,26 @@ void AssAttachment::Import(wxString filename) {
} }
////////////////
// Get filename
wxString AssAttachment::GetFileName(bool raw) {
// Raw
if (raw || filename.Right(4).Lower() != _T(".ttf")) return filename;
// Remove stuff after last underscore if it's a font
int lastUnder = -1;
for (size_t i=0;i<filename.Length();i++) {
if (filename[i] == _T('_')) lastUnder = i;
}
// Underline found
wxString final = filename;
if (lastUnder != -1) {
final = filename.Left(lastUnder) + _T(".ttf");
}
return final;
}
/////////////////// Attachment ////////////////// /////////////////// Attachment //////////////////

View file

@ -71,9 +71,9 @@ public:
class AssAttachment : public AssEntry { class AssAttachment : public AssEntry {
private: private:
boost::shared_ptr<AttachData> data; boost::shared_ptr<AttachData> data;
wxString filename;
public: public:
wxString filename;
const DataVec &GetData(); const DataVec &GetData();
void AddData(wxString data); void AddData(wxString data);
@ -81,6 +81,7 @@ public:
void Extract(wxString filename); void Extract(wxString filename);
void Import(wxString filename); void Import(wxString filename);
wxString GetFileName(bool raw=false);
const wxString GetEntryData(); const wxString GetEntryData();
ASS_EntryType GetType() { return ENTRY_ATTACHMENT; } ASS_EntryType GetType() { return ENTRY_ATTACHMENT; }

View file

@ -91,7 +91,7 @@ void DialogAttachments::UpdateList() {
if (attach) { if (attach) {
// Add item // Add item
int row = listView->GetItemCount(); int row = listView->GetItemCount();
listView->InsertItem(row,attach->filename); listView->InsertItem(row,attach->GetFileName(true));
listView->SetItem(row,1,PrettySize(attach->GetData().size())); listView->SetItem(row,1,PrettySize(attach->GetData().size()));
listView->SetItem(row,2,attach->group); listView->SetItem(row,2,attach->group);
listView->SetItemData(row,(long)attach); listView->SetItemData(row,(long)attach);
@ -197,7 +197,9 @@ void DialogAttachments::OnExtract(wxCommandEvent &event) {
// Multiple or single? // 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("/"); if (listView->GetNextSelected(i) != -1) path = wxDirSelector(_("Select the path to save the files to:"),Options.AsText(_T("Fonts Collector Destination"))) + _T("/");
else { else {
path = wxFileSelector(_("Select the path to save the file to:"),Options.AsText(_T("Fonts Collector Destination")),((AssAttachment*) listView->GetItemData(i))->filename); // Default path
wxString defPath = ((AssAttachment*) listView->GetItemData(i))->GetFileName();
path = wxFileSelector(_("Select the path to save the file to:"),Options.AsText(_T("Fonts Collector Destination")),defPath);
fullPath = true; fullPath = true;
} }
if (path.IsEmpty()) return; if (path.IsEmpty()) return;
@ -206,7 +208,7 @@ void DialogAttachments::OnExtract(wxCommandEvent &event) {
while (i != -1) { while (i != -1) {
AssAttachment *attach = (AssAttachment*) listView->GetItemData(i); AssAttachment *attach = (AssAttachment*) listView->GetItemData(i);
wxString filename = path; wxString filename = path;
if (!fullPath) filename += attach->filename; if (!fullPath) filename += attach->GetFileName();
attach->Extract(filename); attach->Extract(filename);
i = listView->GetNextSelected(i); i = listView->GetNextSelected(i);
} }