From 74e98031c83e6a5632e3ed2d27678916b6b629c0 Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:41:40 +0100 Subject: [PATCH] #4339 --- CHANGELOG.md | 6 +- SandboxiePlus/SandMan/Views/FileView.cpp | 80 +++++++++++++++++++++++- 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc6bc495..e640ffed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [1.15.2 / 5.70.2] - 2024-10- +## [1.15.2 / 5.70.2] - 2024-11- ### Added - added "NetworkAdapterMAC=0,AA-BB-CC-DD-EE-FF" to set MAC address for each box (thanks Yeyixiao) @@ -17,12 +17,13 @@ This project adheres to [Semantic Versioning](http://semver.org/). - added Hide Tray Icon [#4075](https://github.com/sandboxie-plus/Sandboxie/issues/4075) ### Fixed -- fixed Sign the .tmp file that gets dropped when installing or updating Sandboxie Plus [#2643](https://github.com/sandboxie-plus/Sandboxie/issues/2643) +- fixed Sign the .tmp file that gets dropped when installing or updating Sandboxie Plus [#2643](https://github.com/sandboxie-plus/Sandboxie/issues/2643) [#4343](https://github.com/sandboxie-plus/Sandboxie/issues/4343) - fixed issue with DLL unloading - fixed Files Resource Access - Browse for Folder - allows access to excluded folders [#4007](https://github.com/sandboxie-plus/Sandboxie/issues/4007) - fixed "ForceDisableAdminOnly" is weird [#4233](https://github.com/sandboxie-plus/Sandboxie/issues/4233) - fixed deadlock on no op condition when renaming file or folder [#4304](https://github.com/sandboxie-plus/Sandboxie/issues/4304) - fixed Could not move file or folder [#4329](https://github.com/sandboxie-plus/Sandboxie/issues/4329) +- "Run Sandboxed" from the quick-previewer should have only one option [#4339](https://github.com/sandboxie-plus/Sandboxie/issues/4339) ### Changed - validated compatibility with Windows build 27749 and updated DynData @@ -30,6 +31,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). + ## [1.15.1 / 5.70.1] - 2024-10-29 ### Changed diff --git a/SandboxiePlus/SandMan/Views/FileView.cpp b/SandboxiePlus/SandMan/Views/FileView.cpp index af9eb2fd..ae01ea03 100644 --- a/SandboxiePlus/SandMan/Views/FileView.cpp +++ b/SandboxiePlus/SandMan/Views/FileView.cpp @@ -103,6 +103,7 @@ void CFileView::OnAboutToBeModified() #include #include +#define MENU_SANDBOX -1 #define MENU_RECOVER 1 #define MENU_RECOVER_TO_ANY 2 #define MENU_CREATE_SHORTCUT 3 @@ -134,6 +135,57 @@ void addItemToShellContextMenu(HMENU hMenu, const wchar_t *name, int ID, bool bC InsertMenuItem(hMenu, 0, TRUE, &menu_item_info); } +void RemoveMenuItemByVerb(HMENU hMenu, IContextMenu* pContextMenu, UINT idCmdFirst, UINT idCmdLast, const std::wstring& verbToRemove) +{ + int itemCount = GetMenuItemCount(hMenu); + for (int i = itemCount - 1; i >= 0; --i) + { + MENUITEMINFO menuItemInfo = { 0 }; + menuItemInfo.cbSize = sizeof(MENUITEMINFO); + menuItemInfo.fMask = MIIM_ID | MIIM_SUBMENU; + + if (GetMenuItemInfo(hMenu, i, TRUE, &menuItemInfo)) + { + if (menuItemInfo.hSubMenu) + { + // Recursive call for submenus + RemoveMenuItemByVerb(menuItemInfo.hSubMenu, pContextMenu, idCmdFirst, idCmdLast, verbToRemove); + + // Remove the submenu if it's empty + if (GetMenuItemCount(menuItemInfo.hSubMenu) == 0) + { + DeleteMenu(hMenu, i, MF_BYPOSITION); + } + } + else + { + UINT cmdID = menuItemInfo.wID; + if (cmdID >= idCmdFirst && cmdID < idCmdLast) + { + // Retrieve the verb associated with this command ID + wchar_t verbBuffer[256] = { 0 }; + HRESULT hr = pContextMenu->GetCommandString( + cmdID - idCmdFirst, // Adjust for idCmdFirst + GCS_VERBW, + NULL, + (LPSTR)verbBuffer, + sizeof(verbBuffer) / sizeof(wchar_t) + ); + + if (SUCCEEDED(hr)) + { + if (_wcsicmp(verbBuffer, verbToRemove.c_str()) == 0) + { + // Remove the menu item + DeleteMenu(hMenu, i, MF_BYPOSITION); + } + } + } + } + } + } +} + int openShellContextMenu(const QStringList& Files, void* parentWindow, const CSandBoxPtr& pBox, QString* pPin = NULL) { CComPtr pDesktop; @@ -182,8 +234,15 @@ int openShellContextMenu(const QStringList& Files, void* parentWindow, const CSa HMENU hMenu = CreatePopupMenu(); if (!hMenu) return 0; - if (SUCCEEDED(pContextMenu->QueryContextMenu(hMenu, 0, 1, 0x7FFF, CMF_NORMAL))) + UINT idCmdFirst = 1; + HRESULT hrMenu = pContextMenu->QueryContextMenu(hMenu, 0, idCmdFirst, 0x7FFF, CMF_NORMAL); + if (SUCCEEDED(hrMenu)) { + UINT nMenuItems = HRESULT_CODE(hrMenu); + UINT idCmdLast = idCmdFirst + nMenuItems; + + RemoveMenuItemByVerb(hMenu, pContextMenu, idCmdFirst, idCmdLast, L"open"); + addSeparatorToShellContextMenu(hMenu); std::wstring Str1 = CFileView::tr("Create Shortcut").toStdWString(); @@ -235,6 +294,17 @@ int openShellContextMenu(const QStringList& Files, void* parentWindow, const CSa DestroyMenu(hMenu); return iCmd & 0x0FFF; } + + wchar_t verbBuffer[256] = {0}; + HRESULT hr = pContextMenu->GetCommandString(iCmd - 1, GCS_VERBW, NULL, (LPSTR)verbBuffer, sizeof(verbBuffer) / sizeof(wchar_t)); + + if (SUCCEEDED(hr)) { + qDebug() << verbBuffer; + if (_wcsicmp(verbBuffer, L"sandbox") == 0) { + DestroyMenu(hMenu); + return MENU_SANDBOX; + } + } CMINVOKECOMMANDINFOEX info = { 0 }; info.cbSize = sizeof(info); @@ -285,6 +355,14 @@ void CFileView::OnFileMenu(const QPoint&) QString RecoveryFolder; switch (iCmd) { + case MENU_SANDBOX:{ + if (!Files.isEmpty()) { + QString WrkDir = QFileInfo(Files.first()).absoluteDir().path().replace("/", "\\"); + foreach(const QString & Command, Files) + theGUI->RunStart(m_pBox->GetName(), Command, CSbieAPI::eStartDefault, WrkDir); + } + break; + } case MENU_RECOVER_TO_ANY: RecoveryFolder = QFileDialog::getExistingDirectory(this, CFileView::tr("Select Directory")).replace("/", "\\"); if (RecoveryFolder.isEmpty())