Completed OGRE VFS server +test
parent
b601cdff62
commit
262cb9255c
@ -0,0 +1,60 @@
|
||||
#include "ogre_vfs.h"
|
||||
#include "../../stream/imp_server/ogre_datastream.h"
|
||||
|
||||
using namespace Mangle::VFS;
|
||||
|
||||
OgreVFS::OgreVFS(const std::string &_group)
|
||||
: group(_group)
|
||||
{
|
||||
hasList = true;
|
||||
hasFind = true;
|
||||
isCaseSensitive = true;
|
||||
|
||||
// Get the group manager once
|
||||
gm = Ogre::ResourceGroupManager::getSingletonPtr();
|
||||
|
||||
// Use the default group if none was specified
|
||||
if(group.empty())
|
||||
group = gm->getWorldResourceGroupName();
|
||||
}
|
||||
|
||||
Mangle::Stream::InputStream *OgreVFS::open(const std::string &name)
|
||||
{
|
||||
Ogre::DataStreamPtr data = gm->openResource(name, group);
|
||||
return new Stream::OgreStream(data);
|
||||
}
|
||||
|
||||
static void fill(FileInfoList &out, Ogre::FileInfoList &in, bool dirs)
|
||||
{
|
||||
int size = in.size();
|
||||
out.resize(size);
|
||||
|
||||
for(int i=0; i<size; i++)
|
||||
{
|
||||
out[i].name = in[i].filename;
|
||||
out[i].basename = in[i].basename;
|
||||
out[i].size = in[i].uncompressedSize;
|
||||
out[i].isDir = dirs;
|
||||
out[i].time = 0;
|
||||
}
|
||||
}
|
||||
|
||||
FileInfoList OgreVFS::list(const std::string& dir,
|
||||
bool recurse,
|
||||
bool dirs) const
|
||||
{
|
||||
Ogre::FileInfoListPtr olist = gm->listResourceFileInfo(group, dirs);
|
||||
FileInfoList res;
|
||||
fill(res, *olist, dirs);
|
||||
return res;
|
||||
}
|
||||
|
||||
FileInfoList OgreVFS::find(const std::string& pattern,
|
||||
bool recursive,
|
||||
bool dirs) const
|
||||
{
|
||||
Ogre::FileInfoListPtr olist = gm->findResourceFileInfo(group, pattern, dirs);
|
||||
FileInfoList res;
|
||||
fill(res, *olist, dirs);
|
||||
return res;
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
#include "../imp_server/ogre_vfs.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <Ogre.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Mangle::VFS;
|
||||
using namespace Mangle::Stream;
|
||||
|
||||
Ogre::Root *root;
|
||||
|
||||
void setupOgre()
|
||||
{
|
||||
using namespace Ogre;
|
||||
|
||||
// Disable logging
|
||||
new LogManager;
|
||||
Log *log = LogManager::getSingleton().createLog("");
|
||||
log->setDebugOutputEnabled(false);
|
||||
|
||||
// Set up Root
|
||||
root = new Root("","","");
|
||||
|
||||
// Add a zip file and the current directory
|
||||
root->addResourceLocation("test.zip", "Zip", "General");
|
||||
root->addResourceLocation("./", "FileSystem", "General");
|
||||
}
|
||||
|
||||
void find(VFS &vfs, const std::string &file)
|
||||
{
|
||||
cout << "\nFile: " << file << endl;
|
||||
|
||||
if(!vfs.isFile(file))
|
||||
{
|
||||
cout << "File doesn't exist\n";
|
||||
return;
|
||||
}
|
||||
|
||||
InputStream *data = vfs.open(file);
|
||||
|
||||
cout << "Size: " << data->size() << endl;
|
||||
|
||||
char buf[13];
|
||||
buf[12] = 0;
|
||||
data->read(buf, 12);
|
||||
|
||||
cout << "First 12 bytes: " << buf << "\n";
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Set up the engine
|
||||
setupOgre();
|
||||
|
||||
// This is our entry point into the resource file system
|
||||
OgreVFS vfs("General");
|
||||
|
||||
find(vfs, "Makefile"); // From the file system
|
||||
find(vfs, "testfile.txt"); // From the zip
|
||||
find(vfs, "blah_bleh"); // Doesn't exist
|
||||
|
||||
return 0;
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue