2021-10-16 16:19:51 +01:00
# include "stdafx.h"
# include "SettingsWindow.h"
# include "SandMan.h"
# include "../MiscHelpers/Common/Settings.h"
# include "../MiscHelpers/Common/Common.h"
# include "Helpers/WinAdmin.h"
# include "../QSbieAPI/Sandboxie/SbieTemplates.h"
# include "../QSbieAPI/SbieUtils.h"
2022-05-29 07:07:17 +01:00
# include "OptionsWindow.h"
2022-08-11 23:09:35 +01:00
# include "../OnlineUpdater.h"
2021-10-16 16:19:51 +01:00
QSize CustomTabStyle : : sizeFromContents ( ContentsType type , const QStyleOption * option , const QSize & size , const QWidget * widget ) const {
QSize s = QProxyStyle : : sizeFromContents ( type , option , size , widget ) ;
2022-08-20 13:48:18 +01:00
if ( type = = QStyle : : CT_TabBarTab & & widget - > property ( " isSidebar " ) . toBool ( ) ) {
2021-10-16 16:19:51 +01:00
s . transpose ( ) ;
2022-08-10 19:14:37 +01:00
if ( theGUI - > m_FusionTheme )
2021-10-16 16:19:51 +01:00
s . setHeight ( s . height ( ) * 13 / 10 ) ;
else
s . setHeight ( s . height ( ) * 15 / 10 ) ;
s . setWidth ( s . width ( ) * 11 / 10 ) ; // for the the icon
}
return s ;
}
void CustomTabStyle : : drawControl ( ControlElement element , const QStyleOption * option , QPainter * painter , const QWidget * widget ) const {
2022-08-20 13:48:18 +01:00
if ( element = = CE_TabBarTabLabel & & widget - > property ( " isSidebar " ) . toBool ( ) ) {
2021-10-16 16:19:51 +01:00
if ( const QStyleOptionTab * tab = qstyleoption_cast < const QStyleOptionTab * > ( option ) ) {
QStyleOptionTab opt ( * tab ) ;
opt . shape = QTabBar : : RoundedNorth ;
//opt.iconSize = QSize(32, 32);
opt . iconSize = QSize ( 24 , 24 ) ;
QProxyStyle : : drawControl ( element , & opt , painter , widget ) ;
return ;
}
}
QProxyStyle : : drawControl ( element , option , painter , widget ) ;
}
2022-08-10 19:14:37 +01:00
void FixTriStateBoxPallete ( QWidget * pWidget )
{
if ( QApplication : : style ( ) - > objectName ( ) = = " windows " ) {
//
// the built in "windows" theme of Qt does not properly renderd PartiallyChecked
// checkboxes, to remedi this issue we connect to the stateChanged slot
// and change the pattern to improve the rendering.
//
foreach ( QCheckBox * pCheck , pWidget - > findChildren < QCheckBox * > ( ) ) {
QObject : : connect ( pCheck , & QCheckBox : : stateChanged , [ pCheck ] ( int state ) {
if ( pCheck - > isTristate ( ) ) {
QPalette palette = QApplication : : palette ( ) ;
if ( state = = Qt : : PartiallyChecked )
palette . setColor ( QPalette : : Base , Qt : : darkGray ) ;
pCheck - > setPalette ( palette ) ;
}
} ) ;
}
}
}
2021-10-16 16:19:51 +01:00
int CSettingsWindow__Chk2Int ( Qt : : CheckState state )
{
switch ( state ) {
case Qt : : Unchecked : return 0 ;
case Qt : : Checked : return 1 ;
default :
case Qt : : PartiallyChecked : return 2 ;
}
}
Qt : : CheckState CSettingsWindow__Int2Chk ( int state )
{
switch ( state ) {
case 0 : return Qt : : Unchecked ;
case 1 : return Qt : : Checked ;
default :
case 2 : return Qt : : PartiallyChecked ;
}
}
quint32 g_FeatureFlags = 0 ;
2022-01-13 22:52:58 +00:00
QByteArray g_Certificate ;
SCertInfo g_CertInfo = { 0 } ;
2022-08-15 12:18:26 +01:00
CSettingsWindow : : CSettingsWindow ( QWidget * parent )
: CConfigDialog ( parent )
2021-10-16 16:19:51 +01:00
{
Qt : : WindowFlags flags = windowFlags ( ) ;
flags | = Qt : : CustomizeWindowHint ;
//flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint;
//flags &= ~Qt::WindowMinMaxButtonsHint;
flags | = Qt : : WindowMinimizeButtonHint ;
//flags &= ~Qt::WindowCloseButtonHint;
setWindowFlags ( flags ) ;
bool bAlwaysOnTop = theConf - > GetBool ( " Options/AlwaysOnTop " , false ) ;
this - > setWindowFlag ( Qt : : WindowStaysOnTopHint , bAlwaysOnTop ) ;
2022-07-29 09:24:32 +01:00
ui . setupUi ( this ) ;
2022-07-30 09:18:55 +01:00
this - > setWindowTitle ( tr ( " Sandboxie Plus - Global Settings " ) ) ;
2022-07-29 09:24:32 +01:00
if ( theConf - > GetBool ( " Options/AltRowColors " , false ) ) {
ui . treeWarnProgs - > setAlternatingRowColors ( true ) ;
ui . treeCompat - > setAlternatingRowColors ( true ) ;
}
2021-10-16 16:19:51 +01:00
2022-08-10 19:14:37 +01:00
FixTriStateBoxPallete ( this ) ;
2021-10-16 16:19:51 +01:00
ui . tabs - > setTabPosition ( QTabWidget : : West ) ;
ui . tabs - > tabBar ( ) - > setStyle ( new CustomTabStyle ( ui . tabs - > tabBar ( ) - > style ( ) ) ) ;
2022-08-20 13:48:18 +01:00
ui . tabs - > tabBar ( ) - > setProperty ( " isSidebar " , true ) ;
2021-10-16 16:19:51 +01:00
2022-07-09 10:46:07 +01:00
ui . tabs - > setTabIcon ( eOptions , CSandMan : : GetIcon ( " Options " ) ) ;
ui . tabs - > setTabIcon ( eShell , CSandMan : : GetIcon ( " Shell " ) ) ;
ui . tabs - > setTabIcon ( eGuiConfig , CSandMan : : GetIcon ( " GUI " ) ) ;
ui . tabs - > setTabIcon ( eAdvanced , CSandMan : : GetIcon ( " Advanced " ) ) ;
2022-09-08 07:24:47 +01:00
ui . tabs - > setTabIcon ( eProgCtrl , CSandMan : : GetIcon ( " Alarm " ) ) ;
2022-07-09 10:46:07 +01:00
ui . tabs - > setTabIcon ( eConfigLock , CSandMan : : GetIcon ( " Lock " ) ) ;
ui . tabs - > setTabIcon ( eSoftCompat , CSandMan : : GetIcon ( " Compatibility " ) ) ;
ui . tabs - > setTabIcon ( eEditIni , CSandMan : : GetIcon ( " EditIni " ) ) ;
ui . tabs - > setTabIcon ( eSupport , CSandMan : : GetIcon ( " Support " ) ) ;
2021-10-16 16:19:51 +01:00
2022-08-15 12:18:26 +01:00
//if(theConf->GetInt("Options/ViewMode", 1) != 1 && (QApplication::keyboardModifiers() & Qt::ControlModifier) == 0)
// ui.tabs->removeTab(eEditIni);
2021-10-16 16:19:51 +01:00
ui . tabs - > setCurrentIndex ( 0 ) ;
ui . uiLang - > addItem ( tr ( " Auto Detection " ) , " " ) ;
2022-01-14 17:00:23 +00:00
ui . uiLang - > addItem ( tr ( " No Translation " ) , " native " ) ;
2021-10-16 16:19:51 +01:00
QDir langDir ( QApplication : : applicationDirPath ( ) + " /translations/ " ) ;
foreach ( const QString & langFile , langDir . entryList ( QStringList ( " sandman_*.qm " ) , QDir : : Files ) )
{
QString Code = langFile . mid ( 8 , langFile . length ( ) - 8 - 3 ) ;
QLocale Locale ( Code ) ;
QString Lang = Locale . nativeLanguageName ( ) ;
ui . uiLang - > addItem ( Lang , Code ) ;
}
2022-07-09 10:46:07 +01:00
ui . uiLang - > setCurrentIndex ( ui . uiLang - > findData ( theConf - > GetString ( " Options/UiLanguage " ) ) ) ;
2021-10-16 16:19:51 +01:00
ui . cmbSysTray - > addItem ( tr ( " Don't show any icon " ) ) ;
ui . cmbSysTray - > addItem ( tr ( " Show Plus icon " ) ) ;
ui . cmbSysTray - > addItem ( tr ( " Show Classic icon " ) ) ;
2022-02-05 14:09:53 +00:00
ui . cmbTrayBoxes - > addItem ( tr ( " All Boxes " ) ) ;
ui . cmbTrayBoxes - > addItem ( tr ( " Active + Pinned " ) ) ;
ui . cmbTrayBoxes - > addItem ( tr ( " Pinned Only " ) ) ;
2022-07-09 10:46:07 +01:00
ui . cmbDPI - > addItem ( tr ( " None " ) , 0 ) ;
ui . cmbDPI - > addItem ( tr ( " Native " ) , 1 ) ;
ui . cmbDPI - > addItem ( tr ( " Qt " ) , 2 ) ;
int FontScales [ ] = { 75 , 100 , 125 , 150 , 175 , 200 , 225 , 250 , 275 , 300 , 350 , 400 , 0 } ;
for ( int * pFontScales = FontScales ; * pFontScales ! = 0 ; pFontScales + + )
2022-07-20 19:54:09 +01:00
ui . cmbFontScale - > addItem ( tr ( " %1 " ) . arg ( * pFontScales ) , * pFontScales ) ;
2021-10-16 16:19:51 +01:00
2022-07-01 07:19:30 +01:00
QSettings settings ( " HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows NT \\ CurrentVersion " , QSettings : : NativeFormat ) ;
if ( settings . value ( " CurrentBuild " ) . toInt ( ) > = 22000 ) { // Windows 11
QCheckBox * SecretCheckBox = new CSecretCheckBox ( ui . chkShellMenu - > text ( ) ) ;
( ( QGridLayout * ) ( ( QWidget * ) ui . chkShellMenu - > parent ( ) ) - > layout ( ) ) - > replaceWidget ( ui . chkShellMenu , SecretCheckBox ) ;
ui . chkShellMenu - > deleteLater ( ) ;
ui . chkShellMenu = SecretCheckBox ;
}
2021-10-16 16:19:51 +01:00
LoadSettings ( ) ;
2022-07-01 07:19:30 +01:00
2022-07-09 10:46:07 +01:00
connect ( ui . uiLang , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
connect ( ui . cmbDPI , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
connect ( ui . chkDarkTheme , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2022-08-10 19:14:37 +01:00
connect ( ui . chkFusionTheme , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2022-07-29 09:24:32 +01:00
connect ( ui . chkAltRows , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2022-07-09 10:46:07 +01:00
connect ( ui . chkBackground , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
connect ( ui . chkLargeIcons , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
connect ( ui . chkNoIcons , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2022-07-09 23:06:11 +01:00
//connect(ui.chkOptTree, SIGNAL(stateChanged(int)), this, SLOT(OnChangeGUI()));
2022-07-10 17:28:10 +01:00
connect ( ui . chkColorIcons , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2022-07-09 10:46:07 +01:00
connect ( ui . cmbFontScale , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2022-07-20 19:54:09 +01:00
connect ( ui . cmbFontScale , SIGNAL ( currentTextChanged ( const QString & ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2022-07-09 10:46:07 +01:00
m_bRebuildUI = false ;
2022-07-01 07:19:30 +01:00
2021-10-16 16:19:51 +01:00
connect ( ui . cmbSysTray , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( OnChange ( ) ) ) ;
2022-02-05 14:09:53 +00:00
connect ( ui . cmbTrayBoxes , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( OnChange ( ) ) ) ;
2022-07-10 17:28:10 +01:00
connect ( ui . chkCompactTray , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChangeGUI ( ) ) ) ;
2021-10-16 16:19:51 +01:00
m_FeaturesChanged = false ;
connect ( ui . chkWFP , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnFeaturesChanged ( ) ) ) ;
2021-11-13 08:28:32 +00:00
connect ( ui . chkObjCb , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnFeaturesChanged ( ) ) ) ;
2022-02-13 11:55:52 +00:00
//connect(ui.chkWin32k, SIGNAL(stateChanged(int)), this, SLOT(OnFeaturesChanged()));
2022-08-15 12:18:26 +01:00
if ( settings . value ( " CurrentBuild " ) . toInt ( ) < 14393 ) // Windows 10 RS1 and later
ui . chkWin32k - > setEnabled ( false ) ;
2021-10-16 16:19:51 +01:00
m_WarnProgsChanged = false ;
connect ( ui . chkPassRequired , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChange ( ) ) ) ;
connect ( ui . btnSetPassword , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnSetPassword ( ) ) ) ;
connect ( ui . chkStartBlock , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnWarnChanged ( ) ) ) ;
connect ( ui . chkStartBlockMsg , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnWarnChanged ( ) ) ) ;
connect ( ui . btnAddWarnProg , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnAddWarnProg ( ) ) ) ;
connect ( ui . btnAddWarnFolder , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnAddWarnFolder ( ) ) ) ;
connect ( ui . btnDelWarnProg , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnDelWarnProg ( ) ) ) ;
connect ( ui . btnBrowse , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnBrowse ( ) ) ) ;
connect ( ui . chkAutoRoot , SIGNAL ( stateChanged ( int ) ) , this , SLOT ( OnChange ( ) ) ) ;
connect ( ui . btnAddCompat , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnAddCompat ( ) ) ) ;
connect ( ui . btnDelCompat , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnDelCompat ( ) ) ) ;
m_CompatLoaded = 0 ;
m_CompatChanged = false ;
2022-03-12 07:23:02 +00:00
ui . chkNoCompat - > setChecked ( ! theConf - > GetBool ( " Options/AutoRunSoftCompat " , true ) ) ;
2021-10-16 16:19:51 +01:00
connect ( ui . treeCompat , SIGNAL ( itemClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( OnTemplateClicked ( QTreeWidgetItem * , int ) ) ) ;
2022-05-29 07:07:17 +01:00
connect ( ui . treeCompat , SIGNAL ( itemDoubleClicked ( QTreeWidgetItem * , int ) ) , this , SLOT ( OnTemplateDoubleClicked ( QTreeWidgetItem * , int ) ) ) ;
2021-10-16 16:19:51 +01:00
connect ( ui . lblSupport , SIGNAL ( linkActivated ( const QString & ) ) , theGUI , SLOT ( OpenUrl ( const QString & ) ) ) ;
connect ( ui . lblSupportCert , SIGNAL ( linkActivated ( const QString & ) ) , theGUI , SLOT ( OpenUrl ( const QString & ) ) ) ;
2022-01-13 22:52:58 +00:00
connect ( ui . lblCertExp , SIGNAL ( linkActivated ( const QString & ) ) , theGUI , SLOT ( OpenUrl ( const QString & ) ) ) ;
2021-10-16 16:19:51 +01:00
m_CertChanged = false ;
connect ( ui . txtCertificate , SIGNAL ( textChanged ( ) ) , this , SLOT ( CertChanged ( ) ) ) ;
2022-01-13 22:52:58 +00:00
connect ( theGUI , SIGNAL ( CertUpdated ( ) ) , this , SLOT ( UpdateCert ( ) ) ) ;
2021-10-16 16:19:51 +01:00
2022-05-08 13:41:49 +01:00
ui . txtCertificate - > setPlaceholderText (
" NAME: User Name \n "
" LEVEL: ULTIMATE \n "
" DATE: dd.mm.yyyy \n "
" UPDATEKEY: 00000000000000000000000000000000 \n "
" SIGNATURE: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== "
) ;
2022-08-11 23:09:35 +01:00
connect ( ui . lblCurrent , SIGNAL ( linkActivated ( const QString & ) ) , this , SLOT ( OnUpdate ( const QString & ) ) ) ;
connect ( ui . lblRelease , SIGNAL ( linkActivated ( const QString & ) ) , this , SLOT ( OnUpdate ( const QString & ) ) ) ;
connect ( ui . lblPreview , SIGNAL ( linkActivated ( const QString & ) ) , this , SLOT ( OnUpdate ( const QString & ) ) ) ;
2021-10-16 16:19:51 +01:00
connect ( ui . tabs , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( OnTab ( ) ) ) ;
2022-01-13 22:52:58 +00:00
// edit
connect ( ui . btnEditIni , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnEditIni ( ) ) ) ;
connect ( ui . btnSaveIni , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnSaveIni ( ) ) ) ;
connect ( ui . btnCancelEdit , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnCancelEdit ( ) ) ) ;
//connect(ui.txtIniSection, SIGNAL(textChanged()), this, SLOT(OnOptChanged()));
2021-10-16 16:19:51 +01:00
connect ( ui . buttonBox - > button ( QDialogButtonBox : : Ok ) , SIGNAL ( clicked ( bool ) ) , this , SLOT ( ok ( ) ) ) ;
connect ( ui . buttonBox - > button ( QDialogButtonBox : : Apply ) , SIGNAL ( clicked ( bool ) ) , this , SLOT ( apply ( ) ) ) ;
connect ( ui . buttonBox , SIGNAL ( rejected ( ) ) , this , SLOT ( reject ( ) ) ) ;
2022-08-15 12:18:26 +01:00
this - > installEventFilter ( this ) ; // prevent enter from closing the dialog
2021-10-16 16:19:51 +01:00
restoreGeometry ( theConf - > GetBlob ( " SettingsWindow/Window_Geometry " ) ) ;
2022-08-15 12:18:26 +01:00
int iViewMode = theConf - > GetInt ( " Options/ViewMode " , 1 ) ;
int iOptionTree = theConf - > GetInt ( " Options/OptionTree " , 2 ) ;
if ( iOptionTree = = 2 )
iOptionTree = iViewMode = = 2 ? 1 : 0 ;
if ( iOptionTree )
OnSetTree ( ) ;
else {
2022-08-15 18:32:38 +01:00
QWidget * pSearch = AddConfigSearch ( ui . tabs ) ;
ui . horizontalLayout - > insertWidget ( 0 , pSearch ) ;
QTimer : : singleShot ( 0 , [ this ] ( ) {
m_pSearch - > setMaximumWidth ( m_pTabs - > tabBar ( ) - > width ( ) ) ;
} ) ;
2022-08-15 12:18:26 +01:00
}
2022-08-20 19:11:27 +01:00
m_pSearch - > setPlaceholderText ( tr ( " Search for settings " ) ) ;
2022-08-15 12:18:26 +01:00
}
void CSettingsWindow : : OnSetTree ( )
{
if ( ! ui . tabs ) return ;
QWidget * pAltView = ConvertToTree ( ui . tabs ) ;
ui . verticalLayout - > replaceWidget ( ui . tabs , pAltView ) ;
ui . tabs - > deleteLater ( ) ;
ui . tabs = NULL ;
2021-10-16 16:19:51 +01:00
}
CSettingsWindow : : ~ CSettingsWindow ( )
{
theConf - > SetBlob ( " SettingsWindow/Window_Geometry " , saveGeometry ( ) ) ;
}
2022-07-10 17:28:10 +01:00
void CSettingsWindow : : showTab ( int Tab , bool bExclusive )
2021-10-16 16:19:51 +01:00
{
2022-08-15 12:18:26 +01:00
QWidget * pWidget ;
if ( ui . tabs ) {
ui . tabs - > setCurrentIndex ( Tab ) ;
pWidget = ui . tabs - > currentWidget ( ) ;
}
else {
m_pStack - > setCurrentIndex ( Tab ) ;
pWidget = m_pStack - > currentWidget ( ) ;
}
2022-08-15 10:58:39 +01:00
2022-08-15 12:18:26 +01:00
if ( pWidget = = ui . tabCompat )
2022-07-09 10:46:07 +01:00
m_CompatLoaded = 2 ;
2022-08-15 12:18:26 +01:00
if ( pWidget = = ui . tabSupport )
2022-07-09 10:46:07 +01:00
ui . chkNoCheck - > setVisible ( true ) ;
2021-10-16 16:19:51 +01:00
2022-08-15 12:18:26 +01:00
if ( bExclusive ) {
if ( ui . tabs )
ui . tabs - > tabBar ( ) - > setVisible ( false ) ;
else {
m_pTree - > setVisible ( false ) ;
m_pSearch - > setVisible ( false ) ;
}
}
2022-07-10 17:28:10 +01:00
2022-01-14 13:06:01 +00:00
SafeShow ( this ) ;
2022-01-13 22:52:58 +00:00
}
2021-10-16 16:19:51 +01:00
void CSettingsWindow : : closeEvent ( QCloseEvent * e )
{
emit Closed ( ) ;
this - > deleteLater ( ) ;
}
2022-08-15 12:18:26 +01:00
bool CSettingsWindow : : eventFilter ( QObject * source , QEvent * event )
{
2022-08-20 21:32:51 +01:00
//if (event->type() == QEvent::KeyPress && ((QKeyEvent*)event)->key() == Qt::Key_Escape
// && ((QKeyEvent*)event)->modifiers() == Qt::NoModifier)
//{
// return true; // cancel event
//}
2022-08-15 12:18:26 +01:00
if ( event - > type ( ) = = QEvent : : KeyPress & & ( ( ( QKeyEvent * ) event ) - > key ( ) = = Qt : : Key_Enter | | ( ( QKeyEvent * ) event ) - > key ( ) = = Qt : : Key_Return )
2022-08-20 21:32:51 +01:00
& & ( ( ( QKeyEvent * ) event ) - > modifiers ( ) = = Qt : : NoModifier | | ( ( QKeyEvent * ) event ) - > modifiers ( ) = = Qt : : KeypadModifier ) )
2022-08-15 12:18:26 +01:00
{
return true ; // cancel event
}
return QDialog : : eventFilter ( source , event ) ;
}
2021-10-16 16:19:51 +01:00
Qt : : CheckState CSettingsWindow__IsContextMenu ( )
{
2022-05-15 12:26:22 +01:00
QSettings settings ( " HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Classes \\ PackagedCom \\ Package " , QSettings : : NativeFormat ) ;
foreach ( const QString & Key , settings . childGroups ( ) ) {
if ( Key . indexOf ( " SandboxieShell " ) = = 0 )
return Qt : : Checked ;
}
2021-10-16 16:19:51 +01:00
QString cmd = CSbieUtils : : GetContextMenuStartCmd ( ) ;
2022-02-04 21:08:25 +00:00
if ( cmd . contains ( " SandMan.exe " , Qt : : CaseInsensitive ) )
2021-10-16 16:19:51 +01:00
return Qt : : Checked ; // set up and sandman
if ( ! cmd . isEmpty ( ) ) // ... probably sbiectrl.exe
return Qt : : PartiallyChecked ;
return Qt : : Unchecked ; // not set up
}
2022-07-01 07:19:30 +01:00
void CSettingsWindow__AddContextMenu ( bool bAlwaysClassic )
2022-02-04 21:08:25 +00:00
{
2022-05-15 12:26:22 +01:00
QSettings settings ( " HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows NT \\ CurrentVersion " , QSettings : : NativeFormat ) ;
2022-07-01 07:19:30 +01:00
if ( settings . value ( " CurrentBuild " ) . toInt ( ) > = 22000 & & ! bAlwaysClassic ) // Windows 11
2022-05-15 12:26:22 +01:00
{
QProcess Proc ;
2022-08-10 19:14:37 +01:00
Proc . setWorkingDirectory ( QCoreApplication : : applicationDirPath ( ) ) ;
Proc . execute ( " rundll32.exe " , QStringList ( ) < < " SbieShellExt.dll,RegisterPackage " ) ;
2022-05-15 12:26:22 +01:00
Proc . waitForFinished ( ) ;
return ;
}
2022-02-04 21:08:25 +00:00
CSbieUtils : : AddContextMenu ( QApplication : : applicationDirPath ( ) . replace ( " / " , " \\ " ) + " \\ SandMan.exe " ,
2022-02-13 12:24:16 +00:00
CSettingsWindow : : tr ( " Run &Sandboxed " ) , //CSettingsWindow::tr("Explore &Sandboxed"),
2022-02-04 21:08:25 +00:00
QApplication : : applicationDirPath ( ) . replace ( " / " , " \\ " ) + " \\ Start.exe " ) ;
}
2022-05-15 12:26:22 +01:00
void CSettingsWindow__RemoveContextMenu ( )
{
QSettings settings ( " HKEY_LOCAL_MACHINE \\ SOFTWARE \\ Microsoft \\ Windows NT \\ CurrentVersion " , QSettings : : NativeFormat ) ;
2022-05-28 21:24:40 +01:00
if ( settings . value ( " CurrentBuild " ) . toInt ( ) > = 22000 ) // Windows 11
2022-05-15 12:26:22 +01:00
{
QProcess Proc ;
2022-08-10 19:14:37 +01:00
Proc . setWorkingDirectory ( QCoreApplication : : applicationDirPath ( ) ) ;
Proc . execute ( " rundll32.exe " , QStringList ( ) < < " SbieShellExt.dll,RemovePackage " ) ;
2022-05-15 12:26:22 +01:00
Proc . waitForFinished ( ) ;
}
CSbieUtils : : RemoveContextMenu ( ) ;
}
void CSettingsWindow__AddBrowserIcon ( )
{
QString Path = QStandardPaths : : writableLocation ( QStandardPaths : : DesktopLocation ) . replace ( " / " , " \\ " ) ;
Path + = " \\ " + CSettingsWindow : : tr ( " Sandboxed Web Browser " ) + " .lnk " ;
CSbieUtils : : CreateShortcut ( theAPI , Path , " " , " " , " default_browser " ) ;
}
2021-10-16 16:19:51 +01:00
void CSettingsWindow : : LoadSettings ( )
{
ui . uiLang - > setCurrentIndex ( ui . uiLang - > findData ( theConf - > GetString ( " Options/UiLanguage " ) ) ) ;
ui . chkAutoStart - > setChecked ( IsAutorunEnabled ( ) ) ;
2022-01-14 17:58:25 +00:00
if ( theAPI - > IsConnected ( ) ) {
if ( theAPI - > GetUserSettings ( ) - > GetBool ( " SbieCtrl_EnableAutoStart " , true ) ) {
if ( theAPI - > GetUserSettings ( ) - > GetText ( " SbieCtrl_AutoStartAgent " , " " ) ! = " SandMan.exe " )
ui . chkSvcStart - > setCheckState ( Qt : : PartiallyChecked ) ;
else
ui . chkSvcStart - > setChecked ( true ) ;
}
2021-10-16 16:19:51 +01:00
else
2022-01-14 17:58:25 +00:00
ui . chkSvcStart - > setChecked ( false ) ;
}
else {
ui . chkSvcStart - > setEnabled ( false ) ;
}
2021-10-16 16:19:51 +01:00
ui . chkShellMenu - > setCheckState ( CSettingsWindow__IsContextMenu ( ) ) ;
2022-02-04 21:08:25 +00:00
ui . chkShellMenu2 - > setChecked ( CSbieUtils : : HasContextMenu2 ( ) ) ;
2021-10-16 16:19:51 +01:00
ui . chkAlwaysDefault - > setChecked ( theConf - > GetBool ( " Options/RunInDefaultBox " , false ) ) ;
2022-07-09 10:46:07 +01:00
ui . cmbDPI - > setCurrentIndex ( theConf - > GetInt ( " Options/DPIScaling " , 1 ) ) ;
2021-10-16 16:19:51 +01:00
ui . chkDarkTheme - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/UseDarkTheme " , 2 ) ) ) ;
2022-08-10 19:14:37 +01:00
ui . chkFusionTheme - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/UseFusionTheme " , 2 ) ) ) ;
2022-07-29 09:24:32 +01:00
ui . chkAltRows - > setChecked ( theConf - > GetBool ( " Options/AltRowColors " , false ) ) ;
2022-07-09 10:46:07 +01:00
ui . chkBackground - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/UseBackground " , 2 ) ) ) ;
ui . chkLargeIcons - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/LargeIcons " , 2 ) ) ) ;
ui . chkNoIcons - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/NoIcons " , 2 ) ) ) ;
2022-07-09 23:06:11 +01:00
ui . chkOptTree - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/OptionTree " , 2 ) ) ) ;
2022-07-10 17:28:10 +01:00
ui . chkColorIcons - > setChecked ( theConf - > GetBool ( " Options/ColorBoxIcons " , false ) ) ;
2022-07-09 10:46:07 +01:00
2022-07-20 19:54:09 +01:00
//ui.cmbFontScale->setCurrentIndex(ui.cmbFontScale->findData(theConf->GetInt("Options/FontScaling", 100)));
ui . cmbFontScale - > setCurrentText ( QString : : number ( theConf - > GetInt ( " Options/FontScaling " , 100 ) ) ) ;
2021-10-16 16:19:51 +01:00
ui . chkNotifications - > setChecked ( theConf - > GetBool ( " Options/ShowNotifications " , true ) ) ;
ui . chkSandboxUrls - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/OpenUrlsSandboxed " , 2 ) ) ) ;
ui . chkShowRecovery - > setChecked ( theConf - > GetBool ( " Options/ShowRecovery " , false ) ) ;
ui . chkNotifyRecovery - > setChecked ( ! theConf - > GetBool ( " Options/InstantRecovery " , true ) ) ;
2022-07-29 09:24:32 +01:00
ui . chkRecoveryTop - > setChecked ( theConf - > GetBool ( " Options/RecoveryOnTop " , true ) ) ;
2022-02-13 11:55:52 +00:00
ui . chkAsyncBoxOps - > setChecked ( theConf - > GetBool ( " Options/UseAsyncBoxOps " , false ) ) ;
2021-10-16 16:19:51 +01:00
ui . chkPanic - > setChecked ( theConf - > GetBool ( " Options/EnablePanicKey " , false ) ) ;
2021-11-13 12:09:32 +00:00
ui . keyPanic - > setKeySequence ( QKeySequence ( theConf - > GetString ( " Options/PanicKeySequence " , " Shift+Pause " ) ) ) ;
2021-10-16 16:19:51 +01:00
2022-05-16 20:30:40 +01:00
ui . chkMonitorSize - > setChecked ( theConf - > GetBool ( " Options/WatchBoxSize " , false ) ) ;
2021-10-16 16:19:51 +01:00
ui . chkWatchConfig - > setChecked ( theConf - > GetBool ( " Options/WatchIni " , true ) ) ;
ui . cmbSysTray - > setCurrentIndex ( theConf - > GetInt ( " Options/SysTrayIcon " , 1 ) ) ;
2022-02-05 14:09:53 +00:00
ui . cmbTrayBoxes - > setCurrentIndex ( theConf - > GetInt ( " Options/SysTrayFilter " , 0 ) ) ;
2022-07-10 17:28:10 +01:00
ui . chkCompactTray - > setChecked ( theConf - > GetBool ( " Options/CompactTray " , false ) ) ;
2022-02-13 11:55:52 +00:00
ui . chkBoxOpsNotify - > setChecked ( theConf - > GetBool ( " Options/AutoBoxOpsNotify " , false ) ) ;
2021-10-16 16:19:51 +01:00
if ( theAPI - > IsConnected ( ) )
{
QString FileRootPath_Default = " \\ ?? \\ %SystemDrive% \\ Sandbox \\ %USER% \\ %SANDBOX% " ;
QString KeyRootPath_Default = " \\ REGISTRY \\ USER \\ Sandbox_%USER%_%SANDBOX% " ;
QString IpcRootPath_Default = " \\ Sandbox \\ %USER% \\ %SANDBOX% \\ Session_%SESSION% " ;
ui . fileRoot - > setText ( theAPI - > GetGlobalSettings ( ) - > GetText ( " FileRootPath " , FileRootPath_Default ) ) ;
ui . chkSeparateUserFolders - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " SeparateUserFolders " , true ) ) ;
ui . regRoot - > setText ( theAPI - > GetGlobalSettings ( ) - > GetText ( " KeyRootPath " , KeyRootPath_Default ) ) ;
ui . ipcRoot - > setText ( theAPI - > GetGlobalSettings ( ) - > GetText ( " IpcRootPath " , IpcRootPath_Default ) ) ;
ui . chkWFP - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " NetworkEnableWFP " , false ) ) ;
2022-02-13 11:55:52 +00:00
ui . chkObjCb - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " EnableObjectFiltering " , true ) ) ;
2021-12-21 13:57:27 +00:00
ui . chkWin32k - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " EnableWin32kHooks " , true ) ) ;
2022-07-28 07:40:57 +01:00
ui . chkSbieLogon - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " SandboxieLogon " , false ) ) ;
2021-10-16 16:19:51 +01:00
ui . chkAdminOnly - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " EditAdminOnly " , false ) ) ;
2022-09-02 10:04:49 +01:00
ui . chkAdminOnly - > setEnabled ( IsAdminUser ( ) ) ;
2021-10-16 16:19:51 +01:00
ui . chkPassRequired - > setChecked ( ! theAPI - > GetGlobalSettings ( ) - > GetText ( " EditPassword " , " " ) . isEmpty ( ) ) ;
ui . chkAdminOnlyFP - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " ForceDisableAdminOnly " , false ) ) ;
ui . chkClearPass - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " ForgetPassword " , false ) ) ;
ui . chkStartBlock - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " StartRunAlertDenied " , false ) ) ;
ui . chkStartBlockMsg - > setChecked ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " NotifyStartRunAccessDenied " , true ) ) ;
ui . treeWarnProgs - > clear ( ) ;
foreach ( const QString & Value , theAPI - > GetGlobalSettings ( ) - > GetTextList ( " AlertProcess " , false ) )
AddWarnEntry ( Value , 1 ) ;
foreach ( const QString & Value , theAPI - > GetGlobalSettings ( ) - > GetTextList ( " AlertFolder " , false ) )
AddWarnEntry ( Value , 2 ) ;
}
2022-09-02 10:04:49 +01:00
if ( ! theAPI - > IsConnected ( ) | | ( theAPI - > GetGlobalSettings ( ) - > GetBool ( " EditAdminOnly " , false ) & & ! IsAdminUser ( ) ) )
2021-10-16 16:19:51 +01:00
{
ui . fileRoot - > setEnabled ( false ) ;
ui . chkSeparateUserFolders - > setEnabled ( false ) ;
2022-01-14 17:58:25 +00:00
ui . chkAutoRoot - > setEnabled ( false ) ;
2021-10-16 16:19:51 +01:00
ui . chkWFP - > setEnabled ( false ) ;
2021-11-13 08:28:32 +00:00
ui . chkObjCb - > setEnabled ( false ) ;
2021-12-10 21:59:19 +00:00
ui . chkWin32k - > setEnabled ( false ) ;
2022-07-09 10:46:07 +01:00
ui . chkSbieLogon - > setEnabled ( false ) ;
2021-10-16 16:19:51 +01:00
ui . regRoot - > setEnabled ( false ) ;
ui . ipcRoot - > setEnabled ( false ) ;
ui . chkAdminOnly - > setEnabled ( false ) ;
ui . chkPassRequired - > setEnabled ( false ) ;
ui . chkAdminOnlyFP - > setEnabled ( false ) ;
ui . chkClearPass - > setEnabled ( false ) ;
ui . btnSetPassword - > setEnabled ( false ) ;
ui . treeWarnProgs - > setEnabled ( false ) ;
ui . btnAddWarnProg - > setEnabled ( false ) ;
ui . btnDelWarnProg - > setEnabled ( false ) ;
ui . treeCompat - > setEnabled ( false ) ;
ui . btnAddCompat - > setEnabled ( false ) ;
ui . btnDelCompat - > setEnabled ( false ) ;
2022-09-02 10:04:49 +01:00
ui . btnEditIni - > setEnabled ( false ) ;
2021-10-16 16:19:51 +01:00
}
2022-01-14 13:06:01 +00:00
if ( theGUI - > IsFullyPortable ( ) )
ui . chkAutoRoot - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/PortableRootDir " , 2 ) ) ) ;
2021-10-16 16:19:51 +01:00
else
ui . chkAutoRoot - > setVisible ( false ) ;
2022-01-13 22:52:58 +00:00
UpdateCert ( ) ;
ui . chkAutoUpdate - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/CheckForUpdates " , 2 ) ) ) ;
2022-05-15 08:58:40 +01:00
ui . chkAutoDownload - > setCheckState ( CSettingsWindow__Int2Chk ( theConf - > GetInt ( " Options/DownloadUpdates " , 0 ) ) ) ;
2022-05-14 09:34:44 +01:00
//ui.chkAutoInstall->setCheckState(CSettingsWindow__Int2Chk(theConf->GetInt("Options/InstallUpdates", 0)));
2022-01-13 22:52:58 +00:00
ui . chkAutoInstall - > setVisible ( false ) ; // todo implement smart auto updater
2022-08-09 17:19:46 +01:00
int UpdateChannel = theConf - > GetInt ( " Options/UpdateChannel " , 0 ) ;
ui . radRelease - > setChecked ( UpdateChannel = = 0 ) ;
ui . radPreview - > setChecked ( UpdateChannel = = 1 ) ;
2022-01-13 22:52:58 +00:00
ui . chkNoCheck - > setChecked ( theConf - > GetBool ( " Options/NoSupportCheck " , false ) ) ;
if ( ui . chkNoCheck - > isCheckable ( ) & & ! g_CertInfo . expired )
ui . chkNoCheck - > setVisible ( false ) ; // hide if not relevant
OnChange ( ) ;
}
void CSettingsWindow : : UpdateCert ( )
{
2021-10-16 16:19:51 +01:00
ui . lblCertExp - > setVisible ( false ) ;
if ( ! g_Certificate . isEmpty ( ) )
{
ui . txtCertificate - > setPlainText ( g_Certificate ) ;
//ui.lblSupport->setVisible(false);
QPalette palette = QApplication : : palette ( ) ;
if ( theGUI - > m_DarkTheme )
palette . setColor ( QPalette : : Text , Qt : : black ) ;
2022-01-13 22:52:58 +00:00
if ( g_CertInfo . expired ) {
2021-11-13 08:28:32 +00:00
palette . setColor ( QPalette : : Base , QColor ( 255 , 255 , 192 ) ) ;
2022-01-13 22:52:58 +00:00
ui . lblCertExp - > setText ( tr ( " This supporter certificate has expired, please <a href= \" sbie://update/cert \" >get an updated certificate</a>. " ) ) ;
2021-11-13 08:28:32 +00:00
ui . lblCertExp - > setVisible ( true ) ;
}
else {
2022-01-13 22:52:58 +00:00
if ( g_CertInfo . about_to_expire ) {
ui . lblCertExp - > setText ( tr ( " This supporter certificate will <font color='red'>expire in %1 days</font>, please <a href= \" sbie://update/cert \" >get an updated certificate</a>. " ) . arg ( g_CertInfo . expirers_in_sec / ( 60 * 60 * 24 ) ) ) ;
ui . lblCertExp - > setVisible ( true ) ;
}
2022-08-09 17:19:46 +01:00
/*#ifdef _DEBUG
else {
ui . lblCertExp - > setText ( tr ( " This supporter certificate is valid, <a href= \" sbie://update/cert \" >check for an updated certificate</a>. " ) ) ;
ui . lblCertExp - > setVisible ( true ) ;
}
# endif* /
2021-11-13 08:28:32 +00:00
palette . setColor ( QPalette : : Base , QColor ( 192 , 255 , 192 ) ) ;
}
2021-10-16 16:19:51 +01:00
ui . txtCertificate - > setPalette ( palette ) ;
}
}
2022-07-24 14:30:54 +01:00
void CSettingsWindow : : WriteAdvancedCheck ( QCheckBox * pCheck , const QString & Name , const QString & OnValue , const QString & OffValue )
{
//if (pCheck->checkState() == Qt::PartiallyChecked)
// return;
if ( ! pCheck - > isEnabled ( ) )
return ;
SB_STATUS Status ;
if ( pCheck - > checkState ( ) = = Qt : : Checked )
{
if ( ! OnValue . isEmpty ( ) )
Status = theAPI - > GetGlobalSettings ( ) - > SetText ( Name , OnValue ) ;
else
Status = theAPI - > GetGlobalSettings ( ) - > DelValue ( Name ) ;
}
else if ( pCheck - > checkState ( ) = = Qt : : Unchecked )
{
if ( ! OffValue . isEmpty ( ) )
Status = theAPI - > GetGlobalSettings ( ) - > SetText ( Name , OffValue ) ;
else
Status = theAPI - > GetGlobalSettings ( ) - > DelValue ( Name ) ;
}
if ( ! Status )
throw Status ;
}
void CSettingsWindow : : WriteText ( const QString & Name , const QString & Value )
{
SB_STATUS Status ;
if ( Value . isEmpty ( ) )
Status = theAPI - > GetGlobalSettings ( ) - > DelValue ( Name ) ;
else
Status = theAPI - > GetGlobalSettings ( ) - > SetText ( Name , Value ) ;
if ( ! Status )
throw Status ;
}
void CSettingsWindow : : WriteTextList ( const QString & Setting , const QStringList & List )
{
SB_STATUS Status = theAPI - > GetGlobalSettings ( ) - > UpdateTextList ( Setting , List , false ) ;
if ( ! Status )
throw Status ;
}
2021-10-16 16:19:51 +01:00
void CSettingsWindow : : SaveSettings ( )
{
theConf - > SetValue ( " Options/UiLanguage " , ui . uiLang - > currentData ( ) ) ;
2022-07-09 10:46:07 +01:00
theConf - > SetValue ( " Options/DPIScaling " , ui . cmbDPI - > currentData ( ) ) ;
2021-10-16 16:19:51 +01:00
theConf - > SetValue ( " Options/UseDarkTheme " , CSettingsWindow__Chk2Int ( ui . chkDarkTheme - > checkState ( ) ) ) ;
2022-08-10 19:14:37 +01:00
theConf - > SetValue ( " Options/UseFusionTheme " , CSettingsWindow__Chk2Int ( ui . chkFusionTheme - > checkState ( ) ) ) ;
2022-07-29 09:24:32 +01:00
theConf - > SetValue ( " Options/AltRowColors " , ui . chkAltRows - > isChecked ( ) ) ;
2022-07-09 10:46:07 +01:00
theConf - > SetValue ( " Options/UseBackground " , CSettingsWindow__Chk2Int ( ui . chkBackground - > checkState ( ) ) ) ;
theConf - > SetValue ( " Options/LargeIcons " , CSettingsWindow__Chk2Int ( ui . chkLargeIcons - > checkState ( ) ) ) ;
theConf - > SetValue ( " Options/NoIcons " , CSettingsWindow__Chk2Int ( ui . chkNoIcons - > checkState ( ) ) ) ;
2022-07-09 23:06:11 +01:00
theConf - > SetValue ( " Options/OptionTree " , CSettingsWindow__Chk2Int ( ui . chkOptTree - > checkState ( ) ) ) ;
2022-07-10 17:28:10 +01:00
theConf - > SetValue ( " Options/ColorBoxIcons " , ui . chkColorIcons - > isChecked ( ) ) ;
2022-07-09 10:46:07 +01:00
2022-07-20 19:54:09 +01:00
int Scaling = ui . cmbFontScale - > currentText ( ) . toInt ( ) ;
if ( Scaling < 75 )
Scaling = 75 ;
else if ( Scaling > 500 )
Scaling = 500 ;
theConf - > SetValue ( " Options/FontScaling " , Scaling ) ;
2021-10-16 16:19:51 +01:00
AutorunEnable ( ui . chkAutoStart - > isChecked ( ) ) ;
2022-01-14 17:58:25 +00:00
if ( theAPI - > IsConnected ( ) ) {
if ( ui . chkSvcStart - > checkState ( ) = = Qt : : Checked ) {
theAPI - > GetUserSettings ( ) - > SetBool ( " SbieCtrl_EnableAutoStart " , true ) ;
theAPI - > GetUserSettings ( ) - > SetText ( " SbieCtrl_AutoStartAgent " , " SandMan.exe " ) ;
}
else if ( ui . chkSvcStart - > checkState ( ) = = Qt : : Unchecked )
theAPI - > GetUserSettings ( ) - > SetBool ( " SbieCtrl_EnableAutoStart " , false ) ;
}
2021-10-16 16:19:51 +01:00
if ( ui . chkShellMenu - > checkState ( ) ! = CSettingsWindow__IsContextMenu ( ) )
{
2022-07-09 10:46:07 +01:00
if ( ui . chkShellMenu - > isChecked ( ) ) {
CSecretCheckBox * SecretCheckBox = qobject_cast < CSecretCheckBox * > ( ui . chkShellMenu ) ;
CSettingsWindow__AddContextMenu ( SecretCheckBox & & SecretCheckBox - > IsSecretSet ( ) ) ;
}
2022-02-04 21:08:25 +00:00
else
2022-05-15 12:26:22 +01:00
CSettingsWindow__RemoveContextMenu ( ) ;
2022-02-04 21:08:25 +00:00
}
if ( ui . chkShellMenu2 - > isChecked ( ) ! = CSbieUtils : : HasContextMenu2 ( ) ) {
if ( ui . chkShellMenu2 - > isChecked ( ) ) {
CSbieUtils : : AddContextMenu2 ( QApplication : : applicationDirPath ( ) . replace ( " / " , " \\ " ) + " \\ Start.exe " ,
tr ( " Run &Un-Sandboxed " ) ,
2021-10-16 16:19:51 +01:00
QApplication : : applicationDirPath ( ) . replace ( " / " , " \\ " ) + " \\ Start.exe " ) ;
} else
2022-02-04 21:08:25 +00:00
CSbieUtils : : RemoveContextMenu2 ( ) ;
2021-10-16 16:19:51 +01:00
}
2022-02-04 21:08:25 +00:00
2021-10-16 16:19:51 +01:00
theConf - > SetValue ( " Options/RunInDefaultBox " , ui . chkAlwaysDefault - > isChecked ( ) ) ;
theConf - > SetValue ( " Options/ShowNotifications " , ui . chkNotifications - > isChecked ( ) ) ;
theConf - > SetValue ( " Options/OpenUrlsSandboxed " , CSettingsWindow__Chk2Int ( ui . chkSandboxUrls - > checkState ( ) ) ) ;
theConf - > SetValue ( " Options/ShowRecovery " , ui . chkShowRecovery - > isChecked ( ) ) ;
theConf - > SetValue ( " Options/InstantRecovery " , ! ui . chkNotifyRecovery - > isChecked ( ) ) ;
2022-07-29 09:24:32 +01:00
theConf - > SetValue ( " Options/RecoveryOnTop " , ui . chkRecoveryTop - > isChecked ( ) ) ;
2022-02-13 11:55:52 +00:00
theConf - > SetValue ( " Options/UseAsyncBoxOps " , ui . chkAsyncBoxOps - > isChecked ( ) ) ;
2021-10-16 16:19:51 +01:00
theConf - > SetValue ( " Options/EnablePanicKey " , ui . chkPanic - > isChecked ( ) ) ;
theConf - > SetValue ( " Options/PanicKeySequence " , ui . keyPanic - > keySequence ( ) . toString ( ) ) ;
2022-05-16 20:30:40 +01:00
theConf - > SetValue ( " Options/WatchBoxSize " , ui . chkMonitorSize - > isChecked ( ) ) ;
2021-10-16 16:19:51 +01:00
theConf - > SetValue ( " Options/WatchIni " , ui . chkWatchConfig - > isChecked ( ) ) ;
theConf - > SetValue ( " Options/SysTrayIcon " , ui . cmbSysTray - > currentIndex ( ) ) ;
2022-02-05 14:09:53 +00:00
theConf - > SetValue ( " Options/SysTrayFilter " , ui . cmbTrayBoxes - > currentIndex ( ) ) ;
2022-07-10 17:28:10 +01:00
theConf - > SetValue ( " Options/CompactTray " , ui . chkCompactTray - > isChecked ( ) ) ;
2022-02-13 11:55:52 +00:00
theConf - > SetValue ( " Options/AutoBoxOpsNotify " , ui . chkBoxOpsNotify - > isChecked ( ) ) ;
2021-10-16 16:19:51 +01:00
if ( theAPI - > IsConnected ( ) )
{
2022-07-24 14:30:54 +01:00
try
2021-10-16 16:19:51 +01:00
{
2022-07-24 14:30:54 +01:00
WriteText ( " FileRootPath " , ui . fileRoot - > text ( ) ) ; //ui.fileRoot->setText("\\??\\%SystemDrive%\\Sandbox\\%USER%\\%SANDBOX%");
WriteAdvancedCheck ( ui . chkSeparateUserFolders , " SeparateUserFolders " , " " , " n " ) ;
WriteText ( " KeyRootPath " , ui . regRoot - > text ( ) ) ; //ui.regRoot->setText("\\REGISTRY\\USER\\Sandbox_%USER%_%SANDBOX%");
WriteText ( " IpcRootPath " , ui . ipcRoot - > text ( ) ) ; //ui.ipcRoot->setText("\\Sandbox\\%USER%\\%SANDBOX%\\Session_%SESSION%");
WriteAdvancedCheck ( ui . chkWFP , " NetworkEnableWFP " , " y " , " " ) ;
WriteAdvancedCheck ( ui . chkObjCb , " EnableObjectFiltering " , " " , " n " ) ;
WriteAdvancedCheck ( ui . chkWin32k , " EnableWin32kHooks " , " " , " n " ) ;
2022-07-28 07:40:57 +01:00
WriteAdvancedCheck ( ui . chkSbieLogon , " SandboxieLogon " , " y " , " " ) ;
2022-07-24 14:30:54 +01:00
if ( m_FeaturesChanged ) {
m_FeaturesChanged = false ;
theAPI - > ReloadConfig ( true ) ;
2021-10-16 16:19:51 +01:00
}
2022-07-24 14:30:54 +01:00
WriteAdvancedCheck ( ui . chkAdminOnly , " EditAdminOnly " , " y " , " " ) ;
2021-10-16 16:19:51 +01:00
2022-07-24 14:30:54 +01:00
bool isPassSet = ! theAPI - > GetGlobalSettings ( ) - > GetText ( " EditPassword " , " " ) . isEmpty ( ) ;
if ( ui . chkPassRequired - > isChecked ( ) )
2021-10-16 16:19:51 +01:00
{
2022-07-24 14:30:54 +01:00
if ( ! isPassSet & & m_NewPassword . isEmpty ( ) )
OnSetPassword ( ) ; // request password entry if it wasn't entered already
if ( ! m_NewPassword . isEmpty ( ) ) {
theAPI - > LockConfig ( m_NewPassword ) ; // set new/changed password
m_NewPassword . clear ( ) ;
2021-10-16 16:19:51 +01:00
}
}
2022-07-24 14:30:54 +01:00
else if ( isPassSet )
theAPI - > LockConfig ( QString ( ) ) ; // clear password
2021-10-16 16:19:51 +01:00
2022-07-24 14:30:54 +01:00
WriteAdvancedCheck ( ui . chkAdminOnlyFP , " ForceDisableAdminOnly " , " y " , " " ) ;
WriteAdvancedCheck ( ui . chkClearPass , " ForgetPassword " , " y " , " " ) ;
2021-10-16 16:19:51 +01:00
2022-07-24 14:30:54 +01:00
if ( m_WarnProgsChanged )
{
WriteAdvancedCheck ( ui . chkStartBlock , " StartRunAlertDenied " , " y " , " " ) ;
WriteAdvancedCheck ( ui . chkStartBlockMsg , " NotifyStartRunAccessDenied " , " " , " n " ) ;
2021-10-16 16:19:51 +01:00
2022-07-24 14:30:54 +01:00
QStringList AlertProcess ;
QStringList AlertFolder ;
for ( int i = 0 ; i < ui . treeWarnProgs - > topLevelItemCount ( ) ; i + + )
{
QTreeWidgetItem * pItem = ui . treeWarnProgs - > topLevelItem ( i ) ;
int Type = pItem - > data ( 0 , Qt : : UserRole ) . toInt ( ) ;
switch ( Type )
{
case 1 : AlertProcess . append ( pItem - > data ( 1 , Qt : : UserRole ) . toString ( ) ) ; break ;
case 2 : AlertFolder . append ( pItem - > data ( 1 , Qt : : UserRole ) . toString ( ) ) ; break ;
}
2021-10-16 16:19:51 +01:00
}
2022-07-24 14:30:54 +01:00
WriteTextList ( " AlertProcess " , AlertProcess ) ;
WriteTextList ( " AlertFolder " , AlertFolder ) ;
m_WarnProgsChanged = false ;
2021-10-16 16:19:51 +01:00
}
2022-07-24 14:30:54 +01:00
if ( m_CompatChanged )
{
QStringList Used ;
QStringList Rejected ;
for ( int i = 0 ; i < ui . treeCompat - > topLevelItemCount ( ) ; i + + ) {
QTreeWidgetItem * pItem = ui . treeCompat - > topLevelItem ( i ) ;
if ( pItem - > checkState ( 0 ) = = Qt : : Unchecked )
Rejected . append ( pItem - > data ( 0 , Qt : : UserRole ) . toString ( ) ) ;
else
Used . append ( pItem - > data ( 0 , Qt : : UserRole ) . toString ( ) ) ;
}
// retain local templates
foreach ( const QString & Template , theAPI - > GetGlobalSettings ( ) - > GetTextList ( " Template " , false ) ) {
if ( Template . left ( 6 ) = = " Local_ " ) {
Used . append ( Template ) ;
}
}
WriteTextList ( " Template " , Used ) ;
WriteTextList ( " TemplateReject " , Rejected ) ;
m_CompatChanged = false ;
}
}
catch ( SB_STATUS Status )
{
theGUI - > CheckResults ( QList < SB_STATUS > ( ) < < Status ) ;
2021-10-16 16:19:51 +01:00
}
}
if ( ui . chkAutoRoot - > isVisible ( ) )
2022-01-14 13:06:01 +00:00
theConf - > SetValue ( " Options/PortableRootDir " , CSettingsWindow__Chk2Int ( ui . chkAutoRoot - > checkState ( ) ) ) ;
2021-10-16 16:19:51 +01:00
theConf - > SetValue ( " Options/AutoRunSoftCompat " , ! ui . chkNoCompat - > isChecked ( ) ) ;
2022-01-14 17:58:25 +00:00
if ( m_CertChanged & & theAPI - > IsConnected ( ) )
2021-10-16 16:19:51 +01:00
{
QByteArray Certificate = ui . txtCertificate - > toPlainText ( ) . toUtf8 ( ) ;
if ( g_Certificate ! = Certificate ) {
2022-02-19 20:17:30 +00:00
2022-05-15 14:02:58 +01:00
QPalette palette = QApplication : : palette ( ) ;
2021-10-16 16:19:51 +01:00
if ( theGUI - > m_DarkTheme )
palette . setColor ( QPalette : : Text , Qt : : black ) ;
2021-11-13 08:28:32 +00:00
ui . lblCertExp - > setVisible ( false ) ;
2022-05-15 14:02:58 +01:00
bool bRet = ApplyCertificate ( Certificate , this ) ;
2021-10-16 16:19:51 +01:00
if ( Certificate . isEmpty ( ) )
palette . setColor ( QPalette : : Base , Qt : : white ) ;
2022-05-15 14:02:58 +01:00
else if ( ! bRet )
2021-10-16 16:19:51 +01:00
palette . setColor ( QPalette : : Base , QColor ( 255 , 192 , 192 ) ) ;
2022-05-15 14:02:58 +01:00
else if ( g_CertInfo . expired | | g_CertInfo . outdated ) {
palette . setColor ( QPalette : : Base , QColor ( 255 , 255 , 192 ) ) ;
ui . lblCertExp - > setVisible ( true ) ;
2021-10-16 16:19:51 +01:00
}
2022-05-15 14:02:58 +01:00
else
palette . setColor ( QPalette : : Base , QColor ( 192 , 255 , 192 ) ) ;
2021-10-16 16:19:51 +01:00
ui . txtCertificate - > setPalette ( palette ) ;
}
m_CertChanged = false ;
}
theConf - > SetValue ( " Options/CheckForUpdates " , CSettingsWindow__Chk2Int ( ui . chkAutoUpdate - > checkState ( ) ) ) ;
2022-05-14 09:34:44 +01:00
theConf - > SetValue ( " Options/DownloadUpdates " , CSettingsWindow__Chk2Int ( ui . chkAutoDownload - > checkState ( ) ) ) ;
//theConf->SetValue("Options/InstallUpdates", CSettingsWindow__Chk2Int(ui.chkAutoInstall->checkState()));
2021-10-16 16:19:51 +01:00
2022-08-09 17:19:46 +01:00
int UpdateChannel = 0 ; // ui.radRelease->isChecked();
if ( ui . radPreview - > isChecked ( ) )
UpdateChannel = 1 ;
theConf - > SetValue ( " Options/UpdateChannel " , UpdateChannel ) ;
2022-01-13 22:52:58 +00:00
theConf - > SetValue ( " Options/NoSupportCheck " , ui . chkNoCheck - > isChecked ( ) ) ;
2022-07-09 10:46:07 +01:00
emit OptionsChanged ( m_bRebuildUI ) ;
2021-10-16 16:19:51 +01:00
}
2022-05-15 14:02:58 +01:00
bool CSettingsWindow : : ApplyCertificate ( const QByteArray & Certificate , QWidget * widget )
{
QString CertPath = theAPI - > GetSbiePath ( ) + " \\ Certificate.dat " ;
if ( ! Certificate . isEmpty ( ) ) {
auto Args = GetArguments ( Certificate , L ' \n ' , L ' : ' ) ;
bool bLooksOk = true ;
if ( Args . value ( " NAME " ) . isEmpty ( ) ) // mandatory
bLooksOk = false ;
//if (Args.value("UPDATEKEY").isEmpty())
// bLooksOk = false;
if ( Args . value ( " SIGNATURE " ) . isEmpty ( ) ) // absolutely mandatory
bLooksOk = false ;
if ( bLooksOk ) {
QString TempPath = QDir : : tempPath ( ) + " /Sbie+Certificate.dat " ;
QFile CertFile ( TempPath ) ;
if ( CertFile . open ( QFile : : WriteOnly ) ) {
CertFile . write ( Certificate ) ;
CertFile . close ( ) ;
}
WindowsMoveFile ( TempPath . replace ( " / " , " \\ " ) , CertPath . replace ( " / " , " \\ " ) ) ;
}
else {
2022-05-24 00:02:29 +01:00
QMessageBox : : critical ( widget , " Sandboxie-Plus " , tr ( " This does not look like a certificate. Please enter the entire certificate, not just a portion of it. " ) ) ;
2022-05-15 14:02:58 +01:00
return false ;
}
}
else if ( ! g_Certificate . isEmpty ( ) ) {
WindowsMoveFile ( CertPath . replace ( " / " , " \\ " ) , " " ) ;
}
if ( Certificate . isEmpty ( ) )
return false ;
if ( ! theAPI - > ReloadCert ( ) . IsError ( ) )
{
g_FeatureFlags = theAPI - > GetFeatureFlags ( ) ;
theGUI - > UpdateCertState ( ) ;
if ( g_CertInfo . expired | | g_CertInfo . outdated ) {
if ( g_CertInfo . expired )
QMessageBox : : information ( widget , " Sandboxie-Plus " , tr ( " This certificate is unfortunately expired. " ) ) ;
else
QMessageBox : : information ( widget , " Sandboxie-Plus " , tr ( " This certificate is unfortunately outdated. " ) ) ;
}
else {
QMessageBox : : information ( widget , " Sandboxie-Plus " , tr ( " Thank you for supporting the development of Sandboxie-Plus. " ) ) ;
}
g_Certificate = Certificate ;
return true ;
}
else
{
QMessageBox : : critical ( widget , " Sandboxie-Plus " , tr ( " This support certificate is not valid. " ) ) ;
g_CertInfo . State = 0 ;
g_Certificate . clear ( ) ;
return false ;
}
}
2021-10-16 16:19:51 +01:00
void CSettingsWindow : : apply ( )
{
2022-01-13 22:52:58 +00:00
if ( ! ui . btnEditIni - > isEnabled ( ) )
SaveIniSection ( ) ;
else
SaveSettings ( ) ;
2021-10-16 16:19:51 +01:00
LoadSettings ( ) ;
}
void CSettingsWindow : : ok ( )
{
2022-07-24 14:30:54 +01:00
apply ( ) ;
2021-10-16 16:19:51 +01:00
this - > close ( ) ;
}
void CSettingsWindow : : reject ( )
{
this - > close ( ) ;
}
void CSettingsWindow : : OnBrowse ( )
{
QString Value = QFileDialog : : getExistingDirectory ( this , tr ( " Select Directory " ) ) . replace ( " / " , " \\ " ) ;
if ( Value . isEmpty ( ) )
return ;
ui . fileRoot - > setText ( Value + " \\ %SANDBOX% " ) ;
}
void CSettingsWindow : : OnChange ( )
{
2022-01-14 13:06:01 +00:00
if ( ui . chkAutoRoot - > isVisible ( ) )
2021-10-16 16:19:51 +01:00
ui . fileRoot - > setEnabled ( ui . chkAutoRoot - > checkState ( ) ! = Qt : : Checked ) ;
ui . btnSetPassword - > setEnabled ( ui . chkPassRequired - > isChecked ( ) ) ;
}
void CSettingsWindow : : OnTab ( )
{
2022-08-15 12:18:26 +01:00
OnTab ( ui . tabs - > currentIndex ( ) ) ;
}
void CSettingsWindow : : OnTab ( int iTabID )
{
if ( iTabID = = eSupport )
2022-08-11 23:09:35 +01:00
{
if ( ui . lblCurrent - > text ( ) . isEmpty ( ) ) {
if ( ui . chkAutoUpdate - > checkState ( ) )
GetUpdates ( ) ;
else
ui . lblCurrent - > setText ( tr ( " <a href= \" check \" >Check Now</a> " ) ) ;
}
}
2022-08-15 12:18:26 +01:00
else if ( iTabID = = eEditIni )
2022-01-13 22:52:58 +00:00
{
LoadIniSection ( ) ;
ui . txtIniSection - > setReadOnly ( true ) ;
}
2022-08-15 12:18:26 +01:00
else if ( iTabID = = eSoftCompat & & m_CompatLoaded ! = 1 & & theAPI - > IsConnected ( ) )
2021-10-16 16:19:51 +01:00
{
if ( m_CompatLoaded = = 0 )
theGUI - > GetCompat ( ) - > RunCheck ( ) ;
ui . treeCompat - > clear ( ) ;
QMap < QString , int > Templates = theGUI - > GetCompat ( ) - > GetTemplates ( ) ;
for ( QMap < QString , int > : : iterator I = Templates . begin ( ) ; I ! = Templates . end ( ) ; + + I )
{
if ( I . value ( ) = = CSbieTemplates : : eNone )
continue ;
QSharedPointer < CSbieIni > pTemplate = QSharedPointer < CSbieIni > ( new CSbieIni ( " Template_ " + I . key ( ) , theAPI ) ) ;
2022-06-29 07:40:58 +01:00
QString Title = pTemplate - > GetText ( " Tmpl.Title " , " " , false , true , true ) ;
2021-10-16 16:19:51 +01:00
if ( Title . left ( 1 ) = = " # " )
{
int End = Title . mid ( 1 ) . indexOf ( " , " ) ;
if ( End = = - 1 ) End = Title . length ( ) - 1 ;
int MsgNum = Title . mid ( 1 , End ) . toInt ( ) ;
Title = theAPI - > GetSbieMsgStr ( MsgNum , theGUI - > m_LanguageId ) . arg ( Title . mid ( End + 2 ) ) . arg ( " " ) ;
}
//if (Title.isEmpty()) Title = Name;
QTreeWidgetItem * pItem = new QTreeWidgetItem ( ) ;
pItem - > setText ( 0 , Title ) ;
pItem - > setData ( 0 , Qt : : UserRole , I . key ( ) ) ;
if ( ( I . value ( ) & CSbieTemplates : : eDisabled ) ! = 0 )
pItem - > setCheckState ( 0 , Qt : : Unchecked ) ;
else if ( ( I . value ( ) & CSbieTemplates : : eEnabled ) ! = 0 )
pItem - > setCheckState ( 0 , Qt : : Checked ) ;
else
pItem - > setCheckState ( 0 , Qt : : PartiallyChecked ) ;
ui . treeCompat - > addTopLevelItem ( pItem ) ;
}
m_CompatLoaded = 1 ;
m_CompatChanged = true ;
}
}
void CSettingsWindow : : OnSetPassword ( )
{
retry :
QString Value1 = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " Please enter the new configuration password. " ) , QLineEdit : : Password ) ;
if ( Value1 . isEmpty ( ) )
return ;
QString Value2 = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " Please re-enter the new configuration password. " ) , QLineEdit : : Password ) ;
if ( Value2 . isEmpty ( ) )
return ;
if ( Value1 ! = Value2 ) {
QMessageBox : : warning ( this , " Sandboxie-Plus " , tr ( " Passwords did not match, please retry. " ) ) ;
goto retry ;
}
m_NewPassword = Value1 ;
}
void CSettingsWindow : : AddWarnEntry ( const QString & Name , int type )
{
QTreeWidgetItem * pItem = new QTreeWidgetItem ( ) ;
pItem - > setText ( 0 , ( type = = 1 ? tr ( " Process " ) : tr ( " Folder " ) ) ) ;
pItem - > setData ( 0 , Qt : : UserRole , type ) ;
pItem - > setData ( 1 , Qt : : UserRole , Name ) ;
pItem - > setText ( 1 , Name ) ;
ui . treeWarnProgs - > addTopLevelItem ( pItem ) ;
}
void CSettingsWindow : : OnAddWarnProg ( )
{
QString Value = QInputDialog : : getText ( this , " Sandboxie-Plus " , tr ( " Please enter a program file name " ) ) ;
if ( Value . isEmpty ( ) )
return ;
AddWarnEntry ( Value , 1 ) ;
m_WarnProgsChanged = true ;
}
void CSettingsWindow : : OnAddWarnFolder ( )
{
QString Value = QFileDialog : : getExistingDirectory ( this , tr ( " Select Directory " ) ) . replace ( " / " , " \\ " ) ;
if ( Value . isEmpty ( ) )
return ;
AddWarnEntry ( Value , 2 ) ;
m_WarnProgsChanged = true ;
}
void CSettingsWindow : : OnDelWarnProg ( )
{
QTreeWidgetItem * pItem = ui . treeWarnProgs - > currentItem ( ) ;
if ( ! pItem )
return ;
delete pItem ;
m_WarnProgsChanged = true ;
}
void CSettingsWindow : : OnTemplateClicked ( QTreeWidgetItem * pItem , int Column )
{
// todo: check if really changed
m_CompatChanged = true ;
}
2022-05-29 07:07:17 +01:00
void CSettingsWindow : : OnTemplateDoubleClicked ( QTreeWidgetItem * pItem , int Column )
{
QSharedPointer < CSbieIni > pTemplate = QSharedPointer < CSbieIni > ( new CSbieIni ( " Template_ " + pItem - > data ( 0 , Qt : : UserRole ) . toString ( ) , theAPI ) ) ;
COptionsWindow OptionsWindow ( pTemplate , pItem - > text ( 1 ) ) ;
OptionsWindow . exec ( ) ;
}
2021-10-16 16:19:51 +01:00
void CSettingsWindow : : OnAddCompat ( )
{
QTreeWidgetItem * pItem = ui . treeCompat - > currentItem ( ) ;
if ( ! pItem )
return ;
pItem - > setCheckState ( 0 , Qt : : Checked ) ;
m_CompatChanged = true ;
}
void CSettingsWindow : : OnDelCompat ( )
{
QTreeWidgetItem * pItem = ui . treeCompat - > currentItem ( ) ;
if ( ! pItem )
return ;
pItem - > setCheckState ( 0 , Qt : : Unchecked ) ;
m_CompatChanged = true ;
}
2022-01-13 22:52:58 +00:00
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-01-14 21:28:44 +00:00
// Raw section ini Editor
2022-01-13 22:52:58 +00:00
//
void CSettingsWindow : : SetIniEdit ( bool bEnable )
{
2022-08-15 12:18:26 +01:00
if ( m_pTree ) {
m_pTree - > setEnabled ( ! bEnable ) ;
}
else {
for ( int i = 0 ; i < ui . tabs - > count ( ) - 2 ; i + + ) {
bool Enabled = ui . tabs - > widget ( i ) - > isEnabled ( ) ;
ui . tabs - > setTabEnabled ( i , ! bEnable & & Enabled ) ;
ui . tabs - > widget ( i ) - > setEnabled ( Enabled ) ;
}
2022-01-13 22:52:58 +00:00
}
ui . btnSaveIni - > setEnabled ( bEnable ) ;
ui . btnCancelEdit - > setEnabled ( bEnable ) ;
ui . txtIniSection - > setReadOnly ( ! bEnable ) ;
ui . btnEditIni - > setEnabled ( ! bEnable ) ;
}
void CSettingsWindow : : OnEditIni ( )
{
SetIniEdit ( true ) ;
}
void CSettingsWindow : : OnSaveIni ( )
{
SaveIniSection ( ) ;
SetIniEdit ( false ) ;
LoadSettings ( ) ;
}
void CSettingsWindow : : OnCancelEdit ( )
{
SetIniEdit ( false ) ;
}
void CSettingsWindow : : LoadIniSection ( )
{
QString Section ;
2022-01-14 17:58:25 +00:00
if ( theAPI - > IsConnected ( ) )
Section = theAPI - > SbieIniGetEx ( " GlobalSettings " , " " ) ;
2022-01-13 22:52:58 +00:00
ui . txtIniSection - > setPlainText ( Section ) ;
}
void CSettingsWindow : : SaveIniSection ( )
{
2022-01-14 17:58:25 +00:00
if ( theAPI - > IsConnected ( ) )
theAPI - > SbieIniSet ( " GlobalSettings " , " " , ui . txtIniSection - > toPlainText ( ) ) ;
2022-01-13 22:52:58 +00:00
LoadIniSection ( ) ;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-08-11 23:09:35 +01:00
// Update
//
void CSettingsWindow : : GetUpdates ( )
{
QVariantMap Params ;
Params [ " channel " ] = " all " ;
COnlineUpdater : : Instance ( ) - > GetUpdates ( this , SLOT ( OnUpdateData ( const QVariantMap & , const QVariantMap & ) ) , Params ) ;
}
void CSettingsWindow : : OnUpdateData ( const QVariantMap & Data , const QVariantMap & Params )
{
if ( Data . isEmpty ( ) | | Data [ " error " ] . toBool ( ) )
return ;
m_UpdateData = Data ;
QVariantList Channels = m_UpdateData [ " channels " ] . toList ( ) ;
ui . lblCurrent - > setText ( tr ( " %1 (Current) " ) . arg ( theGUI - > GetVersion ( ) ) ) ;
if ( Channels . length ( ) > 0 ) ui . lblRelease - > setText ( tr ( " <a href= \" 0 \" >%1</a> " ) . arg ( Channels [ 0 ] . toMap ( ) . value ( " version " ) . toString ( ) ) ) ;
if ( Channels . length ( ) > 1 ) ui . lblPreview - > setText ( tr ( " <a href= \" 1 \" >%1</a> " ) . arg ( Channels [ 1 ] . toMap ( ) . value ( " version " ) . toString ( ) ) ) ;
}
void CSettingsWindow : : OnUpdate ( const QString & Channel )
{
if ( Channel = = " check " )
GetUpdates ( ) ;
else
{
QVariantList Channels = m_UpdateData [ " channels " ] . toList ( ) ;
QVariantMap Data = Channels [ Channel . toInt ( ) ] . toMap ( ) ;
QString VersionStr = Data [ " version " ] . toString ( ) ;
if ( VersionStr . isEmpty ( ) )
return ;
QString DownloadUrl = Data [ " downloadUrl " ] . toString ( ) ;
// 'sha256'
// 'signature'
if ( ! DownloadUrl . isEmpty ( ) )
{
if ( QMessageBox ( " Sandboxie-Plus " , tr ( " Do you want to download the version %1? " ) . arg ( VersionStr ) , QMessageBox : : Question , QMessageBox : : Yes | QMessageBox : : Default , QMessageBox : : No | QMessageBox : : Escape , QMessageBox : : NoButton , this ) . exec ( ) = = QMessageBox : : Yes )
COnlineUpdater : : Instance ( ) - > DownloadUpdates ( DownloadUrl , true ) ;
}
else
{
QString UpdateUrl = Data [ " updateUrl " ] . toString ( ) ;
QDesktopServices : : openUrl ( UpdateUrl ) ;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2022-01-13 22:52:58 +00:00
// Support
//
2021-10-16 16:19:51 +01:00
void CSettingsWindow : : CertChanged ( )
{
m_CertChanged = true ;
QPalette palette = QApplication : : palette ( ) ;
ui . txtCertificate - > setPalette ( palette ) ;
}
2022-07-09 10:46:07 +01:00
void CSettingsWindow : : LoadCertificate ( QString CertPath )
2021-10-16 16:19:51 +01:00
{
2022-01-30 14:53:37 +00:00
if ( theAPI & & theAPI - > IsConnected ( ) )
2021-10-16 16:19:51 +01:00
CertPath = theAPI - > GetSbiePath ( ) + " \\ Certificate.dat " ;
QFile CertFile ( CertPath ) ;
if ( CertFile . open ( QFile : : ReadOnly ) ) {
g_Certificate = CertFile . readAll ( ) ;
CertFile . close ( ) ;
}
}
# include <windows.h>
# include <shellapi.h>
void WindowsMoveFile ( const QString & From , const QString & To )
{
wstring from = From . toStdWString ( ) ;
from . append ( L " \0 " , 1 ) ;
wstring to = To . toStdWString ( ) ;
to . append ( L " \0 " , 1 ) ;
SHFILEOPSTRUCT SHFileOp ;
memset ( & SHFileOp , 0 , sizeof ( SHFILEOPSTRUCT ) ) ;
SHFileOp . hwnd = NULL ;
SHFileOp . wFunc = To . isEmpty ( ) ? FO_DELETE : FO_MOVE ;
SHFileOp . pFrom = from . c_str ( ) ;
SHFileOp . pTo = to . c_str ( ) ;
SHFileOp . fFlags = NULL ;
//The Copying Function
SHFileOperation ( & SHFileOp ) ;
}