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);
32 search_paths.push_back(std::filesystem::path(bundle_root) /
"Contents" /
33 "Resources" /
"assets" / relative_path);
36 search_paths.push_back(std::filesystem::path(bundle_root) /
"Resources" /
38 search_paths.push_back(std::filesystem::path(bundle_root) /
"Resources" /
39 "assets" / relative_path);
42 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
"assets" /
46 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
47 ".." /
"assets" / relative_path);
48 search_paths.push_back(std::filesystem::path(bundle_root) /
".." /
".." /
49 ".." /
".." /
"assets" / relative_path);
54 search_paths.push_back(std::filesystem::path(
"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") /
59 search_paths.push_back(std::filesystem::path(
"../../../../assets") /
63 search_paths.push_back(std::filesystem::path(
"build/assets") / relative_path);
64 search_paths.push_back(std::filesystem::path(
"../build/assets") /
71 const std::string& relative_path) {
74 for (
const auto& path : search_paths) {
75 if (std::filesystem::exists(path)) {
81 std::string searched_paths;
82 for (
const auto& path : search_paths) {
83 searched_paths +=
"\n - " + path.string();
86 return absl::NotFoundError(
87 absl::StrFormat(
"Asset file not found: %s\nSearched paths:%s",
88 relative_path, searched_paths));
92 const std::string& relative_path) {
94 if (!path_result.ok()) {
95 return path_result.status();
98 const auto& path = *path_result;
99 std::ifstream file(path);
100 if (!file.is_open()) {
101 return absl::InternalError(
102 absl::StrFormat(
"Failed to open file: %s", path.string()));
105 std::stringstream buffer;
106 buffer << file.rdbuf();
107 std::string content = buffer.str();
109 if (content.empty()) {
110 return absl::InternalError(
111 absl::StrFormat(
"File is empty: %s", path.string()));