2016-02-25 20:19:27 +00:00
|
|
|
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
|
|
|
// Copyright (C) 2010 Winch Gate Property Limited
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include "stdpch.h"
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "configfile.h"
|
2016-06-12 13:40:38 +00:00
|
|
|
#include "migratedialog.h"
|
|
|
|
#include "installdialog.h"
|
|
|
|
#include "uninstalldialog.h"
|
2016-05-16 09:11:40 +00:00
|
|
|
#include "operationdialog.h"
|
2016-06-19 18:50:23 +00:00
|
|
|
#include "utils.h"
|
2016-02-25 20:19:27 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef QT_STATICPLUGIN
|
|
|
|
|
|
|
|
#include <QtPlugin>
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN32)
|
|
|
|
Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
|
|
|
|
#elif defined(Q_OS_UNIX)
|
|
|
|
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Q_IMPORT_PLUGIN(QICOPlugin)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG_NEW
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
#endif
|
|
|
|
|
2016-07-27 09:54:35 +00:00
|
|
|
// copy all specified files from current directory to destination directory
|
|
|
|
bool copyInstallerFiles(const QStringList &files, const QString &destination)
|
|
|
|
{
|
|
|
|
QString path = QApplication::applicationDirPath();
|
|
|
|
|
|
|
|
foreach(const QString &file, files)
|
|
|
|
{
|
|
|
|
// convert to absolute path
|
|
|
|
QString srcPath = path + "/" + file;
|
|
|
|
QString dstPath = destination + "/" + file;
|
|
|
|
|
|
|
|
if (QFile::exists(srcPath))
|
|
|
|
{
|
|
|
|
if (QFile::exists(dstPath))
|
|
|
|
{
|
|
|
|
if (!QFile::remove(dstPath))
|
|
|
|
{
|
|
|
|
qDebug() << "Unable to delete" << dstPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!QFile::copy(srcPath, dstPath))
|
|
|
|
{
|
|
|
|
qDebug() << "Unable to copy" << srcPath << "to" << dstPath;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-25 20:19:27 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
2016-05-14 16:53:09 +00:00
|
|
|
_CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
|
2016-02-25 20:19:27 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-14 06:15:31 +00:00
|
|
|
#ifdef Q_OS_WIN
|
2016-09-16 17:24:43 +00:00
|
|
|
CCOMHelper comHelper;
|
2016-09-14 06:15:31 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-25 20:19:27 +00:00
|
|
|
NLMISC::CApplicationContext appContext;
|
|
|
|
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
QApplication::setApplicationName("Ryzom");
|
|
|
|
QApplication::setApplicationVersion(RYZOM_VERSION);
|
|
|
|
QApplication::setWindowIcon(QIcon(":/icons/ryzom.ico"));
|
|
|
|
|
|
|
|
QLocale locale = QLocale::system();
|
|
|
|
|
|
|
|
// load application translations
|
|
|
|
QTranslator localTranslator;
|
2016-09-20 15:37:02 +00:00
|
|
|
if (localTranslator.load(locale, "ryzom_installer", "_", ":/translations"))
|
2016-02-25 20:19:27 +00:00
|
|
|
{
|
|
|
|
QApplication::installTranslator(&localTranslator);
|
|
|
|
}
|
|
|
|
|
|
|
|
// load Qt default translations
|
|
|
|
QTranslator qtTranslator;
|
2016-09-20 15:37:02 +00:00
|
|
|
if (qtTranslator.load(locale, "qtbase", "_", ":/translations"))
|
2016-02-25 20:19:27 +00:00
|
|
|
{
|
|
|
|
QApplication::installTranslator(&qtTranslator);
|
|
|
|
}
|
|
|
|
|
2016-09-22 16:09:02 +00:00
|
|
|
// define commandline arguments
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription(QApplication::tr("Instalation and launcher tool for Ryzom"));
|
|
|
|
parser.addHelpOption();
|
|
|
|
|
|
|
|
QCommandLineOption uninstallOption(QStringList() << "u" << "uninstall", QApplication::tr("Uninstall"));
|
|
|
|
parser.addOption(uninstallOption);
|
|
|
|
|
|
|
|
QCommandLineOption silentOption(QStringList() << "s" << "silent", QApplication::tr("Silent mode"));
|
|
|
|
parser.addOption(silentOption);
|
|
|
|
|
|
|
|
QCommandLineOption versionOption(QStringList() << "v" << "version", QApplication::tr("Version"));
|
|
|
|
parser.addOption(versionOption);
|
|
|
|
|
|
|
|
QCommandLineOption installOption(QStringList() << "i" << "install", QApplication::tr("Install itself"));
|
|
|
|
parser.addOption(installOption);
|
|
|
|
|
|
|
|
// process the actual command line arguments given by the user
|
|
|
|
parser.process(app);
|
|
|
|
|
|
|
|
// don't need to load config file for version
|
|
|
|
if (parser.isSet(versionOption))
|
|
|
|
{
|
|
|
|
printf("Ryzom Installer %s (built on %s)\nCopyright (C) %s\n", RYZOM_VERSION, BUILD_DATE, COPYRIGHT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-25 20:19:27 +00:00
|
|
|
// instanciate ConfigFile
|
|
|
|
CConfigFile config;
|
2016-06-14 17:39:39 +00:00
|
|
|
OperationStep step = config.load() ? config.getInstallNextStep():DisplayNoServerError;
|
2016-02-25 20:19:27 +00:00
|
|
|
|
2016-06-14 17:39:39 +00:00
|
|
|
if (step == DisplayNoServerError)
|
2016-02-25 20:19:27 +00:00
|
|
|
{
|
2016-08-06 18:11:15 +00:00
|
|
|
QMessageBox::critical(NULL, QApplication::tr("Error"), QApplication::tr("Unable to find ryzom_installer.ini"));
|
2016-02-25 20:19:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-14 11:35:46 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(_DEBUG)
|
|
|
|
// under Windows, Ryzom Installer should always be copied in TEMP directory
|
|
|
|
QString tempPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
|
|
|
|
|
|
|
// check if launched from TEMP directory
|
2016-09-20 15:43:08 +00:00
|
|
|
if (step == Done && !QApplication::applicationDirPath().startsWith(tempPath))
|
2016-08-14 11:35:46 +00:00
|
|
|
{
|
2016-09-20 15:43:08 +00:00
|
|
|
// try to delete all temporary installers
|
|
|
|
QDir tempDir(tempPath);
|
|
|
|
|
|
|
|
QStringList filter;
|
|
|
|
filter << "ryzom_installer_*";
|
|
|
|
|
|
|
|
QStringList dirs = tempDir.entryList(filter, QDir::Dirs);
|
|
|
|
|
|
|
|
foreach(const QString &dir, dirs)
|
|
|
|
{
|
2016-09-20 16:35:31 +00:00
|
|
|
// delete each directory
|
|
|
|
QDir dirToRemove(tempDir);
|
|
|
|
dirToRemove.cd(dir);
|
|
|
|
dirToRemove.removeRecursively();
|
2016-09-20 15:43:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tempPath += QString("/ryzom_installer_%1").arg(QDateTime::currentMSecsSinceEpoch());
|
|
|
|
|
2016-08-14 11:35:46 +00:00
|
|
|
// copy installer and required files to TEMP directory
|
2016-09-20 16:35:31 +00:00
|
|
|
if (QDir().mkdir(tempPath) && copyInstallerFiles(config.getInstallerRequiredFiles(), tempPath))
|
2016-08-14 11:35:46 +00:00
|
|
|
{
|
|
|
|
QString tempFile = tempPath + "/" + QFileInfo(QApplication::applicationFilePath()).fileName();
|
|
|
|
|
|
|
|
// launch copy in TEMP directory with same arguments
|
|
|
|
if (QProcess::startDetached(tempFile, QApplication::arguments())) return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-08-06 18:11:15 +00:00
|
|
|
// use product name from ryzom_installer.ini
|
2016-05-29 18:30:12 +00:00
|
|
|
if (!config.getProductName().isEmpty()) QApplication::setApplicationName(config.getProductName());
|
|
|
|
|
|
|
|
if (parser.isSet(uninstallOption))
|
|
|
|
{
|
2016-06-19 19:02:17 +00:00
|
|
|
SComponents components;
|
2016-05-29 18:30:12 +00:00
|
|
|
|
|
|
|
// add all servers by default
|
|
|
|
for (int i = 0; i < config.getServersCount(); ++i)
|
|
|
|
{
|
2016-06-14 17:43:45 +00:00
|
|
|
components.servers << config.getServer(i).id;
|
2016-05-29 18:30:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// show uninstall wizard dialog if not in silent mode
|
|
|
|
if (!parser.isSet(silentOption))
|
|
|
|
{
|
2016-06-12 13:40:38 +00:00
|
|
|
CUninstallDialog dialog;
|
2016-05-29 18:30:12 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
dialog.setSelectedComponents(components);
|
2016-05-29 18:30:12 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
// TODO: check real return codes from Uninstallers
|
|
|
|
if (!dialog.exec()) return 1;
|
2016-05-29 18:30:12 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
components = dialog.getSelectedCompenents();
|
|
|
|
}
|
2016-05-29 18:30:12 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
COperationDialog dialog;
|
2016-05-29 18:30:12 +00:00
|
|
|
|
2016-06-14 17:39:39 +00:00
|
|
|
dialog.setOperation(OperationUninstall);
|
2016-06-04 17:57:50 +00:00
|
|
|
dialog.setUninstallComponents(components);
|
2016-05-29 18:30:12 +00:00
|
|
|
|
2016-06-04 17:57:50 +00:00
|
|
|
// TODO: set all components to uninstall
|
|
|
|
|
|
|
|
return dialog.exec() ? 0 : 1;
|
2016-05-29 18:30:12 +00:00
|
|
|
}
|
2016-02-25 20:19:27 +00:00
|
|
|
|
2016-06-14 17:39:39 +00:00
|
|
|
if (step == ShowMigrateWizard)
|
2016-02-25 20:19:27 +00:00
|
|
|
{
|
2016-06-12 13:40:38 +00:00
|
|
|
CMigrateDialog dialog;
|
2016-02-25 20:19:27 +00:00
|
|
|
|
2016-05-29 18:35:34 +00:00
|
|
|
if (!dialog.exec()) return 1;
|
|
|
|
|
2016-06-14 17:53:44 +00:00
|
|
|
step = config.getInstallNextStep();
|
2016-02-25 20:19:27 +00:00
|
|
|
}
|
2016-06-14 17:39:39 +00:00
|
|
|
else if (step == ShowInstallWizard)
|
2016-05-25 21:23:48 +00:00
|
|
|
{
|
2016-06-12 13:40:38 +00:00
|
|
|
CInstallDialog dialog;
|
2016-05-25 21:23:48 +00:00
|
|
|
|
2016-05-29 18:35:34 +00:00
|
|
|
if (!dialog.exec()) return 1;
|
2016-05-25 21:23:48 +00:00
|
|
|
|
2016-06-14 17:53:44 +00:00
|
|
|
step = config.getInstallNextStep();
|
2016-05-16 09:11:40 +00:00
|
|
|
}
|
2016-05-29 18:35:34 +00:00
|
|
|
|
2016-06-14 17:39:39 +00:00
|
|
|
if (step != Done)
|
2016-05-16 09:11:40 +00:00
|
|
|
{
|
2016-05-29 18:35:34 +00:00
|
|
|
COperationDialog dialog;
|
2016-06-14 17:39:39 +00:00
|
|
|
dialog.setOperation(config.getSrcServerDirectory().isEmpty() ? OperationInstall:OperationMigrate);
|
2016-05-16 09:11:40 +00:00
|
|
|
|
2016-05-29 18:35:34 +00:00
|
|
|
if (!dialog.exec()) return 1;
|
2016-05-16 09:11:40 +00:00
|
|
|
|
2016-06-14 17:53:44 +00:00
|
|
|
step = config.getInstallNextStep();
|
2016-08-16 16:27:00 +00:00
|
|
|
|
|
|
|
if (step == Done)
|
|
|
|
{
|
2016-09-14 06:16:00 +00:00
|
|
|
#if defined(Q_OS_WIN) && !defined(_DEBUG)
|
2016-08-16 16:27:00 +00:00
|
|
|
// restart Installer, so it could be copied in TEMP and allowed to update itself
|
|
|
|
if (QProcess::startDetached(QApplication::applicationFilePath(), QApplication::arguments())) return 0;
|
2016-09-14 06:16:00 +00:00
|
|
|
#endif
|
2016-08-16 16:27:00 +00:00
|
|
|
}
|
2016-02-25 20:19:27 +00:00
|
|
|
}
|
|
|
|
|
2016-05-29 18:35:34 +00:00
|
|
|
CMainWindow mainWindow;
|
|
|
|
mainWindow.show();
|
|
|
|
|
|
|
|
return QApplication::exec();
|
2016-02-25 20:19:27 +00:00
|
|
|
}
|