Sandboxie/SandboxiePlus/SandMan/main.cpp

86 lines
2.3 KiB
C++
Raw Normal View History

2020-06-01 17:11:56 +01:00
#include "stdafx.h"
#include "SandMan.h"
2021-01-30 18:10:49 +00:00
#include <QtWidgets/QApplication>
2020-06-01 17:11:56 +01:00
#include "../QSbieAPI/SbieAPI.h"
2020-06-08 16:17:37 +01:00
#include "../QtSingleApp/src/qtsingleapplication.h"
#include "../QSbieAPI/SbieUtils.h"
2021-03-30 18:02:06 +01:00
//#include "../MiscHelpers/Common/qRC4.h"
2020-06-18 16:44:29 +01:00
#include "../MiscHelpers/Common/Common.h"
#include <windows.h>
2020-06-01 17:11:56 +01:00
CSettings* theConf = NULL;
int main(int argc, char *argv[])
{
2020-06-18 16:44:29 +01:00
#ifdef Q_OS_WIN
SetProcessDPIAware();
#endif // Q_OS_WIN
//QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
2020-06-08 16:17:37 +01:00
QtSingleApplication app(argc, argv);
2021-01-18 12:04:14 +00:00
app.setQuitOnLastWindowClosed(false);
2020-06-08 16:17:37 +01:00
2020-06-18 16:44:29 +01:00
//InitConsole(false);
2020-06-08 16:17:37 +01:00
SB_STATUS Status = CSbieUtils::DoAssist();
if (Status.GetStatus()) {
2020-12-23 18:17:24 +00:00
if(Status.GetStatus() == ERROR_OK) app.sendMessage("Status:OK");
else app.sendMessage("Status:" + CSandMan::FormatError(Status)); // todo: localization
2020-06-08 16:17:37 +01:00
return 0;
}
2021-07-23 08:44:35 +01:00
QString PendingMessage;
2021-07-05 12:37:28 +01:00
QStringList Args = QCoreApplication::arguments();
2021-07-23 08:44:35 +01:00
int CmdPos = Args.indexOf("-op");
if (CmdPos != -1) {
QString Op;
if (Args.count() > CmdPos)
Op = Args.at(CmdPos + 1);
PendingMessage = "Op:" + Op;
}
CmdPos = Args.indexOf("/box:__ask__");
if (CmdPos != -1) {
QString CommandLine;
for (int i = CmdPos + 1; i < Args.count(); i++)
2021-07-10 09:42:39 +01:00
CommandLine += "\"" + Args[i] + "\" ";
2021-07-23 08:44:35 +01:00
PendingMessage = "Run:" + CommandLine.trimmed();
2021-07-05 12:37:28 +01:00
}
2021-07-23 08:44:35 +01:00
if (!PendingMessage.isEmpty()) {
if(app.sendMessage(PendingMessage))
return 0;
}
2021-07-05 12:37:28 +01:00
else if (app.sendMessage("ShowWnd"))
2020-06-08 16:17:37 +01:00
return 0;
2020-06-01 17:11:56 +01:00
theConf = new CSettings("Sandboxie-Plus");
//QThreadPool::globalInstance()->setMaxThreadCount(theConf->GetInt("Options/MaxThreadPool", 10));
CSandMan* pWnd = new CSandMan();
2021-07-05 12:37:28 +01:00
2020-06-08 16:17:37 +01:00
QObject::connect(&app, SIGNAL(messageReceived(const QString&)), pWnd, SLOT(OnMessage(const QString&)));
2021-07-23 08:44:35 +01:00
if (!PendingMessage.isEmpty())
QMetaObject::invokeMethod(pWnd, "OnMessage", Qt::QueuedConnection, Q_ARG(QString, PendingMessage));
2020-06-08 16:17:37 +01:00
2020-06-01 17:11:56 +01:00
int ret = app.exec();
delete pWnd;
delete theConf;
theConf = NULL;
return ret;
}
2021-07-05 12:37:28 +01:00
/*HANDLE hServerPipe = CreateFileW(L"\\\\.\\pipe\\qtsingleapp-sandma-ca4a-1", GENERIC_ALL, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hServerPipe != INVALID_HANDLE_VALUE) {
DWORD lenWritten;
WriteFile(hServerPipe, "test", 4, &lenWritten, NULL)
CloseHandle(hServerPipe);
}*/