diff --git a/aegisub/ass_export_filter.cpp b/aegisub/ass_export_filter.cpp index 9e6e45cf9..9d5b6abde 100644 --- a/aegisub/ass_export_filter.cpp +++ b/aegisub/ass_export_filter.cpp @@ -67,24 +67,35 @@ AssExportFilter::~AssExportFilter() { // Register void AssExportFilter::Register (wxString name,int priority) { // Check if it's registered - if (RegisterName != _T("")) { - throw wxString::Format(_T("Register export filter: filter with name \"%s\" is already registered."), name.c_str()); - } + // Changed this to an assert, since this kind of error should really only happen during dev. -jfs + // (Actually the list of regged filters should rather be looped through and check that this object isn't in.) + assert(RegisterName == _T("")); // Remove pipes from name name.Replace(_T("|"),_T("")); + int filter_copy = 0; + wxString tmpnam; + if (filter_copy == 0) { + tmpnam = name; + } else { +try_new_name: + tmpnam = wxString::Format(_T("%s (%d)"), name.c_str(), filter_copy); + } + // Check if name exists FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin(); FilterList::iterator end = AssExportFilterChain::GetFilterList()->end(); for (FilterList::iterator cur=begin;cur!=end;cur++) { - if ((*cur)->RegisterName == name) { - throw wxString::Format(_T("Register export filter: name \"%s\" already exists."), name.c_str()); + if ((*cur)->RegisterName == tmpnam) { + // Instead of just failing and making a big noise about it, let multiple filters share name, but append something to the later arrivals -jfs + filter_copy++; + goto try_new_name; } } // Set name - RegisterName = name; + RegisterName = tmpnam; Priority = priority; // Look for place to insert diff --git a/aegisub/auto4_base.cpp b/aegisub/auto4_base.cpp index f802edc41..fc0039ca9 100644 --- a/aegisub/auto4_base.cpp +++ b/aegisub/auto4_base.cpp @@ -513,6 +513,12 @@ namespace Automation4 { } } + wxString Script::GetPrettyFilename() const + { + wxFileName fn(filename); + return fn.GetFullName(); + } + const wxString& Script::GetFilename() const { return filename; diff --git a/aegisub/auto4_base.h b/aegisub/auto4_base.h index f5dd180f0..8ce3bb476 100644 --- a/aegisub/auto4_base.h +++ b/aegisub/auto4_base.h @@ -278,6 +278,7 @@ namespace Automation4 { virtual void Reload() = 0; const wxString& GetFilename() const; + wxString GetPrettyFilename() const; const wxString& GetName() const; const wxString& GetDescription() const; const wxString& GetAuthor() const; diff --git a/aegisub/auto4_lua.cpp b/aegisub/auto4_lua.cpp index 8a9900b96..de743d101 100644 --- a/aegisub/auto4_lua.cpp +++ b/aegisub/auto4_lua.cpp @@ -168,13 +168,7 @@ namespace Automation4 { : Script(filename) , L(0) { - try { - Create(); - } - catch (wxChar *e) { - description = e; - loaded = false; - } + Create(); } LuaScript::~LuaScript() @@ -243,7 +237,7 @@ namespace Automation4 { LuaScriptReader script_reader(GetFilename()); if (lua_load(L, script_reader.reader_func, &script_reader, GetFilename().mb_str(wxConvUTF8))) { wxString *err = new wxString(lua_tostring(L, -1), wxConvUTF8); - err->Prepend(_T("An error occurred loading the Lua script file \"") + GetFilename() + _T("\":\n\n")); + err->Prepend(_T("Error loading Lua script \"") + GetPrettyFilename() + _T("\":\n\n")); throw err->c_str(); } _stackcheck.check(1); @@ -256,7 +250,7 @@ namespace Automation4 { if (call.Wait()) { // error occurred, assumed to be on top of Lua stack wxString *err = new wxString(lua_tostring(L, -1), wxConvUTF8); - err->Prepend(_T("An error occurred initialising the Lua script file \"") + GetFilename() + _T("\":\n\n")); + err->Prepend(_T("Error initialising Lua script \"") + GetPrettyFilename() + _T("\":\n\n")); throw err->c_str(); } } @@ -274,7 +268,7 @@ namespace Automation4 { if (lua_isstring(L, -1)) { name = wxString(lua_tostring(L, -1), wxConvUTF8); } else { - name = GetFilename(); + name = GetPrettyFilename(); } lua_getglobal(L, "script_description"); if (lua_isstring(L, -1)) { @@ -293,10 +287,23 @@ namespace Automation4 { _stackcheck.check(0); } + catch (const char *e) { + Destroy(); + loaded = false; + name = GetPrettyFilename(); + description = wxString(e, wxConvUTF8); + } + catch (const wchar_t *e) { + Destroy(); + loaded = false; + name = GetPrettyFilename(); + description = e; + } catch (...) { Destroy(); loaded = false; - throw; + name = GetPrettyFilename(); + description = _T("Unknown error initialising Lua script"); } } @@ -394,13 +401,13 @@ namespace Automation4 { // absolute path, do nothing } if (!fname.IsOk() || !fname.FileExists()) { - lua_pushfstring(L, "Could not find Lua script for inclusion: %s", fnames.mb_str(wxConvUTF8).data()); + lua_pushfstring(L, "Lua include not found: %s", fnames.mb_str(wxConvUTF8).data()); lua_error(L); } LuaScriptReader script_reader(fname.GetFullPath()); if (lua_load(L, script_reader.reader_func, &script_reader, s->GetFilename().mb_str(wxConvUTF8))) { - lua_pushfstring(L, "An error occurred loading the Lua script file \"%s\":\n\n%s", fname.GetFullPath().mb_str(wxConvUTF8).data(), lua_tostring(L, -1)); + lua_pushfstring(L, "Error loading Lua include \"%s\":\n\n%s", fname.GetFullPath().mb_str(wxConvUTF8).data(), lua_tostring(L, -1)); lua_error(L); return 0; } diff --git a/aegisub/changelog.txt b/aegisub/changelog.txt index 0f6af2b01..183fcb316 100644 --- a/aegisub/changelog.txt +++ b/aegisub/changelog.txt @@ -8,7 +8,7 @@ Please visit http://aegisub.net to download latest version o Automation 4 Lua uses Lua 5.1 instead of 5.0, meaning some new language features: o It is now possible to write macros that manipulate subtitles directly o Scripts have full access to the entire subtitle file, not just the "Events" section - o Also has a compatibility Automation 3 engine, so old scripts should continue working with little or no changes + o Also has a compatibility Automation 3 engine, but due to some differences from Lua 5.0.2 to Lua 5.1, there is a good chance you will have to make minor changes to old scripts - Video mode has been mostly rewriten and now uses OpenGL instead of software rendering, making it much faster on computers with video cards that don't belong to the stone age. (AMZ) o Optionally, it can use a Pixel Shader to convert YV12 to RGB32 in hardware, which is much faster, with a decent video card. - Visual Typesetting functionality implemented, which should make typesetting much easier and faster. It supports: (AMZ) diff --git a/automation/tests/test10.lua b/automation/tests/test10.lua new file mode 100644 index 000000000..8c847c620 --- /dev/null +++ b/automation/tests/test10.lua @@ -0,0 +1,19 @@ +-- Automation 4 test file +-- Create a Filter feature that does some kara stuff + +script_name = "Automation 4 test 10" +script_description = "Test reaction to export filter name clashes" +script_author = "Niels Martin Hansen" +script_version = "1" + +include("utils.lua") + +function function1(subtitles, config) + aegisub.debug.out("function 1") +end +function function2(subtitles, config) + aegisub.debug.out("function 2") +end + +aegisub.register_filter("Export breaker", "Export filter with nameclash (1)", 500, function1) +aegisub.register_filter("Export breaker", "Export filter with nameclash (2)", 500, function2)