From bfffaf96a0569ac30ffc00bd326862cc241766c3 Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Thu, 20 Apr 2023 21:52:30 +0200 Subject: [PATCH] 1.9.1 --- CHANGELOG.md | 2 + SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.cpp | 33 ++++++++ SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.h | 3 + SandboxiePlus/SandMan/Views/SbieView.cpp | 89 ++++++++++++-------- SandboxiePlus/SandMan/Views/SbieView.h | 3 +- 5 files changed, 95 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c03a22..62d0bf09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.cpp b/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.cpp index 5c8d04c8..78d2408e 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.cpp +++ b/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.cpp @@ -18,6 +18,7 @@ #include "stdafx.h" #include "SbieIni.h" #include "../SbieAPI.h" +#include "../SbieDefs.h" #include #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); } +void CSbieIni::SetTextMap(const QString& Setting, const QMap 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 CSbieIni::GetTextMap(const QString& Setting) +{ + QMap 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> CSbieIni::GetIniSection(qint32* pStatus, bool withTemplates) const { qint32 status = STATUS_SUCCESS; diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.h b/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.h index 3fe3a534..18ca2ad1 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.h +++ b/SandboxiePlus/QSbieAPI/Sandboxie/SbieIni.h @@ -34,6 +34,9 @@ public: virtual SB_STATUS InsertText(const QString& Setting, const QString& Value); virtual SB_STATUS AppendText(const QString& Setting, const QString& Value); + virtual void SetTextMap(const QString& Setting, const QMap Map); + virtual QMap GetTextMap(const QString& Setting); + virtual SB_STATUS DelValue(const QString& Setting, const QString& Value = QString()); virtual QList> GetIniSection(qint32* pStatus = NULL, bool withTemplates = false) const; diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index de2f6a7a..28352be4 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -25,7 +25,8 @@ CSbieView::CSbieView(QWidget* parent) : CPanelView(parent) m_pMainLayout->setContentsMargins(0,0,0,0); this->setLayout(m_pMainLayout); - //m_UserConfigChanged = false; + m_UserConfigChanged = false; + m_HoldExpand = false; m_pSbieModel = new CSbieModel(this); m_pSbieModel->SetTree(true); @@ -454,8 +455,11 @@ void CSbieView::Refresh() 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_HoldExpand = false; + } else { QString Name; @@ -464,8 +468,11 @@ void CSbieView::Refresh() else if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eBox) 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_HoldExpand = false; + } } } }); @@ -921,7 +928,7 @@ void CSbieView::OnGroupAction(QAction* Action) Refresh(); } - //m_UserConfigChanged = true; + m_UserConfigChanged = true; UpdateMoveMenu(); SaveUserConfig(); @@ -1001,7 +1008,7 @@ QString CSbieView::AddNewGroup() m_Groups[Parent].append(Name); - //m_UserConfigChanged = true; + m_UserConfigChanged = true; UpdateMoveMenu(); SaveUserConfig(); @@ -1435,7 +1442,7 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB CSandMan::CheckResults(Results); - //m_UserConfigChanged = true; + m_UserConfigChanged = true; SaveUserConfig(); } @@ -1826,6 +1833,9 @@ void CSbieView::ShowOptions(const QString& Name) void CSbieView::ChangeExpand(const QModelIndex& index, bool bExpand) { + if (m_HoldExpand) + return; + QModelIndex ModelIndex = m_pSortProxy->mapToSource(index); if (m_pSbieModel->GetType(ModelIndex) == CSbieModel::eProcess) @@ -1842,27 +1852,34 @@ void CSbieView::ChangeExpand(const QModelIndex& index, bool bExpand) else m_Collapsed.insert(Name); - //m_UserConfigChanged = true; + m_UserConfigChanged = true; SaveUserConfig(); } void CSbieView::ReloadUserConfig() { - m_Groups.clear(); + if (!theAPI->IsConnected()) + return; - QString Grouping = theConf->GetString("UIConfig/BoxDisplayOrder"); - if(Grouping.isEmpty()) - Grouping = theAPI->GetUserSettings()->GetText("BoxDisplayOrder"); - CSbieView__ParseGroup(Grouping, m_Groups); + m_Groups = theAPI->GetUserSettings()->GetTextMap("BoxGrouping"); + if (m_Groups.isEmpty()) { // try legacy entries + QString Grouping = theConf->GetString("UIConfig/BoxDisplayOrder"); + if (Grouping.isEmpty()) + Grouping = theAPI->GetUserSettings()->GetText("BoxDisplayOrder"); + CSbieView__ParseGroup(Grouping, m_Groups); + } UpdateMoveMenu(); - QString Collapsed = theConf->GetString("UIConfig/BoxCollapsedView"); - if (Collapsed.isEmpty()) - Collapsed = theAPI->GetUserSettings()->GetText("BoxCollapsedView"); - - m_Collapsed = ListToSet(SplitStr(Collapsed, ",")); + QMap Collapsed = theAPI->GetUserSettings()->GetTextMap("CollapsedBoxes"); + m_Collapsed = ListToSet(Collapsed[""]); + if (m_Collapsed.isEmpty()) { // try legacy entries + QString Collapsed = theConf->GetString("UIConfig/BoxCollapsedView"); + if (Collapsed.isEmpty()) + Collapsed = theAPI->GetUserSettings()->GetText("BoxCollapsedView"); + m_Collapsed = ListToSet(SplitStr(Collapsed, ",")); + } ClearUserUIConfig(); } @@ -1895,27 +1912,31 @@ void CSbieView::ClearUserUIConfig(const QMap AllBoxes) void CSbieView::SaveUserConfig() { - //if (!m_UserConfigChanged) - // return; - //m_UserConfigChanged = false; + if (!m_UserConfigChanged) + return; + m_UserConfigChanged = false; - if (!m_Groups.isEmpty()) { + if (!theAPI->IsConnected()) + return; - auto Groups = m_Groups; - // clean up non existing entries - for (auto I = Groups.begin(); I != Groups.end(); ++I) { - foreach(const QString &Name, I.value()) { - if (theAPI->GetBoxByName(Name).isNull() && !Groups.contains(Name)) - I->removeAll(Name); - } + theAPI->GetUserSettings()->SetRefreshOnChange(false); + + auto Groups = m_Groups; + // clean up non existing entries + for (auto I = Groups.begin(); I != Groups.end(); ++I) { + foreach(const QString &Name, I.value()) { + if (theAPI->GetBoxByName(Name).isNull() && !Groups.contains(Name)) + I->removeAll(Name); } - - QString Grouping = CSbieView__SerializeGroup(Groups); - theConf->SetValue("UIConfig/BoxDisplayOrder", Grouping); } + theAPI->GetUserSettings()->SetTextMap("BoxGrouping", Groups); - QString Collapsed = SetToList(m_Collapsed).join(","); - theConf->SetValue("UIConfig/BoxCollapsedView", Collapsed); + QMap Collapsed; + Collapsed.insert("", SetToList(m_Collapsed)); + theAPI->GetUserSettings()->SetTextMap("CollapsedBoxes", Collapsed); + + theAPI->GetUserSettings()->SetRefreshOnChange(true); + theAPI->CommitIniChanges(); } 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(); } - //m_UserConfigChanged = true; + m_UserConfigChanged = true; UpdateMoveMenu(); SaveUserConfig(); diff --git a/SandboxiePlus/SandMan/Views/SbieView.h b/SandboxiePlus/SandMan/Views/SbieView.h index 22845838..a0eef798 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.h +++ b/SandboxiePlus/SandMan/Views/SbieView.h @@ -79,7 +79,8 @@ protected: QMap m_Groups; QSet m_Collapsed; - //bool m_UserConfigChanged; + bool m_UserConfigChanged; + bool m_HoldExpand; private: