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 <openengine/bullet/BulletShapeLoader.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <OgreRoot.h>
|
||||
#include <OgreRenderWindow.h>
|
||||
|
||||
#include <extern/shiny/Main/Factory.hpp>
|
||||
#include <extern/shiny/Platforms/Ogre/OgrePlatform.hpp>
|
||||
|
||||
#include <components/ogreinit/ogreinit.hpp>
|
||||
#include <components/nifogre/ogrenifloader.hpp>
|
||||
#include <components/vfs/manager.hpp>
|
||||
#include <components/vfs/registerarchives.hpp>
|
||||
|
||||
#include "model/doc/document.hpp"
|
||||
#include "model/world/data.hpp"
|
||||
|
@ -34,10 +26,11 @@ CS::Editor::Editor ()
|
|||
|
||||
//NifOgre::Loader::setShowMarkers(true);
|
||||
|
||||
//Bsa::registerResources (Files::Collections (config.first, !mFsStrict), config.second, true,
|
||||
// mFsStrict);
|
||||
mVFS.reset(new VFS::Manager(mFsStrict));
|
||||
|
||||
mDocumentManager.listResources();
|
||||
VFS::registerArchives(mVFS.get(), Files::Collections(config.first, !mFsStrict), config.second, true);
|
||||
|
||||
mDocumentManager.setVFS(mVFS.get());
|
||||
|
||||
mNewGame.setLocalData (mLocal);
|
||||
mFileDialog.setLocalData (mLocal);
|
||||
|
@ -74,9 +67,6 @@ CS::Editor::~Editor ()
|
|||
if(mServer && boost::filesystem::exists(mPid))
|
||||
static_cast<void> ( // silence coverity warning
|
||||
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)
|
||||
|
|
|
@ -27,12 +27,20 @@
|
|||
|
||||
#include "view/settings/dialog.hpp"
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
class Manager;
|
||||
}
|
||||
|
||||
namespace CS
|
||||
{
|
||||
class Editor : public QObject
|
||||
{
|
||||
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;
|
||||
CSMSettings::UserSettings mUserSettings;
|
||||
CSMDoc::DocumentManager mDocumentManager;
|
||||
|
|
|
@ -90,11 +90,6 @@ void CSMDoc::DocumentManager::setBlacklistedScripts (const std::vector<std::stri
|
|||
mBlacklistedScripts = scriptIds;
|
||||
}
|
||||
|
||||
void CSMDoc::DocumentManager::listResources()
|
||||
{
|
||||
mResourcesManager.listResources();
|
||||
}
|
||||
|
||||
void CSMDoc::DocumentManager::documentLoaded (Document *document)
|
||||
{
|
||||
emit documentAdded (document);
|
||||
|
@ -107,4 +102,9 @@ void CSMDoc::DocumentManager::documentNotLoaded (Document *document, const std::
|
|||
|
||||
if (error.empty()) // do not remove the document yet, if we have an error
|
||||
removeDocument (document);
|
||||
}
|
||||
}
|
||||
|
||||
void CSMDoc::DocumentManager::setVFS(const VFS::Manager *vfs)
|
||||
{
|
||||
mResourcesManager.setVFS(vfs);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
|
||||
#include "loader.hpp"
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
class Manager;
|
||||
}
|
||||
|
||||
namespace Files
|
||||
{
|
||||
class ConfigurationManager;
|
||||
|
@ -35,6 +40,7 @@ namespace CSMDoc
|
|||
ToUTF8::FromType mEncoding;
|
||||
CSMWorld::ResourcesManager mResourcesManager;
|
||||
std::vector<std::string> mBlacklistedScripts;
|
||||
VFS::Manager* mVFS;
|
||||
|
||||
DocumentManager (const DocumentManager&);
|
||||
DocumentManager& operator= (const DocumentManager&);
|
||||
|
@ -56,8 +62,7 @@ namespace CSMDoc
|
|||
|
||||
void setBlacklistedScripts (const std::vector<std::string>& scriptIds);
|
||||
|
||||
/// Ask OGRE for a list of available resources.
|
||||
void listResources();
|
||||
void setVFS(const VFS::Manager* vfs);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -99,4 +104,4 @@ namespace CSMDoc
|
|||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -7,62 +7,50 @@
|
|||
|
||||
#include <OgreResourceGroupManager.h>
|
||||
|
||||
#include <components/vfs/manager.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)
|
||||
: mBaseDirectory (baseDirectory), mType (type)
|
||||
{
|
||||
int baseSize = mBaseDirectory.size();
|
||||
|
||||
/*
|
||||
Ogre::StringVector resourcesGroups =
|
||||
Ogre::ResourceGroupManager::getSingleton().getResourceGroups();
|
||||
|
||||
for (Ogre::StringVector::iterator iter (resourcesGroups.begin());
|
||||
iter!=resourcesGroups.end(); ++iter)
|
||||
const std::map<std::string, VFS::File*>& index = vfs->getIndex();
|
||||
for (std::map<std::string, VFS::File*>::const_iterator it = index.begin(); it != index.end(); ++it)
|
||||
{
|
||||
if (*iter=="General" || *iter=="Internal" || *iter=="Autodetect")
|
||||
std::string filepath = it->first;
|
||||
if (static_cast<int> (filepath.size())<baseSize+1 ||
|
||||
filepath.substr (0, baseSize)!=mBaseDirectory ||
|
||||
(filepath[baseSize]!='/' && filepath[baseSize]!='\\'))
|
||||
continue;
|
||||
|
||||
Ogre::StringVectorPtr resources =
|
||||
Ogre::ResourceGroupManager::getSingleton().listResourceNames (*iter);
|
||||
|
||||
for (Ogre::StringVector::const_iterator iter (resources->begin());
|
||||
iter!=resources->end(); ++iter)
|
||||
if (extensions)
|
||||
{
|
||||
if (static_cast<int> (iter->size())<baseSize+1 ||
|
||||
iter->substr (0, baseSize)!=mBaseDirectory ||
|
||||
((*iter)[baseSize]!='/' && (*iter)[baseSize]!='\\'))
|
||||
std::string::size_type index = filepath.find_last_of ('.');
|
||||
|
||||
if (index==std::string::npos)
|
||||
continue;
|
||||
|
||||
if (extensions)
|
||||
{
|
||||
std::string::size_type index = iter->find_last_of ('.');
|
||||
std::string extension = filepath.substr (index+1);
|
||||
|
||||
if (index==std::string::npos)
|
||||
continue;
|
||||
int i = 0;
|
||||
|
||||
std::string extension = iter->substr (index+1);
|
||||
for (; extensions[i]; ++i)
|
||||
if (extensions[i]==extension)
|
||||
break;
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (; extensions[i]; ++i)
|
||||
if (extensions[i]==extension)
|
||||
break;
|
||||
|
||||
if (!extensions[i])
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string file = iter->substr (baseSize+1);
|
||||
mFiles.push_back (file);
|
||||
std::replace (file.begin(), file.end(), '\\', '/');
|
||||
mIndex.insert (std::make_pair (
|
||||
Misc::StringUtils::lowerCase (file), static_cast<int> (mFiles.size())-1));
|
||||
if (!extensions[i])
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string file = filepath.substr (baseSize+1);
|
||||
mFiles.push_back (file);
|
||||
std::replace (file.begin(), file.end(), '\\', '/');
|
||||
mIndex.insert (std::make_pair (
|
||||
Misc::StringUtils::lowerCase (file), static_cast<int> (mFiles.size())-1));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
int CSMWorld::Resources::getSize() const
|
||||
|
|
|
@ -7,6 +7,11 @@
|
|||
|
||||
#include "universalid.hpp"
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
class Manager;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Resources
|
||||
|
@ -19,7 +24,7 @@ namespace CSMWorld
|
|||
public:
|
||||
|
||||
/// \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);
|
||||
|
||||
int getSize() const;
|
||||
|
|
|
@ -10,16 +10,18 @@ void CSMWorld::ResourcesManager::addResources (const Resources& resources)
|
|||
resources));
|
||||
}
|
||||
|
||||
void CSMWorld::ResourcesManager::listResources()
|
||||
void CSMWorld::ResourcesManager::setVFS(const VFS::Manager *vfs)
|
||||
{
|
||||
mResources.clear();
|
||||
|
||||
static const char * const sMeshTypes[] = { "nif", 0 };
|
||||
|
||||
addResources (Resources ("meshes", UniversalId::Type_Mesh, sMeshTypes));
|
||||
addResources (Resources ("icons", UniversalId::Type_Icon));
|
||||
addResources (Resources ("music", UniversalId::Type_Music));
|
||||
addResources (Resources ("sound", UniversalId::Type_SoundRes));
|
||||
addResources (Resources ("textures", UniversalId::Type_Texture));
|
||||
addResources (Resources ("videos", UniversalId::Type_Video));
|
||||
addResources (Resources (vfs, "meshes", UniversalId::Type_Mesh, sMeshTypes));
|
||||
addResources (Resources (vfs, "icons", UniversalId::Type_Icon));
|
||||
addResources (Resources (vfs, "music", UniversalId::Type_Music));
|
||||
addResources (Resources (vfs, "sound", UniversalId::Type_SoundRes));
|
||||
addResources (Resources (vfs, "textures", UniversalId::Type_Texture));
|
||||
addResources (Resources (vfs, "videos", UniversalId::Type_Video));
|
||||
}
|
||||
|
||||
const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type type) const
|
||||
|
@ -30,4 +32,4 @@ const CSMWorld::Resources& CSMWorld::ResourcesManager::get (UniversalId::Type ty
|
|||
throw std::logic_error ("Unknown resource type");
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
#include "universalid.hpp"
|
||||
#include "resources.hpp"
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
class Manager;
|
||||
}
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class ResourcesManager
|
||||
|
@ -18,11 +23,10 @@ namespace CSMWorld
|
|||
|
||||
public:
|
||||
|
||||
/// Ask OGRE for a list of available resources.
|
||||
void listResources();
|
||||
void setVFS(const VFS::Manager* vfs);
|
||||
|
||||
const Resources& get (UniversalId::Type type) const;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -35,7 +35,7 @@ add_component_dir (bsa
|
|||
)
|
||||
|
||||
add_component_dir (vfs
|
||||
manager archive bsaarchive filesystemarchive
|
||||
manager archive bsaarchive filesystemarchive registerarchives
|
||||
)
|
||||
|
||||
add_component_dir (nif
|
||||
|
|
|
@ -73,4 +73,9 @@ namespace VFS
|
|||
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?
|
||||
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.
|
||||
/// @note Throws an exception if the file can not be found.
|
||||
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