Remove unused Mangle::VFS
parent
bd68f7bd33
commit
b353cfd457
@ -1,85 +0,0 @@
|
||||
#include "ogre_archive.hpp"
|
||||
|
||||
#include "../../stream/clients/ogre_datastream.hpp"
|
||||
|
||||
using namespace Mangle::VFS;
|
||||
using namespace Mangle::Stream;
|
||||
|
||||
Ogre::DataStreamPtr MangleArchive::open(const Ogre::String& filename) const
|
||||
{
|
||||
return Ogre::DataStreamPtr(new Mangle2OgreStream
|
||||
(filename, vfs->open(filename)));
|
||||
}
|
||||
|
||||
static void fill(Ogre::FileInfoList &out, FileInfoList &in)
|
||||
{
|
||||
int size = in.size();
|
||||
out.resize(size);
|
||||
|
||||
for(int i=0; i<size; i++)
|
||||
{
|
||||
out[i].filename = in[i].name;
|
||||
out[i].basename = in[i].basename;
|
||||
out[i].path = ""; // FIXME
|
||||
out[i].uncompressedSize = in[i].size;
|
||||
out[i].compressedSize = in[i].size;
|
||||
}
|
||||
}
|
||||
|
||||
static void fill(Ogre::StringVector &out, FileInfoList &in)
|
||||
{
|
||||
int size = in.size();
|
||||
out.resize(size);
|
||||
|
||||
for(int i=0; i<size; i++)
|
||||
out[i] = in[i].name;
|
||||
}
|
||||
|
||||
Ogre::StringVectorPtr MangleArchive::list(bool recursive, bool dirs)
|
||||
{
|
||||
assert(vfs->hasList);
|
||||
FileInfoListPtr lst = vfs->list("", recursive, dirs);
|
||||
Ogre::StringVector *res = new Ogre::StringVector;
|
||||
|
||||
fill(*res, *lst);
|
||||
|
||||
return Ogre::StringVectorPtr(res);
|
||||
}
|
||||
|
||||
Ogre::FileInfoListPtr MangleArchive::listFileInfo(bool recursive, bool dirs)
|
||||
{
|
||||
assert(vfs->hasList);
|
||||
FileInfoListPtr lst = vfs->list("", recursive, dirs);
|
||||
Ogre::FileInfoList *res = new Ogre::FileInfoList;
|
||||
|
||||
fill(*res, *lst);
|
||||
|
||||
return Ogre::FileInfoListPtr(res);
|
||||
}
|
||||
|
||||
// Find functions will only work if vfs->hasFind is set.
|
||||
Ogre::StringVectorPtr MangleArchive::find(const Ogre::String& pattern,
|
||||
bool recursive,
|
||||
bool dirs)
|
||||
{
|
||||
assert(vfs->hasFind);
|
||||
FileInfoListPtr lst = vfs->find(pattern, recursive, dirs);
|
||||
Ogre::StringVector *res = new Ogre::StringVector;
|
||||
|
||||
fill(*res, *lst);
|
||||
|
||||
return Ogre::StringVectorPtr(res);
|
||||
}
|
||||
|
||||
Ogre::FileInfoListPtr MangleArchive::findFileInfo(const Ogre::String& pattern,
|
||||
bool recursive,
|
||||
bool dirs)
|
||||
{
|
||||
assert(vfs->hasFind);
|
||||
FileInfoListPtr lst = vfs->find(pattern, recursive, dirs);
|
||||
Ogre::FileInfoList *res = new Ogre::FileInfoList;
|
||||
|
||||
fill(*res, *lst);
|
||||
|
||||
return Ogre::FileInfoListPtr(res);
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
#ifndef MANGLE_VFS_OGRECLIENT_H
|
||||
#define MANGLE_VFS_OGRECLIENT_H
|
||||
|
||||
#include <OgreArchive.h>
|
||||
#include <assert.h>
|
||||
#include "../vfs.hpp"
|
||||
|
||||
namespace Mangle {
|
||||
namespace VFS {
|
||||
|
||||
/** An OGRE Archive implementation that wraps a Mangle::VFS
|
||||
filesystem.
|
||||
|
||||
This has been built and tested against OGRE 1.6.2, and has been
|
||||
extended for OGRE 1.7. You might have to make your own
|
||||
modifications if you're working with newer (or older) versions.
|
||||
*/
|
||||
class MangleArchive : public Ogre::Archive
|
||||
{
|
||||
VFSPtr vfs;
|
||||
|
||||
public:
|
||||
MangleArchive(VFSPtr _vfs, const std::string &name,
|
||||
const std::string &archType = "Mangle")
|
||||
: Ogre::Archive(name, archType)
|
||||
, vfs(_vfs)
|
||||
{}
|
||||
|
||||
bool isCaseSensitive() const { return vfs->isCaseSensitive; }
|
||||
|
||||
// These do nothing. You have to load / unload the archive in the
|
||||
// constructor/destructor.
|
||||
void load() {}
|
||||
void unload() {}
|
||||
|
||||
bool exists(const Ogre::String& filename)
|
||||
{ return vfs->isFile(filename); }
|
||||
|
||||
time_t getModifiedTime(const Ogre::String& filename)
|
||||
{ return vfs->stat(filename)->time; }
|
||||
|
||||
// With both these we support both OGRE 1.6 and 1.7
|
||||
Ogre::DataStreamPtr open(const Ogre::String& filename) const;
|
||||
Ogre::DataStreamPtr open(const Ogre::String& filename, bool readOnly) const
|
||||
{ return open(filename); }
|
||||
|
||||
Ogre::StringVectorPtr list(bool recursive = true, bool dirs = false);
|
||||
Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false);
|
||||
|
||||
// Find functions will only work if vfs->hasFind is set.
|
||||
Ogre::StringVectorPtr find(const Ogre::String& pattern, bool recursive = true,
|
||||
bool dirs = false);
|
||||
Ogre::FileInfoListPtr findFileInfo(const Ogre::String& pattern,
|
||||
bool recursive = true,
|
||||
bool dirs = false);
|
||||
};
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
@ -1,61 +0,0 @@
|
||||
#include "ogre_vfs.hpp"
|
||||
#include "../../stream/servers/ogre_datastream.hpp"
|
||||
|
||||
using namespace Mangle::VFS;
|
||||
using namespace Mangle::Stream;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
StreamPtr OgreVFS::open(const std::string &name)
|
||||
{
|
||||
Ogre::DataStreamPtr data = gm->openResource(name, group);
|
||||
return StreamPtr(new 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;
|
||||
}
|
||||
}
|
||||
|
||||
FileInfoListPtr OgreVFS::list(const std::string& dir,
|
||||
bool recurse,
|
||||
bool dirs) const
|
||||
{
|
||||
Ogre::FileInfoListPtr olist = gm->listResourceFileInfo(group, dirs);
|
||||
FileInfoListPtr res(new FileInfoList);
|
||||
fill(*res, *olist, dirs);
|
||||
return res;
|
||||
}
|
||||
|
||||
FileInfoListPtr OgreVFS::find(const std::string& pattern,
|
||||
bool recursive,
|
||||
bool dirs) const
|
||||
{
|
||||
Ogre::FileInfoListPtr olist = gm->findResourceFileInfo(group, pattern, dirs);
|
||||
FileInfoListPtr res(new FileInfoList);
|
||||
fill(*res, *olist, dirs);
|
||||
return res;
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
#ifndef MANGLE_VFS_OGRESERVER_H
|
||||
#define MANGLE_VFS_OGRESERVER_H
|
||||
|
||||
#include "../vfs.hpp"
|
||||
#include <OgreResourceGroupManager.h>
|
||||
|
||||
namespace Mangle {
|
||||
namespace VFS {
|
||||
|
||||
/** @brief An interface into the OGRE VFS system.
|
||||
|
||||
This class does NOT wrap a single Ogre::Archive, but rather an
|
||||
entire resource group in Ogre. You can use this class to tap into
|
||||
all paths, Zip files, custom archives on so on that have been
|
||||
inserted into Ogre as resource locations.
|
||||
|
||||
This has been built and tested against OGRE 1.6.2. You might have
|
||||
to make your own modifications if you're working with newer (or
|
||||
older) versions.
|
||||
*/
|
||||
class OgreVFS : public VFS
|
||||
{
|
||||
std::string group;
|
||||
Ogre::ResourceGroupManager *gm;
|
||||
|
||||
public:
|
||||
/** @brief Constructor
|
||||
|
||||
OGRE must be initialized (ie. you must have created an
|
||||
Ogre::Root object somewhere) before calling this.
|
||||
|
||||
@param group Optional resource group name. If none is given,
|
||||
OGRE's default (or 'World') resource group is used.
|
||||
*/
|
||||
OgreVFS(const std::string &_group = "");
|
||||
|
||||
/// Open a new data stream. Deleting the object should be enough to
|
||||
/// close it.
|
||||
virtual Stream::StreamPtr open(const std::string &name);
|
||||
|
||||
/// Check for the existence of a file
|
||||
virtual bool isFile(const std::string &name) const
|
||||
{ return gm->resourceExists(group, name); }
|
||||
|
||||
/// This doesn't work, always returns false.
|
||||
virtual bool isDir(const std::string &name) const
|
||||
{ return false; }
|
||||
|
||||
/// This doesn't work.
|
||||
virtual FileInfoPtr stat(const std::string &name) const
|
||||
{ return FileInfoPtr(); }
|
||||
|
||||
/// List all entries in a given directory. A blank dir should be
|
||||
/// interpreted as a the root/current directory of the archive. If
|
||||
/// dirs is true, list directories instead of files. OGRE note: The
|
||||
/// ogre resource systemd does not support recursive listing of
|
||||
/// files. We might make a separate filter for this later.
|
||||
virtual FileInfoListPtr list(const std::string& dir = "",
|
||||
bool recurse=true,
|
||||
bool dirs=false) const;
|
||||
|
||||
/// Find files after a given pattern. Wildcards (*) are
|
||||
/// supported.
|
||||
virtual FileInfoListPtr find(const std::string& pattern,
|
||||
bool recursive=true,
|
||||
bool dirs=false) const;
|
||||
};
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
@ -1,71 +0,0 @@
|
||||
#ifndef MANGLE_VFS_PHYSFS_SERVER_H
|
||||
#define MANGLE_VFS_PHYSFS_SERVER_H
|
||||
|
||||
#include "../vfs.hpp"
|
||||
#include "../../stream/servers/phys_stream.hpp"
|
||||
|
||||
#include <physfs.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Mangle {
|
||||
namespace VFS {
|
||||
|
||||
/** @brief An interface into the PhysFS virtual file system library
|
||||
|
||||
You have to set up PhysFS on your own before using this class.
|
||||
*/
|
||||
class PhysVFS : public VFS
|
||||
{
|
||||
public:
|
||||
PhysVFS()
|
||||
{
|
||||
hasList = true;
|
||||
hasFind = false;
|
||||
isCaseSensitive = true;
|
||||
}
|
||||
|
||||
/// Open a new data stream. Deleting the object should be enough to
|
||||
/// close it.
|
||||
virtual Stream::StreamPtr open(const std::string &name)
|
||||
{ return Stream::StreamPtr(new Stream::PhysFile(PHYSFS_openRead(name.c_str()))); }
|
||||
|
||||
/// Check for the existence of a file
|
||||
virtual bool isFile(const std::string &name) const
|
||||
{ return PHYSFS_exists(name.c_str()); }
|
||||
|
||||
/// Checks for a directory
|
||||
virtual bool isDir(const std::string &name) const
|
||||
{ return PHYSFS_isDirectory(name.c_str()); }
|
||||
|
||||
/// This doesn't work
|
||||
virtual FileInfoPtr stat(const std::string &name) const
|
||||
{ assert(0); return FileInfoPtr(); }
|
||||
|
||||
virtual FileInfoListPtr list(const std::string& dir = "",
|
||||
bool recurse=true,
|
||||
bool dirs=false) const
|
||||
{
|
||||
char **files = PHYSFS_enumerateFiles(dir.c_str());
|
||||
FileInfoListPtr lst(new FileInfoList);
|
||||
|
||||
// Add all teh files
|
||||
int i = 0;
|
||||
while(files[i] != NULL)
|
||||
{
|
||||
FileInfo fi;
|
||||
fi.name = files[i];
|
||||
fi.isDir = false;
|
||||
|
||||
lst->push_back(fi);
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
virtual FileInfoListPtr find(const std::string& pattern,
|
||||
bool recursive=true,
|
||||
bool dirs=false) const
|
||||
{ assert(0); }
|
||||
};
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
@ -1 +0,0 @@
|
||||
*_test
|
@ -1,25 +0,0 @@
|
||||
GCC=g++ -I../ -Wall
|
||||
|
||||
all: dummy_test ogre_client_test ogre_resource_test ogre_server_test physfs_server_test
|
||||
|
||||
I_OGRE=$(shell pkg-config --cflags OGRE)
|
||||
L_OGRE=$(shell pkg-config --libs OGRE)
|
||||
L_PHYSFS=-lphysfs
|
||||
|
||||
ogre_client_test: ogre_client_test.cpp dummy_vfs.cpp ../vfs.hpp ../clients/ogre_archive.hpp ../clients/ogre_archive.cpp
|
||||
$(GCC) $< ../clients/ogre_archive.cpp -o $@ $(I_OGRE) $(L_OGRE)
|
||||
|
||||
ogre_resource_test: ogre_resource_test.cpp
|
||||
$(GCC) $< -o $@ $(I_OGRE) $(L_OGRE)
|
||||
|
||||
ogre_server_test: ogre_server_test.cpp ../vfs.hpp ../servers/ogre_vfs.hpp ../servers/ogre_vfs.cpp
|
||||
$(GCC) $< -o $@ $(I_OGRE) $(L_OGRE) ../servers/ogre_vfs.cpp
|
||||
|
||||
physfs_server_test: physfs_server_test.cpp ../vfs.hpp ../servers/physfs_vfs.hpp
|
||||
$(GCC) $< -o $@ $(L_PHYSFS)
|
||||
|
||||
dummy_test: dummy_test.cpp dummy_vfs.cpp ../vfs.hpp
|
||||
$(GCC) $< -o $@
|
||||
|
||||
clean:
|
||||
rm *_test
|
@ -1,42 +0,0 @@
|
||||
#include "dummy_vfs.cpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void print(FileInfo &inf)
|
||||
{
|
||||
cout << "name: " << inf.name << endl;
|
||||
cout << "basename: " << inf.basename << endl;
|
||||
cout << "isDir: " << inf.isDir << endl;
|
||||
cout << "size: " << inf.size << endl;
|
||||
cout << "time: " << inf.time << endl;
|
||||
}
|
||||
void print(FileInfoPtr inf) { print(*inf); }
|
||||
|
||||
void print(FileInfoList &lst)
|
||||
{
|
||||
for(unsigned i=0; i<lst.size(); i++)
|
||||
print(lst[i]);
|
||||
}
|
||||
void print(FileInfoListPtr lst) { print(*lst); }
|
||||
|
||||
int main()
|
||||
{
|
||||
DummyVFS vfs;
|
||||
|
||||
cout << "Listing all files:\n";
|
||||
print(vfs.list());
|
||||
cout << "\nStat for single files:\n";
|
||||
print(vfs.stat("file1"));
|
||||
cout << endl;
|
||||
print(vfs.stat("dir/file2"));
|
||||
cout << endl;
|
||||
print(vfs.stat("dir"));
|
||||
|
||||
StreamPtr inp = vfs.open("file1");
|
||||
cout << "filesize: " << inp->size() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
// This file is shared between several test programs
|
||||
#include "vfs.hpp"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../stream/servers/memory_stream.hpp"
|
||||
|
||||
using namespace Mangle::VFS;
|
||||
using namespace Mangle::Stream;
|
||||
|
||||
class DummyVFS : public VFS
|
||||
{
|
||||
public:
|
||||
DummyVFS()
|
||||
{
|
||||
hasFind = false;
|
||||
hasList = true;
|
||||
isCaseSensitive = true;
|
||||
}
|
||||
|
||||
// We only support opening 'file1' at the moment.
|
||||
StreamPtr open(const std::string &name)
|
||||
{
|
||||
assert(name == "file1");
|
||||
return StreamPtr(new MemoryStream("hello world", 11));
|
||||
}
|
||||
|
||||
bool isFile(const std::string &name) const
|
||||
{
|
||||
return (name == "file1" ||
|
||||
name == "dir/file2");
|
||||
}
|
||||
|
||||
bool isDir(const std::string &name) const
|
||||
{
|
||||
return name == "dir";
|
||||
}
|
||||
|
||||
/// Get info about a single file
|
||||
FileInfoPtr stat(const std::string &name) const
|
||||
{
|
||||
FileInfoPtr fi(new FileInfo);
|
||||
fi->name = name;
|
||||
fi->time = 0;
|
||||
|
||||
if(isFile(name))
|
||||
{
|
||||
if(name == "dir/file2")
|
||||
{
|
||||
fi->basename = "file2";
|
||||
fi->size = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
fi->basename = "file1";
|
||||
fi->size = 1;
|
||||
}
|
||||
fi->isDir = false;
|
||||
}
|
||||
else if(isDir(name))
|
||||
{
|
||||
fi->basename = "dir";
|
||||
fi->isDir = true;
|
||||
fi->size = 0;
|
||||
}
|
||||
else assert(0);
|
||||
|
||||
return fi;
|
||||
}
|
||||
|
||||
/// List all entries in a given directory. A blank dir should be
|
||||
/// interpreted as a the root/current directory of the archive. If
|
||||
/// dirs is true, list directories instead of files.
|
||||
virtual FileInfoListPtr list(const std::string& dir = "",
|
||||
bool recurse=true,
|
||||
bool dirs=false) const
|
||||
{
|
||||
assert(dir == "");
|
||||
|
||||
FileInfoListPtr fl(new FileInfoList);
|
||||
|
||||
FileInfo fi;
|
||||
|
||||
if(!dirs)
|
||||
{
|
||||
fi.name = "file1";
|
||||
fi.basename = "file1";
|
||||
fi.isDir = false;
|
||||
fi.size = 1;
|
||||
fi.time = 0;
|
||||
fl->push_back(fi);
|
||||
|
||||
if(recurse)
|
||||
{
|
||||
fi.name = "dir/file2";
|
||||
fi.basename = "file2";
|
||||
fi.size = 2;
|
||||
fl->push_back(fi);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fi.name = "dir";
|
||||
fi.basename = "dir";
|
||||
fi.isDir = true;
|
||||
fi.size = 0;
|
||||
fi.time = 0;
|
||||
fl->push_back(fi);
|
||||
}
|
||||
return fl;
|
||||
}
|
||||
|
||||
FileInfoListPtr find(const std::string& pattern,
|
||||
bool recursive=true,
|
||||
bool dirs=false) const
|
||||
{ assert(0); }
|
||||
};
|
@ -1,39 +0,0 @@
|
||||
#include "dummy_vfs.cpp"
|
||||
#include "../clients/ogre_archive.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace Ogre;
|
||||
using namespace std;
|
||||
|
||||
void print(StringVectorPtr lst)
|
||||
{
|
||||
int s = lst->size();
|
||||
|
||||
for(int i=0; i<s; i++)
|
||||
{
|
||||
cout << " " << (*lst)[i] << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
VFSPtr vfs(new DummyVFS());
|
||||
MangleArchive arc(vfs, "dummy");
|
||||
|
||||
cout << "Case: " << arc.isCaseSensitive() << endl;
|
||||
cout << "Name: " << arc.getName() << endl;
|
||||
cout << "Type: " << arc.getType() << endl;
|
||||
cout << "All files:\n";
|
||||
print(arc.list());
|
||||
cout << "Non-recursive:\n";
|
||||
print(arc.list(false, false));
|
||||
cout << "Dirs:\n";
|
||||
print(arc.list(false, true));
|
||||
|
||||
DataStreamPtr file = arc.open("file1");
|
||||
|
||||
cout << "filesize: " << file->size() << endl;
|
||||
cout << "contents: " << file->getAsString() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <OgreRoot.h>
|
||||
#include <OgreResourceGroupManager.h>
|
||||
|
||||
/*
|
||||
This isn't really a test of our implementation, but a test of using
|
||||
the Ogre resource system to find files. If the Ogre interface
|
||||
changes and you have to change this test, you will have to change
|
||||
the servers/ogre_vfs.cpp implementation equivalently.
|
||||
|
||||
*/
|
||||
|
||||
using namespace std;
|
||||
using namespace Ogre;
|
||||
|
||||
ResourceGroupManager *gm;
|
||||
String group;
|
||||
|
||||
void find(const std::string &fileName)
|
||||
{
|
||||
cout << "\nFile: " << fileName << endl;
|
||||
|
||||
if(!gm->resourceExists(group, fileName))
|
||||
{
|
||||
cout << "Does not exist\n";
|
||||
return;
|
||||
}
|
||||
|
||||
DataStreamPtr data = gm->openResource(fileName, group);
|
||||
|
||||
cout << "Size: " << data->size() << endl;
|
||||
cout << "First line: " << data->getLine() << "\n";
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Disable logging
|
||||
new LogManager;
|
||||
Log *log = LogManager::getSingleton().createLog("");
|
||||
log->setDebugOutputEnabled(false);
|
||||
|
||||
// Set up Ogre
|
||||
Root root("","","");
|
||||
|
||||
root.addResourceLocation("./", "FileSystem", "General");
|
||||
|
||||
gm = ResourceGroupManager::getSingletonPtr();
|
||||
group = gm->getWorldResourceGroupName();
|
||||
|
||||
find("Makefile");
|
||||
find("ogre_resource_test.cpp");
|
||||
find("bleh");
|
||||
|
||||
cout << "\nAll source files:\n";
|
||||
FileInfoListPtr list = gm->findResourceFileInfo(group, "*.cpp");
|
||||
FileInfoList::iterator it, end;
|
||||
it = list->begin();
|
||||
end = list->end();
|
||||
for(; it != end; it++)
|
||||
cout << " " << it->filename << endl;
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
#include "../servers/ogre_vfs.hpp"
|
||||
|
||||
#include <Ogre.h>
|
||||
|
||||
#include "server_common.cpp"
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Set up the engine
|
||||
setupOgre();
|
||||
|
||||
// This is our entry point into the resource file system
|
||||
OgreVFS vfs("General");
|
||||
|
||||
// Run the test
|
||||
testAll(vfs);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
Listing all files:
|
||||
name: file1
|
||||
basename: file1
|
||||
isDir: 0
|
||||
size: 1
|
||||
time: 0
|
||||
name: dir/file2
|
||||
basename: file2
|
||||
isDir: 0
|
||||
size: 2
|
||||
time: 0
|
||||
|
||||
Stat for single files:
|
||||
name: file1
|
||||
basename: file1
|
||||
isDir: 0
|
||||
size: 1
|
||||
time: 0
|
||||
|
||||
name: dir/file2
|
||||
basename: file2
|
||||
isDir: 0
|
||||
size: 2
|
||||
time: 0
|
||||
|
||||
name: dir
|
||||
basename: dir
|
||||
isDir: 1
|
||||
size: 0
|
||||
time: 0
|
||||
filesize: 11
|
@ -1,12 +0,0 @@
|
||||
Case: 1
|
||||
Name: dummy
|
||||
Type: Mangle
|
||||
All files:
|
||||
file1
|
||||
dir/file2
|
||||
Non-recursive:
|
||||
file1
|
||||
Dirs:
|
||||
dir
|
||||
filesize: 11
|
||||
contents: hello world
|
@ -1,20 +0,0 @@
|
||||
|
||||
File: Makefile
|
||||
Size: 828
|
||||
First line: GCC=g++ -I../
|
||||
|
||||
File: ogre_resource_test.cpp
|
||||
Size: 1437
|
||||
First line: #include <iostream>
|
||||
|
||||
File: bleh
|
||||
Does not exist
|
||||
|
||||
All source files:
|
||||
physfs_server_test.cpp
|
||||
dummy_test.cpp
|
||||
ogre_resource_test.cpp
|
||||
server_common.cpp
|
||||
dummy_vfs.cpp
|
||||
ogre_client_test.cpp
|
||||
ogre_server_test.cpp
|
@ -1,11 +0,0 @@
|
||||
|
||||
File: Makefile
|
||||
Size: 828
|
||||
First 12 bytes: GCC=g++ -I..
|
||||
|
||||
File: testfile.txt
|
||||
Size: 13
|
||||
First 12 bytes: hello world!
|
||||
|
||||
File: blah_bleh
|
||||
File doesn't exist
|
@ -1,11 +0,0 @@
|
||||
|
||||
File: Makefile
|
||||
Size: 828
|
||||
First 12 bytes: GCC=g++ -I..
|
||||
|
||||
File: testfile.txt
|
||||
Size: 13
|
||||
First 12 bytes: hello world!
|
||||
|
||||
File: blah_bleh
|
||||
File doesn't exist
|
@ -1,21 +0,0 @@
|
||||
#include "../servers/physfs_vfs.hpp"
|
||||
|
||||
#include "server_common.cpp"
|
||||
|
||||
#include <physfs.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// Set up the library and paths
|
||||
PHYSFS_init("blah");
|
||||
PHYSFS_addToSearchPath("test.zip", 1);
|
||||
PHYSFS_addToSearchPath("./", 1);
|
||||
|
||||
// Create our interface
|
||||
PhysVFS vfs;
|
||||
|
||||
// Run the test
|
||||
testAll(vfs);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace Mangle::VFS;
|
||||
using namespace Mangle::Stream;
|
||||
using namespace std;
|
||||
|
||||
void find(VFS &vfs, const std::string &file)
|
||||
{
|
||||
cout << "\nFile: " << file << endl;
|
||||
|
||||
if(!vfs.isFile(file))
|
||||
{
|
||||
cout << "File doesn't exist\n";
|
||||
return;
|
||||
}
|
||||
|
||||
StreamPtr 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";
|
||||
}
|
||||
|
||||
void testAll(VFS &vfs)
|
||||
{
|
||||
find(vfs, "Makefile"); // From the file system
|
||||
find(vfs, "testfile.txt"); // From the zip
|
||||
find(vfs, "blah_bleh"); // Doesn't exist
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
make || exit
|
||||
|
||||
mkdir -p output
|
||||
|
||||
PROGS=*_test
|
||||
|
||||
for a in $PROGS; do
|
||||
if [ -f "output/$a.out" ]; then
|
||||
echo "Running $a:"
|
||||
./$a | diff output/$a.out -
|
||||
else
|
||||
echo "Creating $a.out"
|
||||
./$a > "output/$a.out"
|
||||
git add "output/$a.out"
|
||||
fi
|
||||
done
|
Binary file not shown.
@ -1,87 +0,0 @@
|
||||
#ifndef MANGLE_VFS_H
|
||||
#define MANGLE_VFS_H
|
||||
|
||||
#include "../stream/stream.hpp"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Mangle {
|
||||
namespace VFS {
|
||||
|
||||
/// Generic file info structure
|
||||
struct FileInfo
|
||||
{
|
||||
/// Full name, including path
|
||||
std::string name;
|
||||
|
||||
/// Base name, not including path
|
||||
std::string basename;
|
||||
|
||||
/// Is this a directory?
|
||||
bool isDir;
|
||||
|
||||
/// File size
|
||||
size_t size;
|
||||
|
||||
/// Last modification date
|
||||
time_t time;
|
||||
};
|
||||
|
||||
typedef std::vector<FileInfo> FileInfoList;
|
||||
|
||||
typedef boost::shared_ptr<FileInfo> FileInfoPtr;
|
||||
typedef boost::shared_ptr<FileInfoList> FileInfoListPtr;
|
||||
|
||||
/** An interface to any file system or other provider of named data
|
||||
streams
|
||||
*/
|
||||
class VFS
|
||||
{
|
||||
public:
|
||||
// Feature options. These should be set in the constructor.
|
||||
|
||||
/// If true, the list() function work
|
||||
bool hasList;
|
||||
|
||||
/// If true, the find() function work
|
||||
bool hasFind;
|
||||
|
||||
/// If true, the file system is case sensitive
|
||||
bool isCaseSensitive;
|
||||
|
||||
/// Virtual destructor
|
||||
virtual ~VFS() {}
|
||||
|
||||
/// Open a new data stream. Deleting the object (letting all the
|
||||
/// pointers to it go out of scope) should be enough to close it.
|
||||
virtual Stream::StreamPtr open(const std::string &name) = 0;
|
||||
|
||||
/// Check for the existence of a file
|
||||
virtual bool isFile(const std::string &name) const = 0;
|
||||
|
||||
/// Check for the existence of a directory
|
||||
virtual bool isDir(const std::string &name) const = 0;
|
||||
|
||||
/// Get info about a single file
|
||||
virtual FileInfoPtr stat(const std::string &name) const = 0;
|
||||
|
||||
/// List all entries in a given directory. A blank dir should be
|
||||
/// interpreted as a the root/current directory of the archive. If
|
||||
/// dirs is true, list directories instead of files.
|
||||
virtual FileInfoListPtr list(const std::string& dir = "",
|
||||
bool recurse=true,
|
||||
bool dirs=false) const = 0;
|
||||
|
||||
/// Find files after a given pattern. Wildcards (*) are
|
||||
/// supported. Only valid if 'hasFind' is true. Don't implement your
|
||||
/// own pattern matching here if the backend doesn't support it
|
||||
/// natively; use a filter instead.
|
||||
virtual FileInfoListPtr find(const std::string& pattern,
|
||||
bool recursive=true,
|
||||
bool dirs=false) const = 0;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<VFS> VFSPtr;
|
||||
|
||||
}} // namespaces
|
||||
#endif
|
Loading…
Reference in New Issue