Merge pull request #89 from Selmar/missing_bin_to_error_message

missing bin files are reported as warning instead of error
This commit is contained in:
Syoyo Fujita 2018-08-23 02:16:10 +09:00 committed by GitHub
commit 1d0bd6c64f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1238,7 +1238,7 @@ std::string base64_decode(std::string const &encoded_string) {
static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
std::string *warn, const std::string &filename,
const std::string &basedir, size_t reqBytes,
const std::string &basedir, bool required, size_t reqBytes,
bool checkSize, FsCallbacks *fs) {
if (fs == nullptr || fs->FileExists == nullptr ||
fs->ExpandFilePath == nullptr || fs->ReadWholeFile == nullptr) {
@ -1249,6 +1249,8 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
return false;
}
std::string* failMsgOut = required ? err : warn;
out->clear();
std::vector<std::string> paths;
@ -1257,8 +1259,8 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
std::string filepath = FindFile(paths, filename, fs);
if (filepath.empty() || filename.empty()) {
if (warn) {
(*warn) += "File not found : " + filename + "\n";
if (failMsgOut) {
(*failMsgOut) += "File not found : " + filename + "\n";
}
return false;
}
@ -1268,15 +1270,17 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
bool fileRead =
fs->ReadWholeFile(&buf, &fileReadErr, filepath, fs->user_data);
if (!fileRead) {
if (err) {
(*err) += "File read error : " + filepath + " : " + fileReadErr + "\n";
if (failMsgOut) {
(*failMsgOut) += "File read error : " + filepath + " : " + fileReadErr + "\n";
}
return false;
}
size_t sz = buf.size();
if (sz == 0) {
(*err) += "File is empty : " + filepath + "\n";
if(failMsgOut) {
(*failMsgOut) += "File is empty : " + filepath + "\n";
}
return false;
}
@ -1288,8 +1292,8 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
std::stringstream ss;
ss << "File size mismatch : " << filepath << ", requestedBytes "
<< reqBytes << ", but got " << sz << std::endl;
if (err) {
(*err) += ss.str();
if (failMsgOut) {
(*failMsgOut) += ss.str();
}
return false;
}
@ -2171,7 +2175,7 @@ static bool ParseImage(Image *image, std::string *err, std::string *warn,
#ifdef TINYGLTF_NO_EXTERNAL_IMAGE
return true;
#endif
if (!LoadExternalFile(&img, err, warn, uri, basedir, 0, false, fs)) {
if (!LoadExternalFile(&img, err, warn, uri, basedir, false, 0, false, fs)) {
if (warn) {
(*warn) += "Failed to load external 'uri' for image parameter\n";
}
@ -2266,7 +2270,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err, const json &o,
} else {
// External .bin file.
if (!LoadExternalFile(&buffer->data, err, /* warn */ nullptr, buffer->uri,
basedir, bytes, true, fs)) {
basedir, true, bytes, true, fs)) {
return false;
}
}
@ -2308,7 +2312,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err, const json &o,
} else {
// Assume external .bin file.
if (!LoadExternalFile(&buffer->data, err, /* warn */ nullptr, buffer->uri,
basedir, bytes, true, fs)) {
basedir, true, bytes, true, fs)) {
return false;
}
}