17 const std::string& relative_path) {
18 std::vector<std::filesystem::path> search_paths;
26 search_paths.push_back(std::filesystem::path(bundle_root) /
"assets" /
28 search_paths.push_back(std::filesystem::path(bundle_root) / relative_path);
31 search_paths.push_back(std::filesystem::path(bundle_root) /
"Contents" /
32 "Resources" / relative_path);
33 search_paths.push_back(std::filesystem::path(bundle_root) /
"Contents" /
34 "Resources" /
"assets" / relative_path);
37 search_paths.push_back(std::filesystem::path(bundle_root) /
"Resources" /
39 search_paths.push_back(std::filesystem::path(bundle_root) /
"Resources" /
40 "assets" / relative_path);
43 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
"assets" /
47 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
48 ".." /
"assets" / relative_path);
49 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
50 ".." /
".." /
"assets" / relative_path);
55 search_paths.push_back(std::filesystem::path(
"assets") / relative_path);
56 search_paths.push_back(std::filesystem::path(
"../assets") / relative_path);
57 search_paths.push_back(std::filesystem::path(
"../../assets") / relative_path);
58 search_paths.push_back(std::filesystem::path(
"../../../assets") /
60 search_paths.push_back(std::filesystem::path(
"../../../../assets") /
64 search_paths.push_back(std::filesystem::path(
"build/assets") / relative_path);
65 search_paths.push_back(std::filesystem::path(
"../build/assets") /
72 const std::string& relative_path) {
80 for (
const auto& path : search_paths) {
81 if (std::filesystem::exists(path)) {
87 std::string searched_paths;
88 for (
const auto& path : search_paths) {
89 searched_paths +=
"\n - " + path.string();
92 return absl::NotFoundError(
93 absl::StrFormat(
"Asset file not found: %s\nSearched paths:%s",
94 relative_path, searched_paths));
98 const std::string& relative_path) {
100 if (!path_result.ok()) {
101 return path_result.status();
104 const auto& path = *path_result;
105 std::ifstream file(path);
106 if (!file.is_open()) {
107 return absl::InternalError(
108 absl::StrFormat(
"Failed to open file: %s", path.string()));
111 std::stringstream buffer;
112 buffer << file.rdbuf();
113 std::string content = buffer.str();
115 if (content.empty()) {
116 return absl::InternalError(
117 absl::StrFormat(
"File is empty: %s", path.string()));