Skip to content

Commit

Permalink
Fix regression regarding handling subtitle text encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
clsid2 committed Feb 10, 2021
1 parent 4aa0ed0 commit 7ba4872
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/Subtitles/TextFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CTextFile::CTextFile(enc e)
: m_encoding(e)
, m_defaultencoding(e)
, m_fallbackencoding(DEFAULT_ENCODING)
, m_offset(0)
, m_posInFile(0)
, m_posInBuffer(0)
Expand Down Expand Up @@ -128,6 +129,11 @@ void CTextFile::SetEncoding(enc e)
m_encoding = e;
}

void CTextFile::SetFallbackEncoding(enc e)
{
m_fallbackencoding = e;
}

CTextFile::enc CTextFile::GetEncoding()
{
return m_encoding;
Expand Down Expand Up @@ -410,9 +416,8 @@ BOOL CTextFile::ReadString(CStringA& str)
}
}
} else {
TRACE(_T("Fallback to ANSI encoding\n"));
// Switch to text and read again
m_encoding = ANSI;
m_encoding = m_fallbackencoding;
// Stop using the buffer
m_posInBuffer = m_nInBuffer = 0;

Expand Down Expand Up @@ -629,9 +634,8 @@ BOOL CTextFile::ReadString(CStringW& str)
}
}
} else {
TRACE(_T("Fallback to ANSI encoding\n"));
// Switch to text and read again
m_encoding = ANSI;
m_encoding = m_fallbackencoding;
// Stop using the buffer
m_posInBuffer = m_nInBuffer = 0;

Expand Down
3 changes: 2 additions & 1 deletion src/Subtitles/TextFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CTextFile : protected CStdioFile64
};

private:
enc m_encoding, m_defaultencoding;
enc m_encoding, m_defaultencoding, m_fallbackencoding;
int m_offset;
ULONGLONG m_posInFile;
CAutoVectorPtr<char> m_buffer;
Expand All @@ -49,6 +49,7 @@ class CTextFile : protected CStdioFile64
virtual bool Save(LPCTSTR lpszFileName, enc e /*= DEFAULT_ENCODING*/);

void SetEncoding(enc e);
void SetFallbackEncoding(enc e);
enc GetEncoding();
bool IsUnicode();

Expand Down
1 change: 1 addition & 0 deletions src/mpc-hc/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12411,6 +12411,7 @@ void CMainFrame::SetupCueChapters(CString fn) {
CPlaylistItem* pli = m_wndPlaylistBar.GetCur();

CWebTextFile f(CTextFile::UTF8);
f.SetFallbackEncoding(CTextFile::ANSI);
if (!f.Open(fn) || !f.ReadString(str)) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions src/mpc-hc/PlayerPlaylistBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ bool CPlayerPlaylistBar::ParseCUESheet(CString fn) {
int cue_index(0);

CWebTextFile f(CTextFile::UTF8);
f.SetFallbackEncoding(CTextFile::ANSI);
if (!f.Open(fn) || !f.ReadString(str)) {
return false;
}
Expand Down Expand Up @@ -576,6 +577,7 @@ bool CPlayerPlaylistBar::ParseM3UPlayList(CString fn) {
std::vector<int> idx;

CWebTextFile f(CTextFile::UTF8);
f.SetFallbackEncoding(CTextFile::ANSI);
if (!f.Open(fn) || !f.ReadString(str)) {
return false;
}
Expand Down Expand Up @@ -675,6 +677,7 @@ bool CPlayerPlaylistBar::ParseMPCPlayList(CString fn)
std::vector<int> idx;

CWebTextFile f(CTextFile::UTF8);
f.SetFallbackEncoding(CTextFile::ANSI);
if (!f.Open(fn) || !f.ReadString(str) || str != _T("MPCPLAYLIST")) {
return false;
}
Expand Down

0 comments on commit 7ba4872

Please sign in to comment.