File: myguidatamanager.cpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (74 lines) | stat: -rw-r--r-- 1,780 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "myguidatamanager.hpp"

#include <stdexcept>
#include <string>

#include <MyGUI_DataFileStream.h>

#include <components/files/conversion.hpp>
#include <components/vfs/manager.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
{

    void DataManager::setResourcePath(const std::filesystem::path& path)
    {
        mResourcePath = path;
    }

    DataManager::DataManager(const std::string& resourcePath, const VFS::Manager* vfs)
        : mResourcePath(resourcePath)
        , mVfs(vfs)
    {
    }

    MyGUI::IDataStream* DataManager::getData(const std::string& name) const
    {
        return new DataStream(mVfs->get(Files::pathToUnicodeString(mResourcePath / name)));
    }

    void DataManager::freeData(MyGUI::IDataStream* data)
    {
        delete data;
    }

    bool DataManager::isDataExist(const std::string& name) const
    {
        return mVfs->exists(Files::pathToUnicodeString(mResourcePath / name));
    }

    const MyGUI::VectorString& DataManager::getDataListNames(const std::string& pattern) const
    {
        throw std::runtime_error("DataManager::getDataListNames is not implemented - VFS is used");
    }

    std::string DataManager::getDataPath(const std::string& name) const
    {
        if (name.empty())
        {
            return Files::pathToUnicodeString(mResourcePath);
        }

        if (!isDataExist(name))
            return {};

        return Files::pathToUnicodeString(mResourcePath / name);
    }

}