diff --git a/aegisub/frame_main.cpp b/aegisub/frame_main.cpp index 10dbf1bce..dc6507d50 100644 --- a/aegisub/frame_main.cpp +++ b/aegisub/frame_main.cpp @@ -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")) { diff --git a/aegisub/mkv_wrap.cpp b/aegisub/mkv_wrap.cpp index 4358060a8..eeb6a1fe3 100644 --- a/aegisub/mkv_wrap.cpp +++ b/aegisub/mkv_wrap.cpp @@ -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(); diff --git a/aegisub/text_file_reader.cpp b/aegisub/text_file_reader.cpp index deededde7..f24330abe 100644 --- a/aegisub/text_file_reader.cpp +++ b/aegisub/text_file_reader.cpp @@ -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());