Added new migration for special characters
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
a4502f44c2
commit
e0b901169a
@ -50,7 +50,7 @@ INIFile::INIFile() {}
|
||||
bool INIFile::saveFile(QString fileName)
|
||||
{
|
||||
if (!contains("ConfigVersion"))
|
||||
insert("ConfigVersion", "1.1");
|
||||
insert("ConfigVersion", "1.2");
|
||||
QSettings _settings_obj{ fileName, QSettings::Format::IniFormat };
|
||||
_settings_obj.setFallbacksEnabled(false);
|
||||
|
||||
@ -125,6 +125,10 @@ bool parseOldFileFormat(QIODevice& device, QSettings::SettingsMap& map)
|
||||
QString valueStr = line.right(line.length() - eqPos - 1).trimmed();
|
||||
|
||||
valueStr = unescape(valueStr);
|
||||
if ((valueStr.contains(QChar(';')) || valueStr.contains(QChar('=')) || valueStr.contains(QChar(','))) && valueStr.endsWith("\"") &&
|
||||
valueStr.startsWith("\"")) {
|
||||
valueStr = valueStr.removeFirst().removeLast();
|
||||
}
|
||||
|
||||
QVariant value(valueStr);
|
||||
map.insert(key, value);
|
||||
@ -154,7 +158,18 @@ bool INIFile::loadFile(QString fileName)
|
||||
file.close();
|
||||
for (auto&& key : map.keys())
|
||||
insert(key, map.value(key));
|
||||
insert("ConfigVersion", "1.1");
|
||||
insert("ConfigVersion", "1.2");
|
||||
} else if (_settings_obj.value("ConfigVersion").toString() == "1.1") {
|
||||
for (auto&& key : _settings_obj.allKeys()) {
|
||||
if (auto valueStr = _settings_obj.value(key).toString();
|
||||
(valueStr.contains(QChar(';')) || valueStr.contains(QChar('=')) || valueStr.contains(QChar(','))) &&
|
||||
valueStr.endsWith("\"") && valueStr.startsWith("\"")) {
|
||||
valueStr = valueStr.removeFirst().removeLast();
|
||||
insert(key, valueStr);
|
||||
} else
|
||||
insert(key, _settings_obj.value(key));
|
||||
}
|
||||
insert("ConfigVersion", "1.2");
|
||||
} else
|
||||
for (auto&& key : _settings_obj.allKeys())
|
||||
insert(key, _settings_obj.value(key));
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
#include <settings/INIFile.h>
|
||||
#include <QList>
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
#include "FileSystem.h"
|
||||
|
||||
#include <QVariantUtils.h>
|
||||
|
||||
@ -80,7 +82,10 @@ iconKey=vanillia_icon
|
||||
name=Minecraft Vanillia
|
||||
OverrideCommands=true
|
||||
PreLaunchCommand="$INST_JAVA" -jar packwiz-installer-bootstrap.jar link
|
||||
)";
|
||||
Wrapperommand=)";
|
||||
fileContent += "\"";
|
||||
fileContent += +R"(\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link =)";
|
||||
fileContent += "\"\n";
|
||||
QFile file(fileName);
|
||||
|
||||
if (file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
@ -93,11 +98,69 @@ PreLaunchCommand="$INST_JAVA" -jar packwiz-installer-bootstrap.jar link
|
||||
INIFile f1;
|
||||
f1.loadFile(fileName);
|
||||
QCOMPARE(f1.get("PreLaunchCommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link");
|
||||
QCOMPARE(f1.get("Wrapperommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link =");
|
||||
f1.saveFile(fileName);
|
||||
INIFile f2;
|
||||
f2.loadFile(fileName);
|
||||
QCOMPARE(f2.get("PreLaunchCommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link");
|
||||
QCOMPARE(f2.get("ConfigVersion", "NOT SET").toString(), "1.1");
|
||||
QCOMPARE(f2.get("Wrapperommand", "NOT SET").toString(), "\"$INST_JAVA\" -jar packwiz-installer-bootstrap.jar link =");
|
||||
QCOMPARE(f2.get("ConfigVersion", "NOT SET").toString(), "1.2");
|
||||
}
|
||||
|
||||
void test_SaveAleardyExistingFileWithSpecialChars()
|
||||
{
|
||||
QString fileName = "test_SaveAleardyExistingFileWithSpecialChars.ini";
|
||||
FS::deletePath(fileName); // just to clean the previous test run
|
||||
QSettings settings{ fileName, QSettings::Format::IniFormat };
|
||||
settings.setFallbacksEnabled(false);
|
||||
|
||||
settings.setValue("simple", "value1");
|
||||
settings.setValue("withQuotes", R"("value2" with quotes)");
|
||||
settings.setValue("withSpecialCharacters", "env mesa=true");
|
||||
settings.setValue("withSpecialCharacters2", "1,2,3,4");
|
||||
settings.setValue("withSpecialCharacters2", "1;2;3;4");
|
||||
settings.setValue("withAll", "val=\"$INST_JAVA\" -jar; ls ");
|
||||
|
||||
settings.sync();
|
||||
|
||||
QCOMPARE(settings.status(), QSettings::Status::NoError);
|
||||
|
||||
// load
|
||||
INIFile f1;
|
||||
f1.loadFile(fileName);
|
||||
for (auto key : settings.allKeys())
|
||||
QCOMPARE(f1.get(key, "NOT SET").toString(), settings.value(key).toString());
|
||||
f1.saveFile(fileName);
|
||||
INIFile f2;
|
||||
f2.loadFile(fileName);
|
||||
for (auto key : settings.allKeys())
|
||||
QCOMPARE(f2.get(key, "NOT SET").toString(), settings.value(key).toString());
|
||||
QCOMPARE(f2.get("ConfigVersion", "NOT SET").toString(), "1.2");
|
||||
}
|
||||
|
||||
void test_SaveAleardyExistingFileWithSpecialCharsV1()
|
||||
{
|
||||
QString fileName = "test_SaveAleardyExistingFileWithSpecialCharsV1.ini";
|
||||
QString fileContent = R"(InstanceType=OneSix
|
||||
ConfigVersion=1.1
|
||||
iconKey=vanillia_icon
|
||||
name=Minecraft Vanillia
|
||||
OverrideCommands=true
|
||||
PreLaunchCommand=)";
|
||||
fileContent += "\"\\\"env mesa=true\\\"\"\n";
|
||||
QFile file(fileName);
|
||||
|
||||
if (file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QTextStream stream(&file);
|
||||
stream << fileContent;
|
||||
file.close();
|
||||
}
|
||||
|
||||
// load
|
||||
INIFile f1;
|
||||
f1.loadFile(fileName);
|
||||
QCOMPARE(f1.get("PreLaunchCommand", "NOT SET").toString(), "env mesa=true");
|
||||
QCOMPARE(f1.get("ConfigVersion", "NOT SET").toString(), "1.2");
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user