parent
bdf3d86b79
commit
96406acc17
|
@ -98,38 +98,30 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
|
||||||
CSandBoxPtr pBox = theAPI->GetBoxByName(BoxName);
|
CSandBoxPtr pBox = theAPI->GetBoxByName(BoxName);
|
||||||
|
|
||||||
// SharedTemplate
|
// SharedTemplate
|
||||||
const QString TEMPLATE_PREFIX = "Template_Local_";
|
QElapsedTimer timer;
|
||||||
const QString DISABLE_WIZARD_SETTINGS = "#DisableWizardSettings";
|
timer.start();
|
||||||
const QString REMOVE_DEFAULT_ALL = "#RemoveDefaultAll";
|
const QString templateName = "SharedTemplate";
|
||||||
const QString REMOVE_DEFAULT_RECOVERS = "#RemoveDefaultRecovers";
|
const QString templateFullName = "Template_Local_" + templateName;
|
||||||
const QString REMOVE_DEFAULT_TEMPLATES = "#RemoveDefaultTemplates";
|
const QString templateSettings = theAPI->SbieIniGetEx(templateFullName, "");
|
||||||
const QString ENABLED_PREFIX = "Enabled";
|
const QStringList templateSettingsLines = templateSettings.split(QRegularExpression(QStringLiteral("[\r\n]")), Qt::SkipEmptyParts);
|
||||||
const QString CFGLVL_PREFIX = "ConfigLevel";
|
const QString templateComment = tr("Add your settings after this line.");
|
||||||
const QString TMPL_PREFIX = "Tmpl.";
|
const QString templateTitle = tr("Shared Template");
|
||||||
const QString BOX_DISABLED_SUFFIX = "Disabled";
|
const QString boxSettings = theAPI->SbieIniGetEx(BoxName, "");
|
||||||
|
const QStringList boxSettingsLines = boxSettings.split(QRegularExpression(QStringLiteral("[\r\n]")), Qt::SkipEmptyParts);
|
||||||
const QStringList SPECIAL_SETTINGS = { "BorderColor", "BoxIcon", "BoxNameTitle", "ConfigLevel", "CopyLimitKb" };
|
const QStringList SPECIAL_SETTINGS = { "BorderColor", "BoxIcon", "BoxNameTitle", "ConfigLevel", "CopyLimitKb" };
|
||||||
|
|
||||||
QString templateName = "SharedTemplate";
|
bool disableWizardSettings = templateSettings.contains(QRegularExpression(QStringLiteral("[\r\n]#DisableWizardSettings=y[\r\n]")));
|
||||||
QString templateFullName = TEMPLATE_PREFIX + templateName;
|
bool removeDefaultAll = templateSettings.contains(QRegularExpression(QStringLiteral("[\r\n]#RemoveDefaultAll=y[\r\n]")));
|
||||||
QString templateSettings = theAPI->SbieIniGetEx(templateFullName, "");
|
bool removeDefaultRecovers = templateSettings.contains(QRegularExpression(QStringLiteral("[\r\n]#RemoveDefaultRecovers=y[\r\n]")));
|
||||||
QString templateComment = tr("Add your settings after this line.");
|
bool removeDefaultTemplates = templateSettings.contains(QRegularExpression(QStringLiteral("[\r\n]#RemoveDefaultTemplates=y[\r\n]")));
|
||||||
QString templateTitle = tr("Shared Template");
|
|
||||||
|
|
||||||
bool disableWizardSettings = templateSettings.contains(DISABLE_WIZARD_SETTINGS + "=y");
|
|
||||||
bool removeDefaultAll = templateSettings.contains(REMOVE_DEFAULT_ALL + "=y");
|
|
||||||
bool removeDefaultRecovers = templateSettings.contains(REMOVE_DEFAULT_RECOVERS + "=y");
|
|
||||||
bool removeDefaultTemplates = templateSettings.contains(REMOVE_DEFAULT_TEMPLATES + "=y");
|
|
||||||
|
|
||||||
// Create base template
|
// Create base template
|
||||||
if (templateSettings.isEmpty()) {
|
if (templateSettings.isEmpty()) {
|
||||||
QString templateBase = QStringLiteral("Tmpl.Title=%1\nTmpl.Class=Local\n%3=n\n%4=n\n%5=n\n%6=n\nTmpl.Comment=%2")
|
const QString templateBase = QStringLiteral("Tmpl.Title=%1\nTmpl.Class=Local\n%3=n\n%4=n\n%5=n\n%6=n\nTmpl.Comment=%2")
|
||||||
.arg(templateTitle, templateComment, DISABLE_WIZARD_SETTINGS, REMOVE_DEFAULT_ALL, REMOVE_DEFAULT_RECOVERS, REMOVE_DEFAULT_TEMPLATES);
|
.arg(templateTitle, templateComment, "#DisableWizardSettings", "#RemoveDefaultAll", "#RemoveDefaultRecovers", "#RemoveDefaultTemplates");
|
||||||
theAPI->SbieIniSet(templateFullName, "", templateBase);
|
theAPI->SbieIniSet(templateFullName, "", templateBase);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString boxSettings = theAPI->SbieIniGetEx(BoxName, "");
|
|
||||||
QStringList boxSettingsLines = boxSettings.split("\n", Qt::SkipEmptyParts);
|
|
||||||
|
|
||||||
int sharedTemplateMode = field("sharedTemplate").toInt();
|
int sharedTemplateMode = field("sharedTemplate").toInt();
|
||||||
switch (sharedTemplateMode)
|
switch (sharedTemplateMode)
|
||||||
{
|
{
|
||||||
|
@ -147,9 +139,9 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
|
||||||
for (const QString& bLine : boxSettingsLines) {
|
for (const QString& bLine : boxSettingsLines) {
|
||||||
int bParts = bLine.indexOf("=", Qt::SkipEmptyParts);
|
int bParts = bLine.indexOf("=", Qt::SkipEmptyParts);
|
||||||
if (bParts != -1) {
|
if (bParts != -1) {
|
||||||
QString bKey = bLine.mid(0, bParts).trimmed();
|
const QString bKey = bLine.mid(0, bParts).trimmed();
|
||||||
QString bValue = bLine.mid(bParts + 1).trimmed();
|
const QString bValue = bLine.mid(bParts + 1).trimmed();
|
||||||
if (bKey.compare(ENABLED_PREFIX, Qt::CaseInsensitive) != 0 && bKey.compare(CFGLVL_PREFIX) != 0) { // Do not remove Enabled and ConfigLevel
|
if (bKey.compare("Enabled", Qt::CaseInsensitive) != 0 && bKey.compare("ConfigLevel") != 0) { // Do not remove Enabled and ConfigLevel
|
||||||
pBox->DelValue(bKey, bValue);
|
pBox->DelValue(bKey, bValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,20 +152,19 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
|
||||||
// Default case
|
// Default case
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (sharedTemplateMode == 1) { // Insert template
|
if (sharedTemplateMode == 1) { // Insert as template
|
||||||
QString insertValue = templateFullName.replace("Template_", "");
|
const QString insertValue = templateFullName.mid(9); // Template_
|
||||||
pBox->InsertText("Template", insertValue);
|
pBox->InsertText("Template", insertValue);
|
||||||
}
|
}
|
||||||
else if (sharedTemplateMode == 2) { // Append to config
|
else if (sharedTemplateMode == 2) { // Append template settings to configuration
|
||||||
for (const QString& tLine : templateSettings.split("\n", Qt::SkipEmptyParts)) {
|
for (const QString& tLine : templateSettingsLines) {
|
||||||
int tParts = tLine.indexOf("=", Qt::SkipEmptyParts);
|
int tParts = tLine.indexOf("=", Qt::SkipEmptyParts);
|
||||||
if (tParts == -1) {
|
if (tParts == -1) {
|
||||||
continue; // Skip lines that don't have at least one '=' character.
|
continue; // Skip lines that don't have at least one '=' character.
|
||||||
}
|
}
|
||||||
QString tKey = tLine.mid(0, tParts).trimmed();
|
const QString tKey = tLine.mid(0, tParts).trimmed();
|
||||||
QString tValue = tLine.mid(tParts + 1).trimmed();
|
const QString tValue = tLine.mid(tParts + 1).trimmed();
|
||||||
|
if (tKey.compare("Enabled", Qt::CaseInsensitive) == 0 || tKey.startsWith("Tmpl.") || tKey.startsWith("#") || tKey.endsWith("Disabled")) {
|
||||||
if (tKey.compare(ENABLED_PREFIX, Qt::CaseInsensitive) == 0 || tKey.startsWith(TMPL_PREFIX) || tKey.startsWith("#") || tKey.endsWith(BOX_DISABLED_SUFFIX)) {
|
|
||||||
continue; // Skip lines that start or end with one of these
|
continue; // Skip lines that start or end with one of these
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +176,7 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qDebug().noquote().nospace() << templateName << " (Mode = " << sharedTemplateMode << ") operation took " << timer.elapsed() << " ms";
|
||||||
//
|
//
|
||||||
if (!disableWizardSettings || sharedTemplateMode == 0) {
|
if (!disableWizardSettings || sharedTemplateMode == 0) {
|
||||||
switch (BoxType)
|
switch (BoxType)
|
||||||
|
|
Loading…
Reference in New Issue