Filter out invalid chars

Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
Yihe Li 2025-03-27 06:54:10 +08:00
parent 8fea37b8b7
commit 294448a01e
No known key found for this signature in database
3 changed files with 6 additions and 6 deletions

View File

@ -388,10 +388,9 @@ void BaseInstance::setName(QString val)
emit propertiesChanged(this);
}
bool BaseInstance::syncInstanceDirName() const
bool BaseInstance::syncInstanceDirName(const QString& newRoot) const
{
auto oldRoot = instanceRoot();
auto newRoot = FS::PathCombine(QFileInfo(oldRoot).dir().absolutePath(), name());
if (oldRoot == newRoot)
return true;
if (!QFile::rename(oldRoot, newRoot))

View File

@ -127,7 +127,7 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
void setName(QString val);
/// Sync name and rename instance dir accordingly; returns true if successful
bool syncInstanceDirName() const;
bool syncInstanceDirName(const QString& newRoot) const;
/// Value used for instance window titles
QString windowTitle() const;

View File

@ -54,7 +54,8 @@ bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent)
auto oldRoot = instance->instanceRoot();
auto oldName = QFileInfo(oldRoot).baseName();
auto newRoot = FS::PathCombine(QFileInfo(oldRoot).dir().absolutePath(), instance->name());
auto newName = FS::DirNameFromString(instance->name(), QFileInfo(oldRoot).dir().absolutePath());
auto newRoot = FS::PathCombine(QFileInfo(oldRoot).dir().absolutePath(), newName);
if (oldRoot == newRoot)
return false;
@ -69,7 +70,7 @@ bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent)
if (renamingMode == "AskEverytime") {
QMessageBox messageBox(parent);
messageBox.setText(QObject::tr("Would you also like to rename the instance folder?"));
messageBox.setInformativeText(QObject::tr("Renaming \'%1\' -> \'%2\'").arg(oldName, instance->name()));
messageBox.setInformativeText(QObject::tr("Renaming \'%1\' -> \'%2\'").arg(oldName, newName));
messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
messageBox.setDefaultButton(QMessageBox::Yes);
messageBox.setIcon(QMessageBox::Question);
@ -93,7 +94,7 @@ bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent)
return false;
// Now we can confirm that a renaming is happening
if (!instance->syncInstanceDirName()) {
if (!instance->syncInstanceDirName(newRoot)) {
QMessageBox::warning(parent, QObject::tr("Cannot rename instance"),
QObject::tr("An error occurred when performing the following renaming operation: <br/>"
" - Old instance root: %1<br/>"