Skip to content
API Documentation
BastionGuard™
Resource.hpp
Go to the documentation of this file.
1/*
2 * BastionGuard™ Secure Connection
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 * BastionGuard™ is a trademark of Calogero Scarnà.
10 * The BastionGuard™ name and branding are not licensed under the GPL.
11 */
12
13#pragma once
14#include <string>
15#include <filesystem>
16#include <iostream>
17#include <cstdlib>
18
19#ifndef DATA_DIR
20#define DATA_DIR "/usr/share/bastionguard-sc/data"
21#endif
22
23inline std::string resource(const std::string& rel) {
24 namespace fs = std::filesystem;
25
26 if (const char* env = std::getenv("BSC_DATA")) {
27 std::string p = std::string(env) + "/" + rel;
28 if (fs::exists(p)) return p;
29 }
30
31 {
32 std::string system_path = std::string(DATA_DIR) + "/" + rel;
33 if (fs::exists(system_path)) return system_path;
34 }
35
36 {
37 std::string userBase;
38 if (const char* xdg = std::getenv("XDG_DATA_HOME"); xdg && *xdg)
39 userBase = xdg;
40 else if (const char* home = std::getenv("HOME"); home)
41 userBase = std::string(home) + "/.local/share";
42
43 if (!userBase.empty()) {
44 std::string user_path = userBase + "/bastionguard-sc/data/" + rel;
45 if (fs::exists(user_path)) return user_path;
46 }
47 }
48
49 std::cerr << "⚠ Risorsa non trovata: " << rel << std::endl;
50 return std::string(DATA_DIR) + "/" + rel;
51}
std::string resource(const std::string &rel)
Definition Resource.hpp:31
#define DATA_DIR
Definition Resource.hpp:28