16 const std::string& relative_path) {
17 std::vector<std::filesystem::path> search_paths;
25 search_paths.push_back(std::filesystem::path(bundle_root) /
"assets" /
27 search_paths.push_back(std::filesystem::path(bundle_root) / relative_path);
30 search_paths.push_back(std::filesystem::path(bundle_root) /
"Contents" /
31 "Resources" / relative_path);
34 search_paths.push_back(std::filesystem::path(bundle_root) /
"Resources" /
38 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
39 ".." /
"assets" / relative_path);
40 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
41 ".." /
".." /
"assets" / relative_path);
46 search_paths.push_back(std::filesystem::path(
"assets") / relative_path);
47 search_paths.push_back(std::filesystem::path(
"../assets") / relative_path);
48 search_paths.push_back(std::filesystem::path(
"../../assets") / relative_path);
49 search_paths.push_back(std::filesystem::path(
"../../../assets") /
51 search_paths.push_back(std::filesystem::path(
"../../../../assets") /
55 search_paths.push_back(std::filesystem::path(
"build/assets") / relative_path);
56 search_paths.push_back(std::filesystem::path(
"../build/assets") /
63 const std::string& relative_path) {
66 for (
const auto& path : search_paths) {
67 if (std::filesystem::exists(path)) {
73 std::string searched_paths;
74 for (
const auto& path : search_paths) {
75 searched_paths +=
"\n - " + path.string();
78 return absl::NotFoundError(
79 absl::StrFormat(
"Asset file not found: %s\nSearched paths:%s",
80 relative_path, searched_paths));
84 const std::string& relative_path) {
86 if (!path_result.ok()) {
87 return path_result.status();
90 const auto& path = *path_result;
91 std::ifstream file(path);
92 if (!file.is_open()) {
93 return absl::InternalError(
94 absl::StrFormat(
"Failed to open file: %s", path.string()));
97 std::stringstream buffer;
98 buffer << file.rdbuf();
99 std::string content = buffer.str();
101 if (content.empty()) {
102 return absl::InternalError(
103 absl::StrFormat(
"File is empty: %s", path.string()));