2015-04-24 19:55:30 +00:00
|
|
|
#include "myguidatamanager.hpp"
|
|
|
|
|
2022-07-18 18:49:50 +00:00
|
|
|
#include <stdexcept>
|
2022-05-16 22:58:24 +00:00
|
|
|
#include <string>
|
|
|
|
|
2015-04-24 19:55:30 +00:00
|
|
|
#include <MyGUI_DataFileStream.h>
|
|
|
|
|
2022-07-02 22:02:29 +00:00
|
|
|
#include <components/files/conversion.hpp>
|
2022-07-18 18:49:50 +00:00
|
|
|
#include <components/vfs/manager.hpp>
|
2015-04-24 19:55:30 +00:00
|
|
|
|
2022-07-19 19:40:34 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-04-30 23:15:25 +00:00
|
|
|
namespace osgMyGUI
|
2015-04-24 19:55:30 +00:00
|
|
|
{
|
|
|
|
|
2022-06-19 11:28:33 +00:00
|
|
|
void DataManager::setResourcePath(const std::filesystem::path& path)
|
2015-04-24 19:55:30 +00:00
|
|
|
{
|
|
|
|
mResourcePath = path;
|
|
|
|
}
|
|
|
|
|
2022-07-18 18:54:00 +00:00
|
|
|
DataManager::DataManager(const std::string& resourcePath, const VFS::Manager* vfs)
|
|
|
|
: mResourcePath(resourcePath)
|
|
|
|
, mVfs(vfs)
|
2022-07-18 19:34:12 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-12-16 18:48:10 +00:00
|
|
|
MyGUI::IDataStream* DataManager::getData(const std::string& name) const
|
2015-04-24 19:55:30 +00:00
|
|
|
{
|
2022-07-28 20:20:44 +00:00
|
|
|
return new DataStream(mVfs->get(Files::pathToUnicodeString(mResourcePath / name)));
|
2015-04-24 19:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataManager::freeData(MyGUI::IDataStream* data)
|
|
|
|
{
|
|
|
|
delete data;
|
|
|
|
}
|
|
|
|
|
2021-12-16 18:48:10 +00:00
|
|
|
bool DataManager::isDataExist(const std::string& name) const
|
2015-04-24 19:55:30 +00:00
|
|
|
{
|
2022-07-28 20:20:44 +00:00
|
|
|
return mVfs->exists(Files::pathToUnicodeString(mResourcePath / name));
|
2015-04-24 19:55:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 18:48:10 +00:00
|
|
|
const MyGUI::VectorString& DataManager::getDataListNames(const std::string& pattern) const
|
2015-04-24 19:55:30 +00:00
|
|
|
{
|
2022-07-09 15:58:40 +00:00
|
|
|
throw std::runtime_error("DataManager::getDataListNames is not implemented - VFS is used");
|
2015-04-24 19:55:30 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 18:48:10 +00:00
|
|
|
const std::string& DataManager::getDataPath(const std::string& name) const
|
2015-04-24 19:55:30 +00:00
|
|
|
{
|
2022-07-09 16:42:18 +00:00
|
|
|
static std::string result;
|
|
|
|
result.clear();
|
|
|
|
|
2022-07-28 20:20:44 +00:00
|
|
|
if (name.empty())
|
|
|
|
{
|
|
|
|
result = Files::pathToUnicodeString(mResourcePath);
|
|
|
|
return result;
|
|
|
|
}
|
2022-07-09 16:42:18 +00:00
|
|
|
|
|
|
|
if (!isDataExist(name))
|
|
|
|
return result;
|
|
|
|
|
2022-07-02 22:02:29 +00:00
|
|
|
result = Files::pathToUnicodeString(mResourcePath / name);
|
2022-07-09 16:42:18 +00:00
|
|
|
return result;
|
2015-04-24 19:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|