mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 08:45:36 +00:00
Improve binding VFS to MyGUI
This commit is contained in:
parent
3b75ae7ff1
commit
168a097c8b
1 changed files with 16 additions and 7 deletions
|
@ -10,6 +10,21 @@
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class DataStream final : public MyGUI::DataStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit DataStream(std::unique_ptr<std::istream>&& stream)
|
||||||
|
: MyGUI::DataStream(stream.get())
|
||||||
|
, mOwnedStream(std::move(stream))
|
||||||
|
{}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<std::istream> mOwnedStream;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace osgMyGUI
|
namespace osgMyGUI
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -25,13 +40,7 @@ DataManager::DataManager(const VFS::Manager* vfs)
|
||||||
|
|
||||||
MyGUI::IDataStream *DataManager::getData(const std::string &name) const
|
MyGUI::IDataStream *DataManager::getData(const std::string &name) const
|
||||||
{
|
{
|
||||||
// Note: MyGUI is supposed to read/free input steam itself,
|
return new DataStream(mVfs->get(mResourcePath + "/" + name));
|
||||||
// so copy data from VFS stream to the string stream and pass it to MyGUI.
|
|
||||||
Files::IStreamPtr streamPtr = mVfs->get(mResourcePath + "/" + name);
|
|
||||||
std::istream* fileStream = streamPtr.get();
|
|
||||||
auto dataStream = std::make_unique<std::stringstream>();
|
|
||||||
*dataStream << fileStream->rdbuf();
|
|
||||||
return new MyGUI::DataStream(dataStream.release());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::freeData(MyGUI::IDataStream *data)
|
void DataManager::freeData(MyGUI::IDataStream *data)
|
||||||
|
|
Loading…
Reference in a new issue