Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Attempt to initialise Doom3FileSystem in tests
Added a test/data directory with a PK4 containing a couple of test files. Test
can now initialise the Doom3FileSystem but files are not yet being looked up
correctly. Minor changes to Doom3FileSystem implementation, making the handling
of _modPath more lazy so that it won't trigger assertions caused by trying to
access the registry during initialisation.
  • Loading branch information
Matthew Mott committed Feb 20, 2019
1 parent 32cb245 commit 193ff89
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
Binary file added radiant/test/data/vfs_root/test_models.pk4
Binary file not shown.
15 changes: 15 additions & 0 deletions radiant/test/vfsTest.cpp
Expand Up @@ -18,3 +18,18 @@ BOOST_AUTO_TEST_CASE(constructFileSystemModule)
BOOST_TEST(fs.getFileCount("") == 0);
}

BOOST_AUTO_TEST_CASE(readFilesFromVFS)
{
vfs::VirtualFileSystem::ExtensionSet exts;
exts.insert("pk4");

vfs::SearchPaths paths;
paths.insertIfNotExists(std::string(getenv("srcdir")) + "/test/data/vfs_root");

vfs::Doom3FileSystem fs;
fs.initialise(paths, exts);

// Check presence of some files
BOOST_TEST(fs.getFileCount("nothere") == 0);
}

13 changes: 10 additions & 3 deletions radiant/vfs/DirectoryArchive.cpp
Expand Up @@ -11,10 +11,17 @@
#include "DirectoryArchiveTextFile.h"

DirectoryArchive::DirectoryArchive(const std::string& root) :
_root(root),
_modName(game::current::getModPath(_root))
_root(root)
{}

const std::string& DirectoryArchive::modName() const
{
if (_modName.empty())
_modName = game::current::getModPath(_root);

return _modName;
}

ArchiveFilePtr DirectoryArchive::openFile(const std::string& name)
{
UnixPath path(_root);
Expand All @@ -37,7 +44,7 @@ ArchiveTextFilePtr DirectoryArchive::openTextFile(const std::string& name)
path.push_filename(name);

std::shared_ptr<archive::DirectoryArchiveTextFile> file =
std::make_shared<archive::DirectoryArchiveTextFile>(name, _modName, path);
std::make_shared<archive::DirectoryArchiveTextFile>(name, modName(), path);

if (!file->failed())
{
Expand Down
6 changes: 4 additions & 2 deletions radiant/vfs/DirectoryArchive.h
Expand Up @@ -12,13 +12,15 @@
class DirectoryArchive :
public Archive
{
private:
std::string _root;

// The modname for constructing the ModResource is cached here
// since changing the game paths will trigger a re-initialisation
// of the VFS anyway.
std::string _modName;
mutable std::string _modName;

// Construct and return the mod name
const std::string& modName() const;

public:
// Pass the root path to the constructor
Expand Down
13 changes: 10 additions & 3 deletions radiant/vfs/ZipArchive.cpp
Expand Up @@ -32,7 +32,6 @@ class ZipFailureException :
ZipArchive::ZipArchive(const std::string& fullPath) :
_fullPath(fullPath),
_containingFolder(os::standardPathWithSlash(fs::path(_fullPath).remove_filename())),
_modName(game::current::getModPath(_containingFolder)),
_istream(_fullPath)
{
if (_istream.failed())
Expand All @@ -52,6 +51,14 @@ ZipArchive::ZipArchive(const std::string& fullPath) :
}
}

const std::string& ZipArchive::modName() const
{
if (_modName.empty())
_modName = game::current::getModPath(_containingFolder);

return _modName;
}

ZipArchive::~ZipArchive()
{
_filesystem.clear();
Expand Down Expand Up @@ -122,10 +129,10 @@ ArchiveTextFilePtr ZipArchive::openTextFile(const std::string& name)
switch (file->mode)
{
case ZipRecord::eStored:
return std::make_shared<StoredArchiveTextFile>(name, _fullPath, _modName, _istream.tell(), file->stream_size);
return std::make_shared<StoredArchiveTextFile>(name, _fullPath, modName(), _istream.tell(), file->stream_size);

case ZipRecord::eDeflated:
return std::make_shared<DeflatedArchiveTextFile>(name, _fullPath, _modName, _istream.tell(), file->stream_size);
return std::make_shared<DeflatedArchiveTextFile>(name, _fullPath, modName(), _istream.tell(), file->stream_size);
}
}

Expand Down
4 changes: 3 additions & 1 deletion radiant/vfs/ZipArchive.h
Expand Up @@ -50,10 +50,12 @@ class ZipArchive :
ZipFileSystem _filesystem;
std::string _fullPath; // the full path to the Zip file
std::string _containingFolder; // the folder this Zip is located in
std::string _modName; // mod name, calculated based on the containing folder
mutable std::string _modName; // mod name, calculated based on the containing folder
stream::FileInputStream _istream;
std::mutex _streamLock;

const std::string& modName() const;

public:
ZipArchive(const std::string& fullPath);
virtual ~ZipArchive();
Expand Down

0 comments on commit 193ff89

Please sign in to comment.