Improved detection of ASS-family formats.

Originally committed to SVN as r2474.
This commit is contained in:
Rodrigo Braz Monteiro 2008-11-22 00:35:10 +00:00
parent 2a0f9b7447
commit 56e0bea8d9
2 changed files with 47 additions and 3 deletions

View file

@ -96,10 +96,48 @@ StringArray FormatASS2::GetWriteExtensions() const
float FormatASSFamily::CanReadFile(Reader &reader) const
{
shared_ptr<TextReader> file = reader.GetTextReader();
if (!file->HasMoreLines()) return 0;
// Check header
if (!file->HasMoreLines()) return 0.0f;
String line = file->ReadLineFromFile();
if (line == "[Script Info]") return 1;
return 0;
line.AsciiMakeLower();
if (line != "[script info]") return 0.0f;
float version = 0.0f;
float sections = 0.25f;
String section = line;
while (file->HasMoreLines()) {
// Get line
line = file->ReadLineFromFile();
line.AsciiMakeLower();
// Set section
if (line[0] == '[' && line[line.Length()-1] == ']') section = line;
// Check version
if (section == "[script info]") {
if (line.StartsWith("ScriptType")) {
int formatVersion = GetVersion();
String expected = "";
switch (formatVersion) {
case 0: expected = "v4.00"; break;
case 1: expected = "v4.00+"; break;
case 2: expected = "v4.00++"; break;
}
if (line.EndsWith(expected)) version = 0.5f;
else version = 0.25f;
}
}
// Done when events begin
if (section == "[events]") {
sections += 0.25f;
break;
}
}
// OK
return sections+version;
}

View file

@ -68,6 +68,9 @@ namespace Athenasub {
// Advanced Substation Alpha format base class
class FormatASSFamily : public IFormat {
protected:
virtual int GetVersion() const = 0;
public:
virtual ~FormatASSFamily() {}
@ -98,6 +101,7 @@ namespace Athenasub {
String GetName() const { return "Substation Alpha"; }
StringArray GetReadExtensions() const;
StringArray GetWriteExtensions() const;
int GetVersion() const { return 0; }
};
// Advanced Substation Alpha
@ -107,6 +111,7 @@ namespace Athenasub {
String GetName() const { return "Advanced Substation Alpha"; }
StringArray GetReadExtensions() const;
StringArray GetWriteExtensions() const;
int GetVersion() const { return 1; }
};
// Advanced Substation Alpha 2
@ -116,6 +121,7 @@ namespace Athenasub {
String GetName() const { return "Advanced Substation Alpha 2"; }
StringArray GetReadExtensions() const;
StringArray GetWriteExtensions() const;
int GetVersion() const { return 2; }
};
}