Fixed: Check if profiles are correct before using them

This commit is contained in:
kervala 2016-10-11 17:43:53 +02:00
parent 89850bc52d
commit d08ff5970f
3 changed files with 41 additions and 1 deletions

View file

@ -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";
}
}

View file

@ -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;

View file

@ -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();