Skip to content
API Documentation
BastionGuard™
BastionGuard-ransomware-realtime-alert.cpp File Reference

Go to the source code of this file.

Classes

class  AlertApp

Functions

static std::string resolve_theme_css ()
static bool load_lang_conf ()
int main (int argc, char *argv[])

Function Documentation

◆ load_lang_conf()

bool load_lang_conf ( )
static

Definition at line 397 of file BastionGuard-ransomware-realtime-alert.cpp.

398{
399 const std::string lang_conf =
400 Glib::get_home_dir() + "/.config/BastionGuard/lang.conf";
401
402 std::ifstream f(lang_conf);
403 if (!f.is_open()) {
404 return false;
405 }
406
407 std::string line;
408 bool any = false;
409
410 while (std::getline(f, line)) {
411 if (line.empty() || line[0] == '#') {
412 continue;
413 }
414
415 const auto pos = line.find('=');
416 if (pos == std::string::npos) {
417 continue;
418 }
419
420 std::string key = line.substr(0, pos);
421 std::string val = line.substr(pos + 1);
422
423 auto ltrim = [](std::string& s) {
424 const auto p = s.find_first_not_of(" \t\r\n");
425 if (p == std::string::npos) {
426 s.clear();
427 } else {
428 s.erase(0, p);
429 }
430 };
431
432 auto rtrim = [](std::string& s) {
433 const auto p = s.find_last_not_of(" \t\r\n");
434 if (p == std::string::npos) {
435 s.clear();
436 } else {
437 s.erase(p + 1);
438 }
439 };
440
441 ltrim(key);
442 rtrim(key);
443 ltrim(val);
444 rtrim(val);
445
446 if (!key.empty() && !val.empty()) {
447 ::setenv(key.c_str(), val.c_str(), 1);
448 any = true;
449 }
450 }
451
452 return any;
453}

References load_lang_conf().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 455 of file BastionGuard-ransomware-realtime-alert.cpp.

456{
457 const bool loaded = load_lang_conf();
458
459 std::setlocale(LC_ALL, "");
460 bindtextdomain("BastionGuard", LOCALEDIR);
461 bind_textdomain_codeset("BastionGuard", "UTF-8");
462 textdomain("BastionGuard");
463
464 if (loaded) {
465 std::cerr << _("[Lang] Config caricata da ~/.config/BastionGuard/lang.conf") << '\n';
466 } else {
467 std::cerr << _("[Lang] Nessuna config trovata, uso locale di sistema") << '\n';
468 }
469
470 AlertApp app;
471 return app.run(argc, argv);
472}
#define _(s)
static bool load_lang_conf()
#define LOCALEDIR
int run(int argc, char *argv[])

References _, load_lang_conf(), LOCALEDIR, main(), and AlertApp::run().

◆ resolve_theme_css()

std::string resolve_theme_css ( )
static

Definition at line 51 of file BastionGuard-ransomware-realtime-alert.cpp.

51 {
52 const std::string conf =
53 Glib::get_home_dir() + "/.config/BastionGuard/theme.conf";
54 std::ifstream tf(conf);
55 std::string theme;
56 if (tf >> theme && theme == "dark")
57 return "BastionGuard-dark.css";
58 return "BastionGuard.css";
59}

References resolve_theme_css().

Referenced by AlertApp::load_css().