Skip to content
API Documentation
BastionGuard™
resource.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™
3 * Copyright (C) 2025–2026 Calogero Scarnà
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 *
17 * BastionGuard™ is a trademark of Calogero Scarnà.
18 * The BastionGuard™ name and branding are not licensed under the GPL.
19 */
20
21
22#pragma once
23#include <string>
24#include <filesystem>
25#include <iostream>
26#include <cstdlib>
27
28#ifndef DATA_DIR
29#define DATA_DIR "/usr/share/BastionGuard/data"
30#endif
31
32inline std::string resource(const std::string& rel) {
33 namespace fs = std::filesystem;
34
35 std::string build_path = "data/" + rel;
36
37 std::string install_path = std::string(DATA_DIR) + "/" + rel;
38
39 std::string userBase;
40 if (const char* xdg = std::getenv("XDG_DATA_HOME"); xdg && *xdg) {
41 userBase = std::string(xdg);
42 } else if (const char* home = std::getenv("HOME"); home) {
43 userBase = std::string(home) + "/.local/share";
44 }
45 std::string user_path = userBase + "/BastionGuard/data/" + rel;
46
47 if (fs::exists(build_path)) return build_path;
48 if (!userBase.empty() && fs::exists(user_path)) return user_path;
49 if (fs::exists(install_path)) return install_path;
50
51 std::cerr << "⚠ Risorsa non trovata: " << rel << std::endl;
52 return install_path;
53}
std::string resource(const std::string &rel)
Definition Resource.hpp:31
#define DATA_DIR
Definition Resource.hpp:28