60{
61 bool loadFromFile = true;
62
63 if(IsNetWorkConnected() && rand() % 2 == 0)
64 {
65 loadFromFile = false;
66 }
67
68 if(!FileExists(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "texture_database.terr3d"))
69 {
70 loadFromFile = false;
71 }
72
73 if(loadFromFile)
74 {
75 Log("Loading texture database from file");
76 bool tmp = false;
77 std::string tmpStr = ReadShaderSourceFile(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "texture_database.terr3d", &tmp);
78
79 if(tmp == false)
80 {
81 Log("Failed to load texture database from file");
83 }
84
85 try
86 {
88 }
89
91 {
92 Log("Failed to parse texture database from file");
94 }
95 }
96
97 else
98 {
99 Log("Fetching texture database from web database.");
100 std::string tmp = FetchURL("https://api.polyhaven.com", "/assets?t=textures");
101
102 if (tmp.size() < 3)
103 {
104 Log("Failed to fetch texture database from web database.");
106 }
107
108 SaveToFile(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "texture_database.terr3d", tmp);
110 }
111}
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
exception indicating a parse error
basic_json<> json
default JSON class