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.
This commit is contained in:
Rodrigo Braz Monteiro 2008-01-18 03:45:43 +00:00
parent 7ffc21cc7e
commit 85e100c4f7
4 changed files with 33 additions and 8 deletions

View file

@ -674,9 +674,12 @@ namespace Automation4 {
while (more) { while (more) {
script_path.SetName(fn); script_path.SetName(fn);
try { try {
Script *s = ScriptFactory::CreateFromFile(script_path.GetFullPath(), true); wxString fullpath = script_path.GetFullPath();
Add(s); if (ScriptFactory::CanHandleScriptFormat(fullpath)) {
if (!s->GetLoadedState()) error_count++; Script *s = ScriptFactory::CreateFromFile(fullpath, true);
Add(s);
if (!s->GetLoadedState()) error_count++;
}
} }
catch (const wchar_t *e) { catch (const wchar_t *e) {
error_count++; error_count++;
@ -764,6 +767,21 @@ namespace Automation4 {
return new UnknownScript(filename); 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<ScriptFactory*>();
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
wxString pattern = (*i)->GetFilenamePattern();
if (filename.Matches(pattern)) return true;
}
return false;
}
const std::vector<ScriptFactory*>& ScriptFactory::GetFactories() const std::vector<ScriptFactory*>& ScriptFactory::GetFactories()
{ {
if (!factories) if (!factories)

View file

@ -352,6 +352,7 @@ namespace Automation4 {
static void Register(ScriptFactory *factory); static void Register(ScriptFactory *factory);
static void Unregister(ScriptFactory *factory); static void Unregister(ScriptFactory *factory);
static Script* CreateFromFile(const wxString &filename, bool log_errors); static Script* CreateFromFile(const wxString &filename, bool log_errors);
static bool CanHandleScriptFormat(const wxString &filename);
static const std::vector<ScriptFactory*>& GetFactories(); static const std::vector<ScriptFactory*>& GetFactories();
}; };

View file

@ -69,11 +69,13 @@ namespace Automation4 {
class PerlScriptFactory : public ScriptFactory { class PerlScriptFactory : public ScriptFactory {
private: private:
PerlInterpreter *parser; PerlInterpreter *parser;
bool loaded;
public: public:
PerlScriptFactory() PerlScriptFactory()
{ {
// Script engine properties // Script engine properties
loaded = false;
engine_name = _T("Perl"); engine_name = _T("Perl");
filename_pattern = _T("*") _T(PERL_SCRIPT_EXTENSION); filename_pattern = _T("*") _T(PERL_SCRIPT_EXTENSION);
@ -103,16 +105,19 @@ namespace Automation4 {
// Let's register the perl script factory \o/ // Let's register the perl script factory \o/
Register(this); Register(this);
loaded = true;
} }
~PerlScriptFactory() ~PerlScriptFactory()
{ {
// Perl interpreter deinitialization // Perl interpreter deinitialization
perl_destruct(parser); if (loaded) {
perl_free(parser); perl_destruct(parser);
perl_free(parser);
#ifdef __VISUALC__ #ifdef __VISUALC__
PERL_SYS_TERM(); PERL_SYS_TERM();
#endif #endif
}
} }
virtual Script* Produce(const wxString &filename) const virtual Script* Produce(const wxString &filename) const

View file

@ -33,7 +33,7 @@
; ;
#define MyAppName "Aegisub" #define MyAppName "Aegisub"
#define MyAppVerName "Aegisub 2.00 alpha r1760" #define MyAppVerName "Aegisub 2.00 alpha r1762"
#define MyAppPublisher "Aegisub Team" #define MyAppPublisher "Aegisub Team"
#define MyAppURL "http://aegisub.net/" #define MyAppURL "http://aegisub.net/"
#define MyAppExeName "Aegisub.exe" #define MyAppExeName "Aegisub.exe"
@ -68,7 +68,7 @@ PrivilegesRequired=poweruser
DisableProgramGroupPage=true DisableProgramGroupPage=true
UsePreviousGroup=false UsePreviousGroup=false
AlwaysShowComponentsList=true AlwaysShowComponentsList=true
AppVersion=2.00 alpha r1760 AppVersion=2.00 alpha r1762
AppID={{24BC8B57-716C-444F-B46B-A3349B9164C5} AppID={{24BC8B57-716C-444F-B46B-A3349B9164C5}
UninstallDisplayIcon={app}\Aegisub.exe UninstallDisplayIcon={app}\Aegisub.exe
@ -115,6 +115,7 @@ DestDir: {app}\automation\autoload; Source: ..\automation\autoload\cleantags-aut
; perl ; perl
#if IncludePerl != 0 #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\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; 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\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 DestDir: {app}\automation\include\Aegisub; Source: ..\automation\include\Aegisub\Script.pm; Flags: ignoreversion overwritereadonly uninsremovereadonly; Components: auto/perl; Attribs: readonly