Sandboxie/SandboxiePlus/SandMan/Windows/OptionsRecovery.cpp

169 lines
4.5 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::LoadRecoveryList()
{
ui.treeRecovery->clear();
foreach(const QString& Value, m_pBox->GetTextList("RecoverFolder", m_Template))
2022-09-29 17:28:48 +01:00
AddRecoveryEntry(Value);
2021-10-16 16:19:51 +01:00
LoadRecoveryListTmpl();
ui.chkAutoRecovery->setChecked(m_pBox->GetBool("AutoRecover", false));
2022-09-29 17:28:48 +01:00
ui.treeRecIgnore->clear();
foreach(const QString& Value, m_pBox->GetTextList("AutoRecoverIgnore", m_Template))
AddRecIgnoreEntry(Value);
LoadRecIgnoreListTmpl();
2021-10-16 16:19:51 +01:00
m_RecoveryChanged = false;
}
void COptionsWindow::LoadRecoveryListTmpl(bool bUpdate)
{
if (ui.chkShowRecoveryTmpl->isChecked())
{
foreach(const QString& Template, m_pBox->GetTemplates())
{
foreach(const QString& Value, m_pBox->GetTextListTmpl("RecoverFolder", Template))
2022-09-29 17:28:48 +01:00
AddRecoveryEntry(Value, Template);
2021-10-16 16:19:51 +01:00
}
}
else if (bUpdate)
{
for (int i = 0; i < ui.treeRecovery->topLevelItemCount(); )
{
QTreeWidgetItem* pItem = ui.treeRecovery->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1) {
delete pItem;
continue; // entry from template
}
i++;
}
}
}
2022-09-29 17:28:48 +01:00
void COptionsWindow::LoadRecIgnoreListTmpl(bool bUpdate)
{
if (ui.chkShowRecIgnoreTmpl->isChecked())
{
foreach(const QString& Template, m_pBox->GetTemplates())
{
foreach(const QString& Value, m_pBox->GetTextListTmpl("AutoRecoverIgnore", Template))
AddRecIgnoreEntry(Value, Template);
}
}
else if (bUpdate)
{
for (int i = 0; i < ui.treeRecIgnore->topLevelItemCount(); )
{
QTreeWidgetItem* pItem = ui.treeRecIgnore->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1) {
delete pItem;
continue; // entry from template
}
i++;
}
}
}
void COptionsWindow::AddRecoveryEntry(const QString& Name, const QString& Template)
2021-10-16 16:19:51 +01:00
{
QTreeWidgetItem* pItem = new QTreeWidgetItem();
2022-09-29 17:28:48 +01:00
pItem->setText(0, Name + (Template.isEmpty() ? "" : " (" + Template + ")"));
pItem->setData(0, Qt::UserRole, Template.isEmpty() ? 0 : -1);
2021-10-16 16:19:51 +01:00
ui.treeRecovery->addTopLevelItem(pItem);
}
2022-09-29 17:28:48 +01:00
void COptionsWindow::AddRecIgnoreEntry(const QString& Name, const QString& Template)
{
QTreeWidgetItem* pItem = new QTreeWidgetItem();
pItem->setText(0, Name + (Template.isEmpty() ? "" : " (" + Template + ")"));
pItem->setData(0, Qt::UserRole, Template.isEmpty() ? 0 : -1);
ui.treeRecIgnore->addTopLevelItem(pItem);
}
2021-10-16 16:19:51 +01:00
void COptionsWindow::SaveRecoveryList()
{
QStringList RecoverFolder;
for (int i = 0; i < ui.treeRecovery->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeRecovery->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1)
continue; // entry from template
2022-10-07 10:56:07 +01:00
RecoverFolder.append(pItem->text(0));
2021-10-16 16:19:51 +01:00
}
WriteTextList("RecoverFolder", RecoverFolder);
WriteAdvancedCheck(ui.chkAutoRecovery, "AutoRecover", "y", "");
2022-09-29 17:28:48 +01:00
QStringList AutoRecoverIgnore;
for (int i = 0; i < ui.treeRecIgnore->topLevelItemCount(); i++)
{
QTreeWidgetItem* pItem = ui.treeRecIgnore->topLevelItem(i);
int Type = pItem->data(0, Qt::UserRole).toInt();
if (Type == -1)
continue; // entry from template
2022-10-07 10:56:07 +01:00
AutoRecoverIgnore.append(pItem->text(0));
2022-09-29 17:28:48 +01:00
}
WriteTextList("AutoRecoverIgnore", AutoRecoverIgnore);
2021-10-16 16:19:51 +01:00
m_RecoveryChanged = false;
}
void COptionsWindow::OnAddRecFolder()
{
QString Value = QFileDialog::getExistingDirectory(this, tr("Select Directory")).replace("/", "\\");
if (Value.isEmpty())
return;
2022-09-29 17:28:48 +01:00
AddRecoveryEntry(Value);
2021-10-16 16:19:51 +01:00
m_RecoveryChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnAddRecIgnore()
{
QString Value = QFileDialog::getExistingDirectory(this, tr("Select Directory")).replace("/", "\\");
if (Value.isEmpty())
return;
2022-09-29 17:28:48 +01:00
AddRecIgnoreEntry(Value);
2021-10-16 16:19:51 +01:00
m_RecoveryChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnAddRecIgnoreExt()
{
QString Value = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a file extension to be excluded"), QLineEdit::Normal);
if (Value.isEmpty())
return;
2022-09-29 17:28:48 +01:00
AddRecIgnoreEntry(Value);
2021-10-16 16:19:51 +01:00
m_RecoveryChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}
void COptionsWindow::OnDelRecEntry()
{
2022-09-29 17:28:48 +01:00
DeleteAccessEntry(ui.treeRecovery->currentItem());
m_RecoveryChanged = true;
OnOptChanged();
}
2021-10-16 16:19:51 +01:00
2022-09-29 17:28:48 +01:00
void COptionsWindow::OnDelRecIgnoreEntry()
{
DeleteAccessEntry(ui.treeRecIgnore->currentItem());
2021-10-16 16:19:51 +01:00
m_RecoveryChanged = true;
2021-11-13 08:28:32 +00:00
OnOptChanged();
2021-10-16 16:19:51 +01:00
}