Skip to content
API Documentation
BastionGuard™
first-run-main.cpp File Reference

Go to the source code of this file.

Functions

static bool load_lang_conf ()
int main (int argc, char *argv[])

Function Documentation

◆ load_lang_conf()

bool load_lang_conf ( )
static

Definition at line 35 of file first-run-main.cpp.

36{
37 const std::string lang_conf = Glib::get_home_dir() + "/.config/BastionGuard/lang.conf";
38 std::ifstream f(lang_conf);
39 if (!f.is_open())
40 return false;
41
42 std::string line;
43 bool any = false;
44
45 while (std::getline(f, line)) {
46 if (line.empty() || line[0] == '#')
47 continue;
48
49 auto pos = line.find('=');
50 if (pos == std::string::npos)
51 continue;
52
53 std::string key = line.substr(0, pos);
54 std::string val = line.substr(pos + 1);
55
56 auto ltrim = [](std::string& s){
57 s.erase(0, s.find_first_not_of(" \t\r\n"));
58 };
59 auto rtrim = [](std::string& s){
60 s.erase(s.find_last_not_of(" \t\r\n") + 1);
61 };
62 ltrim(key); rtrim(key);
63 ltrim(val); rtrim(val);
64
65 if (!key.empty() && !val.empty()) {
66 setenv(key.c_str(), val.c_str(), 1);
67 any = true;
68 }
69 }
70
71 return any;
72}

References load_lang_conf().

◆ main()

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

Definition at line 74 of file first-run-main.cpp.

75{
76
77 const std::string lang_conf = Glib::get_home_dir() + "/.config/BastionGuard/lang.conf";
78 {
79 std::error_code ec;
80 if (!fs::exists(lang_conf, ec) || ec) {
81 std::string cfgdir = Glib::get_home_dir() + "/.config/BastionGuard";
82 fs::create_directories(cfgdir, ec);
83 std::ofstream out(lang_conf, std::ios::out | std::ios::trunc);
84 if (out.is_open()) {
85 out << "LANG=en_US.UTF-8\n";
86 out << "LC_ALL=en_US.UTF-8\n";
87 out << "LANGUAGE=en_US\n";
88 out.close();
89 std::cout << "[Lang] ✅ Creato lang.conf di default: " << lang_conf << std::endl;
90 }
91 }
92 }
93
94 std::ifstream f(lang_conf);
95 if (f.is_open()) {
96 std::string line;
97 while (std::getline(f, line)) {
98 auto pos = line.find('=');
99 if (pos != std::string::npos) {
100 std::string key = line.substr(0, pos);
101 std::string val = line.substr(pos + 1);
102 if (!key.empty() && !val.empty())
103 setenv(key.c_str(), val.c_str(), 1);
104 }
105 }
106 f.close();
107 std::cout << "[Lang] Config caricata da " << lang_conf << std::endl;
108 } else {
109 std::cerr << "[Lang] ⚠️ Impossibile aprire lang.conf, forzo inglese di default" << std::endl;
110 }
111
112
113 const char* lang_env = std::getenv("LANG");
114 if (!lang_env || std::string(lang_env).empty())
115 setenv("LANG", "en_US.UTF-8", 1);
116
117 const char* lc_all_env = std::getenv("LC_ALL");
118 if (!lc_all_env || std::string(lc_all_env).empty())
119 setenv("LC_ALL", "en_US.UTF-8", 1);
120
121 const char* language_env = std::getenv("LANGUAGE");
122 if (!language_env || std::string(language_env).empty())
123 setenv("LANGUAGE", "en_US", 1);
124
125
126 const char* applied = setlocale(LC_ALL, "");
127 if (!applied) applied = setlocale(LC_ALL, "en_US.UTF-8");
128 if (!applied) applied = setlocale(LC_ALL, "en_US");
129 if (!applied) applied = setlocale(LC_ALL, "C.UTF-8");
130 if (!applied) applied = setlocale(LC_ALL, "C");
131
132 bindtextdomain("BastionGuard", LOCALEDIR);
133 bind_textdomain_codeset("BastionGuard", "UTF-8");
134 textdomain("BastionGuard");
135
136 auto app = Gtk::Application::create("org.bastionguard.first-run-test");
137 load_style();
138 return app->make_window_and_run<FirstRunServicesWindow>(argc, argv);
139}
#define LOCALEDIR
void load_style()

References load_style(), LOCALEDIR, and main().