140 {
141
142 const std::string lang_conf = Glib::get_home_dir() + "/.config/BastionGuard/lang.conf";
143 {
144 std::error_code ec;
145 if (!fs::exists(lang_conf, ec) || ec) {
146 std::string cfgdir = Glib::get_home_dir() + "/.config/BastionGuard";
147 fs::create_directories(cfgdir, ec);
148 std::ofstream out(lang_conf, std::ios::out | std::ios::trunc);
149 if (out.is_open()) {
150 out << "LANG=en_US.UTF-8\n";
151 out << "LC_ALL=en_US.UTF-8\n";
152 out << "LANGUAGE=en_US\n";
153 out.close();
154 std::cout << "[Lang] ✅ Creato lang.conf di default: " << lang_conf << std::endl;
155 }
156 }
157 }
158
159 std::ifstream f(lang_conf);
160 if (f.is_open()) {
162 while (std::getline(f, line)) {
163 auto pos =
line.find(
'=');
164 if (pos != std::string::npos) {
165 std::string key =
line.substr(0, pos);
166 std::string val =
line.substr(pos + 1);
167 if (!key.empty() && !val.empty())
168 setenv(key.c_str(), val.c_str(), 1);
169 }
170 }
171 f.close();
172 std::cout << "[Lang] Config caricata da " << lang_conf << std::endl;
173 } else {
174 std::cerr << "[Lang] ⚠️ Impossibile aprire lang.conf, forzo inglese di default" << std::endl;
175 }
176
177 const char* lang_env = std::getenv("LANG");
178 if (!lang_env || std::string(lang_env).empty())
179 setenv("LANG", "en_US.UTF-8", 1);
180
181 const char* lc_all_env = std::getenv("LC_ALL");
182 if (!lc_all_env || std::string(lc_all_env).empty())
183 setenv("LC_ALL", "en_US.UTF-8", 1);
184
185 const char* language_env = std::getenv("LANGUAGE");
186 if (!language_env || std::string(language_env).empty())
187 setenv("LANGUAGE", "en_US", 1);
188
189 const char* applied = setlocale(LC_ALL, "");
190 if (!applied) applied = setlocale(LC_ALL, "en_US.UTF-8");
191 if (!applied) applied = setlocale(LC_ALL, "en_US");
192 if (!applied) applied = setlocale(LC_ALL, "C.UTF-8");
193 if (!applied) applied = setlocale(LC_ALL, "C");
194
195
196 bindtextdomain(
"BastionGuard",
LOCALEDIR);
197 bind_textdomain_codeset("BastionGuard", "UTF-8");
198 textdomain("BastionGuard");
199
200 auto app = Gtk::Application::create("org.BastionGuard.wizard");
202
204 app->add_window(*wizard);
205
206 wizard->signal_finished().connect([&app, wizard]() {
207 wizard->hide();
208 app->remove_window(*wizard);
209 delete wizard;
210
211
212 const std::string first_run_app = "/usr/bin/BastionGuard-first-run";
213 pid_t pid = fork();
214
215 if (pid == 0) {
216 execl(first_run_app.c_str(), first_run_app.c_str(), nullptr);
217 std::cerr << "[Wizard] ❌ Impossibile lanciare BastionGuard-first-run: "
218 << strerror(errno) << std::endl;
219 _exit(1);
220
221 } else if (pid > 0) {
222 Glib::signal_child_watch().connect([&app](GPid child_pid, int status) {
223 g_spawn_close_pid(child_pid);
224
225 const std::string main_app = "/usr/bin/BastionGuard";
226 std::cout << "[Wizard] 🚀 Lancio: " << main_app << std::endl;
227 execl(main_app.c_str(), main_app.c_str(), nullptr);
228
229 std::cerr << "[Wizard] ❌ Impossibile lanciare BastionGuard: "
230 << strerror(errno) << std::endl;
231 app->quit();
232 }, pid);
233
234 } else {
235 std::cerr << "[Wizard] ❌ fork() fallita: " << strerror(errno) << std::endl;
236 app->quit();
237 }
238 });
239
240 wizard->present();
241 return app->run(argc, argv);
242}