Sandboxie/SandboxiePlus/SandMan/Windows/OptionsForce.cpp

141 lines
4.0 KiB
C++
Raw Normal View History

2021-10-16 16:19:51 +01:00
#include "stdafx.h"
#include "OptionsWindow.h"
#include "SandMan.h"
#include "SettingsWindow.h"
#include "../MiscHelpers/Common/Settings.h"
#include "../MiscHelpers/Common/Common.h"
#include "../MiscHelpers/Common/ComboInputDialog.h"
#include "../MiscHelpers/Common/SettingsWidgets.h"
#include "Helpers/WinAdmin.h"
void COptionsWindow::LoadForced()
{
ui.treeForced->clear();
foreach(const QString& Value, m_pBox->GetTextList("ForceProcess", m_Template))
2021-12-03 19:26:09 +00:00
AddForcedEntry(Value, (int)eProcess);
foreach(const QString& Value, m_pBox->GetTextList("ForceProcessDisabled", m_Template))
AddForcedEntry(Value, (int)eProcess, true);
2021-10-16 16:19:51 +01:00
foreach(const QString& Value, m_pBox->GetTextList("ForceFolder", m_Template))
2021-12-03 19:26:09 +00:00
AddForcedEntry(Value, (int)ePath);
foreach(const QString& Value, m_pBox->GetTextList("ForceFolderDisabled", m_Template))
AddForcedEntry(Value, (int)ePath, true);
2021-10-16 16:19:51 +01:00
LoadForcedTmpl();
m_ForcedChanged = false;
}
void COptionsWindow::LoadForcedTmpl(bool bUpdate)
{
if (ui.chkShowForceTmpl->isChecked())
{
foreach(const QString& Template, m_pBox->GetTemplates())
{
foreach(const QString& Value, m_pBox->GetTextListTmpl("ForceProcess", Template))
2021-12-03 19:26:09 +00:00
AddForcedEntry(Value, (int)eProcess, false, Template);
2021-10-16 16:19:51 +01:00
foreach(const QString& Value, m_pBox->GetTextListTmpl("ForceFolder", Template))
2021-12-03 19:26:09 +00:00
AddForcedEntry(Value, (int)ePath, false, Template);
2021-10-16 16:19:51 +01:00
}
}
else if (bUpdate)
{
for (int i = 0; i < ui.treeForced->topLevelItemCount(); )
{
QTreeWidgetItem* pItem = ui.treeForced->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
2021-12-21 13:57:27 +00:00
if (Type == (int)eTemplate) {
2021-10-16 16:19:51 +01:00
delete pItem;
continue; // entry from template
}
i++;
}
}
}
2021-12-03 19:26:09 +00:00
void COptionsWindow::AddForcedEntry(const QString& Name, int type, bool disabled, const QString& Template)
2021-10-16 16:19:51 +01:00
{
QTreeWidgetItem* pItem = new QTreeWidgetItem();
2021-12-03 19:26:09 +00:00
pItem->setCheckState(0, disabled ? Qt::Unchecked : Qt::Checked);
pItem->setText(0, (type == (int)eProcess ? tr("Process") : tr("Folder")) + (Template.isEmpty() ? "" : (" (" + Template + ")")));
pItem->setData(0, Qt::UserRole, Template.isEmpty() ? type : (int)eTemplate);
SetProgramItem(Name, pItem, (int)eProcess);
pItem->setFlags(pItem->flags() | Qt::ItemIsEditable);
2021-10-16 16:19:51 +01:00
ui.treeForced->addTopLevelItem(pItem);
}
void COptionsWindow::SaveForced()
{
QStringList ForceProcess;
2021-12-03 19:26:09 +00:00
QStringList ForceProcessDisabled;
2021-10-16 16:19:51 +01:00
QStringList ForceFolder;
2021-12-03 19:26:09 +00:00
QStringList ForceFolderDisabled;
2021-10-16 16:19:51 +01:00
for (int i = 0; i < ui.treeForced->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeForced->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
2021-12-03 19:26:09 +00:00
if (Type == (int)eTemplate)
2021-10-16 16:19:51 +01:00
continue; // entry from template
2021-12-03 19:26:09 +00:00
if (pItem->checkState(0) == Qt::Checked) {
switch (Type) {
case eProcess: ForceProcess.append(pItem->data(1, Qt::UserRole).toString()); break;
case ePath: ForceFolder.append(pItem->data(1, Qt::UserRole).toString()); break;
}
}
else {
switch (Type) {
case eProcess: ForceProcessDisabled.append(pItem->data(1, Qt::UserRole).toString()); break;
case ePath: ForceFolderDisabled.append(pItem->data(1, Qt::UserRole).toString()); break;
}
2021-10-16 16:19:51 +01:00
}
}
WriteTextList("ForceProcess", ForceProcess);
2021-12-03 19:26:09 +00:00
WriteTextList("ForceProcessDisabled", ForceProcessDisabled);
2021-10-16 16:19:51 +01:00
WriteTextList("ForceFolder", ForceFolder);
2021-12-03 19:26:09 +00:00
WriteTextList("ForceFolderDisabled", ForceFolderDisabled);
2021-10-16 16:19:51 +01:00
m_ForcedChanged = false;
}
void COptionsWindow::OnForceProg()
{
QString Value = SelectProgram();
if (Value.isEmpty())
return;
2021-12-03 19:26:09 +00:00
AddForcedEntry(Value, (int)eProcess);
2021-10-16 16:19:51 +01:00
m_ForcedChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnForceDir()
{
QString Value = QFileDialog::getExistingDirectory(this, tr("Select Directory")).replace("/", "\\");
if (Value.isEmpty())
return;
2021-12-03 19:26:09 +00:00
AddForcedEntry(Value, (int)ePath);
2021-10-16 16:19:51 +01:00
m_ForcedChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnDelForce()
{
DeleteAccessEntry(ui.treeForced->currentItem());
m_ForcedChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
2021-12-03 19:26:09 +00:00
void COptionsWindow::OnForcedChanged(QTreeWidgetItem* pItem, int Index)
{
//QString Test = pItem->data(1, Qt::UserRole).toString();
//qDebug() << Test;
m_ForcedChanged = true;
OnOptChanged();
}