diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/archivegen/archive.cpp | 169 | ||||
-rw-r--r-- | tools/archivegen/archivegen.pro | 1 | ||||
-rw-r--r-- | tools/binarycreator/binarycreator.cpp | 25 | ||||
-rw-r--r-- | tools/binarycreator/rcc/rcc.cpp | 10 | ||||
-rw-r--r-- | tools/binarycreator/resources/mkdmg.sh | 13 | ||||
-rw-r--r-- | tools/common/repositorygen.cpp | 116 | ||||
-rw-r--r-- | tools/common/repositorygen.h | 1 | ||||
-rw-r--r-- | tools/devtool/binarydump.cpp | 20 | ||||
-rw-r--r-- | tools/devtool/binaryreplace.cpp | 24 | ||||
-rw-r--r-- | tools/devtool/main.cpp | 149 | ||||
-rw-r--r-- | tools/devtool/operationrunner.cpp | 6 | ||||
-rw-r--r-- | tools/repocompare/main.cpp | 2 | ||||
-rw-r--r-- | tools/repocompare/mainwindow.cpp | 10 | ||||
-rw-r--r-- | tools/repocompare/mainwindow.h | 3 | ||||
-rw-r--r-- | tools/repocompare/repositorymanager.cpp | 11 | ||||
-rw-r--r-- | tools/repogen/repogen.cpp | 11 | ||||
-rw-r--r-- | tools/tools.pro | 1 |
17 files changed, 397 insertions, 175 deletions
diff --git a/tools/archivegen/archive.cpp b/tools/archivegen/archive.cpp index 98d6c9366..8860ec437 100644 --- a/tools/archivegen/archive.cpp +++ b/tools/archivegen/archive.cpp @@ -30,47 +30,178 @@ ** $QT_END_LICENSE$ ** **************************************************************************/ -#include "common/repositorygen.h" #include <errors.h> -#include <init.h> +#include <lib7z_create.h> #include <lib7z_facade.h> #include <utils.h> -#include <QtCore/QCoreApplication> -#include <QtCore/QFileInfo> -#include <QtCore/QStringList> +#include <QCoreApplication> +#include <QCommandLineParser> +#include <QDir> #include <iostream> -using namespace Lib7z; using namespace QInstaller; -static void printUsage() +class FailOnErrorCallback : public Lib7z::UpdateCallback { - std::cout << "Usage: " << QFileInfo(QCoreApplication::applicationFilePath()).fileName() - << " directory.7z [files | directories]" << std::endl; -} + HRESULT OpenFileError(const wchar_t*, DWORD) { + return S_FALSE; + } + + HRESULT CanNotFindError(const wchar_t*, DWORD) { + return S_FALSE; + } + + HRESULT OpenResult(const wchar_t*, HRESULT result, const wchar_t*) { + return result; + } +}; + +class VerbosePrinterCallback : public Lib7z::UpdateCallback +{ +public: + ~VerbosePrinterCallback() { + m_PercentPrinter.ClosePrint(); + } + +private: + HRESULT SetTotal(UInt64 size) { + m_PercentPrinter.SetTotal(size); + return S_OK; + } + + HRESULT SetCompleted(const UInt64 *size) { + if (size) { + m_PercentPrinter.SetRatio(*size); + m_PercentPrinter.PrintRatio(); + } + return S_OK; + } + + HRESULT OpenResult(const wchar_t *file, HRESULT result, const wchar_t*) { + if (result != S_OK) { + printBlock(QCoreApplication::translate("archivegen", "Cannot update file \"%1\". " + "Unsupported archive.").arg(QDir::toNativeSeparators(QString::fromWCharArray(file))), Q_NULLPTR); + } + return result; + } + + HRESULT OpenFileError(const wchar_t *file, DWORD) { + printBlock(QCoreApplication::translate("archivegen", "Cannot open file "), file); + return S_FALSE; + } + + HRESULT CanNotFindError(const wchar_t *file, DWORD) { + printBlock(QCoreApplication::translate("archivegen", "Cannot find file "), file); + return S_FALSE; + } + + HRESULT StartArchive(const wchar_t *name, bool) { + printLine(QCoreApplication::translate("archivegen", "Create archive.")); + if (name) { + m_PercentPrinter.PrintNewLine(); + m_PercentPrinter.PrintString(name); + } + return S_OK; + } + + HRESULT FinishArchive() { + m_PercentPrinter.PrintNewLine(); + printLine(QCoreApplication::translate("archivegen", "Finished archive.")); + return S_OK; + } + + void printLine(const QString &message) { + m_PercentPrinter.PrintString(message.toStdWString().c_str()); + } + + void printBlock(const QString &message, const wchar_t *message2) { + m_PercentPrinter.PrintNewLine(); + m_PercentPrinter.PrintString(message.toStdWString().c_str()); + if (message2) + m_PercentPrinter.PrintString(message2); + m_PercentPrinter.PrintNewLine(); + } + + Lib7z::PercentPrinter m_PercentPrinter; +}; int main(int argc, char *argv[]) { try { QCoreApplication app(argc, argv); +#define QUOTE_(x) #x +#define QUOTE(x) QUOTE_(x) + QCoreApplication::setApplicationVersion(QLatin1String(QUOTE(IFW_VERSION_STR))); +#undef QUOTE +#undef QUOTE_ + + QCommandLineParser parser; + const QCommandLineOption help = parser.addHelpOption(); + const QCommandLineOption version = parser.addVersionOption(); + QCommandLineOption verbose(QLatin1String("verbose"), + QCoreApplication::translate("archivegen", "Verbose mode. Prints out more information.")); + const QCommandLineOption compression = QCommandLineOption(QStringList() + << QLatin1String("c") << QLatin1String("compression"), + QCoreApplication::translate("archivegen", + "0 (No compression)\n" + "1 (Fastest compressing)\n" + "3 (Fast compressing)\n" + "5 (Normal compressing)\n" + "7 (Maximum compressing)\n" + "9 (Ultra compressing)\n" + "Defaults to 5 (Normal compression)." + ), QLatin1String("5"), QLatin1String("5")); + + parser.addOption(verbose); + parser.addOption(compression); + parser.addPositionalArgument(QLatin1String("archive"), + QCoreApplication::translate("archivegen", "Compressed archive to create.")); + parser.addPositionalArgument(QLatin1String("sources"), + QCoreApplication::translate("archivegen", "List of files and directories to compress.")); + + parser.parse(app.arguments()); + if (parser.isSet(help)) { + std::cout << parser.helpText() << std::endl; + return EXIT_SUCCESS; + } - if (app.arguments().count() < 3) { - printUsage(); + if (parser.isSet(version)) { + parser.showVersion(); + return EXIT_SUCCESS; + } + + const QStringList args = parser.positionalArguments(); + if (args.count() < 2) { + std::cerr << QCoreApplication::translate("archivegen", "Wrong argument count. See " + "'archivgen --help'.") << std::endl; return EXIT_FAILURE; } - QInstaller::init(); - QInstaller::setVerbose(true); - const QStringList sourceDirectories = app.arguments().mid(2); - QInstallerTools::compressPaths(sourceDirectories, app.arguments().at(1)); + bool ok = false; + const int values[6] = { 0, 1, 3, 5, 7, 9 }; + const int value = parser.value(compression).toInt(&ok); + if (!ok || (std::find(std::begin(values), std::end(values), value) == std::end(values))) { + throw QInstaller::Error(QCoreApplication::translate("archivegen", + "Unknown compression level \"%1\". See 'archivgen --help'.").arg(value)); + } + + Lib7z::initSevenZ(); + Lib7z::createArchive(args[0], args.mid(1), Lib7z::QTmpFile::No, Lib7z::Compression(value), + [&] () -> Lib7z::UpdateCallback * { + if (parser.isSet(verbose)) + return new VerbosePrinterCallback; + return new FailOnErrorCallback; + } () + ); return EXIT_SUCCESS; - } catch (const Lib7z::SevenZipException &e) { - std::cerr << "caught 7zip exception: " << e.message() << std::endl; } catch (const QInstaller::Error &e) { - std::cerr << "caught exception: " << e.message() << std::endl; + std::cerr << e.message() << std::endl; + } catch (...) { + std::cerr << QCoreApplication::translate("archivegen", "Unknown exception caught.") + << std::endl; } return EXIT_FAILURE; } diff --git a/tools/archivegen/archivegen.pro b/tools/archivegen/archivegen.pro index 135c34010..719b35a7f 100644 --- a/tools/archivegen/archivegen.pro +++ b/tools/archivegen/archivegen.pro @@ -7,6 +7,7 @@ include(../../installerfw.pri) QT -= gui QT += qml xml +LIBS += -l7z CONFIG += console DESTDIR = $$IFW_APP_PATH diff --git a/tools/binarycreator/binarycreator.cpp b/tools/binarycreator/binarycreator.cpp index d0dd008ff..c112aa2a6 100644 --- a/tools/binarycreator/binarycreator.cpp +++ b/tools/binarycreator/binarycreator.cpp @@ -198,7 +198,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) QTemporaryFile file(input.outputPath); if (!file.open()) { - throw Error(QString::fromLatin1("Could not copy %1 to %2: %3").arg(input.installerExePath, + throw Error(QString::fromLatin1("Cannot copy %1 to %2: %3").arg(input.installerExePath, input.outputPath, file.errorString())); } @@ -208,7 +208,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) QFile instExe(input.installerExePath); if (!instExe.copy(tempFile)) { - throw Error(QString::fromLatin1("Could not copy %1 to %2: %3").arg(instExe.fileName(), + throw Error(QString::fromLatin1("Cannot copy %1 to %2: %3").arg(instExe.fileName(), tempFile, instExe.errorString())); } @@ -233,7 +233,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) chmod755(copyscript); QProcess p; p.start(copyscript, QStringList() << bundle); - p.waitForFinished(); + p.waitForFinished(-1); QFile::rename(input.outputPath, tempFile); QFile::remove(copyscript); } @@ -251,7 +251,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) { QFile target(targetName); if (target.exists() && !target.remove()) { - qCritical("Could not remove target %s: %s", qPrintable(target.fileName()), + qCritical("Cannot remove target %s: %s", qPrintable(target.fileName()), qPrintable(target.errorString())); QFile::remove(tempFile); return EXIT_FAILURE; @@ -264,7 +264,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) #ifdef Q_OS_OSX if (!exe.copy(input.outputPath)) { - throw Error(QString::fromLatin1("Could not copy %1 to %2: %3").arg(exe.fileName(), + throw Error(QString::fromLatin1("Cannot copy %1 to %2: %3").arg(exe.fileName(), input.outputPath, exe.errorString())); } #else @@ -279,8 +279,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) qDebug() << "Creating resource archive for" << info.name; foreach (const QString &file, info.copiedFiles) { const QSharedPointer<Resource> resource(new Resource(file)); - qDebug() << QString::fromLatin1("Appending %1 (%2)").arg(file, - humanReadableSize(resource->size())); + qDebug().nospace() << "Appending " << file << " (" << humanReadableSize(resource->size()) << ")"; collection.appendResource(resource); } input.manager.insertCollection(collection); @@ -296,7 +295,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) } if (!out.rename(targetName)) { - qCritical("Could not write installer to %s: %s", targetName.toUtf8().constData(), + qCritical("Cannot write installer to %s: %s", targetName.toUtf8().constData(), out.errorString().toUtf8().constData()); QFile::remove(tempFile); return EXIT_FAILURE; @@ -320,7 +319,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) QProcess p; p.start(mkdmgscript, QStringList() << QFileInfo(input.outputPath).fileName() << bundle); - p.waitForFinished(); + p.waitForFinished(-1); QFile::remove(mkdmgscript); qDebug() << "done." << mkdmgscript; } @@ -372,7 +371,7 @@ static QSharedPointer<QInstaller::Resource> createDefaultResourceFile(const QStr { QTemporaryFile projectFile(directory + QLatin1String("/rccprojectXXXXXX.qrc")); if (!projectFile.open()) - throw Error(QString::fromLatin1("Could not create temporary file for generated rcc project file")); + throw Error(QString::fromLatin1("Cannot create temporary file for generated rcc project file")); projectFile.close(); const WorkingDirectoryChange wd(directory); @@ -381,13 +380,13 @@ static QSharedPointer<QInstaller::Resource> createDefaultResourceFile(const QStr // 1. create the .qrc file if (runRcc(QStringList() << QLatin1String("rcc") << QLatin1String("-project") << QLatin1String("-o") << projectFileName) != EXIT_SUCCESS) { - throw Error(QString::fromLatin1("Could not create rcc project file.")); + throw Error(QString::fromLatin1("Cannot create rcc project file.")); } // 2. create the binary resource file from the .qrc file if (runRcc(QStringList() << QLatin1String("rcc") << QLatin1String("-binary") << QLatin1String("-o") << binaryName << projectFileName) != EXIT_SUCCESS) { - throw Error(QString::fromLatin1("Could not compile rcc project file.")); + throw Error(QString::fromLatin1("Cannot compile rcc project file.")); } return QSharedPointer<QInstaller::Resource>(new QInstaller::Resource(binaryName, binaryName @@ -492,7 +491,7 @@ void copyConfigData(const QString &configFile, const QString &targetDir) const QString tagName = domElement.tagName(); const QString elementText = domElement.text(); - qDebug() << QString::fromLatin1("Read dom element: <%1>%2</%1>.").arg(tagName, elementText); + qDebug().noquote() << QString::fromLatin1("Read dom element: <%1>%2</%1>.").arg(tagName, elementText); QString newName = domElement.text().replace(QRegExp(QLatin1String("\\\\|/|\\.|:")), QLatin1String("_")); diff --git a/tools/binarycreator/rcc/rcc.cpp b/tools/binarycreator/rcc/rcc.cpp index f6d2e56f2..e7f1ddfc7 100644 --- a/tools/binarycreator/rcc/rcc.cpp +++ b/tools/binarycreator/rcc/rcc.cpp @@ -713,25 +713,25 @@ bool RCCResourceLibrary::output(QIODevice &outDevice, QIODevice &errorDevice) if (m_verbose) m_errorDevice->write("Outputting code\n"); if (!writeHeader()) { - m_errorDevice->write("Could not write header\n"); + m_errorDevice->write("Cannot write header\n"); return false; } if (m_root) { if (!writeDataBlobs()) { - m_errorDevice->write("Could not write data blobs.\n"); + m_errorDevice->write("Cannot write data blobs.\n"); return false; } if (!writeDataNames()) { - m_errorDevice->write("Could not write file names\n"); + m_errorDevice->write("Cannot write file names\n"); return false; } if (!writeDataStructure()) { - m_errorDevice->write("Could not write data tree\n"); + m_errorDevice->write("Cannot write data tree\n"); return false; } } if (!writeInitializer()) { - m_errorDevice->write("Could not write footer\n"); + m_errorDevice->write("Cannot write footer\n"); return false; } outDevice.write(m_out.constData(), m_out.size()); diff --git a/tools/binarycreator/resources/mkdmg.sh b/tools/binarycreator/resources/mkdmg.sh index 1d482ec82..b697aa0d8 100644 --- a/tools/binarycreator/resources/mkdmg.sh +++ b/tools/binarycreator/resources/mkdmg.sh @@ -51,14 +51,15 @@ VOL="$1" FILES="$2" PATHNAME=`dirname $FILES` -DMG=`mktemp "/tmp/$VOL.XXXXXX.dmg"` +# keep '.XXXXXX' at the end to satisfy 'mktemp' as shipped on OS X +DMG=`mktemp "/tmp/$VOL.XXXXXX"` # create temporary disk image and format, ejecting when done SIZE=`du -sk ${FILES} | sed -n 's,^\([0-9]*\).*,\1,p'` SIZE=$((${SIZE}/1000+1)) -hdiutil create "$DMG" -megabytes ${SIZE} -ov -volname "$VOL" -type UDIF -fs HFS+ >/dev/null -DISK=`hdid "$DMG" | sed -ne 's,^\(.*\) *Apple_H.*,\1,p'` -MOUNT=`hdid "$DMG" | sed -ne 's,^.*Apple_HFS[^/]*\(/.*\)$,\1,p'` +hdiutil create "${DMG}.dmg" -megabytes ${SIZE} -ov -volname "$VOL" -type UDIF -fs HFS+ >/dev/null +DISK=`hdid "${DMG}.dmg" | sed -ne 's,^\(.*\) *Apple_H.*,\1,p'` +MOUNT=`hdid "${DMG}.dmg" | sed -ne 's,^.*Apple_HFS[^/]*\(/.*\)$,\1,p'` # mount and copy files onto volume cp -R "$PATHNAME/`basename $FILES`" "$MOUNT" @@ -66,5 +67,5 @@ hdiutil eject $DISK >/dev/null # convert to compressed image, delete temp image rm -f "$PATHNAME/${VOL}.dmg" -hdiutil convert "$DMG" -format UDZO -o "$PATHNAME/${VOL}.dmg" >/dev/null -rm -f "$DMG" +hdiutil convert "${DMG}.dmg" -format UDZO -o "$PATHNAME/${VOL}.dmg" >/dev/null +rm -f "${DMG}.dmg" diff --git a/tools/common/repositorygen.cpp b/tools/common/repositorygen.cpp index dee97ab7c..1a3b5cb10 100644 --- a/tools/common/repositorygen.cpp +++ b/tools/common/repositorygen.cpp @@ -36,13 +36,15 @@ #include <fileutils.h> #include <errors.h> #include <globals.h> +#include <lib7z_create.h> #include <lib7z_facade.h> +#include <lib7z_list.h> #include <settings.h> #include <qinstallerglobal.h> #include <utils.h> #include <scriptengine.h> -#include <kdupdater.h> +#include <updater.h> #include <QtCore/QDirIterator> @@ -74,7 +76,7 @@ QString QInstallerTools::makePathAbsolute(const QString &path) void QInstallerTools::copyWithException(const QString &source, const QString &target, const QString &kind) { - qDebug() << QString::fromLatin1("Copying associated %1 file '%2'").arg(kind, source); + qDebug() << "Copying associated" << kind << "file" << source; const QFileInfo targetFileInfo(target); if (!targetFileInfo.dir().exists()) @@ -83,8 +85,8 @@ void QInstallerTools::copyWithException(const QString &source, const QString &ta QFile sourceFile(source); if (!sourceFile.copy(target)) { qDebug() << "failed!\n"; - throw QInstaller::Error(QString::fromLatin1("Could not copy the %1 file from\n'%2' to '%3'\nError: " - "'%4'.").arg(kind, source, target, + throw QInstaller::Error(QString::fromLatin1("Cannot copy the %1 file from \"%2\" to \"%3\": " + "%4").arg(kind, QDir::toNativeSeparators(source), QDir::toNativeSeparators(target), /* in case of an existing target the error String does not show the file */ (targetFileInfo.exists() ? QLatin1String("Target already exist.") : sourceFile.errorString()))); } @@ -92,13 +94,6 @@ void QInstallerTools::copyWithException(const QString &source, const QString &ta qDebug() << "done.\n"; } -void QInstallerTools::compressPaths(const QStringList &paths, const QString &archivePath) -{ - QFile archive(archivePath); - QInstaller::openForWrite(&archive); - Lib7z::createArchive(&archive, paths); -} - static QStringList copyFilesFromNode(const QString &parentNode, const QString &childNode, const QString &attr, const QString &kind, const QDomNode &package, const PackageInfo &info, const QString &targetDir) { @@ -113,8 +108,8 @@ static QStringList copyFilesFromNode(const QString &parentNode, const QString &c const QString filter = attr.isEmpty() ? node.toElement().text() : node.toElement().attribute(attr); const QStringList files = dir.entryList(QStringList(filter), QDir::Files); if (files.isEmpty()) { - throw QInstaller::Error(QString::fromLatin1("Could not find any %1 matching '%2' " - "while copying %1 of '%3'.").arg(kind, filter, info.name)); + throw QInstaller::Error(QString::fromLatin1("Cannot find any %1 matching \"%2\" " + "while copying %1 of \"%3\".").arg(kind, filter, info.name)); } foreach (const QString &file, files) { @@ -164,11 +159,10 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met foreach (const PackageInfo &info, packages) { if (!QDir(targetDir).mkpath(info.name)) - throw QInstaller::Error(QString::fromLatin1("Could not create directory '%1'.").arg(info.name)); + throw QInstaller::Error(QString::fromLatin1("Cannot create directory \"%1\".").arg(info.name)); const QString packageXmlPath = QString::fromLatin1("%1/meta/package.xml").arg(info.directory); - qDebug() << QString::fromLatin1("Copy meta data for package '%1' using '%2'.").arg(info.name, - packageXmlPath); + qDebug() << "Copy meta data for package" << info.name << "using" << packageXmlPath; QFile file(packageXmlPath); QInstaller::openForRead(&file); @@ -178,8 +172,8 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met int column = 0; QDomDocument packageXml; if (!packageXml.setContent(&file, &errMsg, &line, &column)) { - throw QInstaller::Error(QString::fromLatin1("Could not parse '%1': line: %2, column: %3: %4 (%5)") - .arg(packageXmlPath).arg(line).arg(column).arg(errMsg, info.name)); + throw QInstaller::Error(QString::fromLatin1("Cannot parse \"%1\": line: %2, column: %3: %4 (%5)") + .arg(QDir::toNativeSeparators(packageXmlPath)).arg(line).arg(column).arg(errMsg, info.name)); } QDomElement update = doc.createElement(QLatin1String("PackageUpdate")); @@ -195,6 +189,7 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met bool foundVirtual = false; bool foundDisplayName = false; bool foundDownloadableArchives = false; + bool foundCheckable = false; const QDomNode package = packageXml.firstChildElement(QLatin1String("Package")); const QDomNodeList childNodes = package.childNodes(); for (int i = 0; i < childNodes.count(); ++i) { @@ -209,6 +204,8 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met foundDisplayName = true; if (key == QLatin1String("DownloadableArchives")) foundDownloadableArchives = true; + if (key == QLatin1String("Checkable")) + foundCheckable = true; if (node.isComment() || blackList.contains(key)) continue; // just skip comments and some tags... @@ -222,12 +219,17 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met if (foundDefault && foundVirtual) { throw QInstaller::Error(QString::fromLatin1("Error: <Default> and <Virtual> elements are " - "mutually exclusive. File: '%0'").arg(packageXmlPath)); + "mutually exclusive in file \"%1\".").arg(QDir::toNativeSeparators(packageXmlPath))); + } + + if (foundDefault && foundCheckable) { + throw QInstaller::Error(QString::fromLatin1("Error: <Default> and <Checkable>" + "elements are mutually exclusive in file \"%1\".") + .arg(QDir::toNativeSeparators(packageXmlPath))); } if (!foundDisplayName) { - qWarning() << QString::fromLatin1("No DisplayName tag found at '%1', using component Name instead." - ).arg(info.name); + qWarning() << "No DisplayName tag found at" << info.name << ", using component Name instead."; QDomElement displayNameElement = doc.createElement(QLatin1String("DisplayName")); update.appendChild(displayNameElement).appendChild(doc.createTextNode(info.name)); } @@ -240,7 +242,7 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met const QDir dataDir = QString::fromLatin1("%1/%2/data").arg(metaDataDir, info.name); const QFileInfoList entries = dataDir.exists() ? dataDir.entryInfoList(filters | QDir::Dirs) : QDir(QString::fromLatin1("%1/%2").arg(metaDataDir, info.name)).entryInfoList(filters); - qDebug() << QString::fromLatin1("calculate size of directory: %1").arg(dataDir.absolutePath()); + qDebug() << "calculate size of directory" << dataDir.absolutePath(); foreach (const QFileInfo &fi, entries) { try { if (fi.isDir()) { @@ -268,7 +270,7 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met compressedComponentSize += size; } } catch (const QInstaller::Error &error) { - qDebug() << error.message(); + qDebug().noquote() << error.message(); } catch(...) { // ignore, that's just about the sizes - and size doesn't matter, you know? } @@ -288,8 +290,8 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met if (!script.isEmpty()) { QFile scriptFile(QString::fromLatin1("%1/meta/%2").arg(info.directory, script)); if (!scriptFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - throw QInstaller::Error(QString::fromLatin1("Could not open component script: '%1'") - .arg(scriptFile.fileName())); + throw QInstaller::Error(QString::fromLatin1("Cannot open component script at \"%1\".") + .arg(QDir::toNativeSeparators(scriptFile.fileName()))); } const QString scriptContent = QLatin1String("(function() {") @@ -307,8 +309,9 @@ void QInstallerTools::copyMetaData(const QString &_targetDir, const QString &met const QJSValue value = testScriptEngine.evaluate(scriptContent, scriptFile.fileName()); if (value.isError()) { throw QInstaller::Error(QString::fromLatin1("Exception while loading component " - "script: '%1'. (%2)").arg(scriptFile.fileName(), value.toString().isEmpty() ? - QString::fromLatin1("Unknown error.") : value.toString())); + "script at \"%1\": %2").arg(QDir::toNativeSeparators(scriptFile.fileName()), + value.toString().isEmpty() ? + QString::fromLatin1("Unknown error.") : value.toString())); } const QString toLocation(QString::fromLatin1("%1/%2/%3").arg(targetDir, info.name, script)); @@ -387,7 +390,7 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QStringList &packa QFileInfoList entries; foreach (const QString &packagesDirectory, packagesDirectories) entries.append(QDir(packagesDirectory).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)); - for (QFileInfoList::const_iterator it = entries.begin(); it != entries.end(); ++it) { + for (QFileInfoList::const_iterator it = entries.constBegin(); it != entries.constEnd(); ++it) { if (filterType == Exclude) { // Check for current file in exclude list, if found, skip it and remove it from exclude list if (packagesToFilter->contains(it->fileName())) { @@ -400,14 +403,14 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QStringList &packa continue; packagesToFilter->removeAll(it->fileName()); } - qDebug() << QString::fromLatin1("found subdirectory '%1'").arg(it->fileName()); + qDebug() << "Found subdirectory" << it->fileName(); // because the filter is QDir::Dirs - filename means the name of the subdirectory if (it->fileName().contains(QLatin1Char('-'))) { if (ignoreInvalidPackages) continue; - throw QInstaller::Error(QString::fromLatin1("Component '%1' must not contain '-'. This is not " + throw QInstaller::Error(QString::fromLatin1("Component \"%1\" must not contain '-'. This is not " "allowed, because dashes are used as the separator between the component name and the " - "version number internally.").arg(it->fileName())); + "version number internally.").arg(QDir::toNativeSeparators(it->fileName()))); } QFile file(QString::fromLatin1("%1/meta/package.xml").arg(it->filePath())); @@ -415,8 +418,8 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QStringList &packa if (!fileInfo.exists()) { if (ignoreInvalidPackages) continue; - throw QInstaller::Error(QString::fromLatin1("Component '%1' does not contain a package " - "description (meta/package.xml is missing).").arg(it->fileName())); + throw QInstaller::Error(QString::fromLatin1("Component \"%1\" does not contain a package " + "description (meta/package.xml is missing).").arg(QDir::toNativeSeparators(it->fileName()))); } file.open(QIODevice::ReadOnly); @@ -428,21 +431,23 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QStringList &packa if (!doc.setContent(&file, &error, &errorLine, &errorColumn)) { if (ignoreInvalidPackages) continue; - throw QInstaller::Error(QString::fromLatin1("Component package description in '%1' is invalid. " - "Error at line: %2, column: %3 -> %4").arg(fileInfo.absoluteFilePath(), QString::number(errorLine), - QString::number(errorColumn), error)); + throw QInstaller::Error(QString::fromLatin1("Component package description in \"%1\" is invalid. " + "Error at line: %2, column: %3 -> %4").arg(QDir::toNativeSeparators(fileInfo.absoluteFilePath()), + QString::number(errorLine), + QString::number(errorColumn), error)); } const QDomElement packageElement = doc.firstChildElement(QLatin1String("Package")); const QString name = packageElement.firstChildElement(QLatin1String("Name")).text(); if (!name.isEmpty() && name != it->fileName()) { - qWarning() << QString::fromLatin1("The <Name> tag in the '%1' is ignored - the installer uses the " - "path element right before the 'meta' ('%2').").arg(fileInfo.absoluteFilePath(), it->fileName()); + qWarning().nospace() << "The <Name> tag in the file " << fileInfo.absoluteFilePath() + << " is ignored - the installer uses the path element right before the 'meta'" + << " (" << it->fileName() << ")"; } QString releaseDate = packageElement.firstChildElement(QLatin1String("ReleaseDate")).text(); if (releaseDate.isEmpty()) { - qWarning("Release date for '%s' is empty! Using the current date instead.", + qWarning("Release date for \"%s\" is empty! Using the current date instead.", qPrintable(fileInfo.absoluteFilePath())); releaseDate = QDate::currentDate().toString(Qt::ISODate); } @@ -450,8 +455,9 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QStringList &packa if (!QDate::fromString(releaseDate, Qt::ISODate).isValid()) { if (ignoreInvalidPackages) continue; - throw QInstaller::Error(QString::fromLatin1("Release date for '%1' is invalid! <ReleaseDate>%2" - "</ReleaseDate>. Supported format: YYYY-MM-DD").arg(fileInfo.absoluteFilePath(), releaseDate)); + throw QInstaller::Error(QString::fromLatin1("Release date for \"%1\" is invalid! <ReleaseDate>%2" + "</ReleaseDate>. Supported format: YYYY-MM-DD").arg(QDir::toNativeSeparators(fileInfo.absoluteFilePath()), + releaseDate)); } PackageInfo info; @@ -460,15 +466,15 @@ PackageInfoVector QInstallerTools::createListOfPackages(const QStringList &packa if (!QRegExp(QLatin1String("[0-9]+((\\.|-)[0-9]+)*")).exactMatch(info.version)) { if (ignoreInvalidPackages) continue; - throw QInstaller::Error(QString::fromLatin1("Component version for '%1' is invalid! <Version>%2</Version>") - .arg(fileInfo.absoluteFilePath(), info.version)); + throw QInstaller::Error(QString::fromLatin1("Component version for \"%1\" is invalid! <Version>%2</Version>") + .arg(QDir::toNativeSeparators(fileInfo.absoluteFilePath()), info.version)); } info.dependencies = packageElement.firstChildElement(QLatin1String("Dependencies")).text() .split(QInstaller::commaRegExp(), QString::SkipEmptyParts); info.directory = it->filePath(); dict.push_back(info); - qDebug() << QString::fromLatin1("- it provides the package %1 - %2").arg(info.name, info.version); + qDebug() << "- it provides the package" << info.name << " - " << info.version; } if (!packagesToFilter->isEmpty() && packagesToFilter->at(0) != QString::fromLatin1( @@ -513,7 +519,7 @@ void QInstallerTools::compressMetaDirectories(const QString &repoDir, const QStr // use existing Updates.xml, if any QFile existingUpdatesXml(QFileInfo(QDir(repoDir), QLatin1String("Updates.xml")).absoluteFilePath()); if (!existingUpdatesXml.open(QIODevice::ReadOnly) || !doc.setContent(&existingUpdatesXml)) { - qDebug() << "Could not find Updates.xml"; + qDebug() << "Cannot find Updates.xml"; } else { root = doc.documentElement(); } @@ -532,7 +538,7 @@ void QInstallerTools::compressMetaDirectories(const QString &repoDir, const QStr const QString absPath = sd.absolutePath(); const QString fn = QLatin1String(versionPrefix.toLatin1() + "meta.7z"); const QString tmpTarget = repoDir + QLatin1String("/") +fn; - compressPaths(QStringList() << absPath, tmpTarget); + Lib7z::createArchive(tmpTarget, QStringList() << absPath, Lib7z::QTmpFile::No); // remove the files that got compressed QInstaller::removeFiles(absPath, true); @@ -543,8 +549,8 @@ void QInstallerTools::compressMetaDirectories(const QString &repoDir, const QStr writeSHA1ToNodeWithName(doc, elements, sha1Sum, path); const QString finalTarget = absPath + QLatin1String("/") + fn; if (!tmp.rename(finalTarget)) { - throw QInstaller::Error(QString::fromLatin1("Could not move '%1' to '%2'").arg(tmpTarget, - finalTarget)); + throw QInstaller::Error(QString::fromLatin1("Cannot move file \"%1\" to \"%2\".").arg( + QDir::toNativeSeparators(tmpTarget), QDir::toNativeSeparators(finalTarget))); } } @@ -563,7 +569,7 @@ void QInstallerTools::copyComponentData(const QStringList &packageDirs, const QS const QString namedRepoDir = QString::fromLatin1("%1/%2").arg(repoDir, name); if (!QDir().mkpath(namedRepoDir)) { - throw QInstaller::Error(QString::fromLatin1("Could not create repository folder for component '%1'") + throw QInstaller::Error(QString::fromLatin1("Cannot create repository directory for component \"%1\".") .arg(name)); } @@ -578,11 +584,10 @@ void QInstallerTools::copyComponentData(const QStringList &packageDirs, const QS if (Lib7z::isSupportedArchive(absoluteEntryFilePath)) { QFile tmp(absoluteEntryFilePath); QString target = QString::fromLatin1("%1/%3%2").arg(namedRepoDir, entry, info.version); - qDebug() << QString::fromLatin1("Copying archive from '%1' to '%2'").arg(tmp.fileName(), - target); + qDebug() << "Copying archive from" << tmp.fileName() << "to" << target; if (!tmp.copy(target)) { - throw QInstaller::Error(QString::fromLatin1("Could not copy '%1' to '%2': %3") - .arg(tmp.fileName(), target, tmp.errorString())); + throw QInstaller::Error(QString::fromLatin1("Cannot copy file \"%1\" to \"%2\": %3") + .arg(QDir::toNativeSeparators(tmp.fileName()), QDir::toNativeSeparators(target), tmp.errorString())); } compressedFiles.append(target); } else { @@ -591,7 +596,8 @@ void QInstallerTools::copyComponentData(const QStringList &packageDirs, const QS } else if (fileInfo.isDir()) { qDebug() << "Compressing data directory" << entry; QString target = QString::fromLatin1("%1/%3%2.7z").arg(namedRepoDir, entry, info.version); - QInstallerTools::compressPaths(QStringList() << dataDir.absoluteFilePath(entry), target); + Lib7z::createArchive(target, QStringList() << dataDir.absoluteFilePath(entry), + Lib7z::QTmpFile::No); compressedFiles.append(target); } else if (fileInfo.isSymLink()) { filesToCompress.append(dataDir.absoluteFilePath(entry)); @@ -603,7 +609,7 @@ void QInstallerTools::copyComponentData(const QStringList &packageDirs, const QS qDebug() << "Compressing files found in data directory:" << filesToCompress; QString target = QString::fromLatin1("%1/%3%2").arg(namedRepoDir, QLatin1String("content.7z"), info.version); - QInstallerTools::compressPaths(filesToCompress, target); + Lib7z::createArchive(target, filesToCompress, Lib7z::QTmpFile::No); compressedFiles.append(target); } diff --git a/tools/common/repositorygen.h b/tools/common/repositorygen.h index ecf5b9337..c369d5183 100644 --- a/tools/common/repositorygen.h +++ b/tools/common/repositorygen.h @@ -65,7 +65,6 @@ PackageInfoVector createListOfPackages(const QStringList &packagesDirectories, Q FilterType ftype); QHash<QString, QString> buildPathToVersionMapping(const PackageInfoVector &info); -void compressPaths(const QStringList &paths, const QString &archivePath); void compressMetaDirectories(const QString &repoDir, const QString &baseDir, const QHash<QString, QString> &versionMapping); diff --git a/tools/devtool/binarydump.cpp b/tools/devtool/binarydump.cpp index 4a6094e66..26e8260dd 100644 --- a/tools/devtool/binarydump.cpp +++ b/tools/devtool/binarydump.cpp @@ -47,19 +47,19 @@ int BinaryDump::dump(const QInstaller::ResourceCollectionManager &manager, const QDir targetDir(QFileInfo(target).absoluteFilePath()); if (targetDir.exists()) { if (!targetDir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) { - std::cerr << qPrintable(QString::fromLatin1("Target directory '%1' already exists and " - "is not empty.").arg(targetDir.path())) << std::endl; + std::cerr << qPrintable(QString::fromLatin1("Target directory \"%1\" already exists and " + "is not empty.").arg(QDir::toNativeSeparators(targetDir.path()))) << std::endl; return EXIT_FAILURE; } } else { if (!QDir().mkpath(targetDir.path())) { - std::cerr << qPrintable(QString::fromLatin1("Could not create '%1'.").arg(targetDir - .path())) << std::endl; + std::cerr << qPrintable(QString::fromLatin1("Cannot create \"%1\".").arg( + QDir::toNativeSeparators(targetDir.path()))) << std::endl; return EXIT_FAILURE; } } - QInstaller::CopyDirectoryOperation copyMetadata; + QInstaller::CopyDirectoryOperation copyMetadata(0); copyMetadata.setArguments(QStringList() << QLatin1String(":/") << (targetDir.path() + QLatin1Char('/'))); // Add "/" at the end to make operation work. if (!copyMetadata.performOperation()) { @@ -68,8 +68,8 @@ int BinaryDump::dump(const QInstaller::ResourceCollectionManager &manager, const } if (!targetDir.cd(QLatin1String("metadata"))) { - std::cerr << qPrintable(QString::fromLatin1("Could not switch to '%1/metadata'.") - .arg(targetDir.path())) << std::endl; + std::cerr << qPrintable(QString::fromLatin1("Cannot switch to \"%1/metadata\".") + .arg(QDir::toNativeSeparators(targetDir.path()))) << std::endl; return EXIT_FAILURE; } @@ -81,8 +81,8 @@ int BinaryDump::dump(const QInstaller::ResourceCollectionManager &manager, const QString error; QDomDocument doc; if (!doc.setContent(&updatesXml, &error)) { - throw QInstaller::Error(QString::fromLatin1("Could not read: '%1'. %2").arg(updatesXml - .fileName(), error)); + throw QInstaller::Error(QString::fromLatin1("Cannot read: \"%1\": %2").arg( + QDir::toNativeSeparators(updatesXml.fileName()), error)); } QHash<QString, QString> versionMap; @@ -113,7 +113,7 @@ int BinaryDump::dump(const QInstaller::ResourceCollectionManager &manager, const continue; if (!targetDir.mkpath(name)) { - throw QInstaller::Error(QString::fromLatin1("Could not create target dir: %1.") + throw QInstaller::Error(QString::fromLatin1("Cannot create target dir: %1.") .arg(targetDir.filePath(name))); } diff --git a/tools/devtool/binaryreplace.cpp b/tools/devtool/binaryreplace.cpp index 65f124a7a..910526b6a 100644 --- a/tools/devtool/binaryreplace.cpp +++ b/tools/devtool/binaryreplace.cpp @@ -39,7 +39,9 @@ #include <errors.h> #include <fileio.h> #include <fileutils.h> +#include <lib7z_extract.h> #include <lib7z_facade.h> +#include <lib7z_list.h> #include <QDir> #include <QFutureWatcher> @@ -81,19 +83,19 @@ int BinaryReplace::replace(const QString &source, const QString &target) .path; result = EXIT_SUCCESS; } catch (const Lib7z::SevenZipException& e) { - std::cerr << qPrintable(QString::fromLatin1("Error while extracting '%1': %2.") - .arg(newInstallerBasePath, e.message())) << std::endl; + std::cerr << qPrintable(QString::fromLatin1("Error while extracting \"%1\": %2") + .arg(QDir::toNativeSeparators(newInstallerBasePath), e.message())) << std::endl; } catch (...) { std::cerr << qPrintable(QString::fromLatin1("Unknown exception caught while " - "extracting '%1'.").arg(newInstallerBasePath)) << std::endl; + "extracting \"%1\".").arg(QDir::toNativeSeparators(newInstallerBasePath))) << std::endl; } } else { - std::cerr << qPrintable(QString::fromLatin1("Could not open '%1' for reading: %2.") - .arg(newInstallerBasePath, archive.errorString())) << std::endl; + std::cerr << qPrintable(QString::fromLatin1("Cannot open \"%1\" for reading: %2") + .arg(QDir::toNativeSeparators(newInstallerBasePath), archive.errorString())) << std::endl; } if (!archive.remove()) { - std::cerr << qPrintable(QString::fromLatin1("Could not delete file '%1': %2.") - .arg(newInstallerBasePath, archive.errorString())) << std::endl; + std::cerr << qPrintable(QString::fromLatin1("Cannot delete file \"%1\": %2") + .arg(QDir::toNativeSeparators(newInstallerBasePath), archive.errorString())) << std::endl; } if (result != EXIT_SUCCESS) return result; @@ -130,19 +132,19 @@ int BinaryReplace::replace(const QString &source, const QString &target) #endif QFile backup(installerBaseOld.fileName() + QLatin1String(".bak")); if (backup.exists() && (!backup.remove())) { - std::cerr << qPrintable(QString::fromLatin1("Could not delete '%1'. %2") - .arg(backup.fileName(), backup.errorString())) << std::endl; + std::cerr << qPrintable(QString::fromLatin1("Cannot delete \"%1\": %2") + .arg(QDir::toNativeSeparators(backup.fileName()), backup.errorString())) << std::endl; } const QString oldBasePath = installerBaseOld.fileName(); if (!installerBaseOld.rename(oldBasePath + QLatin1String(".bak"))) { - std::cerr << qPrintable(QString::fromLatin1("Could not rename '%1' to '%2'. %3") + std::cerr << qPrintable(QString::fromLatin1("Cannot rename \"%1\" to \"%2\": %3") .arg(oldBasePath, oldBasePath + QLatin1String(".bak"), installerBaseOld.errorString())) << std::endl; } if (!installerBaseNew.rename(oldBasePath)) { - std::cerr << qPrintable(QString::fromLatin1("Could not copy '%1' to '%2'. %3") + std::cerr << qPrintable(QString::fromLatin1("Cannot copy \"%1\" to \"%2\": %3") .arg(installerBaseNew.fileName(), oldBasePath, installerBaseNew.errorString())) << std::endl; } else { diff --git a/tools/devtool/main.cpp b/tools/devtool/main.cpp index df9b8bbc7..c9aaab71c 100644 --- a/tools/devtool/main.cpp +++ b/tools/devtool/main.cpp @@ -36,7 +36,6 @@ #include "operationrunner.h" #include <binarycontent.h> -#include <binaryformat.h> #include <binaryformatenginehandler.h> #include <errors.h> #include <fileio.h> @@ -49,39 +48,122 @@ #include <QFileInfo> #include <QResource> +#include <iomanip> #include <iostream> +struct Command +{ + const char* command; + const char* description; + qint32 argC; + const char* arguments; + const char* argDescription; +} Commands[] = { + { "dump", "Dumps the binary content that belongs to an installer or maintenance tool into " + "target directory.", 2, "<binary> <targetdirecory>", "The <binary> containing the data to " + "dump.\nThe <targetdirectory> to dump the data in." + }, + + { "update", "Updates existing installer or maintenance tool with a new installer base.", 2, + "<binary> <installerbase>", "The <binary> to update.\nThe <installerbase> to use as update." + }, + + { "operation", "Executes an operation with with a given mode and a list of arguments. ", 2, + "<binary> <mode,name,args,...>", "The <binary> to run the operation with.\n" + "<mode,name,args,...> 'mode' can be DO or UNDO. 'name' of the operation. 'args,...' " + "used to run the operation." + } +}; + +#define DESCRITION_LENGTH 60 +#define SETW_ALIGNLEFT(X) std::setw(X) << std::setiosflags(std::ios::left) + +static int fail(const QString &message) +{ + std::cerr << qPrintable(message) << " See 'devtool --help'." << std::endl; + return EXIT_FAILURE; +} + +static QStringList split(int index, const QString &description) +{ + QStringList result; + if (description.length() <= DESCRITION_LENGTH) + return result << description; + + const int lastIndexOf = description.left(index + DESCRITION_LENGTH) + .lastIndexOf(QLatin1Char(' ')); + result << description.left(lastIndexOf); + return result + split(lastIndexOf + 1, description.mid(lastIndexOf + 1)); +} + +// -- main + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); app.setApplicationVersion(QLatin1String("1.0.0")); - QCommandLineOption verbose(QLatin1String("verbose"), - QLatin1String("Verbose mode. Prints out more information.")); - QCommandLineOption dump(QLatin1String("dump"), - QLatin1String("Dumps the binary content that belongs to an installer or maintenance tool " - "into target."), QLatin1String("folder")); - QCommandLineOption run(QLatin1String("operation"), - QLatin1String("Executes an operation with a list of arguments. Mode can be DO or UNDO."), - QLatin1String("mode,name,args,...")); - QCommandLineOption update(QLatin1String("update"), - QLatin1String("Updates existing installer or maintenance tool with a new installer base."), - QLatin1String("file")); - QCommandLineParser parser; - parser.addHelpOption(); - parser.addVersionOption(); + QCommandLineOption help = parser.addHelpOption(); + QCommandLineOption version = parser.addVersionOption(); + QCommandLineOption verbose(QLatin1String("verbose"), QLatin1String("Verbose mode. Prints out " + "more information.")); parser.addOption(verbose); - parser.addOption(update); - parser.addOption(dump); - parser.addOption(run); - parser.addPositionalArgument(QLatin1String("binary"), QLatin1String("Existing installer or " - "maintenance tool.")); - parser.process(app.arguments()); - const QStringList arguments = parser.positionalArguments(); - if (arguments.isEmpty() || (arguments.count() > 1)) - parser.showHelp(EXIT_FAILURE); + parser.parse(app.arguments()); + if (parser.isSet(version)) { + parser.showVersion(); + return EXIT_SUCCESS; + } + + if (parser.isSet(help)) { + const QString command = parser.positionalArguments().value(0); + if (!command.isEmpty()) { + for (const auto &c : Commands) { + if (QLatin1String(c.command) == command) { + parser.clearPositionalArguments(); + parser.addPositionalArgument(QString::fromLatin1("%1 %2").arg(QLatin1String(c + .command), QLatin1String(c.arguments)), QLatin1String(c.argDescription)); + parser.showHelp(EXIT_SUCCESS); + } + } + return fail(QString::fromLatin1("\"%1\" is not a devtool command.").arg(command)); + } + + QString helpText = parser.helpText(); + helpText.insert(helpText.indexOf(QLatin1Char(']')) + 1, QLatin1String(" command <args>")); + std::cout << qPrintable(helpText) << std::endl; + std::cout << "Available commands (mutually exclusive):" << std::endl; + for (const auto &c : Commands) { + QStringList lines = split(0, QLatin1String(c.description)); + std::cout << SETW_ALIGNLEFT(2) << " " << SETW_ALIGNLEFT(16) << c.command + << SETW_ALIGNLEFT(DESCRITION_LENGTH) << qPrintable(lines.takeFirst()) << std::endl; + foreach (const QString &line, lines) { + std::cout << SETW_ALIGNLEFT(18) << QByteArray(18, ' ').constData() + << qPrintable(line) << std::endl; + } + } + std::cout << std::endl << "Use 'devtool --help <command>' to read about a specific command." + << std::endl; + return EXIT_SUCCESS; + } + + QStringList arguments = parser.positionalArguments(); + if (arguments.isEmpty()) + return fail(QLatin1String("Missing command.")); + + bool found = false; + const QString command = arguments.takeFirst(); + for (const auto &c : Commands) { + if ((found = (QLatin1String(c.command) == command))) { + if (arguments.count() != c.argC) + return fail(QString::fromLatin1("%1: wrong argument count.").arg(command)); + break; + } + } + + if (!found) + return fail(QString::fromLatin1("\"%1\" is not a devtool command.").arg(command)); QInstaller::init(); QInstaller::setVerbose(parser.isSet(verbose)); @@ -100,7 +182,7 @@ int main(int argc, char *argv[]) QInstaller::openForRead(&tmp); if (!tmp.seek(QInstaller::BinaryContent::findMagicCookie(&tmp, cookie) - sizeof(qint64))) - throw QInstaller::Error(QLatin1String("Could not seek to read magic marker.")); + throw QInstaller::Error(QLatin1String("Cannot seek to read magic marker.")); QInstaller::BinaryLayout layout; layout.magicMarker = QInstaller::retrieveInt64(&tmp); @@ -120,9 +202,9 @@ int main(int argc, char *argv[]) layout = QInstaller::BinaryContent::binaryLayout(&tmp, cookie); tmp.close(); - if (parser.isSet(update)) { + if (command == QLatin1String("update")) { BinaryReplace br(layout); // To update the binary we do not need any mapping. - return br.replace(parser.value(update), QFileInfo(arguments.first()) + return br.replace(arguments.last(), QFileInfo(arguments.first()) .absoluteFilePath()); } } @@ -145,28 +227,29 @@ int main(int argc, char *argv[]) const QByteArray ba = resource->readAll(); if (!QResource::registerResource((const uchar*) ba.data(), QLatin1String(":/metadata"))) - throw QInstaller::Error(QLatin1String("Could not register in-binary resource.")); + throw QInstaller::Error(QLatin1String("Cannot register in-binary resource.")); resourceMappings.append(ba); if (!isOpen) resource->close(); } - if (parser.isSet(dump)) { + if (command == QLatin1String("dump")) { // To dump the content we do not need the binary format engine. BinaryDump bd; - result = bd.dump(manager, parser.value(dump)); - } else if (parser.isSet(run)) { + result = bd.dump(manager, arguments.last()); + } else if (command == QLatin1String("operation")) { QInstaller::BinaryFormatEngineHandler::instance()->registerResources(manager .collections()); // setup the binary format engine OperationRunner runner(magicMarker, operations); - const QStringList arguments = parser.value(run).split(QLatin1Char(',')); + const QStringList arguments = arguments.last().split(QLatin1Char(',')); if (arguments.first() == QLatin1String("DO")) result = runner.runOperation(arguments.mid(1), OperationRunner::RunMode::Do); else if (arguments.first() == QLatin1String("UNDO")) result = runner.runOperation(arguments.mid(1), OperationRunner::RunMode::Undo); else - std::cerr << "Malformed argument: " << qPrintable(parser.value(run)) << std::endl; + std::cerr << "Malformed argument: " << qPrintable(arguments.last()) << std::endl; + } } catch (const QInstaller::Error &error) { std::cerr << qPrintable(error.message()) << std::endl; diff --git a/tools/devtool/operationrunner.cpp b/tools/devtool/operationrunner.cpp index 97bdfd7d7..41cc9d41b 100644 --- a/tools/devtool/operationrunner.cpp +++ b/tools/devtool/operationrunner.cpp @@ -34,7 +34,7 @@ #include "operationrunner.h" #include <errors.h> -#include <kdupdaterupdateoperationfactory.h> +#include <updateoperationfactory.h> #include <packagemanagercore.h> #include <QMetaObject> @@ -59,7 +59,7 @@ int OperationRunner::runOperation(QStringList arguments, RunMode mode) try { const QString name = arguments.takeFirst(); QScopedPointer<QInstaller::Operation> op(KDUpdater::UpdateOperationFactory::instance() - .create(name)); + .create(name, m_core)); if (!op) { std::cerr << "Cannot instantiate operation: " << qPrintable(name) << std::endl; return EXIT_FAILURE; @@ -71,8 +71,6 @@ int OperationRunner::runOperation(QStringList arguments, RunMode mode) connect(object, SIGNAL(outputTextChanged(QString)), this, SLOT(print(QString))); } op->setArguments(arguments); - op->setValue(QLatin1String("installer"), QVariant::fromValue(m_core)); - bool readyPerformed = false; if (mode == RunMode::Do) diff --git a/tools/repocompare/main.cpp b/tools/repocompare/main.cpp index af17b05ac..972c7916c 100644 --- a/tools/repocompare/main.cpp +++ b/tools/repocompare/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) RepositoryManager manager; manager.setProductionRepository(productionRepo); manager.setUpdateRepository(updateRepo); - a.connect(&manager, SIGNAL(repositoriesCompared()), &a, SLOT(quit())); + a.connect(&manager, &RepositoryManager::repositoriesCompared, &a, &QApplication::quit); qDebug() << "Waiting for server reply..."; a.exec(); qDebug() << "Writing into " << outputFile; diff --git a/tools/repocompare/mainwindow.cpp b/tools/repocompare/mainwindow.cpp index 8217d769a..27608f0e4 100644 --- a/tools/repocompare/mainwindow.cpp +++ b/tools/repocompare/mainwindow.cpp @@ -77,11 +77,11 @@ MainWindow::MainWindow(QWidget *parent) : ui->productionRepo->insertItems(0, settings.value(productionIdentifier).toStringList()); ui->updateRepo->insertItems(0, settings.value(updateIdentifier).toStringList()); - connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(close())); - connect(ui->productionButton, SIGNAL(clicked()), this, SLOT(getProductionRepository())); - connect(ui->updateButton, SIGNAL(clicked()), this, SLOT(getUpdateRepository())); - connect(ui->exportButton, SIGNAL(clicked()), this, SLOT(createExportFile())); - connect(&manager, SIGNAL(repositoriesCompared()), this, SLOT(displayRepositories())); + connect(ui->actionExit, &QAction::triggered, this, &QWidget::close); + connect(ui->productionButton, &QAbstractButton::clicked, this, &MainWindow::getProductionRepository); + connect(ui->updateButton, &QAbstractButton::clicked, this, &MainWindow::getUpdateRepository); + connect(ui->exportButton, &QAbstractButton::clicked, this, &MainWindow::createExportFile); + connect(&manager, &RepositoryManager::repositoriesCompared, this, &MainWindow::displayRepositories); } MainWindow::~MainWindow() diff --git a/tools/repocompare/mainwindow.h b/tools/repocompare/mainwindow.h index ecba780dc..ac155b0bd 100644 --- a/tools/repocompare/mainwindow.h +++ b/tools/repocompare/mainwindow.h @@ -42,10 +42,11 @@ #include <QMainWindow> #include <QNetworkAccessManager> +QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } - +QT_END_NAMESPACE class MainWindow : public QMainWindow { diff --git a/tools/repocompare/repositorymanager.cpp b/tools/repocompare/repositorymanager.cpp index 125749882..68faaf124 100644 --- a/tools/repocompare/repositorymanager.cpp +++ b/tools/repocompare/repositorymanager.cpp @@ -33,6 +33,7 @@ #include "repositorymanager.h" #include <QDebug> +#include <QDir> #include <QFile> #include <QStringList> #include <QUrl> @@ -66,7 +67,7 @@ RepositoryManager::RepositoryManager(QObject *parent) : QObject(parent) { manager = new QNetworkAccessManager(this); - connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(receiveRepository(QNetworkReply*))); + connect(manager, &QNetworkAccessManager::finished, this, &RepositoryManager::receiveRepository); productionMap.clear(); updateMap.clear(); } @@ -185,13 +186,15 @@ void RepositoryManager::writeUpdateFile(const QString &fileName) { QFile file(fileName); if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) { - QMessageBox::critical(0, QLatin1String("Error"), QLatin1String("Could not open File for saving")); + QMessageBox::critical(0, QLatin1String("Error"), + QString::fromLatin1("Cannot open file \"%1\" for writing: %2").arg( + QDir::toNativeSeparators(fileName), file.errorString())); return; } QStringList items; - for (QMap<QString, ComponentDescription>::const_iterator it = updateMap.begin(); it != updateMap.end(); - ++it) { + for (QMap<QString, ComponentDescription>::const_iterator it = updateMap.constBegin(); + it != updateMap.constEnd(); ++it) { if (it.value().update) items.append(it.key()); } diff --git a/tools/repogen/repogen.cpp b/tools/repogen/repogen.cpp index dbbf3e1f7..92ec3d04c 100644 --- a/tools/repogen/repogen.cpp +++ b/tools/repogen/repogen.cpp @@ -35,7 +35,7 @@ #include <errors.h> #include <fileutils.h> #include <init.h> -#include <kdupdater.h> +#include <updater.h> #include <settings.h> #include <utils.h> #include <lib7z_facade.h> @@ -51,7 +51,6 @@ #define QUOTE_(x) #x #define QUOTE(x) QUOTE_(x) -using namespace Lib7z; using namespace QInstaller; static void printUsage() @@ -193,7 +192,7 @@ int main(int argc, char** argv) QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty()) { throw QInstaller::Error(QCoreApplication::translate("QInstaller", - "Repository target folder %1 already exists!").arg(repositoryDir)); + "Repository target directory \"%1\" already exists.").arg(QDir::toNativeSeparators(repositoryDir))); } QInstallerTools::PackageInfoVector packages = QInstallerTools::createListOfPackages(packagesDirectories, @@ -206,7 +205,7 @@ int main(int argc, char** argv) const QDomElement root = doc.documentElement(); if (root.tagName() != QLatin1String("Updates")) { throw QInstaller::Error(QCoreApplication::translate("QInstaller", - "Invalid content in '%1'.").arg(file.fileName())); + "Invalid content in \"%1\".").arg(QDir::toNativeSeparators(file.fileName()))); } file.close(); // close the file, we read the content already @@ -221,7 +220,7 @@ int main(int argc, char** argv) for (int j = 0; j < c2.count(); ++j) { if (c2.at(j).toElement().tagName() == scName) info.name = c2.at(j).toElement().text(); - else if (c2.at(j).toElement().tagName() == scRemoteVersion) + else if (c2.at(j).toElement().tagName() == scVersion) info.version = c2.at(j).toElement().text(); } hash.insert(info.name, info); @@ -239,7 +238,7 @@ int main(int argc, char** argv) } if (packages.isEmpty()) { - std::cout << QString::fromLatin1("Could not find new components to update '%1'.") + std::cout << QString::fromLatin1("Cannot find new components to update \"%1\".") .arg(repositoryDir) << std::endl; return EXIT_SUCCESS; } diff --git a/tools/tools.pro b/tools/tools.pro index 25a646252..cf72dba39 100644 --- a/tools/tools.pro +++ b/tools/tools.pro @@ -1,4 +1,3 @@ -CONFIG += ordered TEMPLATE = subdirs SUBDIRS += \ |