mirror of https://github.com/odrling/Aegisub
Fixed loading of subtitles from Matroska files.
Originally committed to SVN as r1033.
This commit is contained in:
parent
716539b54a
commit
d3836e350f
|
@ -556,8 +556,7 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
|
||||||
if (!fileCheck.FileExists()) throw _T("File does not exist.");
|
if (!fileCheck.FileExists()) throw _T("File does not exist.");
|
||||||
|
|
||||||
// Make sure that file isn't actually a timecode file
|
// Make sure that file isn't actually a timecode file
|
||||||
TextFileReader testSubs(filename,charset);
|
TextFileReader testSubs(filename);
|
||||||
charset = testSubs.GetCurrentEncoding();
|
|
||||||
if (testSubs.HasMoreLines()) {
|
if (testSubs.HasMoreLines()) {
|
||||||
wxString cur = testSubs.ReadLineFromFile();
|
wxString cur = testSubs.ReadLineFromFile();
|
||||||
if (cur.Left(10) == _T("# timecode")) {
|
if (cur.Left(10) == _T("# timecode")) {
|
||||||
|
|
|
@ -354,7 +354,8 @@ void MatroskaWrapper::GetSubtitles(AssFile *target) {
|
||||||
// Load into file
|
// Load into file
|
||||||
wxString group = _T("[Script Info]");
|
wxString group = _T("[Script Info]");
|
||||||
int lasttime = 0;
|
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);
|
wxStringTokenizer token(privString,_T("\r\n"),wxTOKEN_STRTOK);
|
||||||
while (token.HasMoreTokens()) {
|
while (token.HasMoreTokens()) {
|
||||||
wxString next = token.GetNextToken();
|
wxString next = token.GetNextToken();
|
||||||
|
|
|
@ -118,6 +118,12 @@ wxString TextFileReader::GetEncoding(const wxString _filename) {
|
||||||
ifile.close();
|
ifile.close();
|
||||||
#endif
|
#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
|
// Try to get the byte order mark from them
|
||||||
if (b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF) return _T("UTF-8");
|
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");
|
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
|
// Checks if there's more to read
|
||||||
bool TextFileReader::HasMoreLines() {
|
bool TextFileReader::HasMoreLines() {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
if (encoding == _T("binary")) return false;
|
||||||
return !feof(file);
|
return !feof(file);
|
||||||
#else
|
#else
|
||||||
return (!file.eof());
|
return (!file.eof());
|
||||||
|
|
Loading…
Reference in New Issue