Skip to content
API Documentation
BastionGuard™
Resource.hpp File Reference

Go to the source code of this file.

Macros

#define DATA_DIR   "/usr/share/bastionguard-recovery-data/data"

Functions

std::string resource (const std::string &rel)

Macro Definition Documentation

◆ DATA_DIR

#define DATA_DIR   "/usr/share/bastionguard-recovery-data/data"

Definition at line 26 of file Resource.hpp.

Function Documentation

◆ resource()

std::string resource ( const std::string & rel)
inline

Definition at line 29 of file Resource.hpp.

30{
31 namespace fs = std::filesystem;
32
33 if (const char* env = std::getenv("BASTIONGUARD_DATA"); env && *env) {
34 fs::path p = fs::path(env) / rel;
35 if (fs::exists(p)) {
36 return p.string();
37 }
38 }
39
40 {
41 fs::path system_path = fs::path(DATA_DIR) / rel;
42 if (fs::exists(system_path)) {
43 return system_path.string();
44 }
45 }
46
47 {
48 std::string user_base;
49
50 if (const char* xdg = std::getenv("XDG_DATA_HOME"); xdg && *xdg) {
51 user_base = xdg;
52 } else if (const char* home = std::getenv("HOME"); home && *home) {
53 user_base = std::string(home) + "/.local/share";
54 }
55
56 if (!user_base.empty()) {
57 fs::path user_path = fs::path(user_base) / "bastionguard-recovery-data" / "data" / rel;
58 if (fs::exists(user_path)) {
59 return user_path.string();
60 }
61 }
62 }
63
64 {
65 fs::path cwd_path = fs::current_path() / rel;
66 if (fs::exists(cwd_path)) {
67 return cwd_path.string();
68 }
69 }
70
71 {
72 fs::path local_data_path = fs::current_path() / "data" / fs::path(rel).filename();
73 if (fs::exists(local_data_path)) {
74 return local_data_path.string();
75 }
76 }
77
78 std::cerr << "⚠ Risorsa non trovata: " << rel << std::endl;
79 return (fs::path(DATA_DIR) / rel).string();
80}
#define DATA_DIR
Definition Resource.hpp:28

References DATA_DIR, and resource().