2021-10-15 16:39:43 +01:00
# include "stdafx.h"
# include "SbieView.h"
# include "..\SandMan.h"
# include "../QSbieAPI/SbieAPI.h"
# include "../QSbieAPI/SbieUtils.h"
# include "../../MiscHelpers/Common/SortFilterProxyModel.h"
# include "../../MiscHelpers/Common/Settings.h"
# include "../../MiscHelpers/Common/Common.h"
# include "../Windows/OptionsWindow.h"
# include "../Windows/SnapshotsWindow.h"
# include "../../MiscHelpers/Common/CheckableMessageBox.h"
# include "../Windows/RecoveryWindow.h"
2022-07-11 18:30:09 +01:00
# include "../Views/FileView.h"
2023-01-28 13:05:37 +00:00
# include "../Wizards/NewBoxWizard.h"
2023-01-29 16:10:11 +00:00
# include "../Helpers/WinHelper.h"
2023-07-31 20:20:29 +01:00
# include "../MiscHelpers/Archive/Archive.h"
2023-07-19 20:15:18 +01:00
# include "../Windows/SettingsWindow.h"
2021-10-15 16:39:43 +01:00
# include "qt_windows.h"
# include "qwindowdefs_win.h"
# include <shellapi.h>
CSbieView : : CSbieView ( QWidget * parent ) : CPanelView ( parent )
{
m_pMainLayout = new QVBoxLayout ( ) ;
2022-09-29 17:28:48 +01:00
m_pMainLayout - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
2021-10-15 16:39:43 +01:00
this - > setLayout ( m_pMainLayout ) ;
2023-04-20 20:52:30 +01:00
m_HoldExpand = false ;
2021-10-15 16:39:43 +01:00
2023-01-12 22:10:50 +00:00
m_pSbieModel = new CSbieModel ( this ) ;
2021-10-15 16:39:43 +01:00
m_pSbieModel - > SetTree ( true ) ;
m_pSbieModel - > SetUseIcons ( true ) ;
2022-07-29 09:24:32 +01:00
m_pSortProxy = new CSortFilterProxyModel ( this ) ;
2021-10-15 16:39:43 +01:00
m_pSortProxy - > setSortRole ( Qt : : EditRole ) ;
m_pSortProxy - > setSourceModel ( m_pSbieModel ) ;
m_pSortProxy - > setDynamicSortFilter ( true ) ;
// SbieTree
m_pSbieTree = new QTreeViewEx ( ) ;
2023-05-21 14:54:37 +01:00
m_pSbieTree - > setColumnFixed ( 0 , true ) ;
2022-07-29 09:24:32 +01:00
m_pSbieTree - > setAlternatingRowColors ( theConf - > GetBool ( " Options/AltRowColors " , false ) ) ;
2021-10-15 16:39:43 +01:00
m_pSbieTree - > setExpandsOnDoubleClick ( false ) ;
//m_pSbieTree->setItemDelegate(theGUI->GetItemDelegate());
m_pSbieTree - > setModel ( m_pSortProxy ) ;
2022-07-09 10:46:07 +01:00
int iViewMode = theConf - > GetInt ( " Options/ViewMode " , 1 ) ;
int iLargeIcons = theConf - > GetInt ( " Options/LargeIcons " , 2 ) ;
if ( iLargeIcons = = 2 )
iLargeIcons = iViewMode = = 2 ? 1 : 0 ;
if ( iLargeIcons ) {
m_pSbieModel - > SetLargeIcons ( ) ;
m_pSbieTree - > setIconSize ( QSize ( 32 , 32 ) ) ;
}
2021-10-15 16:39:43 +01:00
2022-04-16 14:01:01 +01:00
m_pSbieTree - > setDragDropMode ( QAbstractItemView : : InternalMove ) ;
2021-10-15 16:39:43 +01:00
m_pSbieTree - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
m_pSbieTree - > setSortingEnabled ( true ) ;
//m_pSbieTree->setSortingEnabled(false);
//m_pSbieTree->header()->setSortIndicatorShown(true);
//m_pSbieTree->header()->setSectionsClickable(true);
2022-07-10 20:44:24 +01:00
if ( iViewMode ! = 2 )
connect ( m_pSbieTree - > header ( ) , SIGNAL ( sectionClicked ( int ) ) , this , SLOT ( OnCustomSortByColumn ( int ) ) ) ;
2021-10-15 16:39:43 +01:00
2022-07-10 17:28:10 +01:00
QStyle * pStyle = QStyleFactory : : create ( " windows " ) ;
2021-10-15 16:39:43 +01:00
m_pSbieTree - > setStyle ( pStyle ) ;
2022-08-08 09:07:38 +01:00
m_pSbieTree - > setItemDelegate ( iLargeIcons ? new CTreeItemDelegate2 ( ) : new CTreeItemDelegate ( ) ) ;
2021-10-15 16:39:43 +01:00
m_pSbieTree - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
connect ( m_pSbieTree , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( OnMenu ( const QPoint & ) ) ) ;
2022-11-05 13:42:23 +00:00
connect ( m_pSbieTree , SIGNAL ( pressed ( const QModelIndex & ) ) , this , SLOT ( OnClicked ( const QModelIndex & ) ) ) ;
2021-10-15 16:39:43 +01:00
connect ( m_pSbieTree , SIGNAL ( doubleClicked ( const QModelIndex & ) ) , this , SLOT ( OnDoubleClicked ( const QModelIndex & ) ) ) ;
connect ( m_pSbieTree - > selectionModel ( ) , SIGNAL ( selectionChanged ( QItemSelection , QItemSelection ) ) , SLOT ( ProcessSelection ( QItemSelection , QItemSelection ) ) ) ;
connect ( m_pSbieTree , SIGNAL ( expanded ( const QModelIndex & ) ) , this , SLOT ( OnExpanded ( const QModelIndex & ) ) ) ;
connect ( m_pSbieTree , SIGNAL ( collapsed ( const QModelIndex & ) ) , this , SLOT ( OnCollapsed ( const QModelIndex & ) ) ) ;
//connect(theGUI, SIGNAL(ReloadPanels()), m_pSbieModel, SLOT(Clear()));
2022-06-04 20:07:04 +01:00
connect ( m_pSbieModel , SIGNAL ( MoveBox ( const QString & , const QString & , int ) ) , this , SLOT ( OnMoveItem ( const QString & , const QString & , int ) ) ) ;
connect ( m_pSbieModel , SIGNAL ( MoveGroup ( const QString & , const QString & , int ) ) , this , SLOT ( OnMoveItem ( const QString & , const QString & , int ) ) ) ;
2022-04-16 14:01:01 +01:00
2021-10-15 16:39:43 +01:00
m_pMainLayout - > addWidget ( m_pSbieTree ) ;
//
2023-01-12 22:10:50 +00:00
CFinder * pFinder = new CFinder ( m_pSortProxy , this ) ;
m_pMainLayout - > addWidget ( pFinder ) ;
pFinder - > SetTree ( m_pSbieTree ) ;
2021-10-15 16:39:43 +01:00
connect ( m_pSbieModel , SIGNAL ( ToolTipCallback ( const QVariant & , QString & ) ) , this , SLOT ( OnToolTipCallback ( const QVariant & , QString & ) ) , Qt : : DirectConnection ) ;
2022-07-09 10:46:07 +01:00
if ( iViewMode = = 2 )
CreateOldMenu ( ) ;
else
CreateMenu ( ) ;
2023-05-23 21:17:50 +01:00
m_pCtxMenu = new QMenu ( ) ;
m_pCtxPinToRun = m_pCtxMenu - > addAction ( tr ( " Pin to Run Menu " ) , this , SLOT ( OnMenuContextAction ( ) ) ) ;
m_pCtxPinToRun - > setCheckable ( true ) ;
m_pCtxMkLink = m_pCtxMenu - > addAction ( CSandMan : : GetIcon ( " MkLink " ) , tr ( " Create Shortcut " ) , this , SLOT ( OnMenuContextAction ( ) ) ) ;
2022-07-12 17:23:28 +01:00
m_pRemove = new QAction ( this ) ;
m_pRemove - > setShortcut ( QKeySequence : : Delete ) ;
m_pRemove - > setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
this - > addAction ( m_pRemove ) ;
connect ( m_pRemove , SIGNAL ( triggered ( ) ) , this , SLOT ( OnRemoveItem ( ) ) ) ;
CreateGroupMenu ( ) ;
CreateTrayMenu ( ) ;
2022-07-09 10:46:07 +01:00
QByteArray Columns = theConf - > GetBlob ( " MainWindow/BoxTree_Columns " ) ;
2023-05-27 15:14:29 +01:00
if ( Columns . isEmpty ( ) ) {
2022-07-09 10:46:07 +01:00
m_pSbieTree - > setColumnWidth ( 0 , 300 ) ;
m_pSbieTree - > setColumnWidth ( 1 , 70 ) ;
m_pSbieTree - > setColumnWidth ( 2 , 70 ) ;
m_pSbieTree - > setColumnWidth ( 3 , 70 ) ;
2023-05-27 15:14:29 +01:00
} else
2022-07-09 10:46:07 +01:00
m_pSbieTree - > restoreState ( Columns ) ;
2022-07-10 20:44:24 +01:00
if ( theConf - > GetBool ( " MainWindow/BoxTree_UseOrder " , false ) | | iViewMode = = 2 )
2022-07-09 10:46:07 +01:00
SetCustomOrder ( ) ;
//m_pMenu = new QMenu();
AddPanelItemsToMenu ( ) ;
2022-07-12 17:23:28 +01:00
AddCopyMenu ( m_pMenuBox ) ;
AddCopyMenu ( m_pMenuProcess ) ;
AddCopyMenu ( m_pMenuGroup ) ;
2022-07-09 10:46:07 +01:00
}
CSbieView : : ~ CSbieView ( )
2022-10-07 11:53:45 +01:00
{
SaveState ( ) ;
}
void CSbieView : : SaveState ( )
2022-07-09 10:46:07 +01:00
{
theConf - > SetBlob ( " MainWindow/BoxTree_Columns " , m_pSbieTree - > saveState ( ) ) ;
//theConf->SetValue("MainWindow/BoxTree_UseOrder", m_pSortProxy->sortRole() == Qt::InitialSortOrderRole);
}
void CSbieView : : Clear ( )
{
m_Groups . clear ( ) ;
m_pSbieModel - > Clear ( ) ;
}
void CSbieView : : CreateMenu ( )
{
2021-10-15 16:39:43 +01:00
m_pNewBox = m_pMenu - > addAction ( CSandMan : : GetIcon ( " NewBox " ) , tr ( " Create New Box " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
m_pAddGroupe = m_pMenu - > addAction ( CSandMan : : GetIcon ( " Group " ) , tr ( " Create Box Group " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
2023-05-23 21:17:50 +01:00
m_pImportBox = m_pMenu - > addAction ( CSandMan : : GetIcon ( " UnPackBox " ) , tr ( " Import Box " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
2023-07-31 20:20:29 +01:00
m_pImportBox - > setEnabled ( CArchive : : IsInit ( ) ) ;
2022-07-12 17:23:28 +01:00
m_pMenuBox = new QMenu ( ) ;
m_pStopAsync = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Stop " ) , tr ( " Stop Operations " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
//m_pMenuBox->addSeparator();
2023-06-17 19:46:51 +01:00
//m_pMenuRun = m_pMenuBox->addMenu(CSandMan::GetIcon("Start"), tr("Run"));
m_pMenuRun = new CMenuEx ( tr ( " Run " ) , m_pMenuBox ) ;
m_pMenuRun - > setIcon ( CSandMan : : GetIcon ( " Start " ) ) ;
m_pMenuBox - > addAction ( m_pMenuRun - > menuAction ( ) ) ;
connect ( m_pMenuRun , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( OnMenuContextMenu ( const QPoint & ) ) ) ;
2021-10-15 16:39:43 +01:00
m_pMenuRunAny = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " Run " ) , tr ( " Run Program " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunMenu = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " StartMenu " ) , tr ( " Run from Start Menu " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-09-29 17:28:48 +01:00
if ( theConf - > GetBool ( " Options/ScanStartMenu " , true ) ) {
m_pMenuRunStart = new QMenu ( ) ;
m_pMenuRunStart - > addAction ( CSandMan : : GetIcon ( " StartMenu " ) , tr ( " (Host) Start Menu " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunStart - > addSeparator ( ) ;
}
else
m_pMenuRunStart = NULL ;
2023-01-25 11:54:41 +00:00
//m_pMenuRunTools->addSeparator();
m_pMenuAutoRun = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " ReloadIni " ) , tr ( " Execute Autorun Entries " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2023-04-13 18:46:51 +01:00
m_pMenuRunTools = m_pMenuRun - > addMenu ( CSandMan : : GetIcon ( " Maintenance " ) , tr ( " Standard Applications " ) ) ;
2022-11-29 16:03:28 +00:00
m_pMenuRunBrowser = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " Internet " ) , tr ( " Default Web Browser " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunMailer = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " Email " ) , tr ( " Default eMail Client " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunExplorer = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " Explore " ) , tr ( " Windows Explorer " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunRegEdit = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " RegEdit " ) , tr ( " Registry Editor " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunAppWiz = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " Software " ) , tr ( " Programs and Features " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunTools - > addSeparator ( ) ;
m_pMenuRunCmd = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " Cmd " ) , tr ( " Command Prompt " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2021-10-15 16:39:43 +01:00
m_pMenuRunCmdAdmin = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " Cmd " ) , tr ( " Command Prompt (as Admin) " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2023-04-13 18:46:51 +01:00
# ifndef _WIN64
2022-06-27 07:33:15 +01:00
if ( CSbieAPI : : IsWow64 ( ) )
2023-01-25 17:03:13 +00:00
# endif
2023-04-13 18:46:51 +01:00
m_pMenuRunCmd32 = m_pMenuRunTools - > addAction ( CSandMan : : GetIcon ( " Cmd " ) , tr ( " Command Prompt (32-bit) " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2021-10-15 16:39:43 +01:00
m_pMenuRun - > addSeparator ( ) ;
m_iMenuRun = m_pMenuRun - > actions ( ) . count ( ) ;
2022-07-12 17:23:28 +01:00
m_pMenuEmptyBox = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " EmptyAll " ) , tr ( " Terminate All Programs " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuBox - > addSeparator ( ) ;
m_pMenuContent = m_pMenuBox - > addMenu ( CSandMan : : GetIcon ( " Compatibility " ) , tr ( " Box Content " ) ) ;
2022-12-21 09:53:03 +00:00
m_pMenuBrowse = m_pMenuContent - > addAction ( CSandMan : : GetIcon ( " Folder " ) , tr ( " Browse Files " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-07-11 18:30:09 +01:00
m_pMenuContent - > addSeparator ( ) ;
2022-07-09 10:46:07 +01:00
m_pMenuRefresh = m_pMenuContent - > addAction ( CSandMan : : GetIcon ( " Refresh " ) , tr ( " Refresh Info " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2021-10-15 16:39:43 +01:00
m_pMenuMkLink = m_pMenuContent - > addAction ( CSandMan : : GetIcon ( " MkLink " ) , tr ( " Create Shortcut " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuContent - > addSeparator ( ) ;
m_pMenuExplore = m_pMenuContent - > addAction ( CSandMan : : GetIcon ( " Explore " ) , tr ( " Explore Content " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRegEdit = m_pMenuContent - > addAction ( CSandMan : : GetIcon ( " RegEdit " ) , tr ( " Open Registry " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-11-12 09:45:35 +00:00
m_pMenuSnapshots = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Snapshots " ) , tr ( " Snapshots Manager " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-07-12 17:23:28 +01:00
m_pMenuRecover = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Recover " ) , tr ( " Recover Files " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuCleanUp = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Erase " ) , tr ( " Delete Content " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuBox - > addSeparator ( ) ;
m_pMenuOptions = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Options " ) , tr ( " Sandbox Options " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-11-12 09:45:35 +00:00
QFont f = m_pMenuOptions - > font ( ) ;
f . setBold ( true ) ;
m_pMenuOptions - > setFont ( f ) ;
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
m_pMenuPresets = m_pMenuBox - > addMenu ( CSandMan : : GetIcon ( " Presets " ) , tr ( " Sandbox Presets " ) ) ;
2021-10-15 16:39:43 +01:00
m_pMenuPresetsAdmin = new QActionGroup ( m_pMenuPresets ) ;
m_pMenuPresetsShowUAC = MakeAction ( m_pMenuPresetsAdmin , m_pMenuPresets , tr ( " Ask for UAC Elevation " ) , 0 ) ;
m_pMenuPresetsNoAdmin = MakeAction ( m_pMenuPresetsAdmin , m_pMenuPresets , tr ( " Drop Admin Rights " ) , 1 ) ;
m_pMenuPresetsFakeAdmin = MakeAction ( m_pMenuPresetsAdmin , m_pMenuPresets , tr ( " Emulate Admin Rights " ) , 1 | 2 ) ;
if ( theAPI - > IsRunningAsAdmin ( ) ) {
m_pMenuPresetsNoAdmin - > setEnabled ( false ) ;
m_pMenuPresetsFakeAdmin - > setEnabled ( false ) ;
}
connect ( m_pMenuPresetsAdmin , SIGNAL ( triggered ( QAction * ) ) , this , SLOT ( OnSandBoxAction ( QAction * ) ) ) ;
m_pMenuPresets - > addSeparator ( ) ;
m_pMenuPresetsINet = m_pMenuPresets - > addAction ( tr ( " Block Internet Access " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuPresetsINet - > setCheckable ( true ) ;
m_pMenuPresetsShares = m_pMenuPresets - > addAction ( tr ( " Allow Network Shares " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuPresetsShares - > setCheckable ( true ) ;
2022-06-13 19:12:53 +01:00
m_pMenuPresets - > addSeparator ( ) ;
2022-06-14 19:58:13 +01:00
m_pMenuPresetsRecovery = m_pMenuPresets - > addAction ( tr ( " Immediate Recovery " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-06-13 19:12:53 +01:00
m_pMenuPresetsRecovery - > setCheckable ( true ) ;
2023-04-24 01:24:06 +01:00
m_pMenuPresetsForce = m_pMenuPresets - > addAction ( tr ( " Disable Force Rules " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuPresetsForce - > setCheckable ( true ) ;
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
m_pMenuTools = m_pMenuBox - > addMenu ( CSandMan : : GetIcon ( " Maintenance " ) , tr ( " Sandbox Tools " ) ) ;
2022-07-09 10:46:07 +01:00
m_pMenuDuplicate = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " Duplicate " ) , tr ( " Duplicate Box Config " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-11-12 09:45:35 +00:00
m_pMenuExport = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " PackBox " ) , tr ( " Export Box " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2023-07-31 20:20:29 +01:00
m_pMenuExport - > setEnabled ( CArchive : : IsInit ( ) ) ;
2022-07-09 10:46:07 +01:00
2022-07-12 17:23:28 +01:00
m_pMenuRename = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Rename " ) , tr ( " Rename Sandbox " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuMoveTo = m_pMenuBox - > addMenu ( CSandMan : : GetIcon ( " Group " ) , tr ( " Move Sandbox " ) ) ;
2021-10-15 16:39:43 +01:00
m_pMenuMoveUp = m_pMenuMoveTo - > addAction ( CSandMan : : GetIcon ( " Up " ) , tr ( " Move Up " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
m_pMenuMoveUp - > setShortcut ( QKeySequence ( " Alt+Up " ) ) ;
m_pMenuMoveUp - > setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
this - > addAction ( m_pMenuMoveUp ) ;
//m_pMenuMoveBy = m_pMenuMoveTo->addAction(tr("Move to Position"), this, SLOT(OnGroupAction())); // does not seam that intuitive for users
m_pMenuMoveDown = m_pMenuMoveTo - > addAction ( CSandMan : : GetIcon ( " Down " ) , tr ( " Move Down " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
m_pMenuMoveDown - > setShortcut ( QKeySequence ( " Alt+Down " ) ) ;
m_pMenuMoveDown - > setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
this - > addAction ( m_pMenuMoveDown ) ;
m_pMenuMoveTo - > addSeparator ( ) ;
2022-07-12 17:23:28 +01:00
m_pMenuRemove = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Remove " ) , tr ( " Remove Sandbox " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2021-10-15 16:39:43 +01:00
2022-07-09 10:46:07 +01:00
// Process Menu
2022-07-12 17:23:28 +01:00
m_pMenuProcess = new QMenu ( ) ;
m_pMenuTerminate = m_pMenuProcess - > addAction ( CSandMan : : GetIcon ( " Remove " ) , tr ( " Terminate " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
2021-10-15 16:39:43 +01:00
this - > addAction ( m_pMenuTerminate ) ;
2022-07-12 17:23:28 +01:00
m_pMenuLinkTo = m_pMenuProcess - > addAction ( CSandMan : : GetIcon ( " MkLink " ) , tr ( " Create Shortcut " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
m_pMenuPreset = m_pMenuProcess - > addMenu ( CSandMan : : GetIcon ( " Presets " ) , tr ( " Preset " ) ) ;
2022-07-09 10:46:07 +01:00
m_pMenuPinToRun = m_pMenuPreset - > addAction ( tr ( " Pin to Run Menu " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
m_pMenuPinToRun - > setCheckable ( true ) ;
m_pMenuBlackList = m_pMenuPreset - > addAction ( tr ( " Block and Terminate " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
//m_pMenuBlackList->setShortcut(QKeySequence("Shift+Del"));
//m_pMenuBlackList->setShortcutContext(Qt::WidgetWithChildrenShortcut);
this - > addAction ( m_pMenuBlackList ) ;
m_pMenuAllowInternet = m_pMenuPreset - > addAction ( tr ( " Allow internet access " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
m_pMenuAllowInternet - > setCheckable ( true ) ;
m_pMenuMarkForced = m_pMenuPreset - > addAction ( tr ( " Force into this sandbox " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
m_pMenuMarkForced - > setCheckable ( true ) ;
m_pMenuMarkLinger = m_pMenuPreset - > addAction ( tr ( " Set Linger Process " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
m_pMenuMarkLinger - > setCheckable ( true ) ;
m_pMenuMarkLeader = m_pMenuPreset - > addAction ( tr ( " Set Leader Process " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
m_pMenuMarkLeader - > setCheckable ( true ) ;
2023-07-30 13:28:35 +01:00
m_pMenuSuspend = m_pMenuProcess - > addAction ( tr ( " Suspend " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
m_pMenuResume = m_pMenuProcess - > addAction ( tr ( " Resume " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
2022-07-09 10:46:07 +01:00
}
void CSbieView : : CreateOldMenu ( )
{
m_pNewBox = m_pMenu - > addAction ( CSandMan : : GetIcon ( " NewBox " ) , tr ( " Create New Box " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
m_pAddGroupe = m_pMenu - > addAction ( CSandMan : : GetIcon ( " Group " ) , tr ( " Create Box Group " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
2023-05-23 21:17:50 +01:00
m_pImportBox = m_pMenu - > addAction ( CSandMan : : GetIcon ( " UnPackBox " ) , tr ( " Import Box " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
2022-07-12 17:23:28 +01:00
m_pMenuBox = new QMenu ( ) ;
m_pStopAsync = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Stop " ) , tr ( " Stop Operations " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
//m_pMenuBox->addSeparator();
2023-06-17 19:46:51 +01:00
//m_pMenuRun = m_pMenuBox->addMenu(CSandMan::GetIcon("Start"), tr("Run Sandboxed"));
m_pMenuRun = new CMenuEx ( tr ( " Run " ) , m_pMenuBox ) ;
m_pMenuRun - > setIcon ( CSandMan : : GetIcon ( " Start " ) ) ;
m_pMenuBox - > addAction ( m_pMenuRun - > menuAction ( ) ) ;
connect ( m_pMenuRun , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( OnMenuContextMenu ( const QPoint & ) ) ) ;
2022-07-09 10:46:07 +01:00
m_pMenuRunBrowser = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " Internet " ) , tr ( " Run Web Browser " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunMailer = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " Email " ) , tr ( " Run eMail Reader " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunAny = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " Run " ) , tr ( " Run Any Program " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunMenu = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " StartMenu " ) , tr ( " Run From Start Menu " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-09-29 17:28:48 +01:00
if ( theConf - > GetBool ( " Options/ScanStartMenu " , true ) ) {
m_pMenuRunStart = new QMenu ( ) ;
m_pMenuRunStart - > addAction ( CSandMan : : GetIcon ( " StartMenu " ) , tr ( " (Host) Start Menu " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunStart - > addSeparator ( ) ;
}
else
m_pMenuRunStart = NULL ;
2022-07-09 10:46:07 +01:00
m_pMenuRunExplorer = m_pMenuRun - > addAction ( CSandMan : : GetIcon ( " Explore " ) , tr ( " Run Windows Explorer " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRunCmd = NULL ;
m_pMenuRunTools = NULL ;
m_pMenuRunCmdAdmin = NULL ;
2022-11-30 11:45:03 +00:00
# ifdef _WIN64
2022-07-09 10:46:07 +01:00
m_pMenuRunCmd32 = NULL ;
2022-11-30 11:45:03 +00:00
# endif
2022-07-09 10:46:07 +01:00
m_pMenuRunRegEdit = NULL ;
m_pMenuRunAppWiz = NULL ;
m_pMenuAutoRun = NULL ;
m_pMenuRun - > addSeparator ( ) ;
m_iMenuRun = m_pMenuRun - > actions ( ) . count ( ) ;
2022-07-12 17:23:28 +01:00
m_pMenuBox - > addSeparator ( ) ;
m_pMenuEmptyBox = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " EmptyAll " ) , tr ( " Terminate Programs " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuRecover = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Recover " ) , tr ( " Quick Recover " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuCleanUp = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Erase " ) , tr ( " Delete Content " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuExplore = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Explore " ) , tr ( " Explore Content " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-07-09 10:46:07 +01:00
2022-07-12 17:23:28 +01:00
m_pMenuBox - > addSeparator ( ) ;
m_pMenuOptions = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Options " ) , tr ( " Sandbox Settings " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-07-09 10:46:07 +01:00
2022-07-12 17:23:28 +01:00
m_pMenuTools = m_pMenuBox - > addMenu ( CSandMan : : GetIcon ( " Maintenance " ) , tr ( " Sandbox Tools " ) ) ;
2022-07-09 10:46:07 +01:00
m_pMenuBrowse = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " Tree " ) , tr ( " Browse Content " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuSnapshots = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " Snapshots " ) , tr ( " Snapshots Manager " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuTools - > addSeparator ( ) ;
2022-07-11 20:12:42 +01:00
m_pMenuDuplicate = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " Duplicate " ) , tr ( " Duplicate Sandbox Config " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-11-12 09:45:35 +00:00
m_pMenuExport = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " PackBox " ) , tr ( " Export Sandbox " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2023-07-31 20:20:29 +01:00
m_pMenuExport - > setEnabled ( CArchive : : IsInit ( ) ) ;
2022-07-09 10:46:07 +01:00
m_pMenuTools - > addSeparator ( ) ;
m_pMenuRefresh = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " Refresh " ) , tr ( " Refresh Info " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuMkLink = m_pMenuTools - > addAction ( CSandMan : : GetIcon ( " MkLink " ) , tr ( " Create Shortcut " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-07-12 17:23:28 +01:00
m_pMenuBox - > addSeparator ( ) ;
m_pMenuRename = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Rename " ) , tr ( " Rename Sandbox " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
m_pMenuMoveTo = m_pMenuBox - > addMenu ( CSandMan : : GetIcon ( " Group " ) , tr ( " Move Sandbox " ) ) ;
2022-07-09 10:46:07 +01:00
m_pMenuMoveUp = m_pMenuMoveTo - > addAction ( CSandMan : : GetIcon ( " Up " ) , tr ( " Move Up " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
m_pMenuMoveUp - > setShortcut ( QKeySequence ( " Alt+Up " ) ) ;
m_pMenuMoveUp - > setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
this - > addAction ( m_pMenuMoveUp ) ;
//m_pMenuMoveBy = m_pMenuMoveTo->addAction(tr("Move to Position"), this, SLOT(OnGroupAction())); // does not seam that intuitive for users
m_pMenuMoveDown = m_pMenuMoveTo - > addAction ( CSandMan : : GetIcon ( " Down " ) , tr ( " Move Down " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
m_pMenuMoveDown - > setShortcut ( QKeySequence ( " Alt+Down " ) ) ;
m_pMenuMoveDown - > setShortcutContext ( Qt : : WidgetWithChildrenShortcut ) ;
this - > addAction ( m_pMenuMoveDown ) ;
m_pMenuMoveTo - > addSeparator ( ) ;
2022-07-12 17:23:28 +01:00
m_pMenuRemove = m_pMenuBox - > addAction ( CSandMan : : GetIcon ( " Remove " ) , tr ( " Remove Sandbox " ) , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2022-04-16 14:01:01 +01:00
2021-10-15 16:39:43 +01:00
2022-07-09 10:46:07 +01:00
m_pMenuContent = NULL ;
m_pMenuRegEdit = NULL ;
m_pMenuPresets = NULL ;
m_pMenuPresetsAdmin = NULL ;
m_pMenuPresetsShowUAC = NULL ;
m_pMenuPresetsNoAdmin = NULL ;
m_pMenuPresetsFakeAdmin = NULL ;
m_pMenuPresetsINet = NULL ;
m_pMenuPresetsShares = NULL ;
m_pMenuPresetsRecovery = NULL ;
2023-04-24 01:24:06 +01:00
m_pMenuPresetsForce = NULL ;
2022-07-12 17:23:28 +01:00
2022-07-09 10:46:07 +01:00
// Process Menu
2022-07-12 17:23:28 +01:00
m_pMenuProcess = new QMenu ( ) ;
m_pMenuTerminate = m_pMenuProcess - > addAction ( CSandMan : : GetIcon ( " Remove " ) , tr ( " Terminate " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
2022-07-09 10:46:07 +01:00
this - > addAction ( m_pMenuTerminate ) ;
2022-07-12 17:23:28 +01:00
m_pMenuLinkTo = m_pMenuProcess - > addAction ( CSandMan : : GetIcon ( " MkLink " ) , tr ( " Create Shortcut " ) , this , SLOT ( OnProcessAction ( ) ) ) ;
2022-07-09 10:46:07 +01:00
m_pMenuPreset = NULL ;
m_pMenuPinToRun = NULL ;
m_pMenuBlackList = NULL ;
m_pMenuAllowInternet = NULL ;
m_pMenuMarkForced = NULL ;
m_pMenuMarkLinger = NULL ;
m_pMenuMarkLeader = NULL ;
2022-07-12 17:23:28 +01:00
}
2022-07-09 10:46:07 +01:00
2022-07-12 17:23:28 +01:00
void CSbieView : : CreateGroupMenu ( )
{
m_pMenuGroup = new QMenu ( ) ;
m_pMenuGroup - > addAction ( m_pNewBox ) ;
m_pMenuGroup - > addAction ( m_pAddGroupe ) ;
2023-05-23 21:17:50 +01:00
m_pMenuGroup - > addAction ( m_pImportBox ) ;
2022-07-12 17:23:28 +01:00
m_pMenuGroup - > addSeparator ( ) ;
m_pRenGroupe = m_pMenuGroup - > addAction ( CSandMan : : GetIcon ( " Rename " ) , tr ( " Rename Group " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
m_pMenuGroup - > addAction ( CSandMan : : GetIcon ( " Group " ) , tr ( " Move Group " ) ) - > setMenu ( m_pMenuMoveTo ) ;
m_pDelGroupe = m_pMenuGroup - > addAction ( CSandMan : : GetIcon ( " Remove " ) , tr ( " Remove Group " ) , this , SLOT ( OnGroupAction ( ) ) ) ;
2022-07-09 10:46:07 +01:00
}
2022-07-12 17:23:28 +01:00
void CSbieView : : CreateTrayMenu ( )
2022-07-09 10:46:07 +01:00
{
2022-07-12 17:23:28 +01:00
m_pMenuTray = new QMenu ( ) ;
m_pMenuTray - > addMenu ( m_pMenuRun ) ;
m_pMenuTray - > addAction ( m_pMenuEmptyBox ) ;
m_pMenuTray - > addSeparator ( ) ;
m_pMenuTray - > addAction ( m_pMenuBrowse ) ;
m_pMenuTray - > addAction ( m_pMenuExplore ) ;
m_pMenuTray - > addAction ( m_pMenuRegEdit ) ;
m_pMenuTray - > addAction ( m_pMenuSnapshots ) ;
m_pMenuTray - > addAction ( m_pMenuRecover ) ;
m_pMenuTray - > addAction ( m_pMenuCleanUp ) ;
m_pMenuTray - > addSeparator ( ) ;
2022-07-09 10:46:07 +01:00
if ( m_pMenuPresets ) {
2022-07-12 17:23:28 +01:00
m_pMenuTray - > addAction ( m_pMenuOptions ) ;
m_pMenuTray - > addMenu ( m_pMenuPresets ) ;
2021-10-15 16:39:43 +01:00
}
}
2022-06-04 20:07:04 +01:00
int CSbieView__ParseGroup ( const QString & Grouping , QMap < QString , QStringList > & m_Groups , const QString & Parent = " " , int Index = 0 )
{
2022-09-29 17:28:48 +01:00
QRegularExpression RegExp ( " [,() ] " , QRegularExpression::CaseInsensitiveOption) ;
2022-06-04 20:07:04 +01:00
for ( ; ; )
{
int pos = Grouping . indexOf ( RegExp , Index ) ;
QString Name ;
if ( pos = = - 1 ) {
Name = Grouping . mid ( Index ) ;
Index = Grouping . length ( ) ;
}
else {
Name = Grouping . mid ( Index , pos - Index ) ;
Index = pos + 1 ;
}
if ( ! Name . isEmpty ( ) )
m_Groups [ Parent ] . append ( Name ) ;
if ( pos = = - 1 )
break ;
2022-08-09 17:19:46 +01:00
if ( Grouping . at ( pos ) = = ' ( ' )
2022-06-04 20:07:04 +01:00
{
m_Groups [ Name ] = QStringList ( ) ;
Index = CSbieView__ParseGroup ( Grouping , m_Groups , Name , Index ) ;
}
2022-08-09 17:19:46 +01:00
else if ( Grouping . at ( pos ) = = ' ) ' )
2022-06-04 20:07:04 +01:00
break ;
}
return Index ;
}
QString CSbieView__SerializeGroup ( QMap < QString , QStringList > & m_Groups , const QString & Parent = " " , QSet < QString > Test = QSet < QString > ( ) )
{
QStringList Grouping ;
foreach ( const QString & Name , m_Groups [ Parent ] )
{
if ( Test . contains ( Name ) )
continue ; // recursion, skil
Test . insert ( Name ) ;
if ( m_Groups . contains ( Name ) )
Grouping . append ( Name + " ( " + CSbieView__SerializeGroup ( m_Groups , Name , Test ) + " ) " ) ;
else
Grouping . append ( Name ) ;
}
return Grouping . join ( " , " ) ;
}
2021-10-15 16:39:43 +01:00
void CSbieView : : Refresh ( )
{
QList < QVariant > Added = m_pSbieModel - > Sync ( theAPI - > GetAllBoxes ( ) , m_Groups , theGUI - > IsShowHidden ( ) ) ;
if ( m_pSbieModel - > IsTree ( ) )
{
2023-05-23 21:17:50 +01:00
QTimer : : singleShot ( 10 , this , [ this , Added ] ( ) {
2021-10-15 16:39:43 +01:00
foreach ( const QVariant ID , Added ) {
QModelIndex ModelIndex = m_pSbieModel - > FindIndex ( ID ) ;
2023-04-20 20:52:30 +01:00
if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eProcess ) {
m_HoldExpand = true ;
2021-10-15 16:39:43 +01:00
m_pSbieTree - > expand ( m_pSortProxy - > mapFromSource ( ModelIndex ) ) ;
2023-04-20 20:52:30 +01:00
m_HoldExpand = false ;
}
2021-10-15 16:39:43 +01:00
else
{
QString Name ;
if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eGroup )
Name = m_pSbieModel - > GetID ( ModelIndex ) . toString ( ) ;
else if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eBox )
Name = m_pSbieModel - > GetSandBox ( ModelIndex ) - > GetName ( ) ;
2023-04-20 20:52:30 +01:00
if ( ! m_Collapsed . contains ( Name ) ) {
m_HoldExpand = true ;
2021-10-15 16:39:43 +01:00
m_pSbieTree - > expand ( m_pSortProxy - > mapFromSource ( ModelIndex ) ) ;
2023-04-20 20:52:30 +01:00
m_HoldExpand = false ;
}
2021-10-15 16:39:43 +01:00
}
}
} ) ;
}
2022-06-04 20:07:04 +01:00
// add new boxes to the default group
foreach ( const QStringList & list , m_Groups ) {
foreach ( const QString & str , list )
Added . removeAll ( str ) ;
}
if ( ! Added . isEmpty ( ) ) {
2023-05-29 13:11:34 +01:00
bool bChanged = false ;
2022-06-08 16:23:19 +01:00
foreach ( const QVariant & ID , Added ) {
2022-06-09 19:30:52 +01:00
if ( ID . type ( ) = = QVariant : : String ) {
QString id = ID . toString ( ) ;
2023-05-29 13:11:34 +01:00
if ( id . left ( 1 ) ! = " ! " ) {
bChanged = true ;
2022-06-16 17:21:32 +01:00
m_Groups [ " " ] . append ( id ) ;
2023-05-29 13:11:34 +01:00
}
2022-06-09 19:30:52 +01:00
}
2022-06-08 16:23:19 +01:00
}
2022-06-04 20:07:04 +01:00
2023-05-29 13:11:34 +01:00
if ( bChanged )
SaveBoxGrouping ( ) ;
2022-06-04 20:07:04 +01:00
}
2021-10-15 16:39:43 +01:00
}
void CSbieView : : OnToolTipCallback ( const QVariant & ID , QString & ToolTip )
{
if ( ID . type ( ) = = QVariant : : String )
{
QString BoxName = ID . toString ( ) ;
CSandBoxPtr pBox = theAPI - > GetBoxByName ( BoxName ) ;
CSandBoxPlus * pBoxEx = qobject_cast < CSandBoxPlus * > ( pBox . data ( ) ) ;
if ( ! pBoxEx )
return ;
// todo more info
ToolTip = BoxName + " \n " ;
ToolTip + = tr ( " File root: %1 \n " ) . arg ( pBoxEx - > GetFileRoot ( ) ) ;
ToolTip + = tr ( " Registry root: %1 \n " ) . arg ( pBoxEx - > GetRegRoot ( ) ) ;
ToolTip + = tr ( " IPC root: %1 \n " ) . arg ( pBoxEx - > GetIpcRoot ( ) ) ;
ToolTip + = tr ( " Options: \n " ) ;
ToolTip + = pBoxEx - > GetStatusStr ( ) . replace ( " , " , " \n " ) ;
}
else if ( quint32 ProcessId = ID . toUInt ( ) )
{
// todo proc info
}
}
void CSbieView : : OnCustomSortByColumn ( int column )
{
Qt : : SortOrder order = m_pSbieTree - > header ( ) - > sortIndicatorOrder ( ) ;
//m_pSbieTree->sortByColumn(column, order);
//m_pSbieTree->header()->setSortIndicatorShown(true);
if ( column = = 0 ) {
if ( m_pSortProxy - > sortRole ( ) = = Qt : : InitialSortOrderRole ) {
m_pSortProxy - > sort ( 0 , Qt : : AscendingOrder ) ;
m_pSortProxy - > setSortRole ( Qt : : EditRole ) ;
theConf - > SetValue ( " MainWindow/BoxTree_UseOrder " , false ) ;
m_pSbieTree - > header ( ) - > setSortIndicatorShown ( true ) ;
} else if ( order = = Qt : : DescendingOrder ) {
2022-06-04 20:07:04 +01:00
SetCustomOrder ( ) ;
2021-10-15 16:39:43 +01:00
theConf - > SetValue ( " MainWindow/BoxTree_UseOrder " , true ) ;
}
}
else {
m_pSortProxy - > setSortRole ( Qt : : EditRole ) ;
m_pSbieTree - > header ( ) - > setSortIndicatorShown ( true ) ;
}
}
2022-07-12 17:23:28 +01:00
bool CSbieView : : UpdateMenu ( bool bAdvanced , const CSandBoxPtr & pBox , int iSandBoxeCount , bool bBoxBusy )
2021-10-15 16:39:43 +01:00
{
QList < QAction * > MenuActions = m_pMenu - > actions ( ) ;
2022-02-05 14:09:53 +00:00
m_pStopAsync - > setVisible ( bBoxBusy ) ;
2021-10-15 16:39:43 +01:00
m_pMenuRun - > setEnabled ( iSandBoxeCount = = 1 ) ;
if ( iSandBoxeCount = = 1 )
UpdateRunMenu ( pBox ) ;
m_pMenuMkLink - > setEnabled ( iSandBoxeCount = = 1 ) ;
2022-07-09 10:46:07 +01:00
m_pMenuTools - > setEnabled ( iSandBoxeCount = = 1 ) ;
2021-10-15 16:39:43 +01:00
m_pMenuRename - > setEnabled ( iSandBoxeCount = = 1 ) ;
m_pMenuRecover - > setEnabled ( iSandBoxeCount = = 1 ) ;
2022-07-09 10:46:07 +01:00
if ( m_pMenuPresets ) {
m_pMenuPresets - > setEnabled ( iSandBoxeCount = = 1 ) ;
m_pMenuPresetsShowUAC - > setChecked ( pBox & & ! pBox - > GetBool ( " DropAdminRights " , false ) & & ! pBox - > GetBool ( " FakeAdminRights " , false ) ) ;
m_pMenuPresetsNoAdmin - > setChecked ( pBox & & pBox - > GetBool ( " DropAdminRights " , false ) & & ! pBox - > GetBool ( " FakeAdminRights " , false ) ) ;
m_pMenuPresetsFakeAdmin - > setChecked ( pBox & & pBox - > GetBool ( " DropAdminRights " , false ) & & pBox - > GetBool ( " FakeAdminRights " , false ) ) ;
m_pMenuPresetsINet - > setChecked ( pBox & & pBox . objectCast < CSandBoxPlus > ( ) - > IsINetBlocked ( ) ) ;
m_pMenuPresetsShares - > setChecked ( pBox & & pBox . objectCast < CSandBoxPlus > ( ) - > HasSharesAccess ( ) ) ;
m_pMenuPresetsRecovery - > setChecked ( pBox & & pBox - > GetBool ( " AutoRecover " , false ) ) ;
2023-04-24 01:24:06 +01:00
m_pMenuPresetsForce - > setChecked ( pBox & & pBox - > GetBool ( " DisableForceRules " , false ) ) ;
2022-07-09 10:46:07 +01:00
}
2021-10-15 16:39:43 +01:00
m_pMenuBrowse - > setEnabled ( iSandBoxeCount = = 1 ) ;
m_pMenuExplore - > setEnabled ( iSandBoxeCount = = 1 ) ;
2022-07-09 10:46:07 +01:00
if ( m_pMenuRegEdit ) m_pMenuRegEdit - > setEnabled ( iSandBoxeCount = = 1 ) ;
2021-10-15 16:39:43 +01:00
m_pMenuOptions - > setEnabled ( iSandBoxeCount = = 1 ) ;
m_pMenuSnapshots - > setEnabled ( iSandBoxeCount = = 1 ) ;
2022-07-12 17:23:28 +01:00
m_pCopyCell - > setVisible ( bAdvanced ) ;
m_pCopyRow - > setVisible ( bAdvanced ) ;
m_pCopyPanel - > setVisible ( bAdvanced ) ;
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
return bBoxBusy = = false ;
}
2023-07-30 13:28:35 +01:00
void CSbieView : : UpdateProcMenu ( const CBoxedProcessPtr & pProcess , int iProcessCount , int iSuspendedCount )
2022-07-12 17:23:28 +01:00
{
2021-10-15 16:39:43 +01:00
m_pMenuLinkTo - > setEnabled ( iProcessCount = = 1 ) ;
2022-07-12 17:23:28 +01:00
CSandBoxPlus * pBoxPlus = pProcess . objectCast < CSbieProcess > ( ) - > GetBox ( ) ;
QStringList RunOptions = pBoxPlus - > GetTextList ( " RunCommand " , true ) ;
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
QString FoundPin ;
QString FileName = pProcess - > GetFileName ( ) ;
foreach ( const QString & RunOption , RunOptions ) {
2023-07-19 20:15:18 +01:00
QVariantMap Entry = GetRunEntry ( RunOption ) ;
QString CmdFile = pBoxPlus - > GetCommandFile ( Entry [ " Command " ] . toString ( ) ) ;
2023-05-21 18:23:43 +01:00
if ( CmdFile . compare ( FileName , Qt : : CaseInsensitive ) = = 0 ) {
2022-07-12 17:23:28 +01:00
FoundPin = RunOption ;
break ;
}
}
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
if ( m_pMenuPreset ) {
m_pMenuPinToRun - > setChecked ( ! FoundPin . isEmpty ( ) ) ;
m_pMenuPinToRun - > setData ( FoundPin ) ;
2023-07-19 21:27:18 +01:00
m_pMenuPinToRun - > setProperty ( " WorkingDir " , pProcess - > GetWorkingDir ( ) ) ;
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
m_pMenuAllowInternet - > setChecked ( pProcess . objectCast < CSbieProcess > ( ) - > HasInternetAccess ( ) ) ;
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
m_pMenuMarkForced - > setChecked ( pProcess . objectCast < CSbieProcess > ( ) - > IsForcedProgram ( ) ) ;
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
int isLingering = pProcess . objectCast < CSbieProcess > ( ) - > IsLingeringProgram ( ) ;
m_pMenuMarkLinger - > setChecked ( isLingering ! = 0 ) ;
m_pMenuMarkLinger - > setEnabled ( isLingering ! = 2 ) ;
m_pMenuMarkLeader - > setChecked ( pProcess . objectCast < CSbieProcess > ( ) - > IsLeaderProgram ( ) ) ;
2021-10-15 16:39:43 +01:00
}
2023-07-30 13:28:35 +01:00
m_pMenuSuspend - > setEnabled ( iProcessCount > iSuspendedCount ) ;
m_pMenuResume - > setEnabled ( iSuspendedCount > 0 ) ;
2021-10-15 16:39:43 +01:00
}
2022-07-09 10:46:07 +01:00
bool CSbieView : : UpdateMenu ( )
{
2022-07-12 17:23:28 +01:00
m_CurSandBoxes . clear ( ) ;
m_CurProcesses . clear ( ) ;
2022-07-09 10:46:07 +01:00
CSandBoxPtr pBox ;
bool bBoxBusy = false ;
CBoxedProcessPtr pProcess ;
int iProcessCount = 0 ;
int iSandBoxeCount = 0 ;
int iGroupe = 0 ;
2023-07-30 13:28:35 +01:00
int iSuspendedCount = 0 ;
2022-07-09 10:46:07 +01:00
QModelIndexList Rows = m_pSbieTree - > selectedRows ( ) ;
foreach ( const QModelIndex & Index , Rows )
{
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( Index ) ;
pProcess = m_pSbieModel - > GetProcess ( ModelIndex ) ;
if ( pProcess )
{
2022-07-12 17:23:28 +01:00
m_CurProcesses . append ( pProcess ) ;
2022-07-09 10:46:07 +01:00
iProcessCount + + ;
2023-07-30 13:28:35 +01:00
if ( pProcess - > IsSuspended ( ) )
iSuspendedCount + + ;
2022-07-09 10:46:07 +01:00
}
else
{
pBox = m_pSbieModel - > GetSandBox ( ModelIndex ) ;
if ( pBox )
{
2022-07-12 17:23:28 +01:00
m_CurSandBoxes . append ( pBox ) ;
2022-07-09 10:46:07 +01:00
if ( ! pBox - > IsEnabled ( ) )
iSandBoxeCount = - 1 ;
else if ( iSandBoxeCount ! = - 1 )
iSandBoxeCount + + ;
}
else
iGroupe + + ;
}
}
if ( bBoxBusy ) {
iSandBoxeCount = 0 ;
iGroupe = 0 ;
}
2022-07-12 08:35:00 +01:00
2022-07-10 17:28:10 +01:00
bool bAdvanced = theConf - > GetInt ( " Options/ViewMode " , 1 ) = = 1
| | ( QGuiApplication : : queryKeyboardModifiers ( ) & Qt : : ControlModifier ) ! = 0 ;
2022-07-12 17:23:28 +01:00
m_pRenGroupe - > setVisible ( iGroupe = = 1 & & iSandBoxeCount = = 0 & & iProcessCount = = 0 ) ;
m_pDelGroupe - > setVisible ( iGroupe > 0 & & iSandBoxeCount = = 0 & & iProcessCount = = 0 ) ;
if ( ! pProcess . isNull ( ) )
2023-07-30 13:28:35 +01:00
UpdateProcMenu ( pProcess , iProcessCount , iSuspendedCount ) ;
2022-07-12 17:23:28 +01:00
return UpdateMenu ( bAdvanced , pBox , iSandBoxeCount , bBoxBusy ) ;
2022-07-09 10:46:07 +01:00
}
2021-10-15 16:39:43 +01:00
void CSbieView : : OnMenu ( const QPoint & Point )
{
2021-12-23 15:28:14 +00:00
if ( ! theAPI - > IsConnected ( ) )
return ;
2022-02-05 14:09:53 +00:00
UpdateMenu ( ) ;
2022-07-09 10:46:07 +01:00
2022-07-12 17:23:28 +01:00
UpdateCopyMenu ( ) ;
if ( ! m_CurProcesses . isEmpty ( ) )
m_pMenuProcess - > popup ( QCursor : : pos ( ) ) ;
else if ( ! m_CurSandBoxes . isEmpty ( ) )
m_pMenuBox - > popup ( QCursor : : pos ( ) ) ;
else if ( ! GetSelectedGroups ( ) . isEmpty ( ) )
m_pMenuGroup - > popup ( QCursor : : pos ( ) ) ;
else
m_pMenu - > popup ( QCursor : : pos ( ) ) ;
2021-10-15 16:39:43 +01:00
}
2022-07-12 17:23:28 +01:00
void CSbieView : : UpdateMoveMenu ( )
2021-10-15 16:39:43 +01:00
{
// update move to menu
foreach ( QAction * pAction , m_pMenuMoveTo - > actions ( ) ) {
if ( ! pAction - > data ( ) . toString ( ) . isNull ( ) )
m_pMenuMoveTo - > removeAction ( pAction ) ;
}
2022-09-13 02:46:53 +01:00
foreach ( const QString Group , m_Groups . keys ( ) )
2021-10-15 16:39:43 +01:00
{
2022-09-13 02:46:53 +01:00
QString Name = Group , Temp = Group ;
2022-07-10 20:44:24 +01:00
for ( ; ; ) {
2022-09-13 02:46:53 +01:00
QString Parent = FindParent ( Temp ) ;
2022-07-10 20:44:24 +01:00
if ( Parent . isEmpty ( ) )
break ;
2022-09-13 02:46:53 +01:00
Temp = Parent ;
2022-07-10 20:44:24 +01:00
Name . prepend ( Parent + " > " ) ;
}
QAction * pAction = m_pMenuMoveTo - > addAction ( Name . isEmpty ( ) ? tr ( " [None] " ) : Name , this , SLOT ( OnGroupAction ( ) ) ) ;
2021-10-15 16:39:43 +01:00
pAction - > setData ( Group ) ;
}
//m_pMenuMoveTo->setEnabled(m_Groups.keys().count() > 1);
}
void CSbieView : : RenameGroup ( const QString OldName , const QString NewName )
{
auto Group = m_Groups . take ( OldName ) ;
m_Groups . insert ( NewName , Group ) ;
2022-04-16 14:01:01 +01:00
RenameItem ( OldName , NewName ) ;
}
2022-07-10 20:44:24 +01:00
void CSbieView : : RenameItem ( const QString OldName , const QString NewName )
2022-04-16 14:01:01 +01:00
{
2022-09-17 21:16:58 +01:00
quint64 Size = theConf - > GetValue ( " SizeCache/ " + OldName , - 1 ) . toLongLong ( ) ;
theConf - > DelValue ( " SizeCache/ " + OldName ) ;
if ( Size ! = - 1 ) theConf - > SetValue ( " SizeCache/ " + NewName , Size ) ;
2022-09-18 09:54:38 +01:00
if ( m_Collapsed . remove ( OldName ) )
m_Collapsed . insert ( NewName ) ;
2021-10-15 16:39:43 +01:00
for ( auto I = m_Groups . begin ( ) ; I ! = m_Groups . end ( ) ; + + I )
{
if ( I . value ( ) . removeOne ( OldName ) )
I . value ( ) . append ( NewName ) ;
}
}
QString CSbieView : : FindParent ( const QString & Name )
{
for ( auto I = m_Groups . begin ( ) ; I ! = m_Groups . end ( ) ; + + I )
{
if ( I . value ( ) . contains ( Name , Qt : : CaseInsensitive ) )
return I . key ( ) ;
}
return QString ( ) ;
}
bool CSbieView : : IsParentOf ( const QString & Name , const QString & Group )
{
QString Parent = FindParent ( Group ) ;
if ( Parent = = Name )
return true ;
if ( Parent . isEmpty ( ) )
return false ;
return IsParentOf ( Name , Parent ) ;
}
QStringList CSbieView : : GetSelectedGroups ( bool bAndBoxes )
{
QStringList list ;
foreach ( const QModelIndex & Index , m_pSbieTree - > selectedRows ( ) )
{
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( Index ) ;
QString Name ;
if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eGroup )
Name = m_pSbieModel - > GetID ( ModelIndex ) . toString ( ) ;
else if ( bAndBoxes & & m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eBox )
Name = m_pSbieModel - > GetSandBox ( ModelIndex ) - > GetName ( ) ;
if ( Name . isEmpty ( ) )
continue ;
list . append ( Name ) ;
}
return list ;
}
void CSbieView : : OnGroupAction ( )
{
2022-04-16 14:01:01 +01:00
OnGroupAction ( qobject_cast < QAction * > ( sender ( ) ) ) ;
}
2021-10-15 16:39:43 +01:00
2022-04-16 14:01:01 +01:00
void CSbieView : : OnGroupAction ( QAction * Action )
{
2023-05-23 21:17:50 +01:00
if ( Action = = m_pNewBox | | Action = = m_pAddGroupe | | Action = = m_pImportBox )
2021-10-15 16:39:43 +01:00
{
2022-04-16 14:01:01 +01:00
QStringList List = GetSelectedGroups ( ) ;
2023-05-23 21:17:50 +01:00
QString Name = Action = = m_pNewBox ? AddNewBox ( ) : ( Action = = m_pImportBox ? ImportSandbox ( ) : AddNewGroup ( ) ) ;
2021-10-15 16:39:43 +01:00
if ( Name . isEmpty ( ) )
return ;
if ( List . isEmpty ( ) )
return ;
2022-09-01 18:29:07 +01:00
m_Groups [ " " ] . removeAll ( Name ) ;
2022-09-15 09:01:54 +01:00
m_Groups [ List . first ( ) ] . removeAll ( Name ) ;
2022-04-16 14:01:01 +01:00
m_Groups [ List . first ( ) ] . append ( Name ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pRenGroupe )
{
QStringList List = GetSelectedGroups ( ) ;
if ( List . isEmpty ( ) )
return ;
QString OldValue = List . first ( ) ;
QString Value = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " Please enter a new name for the Group. " ) , QLineEdit : : Normal , OldValue ) ;
if ( Value . isEmpty ( ) | | Value = = OldValue )
return ;
2022-04-16 14:01:01 +01:00
if ( ! TestNameAndWarn ( Value ) )
2021-10-15 16:39:43 +01:00
return ;
2022-04-16 14:01:01 +01:00
RenameGroup ( OldValue , Value ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pDelGroupe )
{
if ( QMessageBox ( " Sandboxie-Plus " , tr ( " Do you really want to remove the selected group(s)? " ) , QMessageBox : : Question , QMessageBox : : Yes , QMessageBox : : No | QMessageBox : : Default | QMessageBox : : Escape , QMessageBox : : NoButton , this ) . exec ( ) ! = QMessageBox : : Yes )
return ;
foreach ( const QModelIndex & Index , m_pSbieTree - > selectedRows ( ) )
{
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( Index ) ;
if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eGroup )
{
QString Group = m_pSbieModel - > GetID ( ModelIndex ) . toString ( ) ;
2022-12-07 16:32:40 +00:00
QStringList Items = m_Groups . take ( Group ) ; // remove group
2021-10-15 16:39:43 +01:00
// remove from parents
for ( auto I = m_Groups . begin ( ) ; I ! = m_Groups . end ( ) ; + + I ) {
if ( I . value ( ) . removeOne ( Group ) ) {
// move items to grand parent
I . value ( ) . append ( Items ) ;
break ;
}
}
2022-09-15 08:58:41 +01:00
m_Collapsed . remove ( Group ) ;
2021-10-15 16:39:43 +01:00
}
}
}
else if ( Action = = m_pMenuMoveUp /*|| Action == m_pMenuMoveBy*/ | | Action = = m_pMenuMoveDown )
{
2022-05-29 06:53:58 +01:00
if ( ! theConf - > GetBool ( " MainWindow/BoxTree_UseOrder " , false ) ) {
2022-06-04 20:07:04 +01:00
SetCustomOrder ( ) ;
2022-05-29 06:53:58 +01:00
theConf - > SetValue ( " MainWindow/BoxTree_UseOrder " , true ) ;
}
2021-10-15 16:39:43 +01:00
int Offset = 0 ;
if ( Action = = m_pMenuMoveUp )
Offset = - 1 ;
else if ( Action = = m_pMenuMoveDown )
Offset = 1 ;
else
Offset = QInputDialog : : getInt ( this , " Sandboxie-Plus " , tr ( " Move entries by (negative values move up, positive values move down): " ) , 0 ) ;
if ( Offset = = 0 )
return ;
2022-12-17 20:06:15 +00:00
// todo: fix behaviour on multiple selection
2023-05-14 18:07:18 +01:00
QMap < QString , QVector < int > > GroupPositions ;
bool bOutBounded = false ;
auto FindPosition = [ this , Offset , & bOutBounded , & GroupPositions ] ( const QString & Name ) - > bool {
foreach ( const QString & Group , m_Groups . keys ( ) ) {
int pos = m_Groups [ Group ] . indexOf ( Name ) ;
2021-10-15 16:39:43 +01:00
if ( pos ! = - 1 ) {
2023-05-14 18:07:18 +01:00
if ( pos + Offset > = 0 & & pos + Offset < m_Groups [ Group ] . count ( ) )
GroupPositions [ Group ] . append ( pos ) ;
else
bOutBounded = true ;
return true ;
2021-10-15 16:39:43 +01:00
}
}
2023-05-14 18:07:18 +01:00
return false ;
} ;
foreach ( const QString & Name , GetSelectedGroups ( true ) ) {
if ( ! FindPosition ( Name ) ) {
2021-10-15 16:39:43 +01:00
m_Groups [ " " ] . prepend ( Name ) ;
2023-05-14 18:07:18 +01:00
FindPosition ( Name ) ;
}
if ( bOutBounded )
break ;
}
if ( bOutBounded )
QApplication : : beep ( ) ;
else {
foreach ( const QString & Group , GroupPositions . keys ( ) ) {
std : : sort ( GroupPositions [ Group ] . begin ( ) , GroupPositions [ Group ] . end ( ) , [ Offset ] ( const int & a , const int & b ) {
return Offset > 0 & & a > b | | Offset < 0 & & a < b ;
} ) ;
foreach ( const int ItemIndex , GroupPositions [ Group ] ) {
m_Groups [ Group ] . swapItemsAt ( ItemIndex + Offset , ItemIndex ) ;
}
2021-10-15 16:39:43 +01:00
}
}
}
2022-12-07 16:32:40 +00:00
else // move to group
2021-10-15 16:39:43 +01:00
{
QString Group = Action - > data ( ) . toString ( ) ;
foreach ( const QString & Name , GetSelectedGroups ( true ) )
{
if ( Name = = Group | | IsParentOf ( Name , Group ) ) {
QMessageBox ( " Sandboxie-Plus " , tr ( " A group can not be its own parent. " ) , QMessageBox : : Critical , QMessageBox : : Ok , QMessageBox : : NoButton , QMessageBox : : NoButton , this ) . exec ( ) ;
continue ;
}
2022-04-16 14:01:01 +01:00
MoveItem ( Name , Group ) ;
2021-10-15 16:39:43 +01:00
}
2022-04-16 14:01:01 +01:00
}
2021-10-15 16:39:43 +01:00
2022-07-10 20:44:24 +01:00
if ( ! ( Action = = m_pMenuMoveUp /*|| Action == m_pMenuMoveBy*/ | | Action = = m_pMenuMoveDown ) ) {
2021-10-15 16:39:43 +01:00
m_pSbieModel - > Clear ( ) ; //todo improve that
2022-07-10 20:44:24 +01:00
Refresh ( ) ;
}
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
UpdateMoveMenu ( ) ;
2021-12-23 15:28:14 +00:00
2023-05-29 13:11:34 +01:00
SaveBoxGrouping ( ) ;
2021-10-15 16:39:43 +01:00
}
2022-06-04 20:07:04 +01:00
void CSbieView : : SetCustomOrder ( )
{
m_pSortProxy - > sort ( 0 , Qt : : AscendingOrder ) ;
m_pSortProxy - > setSortRole ( Qt : : InitialSortOrderRole ) ;
m_pSbieTree - > header ( ) - > setSortIndicatorShown ( false ) ;
}
2022-07-10 20:44:24 +01:00
bool CSbieView : : MoveItem ( const QString & Name , const QString & To , int pos )
2022-04-16 14:01:01 +01:00
{
2022-07-10 20:44:24 +01:00
QString From ;
2022-04-16 14:01:01 +01:00
// remove from old
2022-07-10 20:44:24 +01:00
for ( auto I = m_Groups . begin ( ) ; I ! = m_Groups . end ( ) ; + + I ) {
2022-09-01 18:29:07 +01:00
for ( int i = 0 ; i < I . value ( ) . count ( ) ; i + + ) {
if ( I . value ( ) . at ( i ) = = Name ) {
I . value ( ) . removeAt ( i ) ;
From = I . key ( ) ;
if ( From = = To & & i < pos )
pos - - ;
break ;
}
}
2022-07-10 20:44:24 +01:00
}
2022-04-16 14:01:01 +01:00
// add to new
2022-11-18 14:13:39 +00:00
if ( pos < 0 /* || pos > m_Groups[To].size()*/ )
m_Groups [ To ] . append ( Name ) ;
else
m_Groups [ To ] . insert ( pos , Name ) ;
2022-07-10 20:44:24 +01:00
return From ! = To ;
2022-04-16 14:01:01 +01:00
}
2023-01-29 10:48:28 +00:00
QString CSbieView : : AddNewBox ( bool bAlowTemp )
2021-10-15 16:39:43 +01:00
{
2023-07-01 17:54:53 +01:00
QString BoxName = CNewBoxWizard : : CreateNewBox ( bAlowTemp , this ) ;
2023-01-28 13:05:37 +00:00
if ( ! BoxName . isEmpty ( ) ) {
2021-10-15 16:39:43 +01:00
theAPI - > ReloadBoxes ( ) ;
Refresh ( ) ;
2023-01-28 13:05:37 +00:00
SelectBox ( BoxName ) ;
2021-10-15 16:39:43 +01:00
}
2023-01-28 13:05:37 +00:00
return BoxName ;
2021-10-15 16:39:43 +01:00
}
2023-05-23 21:17:50 +01:00
QString CSbieView : : ImportSandbox ( )
{
QString Value = QFileDialog : : getOpenFileName ( this , tr ( " Select file name " ) , " " , tr ( " 7-zip Archive (*.7z) " ) ) ;
if ( Value . isEmpty ( ) )
return " " ;
StrPair PathName = Split2 ( Value , " / " , true ) ;
StrPair NameEx = Split2 ( PathName . second , " . " , true ) ;
QString Name = NameEx . first ;
CSandBoxPtr pBox ;
for ( ; ; ) {
pBox = theAPI - > GetBoxByName ( Name ) ;
if ( pBox . isNull ( ) )
break ;
Name = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " This name is already in use, please select an alternative box name " ) , QLineEdit : : Normal , Name ) ;
if ( Name . isEmpty ( ) )
return " " ;
}
SB_PROGRESS Status = theAPI - > CreateBox ( Name ) ;
if ( ! Status . IsError ( ) ) {
pBox = theAPI - > GetBoxByName ( Name ) ;
if ( pBox ) {
auto pBoxEx = pBox . objectCast < CSandBoxPlus > ( ) ;
Status = pBoxEx - > ImportBox ( Value ) ;
}
}
if ( Status . GetStatus ( ) = = OP_ASYNC ) {
Status = theGUI - > AddAsyncOp ( Status . GetValue ( ) , true , tr ( " Importing: %1 " ) . arg ( Value ) ) ;
if ( Status . IsError ( ) ) {
theGUI - > DeleteBoxContent ( pBox , CSandMan : : eForDelete ) ;
pBox - > RemoveBox ( ) ;
}
}
else
2023-07-01 17:54:53 +01:00
theGUI - > CheckResults ( QList < SB_STATUS > ( ) < < Status , this ) ;
2023-05-23 21:17:50 +01:00
return Name ;
}
2021-10-15 16:39:43 +01:00
QString CSbieView : : AddNewGroup ( )
{
QString Name = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " Please enter a new group name " ) , QLineEdit : : Normal ) ;
if ( Name . isEmpty ( ) | | m_Groups . contains ( Name ) )
return " " ;
2022-04-16 14:01:01 +01:00
if ( ! TestNameAndWarn ( Name ) )
return " " ;
2021-10-15 16:39:43 +01:00
m_Groups [ Name ] = QStringList ( ) ;
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( m_pSbieTree - > currentIndex ( ) ) ;
QString Parent ;
if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eGroup )
Parent = m_pSbieModel - > GetID ( ModelIndex ) . toString ( ) ;
m_Groups [ Parent ] . append ( Name ) ;
2022-07-12 17:23:28 +01:00
UpdateMoveMenu ( ) ;
2021-10-15 16:39:43 +01:00
2023-05-29 13:11:34 +01:00
SaveBoxGrouping ( ) ;
2021-12-23 15:28:14 +00:00
2021-10-15 16:39:43 +01:00
return Name ;
}
2022-04-16 14:01:01 +01:00
bool CSbieView : : TestNameAndWarn ( const QString & Name )
{
2022-09-16 00:31:13 +01:00
if ( Name . contains ( QRegularExpression ( " [,()] " ) ) )
{
QMessageBox : : critical ( this , " Sandboxie-Plus " , tr ( " The Sandbox name and Box Group name cannot use the ',()' symbol. " ) ) ;
return false ;
}
2022-04-16 14:01:01 +01:00
if ( m_Groups . contains ( Name ) ) {
QMessageBox : : critical ( this , " Sandboxie-Plus " , tr ( " This name is already used for a Box Group. " ) ) ;
return false ;
}
if ( ! theAPI - > GetBoxByName ( QString ( Name ) . replace ( " " , " _ " ) ) . isNull ( ) ) {
QMessageBox : : critical ( this , " Sandboxie-Plus " , tr ( " This name is already used for a Sandbox. " ) ) ;
return false ;
}
return true ;
}
2021-10-15 16:39:43 +01:00
void CSbieView : : OnSandBoxAction ( )
{
2022-07-12 08:35:00 +01:00
OnSandBoxAction ( qobject_cast < QAction * > ( sender ( ) ) , m_CurSandBoxes ) ;
2021-10-15 16:39:43 +01:00
}
2022-07-22 21:47:52 +01:00
void CSbieView : : OnSandBoxAction ( QAction * pAction )
{
OnSandBoxAction ( pAction , m_CurSandBoxes ) ;
}
2022-07-12 08:35:00 +01:00
void CSbieView : : OnSandBoxAction ( QAction * Action , const QList < CSandBoxPtr > & SandBoxes )
2021-10-15 16:39:43 +01:00
{
QList < SB_STATUS > Results ;
if ( SandBoxes . isEmpty ( ) )
return ;
2022-02-05 14:09:53 +00:00
if ( Action = = m_pStopAsync )
{
2023-07-01 17:54:53 +01:00
foreach ( const CSandBoxPtr & pBox , SandBoxes )
2022-02-05 14:09:53 +00:00
{
auto pBoxEx = pBox . objectCast < CSandBoxPlus > ( ) ;
pBoxEx - > OnCancelAsync ( ) ;
}
}
else if ( Action = = m_pMenuRunAny )
2021-10-15 16:39:43 +01:00
{
/*QString Command = ShowRunDialog(SandBoxes.first()->GetName());
if ( ! Command . isEmpty ( ) )
SandBoxes . first ( ) - > RunCommand ( Command ) ; */
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " run_dialog " ) ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuRunBrowser )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " default_browser " ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuRunMailer )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " mail_agent " ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuRunExplorer )
{
2022-07-09 10:46:07 +01:00
if ( theConf - > GetInt ( " Options/ViewMode " , 1 ) ! = 1 & & theConf - > GetBool ( " Options/BoxedExplorerInfo " , true ) )
2021-10-15 16:39:43 +01:00
{
bool State = false ;
CCheckableMessageBox : : question ( this , " Sandboxie-Plus " ,
theAPI - > GetSbieMsgStr ( 0x00000DCDL , theGUI - > m_LanguageId ) // MSG_3533
, tr ( " Don't show this message again. " ) , & State , QDialogButtonBox : : Ok , QDialogButtonBox : : Ok , QMessageBox : : Information ) ;
if ( State )
theConf - > SetValue ( " Options/BoxedExplorerInfo " , false ) ;
}
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D} " ) ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuRunRegEdit )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " regedit.exe " ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuRunAppWiz )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " \" C: \\ WINDOWS \\ System32 \\ control.exe \" \" C: \\ Windows \\ System32 \\ appwiz.cpl \" " ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuAutoRun )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " auto_run " ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuRunCmd )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " cmd.exe " ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuRunCmdAdmin )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " cmd.exe " , true ) ) ;
2022-11-30 11:45:03 +00:00
# ifdef _WIN64
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuRunCmd32 )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " C: \\ WINDOWS \\ SysWOW64 \\ cmd.exe " ) ) ;
2022-11-30 11:45:03 +00:00
# endif
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuPresetsShowUAC )
{
2022-11-29 15:49:16 +00:00
SandBoxes . first ( ) - > SetBoolSafe ( " DropAdminRights " , false ) ;
SandBoxes . first ( ) - > SetBoolSafe ( " FakeAdminRights " , false ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuPresetsNoAdmin )
{
2022-11-29 15:49:16 +00:00
SandBoxes . first ( ) - > SetBoolSafe ( " DropAdminRights " , true ) ;
SandBoxes . first ( ) - > SetBoolSafe ( " FakeAdminRights " , false ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuPresetsFakeAdmin )
{
2022-11-29 15:49:16 +00:00
SandBoxes . first ( ) - > SetBoolSafe ( " DropAdminRights " , true ) ;
SandBoxes . first ( ) - > SetBoolSafe ( " FakeAdminRights " , true ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuPresetsINet )
SandBoxes . first ( ) . objectCast < CSandBoxPlus > ( ) - > SetINetBlock ( m_pMenuPresetsINet - > isChecked ( ) ) ;
else if ( Action = = m_pMenuPresetsShares )
SandBoxes . first ( ) . objectCast < CSandBoxPlus > ( ) - > SetAllowShares ( m_pMenuPresetsShares - > isChecked ( ) ) ;
2022-06-13 19:12:53 +01:00
else if ( Action = = m_pMenuPresetsRecovery )
2022-11-29 15:49:16 +00:00
m_pMenuPresetsRecovery - > setChecked ( SandBoxes . first ( ) - > SetBoolSafe ( " AutoRecover " , m_pMenuPresetsRecovery - > isChecked ( ) ) ) ;
2023-04-24 01:24:06 +01:00
else if ( Action = = m_pMenuPresetsForce )
m_pMenuPresetsForce - > setChecked ( SandBoxes . first ( ) - > SetBoolSafe ( " DisableForceRules " , m_pMenuPresetsForce - > isChecked ( ) ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuOptions )
2022-07-09 10:46:07 +01:00
ShowOptions ( SandBoxes . first ( ) ) ;
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuBrowse )
2022-07-09 10:46:07 +01:00
ShowBrowse ( SandBoxes . first ( ) ) ;
2022-06-13 19:12:53 +01:00
else if ( Action = = m_pMenuRefresh )
{
foreach ( const CSandBoxPtr & pBox , SandBoxes )
{
pBox . objectCast < CSandBoxPlus > ( ) - > UpdateSize ( ) ;
2022-09-29 17:28:48 +01:00
if ( theConf - > GetBool ( " Options/ScanStartMenu " , true ) )
pBox . objectCast < CSandBoxPlus > ( ) - > ScanStartMenu ( ) ;
2022-06-13 19:12:53 +01:00
}
}
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuExplore )
{
if ( SandBoxes . first ( ) - > IsEmpty ( ) ) {
QMessageBox ( " Sandboxie-Plus " , tr ( " This Sandbox is empty. " ) , QMessageBox : : Information , QMessageBox : : Ok , QMessageBox : : NoButton , QMessageBox : : NoButton , this ) . exec ( ) ;
return ;
}
2022-07-09 10:46:07 +01:00
if ( theConf - > GetInt ( " Options/ViewMode " , 1 ) ! = 1 & & theConf - > GetBool ( " Options/ExplorerInfo " , true ) )
2021-10-15 16:39:43 +01:00
{
bool State = false ;
CCheckableMessageBox : : question ( this , " Sandboxie-Plus " ,
theAPI - > GetSbieMsgStr ( 0x00000DCEL , theGUI - > m_LanguageId ) // MSG_3534
, tr ( " Don't show this message again. " ) , & State , QDialogButtonBox : : Ok , QDialogButtonBox : : Ok , QMessageBox : : Information ) ;
if ( State )
theConf - > SetValue ( " Options/ExplorerInfo " , false ) ;
}
: : ShellExecute ( NULL , NULL , SandBoxes . first ( ) - > GetFileRoot ( ) . toStdWString ( ) . c_str ( ) , NULL , NULL , SW_SHOWNORMAL ) ;
}
else if ( Action = = m_pMenuRegEdit )
{
if ( SandBoxes . first ( ) - > IsEmpty ( ) ) {
QMessageBox ( " Sandboxie-Plus " , tr ( " This Sandbox is empty. " ) , QMessageBox : : Information , QMessageBox : : Ok , QMessageBox : : NoButton , QMessageBox : : NoButton , this ) . exec ( ) ;
return ;
}
2022-02-13 12:27:26 +00:00
if ( theConf - > GetInt ( " Options/WarnOpenRegistry " , - 1 ) = = - 1 )
{
bool State = false ;
2022-02-13 16:54:54 +00:00
if ( CCheckableMessageBox : : question ( this , " Sandboxie-Plus " , tr ( " WARNING: The opened registry editor is not sandboxed, please be careful and only do changes to the pre-selected sandbox locations. " )
2022-02-13 12:27:26 +00:00
, tr ( " Don't show this warning in future " ) , & State , QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel , QDialogButtonBox : : Yes , QMessageBox : : Information ) ! = QDialogButtonBox : : Ok )
return ;
if ( State )
theConf - > SetValue ( " Options/WarnOpenRegistry " , 1 ) ;
}
2022-09-29 17:28:48 +01:00
std : : wstring path = QCoreApplication : : applicationFilePath ( ) . toStdWString ( ) ;
2021-10-15 16:39:43 +01:00
QStringList RegRoot = SandBoxes . first ( ) - > GetRegRoot ( ) . split ( " \\ " ) ;
while ( RegRoot . first ( ) . isEmpty ( ) )
RegRoot . removeFirst ( ) ;
RegRoot [ 0 ] = QString ( " Computer " ) ;
if ( RegRoot [ 1 ] = = " USER " )
RegRoot [ 1 ] = QString ( " HKEY_USERS " ) ;
else if ( RegRoot [ 1 ] = = " MACHINE " )
RegRoot [ 1 ] = QString ( " HKEY_LOCAL_MACHINE " ) ;
2022-09-29 17:28:48 +01:00
std : : wstring params = L " /OpenReg \" " + RegRoot . join ( " \\ " ) . toStdWString ( ) + L " \" " ;
2021-10-15 16:39:43 +01:00
if ( SandBoxes . first ( ) - > GetActiveProcessCount ( ) = = 0 )
params + = L " \" " + theAPI - > GetStartPath ( ) . toStdWString ( ) + L " /box: " + SandBoxes . first ( ) - > GetName ( ) . toStdWString ( ) + L " mount_hive \" " ;
SHELLEXECUTEINFO shex ;
memset ( & shex , 0 , sizeof ( SHELLEXECUTEINFO ) ) ;
shex . cbSize = sizeof ( SHELLEXECUTEINFO ) ;
shex . fMask = SEE_MASK_FLAG_NO_UI ;
shex . hwnd = NULL ;
shex . lpFile = path . c_str ( ) ;
shex . lpParameters = params . c_str ( ) ;
shex . nShow = SW_SHOWNORMAL ;
shex . lpVerb = L " runas " ;
ShellExecuteEx ( & shex ) ;
}
else if ( Action = = m_pMenuSnapshots )
{
CSandBoxPtr pBox = SandBoxes . first ( ) ;
static QMap < void * , CSnapshotsWindow * > SnapshotWindows ;
2022-02-02 18:31:03 +00:00
CSnapshotsWindow * pSnapshotsWindow = SnapshotWindows . value ( pBox . data ( ) ) ;
if ( pSnapshotsWindow = = NULL ) {
pSnapshotsWindow = new CSnapshotsWindow ( SandBoxes . first ( ) , this ) ;
2023-02-01 21:16:41 +00:00
connect ( theGUI , SIGNAL ( Closed ( ) ) , pSnapshotsWindow , SLOT ( close ( ) ) ) ;
2021-10-15 16:39:43 +01:00
SnapshotWindows . insert ( pBox . data ( ) , pSnapshotsWindow ) ;
connect ( pSnapshotsWindow , & CSnapshotsWindow : : Closed , [ this , pBox ] ( ) {
SnapshotWindows . remove ( pBox . data ( ) ) ;
} ) ;
2022-01-14 13:06:01 +00:00
SafeShow ( pSnapshotsWindow ) ;
2021-10-15 16:39:43 +01:00
}
2022-02-02 18:31:03 +00:00
else {
pSnapshotsWindow - > setWindowState ( ( pSnapshotsWindow - > windowState ( ) & ~ Qt : : WindowMinimized ) | Qt : : WindowActive ) ;
SetForegroundWindow ( ( HWND ) pSnapshotsWindow - > winId ( ) ) ;
}
2021-10-15 16:39:43 +01:00
}
2021-11-13 08:28:32 +00:00
else if ( Action = = m_pMenuDuplicate )
{
QString OldValue = SandBoxes . first ( ) - > GetName ( ) . replace ( " _ " , " " ) ;
QString Value = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " Please enter a new name for the duplicated Sandbox. " ) , QLineEdit : : Normal , tr ( " %1 Copy " ) . arg ( OldValue ) ) ;
if ( Value . isEmpty ( ) | | Value = = OldValue )
return ;
QString Name = Value . replace ( " " , " _ " ) ;
SB_STATUS Status = theAPI - > CreateBox ( Name , false ) ;
if ( ! Status . IsError ( ) )
{
CSandBoxPtr pBox = theAPI - > GetBoxByName ( Value ) ;
QList < QPair < QString , QString > > Settings ;
CSandBoxPtr pSrcBox = theAPI - > GetBoxByName ( SandBoxes . first ( ) - > GetName ( ) ) ;
qint32 status = 0 ;
if ( ! pSrcBox . isNull ( ) ) Settings = pSrcBox - > GetIniSection ( & status ) ;
if ( Settings . isEmpty ( ) )
Status = SB_ERR ( SB_FailedCopyConf , QVariantList ( ) < < SandBoxes . first ( ) - > GetName ( ) < < ( quint32 ) status ) ;
else
{
for ( QList < QPair < QString , QString > > : : iterator I = Settings . begin ( ) ; I ! = Settings . end ( ) ; + + I )
{
2022-01-30 14:53:37 +00:00
if ( I - > first = = " FileRootPath " & & ! I - > second . toUpper ( ) . contains ( " %SANDBOX% " ) )
continue ; // skip the FileRootPath if it does not contain a %SANDBOX%
2021-11-13 08:28:32 +00:00
Status = theAPI - > SbieIniSet ( Name , I - > first , I - > second , CSbieAPI : : eIniInsert , false ) ;
if ( Status . IsError ( ) )
break ;
}
}
theAPI - > CommitIniChanges ( ) ;
2023-07-01 17:54:53 +01:00
theAPI - > ReloadBoxes ( true ) ;
2021-11-13 08:28:32 +00:00
}
Results . append ( Status ) ;
}
2022-11-12 09:45:35 +00:00
else if ( Action = = m_pMenuExport )
{
QString Value = QFileDialog : : getSaveFileName ( this , tr ( " Select file name " ) , SandBoxes . first ( ) - > GetName ( ) + " .7z " , tr ( " 7-zip Archive (*.7z) " ) ) ;
if ( Value . isEmpty ( ) )
return ;
CSandBoxPtr pBox = SandBoxes . first ( ) ;
auto pBoxEx = pBox . objectCast < CSandBoxPlus > ( ) ;
SB_PROGRESS Status = pBoxEx - > ExportBox ( Value ) ;
if ( Status . GetStatus ( ) = = OP_ASYNC )
theGUI - > AddAsyncOp ( Status . GetValue ( ) , false , tr ( " Exporting: %1 " ) . arg ( Value ) ) ;
else
Results . append ( Status ) ;
}
2021-10-15 16:39:43 +01:00
else if ( Action = = m_pMenuRename )
{
2022-09-17 21:16:58 +01:00
QString OldValue = SandBoxes . first ( ) - > GetName ( ) . replace ( " _ " , " " ) ;
QString Value = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " Please enter a new name for the Sandbox. " ) , QLineEdit : : Normal , OldValue ) ;
2021-10-15 16:39:43 +01:00
if ( Value . isEmpty ( ) | | Value = = OldValue )
return ;
2022-04-16 14:01:01 +01:00
if ( ! TestNameAndWarn ( Value ) )
return ;
2022-10-18 14:37:26 +01:00
SB_STATUS Status = SandBoxes . first ( ) - > RenameBox ( Value . replace ( " " , " _ " ) ) ;
2022-09-15 22:45:35 +01:00
if ( ! Status . IsError ( ) )
2022-12-23 06:17:47 +00:00
{
2022-09-17 21:16:58 +01:00
RenameItem ( OldValue . replace ( " " , " _ " ) , Value . replace ( " " , " _ " ) ) ;
2022-12-23 06:17:47 +00:00
if ( theAPI - > GetGlobalSettings ( ) - > GetText ( " DefaultBox " , " DefaultBox " ) . compare ( OldValue . replace ( " " , " _ " ) , Qt : : CaseInsensitive ) = = 0 )
theAPI - > GetGlobalSettings ( ) - > SetText ( " DefaultBox " , Value . replace ( " " , " _ " ) ) ;
}
2022-09-15 22:45:35 +01:00
Results . append ( Status ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuRecover )
{
theGUI - > ShowRecovery ( SandBoxes . first ( ) ) ;
}
else if ( Action = = m_pMenuRemove )
{
2022-01-16 20:28:59 +00:00
if ( QMessageBox ( " Sandboxie-Plus " , tr ( " Do you really want to remove the selected sandbox(es)?<br /><br />Warning: The box content will also be deleted! " ) , QMessageBox : : Warning , QMessageBox : : Yes , QMessageBox : : No | QMessageBox : : Default | QMessageBox : : Escape , QMessageBox : : NoButton , this ) . exec ( ) ! = QMessageBox : : Yes )
2021-10-15 16:39:43 +01:00
return ;
2023-05-29 13:11:34 +01:00
bool bChanged = false ;
2022-02-05 11:42:04 +00:00
foreach ( const CSandBoxPtr & pBox , SandBoxes )
2021-10-15 16:39:43 +01:00
{
2023-07-20 19:45:51 +01:00
SB_STATUS Status = SB_OK ;
2023-07-01 17:54:53 +01:00
if ( ! pBox - > GetBool ( " IsShadow " ) ) {
2023-07-22 08:49:24 +01:00
if ( pBox - > GetBool ( " NeverRemove " , false ) )
Status = SB_ERR ( SB_DeleteProtect ) ;
else {
Status = theGUI - > DeleteBoxContent ( pBox , CSandMan : : eForDelete ) ;
if ( Status . GetMsgCode ( ) = = SB_Canceled )
break ;
}
2023-07-01 17:54:53 +01:00
}
2023-07-20 19:45:51 +01:00
2022-09-16 00:34:31 +01:00
QString Name = pBox - > GetName ( ) ;
2023-07-20 19:45:51 +01:00
if ( ! Status . IsError ( ) )
Status = pBox - > RemoveBox ( ) ;
2022-09-15 09:09:48 +01:00
2022-09-17 21:16:58 +01:00
if ( ! Status . IsError ( ) ) {
theConf - > DelValue ( " SizeCache/ " + Name ) ;
2022-09-20 04:40:28 +01:00
m_Collapsed . remove ( Name ) ;
2022-09-17 21:16:58 +01:00
for ( auto I = m_Groups . begin ( ) ; I ! = m_Groups . end ( ) ; + + I )
{
2023-05-29 13:11:34 +01:00
if ( I . value ( ) . removeOne ( Name ) ) {
bChanged = true ;
2022-09-17 21:16:58 +01:00
break ;
2023-05-29 13:11:34 +01:00
}
2022-09-17 21:16:58 +01:00
}
2022-09-15 09:09:48 +01:00
}
2023-07-20 19:45:51 +01:00
Results . append ( Status ) ;
2022-09-15 09:24:15 +01:00
}
2023-05-29 13:11:34 +01:00
if ( bChanged )
SaveBoxGrouping ( ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuCleanUp )
{
2023-02-03 07:00:11 +00:00
bool DeleteSnapshots = false ;
2022-01-30 14:53:37 +00:00
2021-10-15 16:39:43 +01:00
if ( SandBoxes . count ( ) = = 1 )
{
if ( SandBoxes . first ( ) - > IsEmpty ( ) ) {
QMessageBox ( " Sandboxie-Plus " , tr ( " This Sandbox is already empty. " ) , QMessageBox : : Information , QMessageBox : : Ok , QMessageBox : : NoButton , QMessageBox : : NoButton , this ) . exec ( ) ;
return ;
}
if ( theConf - > GetBool ( " Options/ShowRecovery " , false ) )
{
// Use recovery dialog in place of the confirmation messagebox for box clean up
2023-02-03 07:00:11 +00:00
if ( ! theGUI - > OpenRecovery ( SandBoxes . first ( ) , DeleteSnapshots ) )
2021-10-15 16:39:43 +01:00
return ;
}
2023-07-01 17:54:53 +01:00
else {
if ( SandBoxes . first ( ) - > HasSnapshots ( ) ) {
if ( CCheckableMessageBox : : question ( this , " Sandboxie-Plus " , tr ( " Do you want to delete the content of the selected sandbox? " )
, tr ( " Also delete all Snapshots " ) , & DeleteSnapshots , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : Yes ) ! = QDialogButtonBox : : Yes )
return ;
}
else {
if ( QMessageBox : : question ( this , " Sandboxie-Plus " , tr ( " Do you want to delete the content of the selected sandbox? " )
, QMessageBox : : Yes , QMessageBox : : No ) ! = QMessageBox : : Yes )
return ;
}
}
2021-10-15 16:39:43 +01:00
}
2022-01-30 16:43:21 +00:00
else if ( CCheckableMessageBox : : question ( this , " Sandboxie-Plus " , tr ( " Do you really want to delete the content of all selected sandboxes? " )
2023-02-03 07:00:11 +00:00
, tr ( " Also delete all Snapshots " ) , & DeleteSnapshots , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : Yes ) ! = QDialogButtonBox : : Yes )
2022-01-30 14:53:37 +00:00
return ;
2021-10-15 16:39:43 +01:00
2023-07-01 17:54:53 +01:00
foreach ( const CSandBoxPtr & pBox , SandBoxes )
2021-10-15 16:39:43 +01:00
{
2023-07-01 17:54:53 +01:00
SB_STATUS Status = theGUI - > DeleteBoxContent ( pBox , CSandMan : : eCleanUp , DeleteSnapshots ) ;
if ( Status . GetMsgCode ( ) = = SB_Canceled )
break ;
Results . append ( Status ) ;
2021-10-15 16:39:43 +01:00
}
}
else if ( Action = = m_pMenuEmptyBox )
{
if ( theConf - > GetInt ( " Options/WarnTerminate " , - 1 ) = = - 1 )
{
bool State = false ;
if ( CCheckableMessageBox : : question ( this , " Sandboxie-Plus " , tr ( " Do you want to terminate all processes in the selected sandbox(es)? " )
2022-01-30 14:53:37 +00:00
, tr ( " Terminate without asking " ) , & State , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : Yes ) ! = QDialogButtonBox : : Yes )
2021-10-15 16:39:43 +01:00
return ;
if ( State )
theConf - > SetValue ( " Options/WarnTerminate " , 1 ) ;
}
foreach ( const CSandBoxPtr & pBox , SandBoxes )
Results . append ( pBox - > TerminateAll ( ) ) ;
}
else if ( Action = = m_pMenuMkLink )
{
2022-06-27 07:33:15 +01:00
if ( theConf - > GetInt ( " Options/InfoMkLink " , - 1 ) = = - 1 )
{
bool State = false ;
2022-07-27 17:59:30 +01:00
CCheckableMessageBox : : question ( this , " Sandboxie-Plus " , tr ( " The Sandboxie Start Menu will now be displayed. Select an application from the menu, and Sandboxie will create a new "
2022-06-27 07:33:15 +01:00
" shortcut icon on your real desktop, which you can use to invoke the selected application under the supervision of Sandboxie. " )
, tr ( " Don't show this message again. " ) , & State , QDialogButtonBox : : Ok , QDialogButtonBox : : Ok , QMessageBox : : Information ) ;
if ( State )
theConf - > SetValue ( " Options/InfoMkLink " , 1 ) ;
}
2021-10-15 16:39:43 +01:00
QString BoxName = SandBoxes . first ( ) - > GetName ( ) ;
QString LinkPath , IconPath , WorkDir ;
quint32 IconIndex ;
if ( ! CSbieUtils : : GetStartMenuShortcut ( theAPI , BoxName , LinkPath , IconPath , IconIndex , WorkDir ) )
return ;
2023-08-03 19:17:52 +01:00
CreateShortcutEx ( LinkPath , BoxName , " " , IconPath , IconIndex , WorkDir ) ;
2021-10-15 16:39:43 +01:00
}
else // custom run menu command
{
QString Command = Action - > data ( ) . toString ( ) ;
2023-05-27 16:12:22 +01:00
QString WorkingDir = Action - > property ( " WorkingDir " ) . toString ( ) ;
2022-09-29 17:28:48 +01:00
if ( Command . isEmpty ( ) )
2023-07-01 17:54:53 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , " start_menu " , false , WorkingDir ) ) ;
2023-05-21 18:23:43 +01:00
else {
auto pBoxEx = SandBoxes . first ( ) . objectCast < CSandBoxPlus > ( ) ;
2023-07-19 21:27:18 +01:00
Results . append ( theGUI - > RunStart ( SandBoxes . first ( ) - > GetName ( ) , pBoxEx - > GetFullCommand ( Command ) , false , pBoxEx - > GetFullCommand ( WorkingDir ) ) ) ;
2021-10-15 16:39:43 +01:00
}
}
2023-07-01 17:54:53 +01:00
theGUI - > CheckResults ( Results , this ) ;
2021-10-15 16:39:43 +01:00
}
2023-08-03 19:17:52 +01:00
bool CSbieView : : CreateShortcutEx ( const QString & LinkPath , const QString & BoxName , QString LinkName , const QString & IconPath , int IconIndex , const QString & WorkDir )
2023-05-23 21:17:50 +01:00
{
2023-08-03 19:17:52 +01:00
if ( LinkName . isEmpty ( ) ) {
int pos = LinkPath . lastIndexOf ( L ' \\ ' ) ;
if ( pos = = - 1 )
return false ;
if ( pos = = 2 & & LinkPath . length ( ) = = 3 )
LinkName = QObject : : tr ( " Drive %1 " ) . arg ( LinkPath . left ( 1 ) ) ;
else {
LinkName = LinkPath . mid ( pos + 1 ) ;
pos = LinkName . indexOf ( QRegularExpression ( " [ " + QRegularExpression : : escape ( " \" :;,*?. " ) + " ] " ) ) ;
if ( pos ! = - 1 )
LinkName = LinkName . left ( pos ) ;
}
2023-05-23 21:17:50 +01:00
}
QString Path = QStandardPaths : : writableLocation ( QStandardPaths : : DesktopLocation ) . replace ( " / " , " \\ " ) ;
//Path = QFileDialog::getExistingDirectory(this, tr("Select Directory to create Shortcut in"), Path).replace("/", "\\");
//if (Path.isEmpty())
// return;
if ( Path . right ( 1 ) ! = " \\ " )
Path . append ( " \\ " ) ;
Path + = " [ " + BoxName + " ] " + LinkName ;
2023-07-01 17:54:53 +01:00
Path = QFileDialog : : getSaveFileName ( theGUI , tr ( " Create Shortcut to sandbox %1 " ) . arg ( BoxName ) , Path , QString ( " Shortcut files (*.lnk) " ) ) . replace ( " / " , " \\ " ) ;
2023-05-23 21:17:50 +01:00
if ( Path . isEmpty ( ) )
return false ;
2023-07-01 17:54:53 +01:00
QString StartExe = theAPI - > GetSbiePath ( ) + " \\ SandMan.exe " ;
return CSbieUtils : : CreateShortcut ( StartExe , Path , LinkName , BoxName , LinkPath , IconPath , IconIndex , WorkDir ) ;
2023-05-23 21:17:50 +01:00
}
2021-10-15 16:39:43 +01:00
void CSbieView : : OnProcessAction ( )
2022-04-16 14:01:01 +01:00
{
2022-07-12 08:35:00 +01:00
OnProcessAction ( qobject_cast < QAction * > ( sender ( ) ) , m_CurProcesses ) ;
2022-04-16 14:01:01 +01:00
}
2022-07-12 08:35:00 +01:00
void CSbieView : : OnProcessAction ( QAction * Action , const QList < CBoxedProcessPtr > & Processes )
2021-10-15 16:39:43 +01:00
{
QList < SB_STATUS > Results ;
if ( Action = = m_pMenuTerminate | | Action = = m_pMenuBlackList )
{
if ( theConf - > GetInt ( " Options/WarnTerminate " , - 1 ) = = - 1 )
{
if ( Processes . isEmpty ( ) )
return ;
bool State = false ;
2023-01-31 08:29:55 +00:00
if ( CCheckableMessageBox : : question ( this , " Sandboxie-Plus " , tr ( " Do you want to terminate %1? " ) . arg ( Processes . count ( ) = = 1 ? Processes [ 0 ] - > GetProcessName ( ) : tr ( " the selected processes " ) )
2022-01-30 14:53:37 +00:00
, tr ( " Terminate without asking " ) , & State , QDialogButtonBox : : Yes | QDialogButtonBox : : No , QDialogButtonBox : : Yes ) ! = QDialogButtonBox : : Yes )
2021-10-15 16:39:43 +01:00
return ;
if ( State )
theConf - > SetValue ( " Options/WarnTerminate " , 1 ) ;
}
}
foreach ( const CBoxedProcessPtr & pProcess , Processes )
{
if ( Action = = m_pMenuTerminate )
Results . append ( pProcess - > Terminate ( ) ) ;
else if ( Action = = m_pMenuLinkTo )
{
QString BoxName = pProcess - > GetBoxName ( ) ;
QString LinkName = pProcess - > GetProcessName ( ) ;
QString LinkPath = pProcess - > GetFileName ( ) ;
QString Path = QStandardPaths : : writableLocation ( QStandardPaths : : DesktopLocation ) . replace ( " / " , " \\ " ) ;
2022-12-07 16:32:40 +00:00
//Path = QFileDialog::getExistingDirectory(this, tr("Select Directory to create Shortcut in"), Path).replace("/", "\\");
2021-10-15 16:39:43 +01:00
//if (Path.isEmpty())
// return;
if ( Path . right ( 1 ) ! = " \\ " )
Path . append ( " \\ " ) ;
Path + = " [ " + BoxName + " ] " + LinkName ;
Path = QFileDialog : : getSaveFileName ( this , tr ( " Create Shortcut to sandbox %1 " ) . arg ( BoxName ) , Path , QString ( " Shortcut files (*.lnk) " ) ) . replace ( " / " , " \\ " ) ;
if ( Path . isEmpty ( ) )
return ;
2023-07-01 17:54:53 +01:00
QString StartExe = theAPI - > GetSbiePath ( ) + " \\ SandMan.exe " ;
CSbieUtils : : CreateShortcut ( StartExe , Path , LinkName , BoxName , LinkPath , LinkPath ) ;
2021-10-15 16:39:43 +01:00
}
else if ( Action = = m_pMenuPinToRun )
{
CSandBoxPlus * pBoxPlus = pProcess . objectCast < CSbieProcess > ( ) - > GetBox ( ) ;
if ( m_pMenuPinToRun - > isChecked ( ) )
2023-05-21 18:23:43 +01:00
pBoxPlus - > InsertText ( " RunCommand " , pProcess - > GetProcessName ( ) + " | \" " + pBoxPlus - > MakeBoxCommand ( pProcess - > GetFileName ( ) ) + " \" " ) ;
2021-10-15 16:39:43 +01:00
else if ( ! m_pMenuPinToRun - > data ( ) . toString ( ) . isEmpty ( ) )
pBoxPlus - > DelValue ( " RunCommand " , m_pMenuPinToRun - > data ( ) . toString ( ) ) ;
}
else if ( Action = = m_pMenuBlackList )
{
Results . append ( pProcess - > Terminate ( ) ) ;
pProcess . objectCast < CSbieProcess > ( ) - > BlockProgram ( ) ;
}
else if ( Action = = m_pMenuAllowInternet )
{
if ( ! pProcess . objectCast < CSbieProcess > ( ) - > GetBox ( ) - > IsINetBlocked ( ) )
{
if ( QMessageBox ( " Sandboxie-Plus " , tr ( " This box does not have Internet restrictions in place, do you want to enable them? " ) , QMessageBox : : Question , QMessageBox : : Yes , QMessageBox : : No | QMessageBox : : Default | QMessageBox : : Escape , QMessageBox : : NoButton , this ) . exec ( ) ! = QMessageBox : : Yes )
return ;
pProcess . objectCast < CSbieProcess > ( ) - > GetBox ( ) - > SetINetBlock ( true ) ;
}
pProcess . objectCast < CSbieProcess > ( ) - > SetInternetAccess ( m_pMenuAllowInternet - > isChecked ( ) ) ;
}
else if ( Action = = m_pMenuMarkForced )
pProcess . objectCast < CSbieProcess > ( ) - > SetForcedProgram ( m_pMenuMarkForced - > isChecked ( ) ) ;
else if ( Action = = m_pMenuMarkLinger )
pProcess . objectCast < CSbieProcess > ( ) - > SetLingeringProgram ( m_pMenuMarkLinger - > isChecked ( ) ) ;
else if ( Action = = m_pMenuMarkLeader )
pProcess . objectCast < CSbieProcess > ( ) - > SetLeaderProgram ( m_pMenuMarkLeader - > isChecked ( ) ) ;
2023-07-30 13:28:35 +01:00
else if ( Action = = m_pMenuSuspend )
2021-10-15 16:39:43 +01:00
Results . append ( pProcess - > SetSuspend ( true ) ) ;
else if ( Action = = m_pMenuResume )
2023-07-30 13:28:35 +01:00
Results . append ( pProcess - > SetSuspend ( false ) ) ;
2021-10-15 16:39:43 +01:00
}
2023-07-01 17:54:53 +01:00
theGUI - > CheckResults ( Results , this ) ;
2021-10-15 16:39:43 +01:00
}
2022-07-09 10:46:07 +01:00
void CSbieView : : ShowOptions ( const CSandBoxPtr & pBox )
{
auto pBoxEx = pBox . objectCast < CSandBoxPlus > ( ) ;
if ( pBoxEx - > m_pOptionsWnd = = NULL ) {
pBoxEx - > m_pOptionsWnd = new COptionsWindow ( pBox , pBox - > GetName ( ) ) ;
2023-02-01 21:16:41 +00:00
connect ( theGUI , SIGNAL ( Closed ( ) ) , pBoxEx - > m_pOptionsWnd , SLOT ( close ( ) ) ) ;
2022-07-09 10:46:07 +01:00
connect ( pBoxEx - > m_pOptionsWnd , & COptionsWindow : : Closed , [ pBoxEx ] ( ) {
pBoxEx - > m_pOptionsWnd = NULL ;
} ) ;
SafeShow ( pBoxEx - > m_pOptionsWnd ) ;
}
else {
pBoxEx - > m_pOptionsWnd - > setWindowState ( ( pBoxEx - > m_pOptionsWnd - > windowState ( ) & ~ Qt : : WindowMinimized ) | Qt : : WindowActive ) ;
SetForegroundWindow ( ( HWND ) pBoxEx - > m_pOptionsWnd - > winId ( ) ) ;
}
}
void CSbieView : : ShowBrowse ( const CSandBoxPtr & pBox )
{
if ( pBox - > IsEmpty ( ) ) {
QMessageBox ( " Sandboxie-Plus " , tr ( " This Sandbox is empty. " ) , QMessageBox : : Information , QMessageBox : : Ok , QMessageBox : : NoButton , QMessageBox : : NoButton , this ) . exec ( ) ;
return ;
}
static QMap < void * , CFileBrowserWindow * > FileBrowserWindows ;
CFileBrowserWindow * pFileBrowserWindow = FileBrowserWindows . value ( pBox . data ( ) ) ;
if ( pFileBrowserWindow = = NULL ) {
pFileBrowserWindow = new CFileBrowserWindow ( pBox ) ;
2023-02-01 21:16:41 +00:00
connect ( theGUI , SIGNAL ( Closed ( ) ) , pFileBrowserWindow , SLOT ( close ( ) ) ) ;
2022-07-09 10:46:07 +01:00
FileBrowserWindows . insert ( pBox . data ( ) , pFileBrowserWindow ) ;
connect ( pFileBrowserWindow , & CFileBrowserWindow : : Closed , [ this , pBox ] ( ) {
FileBrowserWindows . remove ( pBox . data ( ) ) ;
} ) ;
SafeShow ( pFileBrowserWindow ) ;
}
else {
pFileBrowserWindow - > setWindowState ( ( pFileBrowserWindow - > windowState ( ) & ~ Qt : : WindowMinimized ) | Qt : : WindowActive ) ;
SetForegroundWindow ( ( HWND ) pFileBrowserWindow - > winId ( ) ) ;
}
}
2021-10-15 16:39:43 +01:00
void CSbieView : : OnDoubleClicked ( const QModelIndex & index )
{
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( index ) ;
CSandBoxPtr pBox = m_pSbieModel - > GetSandBox ( ModelIndex ) ;
if ( pBox . isNull ( ) )
return ;
2022-11-05 13:42:23 +00:00
if ( ( QGuiApplication : : queryKeyboardModifiers ( ) & Qt : : ControlModifier ) ! = 0 ) {
ShowOptions ( pBox ) ;
return ;
}
2022-06-04 20:07:04 +01:00
2022-11-05 13:42:23 +00:00
if ( index . column ( ) = = CSbieModel : : ePath ) {
OnSandBoxAction ( m_pMenuExplore , QList < CSandBoxPtr > ( ) < < pBox ) ;
return ;
2022-06-13 19:12:53 +01:00
}
//if (index.column() != CSbieModel::eName)
// return;
2022-06-04 20:07:04 +01:00
2021-10-15 16:39:43 +01:00
if ( ! pBox - > IsEnabled ( ) )
{
if ( QMessageBox ( " Sandboxie-Plus " , tr ( " This sandbox is disabled, do you want to enable it? " ) , QMessageBox : : Question , QMessageBox : : Yes , QMessageBox : : No | QMessageBox : : Default | QMessageBox : : Escape , QMessageBox : : NoButton , this ) . exec ( ) ! = QMessageBox : : Yes )
return ;
pBox - > SetText ( " Enabled " , " y " ) ;
2022-07-09 10:46:07 +01:00
return ;
2021-10-15 16:39:43 +01:00
}
2022-07-09 10:46:07 +01:00
2022-09-29 17:28:48 +01:00
QString Action = pBox - > GetText ( " DblClickAction " ) ;
if ( Action . compare ( " !browse " , Qt : : CaseInsensitive ) = = 0 )
ShowBrowse ( pBox ) ;
else if ( Action . compare ( " !recovery " , Qt : : CaseInsensitive ) = = 0 )
theGUI - > ShowRecovery ( pBox ) ;
else if ( Action . compare ( " !run " , Qt : : CaseInsensitive ) = = 0 )
pBox - > RunStart ( " run_dialog " ) ;
else if ( ! Action . isEmpty ( ) & & Action . left ( 1 ) ! = " ! " )
{
if ( Action . left ( 1 ) = = " \\ " )
Action . prepend ( pBox - > GetFileRoot ( ) ) ;
pBox - > RunStart ( Action ) ;
}
else
ShowOptions ( pBox ) ;
2021-10-15 16:39:43 +01:00
}
2022-11-05 13:42:23 +00:00
void CSbieView : : OnClicked ( const QModelIndex & index )
{
emit BoxSelected ( ) ;
}
2021-10-15 16:39:43 +01:00
void CSbieView : : ProcessSelection ( const QItemSelection & selected , const QItemSelection & deselected )
{
2022-07-12 17:23:28 +01:00
if ( selected . empty ( ) )
2021-10-15 16:39:43 +01:00
return ;
QItemSelectionModel * selectionModel = m_pSbieTree - > selectionModel ( ) ;
QItemSelection selection = selectionModel - > selection ( ) ;
QItemSelection invalid ;
/*
QModelIndex root_parent = m_pSbieTree - > currentIndex ( ) . parent ( ) ;
while ( root_parent . isValid ( ) & & root_parent . parent ( ) . isValid ( ) )
root_parent = root_parent . parent ( ) ;
foreach ( const QModelIndex & index , selection . indexes ( ) )
{
QModelIndex parent = index . parent ( ) ;
while ( parent . isValid ( ) & & parent . parent ( ) . isValid ( ) )
parent = parent . parent ( ) ;
if ( parent ! = root_parent )
invalid . select ( index , index ) ;
} */
int Type = m_pSbieModel - > GetType ( m_pSortProxy - > mapToSource ( m_pSbieTree - > currentIndex ( ) ) ) ;
foreach ( const QModelIndex & index , selection . indexes ( ) )
{
if ( m_pSbieModel - > GetType ( m_pSortProxy - > mapToSource ( index ) ) ! = Type )
invalid . select ( index , index ) ;
}
selectionModel - > select ( invalid , QItemSelectionModel : : Deselect ) ;
}
QList < CSandBoxPtr > CSbieView : : GetSelectedBoxes ( )
{
QList < CSandBoxPtr > List ;
foreach ( const QModelIndex & Index , m_pSbieTree - > selectedRows ( ) )
{
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( Index ) ;
CSandBoxPtr pBox = m_pSbieModel - > GetSandBox ( ModelIndex ) ;
if ( ! pBox )
continue ;
List . append ( pBox ) ;
}
return List ;
}
QList < CBoxedProcessPtr > CSbieView : : GetSelectedProcesses ( )
{
QList < CBoxedProcessPtr > List ;
foreach ( const QModelIndex & Index , m_pSbieTree - > selectedRows ( ) )
{
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( Index ) ;
CBoxedProcessPtr pProcess = m_pSbieModel - > GetProcess ( ModelIndex ) ;
if ( ! pProcess )
return QList < CBoxedProcessPtr > ( ) ;
List . append ( pProcess ) ;
}
return List ;
}
2023-02-07 19:17:29 +00:00
QMenu * CSbieView : : GetMenuFolder ( const QString & Folder , QMenu * pParent , QMap < QString , QMenu * > & Folders )
2022-09-29 17:28:48 +01:00
{
2023-02-07 19:17:29 +00:00
QMenu * & pMenu = Folders [ Folder ] ;
2022-09-29 17:28:48 +01:00
if ( ! pMenu )
{
2023-05-23 21:17:50 +01:00
QString Title ;
2022-09-29 17:28:48 +01:00
QStringList Names = Folder . split ( " / " ) ;
StrPair Tmp = Split2 ( Folder , " / " , true ) ;
if ( ! Tmp . second . isEmpty ( ) ) {
2023-02-07 19:17:29 +00:00
pParent = GetMenuFolder ( Tmp . first , pParent , Folders ) ;
2023-05-23 21:17:50 +01:00
Title = Tmp . second ;
2022-09-29 17:28:48 +01:00
}
else
2023-05-23 21:17:50 +01:00
Title = Tmp . first ;
pMenu = new CMenuEx ( Title , pParent ) ;
2022-09-29 17:28:48 +01:00
pMenu - > setIcon ( m_IconProvider . icon ( QFileIconProvider : : Folder ) ) ;
2023-05-23 21:17:50 +01:00
pParent - > addAction ( pMenu - > menuAction ( ) ) ;
connect ( pMenu , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( OnMenuContextMenu ( const QPoint & ) ) ) ;
2022-09-29 17:28:48 +01:00
}
return pMenu ;
}
2023-05-23 21:17:50 +01:00
void CSbieView : : OnMenuContextMenu ( const QPoint & point )
{
QMenu * pMenu = ( QMenu * ) sender ( ) ;
QAction * pAction = pMenu - > actionAt ( point ) ;
if ( ! pAction ) return ;
QString LinkTarget = pAction - > data ( ) . toString ( ) ;
if ( ! LinkTarget . isEmpty ( ) ) {
auto pBoxPlus = m_CurSandBoxes . first ( ) . objectCast < CSandBoxPlus > ( ) ;
QStringList RunOptions = pBoxPlus - > GetTextList ( " RunCommand " , true ) ;
QString FoundPin ;
2023-06-17 19:46:51 +01:00
QString FileName = pBoxPlus - > GetCommandFile ( LinkTarget ) ;
2023-05-23 21:17:50 +01:00
foreach ( const QString & RunOption , RunOptions ) {
2023-07-19 20:15:18 +01:00
QVariantMap Entry = GetRunEntry ( RunOption ) ;
QString CmdFile = pBoxPlus - > GetCommandFile ( Entry [ " Command " ] . toString ( ) ) ;
2023-05-23 21:17:50 +01:00
if ( CmdFile . compare ( FileName , Qt : : CaseInsensitive ) = = 0 ) {
FoundPin = RunOption ;
break ;
}
}
m_pCtxPinToRun - > setChecked ( ! FoundPin . isEmpty ( ) ) ;
2023-07-19 20:15:18 +01:00
if ( FoundPin . isEmpty ( ) ) {
QVariantMap Entry ;
Entry [ " Name " ] = pAction - > text ( ) ;
2023-07-25 19:59:26 +01:00
Entry [ " Icon " ] = pAction - > property ( " Icon " ) . toString ( ) . replace ( pBoxPlus - > GetFileRoot ( ) , " %BoxRoot% " , Qt : : CaseInsensitive ) + " , " + pAction - > property ( " IconIndex " ) . toString ( ) ;
2023-07-19 20:15:18 +01:00
Entry [ " WorkingDir " ] = pBoxPlus - > MakeBoxCommand ( pAction - > property ( " WorkingDir " ) . toString ( ) ) ;
2023-08-01 07:16:50 +01:00
Entry [ " Command " ] = pBoxPlus - > MakeBoxCommand ( LinkTarget ) ;
2023-07-19 20:15:18 +01:00
m_pCtxPinToRun - > setData ( MakeRunEntry ( Entry ) ) ;
}
2023-05-23 21:17:50 +01:00
else
m_pCtxPinToRun - > setData ( FoundPin ) ;
2023-08-03 12:53:01 +01:00
m_pCtxMkLink - > setData ( pBoxPlus - > GetFullCommand ( LinkTarget ) ) ;
2023-08-03 19:17:52 +01:00
m_pCtxMkLink - > setProperty ( " Name " , pAction - > text ( ) ) ;
2023-08-03 12:53:01 +01:00
m_pCtxMkLink - > setProperty ( " Icon " , pBoxPlus - > GetFullCommand ( pAction - > property ( " Icon " ) . toString ( ) ) ) ;
m_pCtxMkLink - > setProperty ( " IconIndex " , pAction - > property ( " IconIndex " ) ) ;
m_pCtxMkLink - > setProperty ( " WorkingDir " , pBoxPlus - > GetFullCommand ( pAction - > property ( " WorkingDir " ) . toString ( ) ) ) ;
2023-05-23 21:17:50 +01:00
m_pCtxMenu - > exec ( QCursor : : pos ( ) ) ;
}
}
void CSbieView : : OnMenuContextAction ( )
{
QAction * pAction = ( QAction * ) sender ( ) ;
auto pBoxPlus = m_CurSandBoxes . first ( ) . objectCast < CSandBoxPlus > ( ) ;
if ( pAction = = m_pCtxPinToRun )
{
QString Link = m_pCtxPinToRun - > data ( ) . toString ( ) ;
if ( ! Link . isEmpty ( ) ) {
if ( m_pCtxPinToRun - > isChecked ( ) )
pBoxPlus - > InsertText ( " RunCommand " , Link ) ;
else
pBoxPlus - > DelValue ( " RunCommand " , Link ) ;
}
}
else if ( pAction = = m_pCtxMkLink )
{
QString LinkTarget = m_pCtxMkLink - > data ( ) . toString ( ) ;
2023-08-03 19:17:52 +01:00
QString LinkName = m_pCtxMkLink - > property ( " Name " ) . toString ( ) ;
2023-08-03 12:53:01 +01:00
QString Icon = m_pCtxMkLink - > property ( " Icon " ) . toString ( ) ;
int IconIndex = m_pCtxMkLink - > property ( " IconIndex " ) . toInt ( ) ;
QString WorkingDir = m_pCtxMkLink - > property ( " WorkingDir " ) . toString ( ) ;
2023-05-23 21:17:50 +01:00
QString BoxName = pBoxPlus - > GetName ( ) ;
2023-08-03 19:17:52 +01:00
CreateShortcutEx ( LinkTarget , BoxName , LinkName , Icon , IconIndex , WorkingDir ) ;
2023-05-23 21:17:50 +01:00
}
}
2022-09-29 17:28:48 +01:00
void CSbieView : : UpdateStartMenu ( CSandBoxPlus * pBoxEx )
{
foreach ( const CSandBoxPlus : : SLink & Link , pBoxEx - > GetStartMenu ( ) )
{
2023-02-07 19:17:29 +00:00
QMenu * pMenu = GetMenuFolder ( Link . Folder , m_pMenuRunStart , m_MenuFolders ) ;
2022-09-29 17:28:48 +01:00
QAction * pAction = pMenu - > addAction ( Link . Name , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2023-08-09 07:52:47 +01:00
QIcon Icon ;
2023-08-11 21:26:02 +01:00
if ( Link . IconIndex = = - 1 )
2023-08-09 07:52:47 +01:00
Icon = theGUI - > GetIcon ( " Internet " ) ;
2023-08-12 08:39:18 +01:00
else if ( ! Link . Icon . isEmpty ( ) ) {
if ( QFile : : exists ( Link . Icon ) )
Icon = LoadWindowsIcon ( Link . Icon , Link . IconIndex ) ;
else
Icon = theGUI - > GetIcon ( " File " ) ;
}
2023-08-09 07:52:47 +01:00
if ( Icon . isNull ( ) ) Icon = m_IconProvider . icon ( QFileInfo ( Link . Target ) ) ;
2023-01-29 16:10:11 +00:00
pAction - > setIcon ( Icon ) ;
2023-07-24 18:08:26 +01:00
QString Command ;
if ( Link . Target . contains ( " " ) )
Command = " \" " + Link . Target + " \" " ;
else
Command = Link . Target ;
if ( ! Link . Arguments . isEmpty ( ) )
Command + = " " + Link . Arguments ;
pAction - > setData ( Command ) ;
2023-08-09 07:52:47 +01:00
if ( ! Link . Icon . isEmpty ( ) ) pAction - > setProperty ( " Icon " , Link . Icon ) ;
2023-07-19 20:15:18 +01:00
pAction - > setProperty ( " IconIndex " , Link . IconIndex ) ;
2023-05-27 16:12:22 +01:00
pAction - > setProperty ( " WorkingDir " , Link . WorkDir ) ;
2022-09-29 17:28:48 +01:00
}
}
2021-10-15 16:39:43 +01:00
void CSbieView : : UpdateRunMenu ( const CSandBoxPtr & pBox )
{
2022-09-29 17:28:48 +01:00
CSandBoxPlus * pBoxEx = qobject_cast < CSandBoxPlus * > ( pBox . data ( ) ) ;
2021-10-15 16:39:43 +01:00
while ( m_iMenuRun < m_pMenuRun - > actions ( ) . count ( ) )
m_pMenuRun - > removeAction ( m_pMenuRun - > actions ( ) . at ( m_iMenuRun ) ) ;
2023-02-07 19:17:29 +00:00
while ( ! m_RunFolders . isEmpty ( ) )
m_RunFolders . take ( m_RunFolders . firstKey ( ) ) - > deleteLater ( ) ;
2021-10-15 16:39:43 +01:00
2022-09-29 17:28:48 +01:00
QStringList RunOptions = pBox - > GetTextList ( " RunCommand " , true , false , true ) ;
2021-10-15 16:39:43 +01:00
foreach ( const QString & RunOption , RunOptions )
{
2023-07-19 20:15:18 +01:00
QVariantMap Entry = GetRunEntry ( RunOption ) ;
2023-04-13 18:46:51 +01:00
2023-02-07 19:17:29 +00:00
QMenu * pMenu ;
2023-07-19 20:15:18 +01:00
StrPair FolderName = Split2 ( Entry [ " Name " ] . toString ( ) , " \\ " , true ) ;
2023-02-07 19:17:29 +00:00
if ( FolderName . second . isEmpty ( ) ) {
FolderName . second = FolderName . first ;
pMenu = m_pMenuRun ;
} else
2023-04-13 18:46:51 +01:00
pMenu = GetMenuFolder ( FolderName . first . replace ( " \\ " , " / " ) , m_pMenuRun , m_RunFolders ) ;
2023-08-03 19:17:52 +01:00
StrPair FileIndex = Split2 ( Entry [ " Icon " ] . toString ( ) , " , " , true ) ;
2023-08-09 07:52:47 +01:00
QString CmdFile = pBoxEx - > GetCommandFile ( Entry [ " Command " ] . toString ( ) ) ;
2023-08-03 19:17:52 +01:00
QString IconFile ;
2023-08-11 21:26:02 +01:00
int IconIndex ;
if ( FileIndex . second . isEmpty ( ) ) {
2023-08-09 07:52:47 +01:00
IconFile = CmdFile ;
2023-08-03 19:17:52 +01:00
IconIndex = FileIndex . first . toInt ( ) ;
}
else {
2023-08-11 21:26:02 +01:00
if ( FileIndex . first . isEmpty ( ) )
IconFile = CmdFile ;
else
IconFile = FileIndex . first . replace ( " %BoxRoot% " , pBoxEx - > GetFileRoot ( ) , Qt : : CaseInsensitive ) ;
2023-08-03 19:17:52 +01:00
IconIndex = FileIndex . second . toInt ( ) ;
}
2021-10-15 16:39:43 +01:00
2023-02-07 19:17:29 +00:00
QAction * pAction = pMenu - > addAction ( FolderName . second , this , SLOT ( OnSandBoxAction ( ) ) ) ;
2023-08-09 07:52:47 +01:00
QIcon Icon ;
2023-08-11 21:26:02 +01:00
if ( IconIndex = = - 1 )
2023-08-09 07:52:47 +01:00
Icon = theGUI - > GetIcon ( " Internet " ) ;
2023-08-12 08:39:18 +01:00
else if ( ! IconFile . isEmpty ( ) ) {
if ( QFile : : exists ( IconFile ) )
Icon = LoadWindowsIcon ( IconFile , IconIndex ) ;
else
Icon = theGUI - > GetIcon ( " File " ) ;
}
2023-08-09 07:52:47 +01:00
if ( Icon . isNull ( ) ) Icon = m_IconProvider . icon ( QFileInfo ( CmdFile ) ) ;
pAction - > setIcon ( Icon ) ;
2023-07-19 20:15:18 +01:00
pAction - > setData ( Entry [ " Command " ] . toString ( ) ) ;
2023-08-03 19:17:52 +01:00
pAction - > setProperty ( " Icon " , IconFile ) ;
pAction - > setProperty ( " IconIndex " , IconIndex ) ;
2023-07-19 20:15:18 +01:00
pAction - > setProperty ( " WorkingDir " , Entry [ " WorkingDir " ] ) ;
2021-10-15 16:39:43 +01:00
}
2022-09-29 17:28:48 +01:00
if ( ! m_pMenuRunStart )
return ;
while ( m_pMenuRunStart - > actions ( ) . count ( ) > 2 )
m_pMenuRunStart - > removeAction ( m_pMenuRunStart - > actions ( ) . at ( 2 ) ) ;
while ( ! m_MenuFolders . isEmpty ( ) )
m_MenuFolders . take ( m_MenuFolders . firstKey ( ) ) - > deleteLater ( ) ;
UpdateStartMenu ( pBoxEx ) ;
if ( m_pMenuRunStart - > actions ( ) . count ( ) > 2 )
m_pMenuRunMenu - > setMenu ( m_pMenuRunStart ) ;
else
m_pMenuRunMenu - > setMenu ( ( QMenu * ) NULL ) ;
2021-10-15 16:39:43 +01:00
}
void CSbieView : : SelectBox ( const QString & Name )
{
if ( m_pSbieModel - > Count ( ) = = 0 )
Refresh ( ) ;
QModelIndex Index = m_pSbieModel - > FindIndex ( Name ) ;
QModelIndex ModelIndex = m_pSortProxy - > mapFromSource ( Index ) ;
QModelIndex ModelL = m_pSortProxy - > index ( ModelIndex . row ( ) , 0 , ModelIndex . parent ( ) ) ;
QModelIndex ModelR = m_pSortProxy - > index ( ModelIndex . row ( ) , m_pSortProxy - > columnCount ( ) - 1 , ModelIndex . parent ( ) ) ;
QItemSelection SelectedItems ;
SelectedItems . append ( QItemSelectionRange ( ModelL , ModelR ) ) ;
m_pSbieTree - > setCurrentIndex ( ModelIndex ) ;
m_pSbieTree - > scrollTo ( ModelL ) ;
m_pSbieTree - > selectionModel ( ) - > select ( SelectedItems , QItemSelectionModel : : ClearAndSelect ) ;
}
void CSbieView : : PopUpMenu ( const QString & Name )
{
2022-07-09 10:46:07 +01:00
//SelectBox(Name);
CSandBoxPtr pBox = theAPI - > GetBoxByName ( Name ) ;
2022-07-12 08:35:00 +01:00
m_CurSandBoxes = QList < CSandBoxPtr > ( ) < < pBox ;
2022-07-10 17:28:10 +01:00
if ( pBox . isNull ( ) | | ! UpdateMenu ( false , pBox ) ) return ;
2022-07-12 17:23:28 +01:00
m_pMenuTray - > exec ( QCursor : : pos ( ) ) ;
//m_pMenuTray->popup(QCursor::pos());
2021-10-15 16:39:43 +01:00
//OnMenu(QCursor::pos());
}
2022-07-09 10:46:07 +01:00
QMenu * CSbieView : : GetMenu ( const QString & Name )
{
2022-07-12 08:35:00 +01:00
//SelectBox(Name);
2022-07-09 10:46:07 +01:00
CSandBoxPtr pBox = theAPI - > GetBoxByName ( Name ) ;
2022-07-12 08:35:00 +01:00
m_CurSandBoxes = QList < CSandBoxPtr > ( ) < < pBox ;
2022-07-09 10:46:07 +01:00
if ( pBox . isNull ( ) ) return NULL ;
2022-07-10 17:28:10 +01:00
UpdateMenu ( false , pBox ) ;
2022-07-13 14:42:33 +01:00
return m_pMenuBox ;
2022-07-09 10:46:07 +01:00
}
2021-10-15 16:39:43 +01:00
void CSbieView : : ShowOptions ( const QString & Name )
{
QModelIndex Index = m_pSbieModel - > FindIndex ( Name ) ;
QModelIndex ModelIndex = m_pSortProxy - > mapFromSource ( Index ) ;
OnDoubleClicked ( ModelIndex ) ;
}
void CSbieView : : ChangeExpand ( const QModelIndex & index , bool bExpand )
{
2023-04-20 20:52:30 +01:00
if ( m_HoldExpand )
return ;
2021-10-15 16:39:43 +01:00
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( index ) ;
if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eProcess )
return ;
QString Name ;
if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eGroup )
Name = m_pSbieModel - > GetID ( ModelIndex ) . toString ( ) ;
else if ( m_pSbieModel - > GetType ( ModelIndex ) = = CSbieModel : : eBox )
Name = m_pSbieModel - > GetSandBox ( ModelIndex ) - > GetName ( ) ;
if ( bExpand )
m_Collapsed . remove ( Name ) ;
else
m_Collapsed . insert ( Name ) ;
2021-12-23 15:28:14 +00:00
2023-05-29 13:11:34 +01:00
//QMap<QString, QStringList> Collapsed;
//Collapsed.insert("", SetToList(m_Collapsed));
//theAPI->GetUserSettings()->SetTextMap("CollapsedBoxes", Collapsed);
2021-12-23 15:28:14 +00:00
2023-05-29 13:11:34 +01:00
QString Collapsed = SetToList ( m_Collapsed ) . join ( " , " ) ;
theConf - > SetValue ( " UIConfig/BoxCollapsedView " , Collapsed ) ;
2021-10-15 16:39:43 +01:00
}
void CSbieView : : ReloadUserConfig ( )
{
2023-04-20 20:52:30 +01:00
if ( ! theAPI - > IsConnected ( ) )
return ;
2021-10-15 16:39:43 +01:00
2023-04-20 20:52:30 +01:00
m_Groups = theAPI - > GetUserSettings ( ) - > GetTextMap ( " BoxGrouping " ) ;
if ( m_Groups . isEmpty ( ) ) { // try legacy entries
QString Grouping = theConf - > GetString ( " UIConfig/BoxDisplayOrder " ) ;
if ( Grouping . isEmpty ( ) )
Grouping = theAPI - > GetUserSettings ( ) - > GetText ( " BoxDisplayOrder " ) ;
CSbieView__ParseGroup ( Grouping , m_Groups ) ;
}
2021-10-15 16:39:43 +01:00
2022-07-12 17:23:28 +01:00
UpdateMoveMenu ( ) ;
2021-10-15 16:39:43 +01:00
2023-05-29 13:11:34 +01:00
//QMap<QString, QStringList> Collapsed = theAPI->GetUserSettings()->GetTextMap("CollapsedBoxes");
//m_Collapsed = ListToSet(Collapsed[""]);
//if (m_Collapsed.isEmpty()) { // try legacy entries
2023-04-20 20:52:30 +01:00
QString Collapsed = theConf - > GetString ( " UIConfig/BoxCollapsedView " ) ;
2023-05-29 13:11:34 +01:00
//if (Collapsed.isEmpty())
// Collapsed = theAPI->GetUserSettings()->GetText("BoxCollapsedView");
2023-04-20 20:52:30 +01:00
m_Collapsed = ListToSet ( SplitStr ( Collapsed , " , " ) ) ;
2023-05-29 13:11:34 +01:00
//}
2022-09-20 04:40:28 +01:00
ClearUserUIConfig ( ) ;
}
2022-09-21 10:54:58 +01:00
void CSbieView : : ClearUserUIConfig ( const QMap < QString , CSandBoxPtr > AllBoxes )
{
2022-09-20 04:40:28 +01:00
if ( ! AllBoxes . isEmpty ( ) )
{
2022-09-21 10:54:58 +01:00
for ( auto I = m_Groups . begin ( ) ; I ! = m_Groups . end ( ) ; + + I )
{
2022-09-20 04:40:28 +01:00
QStringList Temp = I . value ( ) ;
foreach ( QString Name , I . value ( ) ) {
if ( AllBoxes . contains ( Name . toLower ( ) ) | | m_Groups . keys ( ) . contains ( Name ) )
continue ;
Temp . removeOne ( Name ) ;
}
I . value ( ) = Temp ;
}
}
QSet < QString > Temp = m_Collapsed ;
foreach ( QString Name , m_Collapsed )
{
2022-09-29 17:28:48 +01:00
if ( m_Groups . end ( ) = = std : : find_if ( m_Groups . begin ( ) , m_Groups . end ( ) ,
2022-09-20 04:40:28 +01:00
[ Name ] ( const QStringList & item ) - > int { return item . contains ( Name ) ; } ) )
Temp . remove ( Name ) ;
}
m_Collapsed = Temp ;
2021-10-15 16:39:43 +01:00
}
2023-05-29 13:11:34 +01:00
void CSbieView : : SaveBoxGrouping ( )
2021-10-15 16:39:43 +01:00
{
2023-04-20 20:52:30 +01:00
if ( ! theAPI - > IsConnected ( ) )
return ;
2022-09-29 17:28:48 +01:00
2023-04-20 20:52:30 +01:00
theAPI - > GetUserSettings ( ) - > SetRefreshOnChange ( false ) ;
2022-09-29 17:28:48 +01:00
2023-04-20 20:52:30 +01:00
auto Groups = m_Groups ;
// clean up non existing entries
for ( auto I = Groups . begin ( ) ; I ! = Groups . end ( ) ; + + I ) {
foreach ( const QString & Name , I . value ( ) ) {
if ( theAPI - > GetBoxByName ( Name ) . isNull ( ) & & ! Groups . contains ( Name ) )
I - > removeAll ( Name ) ;
}
2022-09-29 17:28:48 +01:00
}
2023-04-20 20:52:30 +01:00
theAPI - > GetUserSettings ( ) - > SetTextMap ( " BoxGrouping " , Groups ) ;
theAPI - > GetUserSettings ( ) - > SetRefreshOnChange ( true ) ;
theAPI - > CommitIniChanges ( ) ;
2022-04-16 14:01:01 +01:00
}
2022-06-04 20:07:04 +01:00
void CSbieView : : OnMoveItem ( const QString & Name , const QString & To , int row )
2022-04-16 14:01:01 +01:00
{
2022-06-04 20:07:04 +01:00
QModelIndex index ;
if ( ! To . isEmpty ( ) ) { // only groups can be parents so add the group marker "!"
QModelIndex index0 = m_pSbieModel - > FindIndex ( " ! " + To ) ;
2022-09-29 17:28:48 +01:00
index = m_pSbieModel - > index ( row , 0 , index0 ) ;
2022-06-04 20:07:04 +01:00
} else
index = m_pSbieModel - > index ( row , 0 ) ;
QModelIndex index2 = m_pSortProxy - > mapFromSource ( index ) ;
int row2 = index2 . row ( ) ;
2022-07-10 20:44:24 +01:00
if ( MoveItem ( Name , To , row2 ) ) {
m_pSbieModel - > Clear ( ) ; //todo improve that
Refresh ( ) ;
}
2022-04-16 14:01:01 +01:00
2022-07-12 17:23:28 +01:00
UpdateMoveMenu ( ) ;
2022-04-16 14:01:01 +01:00
2023-05-29 13:11:34 +01:00
SaveBoxGrouping ( ) ;
2022-04-16 14:01:01 +01:00
}
void CSbieView : : OnRemoveItem ( )
{
2022-09-02 09:05:25 +01:00
UpdateMenu ( ) ;
2022-07-12 08:35:00 +01:00
if ( ! m_CurProcesses . isEmpty ( ) )
OnProcessAction ( m_pMenuTerminate , m_CurProcesses ) ;
else if ( ! m_CurSandBoxes . isEmpty ( ) )
OnSandBoxAction ( m_pMenuRemove , m_CurSandBoxes ) ;
2022-04-16 14:01:01 +01:00
else if ( ! GetSelectedGroups ( ) . isEmpty ( ) )
OnGroupAction ( m_pDelGroupe ) ;
2022-06-13 19:49:53 +01:00
}