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-sc/data"

Functions

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

Macro Definition Documentation

◆ DATA_DIR

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

Definition at line 20 of file Resource.hpp.

Function Documentation

◆ resource()

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

Definition at line 23 of file Resource.hpp.

23 {
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}
#define DATA_DIR
Definition Resource.hpp:28

References DATA_DIR, and resource().