From 24a13cc3b36c699fd2027af50b274abe4cbdf3dd Mon Sep 17 00:00:00 2001 From: DavidXanatos Date: Mon, 16 May 2022 21:30:40 +0200 Subject: [PATCH] 1.1.0 --- .../MiscHelpers/Common/ListItemModel.cpp | 4 +- .../MiscHelpers/Common/ListItemModel.h | 2 +- .../MiscHelpers/Common/TreeItemModel.cpp | 4 +- .../MiscHelpers/Common/TreeItemModel.h | 2 +- .../QSbieAPI/Sandboxie/BoxBorder.cpp | 2 +- SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp | 9 +- SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h | 2 + SandboxiePlus/QSbieAPI/SbieAPI.cpp | 49 ++++-- SandboxiePlus/QSbieAPI/SbieAPI.h | 8 +- SandboxiePlus/SandMan/BoxMonitor.cpp | 129 ++++++++++++++ SandboxiePlus/SandMan/BoxMonitor.h | 49 ++++++ SandboxiePlus/SandMan/Forms/SettingsWindow.ui | 161 +++++++++--------- SandboxiePlus/SandMan/Models/MonitorModel.cpp | 4 +- SandboxiePlus/SandMan/Models/SbieModel.cpp | 23 +-- SandboxiePlus/SandMan/Models/SbieModel.h | 7 +- SandboxiePlus/SandMan/Models/TraceModel.cpp | 20 +-- SandboxiePlus/SandMan/SandMan.cpp | 23 ++- SandboxiePlus/SandMan/SandMan.h | 2 + SandboxiePlus/SandMan/SandMan.pri | 2 + SandboxiePlus/SandMan/SandMan.vcxproj | 7 + SandboxiePlus/SandMan/SandMan.vcxproj.filters | 21 +++ SandboxiePlus/SandMan/SbiePlusAPI.cpp | 56 +++++- SandboxiePlus/SandMan/SbiePlusAPI.h | 15 ++ SandboxiePlus/SandMan/Views/SbieView.cpp | 7 +- SandboxiePlus/SandMan/Views/SbieView.h | 3 + .../SandMan/Windows/SettingsWindow.cpp | 4 + SandboxiePlus/SandMan/stdafx.h | 1 + 27 files changed, 483 insertions(+), 133 deletions(-) create mode 100644 SandboxiePlus/SandMan/BoxMonitor.cpp create mode 100644 SandboxiePlus/SandMan/BoxMonitor.h diff --git a/SandboxiePlus/MiscHelpers/Common/ListItemModel.cpp b/SandboxiePlus/MiscHelpers/Common/ListItemModel.cpp index 088d55c1..91a847b2 100644 --- a/SandboxiePlus/MiscHelpers/Common/ListItemModel.cpp +++ b/SandboxiePlus/MiscHelpers/Common/ListItemModel.cpp @@ -69,7 +69,7 @@ void CSimpleListModel::Sync(QList List) Changed = true; ColValue.Raw = Value; - //ColValue.Formated = + //ColValue.Formatted = } if(State != Changed) @@ -195,7 +195,7 @@ QVariant CListItemModel::Data(const QModelIndex &index, int role, int section) c case Qt::DisplayRole: { SListNode::SValue& Value = pNode->Values[section]; - return Value.Formated.isValid() ? Value.Formated : Value.Raw; + return Value.Formatted.isValid() ? Value.Formatted : Value.Raw; } case Qt::EditRole: // sort role { diff --git a/SandboxiePlus/MiscHelpers/Common/ListItemModel.h b/SandboxiePlus/MiscHelpers/Common/ListItemModel.h index d30eb435..513d0d93 100644 --- a/SandboxiePlus/MiscHelpers/Common/ListItemModel.h +++ b/SandboxiePlus/MiscHelpers/Common/ListItemModel.h @@ -56,7 +56,7 @@ protected: struct SValue { QVariant Raw; - QVariant Formated; + QVariant Formatted; }; QVector Values; }; diff --git a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp index 20aaae62..4a6cae2a 100644 --- a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp +++ b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.cpp @@ -110,7 +110,7 @@ void CSimpleTreeModel::Sync(const QMap& List) Changed = true; ColValue.Raw = Value; - //ColValue.Formated = + //ColValue.Formatted = } if(State != Changed) @@ -385,7 +385,7 @@ QVariant CTreeItemModel::NodeData(STreeNode* pNode, int role, int section) const case Qt::DisplayRole: { STreeNode::SValue& Value = pNode->Values[section]; - return Value.Formated.isValid() ? Value.Formated : Value.Raw; + return Value.Formatted.isValid() ? Value.Formatted : Value.Raw; } case Qt::EditRole: // sort role { diff --git a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h index 727ba047..e82e8ef1 100644 --- a/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h +++ b/SandboxiePlus/MiscHelpers/Common/TreeItemModel.h @@ -80,7 +80,7 @@ protected: { QVariant Raw; QVariant SortKey; - QVariant Formated; + QVariant Formatted; }; QVector Values; }; diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/BoxBorder.cpp b/SandboxiePlus/QSbieAPI/Sandboxie/BoxBorder.cpp index c6f89b3c..3d108cd9 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/BoxBorder.cpp +++ b/SandboxiePlus/QSbieAPI/Sandboxie/BoxBorder.cpp @@ -106,7 +106,7 @@ CBoxBorder::CBoxBorder(CSbieAPI* pApi, QObject* parent) : QObject(parent) SetLayeredWindowAttributes(m->BorderWnd, 0, 192, LWA_ALPHA); ::ShowWindow(m->BorderWnd, SW_HIDE); - m_uTimerID = startTimer(10); + m_uTimerID = startTimer(100); } CBoxBorder::~CBoxBorder() diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp index e765ec8e..2710c812 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp +++ b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp @@ -119,6 +119,13 @@ void CSandBox::UpdateDetails() { } +void CSandBox::SetBoxPaths(const QString& FilePath, const QString& RegPath, const QString& IpcPath) +{ + m_FilePath = FilePath; + m_RegPath = RegPath; + m_IpcPath = IpcPath; +} + SB_STATUS CSandBox::RunStart(const QString& Command, bool Elevated) { #ifdef _DEBUG @@ -140,7 +147,7 @@ SB_STATUS CSandBox::TerminateAll() bool CSandBox::IsEmpty() const { - return !QDir(m_FilePath).exists(); + return !QFile::exists(m_FilePath); } SB_PROGRESS CSandBox::CleanBox() diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h index 78bf06b5..c2556e61 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h +++ b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h @@ -42,6 +42,7 @@ public: virtual void UpdateDetails(); + virtual void SetBoxPaths(const QString& FilePath, const QString& RegPath, const QString& IpcPath); virtual QString GetFileRoot() const { return m_FilePath; } virtual QString GetRegRoot() const { return m_RegPath; } virtual QString GetIpcRoot() const { return m_IpcPath; } @@ -54,6 +55,7 @@ public: virtual SB_STATUS RunSandboxed(const QString& Command); virtual SB_STATUS TerminateAll(); + virtual void OpenBox() {} virtual void CloseBox() {} virtual bool IsEnabled() const { return m_IsEnabled; } diff --git a/SandboxiePlus/QSbieAPI/SbieAPI.cpp b/SandboxiePlus/QSbieAPI/SbieAPI.cpp index b07fb619..fa6e8d99 100644 --- a/SandboxiePlus/QSbieAPI/SbieAPI.cpp +++ b/SandboxiePlus/QSbieAPI/SbieAPI.cpp @@ -129,7 +129,9 @@ CSbieAPI::CSbieAPI(QObject* parent) : QThread(parent) m_pGlobalSection = new CSbieIni("GlobalSettings", this, this); m_pUserSection = new CSbieIni("UserSettings", this, this); // dummy + m_IniReLoad = false; m_bReloadPending = false; + m_bBoxesDirty = false; m_LastTraceEntry = 0; @@ -357,6 +359,7 @@ SB_STATUS CSbieAPI::Disconnect() m_SandBoxes.clear(); m_BoxedProxesses.clear(); + m_bBoxesDirty = true; emit StatusChanged(); return SB_OK; @@ -786,10 +789,12 @@ SB_STATUS CSbieAPI::TakeOver() return SB_OK; } -SB_STATUS CSbieAPI::WatchIni(bool bEnable) +SB_STATUS CSbieAPI::WatchIni(bool bEnable, bool bReLoad) { - if (bEnable) + if (bEnable) { m_IniWatcher.addPath(m_IniPath); + m_IniReLoad = bReLoad; + } else m_IniWatcher.removePath(m_IniPath); return SB_OK; @@ -807,7 +812,9 @@ void CSbieAPI::OnIniChanged(const QString &path) void CSbieAPI::OnReloadConfig() { m_bReloadPending = false; - ReloadConfig(); + m_bBoxesDirty = true; + if (m_IniReLoad) + ReloadConfig(); } typedef struct _FILE_FS_VOLUME_INFORMATION { @@ -1115,13 +1122,17 @@ quint32 CSbieAPI::GetSessionID() const return m->sessionId; } -SB_STATUS CSbieAPI::ReloadBoxes(bool bFullUpdate) +SB_STATUS CSbieAPI::ReloadBoxes(bool bForceUpdate) { + if (bForceUpdate || (!m_bBoxesDirty && !m_IniWatcher.files().isEmpty())) + return SB_OK; + m_bBoxesDirty = false; + QMap OldSandBoxes = m_SandBoxes; for (int i = 0;;i++) { - QString BoxName = SbieIniGet(QString(), QString(), (i | CONF_GET_NO_EXPAND)); + QString BoxName = SbieIniGet(QString(), QString(), (i | CONF_GET_NO_EXPAND | CONF_GET_NO_TEMPLS)); if (BoxName.isNull()) break; @@ -1134,10 +1145,8 @@ SB_STATUS CSbieAPI::ReloadBoxes(bool bFullUpdate) { pBox = CSandBoxPtr(NewSandBox(BoxName, this)); m_SandBoxes.insert(BoxName.toLower(), pBox); - UpdateBoxPaths(pBox); } - else if(bFullUpdate) - UpdateBoxPaths(pBox); + UpdateBoxPaths(pBox); pBox->m_IsEnabled = bIsEnabled; @@ -1238,6 +1247,8 @@ void CSbieAPI::CommitIniChanges() SbieIniSet("", "", ""); // commit and refresh if (bRemoved) m_IniWatcher.addPath(m_IniPath); + + m_bBoxesDirty = true; } QString CSbieAPI::SbieIniGetEx(const QString& Section, const QString& Setting) @@ -1405,6 +1416,12 @@ SB_STATUS CSbieAPI::UpdateProcesses(bool bKeep, bool bAllSessions) if (pBox.isNull()) continue; + if (pBox->m_ActiveProcessCount == 0) { + pBox->m_ActiveProcessCount = 1; + pBox->OpenBox(); + emit BoxOpened(pBox->GetName()); + } + pProcess->m_pBox = pBox.data(); pBox->m_ProcessList.insert(ProcessId, pProcess); m_BoxedProxesses.insert(ProcessId, pProcess); @@ -1569,9 +1586,11 @@ SB_STATUS CSbieAPI::UpdateBoxPaths(const CSandBoxPtr& pSandBox) if (!Status) return Status; - pSandBox->m_FilePath = Nt2DosPath(QString::fromWCharArray(FileRoot.c_str(), wcslen(FileRoot.c_str()))); - pSandBox->m_RegPath = QString::fromWCharArray(KeyRoot.c_str(), wcslen(KeyRoot.c_str())); - pSandBox->m_IpcPath = QString::fromWCharArray(IpcRoot.c_str(), wcslen(IpcRoot.c_str())); + QString FilePath = Nt2DosPath(QString::fromWCharArray(FileRoot.c_str(), wcslen(FileRoot.c_str()))); + QString RegPath = QString::fromWCharArray(KeyRoot.c_str(), wcslen(KeyRoot.c_str())); + QString IpcPath = QString::fromWCharArray(IpcRoot.c_str(), wcslen(IpcRoot.c_str())); + + pSandBox->SetBoxPaths(FilePath, RegPath, IpcPath); return SB_OK; } @@ -2048,7 +2067,7 @@ SB_STATUS CSbieAPI::ReloadConf(quint32 flags, quint32 SessionId) //emit LogMessage("Sandboxie config has been reloaded.", false); emit LogSbieMessage(0, QStringList() << "Sandboxie config has been reloaded" << "" << "", 4); - ReloadBoxes(true); + m_bBoxesDirty = true; return SB_OK; } @@ -2318,6 +2337,12 @@ CBoxedProcessPtr CSbieAPI::OnProcessBoxed(quint32 ProcessId, const QString& Path if (!pBox) return CBoxedProcessPtr(); + if (pBox->m_ActiveProcessCount == 0) { + pBox->m_ActiveProcessCount = 1; + pBox->OpenBox(); + emit BoxOpened(pBox->GetName()); + } + pProcess = CBoxedProcessPtr(NewBoxedProcess(ProcessId, pBox.data())); pBox->m_ProcessList.insert(ProcessId, pProcess); m_BoxedProxesses.insert(ProcessId, pProcess); diff --git a/SandboxiePlus/QSbieAPI/SbieAPI.h b/SandboxiePlus/QSbieAPI/SbieAPI.h index 66d63879..fbd0dfcd 100644 --- a/SandboxiePlus/QSbieAPI/SbieAPI.h +++ b/SandboxiePlus/QSbieAPI/SbieAPI.h @@ -47,7 +47,7 @@ public: virtual QString GetVersion(); virtual SB_STATUS TakeOver(); - virtual SB_STATUS WatchIni(bool bEnable = true); + virtual SB_STATUS WatchIni(bool bEnable = true, bool bReLoad = true); virtual QString GetSbiePath() const { return m_SbiePath; } virtual QString GetIniPath() const { return m_IniPath; } @@ -57,7 +57,7 @@ public: virtual void UpdateDriveLetters(); virtual QString Nt2DosPath(QString NtPath, bool* pOk = NULL) const; - virtual SB_STATUS ReloadBoxes(bool bFullUpdate = false); + virtual SB_STATUS ReloadBoxes(bool bForceUpdate = false); static SB_STATUS ValidateName(const QString& BoxName); virtual SB_STATUS CreateBox(const QString& BoxName, bool bReLoad = true); @@ -158,6 +158,7 @@ signals: void LogSbieMessage(quint32 MsgCode, const QStringList& MsgData, quint32 ProcessId); void ProcessBoxed(quint32 ProcessId, const QString& Path, const QString& Box, quint32 ParentId); void FileToRecover(const QString& BoxName, const QString& FilePath, const QString& BoxPath, quint32 ProcessId); + void BoxOpened(const QString& BoxName); void BoxClosed(const QString& BoxName); void NotAuthorized(bool bLoginRequired, bool &bRetry); void QueuedRequest(quint32 ClientPid, quint32 ClientTid, quint32 RequestId, const QVariantMap& Data); @@ -228,8 +229,9 @@ protected: QString m_SbiePath; QString m_IniPath; QFileSystemWatcher m_IniWatcher; - + bool m_IniReLoad; bool m_bReloadPending; + bool m_bBoxesDirty; bool m_bWithQueue; bool m_bTerminate; diff --git a/SandboxiePlus/SandMan/BoxMonitor.cpp b/SandboxiePlus/SandMan/BoxMonitor.cpp new file mode 100644 index 00000000..70d141de --- /dev/null +++ b/SandboxiePlus/SandMan/BoxMonitor.cpp @@ -0,0 +1,129 @@ +#include "stdafx.h" +#include "BoxMonitor.h" +#include "MiscHelpers/Common/Common.h" + +CBoxMonitor::CBoxMonitor() +{ + m_bTerminate = false; + start(); +} + +CBoxMonitor::~CBoxMonitor() +{ + m_bTerminate = true; + if (!wait(10 * 1000)) + terminate(); +} + +void CBoxMonitor::Notify(const wstring& strDirectory) +{ + m_Mutex.lock(); + m_Boxes[QString::fromStdWString(strDirectory)].Changed = true; + m_Mutex.unlock(); +} + +quint64 CBoxMonitor::CounDirSize(const QString& Directory, SBox* Box) +{ + quint64 TotalSize = 0; + if (Box->pBox.isNull() || m_bTerminate) + return TotalSize; + + QDir Dir(Directory); + foreach(const QFileInfo & Info, Dir.entryInfoList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot)) + { + if (Info.isDir()) + TotalSize += CounDirSize(Info.filePath(), Box); + else + TotalSize += QFile(Info.filePath()).size(); + } + + return TotalSize; +} + +void CBoxMonitor::run() +{ + while (!m_bTerminate) + { + m_Mutex.lock(); + QList Keys = m_Boxes.keys(); + m_Mutex.unlock(); + + quint64 CurTick = GetCurTick(); + + foreach(const QString& Key, Keys) { + + m_Mutex.lock(); + SBox* Box = &m_Boxes[Key]; + m_Mutex.unlock(); + + quint64 MinScanInterval = Box->ScanDuration * 100; + if (MinScanInterval < 30 * 1000) + MinScanInterval = 30 * 1000; + if (MinScanInterval > 30 * 60 * 1000) + MinScanInterval = 30 * 60 * 1000; + + if (Box->Changed && (Box->Closed || Box->LastScan == 0 || (CurTick - Box->LastScan) > MinScanInterval)) { + + qDebug() << "Rescanning:" << Key << "(" + QDateTime::currentDateTime().toString() + ")"; + + quint64 ScanStart = GetCurTick(); + + Box->TotalSize = CounDirSize(Key, Box); + + Box->ScanDuration = GetCurTick() - ScanStart; + Box->LastScan = GetCurTick(); + + QMetaObject::invokeMethod(this, "UpdateBox", Qt::QueuedConnection, + //Q_RETURN_ARG(int, retVal), + Q_ARG(QString, Key) + ); + + Box->Changed = false; + } + + m_Mutex.lock(); + if (Box->pBox.isNull()) + m_Boxes.remove(Key); + m_Mutex.unlock(); + } + + Sleep(1000); + } +} + +void CBoxMonitor::UpdateBox(const QString& Path) +{ + // Note: this functin runs in the main thread + + m_Mutex.lock(); + SBox Box = m_Boxes.value(Path); + m_Mutex.unlock(); + + if (Box.pBox) + Box.pBox->SetSize(Box.TotalSize); +} + +void CBoxMonitor::AddBox(CSandBoxPlus* pBox, bool AndWatch) +{ + QMutexLocker Lock(&m_Mutex); + + m_Boxes[pBox->GetFileRoot()].pBox = pBox; + + if (AndWatch) { + m_Boxes[pBox->GetFileRoot()].Closed = false; + AddDirectory(pBox->GetFileRoot().toStdWString().c_str(), true, FILE_NOTIFY_CHANGE_SIZE); + } + else + m_Boxes[pBox->GetFileRoot()].Changed = true; +} + +void CBoxMonitor::CloseBox(CSandBoxPlus* pBox, bool AndClear) +{ + QMutexLocker Lock(&m_Mutex); + + if(AndClear) + m_Boxes[pBox->GetFileRoot()].pBox.clear(); + m_Boxes[pBox->GetFileRoot()].Closed = true; + + DetachDirectory(pBox->GetFileRoot().toStdWString().c_str()); +} \ No newline at end of file diff --git a/SandboxiePlus/SandMan/BoxMonitor.h b/SandboxiePlus/SandMan/BoxMonitor.h new file mode 100644 index 00000000..3862c557 --- /dev/null +++ b/SandboxiePlus/SandMan/BoxMonitor.h @@ -0,0 +1,49 @@ +#pragma once + +#include "Helpers/ReadDirectoryChanges.h" +#include "SbiePlusAPI.h" + +class CBoxMonitor : public QThread, public CReadDirectoryChanges +{ + Q_OBJECT +public: + CBoxMonitor(); + ~CBoxMonitor(); + + virtual void Notify(const wstring& strDirectory); + + virtual void run(); + + void AddBox(CSandBoxPlus* pBox, bool AndWatch = false); + void CloseBox(CSandBoxPlus* pBox, bool AndClear = false); + +private slots: + void UpdateBox(const QString& Path); + +protected: + + struct SBox + { + SBox() { + Changed = false; + Closed = false; + LastScan = 0; + ScanDuration = 0; + TotalSize = 0; + } + + QPointer pBox; + bool Changed; + bool Closed; + quint64 LastScan; + quint64 ScanDuration; + + quint64 TotalSize; + }; + + quint64 CounDirSize(const QString& Dir, SBox* Box); + + QMutex m_Mutex; + QMap m_Boxes; + bool m_bTerminate; +}; \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Forms/SettingsWindow.ui b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui index e6f1d321..7ad35bab 100644 --- a/SandboxiePlus/SandMan/Forms/SettingsWindow.ui +++ b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui @@ -54,6 +54,42 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Show Notifications for relevant log Messages + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -68,83 +104,6 @@ - - - - Run box operations asynchronously whenever possible (like content deletion) - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Show first recovery window when emptying sandboxes - - - - - - - Use Dark Theme (fully applied after a restart) - - - true - - - - - - - Watch Sandboxie.ini for changes - - - - - - - Show Notifications for relevant log Messages - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Show recoverable files as notifications - - - @@ -155,6 +114,13 @@ + + + + Run box operations asynchronously whenever possible (like content deletion) + + + @@ -165,6 +131,16 @@ + + + + Show first recovery window when emptying sandboxes + + + + + + @@ -179,6 +155,37 @@ + + + + Use Dark Theme (fully applied after a restart) + + + true + + + + + + + Watch Sandboxie.ini for changes + + + + + + + Show recoverable files as notifications + + + + + + + Count and display the disk space ocupied by each sandbox + + + diff --git a/SandboxiePlus/SandMan/Models/MonitorModel.cpp b/SandboxiePlus/SandMan/Models/MonitorModel.cpp index 3f60c1eb..5800c4f1 100644 --- a/SandboxiePlus/SandMan/Models/MonitorModel.cpp +++ b/SandboxiePlus/SandMan/Models/MonitorModel.cpp @@ -71,8 +71,8 @@ QList CMonitorModel::Sync(const QMap& Entry /*switch (section) { - //case eType: ColValue.Formated = ; break; - //case eValue: ColValue.Formated = ; break; + //case eType: ColValue.Formatted = ; break; + //case eValue: ColValue.Formatted = ; break; }*/ } diff --git a/SandboxiePlus/SandMan/Models/SbieModel.cpp b/SandboxiePlus/SandMan/Models/SbieModel.cpp index 662db661..76a33317 100644 --- a/SandboxiePlus/SandMan/Models/SbieModel.cpp +++ b/SandboxiePlus/SandMan/Models/SbieModel.cpp @@ -2,7 +2,6 @@ #include "SbieModel.h" #include "../../MiscHelpers/Common/Common.h" #include "../../MiscHelpers/Common/IconExtreactor.h" -#include #include "../SandMan.h" CSbieModel::CSbieModel(QObject *parent) @@ -114,6 +113,8 @@ QList CSbieModel::Sync(const QMap& BoxList, cons QMap, QList > New; QHash Old = m_Map; + bool bWatchSize = theConf->GetBool("Options/WatchBoxSize", false); + foreach(const QString& Group, Groups.keys()) { if (Group.isEmpty()) @@ -232,6 +233,7 @@ QList CSbieModel::Sync(const QMap& BoxList, cons { case eName: Value = pBox->GetName(); break; case eStatus: Value = pBox.objectCast()->GetStatusStr(); break; + case eInfo: Value = bWatchSize ? pBox.objectCast()->GetSize() : 0; break; case ePath: Value = pBox->GetFileRoot(); break; } @@ -245,7 +247,8 @@ QList CSbieModel::Sync(const QMap& BoxList, cons switch (section) { - case eName: ColValue.Formated = Value.toString().replace("_", " "); break; + case eName: ColValue.Formatted = Value.toString().replace("_", " "); break; + case eInfo: ColValue.Formatted = Value.toULongLong() > 0 ? FormatSize(Value.toULongLong()) : ""; break; } } @@ -273,8 +276,6 @@ bool CSbieModel::Sync(const CSandBoxPtr& pBox, const QList& Path, cons int ActiveCount = 0; - QFileIconProvider IconProvider; - foreach(const CBoxedProcessPtr& pProc, ProcessList) { QSharedPointer pProcess = pProc.objectCast(); @@ -326,7 +327,7 @@ bool CSbieModel::Sync(const CSandBoxPtr& pBox, const QList& Path, cons //else // pNode->Icon = icons.first().pixmap; - pNode->Icon = IconProvider.icon(QFileInfo(pProcess->GetFileName())); + pNode->Icon = m_IconProvider.icon(QFileInfo(pProcess->GetFileName())); if (pNode->Icon.isNull() || !pNode->Icon.isValid()) pNode->Icon = m_ExeIcon; Changed = 1; @@ -345,7 +346,7 @@ bool CSbieModel::Sync(const CSandBoxPtr& pBox, const QList& Path, cons case eStatus: Value = pProcess->GetStatusStr(); break; case eTitle: Value = theAPI->GetProcessTitle(pProcess->GetProcessId()); break; //case eLogCount: break; // todo Value = pProcess->GetResourceLog().count(); break; - case eTimeStamp: Value = pProcess->GetTimeStamp(); break; + case eInfo: Value = pProcess->GetTimeStamp(); break; //case ePath: Value = pProcess->GetFileName(); break; case ePath: { QString CmdLine = pProcess->GetCommandLine(); @@ -364,9 +365,9 @@ bool CSbieModel::Sync(const CSandBoxPtr& pBox, const QList& Path, cons switch (section) { - case eProcessId: ColValue.Formated = QString::number(pProcess->GetProcessId()); break; - //case eLogCount: ColValue.Formated = QString::number(Value.toInt()); break; - case eTimeStamp: ColValue.Formated = pProcess->GetTimeStamp().toString("hh:mm:ss"); break; + case eProcessId: ColValue.Formatted = QString::number(pProcess->GetProcessId()); break; + //case eLogCount: ColValue.Formatted = QString::number(Value.toInt()); break; + case eInfo: ColValue.Formatted = pProcess->GetTimeStamp().toString("hh:mm:ss"); break; } } @@ -475,8 +476,10 @@ QVariant CSbieModel::headerData(int section, Qt::Orientation orientation, int ro case eProcessId: return tr("Process ID"); case eStatus: return tr("Status"); case eTitle: return tr("Title"); + case eInfo: return tr("Info"); + //case eSize: return tr("Size"); //case eLogCount: return tr("Log Count"); - case eTimeStamp: return tr("Start Time"); + //case eTimeStamp: return tr("Start Time"); case ePath: return tr("Path / Command Line"); } } diff --git a/SandboxiePlus/SandMan/Models/SbieModel.h b/SandboxiePlus/SandMan/Models/SbieModel.h index e78d808c..d6884379 100644 --- a/SandboxiePlus/SandMan/Models/SbieModel.h +++ b/SandboxiePlus/SandMan/Models/SbieModel.h @@ -4,7 +4,7 @@ #include "../SbieProcess.h" #include "../../MiscHelpers/Common/TreeItemModel.h" #include - +#include class CSbieModel : public CTreeItemModel { @@ -45,8 +45,10 @@ public: eProcessId, eTitle, eStatus, + eInfo, + //eSize, //eLogCount, - eTimeStamp, + //eTimeStamp, ePath, eCount }; @@ -92,4 +94,5 @@ private: QIcon m_ExeIcon; QString m_SbieModelMimeType; + QFileIconProvider m_IconProvider; }; \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Models/TraceModel.cpp b/SandboxiePlus/SandMan/Models/TraceModel.cpp index 906d3749..913ffb4b 100644 --- a/SandboxiePlus/SandMan/Models/TraceModel.cpp +++ b/SandboxiePlus/SandMan/Models/TraceModel.cpp @@ -155,20 +155,20 @@ QList CTraceModel::Sync(const QVector& EntryList, int /*case eProcess: { CBoxedProcessPtr pProcess = theAPI->GetProcessById(pEntry->GetProcessId()); - ColValue.Formated = QString("%1 (%2, %3)").arg(pProcess.isNull() ? tr("Unknown") : pProcess->GetProcessName()).arg(pEntry->GetProcessId()).arg(pEntry->GetThreadId()); + ColValue.Formatted = QString("%1 (%2, %3)").arg(pProcess.isNull() ? tr("Unknown") : pProcess->GetProcessName()).arg(pEntry->GetProcessId()).arg(pEntry->GetThreadId()); break; } - case eTimeStamp: ColValue.Formated = pEntry->GetTimeStamp().toString("hh:mm:ss.zzz"); break;*/ + case eTimeStamp: ColValue.Formatted = pEntry->GetTimeStamp().toString("hh:mm:ss.zzz"); break;*/ case eProcess: if(!m_bTree) { QString Name = pEntry->GetProcessName(); - ColValue.Formated = QString("%1 (%2, %3) - %4").arg(Name.isEmpty() ? tr("Unknown") : Name) + ColValue.Formatted = QString("%1 (%2, %3) - %4").arg(Name.isEmpty() ? tr("Unknown") : Name) .arg(pEntry->GetProcessId()).arg(pEntry->GetThreadId()).arg(pEntry->GetTimeStamp().toString("hh:mm:ss.zzz")); } else - ColValue.Formated = pEntry->GetTimeStamp().toString("hh:mm:ss.zzz"); + ColValue.Formatted = pEntry->GetTimeStamp().toString("hh:mm:ss.zzz"); break; - //case eType: ColValue.Formated = ; break; - //case eValue: ColValue.Formated = ; break; + //case eType: ColValue.Formatted = ; break; + //case eValue: ColValue.Formatted = ; break; } } @@ -252,9 +252,9 @@ CTraceModel::STreeNode* CTraceModel::MkVirtualNode(const QVariant& Id, STreeNode QString Name = GetProcessName(pid); pNode->Values[0].Raw = pid; if(!Name.isEmpty()) - pNode->Values[0].Formated = tr("%1 (%2)").arg(Name).arg(pid); + pNode->Values[0].Formatted = tr("%1 (%2)").arg(Name).arg(pid); else - pNode->Values[0].Formated = tr("Process %1").arg(pid); + pNode->Values[0].Formatted = tr("Process %1").arg(pid); } else if (typeId.first == "tid") { @@ -262,10 +262,10 @@ CTraceModel::STreeNode* CTraceModel::MkVirtualNode(const QVariant& Id, STreeNode quint32 pid = Split2(pParent->ID.toString(), "_").second.toUInt(); LogThreadId(pid, tid); pNode->Values[0].Raw = tid; - pNode->Values[0].Formated = tr("Thread %1").arg(tid); + pNode->Values[0].Formatted = tr("Thread %1").arg(tid); } else*/ - pNode->Values[0].Raw = pNode->Values[0].Formated = Id; + pNode->Values[0].Raw = pNode->Values[0].Formatted = Id; return pNode; } diff --git a/SandboxiePlus/SandMan/SandMan.cpp b/SandboxiePlus/SandMan/SandMan.cpp index d49384e1..dac39bd7 100644 --- a/SandboxiePlus/SandMan/SandMan.cpp +++ b/SandboxiePlus/SandMan/SandMan.cpp @@ -386,6 +386,8 @@ void CSandMan::CreateMenus() m_pMenuView->addSeparator(); + m_pRefreshAll = m_pMenuView->addAction(CSandMan::GetIcon("Recover"), tr("Refresh View"), this, SLOT(OnRefresh())); + m_pCleanUpMenu = m_pMenuView->addMenu(CSandMan::GetIcon("Clean"), tr("Clean Up")); m_pCleanUpProcesses = m_pCleanUpMenu->addAction(tr("Cleanup Processes"), this, SLOT(OnCleanUp())); m_pCleanUpMenu->addSeparator(); @@ -1029,8 +1031,10 @@ SB_STATUS CSandMan::DeleteBoxContent(const CSandBoxPtr& pBox, EDelMode Mode, boo Status = pBox->CleanBox(); Ret = Status; - if (Status.GetStatus() == OP_ASYNC) + if (Status.GetStatus() == OP_ASYNC) { Ret = AddAsyncOp(Status.GetValue(), true, tr("Auto Deleting %1 Content").arg(pBox->GetName())); + pBox.objectCast()->UpdateSize(); + } } finish: @@ -1144,8 +1148,7 @@ void CSandMan::OnStatusChanged() OnIniReloaded(); - if (theConf->GetBool("Options/WatchIni", true)) - theAPI->WatchIni(true); + theAPI->WatchIni(true, theConf->GetBool("Options/WatchIni", true)); if (!theAPI->ReloadCert().IsError()) { CSettingsWindow::LoadCertificate(); @@ -1858,6 +1861,20 @@ void CSandMan::SetViewMode(bool bAdvanced) } } +void CSandMan::OnRefresh() +{ + if (!theAPI->IsConnected()) + return; + + theAPI->ReloadBoxes(true); + + if (theConf->GetBool("Options/WatchBoxSize", false)) { + QMap Boxes = theAPI->GetAllBoxes(); + foreach(const CSandBoxPtr & pBox, Boxes) + pBox.objectCast()->UpdateSize(); + } +} + void CSandMan::OnCleanUp() { if (sender() == m_pCleanUpMsgLog || sender() == m_pCleanUpButton) diff --git a/SandboxiePlus/SandMan/SandMan.h b/SandboxiePlus/SandMan/SandMan.h index edd9a1c6..66c2da3f 100644 --- a/SandboxiePlus/SandMan/SandMan.h +++ b/SandboxiePlus/SandMan/SandMan.h @@ -179,6 +179,7 @@ private slots: void OnViewMode(QAction* action); void OnAlwaysTop(); + void OnRefresh(); void OnCleanUp(); void OnProcView(); @@ -266,6 +267,7 @@ private: QAction* m_pShowHidden; QAction* m_pWndTopMost; int m_iMenuViewPos; + QAction* m_pRefreshAll; QMenu* m_pCleanUpMenu; QAction* m_pCleanUpProcesses; QAction* m_pCleanUpMsgLog; diff --git a/SandboxiePlus/SandMan/SandMan.pri b/SandboxiePlus/SandMan/SandMan.pri index 595a1a52..d5357ca0 100644 --- a/SandboxiePlus/SandMan/SandMan.pri +++ b/SandboxiePlus/SandMan/SandMan.pri @@ -8,6 +8,7 @@ HEADERS += ./stdafx.h \ ./SbiePlusAPI.h \ ./SbieProcess.h \ ./BoxJob.h \ + ./BoxMonitor.h \ ./Models/SbieModel.h \ ./Models/TraceModel.h \ ./Models/MonitorModel.h \ @@ -32,6 +33,7 @@ SOURCES += ./main.cpp \ ./SbiePlusAPI.cpp \ ./SbieProcess.cpp \ ./BoxJob.cpp \ + ./BoxMonitor.cpp \ ./Models/TraceModel.cpp \ ./Models/MonitorModel.cpp \ ./Models/SbieModel.cpp \ diff --git a/SandboxiePlus/SandMan/SandMan.vcxproj b/SandboxiePlus/SandMan/SandMan.vcxproj index d801dcc4..a0edcccf 100644 --- a/SandboxiePlus/SandMan/SandMan.vcxproj +++ b/SandboxiePlus/SandMan/SandMan.vcxproj @@ -196,8 +196,11 @@ + + + @@ -253,7 +256,11 @@ + + + + diff --git a/SandboxiePlus/SandMan/SandMan.vcxproj.filters b/SandboxiePlus/SandMan/SandMan.vcxproj.filters index d17ae05d..6dba1fc7 100644 --- a/SandboxiePlus/SandMan/SandMan.vcxproj.filters +++ b/SandboxiePlus/SandMan/SandMan.vcxproj.filters @@ -153,6 +153,15 @@ Wizards + + Helpers + + + Helpers + + + SandMan + @@ -170,6 +179,15 @@ Header Files + + Helpers + + + Helpers + + + Helpers + @@ -229,6 +247,9 @@ Wizards + + SandMan + diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.cpp b/SandboxiePlus/SandMan/SbiePlusAPI.cpp index 90c68444..c8311cbc 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.cpp +++ b/SandboxiePlus/SandMan/SbiePlusAPI.cpp @@ -4,14 +4,18 @@ #include "SandMan.h" #include "..\MiscHelpers\Common\Common.h" #include +#include "BoxMonitor.h" CSbiePlusAPI::CSbiePlusAPI(QObject* parent) : CSbieAPI(parent) { + m_BoxMonitor = new CBoxMonitor(); + m_JobCount = 0; } CSbiePlusAPI::~CSbiePlusAPI() { + delete m_BoxMonitor; } CSandBox* CSbiePlusAPI::NewSandBox(const QString& BoxName, class CSbieAPI* pAPI) @@ -94,7 +98,10 @@ CSandBoxPlus::CSandBoxPlus(const QString& BoxName, class CSbieAPI* pAPI) : CSand m_bApplicationCompartment = false; m_iUnsecureDebugging = 0; + m_TotalSize = theConf->GetValue("SizeCache/" + m_Name, -1).toLongLong(); + m_SuspendRecovery = false; + m_IsEmpty = false; m_pOptionsWnd = NULL; m_pRecoveryWnd = NULL; @@ -154,11 +161,56 @@ void CSandBoxPlus::UpdateDetails() CSandBox::UpdateDetails(); } +void CSandBoxPlus::SetBoxPaths(const QString& FilePath, const QString& RegPath, const QString& IpcPath) +{ + CSandBox::SetBoxPaths(FilePath, RegPath, IpcPath); + m_IsEmpty = IsEmpty(); + + if (theConf->GetBool("Options/WatchBoxSize", false) && m_TotalSize == -1) + ((CSbiePlusAPI*)theAPI)->m_BoxMonitor->AddBox(this); +} + +void CSandBoxPlus::UpdateSize() +{ + m_TotalSize = -1; + if(theConf->GetBool("Options/WatchBoxSize", false)) + ((CSbiePlusAPI*)theAPI)->m_BoxMonitor->AddBox(this); + + m_IsEmpty = IsEmpty(); +} + +void CSandBoxPlus::SetSize(quint64 Size) +{ + m_TotalSize = Size; + theConf->SetValue("SizeCache/" + m_Name, Size); +} + +void CSandBoxPlus::OpenBox() +{ + CSandBox::OpenBox(); + + m_IsEmpty = false; + + if (theConf->GetBool("Options/WatchBoxSize", false)) + ((CSbiePlusAPI*)theAPI)->m_BoxMonitor->AddBox(this, true); +} + void CSandBoxPlus::CloseBox() { CSandBox::CloseBox(); m_SuspendRecovery = false; + + ((CSbiePlusAPI*)theAPI)->m_BoxMonitor->CloseBox(this); +} + +SB_PROGRESS CSandBoxPlus::CleanBox() +{ + ((CSbiePlusAPI*)theAPI)->m_BoxMonitor->CloseBox(this, true); + + SB_PROGRESS Status = CSandBox::CleanBox(); + + return Status; } bool CSandBoxPlus::CheckUnsecureConfig() const @@ -190,7 +242,7 @@ QString CSandBoxPlus::GetStatusStr() const QStringList Status; - if (IsEmpty()) + if (m_IsEmpty) Status.append(tr("Empty")); if (m_bApplicationCompartment) @@ -513,6 +565,8 @@ void CSandBoxPlus::OnAsyncFinished() if (!m_JobQueue.isEmpty()) StartNextJob(); + else + UpdateSize(); } void CSandBoxPlus::OnAsyncMessage(const QString& Text) diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.h b/SandboxiePlus/SandMan/SbiePlusAPI.h index 94aeea77..f0d7dd2e 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.h +++ b/SandboxiePlus/SandMan/SbiePlusAPI.h @@ -29,6 +29,9 @@ protected: int m_JobCount; QMultiMap m_WindowMap; + + friend class CSandBoxPlus; + class CBoxMonitor* m_BoxMonitor; }; /////////////////////////////////////////////////////////////////////////////// @@ -44,8 +47,13 @@ public: virtual void UpdateDetails(); + virtual void SetBoxPaths(const QString& FilePath, const QString& RegPath, const QString& IpcPath); + + virtual void OpenBox(); virtual void CloseBox(); + virtual SB_PROGRESS CleanBox(); + virtual QString GetStatusStr() const; virtual void SetLogApi(bool bEnable); @@ -72,6 +80,10 @@ public: virtual void SetLeaderProgram(const QString& ProgName, bool bSet); virtual int IsLeaderProgram(const QString& ProgName); + virtual void UpdateSize(); + virtual quint64 GetSize() const { if(m_TotalSize == -1) return 0; return m_TotalSize; } + virtual void SetSize(quint64 Size); //{ m_TotalSize = Size; } + virtual bool IsRecoverySuspended() const { return m_SuspendRecovery; } virtual void SetSuspendRecovery(bool bSet = true) { m_SuspendRecovery = bSet; } @@ -126,7 +138,10 @@ protected: bool m_bApplicationCompartment; int m_iUnsecureDebugging; + quint64 m_TotalSize; + bool m_SuspendRecovery; + bool m_IsEmpty; QString m_StatusStr; QSet m_RecentPrograms; diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index b30cfa5c..a41add8d 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -8,7 +8,6 @@ #include "../../MiscHelpers/Common/Common.h" #include "../Windows/OptionsWindow.h" #include "../Windows/SnapshotsWindow.h" -#include #include "../../MiscHelpers/Common/CheckableMessageBox.h" #include "../Windows/RecoveryWindow.h" #include "../Windows/NewBoxWindow.h" @@ -1351,8 +1350,6 @@ void CSbieView::UpdateRunMenu(const CSandBoxPtr& pBox) while (m_iMenuRun < m_pMenuRun->actions().count()) m_pMenuRun->removeAction(m_pMenuRun->actions().at(m_iMenuRun)); - QFileIconProvider IconProvider; - QStringList RunOptions = pBox->GetTextList("RunCommand", true); foreach(const QString& RunOption, RunOptions) { @@ -1372,7 +1369,7 @@ void CSbieView::UpdateRunMenu(const CSandBoxPtr& pBox) if (Path.left(1) == "\\") Path.prepend(pBox->GetFileRoot()); - pAction->setIcon(IconProvider.icon(QFileInfo(Path))); + pAction->setIcon(m_IconProvider.icon(QFileInfo(Path))); pAction->setData(NameCmd.second); } @@ -1483,4 +1480,4 @@ void CSbieView::OnRemoveItem() OnSandBoxAction(m_pMenuRemove); else if (!GetSelectedGroups().isEmpty()) OnGroupAction(m_pDelGroupe); -} +} \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Views/SbieView.h b/SandboxiePlus/SandMan/Views/SbieView.h index 67b3aeb2..08a6eeb6 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.h +++ b/SandboxiePlus/SandMan/Views/SbieView.h @@ -3,6 +3,7 @@ #include "../../MiscHelpers/Common/PanelView.h" #include "../../MiscHelpers/Common/TreeviewEx.h" #include "../Models/SbieModel.h" +#include class CSbieView : public CPanelView { @@ -152,4 +153,6 @@ private: QAction* m_pRemove; int m_iMenuRun; + + QFileIconProvider m_IconProvider; }; \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp index 79e6c865..95eaeff4 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp @@ -301,6 +301,8 @@ void CSettingsWindow::LoadSettings() ui.chkPanic->setChecked(theConf->GetBool("Options/EnablePanicKey", false)); ui.keyPanic->setKeySequence(QKeySequence(theConf->GetString("Options/PanicKeySequence", "Shift+Pause"))); + ui.chkMonitorSize->setChecked(theConf->GetBool("Options/WatchBoxSize", false)); + ui.chkWatchConfig->setChecked(theConf->GetBool("Options/WatchIni", true)); @@ -458,6 +460,8 @@ void CSettingsWindow::SaveSettings() theConf->SetValue("Options/EnablePanicKey", ui.chkPanic->isChecked()); theConf->SetValue("Options/PanicKeySequence", ui.keyPanic->keySequence().toString()); + theConf->SetValue("Options/WatchBoxSize", ui.chkMonitorSize->isChecked()); + theConf->SetValue("Options/WatchIni", ui.chkWatchConfig->isChecked()); theConf->SetValue("Options/SysTrayIcon", ui.cmbSysTray->currentIndex()); diff --git a/SandboxiePlus/SandMan/stdafx.h b/SandboxiePlus/SandMan/stdafx.h index 0a401ff6..dc6603cf 100644 --- a/SandboxiePlus/SandMan/stdafx.h +++ b/SandboxiePlus/SandMan/stdafx.h @@ -106,6 +106,7 @@ using namespace std; #include #include #include +#include // other includes