From f8693ad241899f997ff3d379d3877fe73e72dea6 Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:35:11 +0200 Subject: [PATCH] 1.15.6 --- CHANGELOG.md | 4 +++ Sandboxie/core/dll/guititle.c | 12 +++++-- SandboxiePlus/QSbieAPI/SbieAPI.cpp | 2 +- SandboxiePlus/SandMan/Models/SbieModel.cpp | 6 ++-- SandboxiePlus/SandMan/SbiePlusAPI.cpp | 9 +++++ SandboxiePlus/SandMan/SbiePlusAPI.h | 3 ++ SandboxiePlus/SandMan/Views/SbieView.cpp | 40 ++++++++++++++++------ 7 files changed, 60 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fd78017..dc067250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - fixed issue with Windows 7 caused by the new CustomLCID option [#4117](https://github.com/sandboxie-plus/Sandboxie/issues/4117) +### Added +- added alias for a sandbox [#4112](https://github.com/sandboxie-plus/Sandboxie/issues/4112) + + ## [1.14.5 / 5.69.5] - 2024-07-23 diff --git a/Sandboxie/core/dll/guititle.c b/Sandboxie/core/dll/guititle.c index 455b3bd8..37c6652a 100644 --- a/Sandboxie/core/dll/guititle.c +++ b/Sandboxie/core/dll/guititle.c @@ -71,13 +71,21 @@ _FX BOOLEAN Gui_InitTitle(HMODULE module) SbieDll_GetSettingsForName(NULL, Dll_ImageName, L"BoxNameTitle", buf, sizeof(buf), NULL); if (*buf == L'y' || *buf == L'Y') { // indicator + box name + const WCHAR* BoxName = Dll_BoxName; + + NTSTATUS status; + WCHAR BoxAlias[MAX_PATH]; + status = SbieApi_QueryConfAsIs(NULL, L"BoxAlias", 0, BoxAlias, ARRAYSIZE(BoxAlias)); + if (NT_SUCCESS(status) && *BoxAlias) + BoxName = BoxAlias; + UNICODE_STRING uni; - Gui_BoxNameTitleLen = wcslen(Dll_BoxName) + 3; + Gui_BoxNameTitleLen = wcslen(BoxName) + 3; Gui_BoxNameTitleW = Dll_Alloc((Gui_BoxNameTitleLen + 3) * sizeof(WCHAR)); Gui_BoxNameTitleW[0] = Gui_TitleSuffixW[1]; // L'[' - wcscpy(&Gui_BoxNameTitleW[1], Dll_BoxName); + wcscpy(&Gui_BoxNameTitleW[1], BoxName); wcscat(Gui_BoxNameTitleW, &Gui_TitleSuffixW[3]); // L"]" wcscat(Gui_BoxNameTitleW, L" "); diff --git a/SandboxiePlus/QSbieAPI/SbieAPI.cpp b/SandboxiePlus/QSbieAPI/SbieAPI.cpp index 393f2ef8..15cc430a 100644 --- a/SandboxiePlus/QSbieAPI/SbieAPI.cpp +++ b/SandboxiePlus/QSbieAPI/SbieAPI.cpp @@ -1312,7 +1312,7 @@ QString CSbieAPI::SbieIniGet2(const QString& Section, const QString& Setting, qu SB_STATUS CSbieAPI::ValidateName(const QString& BoxName) { - if (BoxName.length() > (BOXNAME_COUNT - 2)) + if (BoxName.length() > (BOXNAME_COUNT - 2) || BoxName.isEmpty()) return SB_ERR(SB_NameLenLimit); /* invalid file name characters on windows diff --git a/SandboxiePlus/SandMan/Models/SbieModel.cpp b/SandboxiePlus/SandMan/Models/SbieModel.cpp index 3c9729a4..d7c4fee9 100644 --- a/SandboxiePlus/SandMan/Models/SbieModel.cpp +++ b/SandboxiePlus/SandMan/Models/SbieModel.cpp @@ -327,8 +327,10 @@ QList CSbieModel::Sync(const QMap& BoxList, cons QVariant Value; switch(section) { - case eName: Value = pBox->GetName(); break; + case eName: Value = pBoxEx->GetDisplayName(); break; + //case eName: Value = pBox->GetName(); break; case eStatus: Value = pBox.objectCast()->GetStatusStr(); break; + case eTitle: Value = pBox->GetDesktop(); break; case eInfo: Value = pBox.objectCast()->IsEmptyCached() ? -2 : (bWatchSize ? pBox.objectCast()->GetSize() : 0); break; case ePath: Value = pBox->GetFileRoot(); break; } @@ -343,7 +345,7 @@ QList CSbieModel::Sync(const QMap& BoxList, cons switch (section) { - case eName: ColValue.Formatted = Value.toString().replace("_", " "); break; + //case eName: ColValue.Formatted = Value.toString().replace("_", " "); break; case eInfo: ColValue.Formatted = Value.toULongLong() == -2 ? tr("Empty") : (Value.toULongLong() > 0 ? FormatSize(Value.toULongLong()) : ""); break; } } diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.cpp b/SandboxiePlus/SandMan/SbiePlusAPI.cpp index 89d6340a..545b487e 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.cpp +++ b/SandboxiePlus/SandMan/SbiePlusAPI.cpp @@ -410,6 +410,15 @@ void CSandBoxPlus::UpdateDetails() QStringList BorderCfg = GetText("BorderColor").split(","); m_BoxColor = QColor("#" + BorderCfg[0].mid(5, 2) + BorderCfg[0].mid(3, 2) + BorderCfg[0].mid(1, 2)).rgb(); + + m_BoxAlias = GetText("BoxAlias"); +} + +QString CSandBoxPlus::GetDisplayName() const +{ + if (!m_BoxAlias.isEmpty()) + return m_BoxAlias; + return GetName().replace("_", " "); } bool CSandBoxPlus::IsBoxexPath(const QString& Path) diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.h b/SandboxiePlus/SandMan/SbiePlusAPI.h index da3dc4f6..b6990ae3 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.h +++ b/SandboxiePlus/SandMan/SbiePlusAPI.h @@ -72,6 +72,8 @@ public: CSandBoxPlus(const QString& BoxName, class CSbieAPI* pAPI); virtual ~CSandBoxPlus(); + virtual QString GetDisplayName() const; + SB_PROGRESS ExportBox(const QString& FileName, const QString& Password = "", int Level = 5, bool Solid = false); SB_PROGRESS ImportBox(const QString& FileName, const QString& Password = ""); @@ -256,6 +258,7 @@ protected: bool m_BoxDel; bool m_NoForce; QRgb m_BoxColor; + QString m_BoxAlias; }; /////////////////////////////////////////////////////////////////////////////// diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index a1fb458e..21e25a6f 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -1411,21 +1411,39 @@ 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); - if (Value.isEmpty() || Value == OldValue) + auto pBox = SandBoxes.first(); + QString OldValue = pBox->GetName().replace("_", " "); + QString Alias = pBox->GetText("BoxAlias"); + bool bAlias = false; + if (bAlias = !Alias.isEmpty()) + OldValue = Alias; + bool bOk = false; + QString Value = QInputDialog::getText(this, "Sandboxie-Plus", bAlias ? tr("Please enter a new alias for the Sandbox.") : tr("Please enter a new name for the Sandbox."), QLineEdit::Normal, OldValue, &bOk); + if (!bOk || Value == OldValue) return; - if (!TestNameAndWarn(Value)) + if (!Value.isEmpty() && !TestNameAndWarn(Value)) return; - SB_STATUS Status = SandBoxes.first()->RenameBox(Value.replace(" ", "_")); - if (!Status.IsError()) + bool bError = false; + if (bAlias || (bError = CSbieAPI::ValidateName(QString(Value).replace(" ", "_")).IsError())) { - RenameItem(OldValue.replace(" ", "_"), Value.replace(" ", "_")); - if (theAPI->GetGlobalSettings()->GetText("DefaultBox", "DefaultBox").compare(OldValue.replace(" ", "_"), Qt::CaseInsensitive) == 0) - theAPI->GetGlobalSettings()->SetText("DefaultBox", Value.replace(" ", "_")); + if (!bAlias && QMessageBox::question(this, "Sandboxie-Plus", tr("The entered name is not valid, do you want to set it as an alias instead?"), QMessageBox::Yes, QMessageBox::No) != QMessageBox::Yes) + return; + if (Value.isEmpty()) pBox->DelValue("BoxAlias"); + else pBox->SetText("BoxAlias", Value); + pBox->UpdateDetails(); + } + else + { + SB_STATUS Status = pBox->RenameBox(Value.replace(" ", "_")); + if (!Status.IsError()) + { + RenameItem(OldValue.replace(" ", "_"), Value.replace(" ", "_")); + if (theAPI->GetGlobalSettings()->GetText("DefaultBox", "DefaultBox").compare(OldValue.replace(" ", "_"), Qt::CaseInsensitive) == 0) + theAPI->GetGlobalSettings()->SetText("DefaultBox", Value.replace(" ", "_")); + } + Results.append(Status); } - Results.append(Status); SaveBoxGrouping(); } @@ -1720,7 +1738,7 @@ void CSbieView::ShowOptions(const CSandBoxPtr& pBox) { auto pBoxEx = pBox.objectCast(); if (pBoxEx->m_pOptionsWnd == NULL) { - pBoxEx->m_pOptionsWnd = new COptionsWindow(pBox, pBox->GetName()); + pBoxEx->m_pOptionsWnd = new COptionsWindow(pBox, pBoxEx->GetDisplayName()); connect(theGUI, SIGNAL(Closed()), pBoxEx->m_pOptionsWnd, SLOT(close())); connect(pBoxEx->m_pOptionsWnd, &COptionsWindow::Closed, [pBoxEx]() { pBoxEx->m_pOptionsWnd = NULL;