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#pragma once
22#include <string>
23#include <filesystem>
24#include <iostream>
25#include <cstdlib>
26
27#ifndef DATA_DIR
28#define DATA_DIR "/usr/share/BastionGuard/data"
29#endif
30
31inline std::string resource(const std::string& rel) {
32 namespace fs = std::filesystem;
33
34 if (const char* env = std::getenv("BastionGuard_DATA")) {
35 std::string p = std::string(env) + "/" + rel;
36 if (fs::exists(p))
37 return p;
38 }
39
40
41 {
42 std::string system_path = std::string(DATA_DIR) + "/" + rel;
43 if (fs::exists(system_path))
44 return system_path;
45 }
46
47 {
48 std::string userBase;
49 if (const char* xdg = std::getenv("XDG_DATA_HOME"); xdg && *xdg) {
50 userBase = xdg;
51 } else if (const char* home = std::getenv("HOME"); home) {
52 userBase = std::string(home) + "/.local/share";
53 }
54
55 if (!userBase.empty()) {
56 std::string user_path = userBase + "/BastionGuard/data/" + rel;
57 if (fs::exists(user_path))
58 return user_path;
59 }
60 }
61
62 std::cerr << "⚠ Risorsa non trovata: " << rel << std::endl;
63
64 return std::string(DATA_DIR) + "/" + rel;
65}
66
std::string resource(const std::string &rel)
Definition Resource.hpp:31
#define DATA_DIR
Definition Resource.hpp:28