diff --git a/src/ui/form/home/pages/homepage.cpp b/src/ui/form/home/pages/homepage.cpp index 2ef3268a..bba1da26 100644 --- a/src/ui/form/home/pages/homepage.cpp +++ b/src/ui/form/home/pages/homepage.cpp @@ -21,10 +21,13 @@ HomePage::HomePage(HomeController *ctrl, QWidget *parent) : HomeBasePage(ctrl, p void HomePage::onRetranslateUi() { m_gbDriver->setTitle(tr("Driver")); + m_gbPortable->setTitle(tr("Portable")); retranslateDriverMessage(); m_btInstallDriver->setText(tr("Reinstall")); m_btRemoveDriver->setText(tr("Remove")); + + m_btUninstallPortable->setText(tr("Uninstall")); } void HomePage::retranslateDriverMessage() @@ -44,6 +47,10 @@ void HomePage::setupUi() setupDriverBox(); layout->addWidget(m_gbDriver, 0, Qt::AlignHCenter); + // Portable Group Box + setupPortableBox(); + layout->addWidget(m_gbPortable, 0, Qt::AlignHCenter); + layout->addStretch(); this->setLayout(layout); @@ -119,3 +126,38 @@ void HomePage::setupDriverIcon() connect(driverManager(), &DriverManager::errorCodeChanged, this, &HomePage::retranslateDriverMessage); } + +void HomePage::setupPortableBox() +{ + auto colLayout = new QVBoxLayout(); + colLayout->setSpacing(10); + + // Buttons Row + auto buttonsLayout = new QHBoxLayout(); + buttonsLayout->setSpacing(10); + colLayout->addLayout(buttonsLayout); + + m_btUninstallPortable = ControlUtil::createButton(QString(), [&] { + windowManager()->showConfirmBox( + [&] { + FortManager::uninstall(); + fortManager()->removeDriver(); + }, + tr("Are you sure to uninstall the Fort Firewall?")); + }); + + if (!settings()->isUserAdmin()) { + m_btUninstallPortable->setEnabled(false); + } + + buttonsLayout->addStretch(); + buttonsLayout->addWidget(m_btUninstallPortable); + buttonsLayout->addStretch(); + + m_gbPortable = new QGroupBox(); + m_gbPortable->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + m_gbPortable->setMinimumWidth(200); + m_gbPortable->setLayout(colLayout); + + m_gbPortable->setVisible(settings()->isPortable()); +} diff --git a/src/ui/form/home/pages/homepage.h b/src/ui/form/home/pages/homepage.h index db92f45d..e63c519e 100644 --- a/src/ui/form/home/pages/homepage.h +++ b/src/ui/form/home/pages/homepage.h @@ -19,13 +19,16 @@ private: void setupUi(); void setupDriverBox(); void setupDriverIcon(); + void setupPortableBox(); private: QGroupBox *m_gbDriver = nullptr; + QGroupBox *m_gbPortable = nullptr; QLabel *m_iconDriver = nullptr; QLabel *m_labelDriverMessage = nullptr; QPushButton *m_btInstallDriver = nullptr; QPushButton *m_btRemoveDriver = nullptr; + QPushButton *m_btUninstallPortable = nullptr; }; #endif // HOMEPAGE_H diff --git a/src/ui/fortmanager.cpp b/src/ui/fortmanager.cpp index e7ac1a09..5cee2492 100644 --- a/src/ui/fortmanager.cpp +++ b/src/ui/fortmanager.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include
#include #include @@ -213,6 +214,34 @@ void FortManager::deleteManagers() ioc->autoDeleteAll(); } +void FortManager::install(const char *arg) +{ + switch (arg[0]) { + case 'b': { // "boot_filter" + DriverCommon::provRegister(/*bootFilter=*/true); // Register booted provider + } break; + case 'p': { // "portable" + FortManager::setupPortableResource(); + StartupUtil::setPortable(true); + } break; + case 's': { // "service" + StartupUtil::setAutoRunMode(StartupUtil::StartupAllUsers); + StartupUtil::setServiceInstalled(true); + } break; + case 'e': { // "explorer" + StartupUtil::setExplorerIntegrated(true); + } break; + } +} + +void FortManager::uninstall() +{ + StartupUtil::setAutoRunMode(StartupUtil::StartupDisabled); // Remove auto-run + StartupUtil::setServiceInstalled(false); // Uninstall service + StartupUtil::setExplorerIntegrated(false); // Remove Windows Explorer integration + DriverCommon::provUnregister(); // Unregister booted provider +} + bool FortManager::installDriver() { closeDriver(); diff --git a/src/ui/fortmanager.h b/src/ui/fortmanager.h index ae53c8ef..669bf6e1 100644 --- a/src/ui/fortmanager.h +++ b/src/ui/fortmanager.h @@ -20,6 +20,9 @@ public: void initialize(); + static void install(const char *arg); + static void uninstall(); + public slots: bool installDriver(); bool removeDriver(); diff --git a/src/ui_bin/main.cpp b/src/ui_bin/main.cpp index ed50e5fe..6bd067bf 100644 --- a/src/ui_bin/main.cpp +++ b/src/ui_bin/main.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -16,52 +15,23 @@ #include #include #include -#include namespace { #define FORT_ERROR_INSTANCE 1 #define FORT_ERROR_CONTROL 2 -void uninstall() -{ - StartupUtil::setAutoRunMode(StartupUtil::StartupDisabled); // Remove auto-run - StartupUtil::setServiceInstalled(false); // Uninstall service - StartupUtil::setExplorerIntegrated(false); // Remove Windows Explorer integration - DriverCommon::provUnregister(); // Unregister booted provider -} - -void install(const char *arg) -{ - switch (arg[0]) { - case 'b': { // "boot_filter" - DriverCommon::provRegister(/*bootFilter=*/true); // Register booted provider - } break; - case 'p': { // "portable" - FortManager::setupPortableResource(); - StartupUtil::setPortable(true); - } break; - case 's': { // "service" - StartupUtil::setAutoRunMode(StartupUtil::StartupAllUsers); - StartupUtil::setServiceInstalled(true); - } break; - case 'e': { // "explorer" - StartupUtil::setExplorerIntegrated(true); - } break; - } -} - bool processArgs(int argc, char *argv[]) { // Uninstall if (argc > 1 && !strcmp(argv[1], "-u")) { - uninstall(); + FortManager::uninstall(); return true; } // Install if (argc > 2 && !strcmp(argv[1], "-i")) { - install(argv[2]); + FortManager::install(argv[2]); return true; }