From 9a61bd9a7cac3256928db65b4f7a7759e9249bcd Mon Sep 17 00:00:00 2001 From: kervala Date: Mon, 16 May 2016 16:31:30 +0200 Subject: [PATCH] Merge with develop --- .../client/ryzom_installer/src/configfile.cpp | 31 ++- .../client/ryzom_installer/src/configfile.h | 3 +- .../ryzom_installer/src/filescleaner.cpp | 16 +- .../ryzom_installer/src/filescopier.cpp | 1 - .../ryzom_installer/src/filesextractor.cpp | 4 +- .../client/ryzom_installer/src/operation.h | 1 - .../ryzom_installer/src/operationdialog.cpp | 186 ++++++++++++------ .../ryzom_installer/src/operationdialog.h | 3 +- .../ryzom_installer/src/profilesdialog.cpp | 4 +- .../ryzom_installer/src/profilesmodel.cpp | 6 +- .../ryzom_installer/src/profilesmodel.h | 4 +- .../ryzom_installer/ui/operationdialog.ui | 5 +- 12 files changed, 179 insertions(+), 85 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp index 29c7ba6e4..e7d883314 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp @@ -105,7 +105,7 @@ bool CConfigFile::load(const QString &filename) settings.beginGroup(QString("profile_%1").arg(i)); - profile.id = settings.value("id").toInt(); + profile.id = settings.value("id").toString(); profile.name = settings.value("name").toString(); profile.account = settings.value("account").toString(); profile.server = settings.value("server").toString(); @@ -410,11 +410,20 @@ bool CConfigFile::areRyzomDataInstalledIn(const QString &directory) const // directory doesn't exist if (!dir.exists()) return false; - if (!dir.cd("data") && dir.exists()) return false; + if (!dir.cd("data") || !dir.exists()) return false; // at least 200 BNP in data directory if (dir.entryList(QStringList() << "*.bnp", QDir::Files).size() < 200) return false; + // fonts.bnp is required + if (!dir.exists("fonts.bnp")) return false; + + // gamedev.bnp is required + if (!dir.exists("gamedev.bnp")) return false; + + // interfaces.bnp is required + if (!dir.exists("interfaces.bnp")) return false; + // TODO: more checks return true; @@ -550,16 +559,18 @@ CConfigFile::InstallationStep CConfigFile::getNextStep() const { // user decided to copy files - // selected directory contains Ryzom files (shouldn't fail) - if (!areRyzomDataInstalledIn(getSrcServerDirectory())) - { - return ShowWizard; - } - // data are not copied if (!areRyzomDataInstalledIn(serverDirectory)) { - return CopyServerFiles; + // selected directory contains Ryzom files (shouldn't fail) + if (areRyzomDataInstalledIn(getSrcServerDirectory())) + { + return CopyServerFiles; + } + else + { + return ShowWizard; + } } // client is not extracted from BNP @@ -590,7 +601,7 @@ CConfigFile::InstallationStep CConfigFile::getNextStep() const } // no default profile - if (profile.id < 0) + if (profile.id.isEmpty()) { return CreateProfile; } diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.h b/code/ryzom/tools/client/ryzom_installer/src/configfile.h index e225fcc59..8909e39e6 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.h @@ -46,12 +46,11 @@ struct CProfile { CProfile() { - id = -1; desktopShortcut = false; menuShortcut = false; } - int id; + QString id; QString account; QString name; QString server; diff --git a/code/ryzom/tools/client/ryzom_installer/src/filescleaner.cpp b/code/ryzom/tools/client/ryzom_installer/src/filescleaner.cpp index 4b66b437b..e1481fcf9 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/filescleaner.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/filescleaner.cpp @@ -52,6 +52,8 @@ void CFilesCleaner::setDirectory(const QString &src) bool CFilesCleaner::exec() { + if (m_listener) m_listener->operationPrepare(); + QDir dir(m_directory); // directory doesn't exist @@ -62,9 +64,21 @@ bool CFilesCleaner::exec() // temporary files QStringList files = dir.entryList(QStringList() << "*.string_cache" << "*.packed_sheets" << "*.packed" << "*.pem", QDir::Files); + if (m_listener) + { + m_listener->operationInit(0, files.size()); + m_listener->operationStart(); + } + + int filesCount = 0; + foreach(const QString &file, files) { dir.remove(file); + + if (m_listener) m_listener->operationProgress(filesCount, file); + + ++filesCount; } // fonts directory is not needed anymore @@ -73,7 +87,7 @@ bool CFilesCleaner::exec() dir.removeRecursively(); } - if (m_listener) m_listener->operationFinish(); + if (m_listener) m_listener->operationSuccess(files.size()); return true; } diff --git a/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp b/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp index 8c8cfabb4..8b2af9be8 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/filescopier.cpp @@ -181,7 +181,6 @@ bool CFilesCopier::copyFiles(const FilesToCopy &files) if (m_listener) { m_listener->operationSuccess(totalSize); - m_listener->operationFinish(); } return true; diff --git a/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp b/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp index 222add173..8314d27e6 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/filesextractor.cpp @@ -457,7 +457,6 @@ bool CFilesExtractor::extract7z() if (m_listener) { m_listener->operationSuccess(totalUncompressed); - m_listener->operationFinish(); } return true; @@ -563,7 +562,6 @@ bool CFilesExtractor::extractZip() if (m_listener) { m_listener->operationSuccess(totalSize); - m_listener->operationFinish(); } return true; @@ -594,7 +592,6 @@ bool CFilesExtractor::progress(const std::string &filename, uint32 currentSize, if (m_listener) { m_listener->operationSuccess((qint64)totalSize); - m_listener->operationFinish(); } } @@ -617,6 +614,7 @@ bool CFilesExtractor::extractBnp() if (m_listener && m_listener->operationShouldStop()) { // stopped + m_listener->operationStop(); return true; } diff --git a/code/ryzom/tools/client/ryzom_installer/src/operation.h b/code/ryzom/tools/client/ryzom_installer/src/operation.h index b8cfeea34..121761e57 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operation.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operation.h @@ -29,7 +29,6 @@ public: virtual void operationProgress(qint64 current, const QString &filename) =0; virtual void operationSuccess(qint64 total) =0; virtual void operationFail(const QString &error) =0; - virtual void operationFinish() =0; virtual bool operationShouldStop() =0; }; diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index 88656a68a..1e1f067e6 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -42,6 +42,8 @@ COperationDialog::COperationDialog():QDialog(), m_aborting(false) { setupUi(this); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + #if defined(Q_OS_WIN32) && defined(QT_WINEXTRAS_LIB) m_button = new QWinTaskbarButton(this); #endif @@ -70,6 +72,7 @@ COperationDialog::COperationDialog():QDialog(), m_aborting(false) connect(this, SIGNAL(progress(qint64, QString)), SLOT(onProgressProgress(qint64, QString))); connect(this, SIGNAL(success(qint64)), SLOT(onProgressSuccess(qint64))); connect(this, SIGNAL(fail(QString)), SLOT(onProgressFail(QString))); + connect(this, SIGNAL(done()), SLOT(onDone())); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); } @@ -88,7 +91,10 @@ void COperationDialog::processNextStep() // default profile const CProfile &configuration = config->getProfile(); - switch(config->getNextStep()) + // long operations are done in a thread + CConfigFile::InstallationStep step = config->getNextStep(); + + switch(step) { case CConfigFile::DisplayNoServerError: break; @@ -97,7 +103,7 @@ void COperationDialog::processNextStep() break; case CConfigFile::DownloadData: - m_downloader->prepareFile(config->expandVariables(server.dataDownloadUrl), config->getInstallationDirectory() + "/" + config->expandVariables(server.dataDownloadFilename) + ".part"); + downloadData(); break; case CConfigFile::ExtractDownloadedData: @@ -105,7 +111,7 @@ void COperationDialog::processNextStep() break; case CConfigFile::DownloadClient: - m_downloader->prepareFile(config->expandVariables(server.clientDownloadUrl), config->getInstallationDirectory() + "/" + config->expandVariables(server.clientDownloadFilename) + ".part"); + downloadClient(); break; case CConfigFile::ExtractDownloadedClient: @@ -136,12 +142,14 @@ void COperationDialog::processNextStep() createDefaultShortcuts(); break; + case CConfigFile::Done: + accept(); + break; + default: // cases already managed in main.cpp break; } - - m_downloader->getHtmlPageContent(config->expandVariables(server.displayUrl)); } void COperationDialog::showEvent(QShowEvent *e) @@ -218,7 +226,7 @@ void COperationDialog::onProgressStop() m_button->progress()->hide(); #endif - close(); + reject(); } void COperationDialog::onProgressProgress(qint64 current, const QString &filename) @@ -248,7 +256,33 @@ void COperationDialog::onProgressFail(const QString &error) void COperationDialog::onDone() { - processNextStep(); + if (!operationShouldStop()) processNextStep(); +} + +void COperationDialog::downloadData() +{ + CConfigFile *config = CConfigFile::getInstance(); + + // default server + const CServer &server = config->getServer(); + + m_currentOperation = QApplication::tr("Download data required by server %1").arg(server.name); + m_currentOperationProgressFormat = QApplication::tr("Downloading %1..."); + + m_downloader->prepareFile(config->expandVariables(server.dataDownloadUrl), config->getInstallationDirectory() + "/" + config->expandVariables(server.dataDownloadFilename) + ".part"); +} + +void COperationDialog::downloadClient() +{ + CConfigFile *config = CConfigFile::getInstance(); + + // default server + const CServer &server = config->getServer(); + + m_currentOperation = QApplication::tr("Download client required by server %1").arg(server.name); + m_currentOperationProgressFormat = QApplication::tr("Downloading %1..."); + + m_downloader->prepareFile(config->expandVariables(server.clientDownloadUrl), config->getInstallationDirectory() + "/" + config->expandVariables(server.clientDownloadFilename) + ".part"); } void COperationDialog::copyServerFiles() @@ -258,8 +292,8 @@ void COperationDialog::copyServerFiles() // default server const CServer &server = config->getServer(); - // default profile - const CProfile &configuration = config->getProfile(); + m_currentOperation = QApplication::tr("Copy client files required by server %1").arg(server.name); + m_currentOperationProgressFormat = QApplication::tr("Copying %1..."); QStringList serverFiles; serverFiles << "cfg"; @@ -269,9 +303,6 @@ void COperationDialog::copyServerFiles() serverFiles << "unpack"; serverFiles << "client_default.cfg"; - m_currentOperation = QApplication::tr("Copying client files needed for server %1...").arg(server.name); - m_currentOperationProgressFormat = QApplication::tr("Copying %1..."); - CFilesCopier copier(this); copier.setSourceDirectory(config->getSrcServerDirectory()); copier.setDesinationDirectory(config->getInstallationDirectory() + "/" + server.id); @@ -283,6 +314,8 @@ void COperationDialog::copyServerFiles() else { } + + emit done(); } void COperationDialog::copyProfileFiles() @@ -295,6 +328,9 @@ void COperationDialog::copyProfileFiles() // default profile const CProfile &profile = config->getProfile(); + m_currentOperation = QApplication::tr("Copy old profile to new location"); + m_currentOperationProgressFormat = QApplication::tr("Copying %1..."); + QStringList profileFiles; profileFiles << "cache"; profileFiles << "save"; @@ -314,6 +350,8 @@ void COperationDialog::copyProfileFiles() else { } + + emit done(); } void COperationDialog::extractBnpClient() @@ -323,13 +361,44 @@ void COperationDialog::extractBnpClient() // default server const CServer &server = config->getServer(); - // default profile - const CProfile &profile = config->getProfile(); + m_currentOperation = QApplication::tr("Extract client to new location"); + m_currentOperationProgressFormat = QApplication::tr("Extracting %1..."); + + QString destinationDirectory = config->getInstallationDirectory() + "/" + server.id; CFilesExtractor extractor(this); extractor.setSourceFile(config->getSrcServerClientBNPFullPath()); - extractor.setDesinationDirectory(config->getInstallationDirectory() + "/" + server.id); + extractor.setDesinationDirectory(destinationDirectory); extractor.exec(); + + QString upgradeScript = destinationDirectory + "/upgd_nl."; + +#ifdef Q_OS_WIN + upgradeScript += "bat"; +#else + upgradeScript += "sh"; +#endif + + if (QFile::exists(upgradeScript)) + { + QProcess process; + + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + env.insert("RYZOM_CLIENT", QDir::toNativeSeparators(destinationDirectory + "/ryzom_client_r.exe")); + env.insert("UNPACKPATH", QDir::toNativeSeparators(destinationDirectory + "/unpack")); + env.insert("ROOTPATH", QDir::toNativeSeparators(destinationDirectory)); + env.insert("STARTUPPATH", ""); + process.setProcessEnvironment(env); + + process.start(upgradeScript); + + while (process.waitForFinished()) + { + qDebug() << "waiting"; + } + } + + emit done(); } void COperationDialog::cleanFiles() @@ -339,12 +408,54 @@ void COperationDialog::cleanFiles() // default server const CServer &server = config->getServer(); - // default profile - const CProfile &profile = config->getProfile(); + m_currentOperation = QApplication::tr("Clean obsolete files"); + m_currentOperationProgressFormat = QApplication::tr("Deleting %1..."); CFilesCleaner cleaner(this); cleaner.setDirectory(config->getInstallationDirectory() + "/" + server.id); cleaner.exec(); + + emit done(); +} + +bool COperationDialog::createDefaultProfile() +{ + CConfigFile *config = CConfigFile::getInstance(); + + CServer server = config->getServer(config->getDefaultServerIndex()); + + m_currentOperation = QApplication::tr("Create default profile"); + m_currentOperationProgressFormat = QApplication::tr("Deleting %1..."); + + CProfile profile; + + profile.id = "0"; + profile.executable = config->getClientFullPath(); + profile.name = QString("Ryzom (%1)").arg(server.name); + profile.server = server.id; + profile.comments = "Default profile created by Ryzom Installer"; + +#ifdef Q_OS_WIN32 +// C:\Users\Public\Desktop + profile.desktopShortcut = QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk"); +#endif + + // TODO + // profile.menuShortcut + + config->addProfile(profile); + config->save(); + + emit done(); + + return true; +} + +bool COperationDialog::createDefaultShortcuts() +{ + emit done(); + + return true; } void COperationDialog::operationPrepare() @@ -382,50 +493,9 @@ void COperationDialog::operationFail(const QString &error) emit fail(error); } -void COperationDialog::operationFinish() -{ - emit done(); -} - bool COperationDialog::operationShouldStop() { QMutexLocker locker(&m_abortingMutex); return m_aborting; } - -bool COperationDialog::createDefaultProfile() -{ - CConfigFile *config = CConfigFile::getInstance(); - - CServer server = config->getServer(config->getDefaultServerIndex()); - - CProfile profile; - - profile.id = 0; - profile.executable = config->getClientFullPath(); - profile.name = QString("Ryzom (%1)").arg(server.name); - profile.server = server.id; - profile.comments = "Default profile created by Ryzom Installer"; - -#ifdef Q_OS_WIN32 - profile.desktopShortcut = QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk"); -#endif - - // TODO - // profile.menuShortcut - - config->addProfile(profile); - config->save(); - - onDone(); - - return true; -} - -bool COperationDialog::createDefaultShortcuts() -{ - onDone(); - - return true; -} diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h index b4004988b..39ab5437d 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.h @@ -82,6 +82,8 @@ protected: void processNextStep(); // operations + void downloadData(); + void downloadClient(); void copyServerFiles(); void copyProfileFiles(); void extractBnpClient(); @@ -97,7 +99,6 @@ protected: virtual void operationProgress(qint64 current, const QString &filename); virtual void operationSuccess(qint64 total); virtual void operationFail(const QString &error); - virtual void operationFinish(); virtual bool operationShouldStop(); diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp index c83447d47..b9c3ef29a 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp @@ -38,7 +38,7 @@ CProfilesDialog::CProfilesDialog():QDialog(), m_currentProfileIndex(-1) profilesListView->setModel(m_model); serverComboBox->setModel(m_serversModel); - int index = m_model->getIndexFromProfileID(CConfigFile::getInstance()->getDefaultProfileIndex()); + int index = CConfigFile::getInstance()->getDefaultProfileIndex(); profilesListView->setCurrentIndex(m_model->index(index, 0)); displayProfile(index); @@ -97,7 +97,7 @@ void CProfilesDialog::displayProfile(int index) const CProfile &profile = m_model->getProfiles()[index]; // update all widgets with content of profile - profileIdLabel->setText(QString::number(profile.id)); + profileIdLabel->setText(profile.id); accountEdit->setText(profile.account); nameEdit->setText(profile.name); serverComboBox->setCurrentIndex(m_serversModel->getIndexFromServerID(profile.server)); diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp index 64f15c5d5..dd9c97e40 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.cpp @@ -24,7 +24,7 @@ QVariant CProfilesModel::data(const QModelIndex &index, int role) const const CProfile &profile = m_profiles.at(index.row()); - return QString("%1 (#%2)").arg(profile.name).arg(profile.id); + return tr("#%1: %2").arg(profile.id).arg(profile.name); } bool CProfilesModel::removeRows(int row, int count, const QModelIndex &parent) @@ -48,7 +48,7 @@ bool CProfilesModel::save() const return true; } -int CProfilesModel::getIndexFromProfileID(int profileId) const +int CProfilesModel::getIndexFromProfileID(const QString &profileId) const { for(int i = 0; i < m_profiles.size(); ++i) { @@ -58,7 +58,7 @@ int CProfilesModel::getIndexFromProfileID(int profileId) const return -1; } -int CProfilesModel::getProfileIDFromIndex(int index) const +QString CProfilesModel::getProfileIDFromIndex(int index) const { if (index < 0 || index >= m_profiles.size()) return -1; diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h index ea02f618c..4a3a71a77 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesmodel.h @@ -25,8 +25,8 @@ public: bool save() const; - int getIndexFromProfileID(int profileId) const; - int getProfileIDFromIndex(int index) const; + int getIndexFromProfileID(const QString &profileId) const; + QString getProfileIDFromIndex(int index) const; private: CProfiles m_profiles; diff --git a/code/ryzom/tools/client/ryzom_installer/ui/operationdialog.ui b/code/ryzom/tools/client/ryzom_installer/ui/operationdialog.ui index 104cdd200..86bf38f03 100644 --- a/code/ryzom/tools/client/ryzom_installer/ui/operationdialog.ui +++ b/code/ryzom/tools/client/ryzom_installer/ui/operationdialog.ui @@ -2,6 +2,9 @@ OperationDialog + + Qt::ApplicationModal + 0 @@ -11,7 +14,7 @@ - Dialog + Ryzom Installer