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
AssAttachment::AssAttachment(wxString _name) {
// Parse name
wxFileName fname(_name);
filename = _name;
wxFileName fname(GetFileName());
wxString ext = fname.GetExt().Lower();
wxString name;
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 //////////////////

View file

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

View file

@ -91,7 +91,7 @@ void DialogAttachments::UpdateList() {
if (attach) {
// Add item
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,2,attach->group);
listView->SetItemData(row,(long)attach);
@ -197,7 +197,9 @@ 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")),((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;
}
if (path.IsEmpty()) return;
@ -206,7 +208,7 @@ void DialogAttachments::OnExtract(wxCommandEvent &event) {
while (i != -1) {
AssAttachment *attach = (AssAttachment*) listView->GetItemData(i);
wxString filename = path;
if (!fullPath) filename += attach->filename;
if (!fullPath) filename += attach->GetFileName();
attach->Extract(filename);
i = listView->GetNextSelected(i);
}