Add support for symlinking fonts rather than copying them in the fonts collector. Based on a patch by nodame.

Originally committed to SVN as r6755.
This commit is contained in:
Thomas Goyne 2012-05-10 14:18:47 +00:00
parent 18f158a364
commit f724abd0b8
3 changed files with 38 additions and 12 deletions

View file

@ -63,7 +63,8 @@ enum FcMode {
CheckFontsOnly = 0, CheckFontsOnly = 0,
CopyToFolder = 1, CopyToFolder = 1,
CopyToScriptFolder = 2, CopyToScriptFolder = 2,
CopyToZip = 3 CopyToZip = 3,
SymlinkToFolder = 4
}; };
wxDEFINE_EVENT(EVT_ADD_TEXT, wxThreadEvent); wxDEFINE_EVENT(EVT_ADD_TEXT, wxThreadEvent);
@ -97,10 +98,18 @@ class FontsCollectorThread : public wxThread {
// Copy fonts // Copy fonts
switch (oper) { switch (oper) {
case CheckFontsOnly: return; case CheckFontsOnly:
return;
case SymlinkToFolder:
AppendText(_("Symlinking fonts to folder...\n"));
break;
case CopyToScriptFolder: case CopyToScriptFolder:
case CopyToFolder: AppendText(_("Copying fonts to folder...\n")); break; case CopyToFolder:
case CopyToZip: AppendText(_("Copying fonts to archive...\n")); break; AppendText(_("Copying fonts to folder...\n"));
break;
case CopyToZip:
AppendText(_("Copying fonts to archive...\n"));
break;
} }
// Open zip stream if saving to compressed archive // Open zip stream if saving to compressed archive
@ -119,15 +128,26 @@ class FontsCollectorThread : public wxThread {
total_size += cur_fn.GetSize().GetValue(); total_size += cur_fn.GetSize().GetValue();
switch (oper) { switch (oper) {
case SymlinkToFolder:
case CopyToScriptFolder: case CopyToScriptFolder:
case CopyToFolder: { case CopyToFolder: {
wxString dest = destination + cur_fn.GetFullName(); wxString dest = destination + cur_fn.GetFullName();
if (wxFileName::FileExists(dest)) if (wxFileName::FileExists(dest))
ret = 2; ret = 2;
#ifndef _WIN32
else if (oper == SymlinkToFolder) {
// returns 0 on success, -1 on error...
if (symlink(cur_fn.GetFullPath().utf8_str(), dest.utf8_str()))
ret = 0;
else
ret = 3;
}
#endif
else else
ret = wxCopyFile(*cur, dest, true); ret = wxCopyFile(*cur, dest, true);
} }
break; break;
case CopyToZip: { case CopyToZip: {
wxFFileInputStream in(*cur); wxFFileInputStream in(*cur);
if (!in.IsOk()) if (!in.IsOk())
@ -144,6 +164,8 @@ class FontsCollectorThread : public wxThread {
AppendText(wxString::Format(_("* Copied %s.\n"), *cur), 1); AppendText(wxString::Format(_("* Copied %s.\n"), *cur), 1);
else if (ret == 2) else if (ret == 2)
AppendText(wxString::Format(_("* %s already exists on destination.\n"), wxFileName(*cur).GetFullName()), 3); AppendText(wxString::Format(_("* %s already exists on destination.\n"), wxFileName(*cur).GetFullName()), 3);
else if (ret == 3)
AppendText(wxString::Format(_("* Symlinked %s.\n"), *cur), 1);
else { else {
AppendText(wxString::Format(_("* Failed to copy %s.\n"), *cur), 2); AppendText(wxString::Format(_("* Failed to copy %s.\n"), *cur), 2);
allOk = false; allOk = false;
@ -196,13 +218,16 @@ DialogFontsCollector::DialogFontsCollector(agi::Context *c)
SetIcon(GETICON(font_collector_button_16)); SetIcon(GETICON(font_collector_button_16));
wxString modes[] = { wxString modes[] = {
_("Check fonts for availability"), _("Check fonts for availability")
_("Copy fonts to folder"), ,_("Copy fonts to folder")
_("Copy fonts to subtitle file's folder"), ,_("Copy fonts to subtitle file's folder")
_("Copy fonts to zipped archive") ,_("Copy fonts to zipped archive")
#ifndef _WIN32
,_("Symlink fonts to folder")
#endif
}; };
collection_mode = new wxRadioBox(this, -1, "Action", wxDefaultPosition, wxDefaultSize, 4, modes, 1); collection_mode = new wxRadioBox(this, -1, "Action", wxDefaultPosition, wxDefaultSize, countof(modes), modes, 1);
collection_mode->SetSelection(mid<int>(0, OPT_GET("Tool/Fonts Collector/Action")->GetInt(), 3)); collection_mode->SetSelection(mid<int>(0, OPT_GET("Tool/Fonts Collector/Action")->GetInt(), 4));
if (!subs->filename) if (!subs->filename)
collection_mode->Enable(2, false); collection_mode->Enable(2, false);
@ -341,7 +366,7 @@ void DialogFontsCollector::OnRadio(wxCommandEvent &) {
dest_browse_button->Enable(true); dest_browse_button->Enable(true);
dest_label->Enable(true); dest_label->Enable(true);
if (value == CopyToFolder) { if (value == CopyToFolder || value == SymlinkToFolder) {
dest_label->SetLabel(_("Choose the folder where the fonts will be collected to. It will be created if it doesn't exist.")); dest_label->SetLabel(_("Choose the folder where the fonts will be collected to. It will be created if it doesn't exist."));
// Remove filename from browse box // Remove filename from browse box

View file

@ -467,7 +467,6 @@ void FrameMain::StatusTimeout(wxString text,int ms) {
StatusClear.Start(ms,true); StatusClear.Start(ms,true);
} }
#define countof(array) (sizeof(array) / sizeof(array[0]))
bool FrameMain::LoadList(wxArrayString list) { bool FrameMain::LoadList(wxArrayString list) {
// Keep these lists sorted // Keep these lists sorted

View file

@ -123,6 +123,8 @@ template<typename T> inline T mid(T a, T b, T c) { return std::max(a, std::min(b
#endif #endif
#endif #endif
#define countof(array) (sizeof(array) / sizeof(array[0]))
/// Polymorphic delete functor /// Polymorphic delete functor
struct delete_ptr { struct delete_ptr {
template<class T> template<class T>