forked from teamnwah/openmw-tes3coop
OpenCS: use the new VFS, restored resource tables
This commit is contained in:
parent
49c2da27b3
commit
40fc097722
13 changed files with 143 additions and 76 deletions
|
@ -1,21 +1,13 @@
|
||||||
|
|
||||||
#include "editor.hpp"
|
#include "editor.hpp"
|
||||||
|
|
||||||
#include <openengine/bullet/BulletShapeLoader.h>
|
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QLocalServer>
|
#include <QLocalServer>
|
||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include <OgreRoot.h>
|
#include <components/vfs/manager.hpp>
|
||||||
#include <OgreRenderWindow.h>
|
#include <components/vfs/registerarchives.hpp>
|
||||||
|
|
||||||
#include <extern/shiny/Main/Factory.hpp>
|
|
||||||
#include <extern/shiny/Platforms/Ogre/OgrePlatform.hpp>
|
|
||||||
|
|
||||||
#include <components/ogreinit/ogreinit.hpp>
|
|
||||||
#include <components/nifogre/ogrenifloader.hpp>
|
|
||||||
|
|
||||||
#include "model/doc/document.hpp"
|
#include "model/doc/document.hpp"
|
||||||
#include "model/world/data.hpp"
|
#include "model/world/data.hpp"
|
||||||
|
@ -34,10 +26,11 @@ CS::Editor::Editor ()
|
||||||
|
|
||||||
//NifOgre::Loader::setShowMarkers(true);
|
//NifOgre::Loader::setShowMarkers(true);
|
||||||
|
|
||||||
//Bsa::registerResources (Files::Collections (config.first, !mFsStrict), config.second, true,
|
mVFS.reset(new VFS::Manager(mFsStrict));
|
||||||
// mFsStrict);
|
|
||||||
|
|
||||||
mDocumentManager.listResources();
|
VFS::registerArchives(mVFS.get(), Files::Collections(config.first, !mFsStrict), config.second, true);
|
||||||
|
|
||||||
|
mDocumentManager.setVFS(mVFS.get());
|
||||||
|
|
||||||
mNewGame.setLocalData (mLocal);
|
mNewGame.setLocalData (mLocal);
|
||||||
mFileDialog.setLocalData (mLocal);
|
mFileDialog.setLocalData (mLocal);
|
||||||
|
@ -74,9 +67,6 @@ CS::Editor::~Editor ()
|
||||||
if(mServer && boost::filesystem::exists(mPid))
|
if(mServer && boost::filesystem::exists(mPid))
|
||||||
static_cast<void> ( // silence coverity warning
|
static_cast<void> ( // silence coverity warning
|
||||||
remove(mPid.string().c_str())); // ignore any error
|
remove(mPid.string().c_str())); // ignore any error
|
||||||
|
|
||||||
// cleanup global resources used by OEngine
|
|
||||||
delete OEngine::Physic::BulletShapeManager::getSingletonPtr();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CS::Editor::setupDataFiles (const Files::PathContainer& dataDirs)
|
void CS::Editor::setupDataFiles (const Files::PathContainer& dataDirs)
|
||||||
|
|
|
@ -27,12 +27,20 @@
|
||||||
|
|
||||||
#include "view/settings/dialog.hpp"
|
#include "view/settings/dialog.hpp"
|
||||||
|
|
||||||
|
namespace VFS
|
||||||
|
{
|
||||||
|
class Manager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CS
|
namespace CS
|
||||||
{
|
{
|
||||||
class Editor : public QObject
|
class Editor : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
// FIXME: should be moved to document, so we can have different resources for each opened project
|
||||||
|
std::auto_ptr<VFS::Manager> mVFS;
|
||||||
|
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
CSMSettings::UserSettings mUserSettings;
|
CSMSettings::UserSettings mUserSettings;
|
||||||
CSMDoc::DocumentManager mDocumentManager;
|
CSMDoc::DocumentManager mDocumentManager;
|
||||||
|
|
|
@ -90,11 +90,6 @@ void CSMDoc::DocumentManager::setBlacklistedScripts (const std::vector<std::stri
|
||||||
mBlacklistedScripts = scriptIds;
|
mBlacklistedScripts = scriptIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::DocumentManager::listResources()
|
|
||||||
{
|
|
||||||
mResourcesManager.listResources();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSMDoc::DocumentManager::documentLoaded (Document *document)
|
void CSMDoc::DocumentManager::documentLoaded (Document *document)
|
||||||
{
|
{
|
||||||
emit documentAdded (document);
|
emit documentAdded (document);
|
||||||
|
@ -108,3 +103,8 @@ void CSMDoc::DocumentManager::documentNotLoaded (Document *document, const std::
|
||||||
if (error.empty()) // do not remove the document yet, if we have an error
|
if (error.empty()) // do not remove the document yet, if we have an error
|
||||||
removeDocument (document);
|
removeDocument (document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMDoc::DocumentManager::setVFS(const VFS::Manager *vfs)
|
||||||
|
{
|
||||||
|
mResourcesManager.setVFS(vfs);
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,11 @@
|
||||||
|
|
||||||
#include "loader.hpp"
|
#include "loader.hpp"
|
||||||
|
|
||||||
|
namespace VFS
|
||||||
|
{
|
||||||
|
class Manager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Files
|
namespace Files
|
||||||
{
|
{
|
||||||
class ConfigurationManager;
|
class ConfigurationManager;
|
||||||
|
@ -35,6 +40,7 @@ namespace CSMDoc
|
||||||
ToUTF8::FromType mEncoding;
|
ToUTF8::FromType mEncoding;
|
||||||
CSMWorld::ResourcesManager mResourcesManager;
|
CSMWorld::ResourcesManager mResourcesManager;
|
||||||
std::vector<std::string> mBlacklistedScripts;
|
std::vector<std::string> mBlacklistedScripts;
|
||||||
|
VFS::Manager* mVFS;
|
||||||
|
|
||||||
DocumentManager (const DocumentManager&);
|
DocumentManager (const DocumentManager&);
|
||||||
DocumentManager& operator= (const DocumentManager&);
|
DocumentManager& operator= (const DocumentManager&);
|
||||||
|
@ -56,8 +62,7 @@ namespace CSMDoc
|
||||||
|
|
||||||
void setBlacklistedScripts (const std::vector<std::string>& scriptIds);
|
void setBlacklistedScripts (const std::vector<std::string>& scriptIds);
|
||||||
|
|
||||||
/// Ask OGRE for a list of available resources.
|
void setVFS(const VFS::Manager* vfs);
|
||||||
void listResources();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -7,43 +7,33 @@
|
||||||
|
|
||||||
#include <OgreResourceGroupManager.h>
|
#include <OgreResourceGroupManager.h>
|
||||||
|
|
||||||
|
#include <components/vfs/manager.hpp>
|
||||||
|
|
||||||
#include <components/misc/stringops.hpp>
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
CSMWorld::Resources::Resources (const std::string& baseDirectory, UniversalId::Type type,
|
CSMWorld::Resources::Resources (const VFS::Manager* vfs, const std::string& baseDirectory, UniversalId::Type type,
|
||||||
const char * const *extensions)
|
const char * const *extensions)
|
||||||
: mBaseDirectory (baseDirectory), mType (type)
|
: mBaseDirectory (baseDirectory), mType (type)
|
||||||
{
|
{
|
||||||
int baseSize = mBaseDirectory.size();
|
int baseSize = mBaseDirectory.size();
|
||||||
|
|
||||||
/*
|
const std::map<std::string, VFS::File*>& index = vfs->getIndex();
|
||||||
Ogre::StringVector resourcesGroups =
|
for (std::map<std::string, VFS::File*>::const_iterator it = index.begin(); it != index.end(); ++it)
|
||||||
Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
|
|
||||||
|
|
||||||
for (Ogre::StringVector::iterator iter (resourcesGroups.begin());
|
|
||||||
iter!=resourcesGroups.end(); ++iter)
|
|
||||||
{
|
{
|
||||||
if (*iter=="General" || *iter=="Internal" || *iter=="Autodetect")
|
std::string filepath = it->first;
|
||||||
continue;
|
if (static_cast<int> (filepath.size())<baseSize+1 ||
|
||||||
|
filepath.substr (0, baseSize)!=mBaseDirectory ||
|
||||||
Ogre::StringVectorPtr resources =
|
(filepath[baseSize]!='/' && filepath[baseSize]!='\\'))
|
||||||
Ogre::ResourceGroupManager::getSingleton().listResourceNames (*iter);
|
|
||||||
|
|
||||||
for (Ogre::StringVector::const_iterator iter (resources->begin());
|
|
||||||
iter!=resources->end(); ++iter)
|
|
||||||
{
|
|
||||||
if (static_cast<int> (iter->size())<baseSize+1 ||
|
|
||||||
iter->substr (0, baseSize)!=mBaseDirectory ||
|
|
||||||
((*iter)[baseSize]!='/' && (*iter)[baseSize]!='\\'))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (extensions)
|
if (extensions)
|
||||||
{
|
{
|
||||||
std::string::size_type index = iter->find_last_of ('.');
|
std::string::size_type index = filepath.find_last_of ('.');
|
||||||
|
|
||||||
if (index==std::string::npos)
|
if (index==std::string::npos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::string extension = iter->substr (index+1);
|
std::string extension = filepath.substr (index+1);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
@ -55,14 +45,12 @@ CSMWorld::Resources::Resources (const std::string& baseDirectory, UniversalId::T
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string file = iter->substr (baseSize+1);
|
std::string file = filepath.substr (baseSize+1);
|
||||||
mFiles.push_back (file);
|
mFiles.push_back (file);
|
||||||
std::replace (file.begin(), file.end(), '\\', '/');
|
std::replace (file.begin(), file.end(), '\\', '/');
|
||||||
mIndex.insert (std::make_pair (
|
mIndex.insert (std::make_pair (
|
||||||
Misc::StringUtils::lowerCase (file), static_cast<int> (mFiles.size())-1));
|
Misc::StringUtils::lowerCase (file), static_cast<int> (mFiles.size())-1));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSMWorld::Resources::getSize() const
|
int CSMWorld::Resources::getSize() const
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
|
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
|
|
||||||
|
namespace VFS
|
||||||
|
{
|
||||||
|
class Manager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class Resources
|
class Resources
|
||||||
|
@ -19,7 +24,7 @@ namespace CSMWorld
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// \param type Type of resources in this table.
|
/// \param type Type of resources in this table.
|
||||||
Resources (const std::string& baseDirectory, UniversalId::Type type,
|
Resources (const VFS::Manager* vfs, const std::string& baseDirectory, UniversalId::Type type,
|
||||||
const char * const *extensions = 0);
|
const char * const *extensions = 0);
|
||||||
|
|
||||||
int getSize() const;
|
int getSize() const;
|
||||||
|
|
|
@ -10,16 +10,18 @@ void CSMWorld::ResourcesManager::addResources (const Resources& resources)
|
||||||
resources));
|
resources));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMWorld::ResourcesManager::listResources()
|
void CSMWorld::ResourcesManager::setVFS(const VFS::Manager *vfs)
|
||||||
{
|
{
|
||||||
|
mResources.clear();
|
||||||
|
|
||||||
static const char * const sMeshTypes[] = { "nif", 0 };
|
static const char * const sMeshTypes[] = { "nif", 0 };
|
||||||
|
|
||||||
addResources (Resources ("meshes", UniversalId::Type_Mesh, sMeshTypes));
|
addResources (Resources (vfs, "meshes", UniversalId::Type_Mesh, sMeshTypes));
|
||||||
addResources (Resources ("icons", UniversalId::Type_Icon));
|
addResources (Resources (vfs, "icons", UniversalId::Type_Icon));
|
||||||
addResources (Resources ("music", UniversalId::Type_Music));
|
addResources (Resources (vfs, "music", UniversalId::Type_Music));
|
||||||
addResources (Resources ("sound", UniversalId::Type_SoundRes));
|
addResources (Resources (vfs, "sound", UniversalId::Type_SoundRes));
|
||||||
addResources (Resources ("textures", UniversalId::Type_Texture));
|
addResources (Resources (vfs, "textures", UniversalId::Type_Texture));
|
||||||
addResources (Resources ("videos", UniversalId::Type_Video));
|
addResources (Resources (vfs, "videos", UniversalId::Type_Video));
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const
|
const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
#include "universalid.hpp"
|
#include "universalid.hpp"
|
||||||
#include "resources.hpp"
|
#include "resources.hpp"
|
||||||
|
|
||||||
|
namespace VFS
|
||||||
|
{
|
||||||
|
class Manager;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSMWorld
|
namespace CSMWorld
|
||||||
{
|
{
|
||||||
class ResourcesManager
|
class ResourcesManager
|
||||||
|
@ -18,8 +23,7 @@ namespace CSMWorld
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Ask OGRE for a list of available resources.
|
void setVFS(const VFS::Manager* vfs);
|
||||||
void listResources();
|
|
||||||
|
|
||||||
const Resources& get (UniversalId::Type type) const;
|
const Resources& get (UniversalId::Type type) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,7 +35,7 @@ add_component_dir (bsa
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (vfs
|
add_component_dir (vfs
|
||||||
manager archive bsaarchive filesystemarchive
|
manager archive bsaarchive filesystemarchive registerarchives
|
||||||
)
|
)
|
||||||
|
|
||||||
add_component_dir (nif
|
add_component_dir (nif
|
||||||
|
|
|
@ -73,4 +73,9 @@ namespace VFS
|
||||||
return mIndex.find(normalized) != mIndex.end();
|
return mIndex.find(normalized) != mIndex.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::map<std::string, File*>& Manager::getIndex() const
|
||||||
|
{
|
||||||
|
return mIndex;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,9 @@ namespace VFS
|
||||||
/// Does a file with this name exist?
|
/// Does a file with this name exist?
|
||||||
bool exists(const std::string& name) const;
|
bool exists(const std::string& name) const;
|
||||||
|
|
||||||
|
/// Get a complete list of files from all archives
|
||||||
|
const std::map<std::string, File*>& getIndex() const;
|
||||||
|
|
||||||
/// Retrieve a file by name.
|
/// Retrieve a file by name.
|
||||||
/// @note Throws an exception if the file can not be found.
|
/// @note Throws an exception if the file can not be found.
|
||||||
Files::IStreamPtr get(const std::string& name) const;
|
Files::IStreamPtr get(const std::string& name) const;
|
||||||
|
|
42
components/vfs/registerarchives.cpp
Normal file
42
components/vfs/registerarchives.cpp
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#include "registerarchives.hpp"
|
||||||
|
|
||||||
|
#include <components/vfs/manager.hpp>
|
||||||
|
#include <components/vfs/bsaarchive.hpp>
|
||||||
|
#include <components/vfs/filesystemarchive.hpp>
|
||||||
|
|
||||||
|
namespace VFS
|
||||||
|
{
|
||||||
|
|
||||||
|
void registerArchives(VFS::Manager *vfs, const Files::Collections &collections, const std::vector<std::string> &archives, bool useLooseFiles)
|
||||||
|
{
|
||||||
|
const Files::PathContainer& dataDirs = collections.getPaths();
|
||||||
|
|
||||||
|
if (useLooseFiles)
|
||||||
|
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
|
||||||
|
{
|
||||||
|
// Last data dir has the highest priority
|
||||||
|
vfs->addArchive(new FileSystemArchive(iter->string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::vector<std::string>::const_iterator archive = archives.begin(); archive != archives.end(); ++archive)
|
||||||
|
{
|
||||||
|
if (collections.doesExist(*archive))
|
||||||
|
{
|
||||||
|
// Last BSA has the highest priority
|
||||||
|
const std::string archivePath = collections.getPath(*archive).string();
|
||||||
|
std::cout << "Adding BSA archive " << archivePath << std::endl;
|
||||||
|
|
||||||
|
vfs->addArchive(new BsaArchive(archivePath));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::stringstream message;
|
||||||
|
message << "Archive '" << *archive << "' not found";
|
||||||
|
throw std::runtime_error(message.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vfs->buildIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
15
components/vfs/registerarchives.hpp
Normal file
15
components/vfs/registerarchives.hpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef OPENMW_COMPONENTS_VFS_REGISTER_ARCHIVES_H
|
||||||
|
#define OPENMW_COMPONENTS_VFS_REGISTER_ARCHIVES_H
|
||||||
|
|
||||||
|
#include <components/files/collections.hpp>
|
||||||
|
|
||||||
|
namespace VFS
|
||||||
|
{
|
||||||
|
class Manager;
|
||||||
|
|
||||||
|
/// @brief Register BSA and file system archives based on the given OpenMW configuration.
|
||||||
|
void registerArchives (VFS::Manager* vfs, const Files::Collections& collections,
|
||||||
|
const std::vector<std::string>& archives, bool useLooseFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue