Sandboxie/SandboxiePlus/SandMan/SandMan.h

460 lines
12 KiB
C
Raw Normal View History

2021-10-16 16:19:51 +01:00
#pragma once
#include <QtWidgets/QMainWindow>
#include "../MiscHelpers/Common/Settings.h"
#include "../MiscHelpers/Common/TreeViewEx.h"
#include "../MiscHelpers/Common/PanelView.h"
#include "../MiscHelpers/Common/ProgressDialog.h"
#include "../MiscHelpers/Common/NetworkAccessManager.h"
#include <QTranslator>
#include "Windows/PopUpWindow.h"
#include "../version.h"
//#include "../QSbieAPI/SbieAPI.h"
#include "SbiePlusAPI.h"
class CSbieView;
2022-07-11 18:30:09 +01:00
class CFileView;
2021-10-16 16:19:51 +01:00
class CBoxBorder;
class CSbieTemplates;
class CTraceView;
class CSandMan : public QMainWindow
{
Q_OBJECT
public:
CSandMan(QWidget *parent = Q_NULLPTR);
virtual ~CSandMan();
CSbieTemplates* GetCompat() { return m_SbieTemplates; }
static QString GetVersion();
2023-05-21 14:25:51 +01:00
bool IsWFPEnabled() const;
2023-05-21 13:48:58 +01:00
2023-05-08 20:35:13 +01:00
SB_PROGRESS RecoverFiles(const QString& BoxName, const QList<QPair<QString, QString>>& FileList, QWidget* pParent, int Action = 0);
2023-01-25 14:55:30 +00:00
SB_PROGRESS CheckFiles(const QString& BoxName, const QStringList& Files);
2021-10-16 16:19:51 +01:00
2022-02-18 19:09:35 +00:00
enum EDelMode {
eDefault,
eAuto,
eForDelete
};
2023-02-03 07:00:11 +00:00
SB_STATUS DeleteBoxContent(const CSandBoxPtr& pBox, EDelMode Mode, bool DeleteSnapshots = true);
2022-02-13 11:55:52 +00:00
2022-02-18 19:09:35 +00:00
SB_STATUS AddAsyncOp(const CSbieProgressPtr& pProgress, bool bWait = false, const QString& InitialMsg = QString());
2021-10-16 16:19:51 +01:00
static QString FormatError(const SB_STATUS& Error);
2023-02-07 20:50:06 +00:00
static void CheckResults(QList<SB_STATUS> Results, bool bAsync = false);
2021-10-16 16:19:51 +01:00
2022-11-05 13:53:44 +00:00
static QIcon GetIcon(const QString& Name, int iAction = 1);
2021-10-16 16:19:51 +01:00
bool IsFullyPortable();
2022-07-09 10:46:07 +01:00
bool IsShowHidden() { return m_pShowHidden && m_pShowHidden->isChecked(); }
bool KeepTerminated() { return m_pKeepTerminated && m_pKeepTerminated->isChecked(); }
bool ShowAllSessions() { return m_pShowAllSessions && m_pShowAllSessions->isChecked(); }
2022-12-15 13:06:58 +00:00
bool IsSilentMode();
bool IsDisableRecovery() {return IsSilentMode() || m_pDisableRecovery && m_pDisableRecovery->isChecked();}
bool IsDisableMessages() {return IsSilentMode() || m_pDisableMessages && m_pDisableMessages->isChecked();}
2021-10-16 16:19:51 +01:00
CSbieView* GetBoxView() { return m_pBoxView; }
2022-07-13 16:00:03 +01:00
CFileView* GetFileView() { return m_pFileView; }
2021-10-16 16:19:51 +01:00
2023-05-25 17:33:24 +01:00
int SafeExec(QDialog* pDialog);
2022-12-06 12:48:18 +00:00
bool RunSandboxed(const QStringList& Commands, QString BoxName = QString(), const QString& WrkDir = QString());
2021-10-16 16:19:51 +01:00
2022-07-09 10:46:07 +01:00
QIcon GetBoxIcon(int boxType, bool inUse = false);// , bool inBusy = false);
2022-07-10 17:28:10 +01:00
QRgb GetBoxColor(int boxType) { return m_BoxColors[boxType]; }
2022-09-29 17:28:48 +01:00
QIcon GetColorIcon(QColor boxColor, bool inUse = false/*, bool bOut = false*/);
2022-07-09 10:46:07 +01:00
QIcon MakeIconBusy(const QIcon& Icon, int Index = 0);
2023-01-28 20:49:24 +00:00
QIcon IconAddOverlay(const QIcon& Icon, const QString& Name, int Size = 24);
2021-10-16 16:19:51 +01:00
QString GetBoxDescription(int boxType);
2022-06-06 18:46:03 +01:00
2022-08-09 17:19:46 +01:00
bool CheckCertificate(QWidget* pWidget);
2021-10-16 16:19:51 +01:00
void UpdateTheme();
void UpdateTitleTheme(const HWND& hwnd);
2021-10-16 16:19:51 +01:00
2022-01-13 22:52:58 +00:00
void UpdateCertState();
signals:
void CertUpdated();
2023-02-01 21:16:41 +00:00
void Closed();
2021-10-16 16:19:51 +01:00
protected:
2022-11-20 16:23:15 +00:00
friend class COnlineUpdater;
2022-02-02 18:31:03 +00:00
SB_RESULT(void*) ConnectSbie();
2021-10-16 16:19:51 +01:00
SB_STATUS ConnectSbieImpl();
SB_STATUS DisconnectSbie();
2022-02-02 18:31:03 +00:00
SB_RESULT(void*) StopSbie(bool andRemove = false);
2021-10-16 16:19:51 +01:00
2023-05-08 20:35:13 +01:00
static void RecoverFilesAsync(QPair<const CSbieProgressPtr&,QWidget*> pParam, const QString& BoxName, const QList<QPair<QString, QString>>& FileList, const QStringList& Checkers, int Action = 0);
2023-01-25 14:55:30 +00:00
static void CheckFilesAsync(const CSbieProgressPtr& pProgress, const QString& BoxName, const QStringList &Files, const QStringList& Checkers);
2021-10-16 16:19:51 +01:00
2023-02-07 20:50:06 +00:00
QIcon GetTrayIcon(bool isConnected = true, bool bSun = false);
2022-02-18 19:09:35 +00:00
QString GetTrayText(bool isConnected = true);
2021-10-16 16:19:51 +01:00
2022-08-09 17:19:46 +01:00
void CheckSupport();
2021-10-16 16:19:51 +01:00
void closeEvent(QCloseEvent* e);
void dragEnterEvent(QDragEnterEvent* e);
void dropEvent(QDropEvent* e);
void timerEvent(QTimerEvent* pEvent);
int m_uTimerID;
bool m_bConnectPending;
bool m_bStopPending;
CBoxBorder* m_pBoxBorder;
CSbieTemplates* m_SbieTemplates;
QMap<CSbieProgress*, CSbieProgressPtr> m_pAsyncProgress;
QStringList m_MissingTemplates;
enum EBoxColors
{
eYellow = 0,
eRed,
eGreen,
eBlue,
eCyan,
eMagenta,
eOrang,
2022-07-10 17:28:10 +01:00
eWhite,
2021-10-16 16:19:51 +01:00
eMaxColor
};
2022-07-10 17:28:10 +01:00
QMap<int, QRgb> m_BoxColors;
2022-09-01 18:29:07 +01:00
//struct SBoxIcon {
// QIcon Empty;
// QIcon InUse;
// //QIcon Busy;
//};
//QMap<int, SBoxIcon> m_BoxIcons;
2021-10-16 16:19:51 +01:00
class UGlobalHotkeys* m_pHotkeyManager;
public slots:
2022-09-01 18:29:07 +01:00
void OnBoxSelected();
2022-01-13 22:52:58 +00:00
void OnMessage(const QString& MsgData);
2021-10-16 16:19:51 +01:00
void OnStatusChanged();
void OnLogMessage(const QString& Message, bool bNotify = false);
void OnLogSbieMessage(quint32 MsgCode, const QStringList& MsgData, quint32 ProcessId);
void OnNotAuthorized(bool bLoginRequired, bool& bRetry);
void OnQueuedRequest(quint32 ClientPid, quint32 ClientTid, quint32 RequestId, const QVariantMap& Data);
void OnFileToRecover(const QString& BoxName, const QString& FilePath, const QString& BoxPath, quint32 ProcessId);
2022-06-08 16:23:19 +01:00
void OnFileRecovered(const QString& BoxName, const QString& FilePath, const QString& BoxPath);
2021-10-16 16:19:51 +01:00
2023-02-03 07:00:11 +00:00
bool OpenRecovery(const CSandBoxPtr& pBox, bool& DeleteSnapshots, bool bCloseEmpty = false);
2021-10-16 16:19:51 +01:00
class CRecoveryWindow* ShowRecovery(const CSandBoxPtr& pBox, bool bFind = true);
2022-07-09 10:46:07 +01:00
void UpdateSettings(bool bRebuildUI);
2022-08-28 11:43:08 +01:00
void RebuildUI();
2021-10-16 16:19:51 +01:00
void OnIniReloaded();
void SetupHotKeys();
void OnHotKey(size_t id);
void OnAsyncFinished();
void OnAsyncFinished(CSbieProgress* pProgress);
void OnAsyncMessage(const QString& Text);
void OnAsyncProgress(int Progress);
void OnCancelAsync();
2022-09-29 17:28:48 +01:00
void OnBoxAdded(const CSandBoxPtr& pBox);
2022-06-13 19:12:53 +01:00
void OnBoxClosed(const CSandBoxPtr& pBox);
2023-01-29 09:49:41 +00:00
void OnBoxCleaned(CSandBoxPlus* pBoxEx);
2021-10-16 16:19:51 +01:00
2022-09-29 17:28:48 +01:00
void OnStartMenuChanged();
2021-10-16 16:19:51 +01:00
void OpenUrl(const QString& url) { OpenUrl(QUrl(url)); }
void OpenUrl(const QUrl& url);
2023-05-08 20:33:50 +01:00
int ShowQuestion(const QString& question, const QString& checkBoxText, bool* checkBoxSetting, int buttons, int defaultButton, int type, QWidget* pParent);
2022-09-29 17:28:48 +01:00
void ShowMessage(const QString& message, int type);
2021-10-16 16:19:51 +01:00
void OnBoxMenu(const QPoint &);
void OnBoxDblClick(QTreeWidgetItem*);
2022-09-29 17:28:48 +01:00
void SyncStartMenu();
void ClearStartMenu();
2022-08-09 17:19:46 +01:00
void UpdateLabel();
2021-10-16 16:19:51 +01:00
private slots:
void OnMenuHover(QAction* action);
2022-07-10 17:28:10 +01:00
void OnBoxMenuHover(QAction* action);
2021-10-16 16:19:51 +01:00
2022-07-09 10:46:07 +01:00
void OnSandBoxAction();
2022-07-11 18:30:09 +01:00
void OnSettingsAction();
2021-10-16 16:19:51 +01:00
void OnEmptyAll();
void OnWndFinder();
void OnDisableForce();
void OnDisableForce2();
2022-08-10 19:14:37 +01:00
void OnDisablePopUp();
2021-10-16 16:19:51 +01:00
void OnMaintenance();
void OnViewMode(QAction* action);
void OnAlwaysTop();
2022-07-11 18:30:09 +01:00
void OnView(QAction* action);
2022-05-16 20:30:40 +01:00
void OnRefresh();
2021-10-16 16:19:51 +01:00
void OnCleanUp();
void OnProcView();
2022-07-11 18:30:09 +01:00
void OnRecoveryLog();
2021-10-16 16:19:51 +01:00
void OnSettings();
void OnResetMsgs();
2022-02-02 20:04:37 +00:00
void OnResetGUI();
2021-10-16 16:19:51 +01:00
void OnEditIni();
void OnReloadIni();
2022-07-09 10:46:07 +01:00
void OnMonitoring();
2021-10-16 16:19:51 +01:00
2022-08-09 17:19:46 +01:00
void CheckForUpdates(bool bManual = true);
2021-10-16 16:19:51 +01:00
void OnExit();
void OnHelp();
void OnAbout();
void OnShowHide();
void OnSysTray(QSystemTrayIcon::ActivationReason Reason);
void SetUITheme();
void SetTitleTheme(const HWND& hwnd);
2021-10-16 16:19:51 +01:00
2022-07-09 10:46:07 +01:00
void AddLogMessage(const QString& Message);
void AddFileRecovered(const QString& BoxName, const QString& FilePath);
2022-10-07 11:53:45 +01:00
void commitData(QSessionManager& manager);
2021-10-16 16:19:51 +01:00
private:
2022-07-09 10:46:07 +01:00
void CreateUI();
void CreateMenus(bool bAdvanced);
void CreateOldMenus();
void CreateMaintenanceMenu();
void CreateViewBaseMenu();
void CreateHelpMenu(bool bAdvanced);
2021-10-16 16:19:51 +01:00
void CreateToolBar();
2022-08-10 19:14:37 +01:00
void CreateLabel();
2022-07-11 18:30:09 +01:00
void CreateView(int iViewMode);
2022-07-09 10:46:07 +01:00
void CreateTrayIcon();
2022-05-08 13:41:49 +01:00
void CreateTrayMenu();
2022-07-10 17:28:10 +01:00
void CreateBoxMenu(QMenu* pMenu, int iOffset = 0, int iSysTrayFilter = 0);
2021-10-16 16:19:51 +01:00
2022-02-02 18:31:03 +00:00
void HandleMaintenance(SB_RESULT(void*) Status);
2022-08-10 20:38:52 +01:00
void LoadState(bool bFull = true);
2021-10-16 16:19:51 +01:00
void StoreState();
2022-12-30 21:41:24 +00:00
void UpdateState();
2023-01-29 16:10:11 +00:00
struct SBoxLink {
QString RelPath; // key
QString FullPath;
QString Target;
};
void EnumBoxLinks(QMap<QString, QMap<QString, SBoxLink> >& BoxLinks, const QString& Prefix, const QString& Folder, bool bWithSubDirs = true);
2022-09-29 17:28:48 +01:00
void CleanupShortcutPath(const QString& Path);
void DeleteShortcut(const QString& Path);
2023-01-29 16:10:11 +00:00
void CleanUpStartMenu(QMap<QString, QMap<QString, SBoxLink> >& BoxLinks);
2022-09-29 17:28:48 +01:00
2021-10-16 16:19:51 +01:00
QWidget* m_pMainWidget;
QVBoxLayout* m_pMainLayout;
QToolBar* m_pToolBar;
QSplitter* m_pPanelSplitter;
QSplitter* m_pLogSplitter;
2022-07-11 18:30:09 +01:00
QStackedLayout* m_pViewStack;
QComboBox* m_pBoxCombo;
2021-10-16 16:19:51 +01:00
CSbieView* m_pBoxView;
2022-07-11 18:30:09 +01:00
CFileView* m_pFileView;
2021-10-16 16:19:51 +01:00
QTabWidget* m_pLogTabs;
CPanelWidgetEx* m_pMessageLog;
CTraceView* m_pTraceView;
2022-06-08 16:23:19 +01:00
CPanelWidgetEx* m_pRecoveryLog;
2022-07-11 18:30:09 +01:00
class CRecoveryLogWnd* m_pRecoveryLogWnd;
2021-10-16 16:19:51 +01:00
2022-08-10 19:14:37 +01:00
QMenuBar* m_pMenuBar;
QHBoxLayout* m_pMenuLayout;
2021-10-16 16:19:51 +01:00
QMenu* m_pMenuFile;
2022-12-06 12:48:18 +00:00
QAction* m_pRunBoxed;
2021-10-16 16:19:51 +01:00
QAction* m_pNewBox;
QAction* m_pNewGroup;
2022-11-12 09:45:35 +00:00
QAction* m_pImportBox;
2021-10-16 16:19:51 +01:00
QAction* m_pEmptyAll;
QAction* m_pWndFinder;
QAction* m_pDisableForce;
QAction* m_pDisableForce2;
2022-06-13 19:12:53 +01:00
QAction* m_pDisableRecovery;
QAction* m_pDisableMessages;
2023-05-15 19:28:21 +01:00
QAction* m_pDismissUpdate;
2021-10-16 16:19:51 +01:00
QMenu* m_pMaintenance;
QAction* m_pConnect;
QAction* m_pDisconnect;
QMenu* m_pMaintenanceItems;
QAction* m_pInstallDrv;
QAction* m_pStartDrv;
QAction* m_pStopDrv;
QAction* m_pUninstallDrv;
QAction* m_pInstallSvc;
QAction* m_pStartSvc;
QAction* m_pStopSvc;
QAction* m_pUninstallSvc;
QAction* m_pStopAll;
2022-01-29 09:18:22 +00:00
QAction* m_pUninstallAll;
2022-05-14 14:42:10 +01:00
QAction* m_pSetupWizard;
2021-10-16 16:19:51 +01:00
QAction* m_pExit;
QMenu* m_pMenuView;
QActionGroup* m_pViewMode;
QAction* m_pShowHidden;
QAction* m_pWndTopMost;
2022-07-11 18:30:09 +01:00
QAction* m_pMenuBrowse;
2022-05-16 20:30:40 +01:00
QAction* m_pRefreshAll;
2021-10-16 16:19:51 +01:00
QMenu* m_pCleanUpMenu;
QAction* m_pCleanUpProcesses;
QAction* m_pCleanUpMsgLog;
QAction* m_pCleanUpTrace;
2022-06-08 16:23:19 +01:00
QAction* m_pCleanUpRecovery;
2021-10-16 16:19:51 +01:00
QToolButton* m_pCleanUpButton;
2023-01-29 14:12:01 +00:00
//QToolButton* m_pEditButton;
2021-10-16 16:19:51 +01:00
QAction* m_pKeepTerminated;
QAction* m_pShowAllSessions;
2022-07-11 18:30:09 +01:00
QAction* m_pArrangeGroups;
2021-10-16 16:19:51 +01:00
QMenu* m_pMenuOptions;
QAction* m_pMenuSettings;
QAction* m_pMenuResetMsgs;
2022-02-02 20:04:37 +00:00
QAction* m_pMenuResetGUI;
2021-10-16 16:19:51 +01:00
QAction* m_pEditIni;
2023-01-29 14:12:01 +00:00
QAction* m_pEditIni2;
QAction* m_pEditIni3;
2021-10-16 16:19:51 +01:00
QAction* m_pReloadIni;
QAction* m_pEnableMonitoring;
2022-05-13 22:12:20 +01:00
QAction* m_pSeparator;
QLabel* m_pLabel;
2021-10-16 16:19:51 +01:00
QMenu* m_pMenuHelp;
2023-01-29 14:12:01 +00:00
//QAction* m_pSupport;
QAction* m_pContribution;
2021-10-16 16:19:51 +01:00
QAction* m_pForum;
QAction* m_pManual;
QAction* m_pUpdate;
QAction* m_pAbout;
QAction* m_pAboutQt;
2023-01-07 15:57:55 +00:00
QLabel* m_pTraceInfo;
2022-08-10 19:14:37 +01:00
QLabel* m_pDisabledForce;
QLabel* m_pDisabledRecovery;
QLabel* m_pDisabledMessages;
2022-07-09 10:46:07 +01:00
// for old menu
QMenu* m_pSandbox;
2021-10-16 16:19:51 +01:00
QSystemTrayIcon* m_pTrayIcon;
QMenu* m_pTrayMenu;
QWidgetAction* m_pTrayList;
QTreeWidget* m_pTrayBoxes;
2022-07-10 17:28:10 +01:00
int m_iTrayPos;
2021-10-16 16:19:51 +01:00
//QMenu* m_pBoxMenu;
bool m_bIconEmpty;
2023-01-07 15:57:55 +00:00
int m_iIconDisabled;
2022-02-18 19:09:35 +00:00
bool m_bIconBusy;
2023-02-07 20:50:06 +00:00
bool m_bIconSun;
2022-02-18 19:09:35 +00:00
int m_iDeletingContent;
2021-10-16 16:19:51 +01:00
bool m_bExit;
CProgressDialog* m_pProgressDialog;
bool m_pProgressModal;
CPopUpWindow* m_pPopUpWindow;
2022-09-29 17:28:48 +01:00
bool m_StartMenuUpdatePending;
2021-10-16 16:19:51 +01:00
bool m_ThemeUpdatePending;
QString m_DefaultStyle;
QPalette m_DefaultPalett;
2022-07-09 10:46:07 +01:00
double m_DefaultFontSize;
2022-08-09 17:19:46 +01:00
QPalette m_DarkPalett;
2021-10-16 16:19:51 +01:00
void LoadLanguage();
2021-10-19 08:34:10 +01:00
void LoadLanguage(const QString& Lang, const QString& Module, int Index);
QTranslator m_Translator[2];
2021-10-16 16:19:51 +01:00
public:
2022-11-20 16:23:15 +00:00
class COnlineUpdater*m_pUpdater;
2021-10-16 16:19:51 +01:00
quint32 m_LanguageId;
bool m_DarkTheme;
2022-08-10 19:14:37 +01:00
bool m_FusionTheme;
2021-10-16 16:19:51 +01:00
};
2022-07-11 18:30:09 +01:00
class CRecoveryLogWnd : public QDialog
{
Q_OBJECT
public:
CRecoveryLogWnd(QWidget *parent = Q_NULLPTR);
~CRecoveryLogWnd();
private slots:
void OnDblClick(QTreeWidgetItem* pItem);
signals:
void Closed();
protected:
friend class CSandMan;
void closeEvent(QCloseEvent *e);
CPanelWidgetEx* m_pRecoveryLog;
};
2022-07-20 08:35:07 +01:00
#include <QStyledItemDelegate>
class CTreeItemDelegate : public QStyledItemDelegate
{
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem opt(option);
opt.state &= ~QStyle::State_HasFocus;
QStyledItemDelegate::paint(painter, opt, index);
}
};
2022-07-11 18:30:09 +01:00
2022-08-08 09:07:38 +01:00
class CTreeItemDelegate2 : public CTreeItemDelegate
{
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size = QStyledItemDelegate::sizeHint(option, index);
size.setHeight(32);
return size;
}
};
2021-10-16 16:19:51 +01:00
extern CSandMan* theGUI;