Skip to content
API Documentation
BastionGuard™
USBScanPage.cpp File Reference

Go to the source code of this file.

Functions

std::string usb_conf_path ()
void save_usb_autoscan (bool enabled)
bool load_usb_autoscan ()
bool has_virus (const std::string &text)
static std::string trim (const std::string &s)

Function Documentation

◆ has_virus()

bool has_virus ( const std::string & text)

Definition at line 68 of file USBScanPage.cpp.

69{
70 std::regex re(R"(FOUND\s*$)");
71 std::istringstream ss(text);
72 std::string line;
73
74 while (std::getline(ss, line)) {
75 if (line.find("FOUND") != std::string::npos)
76 return true;
77 }
78 return false;
79}

References has_virus().

Referenced by has_virus().

◆ load_usb_autoscan()

bool load_usb_autoscan ( )

Definition at line 56 of file USBScanPage.cpp.

56 {
57 std::ifstream f(usb_conf_path());
58 if (!f) return false;
59
60 std::string line;
61 while (std::getline(f, line)) {
62 if (line.rfind("auto_scan=", 0) == 0)
63 return line.substr(10) == "1";
64 }
65 return false;
66}
std::string usb_conf_path()

References load_usb_autoscan(), and usb_conf_path().

Referenced by load_usb_autoscan(), and USBScanPage::USBScanPage().

◆ save_usb_autoscan()

void save_usb_autoscan ( bool enabled)

Definition at line 47 of file USBScanPage.cpp.

47 {
48 std::string dir = Glib::get_home_dir() + "/.config/BastionGuard";
49 std::filesystem::create_directories(dir);
50
51 std::ofstream f(usb_conf_path());
52 if (!f) return;
53 f << "auto_scan=" << (enabled ? "1" : "0") << "\n";
54}

References save_usb_autoscan(), and usb_conf_path().

Referenced by save_usb_autoscan(), and USBScanPage::USBScanPage().

◆ trim()

std::string trim ( const std::string & s)
static

Definition at line 97 of file USBScanPage.cpp.

97 {
98 size_t a = s.find_first_not_of(" \t\n\r");
99 size_t b = s.find_last_not_of(" \t\n\r");
100 if (a == std::string::npos) return "";
101 return s.substr(a, b - a + 1);
102}

References trim().

Referenced by USBScanPage::show_infected_dialog().

◆ usb_conf_path()

std::string usb_conf_path ( )

Definition at line 43 of file USBScanPage.cpp.

43 {
44 return Glib::get_home_dir() + "/.config/BastionGuard/usb.conf";
45}

References usb_conf_path().

Referenced by load_usb_autoscan(), save_usb_autoscan(), and usb_conf_path().