2020-11-28 16:20:56 +00:00
# include "stdafx.h"
# include "RecoveryWindow.h"
# include "SandMan.h"
# include "../MiscHelpers/Common/Settings.h"
# include "../MiscHelpers/Common/TreeItemModel.h"
# include "../MiscHelpers/Common/Common.h"
2021-09-09 19:35:29 +01:00
# if defined(Q_OS_WIN)
# include <wtypes.h>
# include <QAbstractNativeEventFilter>
# include <dbt.h>
# endif
2020-11-28 16:20:56 +00:00
CRecoveryWindow : : CRecoveryWindow ( const CSandBoxPtr & pBox , QWidget * parent )
: QDialog ( parent )
{
2021-01-26 20:58:43 +00: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 ) ;
2021-09-09 19:35:29 +01:00
//setWindowState(Qt::WindowActive);
SetForegroundWindow ( ( HWND ) QWidget : : winId ( ) ) ;
2021-01-26 20:58:43 +00:00
bool bAlwaysOnTop = theConf - > GetBool ( " Options/AlwaysOnTop " , false ) ;
this - > setWindowFlag ( Qt : : WindowStaysOnTopHint , bAlwaysOnTop ) ;
2021-09-09 19:35:29 +01:00
if ( ! bAlwaysOnTop ) {
SetWindowPos ( ( HWND ) this - > winId ( ) , HWND_TOPMOST , 0 , 0 , 0 , 0 , SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE ) ;
QTimer : : singleShot ( 100 , this , [ this ] ( ) {
SetWindowPos ( ( HWND ) this - > winId ( ) , HWND_NOTOPMOST , 0 , 0 , 0 , 0 , SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE ) ;
} ) ;
}
2020-11-28 16:20:56 +00:00
ui . setupUi ( this ) ;
this - > setWindowTitle ( tr ( " %1 - File Recovery " ) . arg ( pBox - > GetName ( ) ) ) ;
m_pBox = pBox ;
2021-01-18 12:04:14 +00:00
m_pCounter = NULL ;
2021-09-09 20:48:30 +01:00
m_LastTargetIndex = 0 ;
m_bTargetsChanged = false ;
2021-09-09 19:35:29 +01:00
m_bReloadPending = false ;
2020-11-28 16:20:56 +00:00
# ifdef WIN32
QStyle * pStyle = QStyleFactory : : create ( " windows " ) ;
ui . treeFiles - > setStyle ( pStyle ) ;
# endif
2021-01-18 12:04:14 +00:00
ui . treeFiles - > setExpandsOnDoubleClick ( false ) ;
2020-11-28 16:20:56 +00:00
ui . btnDeleteAll - > setVisible ( false ) ;
m_pFileModel = new CSimpleTreeModel ( ) ;
m_pFileModel - > SetUseIcons ( true ) ;
m_pFileModel - > AddColumn ( tr ( " File Name " ) , " FileName " ) ;
m_pFileModel - > AddColumn ( tr ( " File Size " ) , " FileSize " ) ;
m_pFileModel - > AddColumn ( tr ( " Full Path " ) , " DiskPath " ) ;
2021-09-09 19:35:29 +01:00
m_pSortProxy = new CSortFilterProxyModel ( false , this ) ;
2020-11-28 16:20:56 +00:00
m_pSortProxy - > setSortRole ( Qt : : EditRole ) ;
2021-09-09 19:35:29 +01:00
m_pSortProxy - > setSourceModel ( m_pFileModel ) ;
m_pSortProxy - > setDynamicSortFilter ( true ) ;
//ui.treeFiles->setItemDelegate(theGUI->GetItemDelegate());
2020-11-28 16:20:56 +00:00
2021-09-09 19:35:29 +01:00
ui . treeFiles - > setModel ( m_pSortProxy ) ;
( ( CSortFilterProxyModel * ) m_pSortProxy ) - > setView ( ui . treeFiles ) ;
2020-11-28 16:20:56 +00:00
ui . treeFiles - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
2021-09-09 19:35:29 +01:00
ui . treeFiles - > setSortingEnabled ( true ) ;
//ui.treeFiles->setUniformRowHeights(true);
2021-09-09 20:48:30 +01:00
ui . gridLayout - > addWidget ( new CFinder ( m_pSortProxy , this , true ) , 3 , 0 , 1 , 5 ) ;
2021-09-09 19:35:29 +01:00
ui . finder - > deleteLater ( ) ; // remove place holder
2020-11-28 16:20:56 +00:00
//connect(ui.treeFiles, SIGNAL(clicked(const QModelIndex&)), this, SLOT(UpdateSnapshot(const QModelIndex&)));
//connect(ui.treeFiles->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(UpdateSnapshot(const QModelIndex&)));
//connect(ui.treeFiles, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(OnSelectSnapshot()));
2021-01-30 18:10:49 +00:00
connect ( ui . btnAddFolder , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnAddFolder ( ) ) ) ;
2021-01-18 12:04:14 +00:00
connect ( ui . chkShowAll , SIGNAL ( clicked ( bool ) ) , this , SLOT ( FindFiles ( ) ) ) ;
2021-01-30 18:10:49 +00:00
connect ( ui . btnRefresh , SIGNAL ( clicked ( bool ) ) , this , SLOT ( FindFiles ( ) ) ) ;
connect ( ui . btnRecover , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnRecover ( ) ) ) ;
2021-09-09 20:48:30 +01:00
connect ( ui . cmbRecover , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( OnTargetChanged ( ) ) ) ;
2021-01-30 18:10:49 +00:00
connect ( ui . btnDeleteAll , SIGNAL ( clicked ( bool ) ) , this , SLOT ( OnDeleteAll ( ) ) ) ;
connect ( ui . btnClose , SIGNAL ( clicked ( bool ) ) , this , SLOT ( close ( ) ) ) ;
2020-11-28 16:20:56 +00:00
restoreGeometry ( theConf - > GetBlob ( " RecoveryWindow/Window_Geometry " ) ) ;
2021-09-09 19:35:29 +01:00
QByteArray Columns = theConf - > GetBlob ( " RecoveryWindow/TreeView_Columns " ) ;
2020-11-28 16:20:56 +00:00
if ( ! Columns . isEmpty ( ) )
ui . treeFiles - > header ( ) - > restoreState ( Columns ) ;
for ( int i = 0 ; i < m_pFileModel - > columnCount ( ) ; i + + )
m_pFileModel - > SetColumnEnabled ( i , true ) ;
foreach ( const QString & NtFolder , m_pBox - > GetTextList ( " RecoverFolder " , true , true ) )
{
2021-06-13 17:11:04 +01:00
bool bOk ;
QString Folder = theAPI - > Nt2DosPath ( NtFolder , & bOk ) ;
if ( bOk )
m_RecoveryFolders . append ( Folder ) ;
2020-11-28 16:20:56 +00:00
}
2021-09-09 19:35:29 +01:00
2021-09-09 20:48:30 +01:00
ui . cmbRecover - > addItem ( tr ( " Original location " ) , 0 ) ;
ui . cmbRecover - > addItem ( tr ( " Browse for location " ) , 1 ) ;
ui . cmbRecover - > addItem ( tr ( " Clear folder list " ) , - 1 ) ;
QStringList RecoverTargets = theAPI - > GetUserSettings ( ) - > GetTextList ( " SbieCtrl_RecoverTarget " , true ) ;
ui . cmbRecover - > insertItems ( ui . cmbRecover - > count ( ) - 1 , RecoverTargets ) ;
m_LastTargetIndex = theConf - > GetInt ( " RecoveryWindow/LastTarget " , - 1 ) ;
ui . chkRemember - > setChecked ( m_LastTargetIndex ! = - 1 ) ;
if ( m_LastTargetIndex = = - 1 )
m_LastTargetIndex = 0 ;
ui . cmbRecover - > setCurrentIndex ( m_LastTargetIndex ) ;
2020-11-28 16:20:56 +00:00
}
CRecoveryWindow : : ~ CRecoveryWindow ( )
{
theConf - > SetBlob ( " RecoveryWindow/Window_Geometry " , saveGeometry ( ) ) ;
2021-09-09 19:35:29 +01:00
theConf - > SetBlob ( " RecoveryWindow/TreeView_Columns " , ui . treeFiles - > header ( ) - > saveState ( ) ) ;
}
2020-11-28 16:20:56 +00:00
int CRecoveryWindow : : exec ( )
{
2021-07-05 12:37:28 +01:00
//QDialog::setWindowModality(Qt::WindowModal);
2020-11-28 16:20:56 +00:00
ui . btnDeleteAll - > setVisible ( true ) ;
return QDialog : : exec ( ) ;
}
void CRecoveryWindow : : closeEvent ( QCloseEvent * e )
{
2021-08-22 20:20:22 +01:00
emit Closed ( ) ;
2020-11-28 16:20:56 +00:00
this - > deleteLater ( ) ;
}
void CRecoveryWindow : : OnAddFolder ( )
{
2020-12-22 14:50:58 +00:00
QString Folder = QFileDialog : : getExistingDirectory ( this , tr ( " Select Directory " ) ) . replace ( " / " , " \\ " ) ; ;
2020-11-28 16:20:56 +00:00
if ( Folder . isEmpty ( ) )
return ;
if ( m_RecoveryFolders . contains ( Folder ) )
return ;
2021-01-18 12:04:14 +00:00
m_RecoveryFolders . append ( Folder ) ;
2020-11-28 16:20:56 +00:00
m_pBox - > AppendText ( " RecoverFolder " , Folder ) ;
2021-01-18 12:04:14 +00:00
FindFiles ( Folder ) ;
2020-11-28 16:20:56 +00:00
m_pFileModel - > Sync ( m_FileMap ) ;
ui . treeFiles - > expandAll ( ) ;
}
2021-09-09 20:48:30 +01:00
void CRecoveryWindow : : OnTargetChanged ( )
{
int op = ui . cmbRecover - > currentData ( ) . toInt ( ) ;
if ( op = = 1 )
{
QString Folder = QFileDialog : : getExistingDirectory ( this , tr ( " Select Directory " ) ) . replace ( " / " , " \\ " ) ;
if ( Folder . isEmpty ( ) ) {
ui . cmbRecover - > setCurrentIndex ( m_LastTargetIndex ) ;
2021-09-09 19:35:29 +01:00
return ;
}
2021-09-09 20:48:30 +01:00
m_LastTargetIndex = ui . cmbRecover - > count ( ) - 1 ;
ui . cmbRecover - > insertItem ( m_LastTargetIndex , Folder ) ;
ui . cmbRecover - > setCurrentIndex ( m_LastTargetIndex ) ;
m_bTargetsChanged = true ;
}
else if ( op = = - 1 )
{
while ( ui . cmbRecover - > count ( ) > 3 )
ui . cmbRecover - > removeItem ( 2 ) ;
ui . cmbRecover - > setCurrentIndex ( 0 ) ;
m_bTargetsChanged = true ;
2021-09-09 19:35:29 +01:00
}
2021-09-09 20:48:30 +01:00
else {
m_LastTargetIndex = ui . cmbRecover - > currentIndex ( ) ;
}
}
void CRecoveryWindow : : OnRecover ( )
{
if ( m_bTargetsChanged ) {
QStringList RecoverTargets ;
for ( int i = 2 ; i < ui . cmbRecover - > count ( ) - 1 ; i + + )
RecoverTargets . append ( ui . cmbRecover - > itemText ( i ) ) ;
theAPI - > GetUserSettings ( ) - > UpdateTextList ( " SbieCtrl_RecoverTarget " , RecoverTargets , true ) ;
}
theConf - > SetValue ( " RecoveryWindow/LastTarget " , ui . chkRemember - > isChecked ( ) ? m_LastTargetIndex : - 1 ) ;
QString RecoveryFolder ;
if ( ui . cmbRecover - > currentIndex ( ) > 0 )
RecoveryFolder = ui . cmbRecover - > currentText ( ) ;
2021-09-09 19:35:29 +01:00
2021-09-09 20:48:30 +01:00
RecoverFiles ( false , RecoveryFolder ) ;
2021-09-09 19:35:29 +01:00
}
2020-11-28 16:20:56 +00:00
void CRecoveryWindow : : OnDeleteAll ( )
{
this - > setResult ( 1 ) ;
this - > close ( ) ;
}
2021-09-09 19:35:29 +01:00
void CRecoveryWindow : : AddFile ( const QString & FilePath , const QString & BoxPath )
{
ui . chkShowAll - > setTristate ( true ) ;
if ( m_FileMap . isEmpty ( ) )
ui . chkShowAll - > setCheckState ( Qt : : PartiallyChecked ) ;
m_NewFiles . insert ( FilePath ) ;
if ( m_FileMap . isEmpty ( ) )
FindFiles ( ) ;
else if ( ! m_bReloadPending )
{
m_bReloadPending = true ;
QTimer : : singleShot ( 500 , this , SLOT ( FindFiles ( ) ) ) ;
}
}
2020-11-28 16:20:56 +00:00
int CRecoveryWindow : : FindFiles ( )
{
2021-09-09 19:35:29 +01:00
m_bReloadPending = false ;
if ( ! m_NewFiles . isEmpty ( ) ) {
ui . lblInfo - > setText ( tr ( " There are %1 new files available to recover. " ) . arg ( m_NewFiles . count ( ) ) ) ;
}
else if ( m_pCounter = = NULL ) {
2021-01-18 12:04:14 +00:00
m_pCounter = new CRecoveryCounter ( m_pBox - > GetFileRoot ( ) , this ) ;
connect ( m_pCounter , SIGNAL ( Count ( quint32 , quint32 , quint64 ) ) , this , SLOT ( OnCount ( quint32 , quint32 , quint64 ) ) ) ;
}
2020-11-28 16:20:56 +00:00
m_FileMap . clear ( ) ;
int Count = 0 ;
2021-01-18 12:04:14 +00:00
2021-09-09 19:35:29 +01:00
if ( ui . chkShowAll - > checkState ( ) = = Qt : : Checked )
2021-01-18 12:04:14 +00:00
{
2021-06-13 17:11:04 +01:00
//for(char drive = 'A'; drive <= 'Z'; drive++)
QDir Dir ( m_pBox - > GetFileRoot ( ) + " \\ drive \\ " ) ;
foreach ( const QFileInfo & Info , Dir . entryInfoList ( QDir : : Dirs | QDir : : NoDotAndDotDot ) )
Count + = FindBoxFiles ( " \\ drive \\ " + Info . fileName ( ) ) ;
2021-01-18 12:04:14 +00:00
if ( m_pBox - > GetBool ( " SeparateUserFolders " , true ) ) {
Count + = FindBoxFiles ( " \\ user \\ current " ) ;
Count + = FindBoxFiles ( " \\ user \\ all " ) ;
Count + = FindBoxFiles ( " \\ user \\ public " ) ;
}
2021-06-13 17:11:04 +01:00
//Count += FindBoxFiles("\\share");
QDir DirSvr ( m_pBox - > GetFileRoot ( ) + " \\ share \\ " ) ;
foreach ( const QFileInfo & InfoSrv , DirSvr . entryInfoList ( QDir : : Dirs | QDir : : NoDotAndDotDot ) ) {
QDir DirPub ( m_pBox - > GetFileRoot ( ) + " \\ share \\ " + InfoSrv . fileName ( ) ) ;
foreach ( const QFileInfo & InfoPub , DirPub . entryInfoList ( QDir : : Dirs | QDir : : NoDotAndDotDot ) )
Count + = FindBoxFiles ( " \\ share \\ " + InfoSrv . fileName ( ) + " \\ " + InfoPub . fileName ( ) ) ;
}
2021-01-18 12:04:14 +00:00
}
else
{
foreach ( const QString & Folder , m_RecoveryFolders )
Count + = FindFiles ( Folder ) ;
}
2020-11-28 16:20:56 +00:00
m_pFileModel - > Sync ( m_FileMap ) ;
ui . treeFiles - > expandAll ( ) ;
return Count ;
}
int CRecoveryWindow : : FindFiles ( const QString & Folder )
2021-01-18 12:04:14 +00:00
{
2021-06-13 17:11:04 +01:00
//int Count = 0;
//foreach(const QString & Path, theAPI->GetBoxedPath(m_pBox, Folder))
// Count += FindFiles(Folder, Path, Folder);
//return Count;
2021-09-09 19:35:29 +01:00
return FindFiles ( theAPI - > GetBoxedPath ( m_pBox , Folder ) , Folder , Folder ) . first ;
2021-01-18 12:04:14 +00:00
}
int CRecoveryWindow : : FindBoxFiles ( const QString & Folder )
{
2021-06-13 17:11:04 +01:00
QString RealFolder = theAPI - > GetRealPath ( m_pBox , m_pBox - > GetFileRoot ( ) + Folder ) ;
if ( RealFolder . isEmpty ( ) )
return 0 ;
2021-09-09 19:35:29 +01:00
return FindFiles ( m_pBox - > GetFileRoot ( ) + Folder , Folder , RealFolder ) . first ;
2021-01-18 12:04:14 +00:00
}
2021-09-09 19:35:29 +01:00
QPair < int , quint64 > CRecoveryWindow : : FindFiles ( const QString & BoxedFolder , const QString & RealFolder , const QString & Name , const QString & ParentID )
2020-11-28 16:20:56 +00:00
{
int Count = 0 ;
2021-09-09 19:35:29 +01:00
quint64 Size = 0 ;
QDir Dir ( BoxedFolder ) ;
foreach ( const QFileInfo & Info , Dir . entryInfoList ( QDir : : AllEntries ) )
{
QString Name = Info . fileName ( ) ;
if ( Name = = " . " | | Name = = " .. " )
continue ;
QString Path = Info . filePath ( ) . replace ( " / " , " \\ " ) ;
2020-11-28 16:20:56 +00:00
2021-09-09 19:35:29 +01:00
if ( Info . isFile ( ) )
2020-11-28 16:20:56 +00:00
{
2021-09-09 19:35:29 +01:00
QString RealPath = RealFolder + Path . mid ( BoxedFolder . length ( ) ) ;
if ( ! m_NewFiles . contains ( RealPath ) & & ui . chkShowAll - > checkState ( ) = = Qt : : PartiallyChecked )
2020-11-28 16:20:56 +00:00
continue ;
2021-09-09 19:35:29 +01:00
Count + + ;
Size + = Info . size ( ) ;
QVariantMap RecFile ;
RecFile [ " ID " ] = RealPath ;
RecFile [ " ParentID " ] = RealFolder ;
RecFile [ " FileName " ] = Name ;
RecFile [ " FileSize " ] = FormatSize ( Info . size ( ) ) ;
RecFile [ " DiskPath " ] = RealPath ;
RecFile [ " BoxPath " ] = Path ;
RecFile [ " Icon " ] = m_IconProvider . icon ( Info ) ;
m_FileMap . insert ( RealPath , RecFile ) ;
}
else
{
auto CountSize = FindFiles ( Path , RealFolder + " \\ " + Name , Name , RealFolder ) ;
Count + = CountSize . first ;
Size + = CountSize . second ;
}
}
2020-11-28 16:20:56 +00:00
2021-09-09 19:35:29 +01:00
if ( Count > 0 )
2020-11-28 16:20:56 +00:00
{
QVariantMap RecFolder ;
2021-09-09 19:35:29 +01:00
RecFolder [ " ID " ] = RealFolder ;
RecFolder [ " ParentID " ] = ParentID ;
RecFolder [ " FileName " ] = Name ;
RecFolder [ " FileSize " ] = FormatSize ( Size ) ;
RecFolder [ " DiskPath " ] = RealFolder ;
RecFolder [ " BoxPath " ] = BoxedFolder ;
RecFolder [ " Icon " ] = m_IconProvider . icon ( QFileIconProvider : : Folder ) ;
m_FileMap . insert ( RealFolder , RecFolder ) ;
2020-11-28 16:20:56 +00:00
}
2021-09-09 19:35:29 +01:00
return qMakePair ( Count , Size ) ;
2020-11-28 16:20:56 +00:00
}
2021-09-09 19:35:29 +01:00
void CRecoveryWindow : : RecoverFiles ( bool bBrowse , QString RecoveryFolder )
2020-11-28 16:20:56 +00:00
{
2021-06-13 17:11:04 +01:00
//bool HasShare = false;
2020-11-28 16:20:56 +00:00
QMap < QString , QString > FileMap ;
foreach ( const QModelIndex & Index , ui . treeFiles - > selectionModel ( ) - > selectedIndexes ( ) )
{
2021-09-09 19:35:29 +01:00
QModelIndex ModelIndex = m_pSortProxy - > mapToSource ( Index ) ;
QVariant ID = m_pFileModel - > GetItemID ( ModelIndex ) ;
//QVariant ID = m_pFileModel->GetItemID(Index);
2020-11-28 16:20:56 +00:00
QVariantMap File = m_FileMap . value ( ID ) ;
if ( File . isEmpty ( ) )
continue ;
2021-06-14 20:13:25 +01:00
if ( ! File [ " ParentID " ] . isNull ( ) )
{
2021-06-13 17:11:04 +01:00
//if (File["DiskPath"].toString().indexOf("\\device\\mup", 0, Qt::CaseInsensitive) == 0)
2021-06-14 20:13:25 +01:00
// HasShare = true;
2020-11-28 16:20:56 +00:00
FileMap [ File [ " BoxPath " ] . toString ( ) ] = File [ " DiskPath " ] . toString ( ) ;
2021-01-18 12:04:14 +00:00
}
2020-11-28 16:20:56 +00:00
else
{
for ( int i = 0 ; i < m_pFileModel - > rowCount ( Index ) ; i + + )
{
QModelIndex ChildIndex = m_pFileModel - > index ( i , 0 , Index ) ;
QVariant ChildID = m_pFileModel - > GetItemID ( ChildIndex ) ;
QVariantMap File = m_FileMap . value ( ChildID ) ;
if ( File . isEmpty ( ) )
continue ;
2021-06-13 17:11:04 +01:00
//if (File["DiskPath"].toString().indexOf("\\device\\mup") == 0)
// HasShare = true;
2020-11-28 16:20:56 +00:00
FileMap [ File [ " BoxPath " ] . toString ( ) ] = File [ " DiskPath " ] . toString ( ) ;
}
}
}
2021-06-14 20:13:25 +01:00
/*if (HasShare && !bBrowse) {
QMessageBox : : warning ( this , " Sandboxie-Plus " , tr ( " One or more selected files are located on a network share, and must be recovered to a local drive, please select a folder to recover all selected files to. " ) ) ;
bBrowse = true ;
} */
2021-09-09 19:35:29 +01:00
if ( bBrowse & & RecoveryFolder . isEmpty ( ) ) {
2021-06-14 20:13:25 +01:00
RecoveryFolder = QFileDialog : : getExistingDirectory ( this , tr ( " Select Directory " ) ) . replace ( " / " , " \\ " ) ;
2021-01-18 12:04:14 +00:00
if ( RecoveryFolder . isEmpty ( ) )
return ;
2021-09-09 19:35:29 +01:00
QStringList RecoverTargets = theAPI - > GetUserSettings ( ) - > GetTextList ( " SbieCtrl_RecoverTarget " , true ) ;
if ( ! RecoverTargets . contains ( RecoveryFolder ) )
theAPI - > GetUserSettings ( ) - > UpdateTextList ( " SbieCtrl_RecoverTarget " , RecoverTargets , true ) ;
2021-01-18 12:04:14 +00:00
}
2020-11-28 16:20:56 +00:00
2021-01-30 18:10:49 +00:00
2020-11-28 16:20:56 +00:00
QList < QPair < QString , QString > > FileList ;
for ( QMap < QString , QString > : : const_iterator I = FileMap . begin ( ) ; I ! = FileMap . end ( ) ; + + I )
{
2021-06-14 20:13:25 +01:00
QString BoxedFilePath = I . key ( ) ;
QString RecoveryPath = I . value ( ) ;
if ( ! RecoveryFolder . isEmpty ( ) )
{
QString FileName = RecoveryPath . mid ( RecoveryPath . lastIndexOf ( " \\ " ) + 1 ) ;
RecoveryPath = RecoveryFolder + " \\ " + FileName ;
2020-11-28 16:20:56 +00:00
}
FileList . append ( qMakePair ( BoxedFilePath , RecoveryPath ) ) ;
}
2021-01-30 18:10:49 +00:00
2020-11-28 16:20:56 +00:00
SB_PROGRESS Status = theGUI - > RecoverFiles ( FileList ) ;
if ( Status . GetStatus ( ) = = OP_ASYNC )
{
connect ( Status . GetValue ( ) . data ( ) , SIGNAL ( Finished ( ) ) , this , SLOT ( FindFiles ( ) ) ) ;
theGUI - > AddAsyncOp ( Status . GetValue ( ) ) ;
}
}
2021-01-18 12:04:14 +00:00
void CRecoveryWindow : : OnCount ( quint32 fileCount , quint32 folderCount , quint64 totalSize )
{
2021-06-14 20:13:25 +01:00
ui . lblInfo - > setText ( tr ( " There are %1 files and %2 folders in the sandbox, occupying %3 of disk space. " ) . arg ( fileCount ) . arg ( folderCount ) . arg ( FormatSize ( totalSize ) ) ) ;
2021-01-18 12:04:14 +00:00
}
void CRecoveryCounter : : run ( )
{
quint32 fileCount = 0 ;
quint32 folderCount = 0 ;
quint64 totalSize = 0 ;
QStringList Folders ;
Folders . append ( m_BoxPath ) ;
do {
if ( ! m_run ) break ;
QDir Dir ( Folders . takeFirst ( ) ) ;
foreach ( const QFileInfo & Info , Dir . entryInfoList ( QDir : : AllEntries ) )
{
if ( ! m_run ) break ;
QString Name = Info . fileName ( ) ;
if ( Name = = " . " | | Name = = " .. " )
continue ;
QString Path = Info . filePath ( ) . replace ( " / " , " \\ " ) ;
if ( Info . isFile ( ) )
{
fileCount + + ;
totalSize + = Info . size ( ) ;
}
else
{
Folders . append ( Path ) ;
folderCount + + ;
}
}
emit Count ( fileCount , folderCount , totalSize ) ;
} while ( ! Folders . isEmpty ( ) ) ;
}