Changeset View
Changeset View
Standalone View
Standalone View
krusader/VFS/krarchandler.cpp
Context not available. | |||||
128 | KConfigGroup group(krConfig, "Archives"); | 128 | KConfigGroup group(krConfig, "Archives"); | ||
---|---|---|---|---|---|
129 | QStringList lst = group.readEntry("Supported Packers", QStringList()); | 129 | QStringList lst = group.readEntry("Supported Packers", QStringList()); | ||
130 | 130 | | |||
131 | // Normalize the type of the file | 131 | // Let's notice that in some cases the QString `type` that arrives here | ||
132 | if (type.length() > 4) { | 132 | // represents a mimetype, and in some other cases it represents | ||
133 | // 7zip files are a not a normal case because their mimetype does not | 133 | // a short identifier. | ||
134 | // follow the norm of other types: zip, tar, lha, ace, arj, etc. | 134 | // If `type` is not a short identifier then it's supposed that `type` is a mime type | ||
135 | if (type == "application/x-7z-compressed") | 135 | if (type.length() > maxLenType) { | ||
136 | type = "-7z"; | 136 | type = getShortTypeFromMime(type); | ||
137 | else | | |||
138 | // If it's a rar file but its mimetype isn't "application/x-rar" | | |||
139 | if (type == "application/x-rar-compressed") | | |||
140 | type = "-rar"; | | |||
141 | else | | |||
142 | type = type.right(4); | | |||
143 | } | 137 | } | ||
144 | 138 | | |||
145 | if ((type == "-zip" || type == "/zip") && lst.contains("unzip")) | 139 | if ((type == "zip" || type == "/zip") && lst.contains("unzip")) | ||
146 | return true; | 140 | return true; | ||
147 | else if (type == "-tar" && lst.contains("tar")) | 141 | else if (type == "tar" && lst.contains("tar")) | ||
148 | return true; | 142 | return true; | ||
149 | else if (type == "-tbz" && lst.contains("tar")) | 143 | else if (type == "tbz" && lst.contains("tar")) | ||
150 | return true; | 144 | return true; | ||
151 | else if (type == "-tgz" && lst.contains("tar")) | 145 | else if (type == "tgz" && lst.contains("tar")) | ||
152 | return true; | 146 | return true; | ||
153 | else if (type == "-tlz" && lst.contains("tar")) | 147 | else if (type == "tlz" && lst.contains("tar")) | ||
154 | return true; | 148 | return true; | ||
155 | else if (type == "-txz" && lst.contains("tar")) | 149 | else if (type == "txz" && lst.contains("tar")) | ||
156 | return true; | 150 | return true; | ||
157 | else if (type == "tarz" && lst.contains("tar")) | 151 | else if (type == "tarz" && lst.contains("tar")) | ||
158 | return true; | 152 | return true; | ||
159 | else if (type == "gzip" && lst.contains("gzip")) | 153 | else if (type == "gzip" && lst.contains("gzip")) | ||
160 | return true; | 154 | return true; | ||
161 | else if (type == "zip2" && lst.contains("bzip2")) | 155 | else if (type == "bzip2" && lst.contains("bzip2")) | ||
162 | return true; | 156 | return true; | ||
163 | else if (type == "lzma" && lst.contains("lzma")) | 157 | else if (type == "lzma" && lst.contains("lzma")) | ||
164 | return true; | 158 | return true; | ||
165 | else if (type == "-xz" && lst.contains("xz")) | 159 | else if (type == "xz" && lst.contains("xz")) | ||
166 | return true; | 160 | return true; | ||
167 | else if (type == "-lha" && lst.contains("lha")) | 161 | else if (type == "lha" && lst.contains("lha")) | ||
168 | return true; | 162 | return true; | ||
169 | else if (type == "-ace" && lst.contains("unace")) | 163 | else if (type == "ace" && lst.contains("unace")) | ||
170 | return true; | 164 | return true; | ||
171 | else if (type == "-rpm" && lst.contains("cpio")) | 165 | else if (type == "rpm" && lst.contains("cpio")) | ||
172 | return true; | 166 | return true; | ||
173 | else if (type == "cpio" && lst.contains("cpio")) | 167 | else if (type == "cpio" && lst.contains("cpio")) | ||
174 | return true; | 168 | return true; | ||
175 | else if (type == "-rar" && (lst.contains("unrar") || lst.contains("rar"))) | 169 | else if (type == "rar" && (lst.contains("unrar") || lst.contains("rar"))) | ||
176 | return true; | 170 | return true; | ||
177 | else if (type == "-arj" && (lst.contains("unarj") || lst.contains("arj"))) | 171 | else if (type == "arj" && (lst.contains("unarj") || lst.contains("arj"))) | ||
178 | return true; | 172 | return true; | ||
179 | else if (type == "-deb" && (lst.contains("dpkg") && lst.contains("tar"))) | 173 | else if (type == "deb" && (lst.contains("dpkg") && lst.contains("tar"))) | ||
180 | return true; | 174 | return true; | ||
181 | else if (type == "-7z" && lst.contains("7z")) | 175 | else if (type == "7z" && lst.contains("7z")) | ||
182 | return true; | 176 | return true; | ||
183 | // not supported : ( | 177 | // not supported | ||
184 | return false; | 178 | return false; | ||
185 | } | 179 | } | ||
186 | 180 | | |||
Context not available. | |||||
189 | int divideWith = 1; | 183 | int divideWith = 1; | ||
190 | 184 | | |||
191 | // first check if supported | 185 | // first check if supported | ||
192 | if (!arcSupported(type)) return 0; | 186 | if (!arcSupported(type)) | ||
187 | return 0; | ||||
193 | 188 | | |||
194 | // bzip an gzip archive contains only one file | 189 | // bzip2, gzip, etc. archives contain only one file | ||
195 | if (type == "zip2" || type == "gzip" || type == "lzma" || type == "-xz") return 1L; | 190 | if (type == "bzip2" || type == "gzip" || type == "lzma" || type == "xz") | ||
191 | return 1L; | ||||
196 | 192 | | |||
197 | // set the right lister to do the job | 193 | // set the right lister to do the job | ||
198 | QStringList lister; | 194 | QStringList lister; | ||
199 | 195 | | |||
200 | if (type == "-zip") lister << KrServices::fullPathName("unzip") << "-ZTs"; | 196 | if (type == "zip") lister << KrServices::fullPathName("unzip") << "-ZTs"; | ||
201 | else if (type == "-tar") lister << KrServices::fullPathName("tar") << "-tvf"; | 197 | else if (type == "tar") lister << KrServices::fullPathName("tar") << "-tvf"; | ||
202 | else if (type == "-tgz") lister << KrServices::fullPathName("tar") << "-tvzf"; | 198 | else if (type == "tgz") lister << KrServices::fullPathName("tar") << "-tvzf"; | ||
203 | else if (type == "tarz") lister << KrServices::fullPathName("tar") << "-tvzf"; | 199 | else if (type == "tarz") lister << KrServices::fullPathName("tar") << "-tvzf"; | ||
204 | else if (type == "-tbz") lister << KrServices::fullPathName("tar") << "-tjvf"; | 200 | else if (type == "tbz") lister << KrServices::fullPathName("tar") << "-tjvf"; | ||
205 | else if (type == "-tlz") lister << KrServices::fullPathName("tar") << "--lzma" << "-tvf"; | 201 | else if (type == "tlz") lister << KrServices::fullPathName("tar") << "--lzma" << "-tvf"; | ||
206 | else if (type == "-txz") lister << KrServices::fullPathName("tar") << "--xz" << "-tvf"; | 202 | else if (type == "txz") lister << KrServices::fullPathName("tar") << "--xz" << "-tvf"; | ||
207 | else if (type == "-lha") lister << KrServices::fullPathName("lha") << "l"; | 203 | else if (type == "lha") lister << KrServices::fullPathName("lha") << "l"; | ||
208 | else if (type == "-rar") lister << KrServices::fullPathName(KrServices::cmdExist("rar") ? "rar" : "unrar") << "l" << "-v"; | 204 | else if (type == "rar") lister << KrServices::fullPathName(KrServices::cmdExist("rar") ? "rar" : "unrar") << "l" << "-v"; | ||
209 | else if (type == "-ace") lister << KrServices::fullPathName("unace") << "l"; | 205 | else if (type == "ace") lister << KrServices::fullPathName("unace") << "l"; | ||
210 | else if (type == "-arj") { | 206 | else if (type == "arj") { | ||
211 | if (KrServices::cmdExist("arj")) | 207 | if (KrServices::cmdExist("arj")) | ||
212 | lister << KrServices::fullPathName("arj") << "v" << "-y" << "-v", | 208 | lister << KrServices::fullPathName("arj") << "v" << "-y" << "-v", | ||
213 | divideWith = 4; | 209 | divideWith = 4; | ||
214 | else | 210 | else | ||
215 | lister << KrServices::fullPathName("unarj") << "l"; | 211 | lister << KrServices::fullPathName("unarj") << "l"; | ||
216 | } else if (type == "-rpm") lister << KrServices::fullPathName("rpm") << "--dump" << "-lpq"; | 212 | } else if (type == "rpm") lister << KrServices::fullPathName("rpm") << "--dump" << "-lpq"; | ||
217 | else if (type == "-deb") lister << KrServices::fullPathName("dpkg") << "-c"; | 213 | else if (type == "deb") lister << KrServices::fullPathName("dpkg") << "-c"; | ||
218 | else if (type == "-7z") lister << KrServices::fullPathName("7z") << "-y" << "l"; | 214 | else if (type == "7z") lister << KrServices::fullPathName("7z") << "-y" << "l"; | ||
219 | else return 0L; | 215 | else return 0L; | ||
220 | 216 | | |||
221 | if (!password.isNull()) { | 217 | if (!password.isNull()) { | ||
222 | if (type == "-arj") | 218 | if (type == "arj") | ||
223 | lister << QString("-g%1").arg(password); | 219 | lister << QString("-g%1").arg(password); | ||
224 | if (type == "-ace" || type == "-rar" || type == "-7z") | 220 | if (type == "ace" || type == "rar" || type == "7z") | ||
225 | lister << QString("-p%1").arg(password); | 221 | lister << QString("-p%1").arg(password); | ||
226 | } | 222 | } | ||
227 | 223 | | |||
Context not available. | |||||
232 | long count = 1; | 228 | long count = 1; | ||
233 | KProcess list; | 229 | KProcess list; | ||
234 | list << lister << archive; | 230 | list << lister << archive; | ||
235 | if (type == "-ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | 231 | if (type == "ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | ||
236 | list.setStandardInputFile("/dev/ptmx"); | 232 | list.setStandardInputFile("/dev/ptmx"); | ||
237 | list.setOutputChannelMode(KProcess::SeparateChannels); // without this output redirection has no effect | 233 | list.setOutputChannelMode(KProcess::SeparateChannels); // without this output redirection has no effect | ||
238 | list.start(); | 234 | list.start(); | ||
Context not available. | |||||
266 | KConfigGroup group(krConfig, "Archives"); | 262 | KConfigGroup group(krConfig, "Archives"); | ||
267 | if (group.readEntry("Test Before Unpack", _TestBeforeUnpack)) { | 263 | if (group.readEntry("Test Before Unpack", _TestBeforeUnpack)) { | ||
268 | // test first - or be sorry later... | 264 | // test first - or be sorry later... | ||
269 | if (type != "-rpm" && type != "-deb" && !test(archive, type, password, observer, 0)) { | 265 | if (type != "rpm" && type != "deb" && !test(archive, type, password, observer, 0)) { | ||
270 | observer->error(i18n("Failed to unpack %1.", archive)); | 266 | observer->error(i18n("Failed to unpack %1.", archive)); | ||
271 | return false; | 267 | return false; | ||
272 | } | 268 | } | ||
Context not available. | |||||
274 | 270 | | |||
275 | // count the files in the archive | 271 | // count the files in the archive | ||
276 | long count = arcFileCount(archive, type, password, observer); | 272 | long count = arcFileCount(archive, type, password, observer); | ||
277 | if (count == 0) return false; // not supported | 273 | if (count == 0) | ||
278 | if (count == 1) count = 0 ; | 274 | return false; // not supported | ||
275 | if (count == 1) | ||||
276 | count = 0; | ||||
279 | 277 | | |||
280 | // choose the right packer for the job | 278 | // choose the right packer for the job | ||
281 | QString cpioName; | 279 | QString cpioName; | ||
282 | QStringList packer; | 280 | QStringList packer; | ||
283 | 281 | | |||
284 | // set the right packer to do the job | 282 | // set the right packer to do the job | ||
285 | if (type == "-zip") packer << KrServices::fullPathName("unzip") << "-o" ; | 283 | if (type == "zip") packer << KrServices::fullPathName("unzip") << "-o" ; | ||
286 | else if (type == "-tar") packer << KrServices::fullPathName("tar") << "-xvf"; | 284 | else if (type == "tar") packer << KrServices::fullPathName("tar") << "-xvf"; | ||
287 | else if (type == "-tgz") packer << KrServices::fullPathName("tar") << "-xvzf"; | 285 | else if (type == "tgz") packer << KrServices::fullPathName("tar") << "-xvzf"; | ||
288 | else if (type == "tarz") packer << KrServices::fullPathName("tar") << "-xvzf"; | 286 | else if (type == "tarz") packer << KrServices::fullPathName("tar") << "-xvzf"; | ||
289 | else if (type == "-tbz") packer << KrServices::fullPathName("tar") << "-xjvf"; | 287 | else if (type == "tbz") packer << KrServices::fullPathName("tar") << "-xjvf"; | ||
290 | else if (type == "-tlz") packer << KrServices::fullPathName("tar") << "--lzma" << "-xvf"; | 288 | else if (type == "tlz") packer << KrServices::fullPathName("tar") << "--lzma" << "-xvf"; | ||
291 | else if (type == "-txz") packer << KrServices::fullPathName("tar") << "--xz" << "-xvf"; | 289 | else if (type == "txz") packer << KrServices::fullPathName("tar") << "--xz" << "-xvf"; | ||
292 | else if (type == "gzip") packer << KrServices::fullPathName("gzip") << "-cd"; | 290 | else if (type == "gzip") packer << KrServices::fullPathName("gzip") << "-cd"; | ||
293 | else if (type == "zip2") packer << KrServices::fullPathName("bzip2") << "-cdk"; | 291 | else if (type == "bzip2") packer << KrServices::fullPathName("bzip2") << "-cdk"; | ||
294 | else if (type == "lzma") packer << KrServices::fullPathName("lzma") << "-cdk"; | 292 | else if (type == "lzma") packer << KrServices::fullPathName("lzma") << "-cdk"; | ||
295 | else if (type == "-xz") packer << KrServices::fullPathName("xz") << "-cdk"; | 293 | else if (type == "xz") packer << KrServices::fullPathName("xz") << "-cdk"; | ||
296 | else if (type == "-lha") packer << KrServices::fullPathName("lha") << "xf"; | 294 | else if (type == "lha") packer << KrServices::fullPathName("lha") << "xf"; | ||
297 | else if (type == "-rar") packer << KrServices::fullPathName(KrServices::cmdExist("rar") ? "rar" : "unrar") << "-y" << "x"; | 295 | else if (type == "rar") packer << KrServices::fullPathName(KrServices::cmdExist("rar") ? "rar" : "unrar") << "-y" << "x"; | ||
298 | else if (type == "-ace") packer << KrServices::fullPathName("unace") << "x"; | 296 | else if (type == "ace") packer << KrServices::fullPathName("unace") << "x"; | ||
299 | else if (type == "-arj") { | 297 | else if (type == "arj") { | ||
300 | if (KrServices::cmdExist("arj")) | 298 | if (KrServices::cmdExist("arj")) | ||
301 | packer << KrServices::fullPathName("arj") << "-y" << "-v" << "x"; | 299 | packer << KrServices::fullPathName("arj") << "-y" << "-v" << "x"; | ||
302 | else | 300 | else | ||
303 | packer << KrServices::fullPathName("unarj") << "x"; | 301 | packer << KrServices::fullPathName("unarj") << "x"; | ||
304 | } else if (type == "-7z") packer << KrServices::fullPathName("7z") << "-y" << "x"; | 302 | } else if (type == "7z") packer << KrServices::fullPathName("7z") << "-y" << "x"; | ||
305 | else if (type == "-rpm") { | 303 | else if (type == "rpm") { | ||
306 | // TODO use QTemporaryFile (setAutoRemove(false) when asynchrone) | 304 | // TODO use QTemporaryFile (setAutoRemove(false) when asynchrone) | ||
307 | cpioName = QDir::tempPath() + QStringLiteral("/contents.cpio"); | 305 | cpioName = QDir::tempPath() + QStringLiteral("/contents.cpio"); | ||
308 | 306 | | |||
Context not available. | |||||
317 | 315 | | |||
318 | archive = cpioName; | 316 | archive = cpioName; | ||
319 | packer << KrServices::fullPathName("cpio") << "--force-local" << "--no-absolute-filenames" << "-iuvdF"; | 317 | packer << KrServices::fullPathName("cpio") << "--force-local" << "--no-absolute-filenames" << "-iuvdF"; | ||
320 | } else if (type == "-deb") { | 318 | } else if (type == "deb") { | ||
321 | // TODO use QTemporaryFile (setAutoRemove(false) when asynchrone) | 319 | // TODO use QTemporaryFile (setAutoRemove(false) when asynchrone) | ||
322 | cpioName = QDir::tempPath() + QStringLiteral("/contents.tar"); | 320 | cpioName = QDir::tempPath() + QStringLiteral("/contents.tar"); | ||
323 | 321 | | |||
Context not available. | |||||
325 | dpkg << KrServices::fullPathName("dpkg") << "--fsys-tarfile" << archive; | 323 | dpkg << KrServices::fullPathName("dpkg") << "--fsys-tarfile" << archive; | ||
326 | dpkg.setStandardOutputFile(cpioName); // TODO maybe no tmpfile but a pipe (setStandardOutputProcess(packer)) | 324 | dpkg.setStandardOutputFile(cpioName); // TODO maybe no tmpfile but a pipe (setStandardOutputProcess(packer)) | ||
327 | dpkg.start(); | 325 | dpkg.start(); | ||
328 | if (!dpkg.waitForFinished() || dpkg.exitStatus() != QProcess::NormalExit || !checkStatus("-deb", dpkg.exitCode())) { | 326 | if (!dpkg.waitForFinished() || dpkg.exitStatus() != QProcess::NormalExit || !checkStatus("deb", dpkg.exitCode())) { | ||
329 | observer->detailedError(i18n("Failed to convert deb (%1) to tar.", archive), dpkg.getErrorMsg()); | 327 | observer->detailedError(i18n("Failed to convert deb (%1) to tar.", archive), dpkg.getErrorMsg()); | ||
330 | return 0; | 328 | return 0; | ||
331 | } | 329 | } | ||
Context not available. | |||||
335 | } else return false; | 333 | } else return false; | ||
336 | 334 | | |||
337 | if (!password.isNull()) { | 335 | if (!password.isNull()) { | ||
338 | if (type == "-zip") | 336 | if (type == "zip") | ||
339 | packer << "-P" << password; | 337 | packer << "-P" << password; | ||
340 | if (type == "-arj") | 338 | if (type == "arj") | ||
341 | packer << QString("-g%1").arg(password); | 339 | packer << QString("-g%1").arg(password); | ||
342 | if (type == "-ace" || type == "-rar" || type == "-7z") | 340 | if (type == "ace" || type == "rar" || type == "7z") | ||
343 | packer << QString("-p%1").arg(password); | 341 | packer << QString("-p%1").arg(password); | ||
344 | } | 342 | } | ||
345 | 343 | | |||
346 | // unpack the files | 344 | // unpack the files | ||
347 | KrLinecountingProcess proc; | 345 | KrLinecountingProcess proc; | ||
348 | proc << packer << archive; | 346 | proc << packer << archive; | ||
349 | if (type == "zip2" || type == "gzip" || type == "lzma" || type == "-xz") { | 347 | if (type == "bzip2" || type == "gzip" || type == "lzma" || type == "xz") { | ||
350 | QString arcname = archive.mid(archive.lastIndexOf("/") + 1); | 348 | QString arcname = archive.mid(archive.lastIndexOf("/") + 1); | ||
351 | if (arcname.contains(".")) arcname = arcname.left(arcname.lastIndexOf(".")); | 349 | if (arcname.contains(".")) arcname = arcname.left(arcname.lastIndexOf(".")); | ||
352 | proc.setStandardOutputFile(dest + '/' + arcname); | 350 | proc.setStandardOutputFile(dest + '/' + arcname); | ||
353 | } | 351 | } | ||
354 | if (type == "-ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | 352 | if (type == "ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | ||
355 | proc.setStandardInputFile("/dev/ptmx"); | 353 | proc.setStandardInputFile("/dev/ptmx"); | ||
356 | 354 | | |||
357 | proc.setWorkingDirectory(dest); | 355 | proc.setWorkingDirectory(dest); | ||
Context not available. | |||||
361 | if (count != 0) { | 359 | if (count != 0) { | ||
362 | connect(&proc, SIGNAL(newOutputLines(int)), | 360 | connect(&proc, SIGNAL(newOutputLines(int)), | ||
363 | observer, SLOT(incrementProgress(int))); | 361 | observer, SLOT(incrementProgress(int))); | ||
364 | if (type == "-rpm") | 362 | if (type == "rpm") | ||
365 | connect(&proc, SIGNAL(newErrorLines(int)), | 363 | connect(&proc, SIGNAL(newErrorLines(int)), | ||
366 | observer, SLOT(incrementProgress(int))); | 364 | observer, SLOT(incrementProgress(int))); | ||
367 | } | 365 | } | ||
Context not available. | |||||
370 | proc.start(); | 368 | proc.start(); | ||
371 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | 369 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | ||
372 | // it would be better to connect to started(), error() and finished() | 370 | // it would be better to connect to started(), error() and finished() | ||
373 | if (proc.waitForStarted()) while (proc.state() == QProcess::Running) { | 371 | if (proc.waitForStarted()) | ||
372 | while (proc.state() == QProcess::Running) { | ||||
374 | observer->processEvents(); | 373 | observer->processEvents(); | ||
375 | if (observer->wasCancelled()) | 374 | if (observer->wasCancelled()) | ||
376 | proc.kill(); | 375 | proc.kill(); | ||
Context not available. | |||||
396 | QStringList packer; | 395 | QStringList packer; | ||
397 | 396 | | |||
398 | // set the right packer to do the job | 397 | // set the right packer to do the job | ||
399 | if (type == "-zip") packer << KrServices::fullPathName("unzip") << "-t"; | 398 | if (type == "zip") packer << KrServices::fullPathName("unzip") << "-t"; | ||
400 | else if (type == "-tar") packer << KrServices::fullPathName("tar") << "-tvf"; | 399 | else if (type == "tar") packer << KrServices::fullPathName("tar") << "-tvf"; | ||
401 | else if (type == "-tgz") packer << KrServices::fullPathName("tar") << "-tvzf"; | 400 | else if (type == "tgz") packer << KrServices::fullPathName("tar") << "-tvzf"; | ||
402 | else if (type == "tarz") packer << KrServices::fullPathName("tar") << "-tvzf"; | 401 | else if (type == "tarz") packer << KrServices::fullPathName("tar") << "-tvzf"; | ||
403 | else if (type == "-tbz") packer << KrServices::fullPathName("tar") << "-tjvf"; | 402 | else if (type == "tbz") packer << KrServices::fullPathName("tar") << "-tjvf"; | ||
404 | else if (type == "-tlz") packer << KrServices::fullPathName("tar") << "--lzma" << "-tvf"; | 403 | else if (type == "tlz") packer << KrServices::fullPathName("tar") << "--lzma" << "-tvf"; | ||
405 | else if (type == "-txz") packer << KrServices::fullPathName("tar") << "--xz" << "-tvf"; | 404 | else if (type == "txz") packer << KrServices::fullPathName("tar") << "--xz" << "-tvf"; | ||
406 | else if (type == "gzip") packer << KrServices::fullPathName("gzip") << "-tv"; | 405 | else if (type == "gzip") packer << KrServices::fullPathName("gzip") << "-tv"; | ||
407 | else if (type == "zip2") packer << KrServices::fullPathName("bzip2") << "-tv"; | 406 | else if (type == "bzip2") packer << KrServices::fullPathName("bzip2") << "-tv"; | ||
408 | else if (type == "lzma") packer << KrServices::fullPathName("lzma") << "-tv"; | 407 | else if (type == "lzma") packer << KrServices::fullPathName("lzma") << "-tv"; | ||
409 | else if (type == "-xz") packer << KrServices::fullPathName("xz") << "-tv"; | 408 | else if (type == "xz") packer << KrServices::fullPathName("xz") << "-tv"; | ||
410 | else if (type == "-rar") packer << KrServices::fullPathName(KrServices::cmdExist("rar") ? "rar" : "unrar") << "t"; | 409 | else if (type == "rar") packer << KrServices::fullPathName(KrServices::cmdExist("rar") ? "rar" : "unrar") << "t"; | ||
411 | else if (type == "-ace") packer << KrServices::fullPathName("unace") << "t"; | 410 | else if (type == "ace") packer << KrServices::fullPathName("unace") << "t"; | ||
412 | else if (type == "-lha") packer << KrServices::fullPathName("lha") << "t"; | 411 | else if (type == "lha") packer << KrServices::fullPathName("lha") << "t"; | ||
413 | else if (type == "-arj") packer << KrServices::fullPathName(KrServices::cmdExist("arj") ? "arj" : "unarj") << "t"; | 412 | else if (type == "arj") packer << KrServices::fullPathName(KrServices::cmdExist("arj") ? "arj" : "unarj") << "t"; | ||
414 | else if (type == "cpio") packer << KrServices::fullPathName("cpio") << "--only-verify-crc" << "-tvF"; | 413 | else if (type == "cpio") packer << KrServices::fullPathName("cpio") << "--only-verify-crc" << "-tvF"; | ||
415 | else if (type == "-7z") packer << KrServices::fullPathName("7z") << "-y" << "t"; | 414 | else if (type == "7z") packer << KrServices::fullPathName("7z") << "-y" << "t"; | ||
416 | else return false; | 415 | else return false; | ||
417 | 416 | | |||
418 | if (!password.isNull()) { | 417 | if (!password.isNull()) { | ||
419 | if (type == "-zip") | 418 | if (type == "zip") | ||
420 | packer << "-P" << password; | 419 | packer << "-P" << password; | ||
421 | if (type == "-arj") | 420 | if (type == "arj") | ||
422 | packer << QString("-g%1").arg(password); | 421 | packer << QString("-g%1").arg(password); | ||
423 | if (type == "-ace" || type == "-rar" || type == "-7z") | 422 | if (type == "ace" || type == "rar" || type == "7z") | ||
424 | packer << QString("-p%1").arg(password); | 423 | packer << QString("-p%1").arg(password); | ||
425 | } | 424 | } | ||
426 | 425 | | |||
Context not available. | |||||
428 | KrLinecountingProcess proc; | 427 | KrLinecountingProcess proc; | ||
429 | proc << packer << archive; | 428 | proc << packer << archive; | ||
430 | 429 | | |||
431 | if (type == "-ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | 430 | if (type == "ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | ||
432 | proc.setStandardInputFile("/dev/ptmx"); | 431 | proc.setStandardInputFile("/dev/ptmx"); | ||
433 | 432 | | |||
434 | // tell the user to wait | 433 | // tell the user to wait | ||
Context not available. | |||||
441 | proc.start(); | 440 | proc.start(); | ||
442 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | 441 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | ||
443 | // it would be better to connect to started(), error() and finished() | 442 | // it would be better to connect to started(), error() and finished() | ||
444 | if (proc.waitForStarted()) while (proc.state() == QProcess::Running) { | 443 | if (proc.waitForStarted()) | ||
444 | while (proc.state() == QProcess::Running) { | ||||
445 | observer->processEvents(); | 445 | observer->processEvents(); | ||
446 | if (observer->wasCancelled()) | 446 | if (observer->wasCancelled()) | ||
447 | proc.kill(); | 447 | proc.kill(); | ||
Context not available. | |||||
462 | QStringList packer; | 462 | QStringList packer; | ||
463 | 463 | | |||
464 | if (type == "zip") { | 464 | if (type == "zip") { | ||
465 | packer << KrServices::fullPathName("zip") << "-ry"; type = "-zip"; | 465 | packer << KrServices::fullPathName("zip") << "-ry"; | ||
466 | } else if (type == "cbz") { | 466 | } else if (type == "cbz") { | ||
467 | packer << KrServices::fullPathName("zip") << "-ry"; type = "-zip"; | 467 | packer << KrServices::fullPathName("zip") << "-ry"; | ||
468 | type = "zip"; | ||||
468 | } else if (type == "tar") { | 469 | } else if (type == "tar") { | ||
469 | packer << KrServices::fullPathName("tar") << "-cvf"; type = "-tar"; | 470 | packer << KrServices::fullPathName("tar") << "-cvf"; | ||
470 | } else if (type == "tar.gz") { | 471 | } else if (type == "tar.gz") { | ||
471 | packer << KrServices::fullPathName("tar") << "-cvzf"; type = "-tgz"; | 472 | packer << KrServices::fullPathName("tar") << "-cvzf"; | ||
473 | type = "tgz"; | ||||
472 | } else if (type == "tar.bz2") { | 474 | } else if (type == "tar.bz2") { | ||
473 | packer << KrServices::fullPathName("tar") << "-cvjf"; type = "-tbz"; | 475 | packer << KrServices::fullPathName("tar") << "-cvjf"; | ||
476 | type = "tbz"; | ||||
474 | } else if (type == "tar.lzma") { | 477 | } else if (type == "tar.lzma") { | ||
475 | packer << KrServices::fullPathName("tar") << "--lzma" << "-cvf"; type = "-tlz"; | 478 | packer << KrServices::fullPathName("tar") << "--lzma" << "-cvf"; | ||
479 | type = "tlz"; | ||||
476 | } else if (type == "tar.xz") { | 480 | } else if (type == "tar.xz") { | ||
477 | packer << KrServices::fullPathName("tar") << "--xz" << "-cvf"; type = "-txz"; | 481 | packer << KrServices::fullPathName("tar") << "--xz" << "-cvf"; | ||
482 | type = "txz"; | ||||
478 | } else if (type == "rar") { | 483 | } else if (type == "rar") { | ||
479 | packer << KrServices::fullPathName("rar") << "-r" << "a"; type = "-rar"; | 484 | packer << KrServices::fullPathName("rar") << "-r" << "a"; | ||
480 | } else if (type == "cbr") { | 485 | } else if (type == "cbr") { | ||
481 | packer << KrServices::fullPathName("rar") << "-r" << "a"; type = "-rar"; | 486 | packer << KrServices::fullPathName("rar") << "-r" << "a"; | ||
487 | type = "rar"; | ||||
482 | } else if (type == "lha") { | 488 | } else if (type == "lha") { | ||
483 | packer << KrServices::fullPathName("lha") << "a"; type = "-lha"; | 489 | packer << KrServices::fullPathName("lha") << "a"; | ||
484 | } else if (type == "arj") { | 490 | } else if (type == "arj") { | ||
485 | packer << KrServices::fullPathName("arj") << "-r" << "-y" << "a"; type = "-arj"; | 491 | packer << KrServices::fullPathName("arj") << "-r" << "-y" << "a"; | ||
486 | } else if (type == "7z") { | 492 | } else if (type == "7z") { | ||
487 | packer << KrServices::fullPathName("7z") << "-y" << "a"; type = "-7z"; | 493 | packer << KrServices::fullPathName("7z") << "-y" << "a"; | ||
488 | } else return false; | 494 | } else return false; | ||
489 | 495 | | |||
490 | QString password; | 496 | QString password; | ||
Context not available. | |||||
493 | password = extraProps[ "Password" ]; | 499 | password = extraProps[ "Password" ]; | ||
494 | 500 | | |||
495 | if (!password.isNull()) { | 501 | if (!password.isNull()) { | ||
496 | if (type == "-zip") | 502 | if (type == "zip") | ||
497 | packer << "-P" << password; | 503 | packer << "-P" << password; | ||
498 | else if (type == "-arj") | 504 | else if (type == "arj") | ||
499 | packer << QString("-g%1").arg(password); | 505 | packer << QString("-g%1").arg(password); | ||
500 | else if (type == "-ace" || type == "-7z") | 506 | else if (type == "ace" || type == "7z") | ||
501 | packer << QString("-p%1").arg(password); | 507 | packer << QString("-p%1").arg(password); | ||
502 | else if (type == "-rar") { | 508 | else if (type == "rar") { | ||
503 | if (extraProps.count("EncryptHeaders") > 0) | 509 | if (extraProps.count("EncryptHeaders") > 0) | ||
504 | packer << QString("-hp%1").arg(password); | 510 | packer << QString("-hp%1").arg(password); | ||
505 | else | 511 | else | ||
Context not available. | |||||
514 | KIO::filesize_t size = sizeStr.toLongLong(); | 520 | KIO::filesize_t size = sizeStr.toLongLong(); | ||
515 | 521 | | |||
516 | if (size >= 10000) { | 522 | if (size >= 10000) { | ||
517 | if (type == "-arj" || type == "-rar") | 523 | if (type == "arj" || type == "rar") | ||
518 | packer << QString("-v%1b").arg(sizeStr); | 524 | packer << QString("-v%1b").arg(sizeStr); | ||
519 | } | 525 | } | ||
520 | } | 526 | } | ||
Context not available. | |||||
526 | if (level > 8) | 532 | if (level > 8) | ||
527 | level = 8; | 533 | level = 8; | ||
528 | 534 | | |||
529 | if (type == "-rar") { | 535 | if (type == "rar") { | ||
530 | static const int rarLevels[] = { 0, 1, 2, 2, 3, 3, 4, 4, 5 }; | 536 | static const int rarLevels[] = { 0, 1, 2, 2, 3, 3, 4, 4, 5 }; | ||
531 | packer << QString("-m%1").arg(rarLevels[ level ]); | 537 | packer << QString("-m%1").arg(rarLevels[ level ]); | ||
532 | } else if (type == "-arj") { | 538 | } else if (type == "arj") { | ||
533 | static const int arjLevels[] = { 0, 4, 4, 3, 3, 2, 2, 1, 1 }; | 539 | static const int arjLevels[] = { 0, 4, 4, 3, 3, 2, 2, 1, 1 }; | ||
534 | packer << QString("-m%1").arg(arjLevels[ level ]); | 540 | packer << QString("-m%1").arg(arjLevels[ level ]); | ||
535 | } else if (type == "-zip") { | 541 | } else if (type == "zip") { | ||
536 | static const int zipLevels[] = { 0, 1, 2, 4, 5, 6, 7, 8, 9 }; | 542 | static const int zipLevels[] = { 0, 1, 2, 4, 5, 6, 7, 8, 9 }; | ||
537 | packer << QString("-%1").arg(zipLevels[ level ]); | 543 | packer << QString("-%1").arg(zipLevels[ level ]); | ||
538 | } else if (type == "-7z") { | 544 | } else if (type == "7z") { | ||
539 | static const int sevenZipLevels[] = { 0, 1, 2, 4, 5, 6, 7, 8, 9 }; | 545 | static const int sevenZipLevels[] = { 0, 1, 2, 4, 5, 6, 7, 8, 9 }; | ||
540 | packer << QString("-mx%1").arg(sevenZipLevels[ level ]); | 546 | packer << QString("-mx%1").arg(sevenZipLevels[ level ]); | ||
541 | } | 547 | } | ||
Context not available. | |||||
562 | proc.start(); | 568 | proc.start(); | ||
563 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | 569 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | ||
564 | // it would be better to connect to started(), error() and finished() | 570 | // it would be better to connect to started(), error() and finished() | ||
565 | if (proc.waitForStarted()) while (proc.state() == QProcess::Running) { | 571 | if (proc.waitForStarted()) | ||
572 | while (proc.state() == QProcess::Running) { | ||||
566 | observer->processEvents(); | 573 | observer->processEvents(); | ||
567 | if (observer->wasCancelled()) | 574 | if (observer->wasCancelled()) | ||
568 | proc.kill(); | 575 | proc.kill(); | ||
Context not available. | |||||
667 | { | 674 | { | ||
668 | QString result = detectArchive(encrypted, fileName, checkEncrypted, fast); | 675 | QString result = detectArchive(encrypted, fileName, checkEncrypted, fast); | ||
669 | if (result.isNull()) { | 676 | if (result.isNull()) { | ||
670 | result = mime; | 677 | // Then the type is based on the mime type | ||
671 | } else { | 678 | return getShortTypeFromMime(mime); | ||
672 | result = '-' + result; | | |||
673 | } | | |||
674 | | ||||
675 | if (result.endsWith(QLatin1String("-7z"))) { | | |||
676 | result = "-7z"; | | |||
677 | } | 679 | } | ||
678 | 680 | return result; | |||
679 | if (result.endsWith(QLatin1String("-xz"))) { | | |||
680 | result = "-xz"; | | |||
681 | } | | |||
682 | | ||||
683 | return result.right(4); | | |||
684 | } | 681 | } | ||
685 | 682 | | |||
686 | | ||||
687 | bool KRarcHandler::checkStatus(QString type, int exitCode) | 683 | bool KRarcHandler::checkStatus(QString type, int exitCode) | ||
688 | { | 684 | { | ||
689 | // if this code is changed, the code of kio_krarcProtocol::checkStatus() must be reviewed | 685 | // if this code is changed, the code of kio_krarcProtocol::checkStatus() must be reviewed | ||
690 | if (type == "-zip" || type == "-rar" || type == "-7z") | 686 | if (type == "zip" || type == "rar" || type == "7z") | ||
691 | return exitCode == 0 || exitCode == 1; | 687 | return exitCode == 0 || exitCode == 1; | ||
692 | else if (type == "-ace" || type == "zip2" || type == "-lha" || type == "-rpm" || type == "cpio" || | 688 | else if (type == "ace" || type == "bzip2" || type == "lha" || type == "rpm" || type == "cpio" || | ||
693 | type == "-tar" || type == "tarz" || type == "-tbz" || type == "-tgz" || type == "-arj" || | 689 | type == "tar" || type == "tarz" || type == "tbz" || type == "tgz" || type == "arj" || | ||
694 | type == "-deb" || type == "-tlz" || type == "-txz") | 690 | type == "deb" || type == "tlz" || type == "txz") | ||
695 | return exitCode == 0; | 691 | return exitCode == 0; | ||
696 | else if (type == "gzip" || type == "lzma" || type == "-xz") | 692 | else if (type == "gzip" || type == "lzma" || type == "xz") | ||
697 | return exitCode == 0 || exitCode == 2; | 693 | return exitCode == 0 || exitCode == 2; | ||
698 | else | 694 | else | ||
699 | return exitCode == 0; | 695 | return exitCode == 0; | ||
Context not available. |