mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-30 14:44:31 +02:00
Filter out invalid chars
Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
parent
8fea37b8b7
commit
294448a01e
@ -388,10 +388,9 @@ void BaseInstance::setName(QString val)
|
|||||||
emit propertiesChanged(this);
|
emit propertiesChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseInstance::syncInstanceDirName() const
|
bool BaseInstance::syncInstanceDirName(const QString& newRoot) const
|
||||||
{
|
{
|
||||||
auto oldRoot = instanceRoot();
|
auto oldRoot = instanceRoot();
|
||||||
auto newRoot = FS::PathCombine(QFileInfo(oldRoot).dir().absolutePath(), name());
|
|
||||||
if (oldRoot == newRoot)
|
if (oldRoot == newRoot)
|
||||||
return true;
|
return true;
|
||||||
if (!QFile::rename(oldRoot, newRoot))
|
if (!QFile::rename(oldRoot, newRoot))
|
||||||
|
@ -127,7 +127,7 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
|
|||||||
void setName(QString val);
|
void setName(QString val);
|
||||||
|
|
||||||
/// Sync name and rename instance dir accordingly; returns true if successful
|
/// 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
|
/// Value used for instance window titles
|
||||||
QString windowTitle() const;
|
QString windowTitle() const;
|
||||||
|
@ -54,7 +54,8 @@ bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent)
|
|||||||
|
|
||||||
auto oldRoot = instance->instanceRoot();
|
auto oldRoot = instance->instanceRoot();
|
||||||
auto oldName = QFileInfo(oldRoot).baseName();
|
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)
|
if (oldRoot == newRoot)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent)
|
|||||||
if (renamingMode == "AskEverytime") {
|
if (renamingMode == "AskEverytime") {
|
||||||
QMessageBox messageBox(parent);
|
QMessageBox messageBox(parent);
|
||||||
messageBox.setText(QObject::tr("Would you also like to rename the instance folder?"));
|
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.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
messageBox.setDefaultButton(QMessageBox::Yes);
|
messageBox.setDefaultButton(QMessageBox::Yes);
|
||||||
messageBox.setIcon(QMessageBox::Question);
|
messageBox.setIcon(QMessageBox::Question);
|
||||||
@ -93,7 +94,7 @@ bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Now we can confirm that a renaming is happening
|
// Now we can confirm that a renaming is happening
|
||||||
if (!instance->syncInstanceDirName()) {
|
if (!instance->syncInstanceDirName(newRoot)) {
|
||||||
QMessageBox::warning(parent, QObject::tr("Cannot rename instance"),
|
QMessageBox::warning(parent, QObject::tr("Cannot rename instance"),
|
||||||
QObject::tr("An error occurred when performing the following renaming operation: <br/>"
|
QObject::tr("An error occurred when performing the following renaming operation: <br/>"
|
||||||
" - Old instance root: %1<br/>"
|
" - Old instance root: %1<br/>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user