From c0e864b8175e5da74b7d2f00e3cc5bee1a9d6b24 Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Thu, 15 Sep 2022 15:58:41 +0800 Subject: [PATCH 01/10] Update SbieView.cpp Fix https://github.com/sandboxie-plus/Sandboxie/issues/2231 Fix the issue that BoxCollapsedView is not refreshed in time when groups are renamed and deleted. --- SandboxiePlus/SandMan/Views/SbieView.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index c598bb40..48e75dff 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -704,6 +704,9 @@ void CSbieView::RenameGroup(const QString OldName, const QString NewName) auto Group = m_Groups.take(OldName); m_Groups.insert(NewName, Group); + m_Collapsed.remove(OldName); + m_Collapsed.insert(NewName); + RenameItem(OldName, NewName); } @@ -814,6 +817,7 @@ void CSbieView::OnGroupAction(QAction* Action) break; } } + m_Collapsed.remove(Group); } } } From 138387328a53c5e45e2836a9acec4264107dde23 Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Thu, 15 Sep 2022 16:01:54 +0800 Subject: [PATCH 02/10] Update SbieView.cpp Fix https://github.com/sandboxie-plus/Sandboxie/issues/2231 When creating groups nested within groups, m_Groups.append ran twice and now removes a value. --- SandboxiePlus/SandMan/Views/SbieView.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 48e75dff..b5d1ebf3 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -777,6 +777,7 @@ void CSbieView::OnGroupAction(QAction* Action) if (List.isEmpty()) return; m_Groups[""].removeAll(Name); + m_Groups[List.first()].removeAll(Name); m_Groups[List.first()].append(Name); } else if (Action == m_pRenGroupe) From e254b95cb26c8cde0e783eb05fd11d49237b05ad Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Thu, 15 Sep 2022 16:09:48 +0800 Subject: [PATCH 03/10] Update SbieView.cpp Fix https://github.com/sandboxie-plus/Sandboxie/issues/2231 OldValue should be the underlined version, which should be in the same format as m_Groups Value. Otherwise OldValue can never be found in m_Groups. Fix BoxDisplayOrder not being refreshed in time when renaming and deleting sandbox operations. --- SandboxiePlus/SandMan/Views/SbieView.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index b5d1ebf3..d9bb7f6b 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -1198,14 +1198,14 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB } else if (Action == m_pMenuRename) { - QString OldValue = SandBoxes.first()->GetName().replace("_", " "); - QString Value = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a new name for the Sandbox."), QLineEdit::Normal, OldValue); + QString OldValue = SandBoxes.first()->GetName(); + QString Value = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a new name for the Sandbox."), QLineEdit::Normal, OldValue).replace(" ", "_"); if (Value.isEmpty() || Value == OldValue) return; if (!TestNameAndWarn(Value)) return; - Results.append((SandBoxes.first()->RenameBox(Value.replace(" ", "_")))); + Results.append((SandBoxes.first()->RenameBox(Value))); RenameItem(OldValue, Value); } @@ -1226,6 +1226,12 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB if (!Status.IsError()) Status = pBox->RemoveBox(); Results.append(Status); + + for (auto I = m_Groups.begin(); I != m_Groups.end(); ++I) + { + if (I.value().removeOne(pBox->GetName())) + break; + } } } else if (Action == m_pMenuCleanUp) @@ -1345,6 +1351,9 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB } CSandMan::CheckResults(Results); + + //m_UserConfigChanged = true; + SaveUserConfig(); } void CSbieView::OnProcessAction() From 04792c218ff65892e156a51692869c01a1352aad Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Thu, 15 Sep 2022 16:24:15 +0800 Subject: [PATCH 04/10] Fix SizeCache Delete cleans up old data when the sandbox is renamed. I hope to delete or refuse to write Size by default when m_TotalSize is 0. This avoids extra cleanup work. Fix https://github.com/sandboxie-plus/Sandboxie/issues/2231 --- SandboxiePlus/SandMan/SbiePlusAPI.cpp | 7 +++++-- SandboxiePlus/SandMan/Views/SbieView.cpp | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.cpp b/SandboxiePlus/SandMan/SbiePlusAPI.cpp index 17fb623b..36db6fc9 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.cpp +++ b/SandboxiePlus/SandMan/SbiePlusAPI.cpp @@ -236,8 +236,11 @@ void CSandBoxPlus::UpdateSize() void CSandBoxPlus::SetSize(quint64 Size) { - m_TotalSize = Size; - theConf->SetValue("SizeCache/" + m_Name, Size); + m_TotalSize = Size; + if (m_TotalSize == 0) + theConf->DelValue("SizeCache/" + m_Name); + else + theConf->SetValue("SizeCache/" + m_Name, Size); } bool CSandBoxPlus::IsSizePending() const diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index d9bb7f6b..826f7559 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -1208,6 +1208,7 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB Results.append((SandBoxes.first()->RenameBox(Value))); RenameItem(OldValue, Value); + theConf->DelValue("SizeCache/" + OldValue); } else if (Action == m_pMenuRecover) { @@ -1232,7 +1233,7 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB if (I.value().removeOne(pBox->GetName())) break; } - } + } } else if (Action == m_pMenuCleanUp) { From 3e406dc4eebe5643a3febbba8f322184edff7c5d Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Thu, 15 Sep 2022 17:01:16 +0800 Subject: [PATCH 05/10] Update SbieView.cpp --- SandboxiePlus/SandMan/Views/SbieView.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 826f7559..560bb6e0 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -1224,13 +1224,14 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB SB_STATUS Status = theGUI->DeleteBoxContent(pBox, CSandMan::eForDelete); if (Status.GetMsgCode() == SB_Canceled) break; + QString m_Name = pBox->GetName(); if (!Status.IsError()) Status = pBox->RemoveBox(); Results.append(Status); for (auto I = m_Groups.begin(); I != m_Groups.end(); ++I) { - if (I.value().removeOne(pBox->GetName())) + if (I.value().removeOne(m_Name)) break; } } From b20c87569f2f529900f8aad1e21eadaabdbac3c1 Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Fri, 16 Sep 2022 05:45:35 +0800 Subject: [PATCH 06/10] Update SbieView.cpp --- SandboxiePlus/SandMan/Views/SbieView.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 560bb6e0..5c10d8d5 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -1205,10 +1205,13 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB if (!TestNameAndWarn(Value)) return; - Results.append((SandBoxes.first()->RenameBox(Value))); - - RenameItem(OldValue, Value); - theConf->DelValue("SizeCache/" + OldValue); + SB_STATUS Status = SandBoxes.first()->RenameBox(Value); + if (!Status.IsError()) + { + RenameItem(OldValue, Value); + theConf->DelValue("SizeCache/" + OldValue); + } + Results.append(Status); } else if (Action == m_pMenuRecover) { From 379ffa750a4b689859a5e4f82f14462b59489241 Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Fri, 16 Sep 2022 05:57:02 +0800 Subject: [PATCH 07/10] Update SbieView.cpp --- SandboxiePlus/SandMan/Views/SbieView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 5c10d8d5..37ef2217 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -704,8 +704,8 @@ void CSbieView::RenameGroup(const QString OldName, const QString NewName) auto Group = m_Groups.take(OldName); m_Groups.insert(NewName, Group); - m_Collapsed.remove(OldName); - m_Collapsed.insert(NewName); + if (m_Collapsed.remove(OldName)) + m_Collapsed.insert(NewName); RenameItem(OldName, NewName); } From a8cdb4029593234d33d7b6d135e955369214a8cb Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Fri, 16 Sep 2022 07:31:13 +0800 Subject: [PATCH 08/10] Update SbieView.cpp Disable the use of these characters for the Box Group name, which can cause some exceptions. --- SandboxiePlus/SandMan/Views/SbieView.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 37ef2217..7195a878 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -963,6 +963,12 @@ QString CSbieView::AddNewGroup() bool CSbieView::TestNameAndWarn(const QString& Name) { + if (Name.contains(QRegularExpression("[,()]"))) + { + QMessageBox::critical(this, "Sandboxie-Plus", tr("The Sandbox name and Box Group name cannot use the ',()' symbol.")); + return false; + } + if (m_Groups.contains(Name)) { QMessageBox::critical(this, "Sandboxie-Plus", tr("This name is already used for a Box Group.")); return false; From c19bda441645beec7dec4adfc9ac7cd0b0ab9ad9 Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Fri, 16 Sep 2022 07:34:31 +0800 Subject: [PATCH 09/10] Update SbieView.cpp --- SandboxiePlus/SandMan/Views/SbieView.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 7195a878..35288de0 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -1233,14 +1233,14 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB SB_STATUS Status = theGUI->DeleteBoxContent(pBox, CSandMan::eForDelete); if (Status.GetMsgCode() == SB_Canceled) break; - QString m_Name = pBox->GetName(); + QString Name = pBox->GetName(); if (!Status.IsError()) Status = pBox->RemoveBox(); Results.append(Status); for (auto I = m_Groups.begin(); I != m_Groups.end(); ++I) { - if (I.value().removeOne(m_Name)) + if (I.value().removeOne(Name)) break; } } From e6fdde10eb5a079217893c935c31573be4c00c4d Mon Sep 17 00:00:00 2001 From: okrc <29057533+okrc@users.noreply.github.com> Date: Fri, 16 Sep 2022 15:37:22 +0800 Subject: [PATCH 10/10] Restore some changes. --- SandboxiePlus/SandMan/SbiePlusAPI.cpp | 7 ++----- SandboxiePlus/SandMan/Views/SbieView.cpp | 1 - 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.cpp b/SandboxiePlus/SandMan/SbiePlusAPI.cpp index 36db6fc9..17fb623b 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.cpp +++ b/SandboxiePlus/SandMan/SbiePlusAPI.cpp @@ -236,11 +236,8 @@ void CSandBoxPlus::UpdateSize() void CSandBoxPlus::SetSize(quint64 Size) { - m_TotalSize = Size; - if (m_TotalSize == 0) - theConf->DelValue("SizeCache/" + m_Name); - else - theConf->SetValue("SizeCache/" + m_Name, Size); + m_TotalSize = Size; + theConf->SetValue("SizeCache/" + m_Name, Size); } bool CSandBoxPlus::IsSizePending() const diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 35288de0..5469c69c 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -1215,7 +1215,6 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB if (!Status.IsError()) { RenameItem(OldValue, Value); - theConf->DelValue("SizeCache/" + OldValue); } Results.append(Status); }