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/Forms/SettingsWindow.ui b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui index a30acc1e..0d4a8de9 100644 --- a/SandboxiePlus/SandMan/Forms/SettingsWindow.ui +++ b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui @@ -48,7 +48,7 @@ QTabWidget::North - 5 + 1 @@ -477,7 +477,7 @@ - + Start UI when a sandboxed process is started @@ -544,14 +544,14 @@ - + Always use DefaultBox - + Add 'Run Un-Sandboxed' to the context menu @@ -565,7 +565,14 @@ - + + + + Add 'Open Path to Certain Sandbox' to context menu + + + + @@ -579,14 +586,14 @@ - + Scan shell folders and offer links in run menu - + Integrate with Host Start Menu @@ -599,10 +606,10 @@ - + - + Integrate with Host Desktop @@ -615,10 +622,10 @@ - + - + Qt::Vertical @@ -631,7 +638,7 @@ - + Qt::Horizontal diff --git a/SandboxiePlus/SandMan/SandMan.cpp b/SandboxiePlus/SandMan/SandMan.cpp index cad61cb0..ca73e784 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 response = QInputDialog::getText(g_GUIParent, tr("Which box you want to add in?"), tr("Type the box name which you are going to set:")); + if (!response.isEmpty()) + { + if (theAPI->GetBoxByName(response) != NULL) { + theAPI->GetBoxByName(response)->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/Windows/SettingsWindow.cpp b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp index c2f98f8e..4d09119f 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp @@ -332,6 +332,8 @@ CSettingsWindow::CSettingsWindow(QWidget* parent) 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.chkShellMenu4, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); + connect(ui.chkScanMenu, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); connect(ui.cmbIntegrateMenu, SIGNAL(currentIndexChanged(int)), this, SLOT(OnOptChanged())); @@ -893,6 +895,7 @@ void CSettingsWindow::LoadSettings() ui.chkShellMenu->setCheckState(IsContextMenu()); ui.chkShellMenu2->setChecked(CSbieUtils::HasContextMenu2()); ui.chkShellMenu3->setChecked(CSbieUtils::HasContextMenu3()); + ui.chkShellMenu4->setChecked(CSbieUtils::HasContextMenu4()); ui.chkAlwaysDefault->setChecked(theConf->GetBool("Options/RunInDefaultBox", false)); ui.cmbDPI->setCurrentIndex(theConf->GetInt("Options/DPIScaling", 1)); @@ -1609,6 +1612,15 @@ void CSettingsWindow::SaveSettings() else CSbieUtils::RemoveContextMenu3(); } + if (ui.chkShellMenu4->isChecked() != CSbieUtils::HasContextMenu4()) { + if (ui.chkShellMenu4->isChecked()) { + CSbieUtils::AddContextMenu4(QApplication::applicationDirPath().replace("/", "\\") + "\\SandMan.exe", + tr("&Open Path to Certain Sandbox"), + QApplication::applicationDirPath().replace("/", "\\") + "\\Start.exe"); + } + else + CSbieUtils::RemoveContextMenu4(); + } 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 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!"));