2011-02-21 16:30:31 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt SDK**
|
|
|
|
**
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).*
|
|
|
|
**
|
|
|
|
** Contact: Nokia Corporation qt-info@nokia.com**
|
|
|
|
**
|
|
|
|
** No Commercial Usage
|
|
|
|
**
|
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
** this package.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception version
|
|
|
|
** 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** If you are unsure which license is appropriate for your use, please contact
|
|
|
|
** (qt-info@nokia.com).
|
|
|
|
**
|
|
|
|
**************************************************************************/
|
2011-09-30 12:17:38 +02:00
|
|
|
#include "installerbase_p.h"
|
|
|
|
|
2011-03-03 16:03:57 +01:00
|
|
|
#include "installerbasecommons.h"
|
|
|
|
#include "tabcontroller.h"
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-09-30 12:17:38 +02:00
|
|
|
#include <common/binaryformat.h>
|
|
|
|
#include <common/errors.h>
|
|
|
|
#include <common/fileutils.h>
|
|
|
|
#include <common/utils.h>
|
|
|
|
#include <fsengineserver.h>
|
|
|
|
#include <init.h>
|
|
|
|
#include <lib7z_facade.h>
|
|
|
|
#include <operationrunner.h>
|
2011-06-15 12:39:03 +02:00
|
|
|
#include <packagemanagercore.h>
|
2011-09-30 12:17:38 +02:00
|
|
|
#include <packagemanagergui.h>
|
|
|
|
#include <qinstallerglobal.h>
|
2011-06-20 22:00:34 +02:00
|
|
|
#include <settings.h>
|
2011-09-30 12:17:38 +02:00
|
|
|
#include <updater.h>
|
2011-03-10 15:50:33 +01:00
|
|
|
|
2011-11-19 00:00:52 +01:00
|
|
|
#include <kdselfrestarter.h>
|
|
|
|
#include <kdrunoncechecker.h>
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-09-30 12:17:38 +02:00
|
|
|
#include <QtCore/QTranslator>
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
#include <QtNetwork/QNetworkProxyFactory>
|
|
|
|
|
2011-11-23 15:26:28 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2011-09-30 12:24:57 +02:00
|
|
|
#define QUOTE_(x) #x
|
|
|
|
#define QUOTE(x) QUOTE_(x)
|
|
|
|
#define VERSION "Installerbase SHA1: \"" QUOTE(_GIT_SHA1_) "\" , Build date: " QUOTE(__DATE__) "."
|
2011-07-04 22:47:25 +02:00
|
|
|
|
2011-02-21 16:30:31 +01:00
|
|
|
using namespace QInstaller;
|
|
|
|
using namespace QInstallerCreator;
|
|
|
|
|
2011-11-15 12:37:01 +01:00
|
|
|
static QSet<Repository> repositories(const QStringList &arguments, const int index)
|
2011-05-10 11:53:36 +02:00
|
|
|
{
|
2011-11-15 12:37:01 +01:00
|
|
|
QSet<Repository> set;
|
2011-05-10 11:53:36 +02:00
|
|
|
if (index < arguments.size()) {
|
|
|
|
QStringList items = arguments.at(index).split(QLatin1Char(','));
|
2011-05-10 11:54:17 +02:00
|
|
|
foreach (const QString &item, items) {
|
2011-11-15 12:37:01 +01:00
|
|
|
set.insert(Repository(item, false));
|
2011-05-10 11:53:36 +02:00
|
|
|
verbose() << "Adding custom repository:" << item << std::endl;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std::cerr << "No repository specified" << std::endl;
|
|
|
|
}
|
2011-11-15 12:37:01 +01:00
|
|
|
return set;
|
2011-05-10 11:53:36 +02:00
|
|
|
}
|
|
|
|
|
2011-11-22 17:52:59 +01:00
|
|
|
|
|
|
|
// -- main
|
2011-11-21 17:32:29 +01:00
|
|
|
|
2011-02-21 16:30:31 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
qsrand(QDateTime::currentDateTime().toTime_t());
|
|
|
|
const KDSelfRestarter restarter(argc, argv);
|
|
|
|
KDRunOnceChecker runCheck(QLatin1String("lockmyApp1234865.lock"));
|
|
|
|
|
2011-11-25 16:05:08 +01:00
|
|
|
QStringList args = QInstaller::parseCommandLineArgs(argc, argv);
|
2011-02-21 16:30:31 +01:00
|
|
|
try {
|
2011-09-30 12:24:57 +02:00
|
|
|
if (args.contains(QLatin1String("--version"))) {
|
2011-11-22 17:52:59 +01:00
|
|
|
InstallerBase::showVersion(QLatin1String(VERSION));
|
2011-09-30 12:24:57 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-18 13:24:28 +02:00
|
|
|
// this is the FSEngineServer as an admin rights process upon request:
|
|
|
|
if (args.count() >= 3 && args[1] == QLatin1String("--startserver")) {
|
2011-07-29 16:10:54 +02:00
|
|
|
MyCoreApplication app(argc, argv);
|
2011-05-18 13:24:28 +02:00
|
|
|
FSEngineServer* const server = new FSEngineServer(args[2].toInt());
|
|
|
|
if (args.count() >= 4)
|
|
|
|
server->setAuthorizationKey(args[3]);
|
|
|
|
QObject::connect(server, SIGNAL(destroyed()), &app, SLOT(quit()));
|
|
|
|
return app.exec();
|
|
|
|
}
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-05-18 13:24:28 +02:00
|
|
|
// Make sure we honor the system's proxy settings
|
|
|
|
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
|
|
|
QUrl proxyUrl(QString::fromLatin1(qgetenv("http_proxy")));
|
|
|
|
if (proxyUrl.isValid()) {
|
2011-05-18 13:31:39 +02:00
|
|
|
QNetworkProxy proxy(QNetworkProxy::HttpProxy, proxyUrl.host(), proxyUrl.port(),
|
|
|
|
proxyUrl.userName(), proxyUrl.password());
|
2011-05-18 13:24:28 +02:00
|
|
|
QNetworkProxy::setApplicationProxy(proxy);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (args.contains(QLatin1String("--proxy")))
|
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
|
|
|
#endif
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-05-18 13:24:28 +02:00
|
|
|
if (args.contains(QLatin1String("--checkupdates"))) {
|
2011-07-29 16:10:54 +02:00
|
|
|
MyCoreApplication app(argc, argv);
|
2011-05-18 13:24:28 +02:00
|
|
|
if (runCheck.isRunning(KDRunOnceChecker::ProcessList))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Updater u;
|
2011-05-18 13:31:39 +02:00
|
|
|
u.setVerbose(args.contains(QLatin1String("--verbose")));
|
|
|
|
return u.checkForUpdates() ? 0 : 1;
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
2011-09-14 17:41:54 +02:00
|
|
|
if (args.contains(QLatin1String("--runoperation"))
|
2011-09-06 16:12:18 +02:00
|
|
|
|| args.contains(QLatin1String("--undooperation"))) {
|
2011-09-14 16:03:28 +02:00
|
|
|
MyCoreApplication app(argc, argv);
|
2011-09-06 16:12:18 +02:00
|
|
|
OperationRunner o;
|
|
|
|
o.setVerbose(args.contains(QLatin1String("--verbose")));
|
|
|
|
return o.runOperation(args);
|
|
|
|
}
|
|
|
|
|
2011-10-04 12:46:04 +02:00
|
|
|
if (args.contains(QLatin1String("--update-installerbase"))) {
|
|
|
|
MyCoreApplication app(argc, argv);
|
|
|
|
if (runCheck.isRunning(KDRunOnceChecker::ProcessList))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return InstallerBase().replaceMaintenanceToolBinary(args);
|
|
|
|
}
|
|
|
|
|
2011-05-18 21:26:21 +02:00
|
|
|
// from here, the "normal" installer binary is running
|
2011-07-29 16:10:54 +02:00
|
|
|
MyApplication app(argc, argv);
|
2011-11-25 16:05:08 +01:00
|
|
|
args = app.arguments();
|
2011-05-18 21:26:21 +02:00
|
|
|
|
2011-02-21 16:30:31 +01:00
|
|
|
if (runCheck.isRunning(KDRunOnceChecker::ProcessList)) {
|
|
|
|
if (runCheck.isRunning(KDRunOnceChecker::Lockfile))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (runCheck.isRunning(KDRunOnceChecker::ProcessList))
|
|
|
|
Sleep::sleep(1);
|
|
|
|
}
|
|
|
|
|
2011-11-22 17:52:59 +01:00
|
|
|
if (args.contains(QLatin1String("--verbose")) || args.contains(QLatin1String("Verbose"))) {
|
|
|
|
app.setVerbose();
|
2011-02-21 16:30:31 +01:00
|
|
|
QInstaller::setVerbose(true);
|
2011-11-22 17:52:59 +01:00
|
|
|
}
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
// install the default translator
|
|
|
|
const QString localeFile =
|
|
|
|
QString::fromLatin1(":/translations/qt_%1").arg(QLocale::system().name());
|
|
|
|
{
|
|
|
|
QTranslator* const translator = new QTranslator(&app);
|
|
|
|
translator->load(localeFile);
|
|
|
|
app.installTranslator(translator);
|
|
|
|
}
|
|
|
|
|
|
|
|
// install "our" default translator
|
|
|
|
const QString ourLocaleFile =
|
|
|
|
QString::fromLatin1(":/translations/%1.qm").arg(QLocale().name().toLower());
|
2011-11-25 14:09:06 +01:00
|
|
|
if (QFile::exists(ourLocaleFile)) {
|
2011-02-21 16:30:31 +01:00
|
|
|
QTranslator* const translator = new QTranslator(&app);
|
|
|
|
translator->load(ourLocaleFile);
|
|
|
|
app.installTranslator(translator);
|
|
|
|
}
|
|
|
|
|
2011-03-04 15:51:23 +01:00
|
|
|
if (QInstaller::isVerbose()) {
|
2011-09-30 12:24:57 +02:00
|
|
|
verbose() << VERSION << std::endl;
|
|
|
|
verbose() << "Arguments: " << args << std::endl;
|
|
|
|
verbose() << "Resource tree before loading the in-binary resource: " << std::endl;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-03-04 15:51:23 +01:00
|
|
|
QDir dir(QLatin1String(":/"));
|
|
|
|
foreach (const QString &i, dir.entryList()) {
|
|
|
|
const QByteArray ba = i.toUtf8();
|
2011-09-30 12:24:57 +02:00
|
|
|
verbose() << " :/" << ba.constData() << std::endl;
|
2011-03-04 15:51:23 +01:00
|
|
|
}
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// register custom operations before reading the binary content cause they may used in
|
2011-03-04 15:51:23 +01:00
|
|
|
// the uninstaller for the recorded list of during the installation performed operations
|
2011-02-21 16:30:31 +01:00
|
|
|
QInstaller::init();
|
|
|
|
|
|
|
|
// load the embedded binary resource
|
|
|
|
BinaryContent content = BinaryContent::readFromApplicationFile();
|
|
|
|
content.registerEmbeddedQResources();
|
|
|
|
|
2011-03-04 15:51:23 +01:00
|
|
|
// instantiate the installer we are actually going to use
|
2011-06-14 16:24:50 +02:00
|
|
|
QInstaller::PackageManagerCore core(content.magicmaker(), content.performedOperations());
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-03-04 15:51:23 +01:00
|
|
|
if (QInstaller::isVerbose()) {
|
2011-09-30 12:24:57 +02:00
|
|
|
verbose() << "Resource tree after loading the in-binary resource: " << std::endl;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-03-04 15:51:23 +01:00
|
|
|
QDir dir = QDir(QLatin1String(":/"));
|
|
|
|
foreach (const QString &i, dir.entryList())
|
2011-09-30 12:24:57 +02:00
|
|
|
verbose() << QString::fromLatin1(" :/%1").arg(i) << std::endl;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-03-04 15:51:23 +01:00
|
|
|
dir = QDir(QLatin1String(":/metadata/"));
|
|
|
|
foreach (const QString &i, dir.entryList())
|
2011-09-30 12:24:57 +02:00
|
|
|
verbose() << QString::fromLatin1(" :/metadata/%1").arg(i) << std::endl;
|
2011-03-04 15:51:23 +01:00
|
|
|
}
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
QString controlScript;
|
|
|
|
QHash<QString, QString> params;
|
|
|
|
for (int i = 1; i < args.size(); ++i) {
|
|
|
|
const QString &argument = args.at(i);
|
|
|
|
if (argument.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (argument.contains(QLatin1Char('='))) {
|
|
|
|
const QString name = argument.section(QLatin1Char('='), 0, 0);
|
|
|
|
const QString value = argument.section(QLatin1Char('='), 1, 1);
|
|
|
|
params.insert(name, value);
|
2011-06-14 16:24:50 +02:00
|
|
|
core.setValue(name, value);
|
2011-02-21 16:30:31 +01:00
|
|
|
} else if (argument == QLatin1String("--script") || argument == QLatin1String("Script")) {
|
|
|
|
++i;
|
|
|
|
if (i < args.size()) {
|
|
|
|
controlScript = args.at(i);
|
|
|
|
if (!QFileInfo(controlScript).exists())
|
2011-06-14 16:24:50 +02:00
|
|
|
return PackageManagerCore::Failure;
|
2011-02-21 16:30:31 +01:00
|
|
|
} else {
|
2011-06-14 16:24:50 +02:00
|
|
|
return PackageManagerCore::Failure;
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
} else if (argument == QLatin1String("--verbose") || argument == QLatin1String("Verbose")) {
|
2011-06-14 16:24:50 +02:00
|
|
|
core.setVerbose(true);
|
2011-02-21 16:30:31 +01:00
|
|
|
} else if (argument == QLatin1String("--proxy")) {
|
2011-05-18 13:24:28 +02:00
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
2011-02-21 16:30:31 +01:00
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(true);
|
2011-05-18 13:24:28 +02:00
|
|
|
#endif
|
2011-02-21 16:30:31 +01:00
|
|
|
} else if (argument == QLatin1String("--show-virtual-components")
|
|
|
|
|| argument == QLatin1String("ShowVirtualComponents")) {
|
|
|
|
QFont f;
|
|
|
|
f.setItalic(true);
|
2011-06-14 16:24:50 +02:00
|
|
|
PackageManagerCore::setVirtualComponentsFont(f);
|
|
|
|
PackageManagerCore::setVirtualComponentsVisible(true);
|
2011-03-03 16:03:57 +01:00
|
|
|
} else if ((argument == QLatin1String("--updater")
|
2011-06-14 16:24:50 +02:00
|
|
|
|| argument == QLatin1String("Updater")) && core.isUninstaller()) {
|
|
|
|
core.setUpdater();
|
2011-03-03 16:03:57 +01:00
|
|
|
} else if ((argument == QLatin1String("--manage-packages")
|
2011-06-14 16:24:50 +02:00
|
|
|
|| argument == QLatin1String("ManagePackages")) && core.isUninstaller()) {
|
|
|
|
core.setPackageManager();
|
2011-02-21 16:30:31 +01:00
|
|
|
} else if (argument == QLatin1String("--help") || argument == QLatin1String("-h")) {
|
2011-11-22 17:52:59 +01:00
|
|
|
InstallerBase::showUsage();
|
2011-06-14 16:24:50 +02:00
|
|
|
return PackageManagerCore::Success;
|
2011-02-21 16:30:31 +01:00
|
|
|
} else if (argument == QLatin1String("--addTempRepository")
|
|
|
|
|| argument == QLatin1String("--setTempRepository")) {
|
|
|
|
++i;
|
2011-11-15 12:37:01 +01:00
|
|
|
QSet<Repository> repoList = repositories(args, i);
|
2011-05-10 11:53:36 +02:00
|
|
|
if (repoList.isEmpty())
|
2011-06-14 16:24:50 +02:00
|
|
|
return PackageManagerCore::Failure;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
// We cannot use setRemoteRepositories as that is a synchronous call which "
|
|
|
|
// tries to get the data from server and this isn't what we want at this point
|
|
|
|
const bool replace = (argument == QLatin1String("--setTempRepository"));
|
2011-06-14 16:24:50 +02:00
|
|
|
core.setTemporaryRepositories(repoList, replace);
|
2011-05-10 11:53:36 +02:00
|
|
|
} else if (argument == QLatin1String("--addRepository")) {
|
|
|
|
++i;
|
2011-11-15 12:37:01 +01:00
|
|
|
QSet<Repository> repoList = repositories(args, i);
|
2011-05-10 11:53:36 +02:00
|
|
|
if (repoList.isEmpty())
|
2011-06-14 16:24:50 +02:00
|
|
|
return PackageManagerCore::Failure;
|
2011-11-15 12:37:01 +01:00
|
|
|
core.addUserRepositories(repoList);
|
2011-03-15 20:19:14 +01:00
|
|
|
} else if (argument == QLatin1String("--no-force-installations")) {
|
2011-06-14 16:24:50 +02:00
|
|
|
PackageManagerCore::setNoForceInstallation(true);
|
2011-02-21 16:30:31 +01:00
|
|
|
} else {
|
2011-11-17 12:46:41 +01:00
|
|
|
std::cerr << "Unknown option: " << argument << std::endl;
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the wizard gui
|
|
|
|
TabController controller(0);
|
2011-06-14 16:24:50 +02:00
|
|
|
controller.setManager(&core);
|
|
|
|
controller.setManagerParams(params);
|
2011-02-21 16:30:31 +01:00
|
|
|
controller.setControlScript(controlScript);
|
|
|
|
|
2011-06-14 16:24:50 +02:00
|
|
|
if (core.isInstaller()) {
|
|
|
|
controller.setGui(new InstallerGui(&core));
|
2011-02-21 16:30:31 +01:00
|
|
|
} else {
|
2011-06-14 16:24:50 +02:00
|
|
|
controller.setGui(new MaintenanceGui(&core));
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|
|
|
|
|
2011-06-14 16:24:50 +02:00
|
|
|
PackageManagerCore::Status status = PackageManagerCore::Status(controller.init());
|
|
|
|
if (status != PackageManagerCore::Success)
|
2011-03-14 17:42:15 +01:00
|
|
|
return status;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
const int result = app.exec();
|
|
|
|
if (result != 0)
|
|
|
|
return result;
|
|
|
|
|
2011-06-14 16:24:50 +02:00
|
|
|
if (core.finishedWithSuccess())
|
|
|
|
return PackageManagerCore::Success;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-06-14 16:24:50 +02:00
|
|
|
status = core.status();
|
2011-02-21 16:30:31 +01:00
|
|
|
switch (status) {
|
2011-06-14 16:24:50 +02:00
|
|
|
case PackageManagerCore::Success:
|
2011-03-10 15:50:33 +01:00
|
|
|
return status;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
2011-06-14 16:24:50 +02:00
|
|
|
case PackageManagerCore::Canceled:
|
2011-03-10 15:50:33 +01:00
|
|
|
return status;
|
2011-02-21 16:30:31 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-06-14 16:24:50 +02:00
|
|
|
return PackageManagerCore::Failure;
|
2011-02-21 16:30:31 +01:00
|
|
|
} catch(const Error &e) {
|
|
|
|
std::cerr << qPrintable(e.message()) << std::endl;
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
} catch(...) {
|
|
|
|
std::cerr << "Unknown error, aborting." << std::endl;
|
|
|
|
}
|
|
|
|
|
2011-06-14 16:24:50 +02:00
|
|
|
return PackageManagerCore::Failure;
|
2011-02-21 16:30:31 +01:00
|
|
|
}
|