Fonts collector can now collect fonts directly to a zip archive.
Originally committed to SVN as r580.
This commit is contained in:
parent
76dbc901f9
commit
d4e2b2ce4f
3 changed files with 102 additions and 20 deletions
|
@ -36,6 +36,7 @@ Please visit http://aegisub.net to download latest version
|
||||||
- Added support to save and load keyframe list files. (AMZ)
|
- Added support to save and load keyframe list files. (AMZ)
|
||||||
- Switching to a new line in audio mode now centers the line on the grid. (AMZ)
|
- Switching to a new line in audio mode now centers the line on the grid. (AMZ)
|
||||||
- Commiting changes in audio to the last line will insert a new line after it. (AMZ)
|
- Commiting changes in audio to the last line will insert a new line after it. (AMZ)
|
||||||
|
- Fonts collector can now collect fonts directly to a zip archive. (AMZ)
|
||||||
|
|
||||||
|
|
||||||
= 1.10 beta - 2006.08.07 ===========================
|
= 1.10 beta - 2006.08.07 ===========================
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
// Includes
|
// Includes
|
||||||
#include <wx/config.h>
|
#include <wx/config.h>
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
#include <wx/wfstream.h>
|
||||||
|
#include <wx/zipstrm.h>
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
#include <shlobj.h>
|
#include <shlobj.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,16 +69,18 @@ DialogFontsCollector::DialogFontsCollector(wxWindow *parent)
|
||||||
dest = filename.GetPath();
|
dest = filename.GetPath();
|
||||||
}
|
}
|
||||||
AttachmentCheck = new wxCheckBox(this,ATTACHMENT_CHECK,_T("As attachments"),wxDefaultPosition);
|
AttachmentCheck = new wxCheckBox(this,ATTACHMENT_CHECK,_T("As attachments"),wxDefaultPosition);
|
||||||
|
ArchiveCheck = new wxCheckBox(this,ARCHIVE_CHECK,_T("As a zipped archive"),wxDefaultPosition);
|
||||||
DestBox = new wxTextCtrl(this,-1,dest,wxDefaultPosition,wxSize(250,20),0);
|
DestBox = new wxTextCtrl(this,-1,dest,wxDefaultPosition,wxSize(250,20),0);
|
||||||
BrowseButton = new wxButton(this,BROWSE_BUTTON,_("&Browse..."));
|
BrowseButton = new wxButton(this,BROWSE_BUTTON,_("&Browse..."));
|
||||||
wxSizer *DestBottomSizer = new wxBoxSizer(wxHORIZONTAL);
|
wxSizer *DestBottomSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
wxStaticText *DestLabel = new wxStaticText(this,-1,_("Choose the folder where the fonts will be collected to.\nIt will be created if it doesn't exist."));
|
DestLabel = new wxStaticText(this,-1,_("Choose the folder where the fonts will be collected to.\nIt will be created if it doesn't exist."));
|
||||||
DestBottomSizer->Add(DestBox,1,wxEXPAND | wxRIGHT,5);
|
DestBottomSizer->Add(DestBox,1,wxEXPAND | wxRIGHT,5);
|
||||||
DestBottomSizer->Add(BrowseButton,0,0,0);
|
DestBottomSizer->Add(BrowseButton,0,0,0);
|
||||||
wxSizer *DestSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Destination"));
|
wxSizer *DestSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Destination"));
|
||||||
DestSizer->Add(DestLabel,0,wxEXPAND | wxBOTTOM,5);
|
DestSizer->Add(DestLabel,0,wxEXPAND | wxBOTTOM,5);
|
||||||
DestSizer->Add(DestBottomSizer,0,wxEXPAND,0);
|
DestSizer->Add(DestBottomSizer,0,wxEXPAND,0);
|
||||||
DestSizer->Add(AttachmentCheck,0,wxTOP,5);
|
DestSizer->Add(AttachmentCheck,0,wxTOP,5);
|
||||||
|
DestSizer->Add(ArchiveCheck,0,wxTOP,5);
|
||||||
|
|
||||||
// Log box
|
// Log box
|
||||||
LogBox = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(300,210),wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH);
|
LogBox = new wxTextCtrl(this,-1,_T(""),wxDefaultPosition,wxSize(300,210),wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH);
|
||||||
|
@ -149,7 +153,8 @@ BEGIN_EVENT_TABLE(DialogFontsCollector, wxDialog)
|
||||||
EVT_BUTTON(START_BUTTON,DialogFontsCollector::OnStart)
|
EVT_BUTTON(START_BUTTON,DialogFontsCollector::OnStart)
|
||||||
EVT_BUTTON(BROWSE_BUTTON,DialogFontsCollector::OnBrowse)
|
EVT_BUTTON(BROWSE_BUTTON,DialogFontsCollector::OnBrowse)
|
||||||
EVT_BUTTON(wxID_CLOSE,DialogFontsCollector::OnClose)
|
EVT_BUTTON(wxID_CLOSE,DialogFontsCollector::OnClose)
|
||||||
EVT_CHECKBOX(ATTACHMENT_CHECK,DialogFontsCollector::OnCheck)
|
EVT_CHECKBOX(ATTACHMENT_CHECK,DialogFontsCollector::OnCheckAttach)
|
||||||
|
EVT_CHECKBOX(ARCHIVE_CHECK,DialogFontsCollector::OnCheckArchive)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,12 +164,13 @@ void DialogFontsCollector::OnStart(wxCommandEvent &event) {
|
||||||
// Check if it's OK to do it
|
// Check if it's OK to do it
|
||||||
wxString foldername = DestBox->GetValue();
|
wxString foldername = DestBox->GetValue();
|
||||||
wxFileName folder(foldername);
|
wxFileName folder(foldername);
|
||||||
|
bool zipOut = ArchiveCheck->IsChecked();
|
||||||
|
|
||||||
// Make folder if it doesn't exist
|
// Make folder if it doesn't exist
|
||||||
if (!folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
|
if (!zipOut && !folder.DirExists()) folder.Mkdir(0777,wxPATH_MKDIR_FULL);
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
if (folder.DirExists()) {
|
if (zipOut || folder.DirExists()) {
|
||||||
// Start thread
|
// Start thread
|
||||||
wxThread *worker = new FontsCollectorThread(AssFile::top,foldername,this);
|
wxThread *worker = new FontsCollectorThread(AssFile::top,foldername,this);
|
||||||
worker->Create();
|
worker->Create();
|
||||||
|
@ -190,7 +196,7 @@ void DialogFontsCollector::OnStart(wxCommandEvent &event) {
|
||||||
|
|
||||||
// Folder not available
|
// Folder not available
|
||||||
else {
|
else {
|
||||||
wxMessageBox(_("Invalid folder"),_("Error"),wxICON_EXCLAMATION | wxOK);
|
wxMessageBox(_("Invalid destination"),_("Error"),wxICON_EXCLAMATION | wxOK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,18 +211,44 @@ void DialogFontsCollector::OnClose(wxCommandEvent &event) {
|
||||||
///////////////////
|
///////////////////
|
||||||
// Browse location
|
// Browse location
|
||||||
void DialogFontsCollector::OnBrowse(wxCommandEvent &event) {
|
void DialogFontsCollector::OnBrowse(wxCommandEvent &event) {
|
||||||
wxString dest = wxDirSelector(_("Select folder to save fonts on"),DestBox->GetValue(),0);
|
// Chose file name
|
||||||
if (!dest.empty()) {
|
if (ArchiveCheck->IsChecked()) {
|
||||||
DestBox->SetValue(dest);
|
wxFileName fname(DestBox->GetValue());
|
||||||
|
wxString dest = wxFileSelector(_("Select archive file name"),DestBox->GetValue(),fname.GetFullName(),_T(".zip"),_T("Zip Archives (*.zip)|*.zip"),wxSAVE|wxOVERWRITE_PROMPT);
|
||||||
|
if (!dest.empty()) {
|
||||||
|
DestBox->SetValue(dest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Choose folder
|
||||||
|
else {
|
||||||
|
wxString dest = wxDirSelector(_("Select folder to save fonts on"),DestBox->GetValue(),0);
|
||||||
|
if (!dest.empty()) {
|
||||||
|
DestBox->SetValue(dest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////
|
////////////////////
|
||||||
// Checkbox
|
// Check Attachment
|
||||||
void DialogFontsCollector::OnCheck(wxCommandEvent &event) {
|
void DialogFontsCollector::OnCheckAttach(wxCommandEvent &event) {
|
||||||
BrowseButton->Enable(!AttachmentCheck->IsChecked());
|
bool check = AttachmentCheck->IsChecked();
|
||||||
DestBox->Enable(!AttachmentCheck->IsChecked());
|
BrowseButton->Enable(!check);
|
||||||
|
DestBox->Enable(!check);
|
||||||
|
if (check) ArchiveCheck->SetValue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////
|
||||||
|
// Check Archive
|
||||||
|
void DialogFontsCollector::OnCheckArchive(wxCommandEvent &event) {
|
||||||
|
bool check = ArchiveCheck->IsChecked();
|
||||||
|
if (check) {
|
||||||
|
AttachmentCheck->SetValue(false);
|
||||||
|
DestLabel->SetLabel(_("Enter the name of the destination zip file to collect the fonts to.\nIf a folder is entered, a default name will be used."));
|
||||||
|
}
|
||||||
|
else DestLabel->SetLabel(_("Choose the folder where the fonts will be collected to.\nIt will be created if it doesn't exist."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -303,8 +335,25 @@ wxThread::ExitCode FontsCollectorThread::Entry() {
|
||||||
///////////
|
///////////
|
||||||
// Collect
|
// Collect
|
||||||
void FontsCollectorThread::Collect() {
|
void FontsCollectorThread::Collect() {
|
||||||
|
// Prepare
|
||||||
|
bool attaching = collector->AttachmentCheck->IsChecked();
|
||||||
|
bool zipOut = collector->ArchiveCheck->IsChecked();
|
||||||
|
|
||||||
// Make sure there is a separator at the end
|
// Make sure there is a separator at the end
|
||||||
destination += _T("\\");
|
if (!zipOut) destination += _T("\\");
|
||||||
|
|
||||||
|
// For zipped files, enter a default name if none was given
|
||||||
|
else {
|
||||||
|
wxFileName dest(destination);
|
||||||
|
if (!dest.IsFileWritable()) {
|
||||||
|
wxFileName subsname(subs->filename);
|
||||||
|
if (!dest.IsDir()) {
|
||||||
|
destination = subsname.GetPath();
|
||||||
|
}
|
||||||
|
destination += _T("\\");
|
||||||
|
destination += subsname.GetName() + _T(".zip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reset log box
|
// Reset log box
|
||||||
wxTextCtrl *LogBox = collector->LogBox;
|
wxTextCtrl *LogBox = collector->LogBox;
|
||||||
|
@ -367,10 +416,17 @@ void FontsCollectorThread::Collect() {
|
||||||
else source = wxGetOSDirectory() + _T("\\fonts");
|
else source = wxGetOSDirectory() + _T("\\fonts");
|
||||||
source += _T("\\");
|
source += _T("\\");
|
||||||
|
|
||||||
|
// Open zip stream if saving to compressed archive
|
||||||
|
wxFFileOutputStream *out = NULL;
|
||||||
|
wxZipOutputStream *zip = NULL;
|
||||||
|
if (zipOut) {
|
||||||
|
out = new wxFFileOutputStream(destination);
|
||||||
|
zip = new wxZipOutputStream(*out);
|
||||||
|
}
|
||||||
|
|
||||||
// Get font file names
|
// Get font file names
|
||||||
wxArrayString work;
|
wxArrayString work;
|
||||||
wxArrayString copied;
|
wxArrayString copied;
|
||||||
bool attaching = collector->AttachmentCheck->IsChecked();
|
|
||||||
for (size_t i=0;i<fonts.GetCount();i++) {
|
for (size_t i=0;i<fonts.GetCount();i++) {
|
||||||
try {
|
try {
|
||||||
work = GetFontFiles(fonts[i]);
|
work = GetFontFiles(fonts[i]);
|
||||||
|
@ -391,7 +447,7 @@ void FontsCollectorThread::Collect() {
|
||||||
copied.Add(work[j]);
|
copied.Add(work[j]);
|
||||||
|
|
||||||
// Check if it exists
|
// Check if it exists
|
||||||
if (!attaching && wxFileName::FileExists(dstFile)) {
|
if (!attaching && !zipOut && wxFileName::FileExists(dstFile)) {
|
||||||
wxMutexGuiEnter();
|
wxMutexGuiEnter();
|
||||||
LogBox->SetDefaultStyle(wxTextAttr(wxColour(255,128,0)));
|
LogBox->SetDefaultStyle(wxTextAttr(wxColour(255,128,0)));
|
||||||
LogBox->AppendText(wxString(_T("\"")) + work[j] + _("\" already exists on destination.\n"));
|
LogBox->AppendText(wxString(_T("\"")) + work[j] + _("\" already exists on destination.\n"));
|
||||||
|
@ -403,7 +459,7 @@ void FontsCollectorThread::Collect() {
|
||||||
|
|
||||||
// Copy
|
// Copy
|
||||||
else {
|
else {
|
||||||
// Copy font
|
// Attach to file
|
||||||
bool success;
|
bool success;
|
||||||
if (attaching) {
|
if (attaching) {
|
||||||
try {
|
try {
|
||||||
|
@ -413,7 +469,21 @@ void FontsCollectorThread::Collect() {
|
||||||
}
|
}
|
||||||
catch (...) { success = false; }
|
catch (...) { success = false; }
|
||||||
}
|
}
|
||||||
else success = Copy(srcFile,dstFile);
|
|
||||||
|
// Copy to zip destination
|
||||||
|
else if (zipOut) {
|
||||||
|
// Open file
|
||||||
|
wxFFileInputStream in(srcFile);
|
||||||
|
|
||||||
|
// Write to archive
|
||||||
|
zip->PutNextEntry(work[j]);
|
||||||
|
zip->Write(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy to destination
|
||||||
|
else {
|
||||||
|
success = Copy(srcFile,dstFile);
|
||||||
|
}
|
||||||
|
|
||||||
// Report
|
// Report
|
||||||
wxMutexGuiEnter();
|
wxMutexGuiEnter();
|
||||||
|
@ -442,6 +512,13 @@ void FontsCollectorThread::Collect() {
|
||||||
wxMutexGuiLeave();
|
wxMutexGuiLeave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close ZIP archive
|
||||||
|
if (zipOut) {
|
||||||
|
zip->Close();
|
||||||
|
delete zip;
|
||||||
|
delete out;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Flag file as modified
|
// Flag file as modified
|
||||||
|
|
|
@ -95,12 +95,15 @@ private:
|
||||||
wxButton *StartButton;
|
wxButton *StartButton;
|
||||||
wxButton *CloseButton;
|
wxButton *CloseButton;
|
||||||
wxCheckBox *AttachmentCheck;
|
wxCheckBox *AttachmentCheck;
|
||||||
|
wxCheckBox *ArchiveCheck;
|
||||||
|
wxStaticText *DestLabel;
|
||||||
FrameMain *main;
|
FrameMain *main;
|
||||||
|
|
||||||
void OnStart(wxCommandEvent &event);
|
void OnStart(wxCommandEvent &event);
|
||||||
void OnClose(wxCommandEvent &event);
|
void OnClose(wxCommandEvent &event);
|
||||||
void OnBrowse(wxCommandEvent &event);
|
void OnBrowse(wxCommandEvent &event);
|
||||||
void OnCheck(wxCommandEvent &event);
|
void OnCheckAttach(wxCommandEvent &event);
|
||||||
|
void OnCheckArchive(wxCommandEvent &event);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DialogFontsCollector(wxWindow *parent);
|
DialogFontsCollector(wxWindow *parent);
|
||||||
|
@ -115,5 +118,6 @@ public:
|
||||||
enum {
|
enum {
|
||||||
BROWSE_BUTTON = 1100,
|
BROWSE_BUTTON = 1100,
|
||||||
START_BUTTON,
|
START_BUTTON,
|
||||||
ATTACHMENT_CHECK
|
ATTACHMENT_CHECK,
|
||||||
|
ARCHIVE_CHECK
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue