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

Functions

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

Macro Definition Documentation

◆ DATA_DIR

#define DATA_DIR   "/usr/share/BastionGuard/data"

Definition at line 29 of file resource.hpp.

Function Documentation

◆ resource()

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

Definition at line 32 of file resource.hpp.

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

References DATA_DIR, and resource().