From 84fb5ceea6ffcc3f4a6b87d51d019c86eb0dc2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=BC=96=E7=A8=8B=E7=9A=84=E5=8F=B6=E4=B8=80?= =?UTF-8?q?=E7=AC=91?= <92030377+love-code-yeyixiao@users.noreply.github.com> Date: Sat, 1 Aug 2026 09:42:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8D=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=92=8C=E5=90=91=E5=AF=BC=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BF=9D=E6=8A=A4=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 `CVolumeManager::AddVolume` 方法,新增布尔参数 `bProtect` 以支持卷保护。 - 更新 `CVolumeWizard::ShowWizard` 方法,传递保护参数并添加 `GetProtectContainerFile` 方法。 - 在 `CVolumeSummaryPage` 中添加复选框,允许用户选择保护卷容器文件。 - 在 `VolumeWizard.h` 中声明 `GetProtectContainerFile` 方法,并添加 `QCheckBox* m_pProtectFile` 成员变量。 --- MajorPrivacy/Core/Volumes/VolumeManager.cpp | 13 ++++++++++++- MajorPrivacy/Core/Volumes/VolumeManager.h | 2 +- MajorPrivacy/Wizards/VolumeWizard.cpp | 21 +++++++++++++++++++-- MajorPrivacy/Wizards/VolumeWizard.h | 2 ++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/MajorPrivacy/Core/Volumes/VolumeManager.cpp b/MajorPrivacy/Core/Volumes/VolumeManager.cpp index 56282a5..0b1a6a9 100644 --- a/MajorPrivacy/Core/Volumes/VolumeManager.cpp +++ b/MajorPrivacy/Core/Volumes/VolumeManager.cpp @@ -53,7 +53,7 @@ void CVolumeManager::Update() } } -STATUS CVolumeManager::AddVolume(const QString& Path) +STATUS CVolumeManager::AddVolume(const QString& Path, bool bProtect) { if (Path.endsWith("\\")) { @@ -66,6 +66,17 @@ STATUS CVolumeManager::AddVolume(const QString& Path) if(!Status) return Status; } + else if (bProtect) + { + CAccessRulePtr pRule = CAccessRulePtr(new CAccessRule(theCore->ProgramManager()->GetAll()->GetID())); + pRule->SetType(EAccessRuleType::eProtect); + pRule->SetEnabled(true); + pRule->SetName(tr("%1 - Protection").arg(Path)); + pRule->SetPath(Path); + STATUS Status = theCore->AccessManager()->SetAccessRule(pRule); + if(!Status) + return Status; + } CVolumePtr pVolume = CVolumePtr(new CVolume()); pVolume->SetImagePath(Path); diff --git a/MajorPrivacy/Core/Volumes/VolumeManager.h b/MajorPrivacy/Core/Volumes/VolumeManager.h index 5e96c2e..1d0768e 100644 --- a/MajorPrivacy/Core/Volumes/VolumeManager.h +++ b/MajorPrivacy/Core/Volumes/VolumeManager.h @@ -13,7 +13,7 @@ class CVolumeManager : public QObject QList List() { return m_List.values(); } - STATUS AddVolume(const QString& Path); + STATUS AddVolume(const QString& Path, bool bProtect = false); STATUS RemoveVolume(const QString& Path); STATUS SetVolume(const CVolumePtr& pVolume); diff --git a/MajorPrivacy/Wizards/VolumeWizard.cpp b/MajorPrivacy/Wizards/VolumeWizard.cpp index a1f7358..171b13d 100644 --- a/MajorPrivacy/Wizards/VolumeWizard.cpp +++ b/MajorPrivacy/Wizards/VolumeWizard.cpp @@ -131,8 +131,11 @@ bool CVolumeWizard::ShowWizard(QWidget* parent) pWatcher->deleteLater(); - if (Result.IsSuccess()) - theCore->VolumeManager()->AddVolume(Path); + if (Result.IsSuccess()) { + STATUS Status = theCore->VolumeManager()->AddVolume(Path, wizard.GetProtectContainerFile()); + if (!Status) + Result = Status; + } theGUI->CheckResults(QList() << Result, parent ? parent : theGUI); return Result.IsSuccess(); @@ -185,6 +188,11 @@ int CVolumeWizard::GetKdf() const return iKdf; } +bool CVolumeWizard::GetProtectContainerFile() const +{ + return field("protectContainerFile").toBool(); +} + ////////////////////////////////////////////////////////////////////////////////////////// // CVolumeIntroPage // @@ -1076,6 +1084,15 @@ CVolumeSummaryPage::CVolumeSummaryPage(QWidget *parent) m_pSummaryLabel->setStyleSheet("QLabel { background-color: palette(alternate-base); padding: 15px; border-radius: 5px; }"); layout->addWidget(m_pSummaryLabel); + layout->addSpacing(16); + + m_pProtectFile = new QCheckBox(tr("Protect the volume container file (.pv) from modification by other programs")); + m_pProtectFile->setWordWrap(true); + m_pProtectFile->setToolTip(tr("Adds a Protect access rule for the container file itself, so that no other program can read, modify or delete it while the protection is active.")); + m_pProtectFile->setChecked(true); + layout->addWidget(m_pProtectFile); + registerField("protectContainerFile", m_pProtectFile); + layout->addSpacing(20); QLabel* noteLabel = new QLabel(tr( diff --git a/MajorPrivacy/Wizards/VolumeWizard.h b/MajorPrivacy/Wizards/VolumeWizard.h index 0acdb39..e9ac0a8 100644 --- a/MajorPrivacy/Wizards/VolumeWizard.h +++ b/MajorPrivacy/Wizards/VolumeWizard.h @@ -32,6 +32,7 @@ class CVolumeWizard : public QWizard QString GetCipher() const; QString GetFileSystem() const; int GetKdf() const; + bool GetProtectContainerFile() const; private slots: void showHelp(); @@ -234,4 +235,5 @@ class CVolumeSummaryPage : public QWizardPage private: QLabel* m_pSummaryLabel; + QCheckBox* m_pProtectFile; };