From 85e100c4f74ab41f83fe980326f088bb020bd7e6 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Fri, 18 Jan 2008 03:45:43 +0000 Subject: [PATCH] Changed Automation's autoload to ignore files of unknown extensions, instead of complaining about being unable to load them. This is necessary for the optional Perl support. Originally committed to SVN as r1762. --- aegisub/auto4_base.cpp | 24 +++++++++++++++++++++--- aegisub/auto4_base.h | 1 + aegisub/auto4_perl.cpp | 11 ++++++++--- installer/aegisub2.iss | 5 +++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/aegisub/auto4_base.cpp b/aegisub/auto4_base.cpp index 1fd062247..f1ae115c5 100644 --- a/aegisub/auto4_base.cpp +++ b/aegisub/auto4_base.cpp @@ -674,9 +674,12 @@ namespace Automation4 { while (more) { script_path.SetName(fn); try { - Script *s = ScriptFactory::CreateFromFile(script_path.GetFullPath(), true); - Add(s); - if (!s->GetLoadedState()) error_count++; + wxString fullpath = script_path.GetFullPath(); + if (ScriptFactory::CanHandleScriptFormat(fullpath)) { + Script *s = ScriptFactory::CreateFromFile(fullpath, true); + Add(s); + if (!s->GetLoadedState()) error_count++; + } } catch (const wchar_t *e) { error_count++; @@ -764,6 +767,21 @@ namespace Automation4 { return new UnknownScript(filename); } + bool ScriptFactory::CanHandleScriptFormat(const wxString &filename) + { + // Just make this always return true to bitch about unknown script formats in autoload + + if (!factories) + factories = new std::vector(); + + for (std::vector::iterator i = factories->begin(); i != factories->end(); ++i) { + wxString pattern = (*i)->GetFilenamePattern(); + if (filename.Matches(pattern)) return true; + } + + return false; + } + const std::vector& ScriptFactory::GetFactories() { if (!factories) diff --git a/aegisub/auto4_base.h b/aegisub/auto4_base.h index ec09ca78a..68f776971 100644 --- a/aegisub/auto4_base.h +++ b/aegisub/auto4_base.h @@ -352,6 +352,7 @@ namespace Automation4 { static void Register(ScriptFactory *factory); static void Unregister(ScriptFactory *factory); static Script* CreateFromFile(const wxString &filename, bool log_errors); + static bool CanHandleScriptFormat(const wxString &filename); static const std::vector& GetFactories(); }; diff --git a/aegisub/auto4_perl.cpp b/aegisub/auto4_perl.cpp index 045790b16..c61b46744 100644 --- a/aegisub/auto4_perl.cpp +++ b/aegisub/auto4_perl.cpp @@ -69,11 +69,13 @@ namespace Automation4 { class PerlScriptFactory : public ScriptFactory { private: PerlInterpreter *parser; + bool loaded; public: PerlScriptFactory() { // Script engine properties + loaded = false; engine_name = _T("Perl"); filename_pattern = _T("*") _T(PERL_SCRIPT_EXTENSION); @@ -103,16 +105,19 @@ namespace Automation4 { // Let's register the perl script factory \o/ Register(this); + loaded = true; } ~PerlScriptFactory() { // Perl interpreter deinitialization - perl_destruct(parser); - perl_free(parser); + if (loaded) { + perl_destruct(parser); + perl_free(parser); #ifdef __VISUALC__ - PERL_SYS_TERM(); + PERL_SYS_TERM(); #endif + } } virtual Script* Produce(const wxString &filename) const diff --git a/installer/aegisub2.iss b/installer/aegisub2.iss index bb14a1506..a4f463a7b 100644 --- a/installer/aegisub2.iss +++ b/installer/aegisub2.iss @@ -33,7 +33,7 @@ ; #define MyAppName "Aegisub" -#define MyAppVerName "Aegisub 2.00 alpha r1760" +#define MyAppVerName "Aegisub 2.00 alpha r1762" #define MyAppPublisher "Aegisub Team" #define MyAppURL "http://aegisub.net/" #define MyAppExeName "Aegisub.exe" @@ -68,7 +68,7 @@ PrivilegesRequired=poweruser DisableProgramGroupPage=true UsePreviousGroup=false AlwaysShowComponentsList=true -AppVersion=2.00 alpha r1760 +AppVersion=2.00 alpha r1762 AppID={{24BC8B57-716C-444F-B46B-A3349B9164C5} UninstallDisplayIcon={app}\Aegisub.exe @@ -115,6 +115,7 @@ DestDir: {app}\automation\autoload; Source: ..\automation\autoload\cleantags-aut ; perl #if IncludePerl != 0 DestDir: {app}\automation\docs; Source: ..\automation\v4-docs\perl-api.txt; Flags: ignoreversion overwritereadonly uninsremovereadonly; Components: auto/perl; Attribs: readonly +DestDir: {app}\automation\include; Source: ..\automation\include\Aegisub.pm; Flags: ignoreversion overwritereadonly uninsremovereadonly; Components: auto/perl; Attribs: readonly DestDir: {app}\automation\include; Source: ..\automation\include\Auto4Utils.pm; Flags: ignoreversion overwritereadonly uninsremovereadonly; Components: auto/perl; Attribs: readonly DestDir: {app}\automation\include\Aegisub; Source: ..\automation\include\Aegisub\PerlConsole.pm; Flags: ignoreversion overwritereadonly uninsremovereadonly; Components: auto/perl; Attribs: readonly DestDir: {app}\automation\include\Aegisub; Source: ..\automation\include\Aegisub\Script.pm; Flags: ignoreversion overwritereadonly uninsremovereadonly; Components: auto/perl; Attribs: readonly