2007-06-20 07:18:47 +02:00
// Copyright (c) 2007, Rodrigo Braz Monteiro
2006-01-16 22:02:54 +01:00
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
////////////
// Includes
# include <wx/config.h>
# include <wx/filename.h>
2006-12-18 23:24:25 +01:00
# include <wx/wfstream.h>
# include <wx/zipstrm.h>
2006-01-16 22:02:54 +01:00
# include "ass_override.h"
# include "ass_file.h"
# include "ass_dialogue.h"
# include "ass_style.h"
2006-12-24 22:52:54 +01:00
# include "dialog_fonts_collector.h"
2006-01-16 22:02:54 +01:00
# include "utils.h"
# include "options.h"
2006-07-09 01:07:24 +02:00
# include "frame_main.h"
# include "subs_grid.h"
2006-12-30 21:58:24 +01:00
# include "main.h"
2007-06-20 07:18:47 +02:00
# include "font_file_lister.h"
# include "utils.h"
///////
// IDs
enum IDs {
START_BUTTON = 1150 ,
BROWSE_BUTTON ,
RADIO_BOX
} ;
2006-01-16 22:02:54 +01:00
///////////////
// Constructor
DialogFontsCollector : : DialogFontsCollector ( wxWindow * parent )
: wxDialog ( parent , - 1 , _ ( " Fonts Collector " ) , wxDefaultPosition , wxDefaultSize , wxDEFAULT_DIALOG_STYLE )
{
2006-07-09 01:07:24 +02:00
// Parent
main = ( FrameMain * ) parent ;
2006-01-16 22:02:54 +01:00
// Destination box
2006-02-20 23:06:38 +01:00
wxString dest = Options . AsText ( _T ( " Fonts Collector Destination " ) ) ;
if ( dest = = _T ( " ?script " ) ) {
wxFileName filename ( AssFile : : top - > filename ) ;
dest = filename . GetPath ( ) ;
}
DestBox = new wxTextCtrl ( this , - 1 , dest , wxDefaultPosition , wxSize ( 250 , 20 ) , 0 ) ;
2006-01-16 22:02:54 +01:00
BrowseButton = new wxButton ( this , BROWSE_BUTTON , _ ( " &Browse... " ) ) ;
wxSizer * DestBottomSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2006-12-18 23:24:25 +01:00
DestLabel = new wxStaticText ( this , - 1 , _ ( " Choose the folder where the fonts will be collected to. \n It will be created if it doesn't exist. " ) ) ;
2006-01-16 22:02:54 +01:00
DestBottomSizer - > Add ( DestBox , 1 , wxEXPAND | wxRIGHT , 5 ) ;
DestBottomSizer - > Add ( BrowseButton , 0 , 0 , 0 ) ;
wxSizer * DestSizer = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Destination " ) ) ;
DestSizer - > Add ( DestLabel , 0 , wxEXPAND | wxBOTTOM , 5 ) ;
DestSizer - > Add ( DestBottomSizer , 0 , wxEXPAND , 0 ) ;
2007-06-20 07:18:47 +02:00
// Action radio box
wxArrayString choices ;
choices . Add ( _T ( " Check fonts for availability " ) ) ;
choices . Add ( _T ( " Copy fonts to folder " ) ) ;
choices . Add ( _T ( " Copy fonts to zipped archive " ) ) ;
choices . Add ( _T ( " Attach fonts to current subtitles " ) ) ;
CollectAction = new wxRadioBox ( this , RADIO_BOX , _T ( " Action " ) , wxDefaultPosition , wxDefaultSize , choices , 1 ) ;
2007-06-20 08:29:20 +02:00
CollectAction - > SetSelection ( Options . AsInt ( _T ( " Fonts Collector Action " ) ) ) ;
2006-01-16 22:02:54 +01:00
// Log box
2007-06-20 07:18:47 +02:00
LogBox = new wxStyledTextCtrl ( this , - 1 , wxDefaultPosition , wxSize ( 300 , 210 ) , 0 , _T ( " " ) ) ;
LogBox - > SetWrapMode ( wxSTC_WRAP_WORD ) ;
LogBox - > SetMarginWidth ( 1 , 0 ) ;
LogBox - > SetReadOnly ( true ) ;
LogBox - > StyleSetForeground ( 1 , wxColour ( 0 , 200 , 0 ) ) ;
LogBox - > StyleSetForeground ( 2 , wxColour ( 200 , 0 , 0 ) ) ;
LogBox - > StyleSetForeground ( 3 , wxColour ( 200 , 100 , 0 ) ) ;
2006-01-16 22:02:54 +01:00
wxSizer * LogSizer = new wxStaticBoxSizer ( wxVERTICAL , this , _ ( " Log " ) ) ;
LogSizer - > Add ( LogBox , 1 , wxEXPAND , 0 ) ;
// Buttons sizer
StartButton = new wxButton ( this , START_BUTTON , _ ( " &Start! " ) ) ;
StartButton - > SetDefault ( ) ;
2006-12-30 21:58:24 +01:00
CloseButton = new wxButton ( this , wxID_CANCEL , _T ( " Close " ) ) ;
2006-01-16 22:02:54 +01:00
wxSizer * ButtonSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
ButtonSizer - > AddStretchSpacer ( 1 ) ;
2006-12-30 21:58:24 +01:00
# ifdef __WXMAC__
2006-06-19 04:57:27 +02:00
ButtonSizer - > Add ( CloseButton , 0 , wxRIGHT , 5 ) ;
ButtonSizer - > Add ( StartButton ) ;
2006-12-30 21:58:24 +01:00
# else
ButtonSizer - > Add ( StartButton , 0 , wxRIGHT , 5 ) ;
ButtonSizer - > Add ( CloseButton ) ;
2006-06-19 04:57:27 +02:00
# endif
2006-01-16 22:02:54 +01:00
// Main sizer
wxSizer * MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
2007-06-20 07:18:47 +02:00
MainSizer - > Add ( CollectAction , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 5 ) ;
2006-01-16 22:02:54 +01:00
MainSizer - > Add ( DestSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 5 ) ;
MainSizer - > Add ( LogSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 5 ) ;
MainSizer - > Add ( ButtonSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 5 ) ;
// Set sizer
SetSizer ( MainSizer ) ;
MainSizer - > SetSizeHints ( this ) ;
2007-06-20 07:18:47 +02:00
CenterOnParent ( ) ;
2006-12-30 21:58:24 +01:00
// Run dummy event to update label
Update ( ) ;
2006-01-16 22:02:54 +01:00
}
//////////////
// Destructor
DialogFontsCollector : : ~ DialogFontsCollector ( ) {
2007-06-20 07:18:47 +02:00
FontFileLister : : ClearData ( ) ;
2006-01-16 22:02:54 +01:00
}
///////////////
// Event table
BEGIN_EVENT_TABLE ( DialogFontsCollector , wxDialog )
EVT_BUTTON ( START_BUTTON , DialogFontsCollector : : OnStart )
EVT_BUTTON ( BROWSE_BUTTON , DialogFontsCollector : : OnBrowse )
EVT_BUTTON ( wxID_CLOSE , DialogFontsCollector : : OnClose )
2007-06-20 07:18:47 +02:00
EVT_RADIOBOX ( RADIO_BOX , DialogFontsCollector : : OnRadio )
2006-01-16 22:02:54 +01:00
END_EVENT_TABLE ( )
////////////////////
// Start processing
void DialogFontsCollector : : OnStart ( wxCommandEvent & event ) {
2007-06-20 09:10:41 +02:00
// Action being done
int action = CollectAction - > GetSelection ( ) ;
2006-01-16 22:02:54 +01:00
// Check if it's OK to do it
wxString foldername = DestBox - > GetValue ( ) ;
2007-06-20 09:10:41 +02:00
if ( action = = 1 ) foldername + = _T ( " // " ) ;
2006-01-16 22:02:54 +01:00
wxFileName folder ( foldername ) ;
2007-06-20 09:10:41 +02:00
bool isFolder = folder . IsDir ( ) ;
// Check if it's a folder
if ( action = = 1 & & ! isFolder ) {
wxMessageBox ( _ ( " Invalid destination. " ) , _ ( " Error " ) , wxICON_EXCLAMATION | wxOK ) ;
return ;
}
2006-01-16 22:02:54 +01:00
// Make folder if it doesn't exist
2007-06-20 09:10:41 +02:00
if ( action = = 1 | | action = = 2 ) {
2007-06-20 07:18:47 +02:00
if ( ! folder . DirExists ( ) ) {
2007-06-20 09:10:41 +02:00
folder . Mkdir ( 0777 , wxPATH_MKDIR_FULL ) ;
if ( ! folder . DirExists ( ) ) {
wxMessageBox ( _ ( " Could not create destination folder. " ) , _ ( " Error " ) , wxICON_EXCLAMATION | wxOK ) ;
return ;
}
}
}
// Check if we have a valid archive name
if ( action = = 2 ) {
if ( isFolder | | folder . GetName ( ) . IsEmpty ( ) | | folder . GetExt ( ) ! = _T ( " zip " ) ) {
wxMessageBox ( _ ( " Invalid path for .zip file. " ) , _ ( " Error " ) , wxICON_EXCLAMATION | wxOK ) ;
2007-06-20 07:18:47 +02:00
return ;
}
}
2006-01-16 22:02:54 +01:00
2007-06-20 07:18:47 +02:00
// Start thread
wxThread * worker = new FontsCollectorThread ( AssFile : : top , foldername , this ) ;
worker - > Create ( ) ;
worker - > Run ( ) ;
2006-01-16 22:02:54 +01:00
2007-06-20 07:18:47 +02:00
// Set options
if ( action = = 1 | | action = = 2 ) {
2006-02-20 23:06:38 +01:00
wxString dest = foldername ;
wxFileName filename ( AssFile : : top - > filename ) ;
if ( filename . GetPath ( ) = = dest ) {
dest = _T ( " ?script " ) ;
}
Options . SetText ( _T ( " Fonts Collector Destination " ) , dest ) ;
2006-01-16 22:02:54 +01:00
}
2007-06-20 08:29:20 +02:00
Options . SetInt ( _T ( " Fonts Collector Action " ) , action ) ;
Options . Save ( ) ;
2006-01-16 22:02:54 +01:00
2007-06-20 07:18:47 +02:00
// Set buttons
StartButton - > Enable ( false ) ;
BrowseButton - > Enable ( false ) ;
DestBox - > Enable ( false ) ;
CloseButton - > Enable ( false ) ;
CollectAction - > Enable ( false ) ;
DestLabel - > Enable ( false ) ;
if ( ! worker - > IsDetached ( ) ) worker - > Wait ( ) ;
2006-01-16 22:02:54 +01:00
}
////////////////
// Close dialog
void DialogFontsCollector : : OnClose ( wxCommandEvent & event ) {
EndModal ( 0 ) ;
}
///////////////////
// Browse location
void DialogFontsCollector : : OnBrowse ( wxCommandEvent & event ) {
2006-12-18 23:24:25 +01:00
// Chose file name
2007-06-20 07:18:47 +02:00
if ( CollectAction - > GetSelection ( ) = = 2 ) {
2006-12-18 23:24:25 +01:00
wxFileName fname ( DestBox - > GetValue ( ) ) ;
2007-01-22 20:31:49 +01:00
wxString dest = wxFileSelector ( _ ( " Select archive file name " ) , DestBox - > GetValue ( ) , fname . GetFullName ( ) , _T ( " .zip " ) , _T ( " Zip Archives (*.zip)|*.zip " ) , wxFD_SAVE | wxFD_OVERWRITE_PROMPT ) ;
2006-12-18 23:24:25 +01:00
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 ) ;
}
2006-01-16 22:02:54 +01:00
}
}
2007-06-20 07:18:47 +02:00
/////////////////////
// Radio box changed
void DialogFontsCollector : : OnRadio ( wxCommandEvent & event ) {
Update ( event . GetInt ( ) ) ;
2006-12-30 21:58:24 +01:00
}
///////////////////
// Update controls
2007-06-20 07:18:47 +02:00
void DialogFontsCollector : : Update ( int value ) {
2007-06-20 08:29:20 +02:00
// Enable buttons
CloseButton - > Enable ( true ) ;
StartButton - > Enable ( true ) ;
CollectAction - > Enable ( true ) ;
2007-06-20 09:10:41 +02:00
wxString dst = DestBox - > GetValue ( ) ;
2007-06-20 08:29:20 +02:00
2007-06-20 07:18:47 +02:00
// Get value if -1
if ( value = = - 1 ) {
value = CollectAction - > GetSelection ( ) ;
2006-12-18 23:24:25 +01:00
}
2007-06-20 07:18:47 +02:00
2007-06-20 08:29:20 +02:00
// Check or attach
if ( value = = 0 | | value = = 3 ) {
2007-06-20 07:18:47 +02:00
DestBox - > Enable ( false ) ;
BrowseButton - > Enable ( false ) ;
DestLabel - > Enable ( false ) ;
2007-06-20 08:29:20 +02:00
DestLabel - > SetLabel ( _T ( " N/A \n " ) ) ;
2007-06-20 07:18:47 +02:00
}
// Collect to folder
else if ( value = = 1 ) {
DestBox - > Enable ( true ) ;
BrowseButton - > Enable ( true ) ;
DestLabel - > Enable ( true ) ;
2006-12-30 21:58:24 +01:00
DestLabel - > SetLabel ( _ ( " Choose the folder where the fonts will be collected to. \n It will be created if it doesn't exist. " ) ) ;
2007-06-20 09:10:41 +02:00
// Remove filename from browse box
if ( dst . Right ( 4 ) = = _T ( " .zip " ) ) {
wxFileName fn ( dst ) ;
DestBox - > SetValue ( fn . GetPath ( ) ) ;
2006-12-30 21:58:24 +01:00
}
}
2006-01-16 22:02:54 +01:00
2007-06-20 07:18:47 +02:00
// Collect to zip
else if ( value = = 2 ) {
DestBox - > Enable ( true ) ;
BrowseButton - > Enable ( true ) ;
DestLabel - > Enable ( true ) ;
DestLabel - > SetLabel ( _ ( " Enter the name of the destination zip file to collect the fonts to. \n If a folder is entered, a default name will be used. " ) ) ;
2007-06-20 09:10:41 +02:00
// Add filename to browse box
if ( dst . Right ( 4 ) ! = _T ( " .zip " ) ) {
wxFileName fn ( dst + _T ( " // " ) ) ;
fn . SetFullName ( _T ( " fonts.zip " ) ) ;
DestBox - > SetValue ( fn . GetFullPath ( ) ) ;
}
2006-01-16 22:02:54 +01:00
}
}
///////////////////////
// Collect font files
void FontsCollectorThread : : CollectFontData ( ) {
2007-06-20 07:18:47 +02:00
FontFileLister : : GatherData ( ) ;
2006-01-16 22:02:54 +01:00
}
////////////////////
// Collector thread
FontsCollectorThread : : FontsCollectorThread ( AssFile * _subs , wxString _destination , DialogFontsCollector * _collector )
: wxThread ( wxTHREAD_DETACHED )
{
subs = _subs ;
destination = _destination ;
collector = _collector ;
instance = this ;
}
////////////////
// Thread entry
wxThread : : ExitCode FontsCollectorThread : : Entry ( ) {
// Collect
Collect ( ) ;
2007-06-20 08:29:20 +02:00
// After done, restore status
collector - > Update ( ) ;
2006-01-16 22:02:54 +01:00
// Return
if ( IsDetached ( ) ) Delete ( ) ;
return 0 ;
}
///////////
// Collect
void FontsCollectorThread : : Collect ( ) {
2007-06-20 08:29:20 +02:00
// Clear log box
wxMutexGuiEnter ( ) ;
collector - > LogBox - > SetReadOnly ( false ) ;
collector - > LogBox - > ClearAll ( ) ;
collector - > LogBox - > SetReadOnly ( true ) ;
wxMutexGuiLeave ( ) ;
2007-06-20 07:18:47 +02:00
// Set destination folder
int oper = collector - > CollectAction - > GetSelection ( ) ;
destFolder = collector - > DestBox - > GetValue ( ) ;
if ( oper = = 1 & & ! wxFileName : : DirExists ( destFolder ) ) {
AppendText ( _ ( " Invalid destination directory. " ) , 1 ) ;
return ;
2006-12-18 23:24:25 +01:00
}
2006-01-16 22:02:54 +01:00
2007-06-20 09:10:41 +02:00
// Open zip stream if saving to compressed archive
wxFFileOutputStream * out = NULL ;
zip = NULL ;
if ( oper = = 2 ) {
out = new wxFFileOutputStream ( destFolder ) ;
zip = new wxZipOutputStream ( * out ) ;
}
2007-06-20 07:18:47 +02:00
// Collect font data
2007-06-20 23:08:31 +02:00
AppendText ( _ ( " Collecting font data from system. This might take a while, depending on the number of fonts installed. Results are cached and subsequent executions will be faster... " ) ) ;
2007-06-20 07:18:47 +02:00
CollectFontData ( ) ;
AppendText ( _ ( " done. \n \n Scanning file for fonts... " ) ) ;
2006-01-16 22:02:54 +01:00
2007-06-20 07:18:47 +02:00
// Scan file
2006-01-16 22:02:54 +01:00
AssDialogue * curDiag ;
curLine = 0 ;
for ( std : : list < AssEntry * > : : iterator cur = subs - > Line . begin ( ) ; cur ! = subs - > Line . end ( ) ; cur + + ) {
// Collect from style
curStyle = AssEntry : : GetAsStyle ( * cur ) ;
if ( curStyle ) {
AddFont ( curStyle - > font , true ) ;
}
// Collect from dialogue
else {
curDiag = AssEntry : : GetAsDialogue ( * cur ) ;
if ( curDiag ) {
curLine + + ;
2006-03-22 01:25:47 +01:00
curDiag - > ParseASSTags ( ) ;
2006-01-16 22:02:54 +01:00
curDiag - > ProcessParameters ( GetFonts ) ;
2006-03-22 01:25:47 +01:00
curDiag - > ClearBlocks ( ) ;
2006-01-16 22:02:54 +01:00
}
}
}
2007-06-20 07:18:47 +02:00
// Copy fonts
AppendText ( _ ( " Done. \n \n " ) ) ;
switch ( oper ) {
case 0 : AppendText ( _ ( " Checking fonts... \n " ) ) ; break ;
case 1 : AppendText ( _ ( " Copying fonts to folder... \n " ) ) ; break ;
case 2 : AppendText ( _ ( " Copying fonts to archive... \n " ) ) ; break ;
case 3 : AppendText ( _ ( " Attaching fonts to file... \n " ) ) ; break ;
}
bool ok = true ;
2007-06-20 08:29:20 +02:00
bool someOk = false ;
2007-06-20 07:18:47 +02:00
for ( size_t i = 0 ; i < fonts . Count ( ) ; i + + ) {
2007-06-20 08:29:20 +02:00
bool result = ProcessFont ( fonts [ i ] ) ;
if ( result ) someOk = true ;
if ( ! result ) ok = false ;
2007-06-20 07:18:47 +02:00
}
2007-06-20 09:10:41 +02:00
// Close ZIP archive
if ( oper = = 2 ) {
zip - > Close ( ) ;
delete zip ;
delete out ;
AppendText ( wxString : : Format ( _ ( " \n Finished writing to %s. \n " ) , destination . c_str ( ) ) , 1 ) ;
}
2007-06-20 07:18:47 +02:00
// Final result
if ( ok ) {
if ( oper = = 0 ) AppendText ( _ ( " Done. All fonts found. " ) , 1 ) ;
2007-06-20 08:29:20 +02:00
else {
AppendText ( _ ( " Done. All fonts copied. " ) , 1 ) ;
// Modify file if it was attaching
if ( oper = = 3 & & someOk ) {
wxMutexGuiEnter ( ) ;
subs - > FlagAsModified ( _ ( " font attachment " ) ) ;
collector - > main - > SubsBox - > CommitChanges ( ) ;
wxMutexGuiLeave ( ) ;
}
}
2007-06-20 07:18:47 +02:00
}
else {
if ( oper = = 0 ) AppendText ( _ ( " Done. Some fonts could not be found. " ) , 2 ) ;
else AppendText ( _ ( " Done. Some fonts could not be copied. " ) , 2 ) ;
}
}
2006-01-16 22:02:54 +01:00
2007-06-20 07:18:47 +02:00
////////////////
// Process font
bool FontsCollectorThread : : ProcessFont ( wxString name ) {
// Action
int action = collector - > CollectAction - > GetSelection ( ) ;
// Font name
AppendText ( wxString : : Format ( _T ( " \" %s \" ... " ) , name . c_str ( ) ) ) ;
// Get font list
wxArrayString files = FontFileLister : : GetFilesWithFace ( name ) ;
bool result = files . Count ( ) ! = 0 ;
// No files found
if ( ! result ) {
AppendText ( _ ( " Not found. \n " ) , 2 ) ;
return false ;
2006-01-16 22:02:54 +01:00
}
2007-06-20 07:18:47 +02:00
// Just checking, found
else if ( action = = 0 ) {
AppendText ( _ ( " Found. \n " ) , 1 ) ;
return true ;
2006-12-18 23:24:25 +01:00
}
2007-06-20 07:18:47 +02:00
// Copy font
AppendText ( _T ( " \n " ) ) ;
for ( size_t i = 0 ; i < files . Count ( ) ; i + + ) {
int tempResult = 0 ;
switch ( action ) {
case 1 : tempResult = CopyFont ( files [ i ] ) ; break ;
case 2 : tempResult = ArchiveFont ( files [ i ] ) ? 1 : 0 ; break ;
case 3 : tempResult = AttachFont ( files [ i ] ) ? 1 : 0 ; break ;
2006-01-16 22:02:54 +01:00
}
2007-06-20 07:18:47 +02:00
if ( tempResult = = 1 ) {
AppendText ( wxString : : Format ( _ ( " * Copied %s. \n " ) , files [ i ] . c_str ( ) ) , 1 ) ;
}
else if ( tempResult = = 2 ) {
wxFileName fn ( files [ i ] ) ;
AppendText ( wxString : : Format ( _ ( " * %s already exists on destination. \n " ) , fn . GetFullName ( ) . c_str ( ) ) , 3 ) ;
2006-01-16 22:02:54 +01:00
}
2007-06-20 07:18:47 +02:00
else {
AppendText ( wxString : : Format ( _ ( " * Failed to copy %s. \n " ) , files [ i ] . c_str ( ) ) , 2 ) ;
result = false ;
}
}
// Done
return result ;
}
/////////////
// Copy font
int FontsCollectorThread : : CopyFont ( wxString filename ) {
wxFileName fn ( filename ) ;
wxString dstName = destFolder + _T ( " // " ) + fn . GetFullName ( ) ;
if ( wxFileName : : FileExists ( dstName ) ) return 2 ;
return CopyFile ( filename , dstName ) ? 1 : 0 ;
}
////////////////
// Archive font
bool FontsCollectorThread : : ArchiveFont ( wxString filename ) {
2007-06-20 09:10:41 +02:00
// Open file
wxFFileInputStream in ( filename ) ;
if ( ! in . IsOk ( ) ) return false ;
// Write to archive
try {
wxFileName fn ( filename ) ;
zip - > PutNextEntry ( fn . GetFullName ( ) ) ;
zip - > Write ( in ) ;
}
catch ( . . . ) {
return false ;
}
return true ;
2007-06-20 07:18:47 +02:00
}
///////////////
// Attach font
bool FontsCollectorThread : : AttachFont ( wxString filename ) {
2007-06-20 08:29:20 +02:00
try {
subs - > InsertAttachment ( filename ) ;
}
catch ( . . . ) {
return false ;
}
return true ;
2007-06-20 07:18:47 +02:00
}
////////////////////////////////
// Get fonts from ass overrides
void FontsCollectorThread : : GetFonts ( wxString tagName , int par_n , AssOverrideParameter * param , void * usr ) {
if ( tagName = = _T ( " \\ fn " ) ) {
instance - > AddFont ( param - > AsText ( ) , false ) ;
2006-01-16 22:02:54 +01:00
}
2007-06-20 07:18:47 +02:00
}
2006-12-18 23:24:25 +01:00
2007-06-20 07:18:47 +02:00
///////////////
// Adds a font
void FontsCollectorThread : : AddFont ( wxString fontname , bool isStyle ) {
if ( fonts . Index ( fontname ) = = wxNOT_FOUND ) {
fonts . Add ( fontname ) ;
2007-01-04 04:53:56 +01:00
2007-06-20 07:18:47 +02:00
if ( isStyle ) AppendText ( wxString ( _T ( " \" " ) ) + fontname + _ ( " \" found on style \" " ) + curStyle - > name + _T ( " \" . \n " ) ) ;
if ( ! isStyle ) AppendText ( wxString ( _T ( " \" " ) ) + fontname + _ ( " \" found on dialogue line " ) + wxString : : Format ( _T ( " %i " ) , curLine ) + _T ( " . \n " ) ) ;
2006-12-18 23:24:25 +01:00
}
2007-06-20 07:18:47 +02:00
}
2006-07-09 01:07:24 +02:00
2007-06-20 07:18:47 +02:00
///////////////
// Append text
void FontsCollectorThread : : AppendText ( wxString text , int colour ) {
wxStyledTextCtrl * LogBox = collector - > LogBox ;
wxMutexGuiEnter ( ) ;
LogBox - > SetReadOnly ( false ) ;
int pos = LogBox - > GetLength ( ) ;
LogBox - > AppendText ( text ) ;
if ( colour ) {
LogBox - > StartStyling ( pos , 31 ) ;
LogBox - > SetStyling ( text . Length ( ) , colour ) ;
2006-07-09 01:07:24 +02:00
}
2007-06-20 07:18:47 +02:00
LogBox - > GotoPos ( pos ) ;
LogBox - > SetReadOnly ( true ) ;
wxSafeYield ( ) ;
wxMutexGuiLeave ( ) ;
2006-01-16 22:02:54 +01:00
}
2007-06-20 07:18:47 +02:00
///////////////////
// Static instance
FontsCollectorThread * FontsCollectorThread : : instance ;