From 2080c59915bc5b8f511d3438ea65978bf202d074 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 11 Jun 2016 17:02:44 +0200 Subject: [PATCH] Fixed: Use the right executable for client or default one --- .../client/ryzom_installer/src/configfile.cpp | 26 +++++++++++-- .../client/ryzom_installer/src/configfile.h | 4 +- .../client/ryzom_installer/src/mainwindow.cpp | 20 ++++++---- .../ryzom_installer/src/operationdialog.cpp | 1 - .../ryzom_installer/src/profilesdialog.cpp | 37 +++++++++++-------- 5 files changed, 60 insertions(+), 28 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp index d10e227ef..048074d4c 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.cpp @@ -575,13 +575,33 @@ bool CConfigFile::shouldCreateDesktopShortcut() const return profile.desktopShortcut && !QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) + "/Ryzom.lnk"); } -QString CConfigFile::getClientFullPath() const +QString CConfigFile::getProfileClientFullPath(int profileIndex) const { - QString path = getProfile().executable; + const CProfile &profile = getProfile(profileIndex); + + QString path = profile.executable; if (!path.isEmpty()) return path; - return getInstallationDirectory() + "/" + getServer().id + "/" + getServer().clientFilename; + return getServerClientFullPath(profile.server); +} + +QString CConfigFile::getServerClientFullPath(const QString &serverId) const +{ + const CServer &server = getServer(serverId); + + if (server.clientFilename.isEmpty()) return ""; + + return getInstallationDirectory() + "/" + server.id + "/" + server.clientFilename; +} + +QString CConfigFile::getServerConfigurationFullPath(const QString &serverId) const +{ + const CServer &server = getServer(serverId); + + if (server.configurationFilename.isEmpty()) return ""; + + return getInstallationDirectory() + "/" + server.id + "/" + server.configurationFilename; } QString CConfigFile::getSrcServerClientBNPFullPath() const diff --git a/code/ryzom/tools/client/ryzom_installer/src/configfile.h b/code/ryzom/tools/client/ryzom_installer/src/configfile.h index fe2dcb05e..d95894fae 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/configfile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/configfile.h @@ -171,7 +171,9 @@ public: QString getClientArch() const; - QString getClientFullPath() const; + QString getProfileClientFullPath(int profileIndex = -1) const; + QString getServerClientFullPath(const QString &serverId = "") const; + QString getServerConfigurationFullPath(const QString &serverId = "") const; QString getSrcServerClientBNPFullPath() const; diff --git a/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp b/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp index 34b8303b9..217d67018 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/mainwindow.cpp @@ -80,16 +80,20 @@ void CMainWindow::onPlayClicked() if (profileIndex < 0) return; - CProfile profile = CConfigFile::getInstance()->getProfile(profileIndex); + CConfigFile *config = CConfigFile::getInstance(); - if (profile.executable.isEmpty()) return; + const CProfile &profile = config->getProfile(profileIndex); + + QString executable = config->getProfileClientFullPath(profileIndex); + + if (executable.isEmpty() || !QFile::exists(executable)) return; QStringList arguments; arguments << "-p"; arguments << QString::number(profileIndex); arguments << profile.arguments.split(' '); - bool started = QProcess::startDetached(profile.executable, arguments); + bool started = QProcess::startDetached(executable, arguments); CConfigFile::getInstance()->setDefaultProfileIndex(profileIndex); } @@ -100,19 +104,19 @@ void CMainWindow::onConfigureClicked() if (profileIndex < 0) return; - CProfile profile = CConfigFile::getInstance()->getProfile(profileIndex); + CConfigFile *config = CConfigFile::getInstance(); - if (profile.server.isEmpty()) return; + const CProfile &profile = config->getProfile(profileIndex); - CServer server = CConfigFile::getInstance()->getServer(profile.server); + QString executable = config->getServerConfigurationFullPath(profile.server); - if (server.configurationFilename.isEmpty()) return; + if (executable.isEmpty() || !QFile::exists(executable)) return; QStringList arguments; arguments << "-p"; arguments << QString::number(profileIndex); - bool started = QProcess::startDetached(server.configurationFilename, arguments); + bool started = QProcess::startDetached(executable, arguments); CConfigFile::getInstance()->setDefaultProfileIndex(profileIndex); } diff --git a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp index 81db90561..61649c587 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/operationdialog.cpp @@ -590,7 +590,6 @@ bool COperationDialog::createDefaultProfile() 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"; diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp index 8f9cbbe2d..18570f5db 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp @@ -111,7 +111,7 @@ void CProfilesDialog::displayProfile(int index) profileIdLabel->setText(profile.id); nameEdit->setText(profile.name); serverComboBox->setCurrentIndex(m_serversModel->getIndexFromServerID(profile.server)); - executablePathLabel->setText(QFileInfo(profile.executable).fileName()); + executablePathLabel->setText(QFileInfo(executable).fileName()); argumentsEdit->setText(profile.arguments); commentsEdit->setPlainText(profile.comments); directoryPathLabel->setText(profileDirectory); @@ -208,19 +208,11 @@ void CProfilesDialog::updateExecutableVersion(int index) // file empty, use default one if (executable.isEmpty()) { - executable = CConfigFile::getInstance()->getInstallationDirectory() + "/" + profile.server + "/"; - -#if defined(Q_OS_WIN32) - executable += "ryzom_client_r.exe"; -#elif defined(Q_OS_APPLE) - executable += "Ryzom.app/Contents/MacOS/Ryzom"; -#else - executable += "ryzom_client"; -#endif + executable += CConfigFile::getInstance()->getServerClientFullPath(profile.server); } // file doesn't exist - if (!QFile::exists(executable)) return; + if (executable.isEmpty() || !QFile::exists(executable)) return; // launch executable with --version argument QProcess process; @@ -252,13 +244,28 @@ void CProfilesDialog::onExecutableBrowseClicked() CProfile &profile = m_model->getProfiles()[m_currentProfileIndex]; - QString file = QFileDialog::getOpenFileName(this, tr("Please choose Ryzom client executable to launch"), profile.executable, tr("Executables (*.exe)")); + QString executable = profile.executable; - if (file.isEmpty()) return; + if (executable.isEmpty()) + { + executable = CConfigFile::getInstance()->getServerClientFullPath(profile.server); + } - profile.executable = file; + executable = QFileDialog::getOpenFileName(this, tr("Please choose Ryzom client executable to launch"), executable, tr("Executables (*.exe)")); - executablePathLabel->setText(QFileInfo(profile.executable).fileName()); + if (executable.isEmpty()) return; + + // don't need to save the new executable if the same as default one + if (executable == CConfigFile::getInstance()->getServerClientFullPath(profile.server)) + { + profile.executable.clear(); + } + else + { + profile.executable = executable; + } + + executablePathLabel->setText(QFileInfo(executable).fileName()); updateExecutableVersion(m_currentProfileIndex); }