Mercurial > hg > svcore
diff data/fileio/BZipFileDevice.cpp @ 1348:b3cb0edc25cd 3.0-integration
Update WAV/MP3/BZipFileDevice code to avoid using local 8-bit encoding
author | Chris Cannam |
---|---|
date | Fri, 06 Jan 2017 16:40:11 +0000 |
parents | cc27f35aa75c |
children | ce08318aad83 |
line wrap: on
line diff
--- a/data/fileio/BZipFileDevice.cpp Fri Jan 06 15:53:02 2017 +0000 +++ b/data/fileio/BZipFileDevice.cpp Fri Jan 06 16:40:11 2017 +0000 @@ -23,6 +23,7 @@ BZipFileDevice::BZipFileDevice(QString fileName) : m_fileName(fileName), + m_qfile(fileName), m_file(0), m_bzFile(0), m_atEnd(true), @@ -72,9 +73,16 @@ if (mode & WriteOnly) { - m_file = fopen(m_fileName.toLocal8Bit().data(), "wb"); + if (!m_qfile.open(QIODevice::WriteOnly)) { + setErrorString(tr("Failed to open file for writing")); + m_ok = false; + return false; + } + + m_file = fdopen(m_qfile.handle(), "wb"); if (!m_file) { - setErrorString(tr("Failed to open file for writing")); + setErrorString(tr("Failed to open file handle for writing")); + m_qfile.close(); m_ok = false; return false; } @@ -85,6 +93,7 @@ if (!m_bzFile) { fclose(m_file); m_file = 0; + m_qfile.close(); setErrorString(tr("Failed to open bzip2 stream for writing")); m_ok = false; return false; @@ -99,9 +108,15 @@ if (mode & ReadOnly) { - m_file = fopen(m_fileName.toLocal8Bit().data(), "rb"); + if (!m_qfile.open(QIODevice::ReadOnly)) { + setErrorString(tr("Failed to open file for reading")); + m_ok = false; + return false; + } + + m_file = fdopen(m_qfile.handle(), "rb"); if (!m_file) { - setErrorString(tr("Failed to open file for reading")); + setErrorString(tr("Failed to open file handle for reading")); m_ok = false; return false; } @@ -112,6 +127,7 @@ if (!m_bzFile) { fclose(m_file); m_file = 0; + m_qfile.close(); setErrorString(tr("Failed to open bzip2 stream for reading")); m_ok = false; return false; @@ -150,6 +166,7 @@ setErrorString(tr("bzip2 stream write close error")); } fclose(m_file); + m_qfile.close(); m_bzFile = 0; m_file = 0; m_ok = false; @@ -162,6 +179,7 @@ setErrorString(tr("bzip2 stream read close error")); } fclose(m_file); + m_qfile.close(); m_bzFile = 0; m_file = 0; m_ok = false;