From 721f2da0320affcd0656aac75b99d8e8742d5f0c Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Mon, 1 Jul 2024 18:43:06 +0800 Subject: [PATCH] 1.14.3 --- SandboxiePlus/QSbieAPI/SbieUtils.cpp | 36 +++++++++++++++++++ SandboxiePlus/QSbieAPI/SbieUtils.h | 4 +++ SandboxiePlus/SandMan/SandMan.cpp | 19 ++++++++++ .../SandMan/Windows/SettingsWindow.cpp | 14 ++++++-- SandboxiePlus/SandMan/main.cpp | 15 +++++++- 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/SandboxiePlus/QSbieAPI/SbieUtils.cpp b/SandboxiePlus/QSbieAPI/SbieUtils.cpp index 0466b92c..f176148d 100644 --- a/SandboxiePlus/QSbieAPI/SbieUtils.cpp +++ b/SandboxiePlus/QSbieAPI/SbieUtils.cpp @@ -487,6 +487,42 @@ void CSbieUtils::RemoveContextMenu2() RegDeleteTreeW(HKEY_CURRENT_USER, L"software\\classes\\*\\shell\\unbox"); } +bool CSbieUtils::HasContextMenu3() +{ + const wchar_t* key = L"Software\\Classes\\*\\shell\\addforce\\command"; + const wchar_t* key2 = L"Software\\Classes\\*\\folder\\addforce\\command"; + HKEY hkey; + 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, &hkey); + if (rc != 0) + return false; + + RegCloseKey(hkey); + + return true; +} + +void CSbieUtils::AddContextMenu3(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"addforce", RunStr.toStdWString(), icon_path, start_path + L" /add_force \"%1\" %*"); + CreateShellEntry(L"Folder", L"addforce", RunStr.toStdWString(), icon_path, start_path + L" /add_force \"%1\" %*"); +} + +void CSbieUtils::RemoveContextMenu3() +{ + RegDeleteTreeW(HKEY_CURRENT_USER, L"software\\classes\\*\\shell\\addforce"); + RegDeleteTreeW(HKEY_CURRENT_USER, L"software\\classes\\folder\\shell\\addforce"); +} + ////////////////////////////////////////////////////////////////////////////// // Shortcuts diff --git a/SandboxiePlus/QSbieAPI/SbieUtils.h b/SandboxiePlus/QSbieAPI/SbieUtils.h index c0c38933..c3e858f7 100644 --- a/SandboxiePlus/QSbieAPI/SbieUtils.h +++ b/SandboxiePlus/QSbieAPI/SbieUtils.h @@ -36,6 +36,10 @@ public: static void AddContextMenu2(const QString& StartPath, const QString& RunStr, const QString& IconPath = QString()); static void RemoveContextMenu2(); + static bool HasContextMenu3(); + static void AddContextMenu3(const QString& StartPath, const QString& RunStr, const QString& IconPath = QString()); + static void RemoveContextMenu3(); + 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 4e7937e9..890c2ed5 100644 --- a/SandboxiePlus/SandMan/SandMan.cpp +++ b/SandboxiePlus/SandMan/SandMan.cpp @@ -1636,6 +1636,25 @@ void CSandMan::OnMessage(const QString& MsgData) setWindowState(Qt::WindowActive); SetForegroundWindow(MainWndHandle); } + else if (Message.left(4) == "Add:") + { + + + 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) { + if (Message.right(1)=="\\"||!Message.contains(".", Qt::CaseInsensitive)) { + theAPI->GetBoxByName(respone)->AppendText("ForceFolder", Message.mid(4)); + } + else { + theAPI->GetBoxByName(respone)->AppendText("ForceProcess", Message.mid(4)); + + } + } + } + + } else if (Message.left(4) == "Run:") { QString BoxName; diff --git a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp index 91700bd7..c2f98f8e 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp @@ -331,7 +331,8 @@ CSettingsWindow::CSettingsWindow(QWidget* parent) connect(ui.chkShellMenu, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); connect(ui.chkAlwaysDefault, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); connect(ui.chkShellMenu2, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); - + connect(ui.chkShellMenu3, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); + connect(ui.chkScanMenu, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); connect(ui.cmbIntegrateMenu, SIGNAL(currentIndexChanged(int)), this, SLOT(OnOptChanged())); connect(ui.cmbIntegrateDesk, SIGNAL(currentIndexChanged(int)), this, SLOT(OnOptChanged())); @@ -891,6 +892,7 @@ void CSettingsWindow::LoadSettings() ui.chkShellMenu->setCheckState(IsContextMenu()); ui.chkShellMenu2->setChecked(CSbieUtils::HasContextMenu2()); + ui.chkShellMenu3->setChecked(CSbieUtils::HasContextMenu3()); ui.chkAlwaysDefault->setChecked(theConf->GetBool("Options/RunInDefaultBox", false)); ui.cmbDPI->setCurrentIndex(theConf->GetInt("Options/DPIScaling", 1)); @@ -1598,7 +1600,15 @@ void CSettingsWindow::SaveSettings() } else CSbieUtils::RemoveContextMenu2(); } - + if (ui.chkShellMenu3->isChecked() != CSbieUtils::HasContextMenu3()) { + if (ui.chkShellMenu3->isChecked()) { + CSbieUtils::AddContextMenu3(QApplication::applicationDirPath().replace("/", "\\") + "\\SandMan.exe", + tr("Make Folder/File &Forced"), + QApplication::applicationDirPath().replace("/", "\\") + "\\Start.exe"); + } + else + CSbieUtils::RemoveContextMenu3(); + } theConf->SetValue("Options/RunInDefaultBox", ui.chkAlwaysDefault->isChecked()); theConf->SetValue("Options/CheckSilentMode", ui.chkSilentMode->isChecked()); diff --git a/SandboxiePlus/SandMan/main.cpp b/SandboxiePlus/SandMan/main.cpp index ce5d1baa..6d1f88c2 100644 --- a/SandboxiePlus/SandMan/main.cpp +++ b/SandboxiePlus/SandMan/main.cpp @@ -111,7 +111,14 @@ int main(int argc, char *argv[]) } } int DfpPos = Args.indexOf("/disable_force", Qt::CaseInsensitive); - // the first argument wins + int AfpPos = Args.indexOf("/add_force", Qt::CaseInsensitive); + + //Add_Force has the highest priority. + if (AfpPos != -1) { + DfpPos = -1; + BoxPos = -1; + }else + // the first argument wins if (BoxPos != -1 && DfpPos != -1) { if (BoxPos < DfpPos) DfpPos = -1; else BoxPos = -1; @@ -158,7 +165,13 @@ int main(int argc, char *argv[]) g_PendingMessage += "\nIn:*DFP*"; } + if (AfpPos != -1) { + LPWSTR cmdLine0 = wcsstr(GetCommandLineW(), L"/add_force"); + if (!cmdLine0) return -1; + LPWSTR cmdLine = cmdLine0 + 10; + g_PendingMessage = "Add:" + QString::fromWCharArray(cmdLine + 1); + } if (IsBoxed) { QMessageBox::critical(NULL, "Sandboxie-Plus", CSandMan::tr("Sandboxie Manager can not be run sandboxed!"));