From c1205fd043d4b77b2c2e4d7da24c0f039111ac4b Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Tue, 16 Jul 2024 12:15:03 +0800 Subject: [PATCH] OpenFile Shell --- SandboxiePlus/QSbieAPI/SbieUtils.cpp | 37 ++++++++++++++++++++++++++++ SandboxiePlus/QSbieAPI/SbieUtils.h | 4 +++ SandboxiePlus/SandMan/SandMan.cpp | 20 ++++++++++++++- SandboxiePlus/SandMan/main.cpp | 19 +++++++++++--- 4 files changed, 76 insertions(+), 4 deletions(-) diff --git a/SandboxiePlus/QSbieAPI/SbieUtils.cpp b/SandboxiePlus/QSbieAPI/SbieUtils.cpp index 5f389338..f48c553c 100644 --- a/SandboxiePlus/QSbieAPI/SbieUtils.cpp +++ b/SandboxiePlus/QSbieAPI/SbieUtils.cpp @@ -523,6 +523,43 @@ void CSbieUtils::RemoveContextMenu3() RegDeleteTreeW(HKEY_CURRENT_USER, L"software\\classes\\folder\\shell\\addforce"); } + +bool CSbieUtils::HasContextMenu4() +{ + const wchar_t* key = L"Software\\Classes\\*\\shell\\addopen\\command"; + //const wchar_t* key2 = L"Software\\Classes\\*\\Folder\\addforce\\command"; + HKEY hkey, hKey2; + LONG rc = RegOpenKeyEx(HKEY_CURRENT_USER, key, 0, KEY_READ, &hkey); + if (rc != 0) + return false; + + RegCloseKey(hkey); + + + /*rc = RegOpenKeyEx(HKEY_CURRENT_USER, key2, 0, KEY_READ, &hkey2); + if (rc != 0) + return false; + + RegCloseKey(hkey2);*/ + + return true; +} + +void CSbieUtils::AddContextMenu4(const QString& StartPath, const QString& RunStr, const QString& IconPath) +{ + std::wstring start_path = L"\"" + StartPath.toStdWString() + L"\""; + std::wstring icon_path = L"\"" + (IconPath.isEmpty() ? StartPath : IconPath).toStdWString() + L"\""; + + CreateShellEntry(L"*", L"addopen", RunStr.toStdWString(), icon_path, start_path + L" /add_open \"%1\" %*"); + CreateShellEntry(L"Folder", L"addopen", RunStr.toStdWString(), icon_path, start_path + L" /add_open \"%1\" %*"); +} + +void CSbieUtils::RemoveContextMenu4() +{ + RegDeleteTreeW(HKEY_CURRENT_USER, L"software\\classes\\*\\shell\\addopen"); + RegDeleteTreeW(HKEY_CURRENT_USER, L"software\\classes\\folder\\shell\\addopen"); +} + ////////////////////////////////////////////////////////////////////////////// // Shortcuts diff --git a/SandboxiePlus/QSbieAPI/SbieUtils.h b/SandboxiePlus/QSbieAPI/SbieUtils.h index c3e858f7..7fa44001 100644 --- a/SandboxiePlus/QSbieAPI/SbieUtils.h +++ b/SandboxiePlus/QSbieAPI/SbieUtils.h @@ -40,6 +40,10 @@ public: static void AddContextMenu3(const QString& StartPath, const QString& RunStr, const QString& IconPath = QString()); static void RemoveContextMenu3(); + static bool HasContextMenu4(); + static void AddContextMenu4(const QString& StartPath, const QString& RunStr, const QString& IconPath = QString()); + static void RemoveContextMenu4(); + static bool CreateShortcut(const QString& StartExe, QString LinkPath, const QString &LinkName, const QString &boxname, const QString &arguments, const QString &iconPath = QString(), int iconIndex = 0, const QString &workdir = QString(), bool bRunElevated = false); static bool GetStartMenuShortcut(class CSbieAPI* pApi, QString &BoxName, QString &LinkPath, QString &IconPath, quint32& IconIndex, QString &WorkDir); diff --git a/SandboxiePlus/SandMan/SandMan.cpp b/SandboxiePlus/SandMan/SandMan.cpp index fc68adc8..5cce4fa3 100644 --- a/SandboxiePlus/SandMan/SandMan.cpp +++ b/SandboxiePlus/SandMan/SandMan.cpp @@ -1636,7 +1636,7 @@ void CSandMan::OnMessage(const QString& MsgData) setWindowState(Qt::WindowActive); SetForegroundWindow(MainWndHandle); } - else if (Message.left(4) == "Add:") + else if (Message.left(9) == "AddForce:") { @@ -1660,6 +1660,24 @@ void CSandMan::OnMessage(const QString& MsgData) QMessageBox::warning(g_GUIParent, tr("Sandboxie-Plus Warning"), tr("Users canceled this operation."), QMessageBox::Yes, 0); } } + else if (Message.left(8) == "AddOpen:") + { + + + QString respone = QInputDialog::getText(g_GUIParent, tr("Which box you want to add in?"), tr("Type the box name which you are going to set:")); + if (!respone.isEmpty()) + { + if (theAPI->GetBoxByName(respone) != NULL) { + theAPI->GetBoxByName(respone)->AppendText("OpenFilePath", Message.mid(4).replace("\"", "")); + } + else { + QMessageBox::warning(g_GUIParent, tr("Sandboxie-Plus Warning"), tr("You typed a wrong box name!Nothing was changed."), QMessageBox::Ok, 0); + } + } + else { + QMessageBox::warning(g_GUIParent, tr("Sandboxie-Plus Warning"), tr("Users canceled this operation."), QMessageBox::Yes, 0); + } + } else if (Message.left(4) == "Run:") { QString BoxName; diff --git a/SandboxiePlus/SandMan/main.cpp b/SandboxiePlus/SandMan/main.cpp index 6d1f88c2..5f53b6d2 100644 --- a/SandboxiePlus/SandMan/main.cpp +++ b/SandboxiePlus/SandMan/main.cpp @@ -112,14 +112,20 @@ int main(int argc, char *argv[]) } int DfpPos = Args.indexOf("/disable_force", Qt::CaseInsensitive); int AfpPos = Args.indexOf("/add_force", Qt::CaseInsensitive); + int AOPos = Args.indexOf("/add_open", Qt::CaseInsensitive); //Add_Force has the highest priority. if (AfpPos != -1) { DfpPos = -1; BoxPos = -1; - }else + } + else if (AOPos != -1) + { + DfpPos = -1; + BoxPos = -1; + } // the first argument wins - if (BoxPos != -1 && DfpPos != -1) { + else if (BoxPos != -1 && DfpPos != -1) { if (BoxPos < DfpPos) DfpPos = -1; else BoxPos = -1; } @@ -169,9 +175,16 @@ int main(int argc, char *argv[]) LPWSTR cmdLine0 = wcsstr(GetCommandLineW(), L"/add_force"); if (!cmdLine0) return -1; LPWSTR cmdLine = cmdLine0 + 10; - g_PendingMessage = "Add:" + QString::fromWCharArray(cmdLine + 1); + g_PendingMessage = "AddForce:" + QString::fromWCharArray(cmdLine + 1); } + + if (AOPos != -1) { + LPWSTR cmdLine0 = wcsstr(GetCommandLineW(), L"/add_open"); + if (!cmdLine0) return -1; + LPWSTR cmdLine = cmdLine0 + 10; + g_PendingMessage = "AddOpen:" + QString::fromWCharArray(cmdLine + 1); + } if (IsBoxed) { QMessageBox::critical(NULL, "Sandboxie-Plus", CSandMan::tr("Sandboxie Manager can not be run sandboxed!"));