void loadShaderCache() { FILE* fp = fopen(_shaderCacheFilePath.c_str(), "rb"); if (fp == nullptr) { _INTR_LOG_WARNING("Shader cache not available..."); return; } char* readBuffer = (char*)Memory::Tlsf::MainAllocator::allocate(65536u); { rapidjson::FileReadStream is(fp, readBuffer, 65536u); _shaderCache.ParseStream(is); fclose(fp); } Memory::Tlsf::MainAllocator::free(readBuffer); }
void LoadConfig(rapidjson::Document& d, const std::string& fileName, const std::string& defaultFileName) { FILE* f = fopen(fileName.c_str(), "rb"); if (!f) { s_CopyFile(defaultFileName.c_str(), fileName.c_str()); f = fopen(fileName.c_str(), "rb"); } if (!f) throw std::runtime_error((std::string) "can't open config file " + fileName); char buffer[4096]; rapidjson::FileReadStream stream(f, buffer, sizeof(buffer)); d.ParseStream(stream); fclose(f); if (d.GetParseError() != rapidjson::kParseErrorNone) throw std::runtime_error((std::string) "syntax error in config file " + fileName); }
int SettingRegistry::loadJSON(std::string filename, rapidjson::Document& json_document) { FILE* f = fopen(filename.c_str(), "rb"); if (!f) { cura::logError("Couldn't open JSON file.\n"); return 1; } char read_buffer[4096]; rapidjson::FileReadStream reader_stream(f, read_buffer, sizeof(read_buffer)); json_document.ParseStream(reader_stream); fclose(f); if (json_document.HasParseError()) { cura::logError("Error parsing JSON(offset %u): %s\n", (unsigned)json_document.GetErrorOffset(), GetParseError_En(json_document.GetParseError())); return 2; } return 0; }