12 const std::string& relative_path) {
13 std::vector<std::filesystem::path> search_paths;
20 search_paths.push_back(std::filesystem::path(bundle_root) /
"Contents" /
21 "Resources" / relative_path);
24 search_paths.push_back(std::filesystem::path(bundle_root) /
"Resources" /
28 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
29 ".." /
"assets" / relative_path);
30 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
31 ".." /
".." /
"assets" / relative_path);
35 search_paths.push_back(std::filesystem::path(
"assets") / relative_path);
36 search_paths.push_back(std::filesystem::path(
"../assets") / relative_path);
37 search_paths.push_back(std::filesystem::path(
"../../assets") / relative_path);
38 search_paths.push_back(std::filesystem::path(
"../../../assets") /
40 search_paths.push_back(std::filesystem::path(
"../../../../assets") /
44 search_paths.push_back(std::filesystem::path(
"build/assets") / relative_path);
45 search_paths.push_back(std::filesystem::path(
"../build/assets") /
52 const std::string& relative_path) {
55 for (
const auto& path : search_paths) {
56 if (std::filesystem::exists(path)) {
62 std::string searched_paths;
63 for (
const auto& path : search_paths) {
64 searched_paths +=
"\n - " + path.string();
67 return absl::NotFoundError(
68 absl::StrFormat(
"Asset file not found: %s\nSearched paths:%s",
69 relative_path, searched_paths));
73 const std::string& relative_path) {
75 if (!path_result.ok()) {
76 return path_result.status();
79 const auto& path = *path_result;
80 std::ifstream file(path);
81 if (!file.is_open()) {
82 return absl::InternalError(
83 absl::StrFormat(
"Failed to open file: %s", path.string()));
86 std::stringstream buffer;
87 buffer << file.rdbuf();
88 std::string content = buffer.str();
90 if (content.empty()) {
91 return absl::InternalError(
92 absl::StrFormat(
"File is empty: %s", path.string()));