MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / extractFile

Method extractFile

lib/QuaZip/quazip/JlCompress.cpp:148–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148bool JlCompress::extractFile(QuaZip* zip, QString fileName, QString fileDest) {
149 // zip: object where to add the file
150 // filename: real file name
151 // fileincompress: file name of the compressed file
152
153 if (!zip) return false;
154 if (zip->getMode()!=QuaZip::mdUnzip) return false;
155
156 if (!fileName.isEmpty())
157 zip->setCurrentFile(fileName);
158 QuaZipFile inFile(zip);
159 if(!inFile.open(QIODevice::ReadOnly) || inFile.getZipError()!=UNZ_OK) return false;
160
161 // Check existence of resulting file
162 QDir curDir;
163 if (fileDest.endsWith(QLatin1String("/"))) {
164 if (!curDir.mkpath(fileDest)) {
165 return false;
166 }
167 } else {
168 if (!curDir.mkpath(QFileInfo(fileDest).absolutePath())) {
169 return false;
170 }
171 }
172
173 QuaZipFileInfo64 info;
174 if (!zip->getCurrentFileInfo(&info))
175 return false;
176
177 QFile::Permissions srcPerm = info.getPermissions();
178 if (fileDest.endsWith(QLatin1String("/")) && QFileInfo(fileDest).isDir()) {
179 if (srcPerm != 0) {
180 QFile(fileDest).setPermissions(srcPerm);
181 }
182 return true;
183 }
184
185 if (info.isSymbolicLink()) {
186 QString target = QFile::decodeName(inFile.readAll());
187 return QFile::link(target, fileDest);
188 }
189
190 // Open resulting file
191 QFile outFile;
192 outFile.setFileName(fileDest);
193 if(!outFile.open(QIODevice::WriteOnly)) return false;
194
195 // Copy data
196 if (!copyData(inFile, outFile) || inFile.getZipError()!=UNZ_OK) {
197 outFile.close();
198 removeFile(QStringList(fileDest));
199 return false;
200 }
201 outFile.close();
202
203 // Close file
204 inFile.close();
205 if (inFile.getZipError()!=UNZ_OK) {

Callers

nothing calls this directly

Calls 12

QFileClass · 0.85
getModeMethod · 0.80
isEmptyMethod · 0.80
setCurrentFileMethod · 0.80
getCurrentFileInfoMethod · 0.80
getPermissionsMethod · 0.80
setPermissionsMethod · 0.80
isSymbolicLinkMethod · 0.80
openMethod · 0.45
getZipErrorMethod · 0.45
setFileNameMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected