Changeset View
Changeset View
Standalone View
Standalone View
krusader/Archive/krarchandler.cpp
Show All 40 Lines | |||||
41 | #include "kr7zencryptionchecker.h" | 41 | #include "kr7zencryptionchecker.h" | ||
42 | #include "../krglobal.h" | 42 | #include "../krglobal.h" | ||
43 | #include "../defaults.h" | 43 | #include "../defaults.h" | ||
44 | #include "../krservices.h" | 44 | #include "../krservices.h" | ||
45 | #include "../Dialogs/krpleasewait.h" | 45 | #include "../Dialogs/krpleasewait.h" | ||
46 | #include "../../krArc/krlinecountingprocess.h" | 46 | #include "../../krArc/krlinecountingprocess.h" | ||
47 | 47 | | |||
48 | #if 0 | 48 | #if 0 | ||
49 | class DefaultKRarcObserver : public KRarcObserver | 49 | class DefaultKrArcObserver : public KrArcObserver | ||
50 | { | 50 | { | ||
51 | public: | 51 | public: | ||
52 | DefaultKRarcObserver() {} | 52 | DefaultKrArcObserver() {} | ||
53 | virtual ~DefaultKRarcObserver() {} | 53 | virtual ~DefaultKrArcObserver() {} | ||
54 | 54 | | |||
55 | virtual void processEvents() override { | 55 | virtual void processEvents() override { | ||
56 | usleep(1000); | 56 | usleep(1000); | ||
57 | qApp->processEvents(); | 57 | qApp->processEvents(); | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | virtual void subJobStarted(const QString & jobTitle, int count) override { | 60 | virtual void subJobStarted(const QString & jobTitle, int count) override { | ||
61 | krApp->startWaiting(jobTitle, count, true); | 61 | krApp->startWaiting(jobTitle, count, true); | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 177 | return (type == "zip" && lst.contains("unzip")) | |||
190 | || (type == "rpm" && lst.contains("cpio")) | 190 | || (type == "rpm" && lst.contains("cpio")) | ||
191 | || (type == "cpio" && lst.contains("cpio")) | 191 | || (type == "cpio" && lst.contains("cpio")) | ||
192 | || (type == "rar" && (lst.contains("unrar") || lst.contains("rar"))) | 192 | || (type == "rar" && (lst.contains("unrar") || lst.contains("rar"))) | ||
193 | || (type == "arj" && (lst.contains("unarj") || lst.contains("arj"))) | 193 | || (type == "arj" && (lst.contains("unarj") || lst.contains("arj"))) | ||
194 | || (type == "deb" && (lst.contains("dpkg") && lst.contains("tar"))) | 194 | || (type == "deb" && (lst.contains("dpkg") && lst.contains("tar"))) | ||
195 | || (type == "7z" && lst.contains("7z")); | 195 | || (type == "7z" && lst.contains("7z")); | ||
196 | } | 196 | } | ||
197 | 197 | | |||
198 | long KrArcHandler::arcFileCount(const QString& archive, const QString& type, const QString& password, KRarcObserver *observer) | 198 | long KrArcHandler::arcFileCount(const QString& archive, const QString& type, const QString& password, KrArcObserver *observer) | ||
199 | { | 199 | { | ||
200 | int divideWith = 1; | 200 | int divideWith = 1; | ||
201 | 201 | | |||
202 | // first check if supported | 202 | // first check if supported | ||
203 | if (!arcSupported(type)) | 203 | if (!arcSupported(type)) | ||
204 | return 0; | 204 | return 0; | ||
205 | 205 | | |||
206 | // bzip2, gzip, etc. archives contain only one file | 206 | // bzip2, gzip, etc. archives contain only one file | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
269 | count = list.readAllStandardOutput().count('\n'); | 269 | count = list.readAllStandardOutput().count('\n'); | ||
270 | 270 | | |||
271 | //make sure you call stopWait after this function return... | 271 | //make sure you call stopWait after this function return... | ||
272 | // observer->subJobStopped(); | 272 | // observer->subJobStopped(); | ||
273 | 273 | | |||
274 | return count / divideWith; | 274 | return count / divideWith; | ||
275 | } | 275 | } | ||
276 | 276 | | |||
277 | bool KrArcHandler::unpack(QString archive, const QString& type, const QString& password, const QString& dest, KRarcObserver *observer) | 277 | bool KrArcHandler::unpack(QString archive, const QString& type, const QString& password, const QString& dest, KrArcObserver *observer) | ||
278 | { | 278 | { | ||
279 | KConfigGroup group(krConfig, "Archives"); | 279 | KConfigGroup group(krConfig, "Archives"); | ||
280 | if (group.readEntry("Test Before Unpack", _TestBeforeUnpack)) { | 280 | if (group.readEntry("Test Before Unpack", _TestBeforeUnpack)) { | ||
281 | // test first - or be sorry later... | 281 | // test first - or be sorry later... | ||
282 | if (type != "rpm" && type != "deb" && !test(archive, type, password, observer, 0)) { | 282 | if (type != "rpm" && type != "deb" && !test(archive, type, password, observer, 0)) { | ||
283 | observer->error(i18n("Failed to unpack %1.", archive)); | 283 | observer->error(i18n("Failed to unpack %1.", archive)); | ||
284 | return false; | 284 | return false; | ||
285 | } | 285 | } | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | |||||
369 | if (type == "ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | 369 | if (type == "ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | ||
370 | proc.setStandardInputFile("/dev/ptmx"); | 370 | proc.setStandardInputFile("/dev/ptmx"); | ||
371 | 371 | | |||
372 | proc.setWorkingDirectory(dest); | 372 | proc.setWorkingDirectory(dest); | ||
373 | 373 | | |||
374 | // tell the user to wait | 374 | // tell the user to wait | ||
375 | observer->subJobStarted(i18n("Unpacking File(s)"), count); | 375 | observer->subJobStarted(i18n("Unpacking File(s)"), count); | ||
376 | if (count != 0) { | 376 | if (count != 0) { | ||
377 | connect(&proc, &KrLinecountingProcess::newOutputLines, observer, &KRarcObserver::incrementProgress); | 377 | connect(&proc, &KrLinecountingProcess::newOutputLines, observer, &KrArcObserver::incrementProgress); | ||
378 | if (type == "rpm") | 378 | if (type == "rpm") | ||
379 | connect(&proc, &KrLinecountingProcess::newErrorLines, observer, &KRarcObserver::incrementProgress); | 379 | connect(&proc, &KrLinecountingProcess::newErrorLines, observer, &KrArcObserver::incrementProgress); | ||
380 | } | 380 | } | ||
381 | 381 | | |||
382 | // start the unpacking process | 382 | // start the unpacking process | ||
383 | proc.start(); | 383 | proc.start(); | ||
384 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | 384 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | ||
385 | // it would be better to connect to started(), error() and finished() | 385 | // it would be better to connect to started(), error() and finished() | ||
386 | if (proc.waitForStarted()) | 386 | if (proc.waitForStarted()) | ||
387 | while (proc.state() == QProcess::Running) { | 387 | while (proc.state() == QProcess::Running) { | ||
Show All 11 Lines | |||||
399 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) { | 399 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) { | ||
400 | observer->detailedError(i18n("Failed to unpack %1.", archive), | 400 | observer->detailedError(i18n("Failed to unpack %1.", archive), | ||
401 | observer->wasCancelled() ? i18n("User cancelled.") : proc.getErrorMsg()); | 401 | observer->wasCancelled() ? i18n("User cancelled.") : proc.getErrorMsg()); | ||
402 | return false; | 402 | return false; | ||
403 | } | 403 | } | ||
404 | return true; // SUCCESS | 404 | return true; // SUCCESS | ||
405 | } | 405 | } | ||
406 | 406 | | |||
407 | bool KrArcHandler::test(const QString& archive, const QString& type, const QString& password, KRarcObserver *observer, long count) | 407 | bool KrArcHandler::test(const QString& archive, const QString& type, const QString& password, KrArcObserver *observer, long count) | ||
408 | { | 408 | { | ||
409 | // choose the right packer for the job | 409 | // choose the right packer for the job | ||
410 | QStringList packer; | 410 | QStringList packer; | ||
411 | 411 | | |||
412 | // set the right packer to do the job | 412 | // set the right packer to do the job | ||
413 | if (type == "zip") packer << KrServices::fullPathName("unzip") << "-t"; | 413 | if (type == "zip") packer << KrServices::fullPathName("unzip") << "-t"; | ||
414 | else if (type == "tar") packer << KrServices::fullPathName("tar") << "-tvf"; | 414 | else if (type == "tar") packer << KrServices::fullPathName("tar") << "-tvf"; | ||
415 | else if (type == "tgz") packer << KrServices::fullPathName("tar") << "-tvzf"; | 415 | else if (type == "tgz") packer << KrServices::fullPathName("tar") << "-tvzf"; | ||
Show All 27 Lines | |||||
443 | proc << packer << archive; | 443 | proc << packer << archive; | ||
444 | 444 | | |||
445 | if (type == "ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | 445 | if (type == "ace" && QFile("/dev/ptmx").exists()) // Don't remove, unace crashes if missing!!! | ||
446 | proc.setStandardInputFile("/dev/ptmx"); | 446 | proc.setStandardInputFile("/dev/ptmx"); | ||
447 | 447 | | |||
448 | // tell the user to wait | 448 | // tell the user to wait | ||
449 | observer->subJobStarted(i18n("Testing Archive"), count); | 449 | observer->subJobStarted(i18n("Testing Archive"), count); | ||
450 | if (count != 0) | 450 | if (count != 0) | ||
451 | connect(&proc, &KrLinecountingProcess::newOutputLines, observer, &KRarcObserver::incrementProgress); | 451 | connect(&proc, &KrLinecountingProcess::newOutputLines, observer, &KrArcObserver::incrementProgress); | ||
452 | 452 | | |||
453 | // start the unpacking process | 453 | // start the unpacking process | ||
454 | proc.start(); | 454 | proc.start(); | ||
455 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | 455 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | ||
456 | // it would be better to connect to started(), error() and finished() | 456 | // it would be better to connect to started(), error() and finished() | ||
457 | if (proc.waitForStarted()) | 457 | if (proc.waitForStarted()) | ||
458 | while (proc.state() == QProcess::Running) { | 458 | while (proc.state() == QProcess::Running) { | ||
459 | observer->processEvents(); | 459 | observer->processEvents(); | ||
460 | if (observer->wasCancelled()) | 460 | if (observer->wasCancelled()) | ||
461 | proc.kill(); | 461 | proc.kill(); | ||
462 | } | 462 | } | ||
463 | ; // busy wait - need to find something better... | 463 | ; // busy wait - need to find something better... | ||
464 | observer->subJobStopped(); | 464 | observer->subJobStopped(); | ||
465 | 465 | | |||
466 | // check the return value | 466 | // check the return value | ||
467 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) | 467 | if (proc.exitStatus() != QProcess::NormalExit || !checkStatus(type, proc.exitCode())) | ||
468 | return false; | 468 | return false; | ||
469 | 469 | | |||
470 | return true; // SUCCESS | 470 | return true; // SUCCESS | ||
471 | } | 471 | } | ||
472 | 472 | | |||
473 | bool KrArcHandler::pack(QStringList fileNames, QString type, const QString& dest, long count, QMap<QString, QString> extraProps, KRarcObserver *observer) | 473 | bool KrArcHandler::pack(QStringList fileNames, QString type, const QString& dest, long count, QMap<QString, QString> extraProps, KrArcObserver *observer) | ||
474 | { | 474 | { | ||
475 | // set the right packer to do the job | 475 | // set the right packer to do the job | ||
476 | QStringList packer; | 476 | QStringList packer; | ||
477 | 477 | | |||
478 | if (type == "zip") { | 478 | if (type == "zip") { | ||
479 | packer << KrServices::fullPathName("zip") << "-ry"; | 479 | packer << KrServices::fullPathName("zip") << "-ry"; | ||
480 | } else if (type == "cbz") { | 480 | } else if (type == "cbz") { | ||
481 | packer << KrServices::fullPathName("zip") << "-ry"; | 481 | packer << KrServices::fullPathName("zip") << "-ry"; | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | |||||
570 | 570 | | |||
571 | for (auto & fileName : fileNames) { | 571 | for (auto & fileName : fileNames) { | ||
572 | proc << fileName; | 572 | proc << fileName; | ||
573 | } | 573 | } | ||
574 | 574 | | |||
575 | // tell the user to wait | 575 | // tell the user to wait | ||
576 | observer->subJobStarted(i18n("Packing File(s)"), count); | 576 | observer->subJobStarted(i18n("Packing File(s)"), count); | ||
577 | if (count != 0) | 577 | if (count != 0) | ||
578 | connect(&proc, &KrLinecountingProcess::newOutputLines, observer, &KRarcObserver::incrementProgress); | 578 | connect(&proc, &KrLinecountingProcess::newOutputLines, observer, &KrArcObserver::incrementProgress); | ||
579 | 579 | | |||
580 | // start the packing process | 580 | // start the packing process | ||
581 | proc.start(); | 581 | proc.start(); | ||
582 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | 582 | // TODO make use of asynchronous process starting. waitForStarted(int msec = 30000) is blocking | ||
583 | // it would be better to connect to started(), error() and finished() | 583 | // it would be better to connect to started(), error() and finished() | ||
584 | if (proc.waitForStarted()) | 584 | if (proc.waitForStarted()) | ||
585 | while (proc.state() == QProcess::Running) { | 585 | while (proc.state() == QProcess::Running) { | ||
586 | observer->processEvents(); | 586 | observer->processEvents(); | ||
▲ Show 20 Lines • Show All 158 Lines • Show Last 20 Lines |