From 2460943bea23ad0798e5c103cefccedaae77820e Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 11 Oct 2016 17:43:53 +0200 Subject: [PATCH] Fixed: Check if profiles are correct before using them --HG-- branch : develop --- .../client/ryzom_installer/src/profile.cpp | 25 ++++++++++++++++++- .../client/ryzom_installer/src/profile.h | 2 ++ .../ryzom_installer/src/profilesdialog.cpp | 15 +++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/profile.cpp b/code/ryzom/tools/client/ryzom_installer/src/profile.cpp index 79aa74b25..90adb000c 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profile.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profile.cpp @@ -49,6 +49,29 @@ void CProfile::saveToSettings(QSettings &settings) const settings.setValue("menu_shortcut", menuShortcut); } +bool CProfile::isValid(QString &error) const +{ + QRegExp idReg("^[0-9a-z_]+$"); + + if (!idReg.exactMatch(id)) + { + error = QApplication::tr("Profile ID %1 is using invalid characters (only lowercase letters, numbers and underscore are allowed)").arg(id); + return false; + } + + QRegExp nameReg("[/\\\\<>?*:.%|\"]"); + + int pos = nameReg.indexIn(name); + + if (pos > -1) + { + error = QApplication::tr("Profile name %1 is using invalid character %2 at position %3").arg(name).arg(name[pos]).arg(pos); + return false; + } + + return true; +} + QString CProfile::getDirectory() const { return CConfigFile::getInstance()->getProfileDirectory() + "/" + id; @@ -105,7 +128,7 @@ void CProfile::createShortcuts() const // create desktop shortcut if (!createShortcut(shortcut, name, exe, profileArguments, icon, workingDir)) { - qDebug() << "Unable to create desktop directory"; + qDebug() << "Unable to create desktop shortcut"; } } diff --git a/code/ryzom/tools/client/ryzom_installer/src/profile.h b/code/ryzom/tools/client/ryzom_installer/src/profile.h index 774d55193..5b7f8158f 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profile.h +++ b/code/ryzom/tools/client/ryzom_installer/src/profile.h @@ -40,6 +40,8 @@ public: void loadFromSettings(const QSettings &settings); void saveToSettings(QSettings &settings) const; + bool isValid(QString &error) const; + // helpers QString getDirectory() const; QString getClientFullPath() const; diff --git a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp index 5bbeb86b2..4aa0b2f27 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/profilesdialog.cpp @@ -56,6 +56,21 @@ void CProfilesDialog::accept() { saveProfile(m_currentProfileIndex); + const CProfiles &profiles = m_model->getProfiles(); + + // check if profiles are valid + foreach(const CProfile &profile, profiles) + { + QString error; + + if (!profile.isValid(error)) + { + // display an error message + QMessageBox::critical(this, tr("Error"), error); + return; + } + } + m_model->save(); QDialog::accept();