2022-08-09 17:19:46 +01:00
# include "stdafx.h"
# include "SupportDialog.h"
# include "SandMan.h"
# include "../MiscHelpers/Common/Common.h"
# include "SettingsWindow.h"
# include <Windows.h>
2023-07-01 17:54:53 +01:00
# include "OnlineUpdater.h"
2022-08-09 17:19:46 +01:00
bool CSupportDialog : : m_ReminderShown = false ;
QDateTime GetSbieInstallationDate ( )
{
time_t InstalDate = 0 ;
theAPI - > GetSecureParam ( " InstallationDate " , & InstalDate , sizeof ( InstalDate ) ) ;
2022-09-29 17:28:48 +01:00
time_t CurrentDate = QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ;
2022-08-09 17:19:46 +01:00
if ( InstalDate = = 0 | | InstalDate > CurrentDate ) {
InstalDate = CurrentDate ;
theAPI - > SetSecureParam ( " InstallationDate " , & InstalDate , sizeof ( InstalDate ) ) ;
}
2022-09-29 17:28:48 +01:00
return QDateTime : : fromSecsSinceEpoch ( InstalDate ) ;
2022-08-09 17:19:46 +01:00
}
bool CSupportDialog : : IsBusinessUse ( )
{
2023-07-11 21:35:59 +01:00
if ( CERT_IS_TYPE ( g_CertInfo , eCertBusiness ) )
2022-08-09 17:19:46 +01:00
return true ;
uchar UsageFlags = 0 ;
theAPI - > GetSecureParam ( " UsageFlags " , & UsageFlags , sizeof ( UsageFlags ) ) ;
return ( UsageFlags & 1 ) ! = 0 ;
}
bool CSupportDialog : : CheckSupport ( bool bOnRun )
{
2023-07-01 17:54:53 +01:00
bool NoGo = false ;
# ifdef INSIDER_BUILD
2023-07-11 21:35:59 +01:00
if ( g_CertInfo . active ) {
if ( ! CERT_IS_INSIDER ( g_CertInfo ) ) {
2023-07-01 17:54:53 +01:00
TArguments args = GetArguments ( g_Certificate , L ' \n ' , L ' : ' ) ;
if ( args . value ( " TYPE " ) . contains ( " PATREON " ) ) {
2023-07-06 12:53:19 +01:00
if ( QMessageBox : : question ( NULL , " Sandboxie-Plus " , tr ( " This Insider build requires a special certificate of type GREAT_PATREON, PERSONAL-HUGE, or CONTRIBUTOR. \n "
2023-07-06 13:17:20 +01:00
" If you are a Great Supporter on Patreon already, Sandboxie can check online for an update of your certificate. " ) , QMessageBox : : Ok , QMessageBox : : Cancel ) = = QMessageBox : : Ok ) {
2023-07-01 17:54:53 +01:00
theGUI - > m_pUpdater - > UpdateCert ( true ) ;
2023-07-11 21:35:59 +01:00
if ( CERT_IS_INSIDER ( g_CertInfo ) )
2023-07-01 17:54:53 +01:00
return false ;
}
}
else
QMessageBox : : warning ( NULL , " Sandboxie-Plus " , tr ( " This Insider build requires a special certificate of type GREAT_PATREON, PERSONAL-HUGE, or CONTRIBUTOR. " ) ) ;
}
else
return false ;
}
NoGo = true ;
# else
2023-07-11 21:35:59 +01:00
if ( g_CertInfo . active )
2022-08-09 17:19:46 +01:00
return false ;
QDateTime InstallDate = GetSbieInstallationDate ( ) ;
bool bOnARM64 = ( g_FeatureFlags & CSbieAPI : : eSbieFeatureARM64 ) ! = 0 ;
QDateTime CurretnDate = QDateTime : : currentDateTimeUtc ( ) ;
int Days = InstallDate . daysTo ( CurretnDate ) ;
2023-10-18 21:32:33 +01:00
BYTE CertBlocked = 0 ;
theAPI - > GetSecureParam ( " CertBlocked " , & CertBlocked , sizeof ( CertBlocked ) ) ;
if ( CertBlocked )
{
QString Message = tr ( " An attempt was made to use a blocked certificate on this system. This action violates the terms of use for the support certificate. "
" You must now purchase a valid certificate, as the usage of the free version has been restricted. " ) ;
CSupportDialog dialog ( Message , NoGo , Days ) ;
if ( dialog . exec ( ) = = QDialog : : Rejected )
PostQuitMessage ( 0 ) ;
return true ;
}
2022-08-09 17:19:46 +01:00
if ( Days < 40 )
return false ;
if ( IsBusinessUse ( ) )
{
if ( g_CertInfo . expired )
Days = - g_CertInfo . expirers_in_sec / ( 24 * 3600 ) ;
NoGo = ( Days > 60 ) ;
if ( ! NoGo & & m_ReminderShown & & ! bOnRun )
return false ;
}
else if ( ! bOnARM64 & & ! theAPI - > GetGlobalSettings ( ) - > GetBool ( " AlwaysShowReminder " ) )
{
// Note: the old sandboxie showed a message after 30 days every 12 hours for 5 seconds
2022-08-19 07:53:38 +01:00
2023-10-21 10:32:05 +01:00
int Interval = 30 * 24 ; // in hours
USHORT ReminderShedule [ 2 * 11 ] = {
// days, itnerval,
730 , 1 * 24 ,
365 , 5 * 24 ,
182 , 10 * 24 ,
30 , 30 * 24 ,
0
} ;
USHORT CurReminderRevision = 1 ;
USHORT ReminderRevision = 0 ;
theAPI - > GetSecureParam ( " ReminderRevision " , & ReminderRevision , sizeof ( ReminderRevision ) ) ;
if ( ReminderRevision < CurReminderRevision ) {
theAPI - > SetSecureParam ( " ReminderShedule " , & ReminderShedule , sizeof ( ReminderShedule ) ) ;
theAPI - > SetSecureParam ( " ReminderRevision " , & CurReminderRevision , sizeof ( CurReminderRevision ) ) ;
}
else if ( ReminderRevision > CurReminderRevision )
theAPI - > GetSecureParam ( " ReminderShedule " , & ReminderShedule , sizeof ( ReminderShedule ) ) ;
for ( USHORT * Cur = ReminderShedule ; ( ULONG_PTR ) Cur < ( ULONG_PTR ) ReminderShedule + sizeof ( ReminderShedule ) & & * Cur ! = 0 ; Cur + = 2 ) {
if ( Days > Cur [ 0 ] ) {
if ( Cur [ 1 ] < Interval ) Interval = Cur [ 1 ] ;
break ;
2022-08-19 07:53:38 +01:00
}
}
2022-08-09 17:19:46 +01:00
time_t LastReminder = 0 ;
theAPI - > GetSecureParam ( " LastReminder " , & LastReminder , sizeof ( LastReminder ) ) ;
2022-09-29 17:28:48 +01:00
if ( LastReminder > 0 & & LastReminder < CurretnDate . toSecsSinceEpoch ( ) ) {
if ( CurretnDate . toSecsSinceEpoch ( ) - LastReminder < ( time_t ( Interval ) * 3600 ) )
2022-08-09 17:19:46 +01:00
return false ;
}
2022-08-19 07:53:38 +01:00
//ULONG ReminderConfig = 0;
//theAPI->GetSecureParam("ReminderConfig", &ReminderConfig, sizeof(ReminderConfig));
2022-08-11 23:09:35 +01:00
if ( ( rand ( ) % 5 ) ! = 0 )
2022-08-09 17:19:46 +01:00
return false ;
}
m_ReminderShown = true ;
2023-07-01 17:54:53 +01:00
# endif
2022-08-09 17:19:46 +01:00
if ( ! ShowDialog ( NoGo ) )
PostQuitMessage ( 0 ) ;
return true ;
}
2023-08-02 07:25:47 +01:00
extern int g_CertAmount ;
int CountSeats ( ) ;
2022-08-09 17:19:46 +01:00
bool CSupportDialog : : ShowDialog ( bool NoGo , int Wait )
{
QDateTime InstallDate = GetSbieInstallationDate ( ) ;
int Days = InstallDate . daysTo ( QDateTime : : currentDateTimeUtc ( ) ) ;
QString Message ;
2023-07-01 17:54:53 +01:00
# ifdef INSIDER_BUILD
2023-07-11 21:35:59 +01:00
if ( ! CERT_IS_INSIDER ( g_CertInfo ) )
2023-07-01 17:54:53 +01:00
{
Message + = tr ( " This is a <a href= \" https://sandboxie-plus.com/go.php?to=sbie-insider \" >exclusive Insider build</a> of Sandboxie-Plus it is only available to <a href= \" https://sandboxie-plus.com/go.php?to=patreon \" >Patreon Supporters</a> on higher tiers as well as to project contributors and owners of a HUGE supporter certificate. " ) ;
}
else
# endif
2023-08-02 07:25:47 +01:00
if ( CountSeats ( ) > g_CertAmount )
{
Message = tr ( " The installed supporter certificate allows for <b>%1 seats</b> to be active.<br /><br /> " ) . arg ( g_CertAmount ) ;
2023-08-03 23:06:46 +01:00
Message + = tr ( " <b>There seems to be however %1 Sandboxie-Plus instances on your network, <font color='red'>you need to obtain additional <a href= \" https://sandboxie-plus.com/go.php?to=sbie-obtain-cert&tip=more \" >support certificates</a></font>.</b><br /><br /> " ) . arg ( CountSeats ( ) ) ;
2023-08-02 07:25:47 +01:00
}
else if ( IsBusinessUse ( ) )
2022-08-09 17:19:46 +01:00
{
if ( g_CertInfo . expired ) {
Days = - g_CertInfo . expirers_in_sec / ( 24 * 3600 ) ;
2023-08-02 07:25:47 +01:00
Message = tr ( " The installed supporter certificate <b>has expired %1 days ago</b> and <a href= \" https://sandboxie-plus.com/go.php?to=sbie-renew-cert \" >must be renewed</a>.<br /><br /> " ) . arg ( Days ) ;
2022-08-09 17:19:46 +01:00
} else
Message = tr ( " <b>You have installed Sandboxie-Plus more than %1 days ago.</b><br /><br /> " ) . arg ( Days ) ;
2023-05-21 11:36:05 +01:00
Message + = tr ( " <u>Commercial use of Sandboxie past the evaluation period</u>, requires a valid <a href= \" https://sandboxie-plus.com/go.php?to=sbie-obtain-cert \" >support certificate</a>. " ) . arg ( Days ) ;
2022-08-09 17:19:46 +01:00
}
else
{
bool bOnARM64 = ( g_FeatureFlags & CSbieAPI : : eSbieFeatureARM64 ) ! = 0 ;
if ( g_CertInfo . outdated )
2023-08-02 07:25:47 +01:00
Message = tr ( " The installed supporter certificate is <b>outdated</b> and it is <u>not valid for<b> this version</b></u> of Sandboxie-Plus.<br /><br /> " ) ;
2022-08-09 17:19:46 +01:00
else if ( g_CertInfo . expired )
2023-08-02 07:25:47 +01:00
Message = tr ( " The installed supporter certificate is <b>expired</b> and <u>should be renewed</u>.<br /><br /> " ) ;
2022-08-09 17:19:46 +01:00
else
Message = tr ( " <b>You have been using Sandboxie-Plus for more than %1 days now.</b><br /><br /> " ) . arg ( Days ) ;
if ( bOnARM64 )
Message + = tr ( " Sandboxie on ARM64 requires a valid supporter certificate for continued use.<br /><br /> " ) ;
else
Message + = tr ( " Personal use of Sandboxie is free of charge on x86/x64, although some functionality is only available to project supporters.<br /><br /> " ) ;
if ( g_CertInfo . expired )
2023-05-21 11:36:05 +01:00
Message + = tr ( " Please continue <a href= \" https://sandboxie-plus.com/go.php?to=sbie-renew-cert \" >supporting the project</a> "
2022-08-09 17:19:46 +01:00
" by renewing your <a href= \" https://sandboxie-plus.com/go.php?to=sbie-cert \" >supporter certificate</a> and continue using the <b>enhanced functionality</b> in new builds. " ) ;
else
2023-05-21 11:36:05 +01:00
Message + = tr ( " Sandboxie <u>without</u> a valid supporter certificate will sometimes <b><font color='red'>pause for a few seconds</font></b>. This pause allows you to consider <a href= \" https://sandboxie-plus.com/go.php?to=sbie-obtain-cert \" >purchasing a supporter certificate</a> or <a href= \" https://sandboxie-plus.com/go.php?to=sbie-contribute \" >earning one by contributing</a> to the project. <br /><br /> "
2022-08-09 17:19:46 +01:00
" A <a href= \" https://sandboxie-plus.com/go.php?to=sbie-cert \" >supporter certificate</a> not just removes this reminder, but also enables <b>exclusive enhanced functionality</b> providing better security and compatibility. " ) ;
}
2022-09-29 17:28:48 +01:00
time_t LastReminder = QDateTime : : currentDateTimeUtc ( ) . toSecsSinceEpoch ( ) ;
2022-08-09 17:19:46 +01:00
theAPI - > SetSecureParam ( " LastReminder " , & LastReminder , sizeof ( LastReminder ) ) ;
CSupportDialog dialog ( Message , NoGo ) ;
return dialog . exec ( ) ! = QDialog : : Rejected ;
}
CSupportDialog : : CSupportDialog ( const QString & Message , bool NoGo , int Wait , QWidget * parent )
: QDialog ( parent )
{
Qt : : WindowFlags flags = windowFlags ( ) ;
flags | = Qt : : CustomizeWindowHint ;
//flags &= ~Qt::WindowContextHelpButtonHint;
//flags &= ~Qt::WindowSystemMenuHint;
//flags &= ~Qt::WindowMinMaxButtonsHint;
//flags |= Qt::WindowMinimizeButtonHint;
//flags &= ~Qt::WindowCloseButtonHint;
flags & = ~ Qt : : WindowContextHelpButtonHint ;
//flags &= ~Qt::WindowSystemMenuHint;
setWindowFlags ( flags ) ;
//setWindowState(Qt::WindowActive);
SetForegroundWindow ( ( HWND ) QWidget : : winId ( ) ) ;
2023-10-21 21:15:07 +01:00
this - > setWindowFlag ( Qt : : WindowStaysOnTopHint , theGUI - > IsAlwaysOnTop ( ) ) ;
2022-08-09 17:19:46 +01:00
this - > setWindowTitle ( tr ( " Sandboxie-Plus - Support Reminder " ) ) ;
this - > resize ( 420 , 300 ) ;
QVBoxLayout * verticalLayout = new QVBoxLayout ( this ) ;
QGridLayout * gridLayout = new QGridLayout ( ) ;
QHBoxLayout * horizontalLayout = new QHBoxLayout ( ) ;
m_Buttons [ 0 ] = new QPushButton ( this ) ;
horizontalLayout - > addWidget ( m_Buttons [ 0 ] ) ;
m_Buttons [ 1 ] = new QPushButton ( this ) ;
horizontalLayout - > addWidget ( m_Buttons [ 1 ] ) ;
m_Buttons [ 2 ] = new QPushButton ( this ) ;
horizontalLayout - > addWidget ( m_Buttons [ 2 ] ) ;
gridLayout - > addLayout ( horizontalLayout , 2 , 0 , 1 , 1 ) ;
QLabel * label = new QLabel ( this ) ;
QSizePolicy sizePolicy ( QSizePolicy : : Ignored , QSizePolicy : : Expanding ) ;
sizePolicy . setHorizontalStretch ( 0 ) ;
sizePolicy . setVerticalStretch ( 0 ) ;
sizePolicy . setHeightForWidth ( label - > sizePolicy ( ) . hasHeightForWidth ( ) ) ;
label - > setSizePolicy ( sizePolicy ) ;
label - > setAlignment ( Qt : : AlignCenter ) ;
label - > setWordWrap ( true ) ;
label - > setText ( Message ) ;
connect ( label , SIGNAL ( linkActivated ( const QString & ) ) , theGUI , SLOT ( OpenUrl ( const QString & ) ) ) ;
gridLayout - > addWidget ( label , 1 , 0 , 1 , 1 ) ;
QLabel * logo = new QLabel ( this ) ;
logo - > setFrameShape ( QFrame : : StyledPanel ) ;
logo - > setFrameShadow ( QFrame : : Plain ) ;
//QPalette back = logo->palette();
//SetPaleteTexture(back, QPalette::Window, QImage(":/Assets/sandboxie-back.png"));
//logo->setPalette(back);
//logo->setAutoFillBackground(true);
logo - > setStyleSheet ( " background-image: url(:/Assets/sandboxie-back.png); " ) ;
logo - > setPixmap ( QPixmap : : fromImage ( QImage ( " :/Assets/sandboxie-logo.png " ) ) ) ;
logo - > setAlignment ( Qt : : AlignCenter ) ;
gridLayout - > addWidget ( logo , 0 , 0 , 1 , 1 ) ;
verticalLayout - > addLayout ( gridLayout ) ;
2022-09-29 17:28:48 +01:00
for ( int s = rand ( ) % 3 , i = 0 ; i < 3 ; i + + )
2022-08-09 17:19:46 +01:00
{
QPushButton * pButton = m_Buttons [ ( s + i ) % 3 ] ;
pButton - > setAutoDefault ( false ) ;
//pButton->setEnabled(false);
if ( i = = 1 & & NoGo )
pButton - > setEnabled ( false ) ;
if ( i = = 2 & & NoGo )
i = 3 ;
pButton - > setProperty ( " Action " , i ) ;
connect ( pButton , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnButton ( ) ) ) ;
}
m_CountDown = Wait ;
UpdateButtons ( ) ;
m_uTimerID = startTimer ( 1000 ) ;
}
CSupportDialog : : ~ CSupportDialog ( )
{
killTimer ( m_uTimerID ) ;
}
void CSupportDialog : : timerEvent ( QTimerEvent * pEvent )
{
if ( pEvent - > timerId ( ) ! = m_uTimerID )
return ;
if ( m_CountDown > = 0 )
UpdateButtons ( ) ;
}
void CSupportDialog : : UpdateButtons ( )
{
if ( m_CountDown - - > 0 )
m_Buttons [ 1 ] - > setText ( tr ( " %1 " ) . arg ( m_CountDown + 1 ) ) ;
else
{
for ( int i = 0 ; i < 3 ; i + + ) {
QPushButton * pButton = m_Buttons [ i ] ;
//pButton->setEnabled(true);
switch ( pButton - > property ( " Action " ) . toInt ( ) ) {
case 0 : pButton - > setText ( tr ( " Quit " ) ) ; break ;
case 1 : pButton - > setText ( tr ( " Continue " ) ) ; break ;
case 2 : pButton - > setText ( tr ( " Get Certificate " ) ) ; break ;
case 3 : pButton - > setText ( tr ( " Enter Certificate " ) ) ; break ;
}
}
}
}
void CSupportDialog : : OnButton ( )
{
int Action = ( ( QPushButton * ) sender ( ) ) - > property ( " Action " ) . toInt ( ) ;
if ( Action = = 3 ) {
CSettingsWindow * pSettingsWindow = new CSettingsWindow ( this ) ;
2023-07-08 10:46:29 +01:00
pSettingsWindow - > showTab ( " Support " , true ) ;
2022-08-09 17:19:46 +01:00
connect ( pSettingsWindow , & CSettingsWindow : : Closed , [ this ] ( ) {
2023-07-01 17:54:53 +01:00
# ifdef INSIDER_BUILD
2023-07-11 21:35:59 +01:00
if ( g_CertInfo . active & & ! CERT_IS_INSIDER ( g_CertInfo ) ) {
2023-07-01 17:54:53 +01:00
TArguments args = GetArguments ( g_Certificate , L ' \n ' , L ' : ' ) ;
if ( args . value ( " TYPE " ) . contains ( " PATREON " ) ) {
theGUI - > m_pUpdater - > UpdateCert ( true ) ;
2023-07-11 21:35:59 +01:00
if ( CERT_IS_INSIDER ( g_CertInfo ) ) {
2023-07-01 17:54:53 +01:00
accept ( ) ;
return ;
}
}
QMessageBox : : warning ( this , " Sandboxie-Plus " , tr ( " This Insider build requires a special certificate of type GREAT_PATREON, PERSONAL-HUGE, or CONTRIBUTOR. " ) ) ;
return ;
}
# endif
2023-07-11 21:35:59 +01:00
if ( g_CertInfo . active )
2022-08-09 17:19:46 +01:00
accept ( ) ;
} ) ;
}
else if ( Action = = 2 )
return theGUI - > OpenUrl ( QUrl ( " https://sandboxie-plus.com/go.php?to=sbie-get-cert " ) ) ;
else if ( Action = = 1 )
accept ( ) ;
else
reject ( ) ;
}