This commit is contained in:
love-code-yeyixiao 2024-07-01 18:43:06 +08:00
parent fef278ad76
commit 721f2da032
5 changed files with 85 additions and 3 deletions

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -331,6 +331,7 @@ 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()));
@ -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());

View File

@ -111,6 +111,13 @@ int main(int argc, char *argv[])
}
}
int DfpPos = Args.indexOf("/disable_force", Qt::CaseInsensitive);
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;
@ -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!"));