summaryrefslogtreecommitdiff
path: root/src/instancemanager.cpp
diff options
context:
space:
mode:
authorBrian Munro <brian.alexander.munro@gmail.com>2018-08-02 09:15:12 +0200
committerGitHub <noreply@github.com>2018-08-02 09:15:12 +0200
commit9a3a15b1f6339589be97e2546b7d532d30abc292 (patch)
tree2776d6834b92fdc95b5b26ab43e9e743e10c1128 /src/instancemanager.cpp
parent886fb10288baf4f52af2ad812a1c2121e138a16e (diff)
parent1ea43586d8eb304d8e91bf7f1480d7e4db5ef05f (diff)
Merge pull request #454 from Modorganizer2/Develop
Release 2.1.4
Diffstat (limited to 'src/instancemanager.cpp')
-rw-r--r--src/instancemanager.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp
index 43ae152b..1c6542e8 100644
--- a/src/instancemanager.cpp
+++ b/src/instancemanager.cpp
@@ -131,11 +131,12 @@ QString InstanceManager::manageInstances(const QStringList &instanceList) const
QString InstanceManager::queryInstanceName(const QStringList &instanceList) const
{
QString instanceId;
+ QString dialogText;
while (instanceId.isEmpty()) {
QInputDialog dialog;
- dialog.setWindowTitle(QObject::tr("Enter a Name for the new Instance"));
- dialog.setLabelText(QObject::tr("Enter a new name or select one from the sugested list (only letters and numbers allowed):"));
+ dialog.setWindowTitle(QObject::tr("Enter a Name for the new Instance"));
+ dialog.setLabelText(QObject::tr("Enter a new name or select one from the suggested list:"));
// would be neat if we could take the names from the game plugins but
// the required initialization order requires the ini file to be
// available *before* we load plugins
@@ -146,7 +147,17 @@ QString InstanceManager::queryInstanceName(const QStringList &instanceList) cons
if (dialog.exec() == QDialog::Rejected) {
throw MOBase::MyException(QObject::tr("Canceled"));
}
- instanceId = dialog.textValue().replace(QRegExp("[^0-9a-zA-Z ]"), "");
+ dialogText = dialog.textValue();
+ instanceId = sanitizeInstanceName(dialogText);
+ if (instanceId != dialogText) {
+ if (QMessageBox::question( nullptr,
+ QObject::tr("Invalid instance name"),
+ QObject::tr("The instance name \"%1\" is invalid. Use the name \"%2\" instead?").arg(dialogText,instanceId),
+ QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
+ instanceId="";
+ continue;
+ }
+ }
bool alreadyExists=false;
for (const QString &instance : instanceList) {
@@ -296,3 +307,21 @@ QString InstanceManager::determineDataPath()
}
}
+
+QString InstanceManager::sanitizeInstanceName(const QString &name) const
+{
+ QString new_name = name;
+
+ // Restrict the allowed characters
+ new_name = new_name.remove(QRegExp("[^A-Za-z0-9 _=+;!@#$%^'\\-\\.\\[\\]\\{\\}\\(\\)]"));
+
+ // Don't end in spaces and periods
+ new_name = new_name.remove(QRegExp("\\.*$"));
+ new_name = new_name.remove(QRegExp(" *$"));
+
+ // Recurse until stuff stops changing
+ if (new_name != name) {
+ return sanitizeInstanceName(new_name);
+ }
+ return new_name;
+} \ No newline at end of file