Fixed loading of subtitles from Matroska files.

Originally committed to SVN as r1033.
This commit is contained in:
Rodrigo Braz Monteiro 2007-04-08 21:20:32 +00:00
parent 716539b54a
commit d3836e350f
3 changed files with 10 additions and 3 deletions

View File

@ -556,8 +556,7 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
if (!fileCheck.FileExists()) throw _T("File does not exist.");
// Make sure that file isn't actually a timecode file
TextFileReader testSubs(filename,charset);
charset = testSubs.GetCurrentEncoding();
TextFileReader testSubs(filename);
if (testSubs.HasMoreLines()) {
wxString cur = testSubs.ReadLineFromFile();
if (cur.Left(10) == _T("# timecode")) {

View File

@ -354,7 +354,8 @@ void MatroskaWrapper::GetSubtitles(AssFile *target) {
// Load into file
wxString group = _T("[Script Info]");
int lasttime = 0;
int version = (CodecID == _T("S_TEXT/SSA"));
int version = 1;
if (CodecID == _T("S_TEXT/SSA")) version = 0;
wxStringTokenizer token(privString,_T("\r\n"),wxTOKEN_STRTOK);
while (token.HasMoreTokens()) {
wxString next = token.GetNextToken();

View File

@ -118,6 +118,12 @@ wxString TextFileReader::GetEncoding(const wxString _filename) {
ifile.close();
#endif
// If any of the first four bytes are under 0x20 (the first printable character),
// except for 9-13 range, assume binary
for (int i=0;i<4;i++) {
if (b[i] < 9 || (b[i] > 13 && b[i] < 32)) return _T("binary");
}
// Try to get the byte order mark from them
if (b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF) return _T("UTF-8");
else if (b[0] == 0xFF && b[1] == 0xFE && b[2] == 0x00 && b[3] == 0x00) return _T("UTF-32LE");
@ -299,6 +305,7 @@ void TextFileReader::Close() {
// Checks if there's more to read
bool TextFileReader::HasMoreLines() {
#ifdef WIN32
if (encoding == _T("binary")) return false;
return !feof(file);
#else
return (!file.eof());