From 9638a797d16eb2d9b504a4a337a20b4eee535e4c Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Thu, 29 Apr 2021 00:42:51 -0700 Subject: Sanitize download file names Also switch instance name sanitizer to MOBase version --- src/instancemanager.cpp | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'src/instancemanager.cpp') diff --git a/src/instancemanager.cpp b/src/instancemanager.cpp index a1b17577..e7474584 100644 --- a/src/instancemanager.cpp +++ b/src/instancemanager.cpp @@ -32,6 +32,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include "filesystemutilities.h" #include #include @@ -721,7 +722,7 @@ const MOBase::IPluginGame* InstanceManager::gamePluginForDirectory( QString InstanceManager::makeUniqueName(const QString& instanceName) const { - const QString sanitized = sanitizeInstanceName(instanceName); + const QString sanitized = MOBase::sanitizeFileName(instanceName); // trying "name (N)" QString name = sanitized; @@ -742,35 +743,6 @@ bool InstanceManager::instanceExists(const QString& instanceName) const return root.exists(instanceName); } -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; -} - -bool InstanceManager::validInstanceName(const QString& instanceName) const -{ - if (instanceName.isEmpty()) { - return false; - } - - return (instanceName == sanitizeInstanceName(instanceName)); -} - - - std::unique_ptr selectInstance() { auto& m = InstanceManager::singleton(); -- cgit v1.3.1