Mercurial > hg > svcore
comparison 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 |
comparison
equal
deleted
inserted
replaced
1347:281a8c9d4886 | 1348:b3cb0edc25cd |
---|---|
21 | 21 |
22 #include "base/Debug.h" | 22 #include "base/Debug.h" |
23 | 23 |
24 BZipFileDevice::BZipFileDevice(QString fileName) : | 24 BZipFileDevice::BZipFileDevice(QString fileName) : |
25 m_fileName(fileName), | 25 m_fileName(fileName), |
26 m_qfile(fileName), | |
26 m_file(0), | 27 m_file(0), |
27 m_bzFile(0), | 28 m_bzFile(0), |
28 m_atEnd(true), | 29 m_atEnd(true), |
29 m_ok(true) | 30 m_ok(true) |
30 { | 31 { |
70 return false; | 71 return false; |
71 } | 72 } |
72 | 73 |
73 if (mode & WriteOnly) { | 74 if (mode & WriteOnly) { |
74 | 75 |
75 m_file = fopen(m_fileName.toLocal8Bit().data(), "wb"); | 76 if (!m_qfile.open(QIODevice::WriteOnly)) { |
77 setErrorString(tr("Failed to open file for writing")); | |
78 m_ok = false; | |
79 return false; | |
80 } | |
81 | |
82 m_file = fdopen(m_qfile.handle(), "wb"); | |
76 if (!m_file) { | 83 if (!m_file) { |
77 setErrorString(tr("Failed to open file for writing")); | 84 setErrorString(tr("Failed to open file handle for writing")); |
85 m_qfile.close(); | |
78 m_ok = false; | 86 m_ok = false; |
79 return false; | 87 return false; |
80 } | 88 } |
81 | 89 |
82 int bzError = BZ_OK; | 90 int bzError = BZ_OK; |
83 m_bzFile = BZ2_bzWriteOpen(&bzError, m_file, 9, 0, 0); | 91 m_bzFile = BZ2_bzWriteOpen(&bzError, m_file, 9, 0, 0); |
84 | 92 |
85 if (!m_bzFile) { | 93 if (!m_bzFile) { |
86 fclose(m_file); | 94 fclose(m_file); |
87 m_file = 0; | 95 m_file = 0; |
96 m_qfile.close(); | |
88 setErrorString(tr("Failed to open bzip2 stream for writing")); | 97 setErrorString(tr("Failed to open bzip2 stream for writing")); |
89 m_ok = false; | 98 m_ok = false; |
90 return false; | 99 return false; |
91 } | 100 } |
92 | 101 |
97 return true; | 106 return true; |
98 } | 107 } |
99 | 108 |
100 if (mode & ReadOnly) { | 109 if (mode & ReadOnly) { |
101 | 110 |
102 m_file = fopen(m_fileName.toLocal8Bit().data(), "rb"); | 111 if (!m_qfile.open(QIODevice::ReadOnly)) { |
112 setErrorString(tr("Failed to open file for reading")); | |
113 m_ok = false; | |
114 return false; | |
115 } | |
116 | |
117 m_file = fdopen(m_qfile.handle(), "rb"); | |
103 if (!m_file) { | 118 if (!m_file) { |
104 setErrorString(tr("Failed to open file for reading")); | 119 setErrorString(tr("Failed to open file handle for reading")); |
105 m_ok = false; | 120 m_ok = false; |
106 return false; | 121 return false; |
107 } | 122 } |
108 | 123 |
109 int bzError = BZ_OK; | 124 int bzError = BZ_OK; |
110 m_bzFile = BZ2_bzReadOpen(&bzError, m_file, 0, 0, NULL, 0); | 125 m_bzFile = BZ2_bzReadOpen(&bzError, m_file, 0, 0, NULL, 0); |
111 | 126 |
112 if (!m_bzFile) { | 127 if (!m_bzFile) { |
113 fclose(m_file); | 128 fclose(m_file); |
114 m_file = 0; | 129 m_file = 0; |
130 m_qfile.close(); | |
115 setErrorString(tr("Failed to open bzip2 stream for reading")); | 131 setErrorString(tr("Failed to open bzip2 stream for reading")); |
116 m_ok = false; | 132 m_ok = false; |
117 return false; | 133 return false; |
118 } | 134 } |
119 | 135 |
148 // cerr << "Wrote bzip2 stream (in=" << in << ", out=" << out << ")" << endl; | 164 // cerr << "Wrote bzip2 stream (in=" << in << ", out=" << out << ")" << endl; |
149 if (bzError != BZ_OK) { | 165 if (bzError != BZ_OK) { |
150 setErrorString(tr("bzip2 stream write close error")); | 166 setErrorString(tr("bzip2 stream write close error")); |
151 } | 167 } |
152 fclose(m_file); | 168 fclose(m_file); |
169 m_qfile.close(); | |
153 m_bzFile = 0; | 170 m_bzFile = 0; |
154 m_file = 0; | 171 m_file = 0; |
155 m_ok = false; | 172 m_ok = false; |
156 return; | 173 return; |
157 } | 174 } |
160 BZ2_bzReadClose(&bzError, m_bzFile); | 177 BZ2_bzReadClose(&bzError, m_bzFile); |
161 if (bzError != BZ_OK) { | 178 if (bzError != BZ_OK) { |
162 setErrorString(tr("bzip2 stream read close error")); | 179 setErrorString(tr("bzip2 stream read close error")); |
163 } | 180 } |
164 fclose(m_file); | 181 fclose(m_file); |
182 m_qfile.close(); | |
165 m_bzFile = 0; | 183 m_bzFile = 0; |
166 m_file = 0; | 184 m_file = 0; |
167 m_ok = false; | 185 m_ok = false; |
168 return; | 186 return; |
169 } | 187 } |