Merge pull request #3762 from offhub/add007-4

Update NewBoxWizard.cpp
This commit is contained in:
DavidXanatos 2024-03-27 20:10:20 +01:00 committed by GitHub
commit 819ba064c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 8 deletions

View File

@ -176,6 +176,7 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
if(field("imagesProtection").toBool())
pBox->SetBool("ProtectHostImages", true);
// SharedTemplate
QString templateName = "SharedTemplate";
QString templateFullName = QString("Template_Local_%1").arg(templateName);
QString templateSettings = theAPI->SbieIniGetEx(templateFullName, "");
@ -185,21 +186,38 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
QString templateBase = QString("Tmpl.Title=%1\r\nTmpl.Class=Local\r\nTmpl.Comment=%2\r\n").arg(templateName, templateComment);
theAPI->SbieIniSet(templateFullName, "", templateBase);
}
if (field("sharedTemplate").toInt() == 1) { // insert template
QString insertValue = templateFullName.replace("Template_", "");
pBox->InsertText("Template", insertValue);
}
else if (field("sharedTemplate").toInt() == 2) { // append to config
QStringList templateSettingsLines = templateSettings.split("\r\n", Qt::SkipEmptyParts);
for (const QString& tLine : templateSettingsLines) {
if (!tLine.startsWith("Enabled=") && !tLine.startsWith("ConfigLevel=") && !tLine.startsWith("Tmpl.") && !tLine.startsWith("#")) { // skip lines
QStringList tParts = tLine.split('=');
if (tParts.size() == 2) {
QString tKey = tParts[0].trimmed();
QString tValue = tParts[1].trimmed();
pBox->AppendText(tKey, tValue);
}
if (tLine.startsWith("Enabled=") ||
tLine.startsWith("ConfigLevel=") ||
tLine.startsWith("Tmpl.") ||
tLine.startsWith("#")) {
continue; // Skip lines that start with these prefixes
}
QStringList tParts = tLine.split('=');
if (tParts.size() != 2) {
continue; // Skip lines that don't have exactly one '=' character
}
QString tKey = tParts[0].trimmed();
QString tValue = tParts[1].trimmed();
if (tLine.endsWith("=y") ||
tLine.endsWith("=Y") ||
tLine.endsWith("=n") ||
tLine.endsWith("=N")) {
pBox->SetText(tKey, tValue);
}
else {
pBox->AppendText(tKey, tValue);
}
}
}