This commit is contained in:
DavidXanatos 2023-04-20 21:52:30 +02:00
parent f340330b1a
commit bfffaf96a0
5 changed files with 95 additions and 35 deletions

View File

@ -22,6 +22,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- fixed memory corruption issue with Normal[File/Key]Path [#2588](https://github.com/sandboxie-plus/Sandboxie/issues/2588) - fixed memory corruption issue with Normal[File/Key]Path [#2588](https://github.com/sandboxie-plus/Sandboxie/issues/2588)
- fixed DPI scaling in the snapshot manager window [#782](https://github.com/sandboxie-plus/Sandboxie/issues/782) - fixed DPI scaling in the snapshot manager window [#782](https://github.com/sandboxie-plus/Sandboxie/issues/782)
### Changed
- reworked box grouping config storeage
## [1.9.0 / 5.64.0] - 2023-04-17 ## [1.9.0 / 5.64.0] - 2023-04-17

View File

@ -18,6 +18,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SbieIni.h" #include "SbieIni.h"
#include "../SbieAPI.h" #include "../SbieAPI.h"
#include "../SbieDefs.h"
#include <ntstatus.h> #include <ntstatus.h>
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
@ -206,6 +207,38 @@ SB_STATUS CSbieIni::DelValue(const QString& Setting, const QString& Value)
return m_pAPI->SbieIniSet(m_Name, Setting, Value, CSbieAPI::eIniDelete, m_RefreshOnChange); return m_pAPI->SbieIniSet(m_Name, Setting, Value, CSbieAPI::eIniDelete, m_RefreshOnChange);
} }
void CSbieIni::SetTextMap(const QString& Setting, const QMap<QString, QStringList> Map)
{
QStringList Mapping;
foreach(const QString& Group, Map.keys())
{
QString CurrentLine;
foreach(const QString & Name, Map[Group]) {
if (Setting.length() + 1 + Group.length() + 1 + CurrentLine.length() + 1 + Name.length() >= CONF_LINE_LEN) { // limit line length
Mapping.append(Group + ":" + CurrentLine);
CurrentLine.clear();
}
if (!CurrentLine.isEmpty()) CurrentLine.append(",");
CurrentLine.append(Name);
}
if(!CurrentLine.isEmpty())
Mapping.append(Group + ":" + CurrentLine);
}
DelValue(Setting);
foreach(const QString & Value, Mapping)
AppendText(Setting, Value);
}
QMap<QString, QStringList> CSbieIni::GetTextMap(const QString& Setting)
{
QMap<QString, QStringList> Map;
foreach(const QString &CurrentLine, GetTextList(Setting, false)) {
int pos = CurrentLine.lastIndexOf(":");
Map[pos == -1 ? "" : CurrentLine.left(pos)].append(CurrentLine.mid(pos+1).split(","));
}
return Map;
}
QList<QPair<QString, QString>> CSbieIni::GetIniSection(qint32* pStatus, bool withTemplates) const QList<QPair<QString, QString>> CSbieIni::GetIniSection(qint32* pStatus, bool withTemplates) const
{ {
qint32 status = STATUS_SUCCESS; qint32 status = STATUS_SUCCESS;

View File

@ -34,6 +34,9 @@ public:
virtual SB_STATUS InsertText(const QString& Setting, const QString& Value); virtual SB_STATUS InsertText(const QString& Setting, const QString& Value);
virtual SB_STATUS AppendText(const QString& Setting, const QString& Value); virtual SB_STATUS AppendText(const QString& Setting, const QString& Value);
virtual void SetTextMap(const QString& Setting, const QMap<QString, QStringList> Map);
virtual QMap<QString, QStringList> GetTextMap(const QString& Setting);
virtual SB_STATUS DelValue(const QString& Setting, const QString& Value = QString()); virtual SB_STATUS DelValue(const QString& Setting, const QString& Value = QString());
virtual QList<QPair<QString, QString>> GetIniSection(qint32* pStatus = NULL, bool withTemplates = false) const; virtual QList<QPair<QString, QString>> GetIniSection(qint32* pStatus = NULL, bool withTemplates = false) const;

View File

@ -25,7 +25,8 @@ CSbieView::CSbieView(QWidget* parent) : CPanelView(parent)
m_pMainLayout->setContentsMargins(0,0,0,0); m_pMainLayout->setContentsMargins(0,0,0,0);
this->setLayout(m_pMainLayout); this->setLayout(m_pMainLayout);
//m_UserConfigChanged = false; m_UserConfigChanged = false;
m_HoldExpand = false;
m_pSbieModel = new CSbieModel(this); m_pSbieModel = new CSbieModel(this);
m_pSbieModel->SetTree(true); m_pSbieModel->SetTree(true);
@ -454,8 +455,11 @@ void CSbieView::Refresh()
QModelIndex ModelIndex = m_pSbieModel->FindIndex(ID); QModelIndex ModelIndex = m_pSbieModel->FindIndex(ID);
if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eProcess) if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eProcess) {
m_HoldExpand = true;
m_pSbieTree->expand(m_pSortProxy->mapFromSource(ModelIndex)); m_pSbieTree->expand(m_pSortProxy->mapFromSource(ModelIndex));
m_HoldExpand = false;
}
else else
{ {
QString Name; QString Name;
@ -464,8 +468,11 @@ void CSbieView::Refresh()
else if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eBox) else if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eBox)
Name = m_pSbieModel->GetSandBox(ModelIndex)->GetName(); Name = m_pSbieModel->GetSandBox(ModelIndex)->GetName();
if (!m_Collapsed.contains(Name)) if (!m_Collapsed.contains(Name)) {
m_HoldExpand = true;
m_pSbieTree->expand(m_pSortProxy->mapFromSource(ModelIndex)); m_pSbieTree->expand(m_pSortProxy->mapFromSource(ModelIndex));
m_HoldExpand = false;
}
} }
} }
}); });
@ -921,7 +928,7 @@ void CSbieView::OnGroupAction(QAction* Action)
Refresh(); Refresh();
} }
//m_UserConfigChanged = true; m_UserConfigChanged = true;
UpdateMoveMenu(); UpdateMoveMenu();
SaveUserConfig(); SaveUserConfig();
@ -1001,7 +1008,7 @@ QString CSbieView::AddNewGroup()
m_Groups[Parent].append(Name); m_Groups[Parent].append(Name);
//m_UserConfigChanged = true; m_UserConfigChanged = true;
UpdateMoveMenu(); UpdateMoveMenu();
SaveUserConfig(); SaveUserConfig();
@ -1435,7 +1442,7 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList<CSandBoxPtr>& SandB
CSandMan::CheckResults(Results); CSandMan::CheckResults(Results);
//m_UserConfigChanged = true; m_UserConfigChanged = true;
SaveUserConfig(); SaveUserConfig();
} }
@ -1826,6 +1833,9 @@ void CSbieView::ShowOptions(const QString& Name)
void CSbieView::ChangeExpand(const QModelIndex& index, bool bExpand) void CSbieView::ChangeExpand(const QModelIndex& index, bool bExpand)
{ {
if (m_HoldExpand)
return;
QModelIndex ModelIndex = m_pSortProxy->mapToSource(index); QModelIndex ModelIndex = m_pSortProxy->mapToSource(index);
if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eProcess) if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eProcess)
@ -1842,27 +1852,34 @@ void CSbieView::ChangeExpand(const QModelIndex& index, bool bExpand)
else else
m_Collapsed.insert(Name); m_Collapsed.insert(Name);
//m_UserConfigChanged = true; m_UserConfigChanged = true;
SaveUserConfig(); SaveUserConfig();
} }
void CSbieView::ReloadUserConfig() void CSbieView::ReloadUserConfig()
{ {
m_Groups.clear(); if (!theAPI->IsConnected())
return;
m_Groups = theAPI->GetUserSettings()->GetTextMap("BoxGrouping");
if (m_Groups.isEmpty()) { // try legacy entries
QString Grouping = theConf->GetString("UIConfig/BoxDisplayOrder"); QString Grouping = theConf->GetString("UIConfig/BoxDisplayOrder");
if(Grouping.isEmpty()) if (Grouping.isEmpty())
Grouping = theAPI->GetUserSettings()->GetText("BoxDisplayOrder"); Grouping = theAPI->GetUserSettings()->GetText("BoxDisplayOrder");
CSbieView__ParseGroup(Grouping, m_Groups); CSbieView__ParseGroup(Grouping, m_Groups);
}
UpdateMoveMenu(); UpdateMoveMenu();
QMap<QString, QStringList> Collapsed = theAPI->GetUserSettings()->GetTextMap("CollapsedBoxes");
m_Collapsed = ListToSet(Collapsed[""]);
if (m_Collapsed.isEmpty()) { // try legacy entries
QString Collapsed = theConf->GetString("UIConfig/BoxCollapsedView"); QString Collapsed = theConf->GetString("UIConfig/BoxCollapsedView");
if (Collapsed.isEmpty()) if (Collapsed.isEmpty())
Collapsed = theAPI->GetUserSettings()->GetText("BoxCollapsedView"); Collapsed = theAPI->GetUserSettings()->GetText("BoxCollapsedView");
m_Collapsed = ListToSet(SplitStr(Collapsed, ",")); m_Collapsed = ListToSet(SplitStr(Collapsed, ","));
}
ClearUserUIConfig(); ClearUserUIConfig();
} }
@ -1895,11 +1912,14 @@ void CSbieView::ClearUserUIConfig(const QMap<QString, CSandBoxPtr> AllBoxes)
void CSbieView::SaveUserConfig() void CSbieView::SaveUserConfig()
{ {
//if (!m_UserConfigChanged) if (!m_UserConfigChanged)
// return; return;
//m_UserConfigChanged = false; m_UserConfigChanged = false;
if (!m_Groups.isEmpty()) { if (!theAPI->IsConnected())
return;
theAPI->GetUserSettings()->SetRefreshOnChange(false);
auto Groups = m_Groups; auto Groups = m_Groups;
// clean up non existing entries // clean up non existing entries
@ -1909,13 +1929,14 @@ void CSbieView::SaveUserConfig()
I->removeAll(Name); I->removeAll(Name);
} }
} }
theAPI->GetUserSettings()->SetTextMap("BoxGrouping", Groups);
QString Grouping = CSbieView__SerializeGroup(Groups); QMap<QString, QStringList> Collapsed;
theConf->SetValue("UIConfig/BoxDisplayOrder", Grouping); Collapsed.insert("", SetToList(m_Collapsed));
} theAPI->GetUserSettings()->SetTextMap("CollapsedBoxes", Collapsed);
QString Collapsed = SetToList(m_Collapsed).join(","); theAPI->GetUserSettings()->SetRefreshOnChange(true);
theConf->SetValue("UIConfig/BoxCollapsedView", Collapsed); theAPI->CommitIniChanges();
} }
void CSbieView::OnMoveItem(const QString& Name, const QString& To, int row) void CSbieView::OnMoveItem(const QString& Name, const QString& To, int row)
@ -1933,7 +1954,7 @@ void CSbieView::OnMoveItem(const QString& Name, const QString& To, int row)
Refresh(); Refresh();
} }
//m_UserConfigChanged = true; m_UserConfigChanged = true;
UpdateMoveMenu(); UpdateMoveMenu();
SaveUserConfig(); SaveUserConfig();

View File

@ -79,7 +79,8 @@ protected:
QMap<QString, QStringList> m_Groups; QMap<QString, QStringList> m_Groups;
QSet<QString> m_Collapsed; QSet<QString> m_Collapsed;
//bool m_UserConfigChanged; bool m_UserConfigChanged;
bool m_HoldExpand;
private: private: