1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00
OpenMW/components/myguiplatform/myguidatamanager.cpp

68 lines
1.5 KiB
C++
Raw Normal View History

2015-04-24 21:55:30 +02:00
#include "myguidatamanager.hpp"
#include <memory>
#include <string>
2015-04-24 21:55:30 +02:00
#include <MyGUI_DataFileStream.h>
#include <filesystem>
#include <fstream>
2015-04-24 21:55:30 +02:00
2018-08-14 19:42:41 +04:00
#include <components/debug/debuglog.hpp>
2015-04-24 21:55:30 +02:00
2015-05-01 01:15:25 +02:00
namespace osgMyGUI
2015-04-24 21:55:30 +02:00
{
void DataManager::setResourcePath(const std::string &path)
{
mResourcePath = path;
}
2022-07-18 23:34:12 +04:00
DataManager::DataManager(const VFS::Manager* vfs)
: mVfs(vfs)
{
}
2021-12-16 19:48:10 +01:00
MyGUI::IDataStream *DataManager::getData(const std::string &name) const
2015-04-24 21:55:30 +02:00
{
2022-07-09 19:58:40 +04:00
// Note: MyGUI is supposed to read/free input steam itself,
// so copy data from VFS stream to the string stream and pass it to MyGUI.
2022-07-17 17:54:06 +04:00
Files::IStreamPtr streamPtr = mVfs->get(mResourcePath + "/" + name);
2022-07-09 19:58:40 +04:00
std::istream* fileStream = streamPtr.get();
2022-07-17 17:54:06 +04:00
auto dataStream = std::make_unique<std::stringstream>();
2022-07-09 19:58:40 +04:00
*dataStream << fileStream->rdbuf();
return new MyGUI::DataStream(dataStream.release());
2015-04-24 21:55:30 +02:00
}
void DataManager::freeData(MyGUI::IDataStream *data)
{
delete data;
}
2021-12-16 19:48:10 +01:00
bool DataManager::isDataExist(const std::string &name) const
2015-04-24 21:55:30 +02:00
{
2022-07-17 17:54:06 +04:00
return mVfs->exists(mResourcePath + "/" + name);
2015-04-24 21:55:30 +02:00
}
2021-12-16 19:48:10 +01:00
const MyGUI::VectorString &DataManager::getDataListNames(const std::string &pattern) const
2015-04-24 21:55:30 +02:00
{
2022-07-09 19:58:40 +04:00
throw std::runtime_error("DataManager::getDataListNames is not implemented - VFS is used");
2015-04-24 21:55:30 +02:00
}
2021-12-16 19:48:10 +01:00
const std::string &DataManager::getDataPath(const std::string &name) const
2015-04-24 21:55:30 +02:00
{
2022-07-09 20:42:18 +04:00
static std::string result;
result.clear();
if (name.empty())
return mResourcePath;
if (!isDataExist(name))
return result;
2022-07-17 17:54:06 +04:00
result = mResourcePath + "/" + name;
2022-07-09 20:42:18 +04:00
return result;
2015-04-24 21:55:30 +02:00
}
}