mirror of https://github.com/odrling/Aegisub
Support multiple Automation autoload dirs. (I hope. As usual, not tested.)
Originally committed to SVN as r1219.
This commit is contained in:
parent
77e2f20424
commit
ac662477b9
|
@ -512,7 +512,7 @@ namespace Automation4 {
|
||||||
// copied from auto3
|
// copied from auto3
|
||||||
include_path.clear();
|
include_path.clear();
|
||||||
include_path.EnsureFileAccessible(filename);
|
include_path.EnsureFileAccessible(filename);
|
||||||
wxStringTokenizer toker(Options.AsText(_T("Automation Include Path")), _T("|"), false);
|
wxStringTokenizer toker(Options.AsText(_T("Automation Include Path")), _T("|"), wxTOKEN_STRTOK);
|
||||||
while (toker.HasMoreTokens()) {
|
while (toker.HasMoreTokens()) {
|
||||||
// todo? make some error reporting here
|
// todo? make some error reporting here
|
||||||
wxFileName path(toker.GetNextToken());
|
wxFileName path(toker.GetNextToken());
|
||||||
|
@ -641,37 +641,45 @@ namespace Automation4 {
|
||||||
|
|
||||||
void AutoloadScriptManager::Reload()
|
void AutoloadScriptManager::Reload()
|
||||||
{
|
{
|
||||||
wxDir dir;
|
|
||||||
if (!dir.Exists(path)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!dir.Open(path)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RemoveAll();
|
RemoveAll();
|
||||||
|
|
||||||
int error_count = 0;
|
int error_count = 0;
|
||||||
|
|
||||||
wxString fn;
|
wxStringTokenizer tok(path, _T("|"), wxTOKEN_STRTOK);
|
||||||
wxFileName script_path(path, _T(""));
|
while (tok.HasMoreTokens()) {
|
||||||
bool more = dir.GetFirst(&fn, wxEmptyString, wxDIR_FILES);
|
wxDir dir;
|
||||||
while (more) {
|
wxString dirname = tok.GetNextToken();
|
||||||
script_path.SetName(fn);
|
if (!dir.Exists(dirname)) {
|
||||||
try {
|
wxLogWarning(_T("A directory was specified in the Automation autoload path, but it doesn't exist: %s"), dirname.c_str());
|
||||||
Add(ScriptFactory::CreateFromFile(script_path.GetFullPath()));
|
continue;
|
||||||
}
|
}
|
||||||
catch (const wchar_t *e) {
|
if (!dir.Open(dirname)) {
|
||||||
error_count++;
|
wxLogWarning(_T("Failed to open a directory in the Automation autoload path: %s"), dirname.c_str());
|
||||||
wxLogError(_T("Error loading Automation script: %s\n%s"), fn.c_str(), e);
|
continue;
|
||||||
}
|
}
|
||||||
catch (...) {
|
|
||||||
error_count++;
|
wxString fn;
|
||||||
wxLogError(_T("Error loading Automation script: %s\nUnknown error."), fn.c_str());
|
wxFileName script_path(path, _T(""));
|
||||||
|
bool more = dir.GetFirst(&fn, wxEmptyString, wxDIR_FILES);
|
||||||
|
while (more) {
|
||||||
|
script_path.SetName(fn);
|
||||||
|
try {
|
||||||
|
Script *s = ScriptFactory::CreateFromFile(script_path.GetFullPath(), true);
|
||||||
|
Add(s);
|
||||||
|
if (!s->GetLoadedState()) error_count++;
|
||||||
|
}
|
||||||
|
catch (const wchar_t *e) {
|
||||||
|
error_count++;
|
||||||
|
wxLogError(_T("Error loading Automation script: %s\n%s"), fn.c_str(), e);
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
error_count++;
|
||||||
|
wxLogError(_T("Error loading Automation script: %s\nUnknown error."), fn.c_str());
|
||||||
|
}
|
||||||
|
more = dir.GetNext(&fn);
|
||||||
}
|
}
|
||||||
more = dir.GetNext(&fn);
|
|
||||||
}
|
}
|
||||||
if (error_count) {
|
if (error_count > 0) {
|
||||||
wxLogWarning(_T("One or more scripts placed in the Automation autoload directory failed to load\nPlease review the errors above, correct them and use the Reload Autoload dir button in Automation Manager to attempt loading the scripts again."));
|
wxLogWarning(_T("One or more scripts placed in the Automation autoload directory failed to load\nPlease review the errors above, correct them and use the Reload Autoload dir button in Automation Manager to attempt loading the scripts again."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -699,7 +707,7 @@ namespace Automation4 {
|
||||||
|
|
||||||
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
|
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
|
||||||
if (*i == factory) {
|
if (*i == factory) {
|
||||||
throw _T("Automation 4: Attempt to register the same script factory multiple times.");
|
throw _T("Automation 4: Attempt to register the same script factory multiple times. This should never happen.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
factories->push_back(factory);
|
factories->push_back(factory);
|
||||||
|
@ -718,7 +726,7 @@ namespace Automation4 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Script* ScriptFactory::CreateFromFile(const wxString &filename)
|
Script* ScriptFactory::CreateFromFile(const wxString &filename, bool log_errors)
|
||||||
{
|
{
|
||||||
if (!factories)
|
if (!factories)
|
||||||
factories = new std::vector<ScriptFactory*>();
|
factories = new std::vector<ScriptFactory*>();
|
||||||
|
@ -726,7 +734,13 @@ namespace Automation4 {
|
||||||
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
|
for (std::vector<ScriptFactory*>::iterator i = factories->begin(); i != factories->end(); ++i) {
|
||||||
try {
|
try {
|
||||||
Script *s = (*i)->Produce(filename);
|
Script *s = (*i)->Produce(filename);
|
||||||
if (s) return s;
|
if (s) {
|
||||||
|
if (!s->GetLoadedState() && log_errors) {
|
||||||
|
wxLogError(_("An Automation script failed to load. File name: '%s', error reported:"), filename.c_str());
|
||||||
|
wxLogError(s->GetDescription());
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Script *e) {
|
catch (Script *e) {
|
||||||
// This was the wrong script factory, but it throwing a Script object means it did know what to do about the file
|
// This was the wrong script factory, but it throwing a Script object means it did know what to do about the file
|
||||||
|
@ -734,6 +748,9 @@ namespace Automation4 {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (log_errors) {
|
||||||
|
wxLogWarning(_("The file was not recognised as an Automation script: %s"), filename.c_str());
|
||||||
|
}
|
||||||
return new UnknownScript(filename);
|
return new UnknownScript(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -345,7 +345,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);
|
static Script* CreateFromFile(const wxString &filename, bool log_errors);
|
||||||
static const std::vector<ScriptFactory*>& GetFactories();
|
static const std::vector<ScriptFactory*>& GetFactories();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -203,7 +203,7 @@ void DialogAutomation::OnAdd(wxCommandEvent &evt)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ExtraScriptInfo ei;
|
ExtraScriptInfo ei;
|
||||||
ei.script = Automation4::ScriptFactory::CreateFromFile(fname);
|
ei.script = Automation4::ScriptFactory::CreateFromFile(fname, false);
|
||||||
local_manager->Add(ei.script);
|
local_manager->Add(ei.script);
|
||||||
ei.is_global = false;
|
ei.is_global = false;
|
||||||
AddScript(ei);
|
AddScript(ei);
|
||||||
|
|
|
@ -847,7 +847,7 @@ void FrameMain::SynchronizeProject(bool fromSubs) {
|
||||||
sfname.MakeAbsolute(basepath);
|
sfname.MakeAbsolute(basepath);
|
||||||
if (sfname.FileExists()) {
|
if (sfname.FileExists()) {
|
||||||
sfnames = sfname.GetFullPath();
|
sfnames = sfname.GetFullPath();
|
||||||
local_scripts->Add(Automation4::ScriptFactory::CreateFromFile(sfnames));
|
local_scripts->Add(Automation4::ScriptFactory::CreateFromFile(sfnames, true));
|
||||||
} else {
|
} else {
|
||||||
wxLogWarning(_T("Automation Script referenced could not be found.\nFilename specified: %s%s\nSearched relative to: %s\nResolved filename: %s"),
|
wxLogWarning(_T("Automation Script referenced could not be found.\nFilename specified: %s%s\nSearched relative to: %s\nResolved filename: %s"),
|
||||||
sfnamel.c_str(), sfnames.c_str(), basepath.c_str(), sfname.GetFullPath().c_str());
|
sfnamel.c_str(), sfnames.c_str(), basepath.c_str(), sfname.GetFullPath().c_str());
|
||||||
|
|
Loading…
Reference in New Issue