Fix thumbnail cache retrieval
Use direct reading of thumbnail-cache files, instead of using libCurl
This commit is contained in:
14
simgear/io/iostreams/sgstream.cxx
Normal file → Executable file
14
simgear/io/iostreams/sgstream.cxx
Normal file → Executable file
@@ -227,6 +227,20 @@ void sg_ifstream::open( const SGPath& name, ios_openmode io_mode )
|
||||
std::ifstream::open(ps.c_str(), io_mode);
|
||||
}
|
||||
|
||||
std::string sg_ifstream::read_all()
|
||||
{
|
||||
this->seekg(0, std::ios::end); // seek to end
|
||||
const auto pos = this->tellg();
|
||||
|
||||
std::string result;
|
||||
result.resize(pos);
|
||||
|
||||
this->seekg(0, std::ios::beg);
|
||||
this->read(const_cast<char*>(result.data()), pos);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
sg_ofstream::sg_ofstream(const SGPath& path, ios_openmode io_mode)
|
||||
{
|
||||
#if defined(SG_WINDOWS)
|
||||
|
||||
@@ -196,6 +196,10 @@ public:
|
||||
|
||||
void open( const SGPath& name,
|
||||
ios_openmode io_mode = ios_in|ios_binary );
|
||||
|
||||
/// read the entire stream into a buffer. Use on files, etc - not recommended on streams
|
||||
/// which never EOF, will bvlock forever.
|
||||
std::string read_all();
|
||||
};
|
||||
|
||||
class sg_ofstream : public std::ofstream
|
||||
|
||||
24
simgear/package/Root.cxx
Normal file → Executable file
24
simgear/package/Root.cxx
Normal file → Executable file
@@ -178,8 +178,7 @@ public:
|
||||
SG_LOG(SG_IO, SG_WARN, "Download failed for: " << u << ", will use old cached data");
|
||||
cachePath.touch(); // touch the file so we don't repeat this danxce
|
||||
// kick a load from the cache
|
||||
|
||||
queueLoadFromPersistentCache(u, cachePath);
|
||||
loadFromPersistentCache(u, cachePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,6 +201,7 @@ public:
|
||||
|
||||
std::string u = pendingThumbnails.front();
|
||||
pendingThumbnails.pop_front();
|
||||
|
||||
thumbnailDownloadRequest = new Root::ThumbnailDownloader(this, u);
|
||||
|
||||
if (http) {
|
||||
@@ -260,11 +260,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
queueLoadFromPersistentCache(url, cachePath);
|
||||
loadFromPersistentCache(url, cachePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
void queueLoadFromPersistentCache(const std::string& url, const SGPath& path)
|
||||
void loadFromPersistentCache(const std::string& url, const SGPath& path)
|
||||
{
|
||||
assert(path.exists());
|
||||
|
||||
@@ -277,17 +277,9 @@ public:
|
||||
assert(it->second.pathOnDisk.isNull() || (it->second.pathOnDisk == path));
|
||||
}
|
||||
|
||||
if (it->second.requestPending) {
|
||||
return; // all done
|
||||
}
|
||||
|
||||
it->second.requestPending = true;
|
||||
auto dl = new Root::ThumbnailDownloader(this, path.fileUrl(), url);
|
||||
if (http) {
|
||||
http->makeRequest(dl);
|
||||
} else {
|
||||
httpPendingRequests.push_back(dl);
|
||||
}
|
||||
sg_ifstream thumbnailStream(path, std::ios::in | std::ios::binary);
|
||||
string bytes = thumbnailStream.read_all();
|
||||
fireDataForThumbnail(url, reinterpret_cast<const uint8_t*>(bytes.data()), bytes.size());
|
||||
}
|
||||
|
||||
DelegateVec delegates;
|
||||
@@ -813,7 +805,7 @@ void Root::requestThumbnailData(const std::string& aUrl)
|
||||
}
|
||||
} else {
|
||||
if (!it->second.requestPending && it->second.pathOnDisk.exists()) {
|
||||
d->queueLoadFromPersistentCache(aUrl, it->second.pathOnDisk);
|
||||
d->loadFromPersistentCache(aUrl, it->second.pathOnDisk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,14 +107,7 @@ bool loadShaderFromUTF8File(osg::Shader* shader, const std::string& fileName)
|
||||
if (!inStream.is_open())
|
||||
return false;
|
||||
|
||||
string shaderSource;
|
||||
while (!inStream.eof()) {
|
||||
char bytes[8192];
|
||||
inStream.read(bytes, 8192);
|
||||
shaderSource.append(bytes, inStream.gcount());
|
||||
}
|
||||
inStream.close();
|
||||
shader->setShaderSource(shaderSource);
|
||||
shader->setShaderSource(inStream.read_all());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user