39 #include "core/security.h"
63 if (uncompresssetting ==
"true") {
64 uncompresssetting =
"always";
66 if (uncompresssetting !=
"always" && uncompresssetting !=
"archive" && uncompresssetting !=
"never") {
67 kError() <<
"invalid Uncompress setting chosen, must be one of: always, archive, or never" << endl;
70 uncompression = uncompresssetting;
78 customName = group.
readEntry(
"CustomName",
false);
79 acceptHtml = group.
readEntry(
"AcceptHtmlDownloads",
false);
81 if (standardResourceDirectory.isEmpty() &&
82 targetDirectory.isEmpty() &&
83 xdgTargetDirectory.isEmpty() &&
84 installPath.isEmpty() &&
85 absoluteInstallPath.isEmpty()) {
86 kError() <<
"No installation target set";
91 if (!checksumpolicy.isEmpty()) {
92 if (checksumpolicy ==
"never")
94 else if (checksumpolicy ==
"ifpossible")
96 else if (checksumpolicy ==
"always")
99 kError() <<
"The checksum policy '" + checksumpolicy +
"' is unknown." << endl;
105 if (!signaturepolicy.isEmpty()) {
106 if (signaturepolicy ==
"never")
108 else if (signaturepolicy ==
"ifpossible")
110 else if (signaturepolicy ==
"always")
113 kError() <<
"The signature policy '" + signaturepolicy +
"' is unknown." << endl;
119 if (!scopeString.isEmpty()) {
120 if (scopeString ==
"user")
122 else if (scopeString ==
"system")
125 kError() <<
"The scope '" + scopeString +
"' is unknown." << endl;
130 if (!installPath.isEmpty()) {
131 kError() <<
"System installation cannot be mixed with InstallPath." << endl;
141 if (!installPath.isEmpty())
return false;
142 if (!targetDirectory.isEmpty())
return false;
143 if (!xdgTargetDirectory.isEmpty())
return false;
144 if (!absoluteInstallPath.isEmpty())
return false;
145 if (!standardResourceDirectory.isEmpty())
return false;
162 if (!source.isValid()) {
163 kError() <<
"The entry doesn't have a payload." << endl;
179 KUrl destination =
QString(KGlobal::dirs()->saveLocation(
"tmp") + KRandom::randomString(10) +
'-' + fileName);
180 kDebug() <<
"Downloading payload '" << source <<
"' to '" << destination <<
"'";
183 KIO::FileCopyJob *job = KIO::file_copy(source, destination, -1, KIO::Overwrite | KIO::HideProgressInfo);
185 SIGNAL(result(
KJob*)),
188 entry_jobs[job] = entry;
195 if (entry_jobs.contains(job)) {
197 entry_jobs.remove(job);
207 if (mimeType->is(
"text/html") || mimeType->is(
"application/x-php")) {
208 if (
KMessageBox::questionYesNo(0,
i18n(
"The downloaded file is a html file. This indicates a link to a website instead of the actual download. Would you like to open the site with a browser instead?"),
i18n(
"Possibly bad download link"))
228 kDebug() <<
"Install: " << entry.
name() <<
" from " << downloadedFile;
230 if (entry.
payload().isEmpty()) {
231 kDebug() <<
"No payload associated with: " << entry.
name();
265 QString targetPath = targetInstallationPath(downloadedFile);
266 QStringList installedFiles = installDownloadedFileAndUncompress(entry, downloadedFile, targetPath);
268 if (installedFiles.isEmpty()) {
281 if (!postInstallationCommand.isEmpty()) {
283 if (installedFiles.size() == 1) {
284 runPostInstallationCommand(installedFiles.first());
286 runPostInstallationCommand(targetPath);
296 SIGNAL(validityResult(
int)),
317 QString Installation::targetInstallationPath(
const QString& payloadfile)
319 QString installpath(payloadfile);
327 if (!standardResourceDirectory.isEmpty()) {
335 if (!targetDirectory.isEmpty()) {
343 if (!xdgTargetDirectory.isEmpty()) {
347 if (!installPath.isEmpty()) {
348 #if defined(Q_WS_WIN)
350 WCHAR wPath[MAX_PATH+1];
351 if ( SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wPath) == S_OK) {
352 installdir = QString::fromUtf16((
const ushort *) wPath) + QLatin1Char(
'/') + installpath + QLatin1Char(
'/');
355 installdir = QDir::home().path() + QLatin1Char(
'/') + installPath + QLatin1Char(
'/');
360 installdir = QDir::home().path() +
'/' + installPath +
'/';
364 if (!absoluteInstallPath.isEmpty()) {
365 installdir = absoluteInstallPath +
'/';
368 if (pathcounter != 1) {
369 kError() <<
"Wrong number of installation directories given." << endl;
373 kDebug() <<
"installdir: " << installdir;
382 QString installpath(payloadfile);
387 bool isarchive =
true;
390 if (uncompression ==
"always" || uncompression ==
"archive") {
392 installpath = installdir;
401 if (mimeType->is(
"application/zip")) {
402 archive =
new KZip(payloadfile);
403 }
else if (mimeType->is(
"application/tar")
404 || mimeType->is(
"application/x-gzip")
405 || mimeType->is(
"application/x-bzip")
406 || mimeType->is(
"application/x-lzma")
407 || mimeType->is(
"application/x-xz")
408 || mimeType->is(
"application/x-bzip-compressed-tar")
409 || mimeType->is(
"application/x-compressed-tar") ) {
410 archive =
new KTar(payloadfile);
413 kError() <<
"Could not determine type of archive file '" << payloadfile <<
"'";
414 if (uncompression ==
"always") {
421 bool success = archive->open(QIODevice::ReadOnly);
423 kError() <<
"Cannot open archive file '" << payloadfile <<
"'";
424 if (uncompression ==
"always") {
435 installedFiles << archiveEntries(installdir, dir);
436 installedFiles << installdir +
'/';
439 QFile::remove(payloadfile);
445 kDebug() <<
"isarchive: " << isarchive;
447 if (uncompression ==
"never" || (uncompression ==
"archive" && !isarchive)) {
453 kDebug() <<
"installing non-archive from " << source.
url();
457 installfile = entry.
name();
458 installfile +=
'-' + entry.
version();
459 if (!ext.isEmpty()) installfile +=
'.' + ext;
464 if (source.
url().startsWith(
"http://newstuff.kde.org/cgi-bin/hotstuff-access?file=")) {
465 installfile = source.queryItemValue(
"file");
466 int lastSlash = installfile.lastIndexOf(
'/');
468 installfile = installfile.mid(lastSlash);
470 if (installfile.isEmpty()) {
474 installpath = installdir +
'/' + installfile;
482 QFile file(payloadfile);
486 if (QFile::exists(installpath)) {
492 success = QFile::remove(installpath);
495 success = file.rename(
KUrl(installpath).toLocalFile());
496 kDebug() <<
"move: " << file.fileName() <<
" to " << installpath;
499 kError() <<
"Cannot move file '" << payloadfile <<
"' to destination '" << installpath <<
"'";
502 installedFiles << installpath;
505 return installedFiles;
508 void Installation::runPostInstallationCommand(
const QString& installPath)
511 QString command(postInstallationCommand);
512 QString fileArg(KShell::quoteArg(installPath));
513 command.replace(
"%f", fileArg);
515 kDebug() <<
"Run command: " << command;
518 int exitcode = process.
execute();
521 kError() <<
"Command failed" << endl;
530 if (!uninstallCommand.isEmpty()) {
533 QFileInfo info(file);
535 QString fileArg(KShell::quoteArg(file));
536 QString command(uninstallCommand);
537 command.replace(
"%f", fileArg);
540 int exitcode = process.
execute();
543 kError() <<
"Command failed" << endl;
552 if (file.endsWith(
'/')) {
554 bool worked = dir.rmdir(file);
560 QFileInfo info(file);
561 if (info.exists() || info.isSymLink()) {
562 bool worked = QFile::remove(file);
564 kWarning() <<
"unable to delete file " << file;
568 kWarning() <<
"unable to delete file " << file <<
". file does not exist.";
597 QString childPath = path +
'/' + entry;
598 if (dir->
entry(entry)->isFile()) {
604 files << archiveEntries(childPath, childDir);
605 files << childPath +
'/';
612 #include "installation.moc"