forked from teamnwah/openmw-tes3coop
VFS changes, one VFS and resource system per document.
Added ability to reset a VFS::Manager. Removed ability to rebuild the index for a VFS::Manager. Moved VFS creation to CSM::Data.
This commit is contained in:
parent
979b0d7211
commit
8c4b12a603
15 changed files with 61 additions and 88 deletions
|
@ -5,9 +5,6 @@
|
|||
#include <QLocalSocket>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <components/vfs/manager.hpp>
|
||||
#include <components/vfs/registerarchives.hpp>
|
||||
|
||||
#include <components/fallback/validate.hpp>
|
||||
|
||||
#include <components/nifosg/nifloader.hpp>
|
||||
|
@ -33,11 +30,7 @@ CS::Editor::Editor ()
|
|||
|
||||
NifOsg::Loader::setShowMarkers(true);
|
||||
|
||||
mVFS.reset(new VFS::Manager(mFsStrict));
|
||||
|
||||
VFS::registerArchives(mVFS.get(), Files::Collections(config.first, !mFsStrict), config.second, true);
|
||||
|
||||
mDocumentManager.setVFS(mVFS.get());
|
||||
mDocumentManager.setFileData(mFsStrict, config.first, config.second);
|
||||
|
||||
mNewGame.setLocalData (mLocal);
|
||||
mFileDialog.setLocalData (mLocal);
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
#ifndef CS_EDITOR_H
|
||||
#define CS_EDITOR_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <boost/interprocess/sync/file_lock.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
|
@ -30,11 +28,6 @@
|
|||
|
||||
#include "view/tools/merge.hpp"
|
||||
|
||||
namespace VFS
|
||||
{
|
||||
class Manager;
|
||||
}
|
||||
|
||||
namespace CSMDoc
|
||||
{
|
||||
class Document;
|
||||
|
@ -46,9 +39,6 @@ namespace CS
|
|||
{
|
||||
Q_OBJECT
|
||||
|
||||
// FIXME: should be moved to document, so we can have different resources for each opened project
|
||||
std::unique_ptr<VFS::Manager> mVFS;
|
||||
|
||||
Files::ConfigurationManager mCfgMgr;
|
||||
CSMPrefs::State mSettingsState;
|
||||
CSMDoc::DocumentManager mDocumentManager;
|
||||
|
|
|
@ -269,13 +269,14 @@ void CSMDoc::Document::createBase()
|
|||
}
|
||||
}
|
||||
|
||||
CSMDoc::Document::Document (VFS::Manager* vfs, const Files::ConfigurationManager& configuration,
|
||||
const std::vector< boost::filesystem::path >& files, bool new_,
|
||||
CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
|
||||
const std::vector< boost::filesystem::path >& files,bool new_,
|
||||
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
|
||||
const Fallback::Map* fallback,
|
||||
ToUTF8::FromType encoding, CSMWorld::ResourcesManager& resourcesManager,
|
||||
const std::vector<std::string>& blacklistedScripts)
|
||||
: mVFS(vfs), mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, vfs, resourcesManager, fallback, resDir),
|
||||
ToUTF8::FromType encoding,
|
||||
const std::vector<std::string>& blacklistedScripts,
|
||||
bool fsStrict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives)
|
||||
: mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, fsStrict, dataPaths, archives, fallback, resDir),
|
||||
mTools (*this, encoding),
|
||||
mProjectPath ((configuration.getUserDataPath() / "projects") /
|
||||
(savePath.filename().string() + ".project")),
|
||||
|
@ -337,11 +338,6 @@ CSMDoc::Document::~Document()
|
|||
{
|
||||
}
|
||||
|
||||
const VFS::Manager *CSMDoc::Document::getVFS() const
|
||||
{
|
||||
return mVFS;
|
||||
}
|
||||
|
||||
QUndoStack& CSMDoc::Document::getUndoStack()
|
||||
{
|
||||
return mUndoStack;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include <components/files/multidircollection.hpp>
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
#include "../world/data.hpp"
|
||||
|
@ -59,7 +60,6 @@ namespace CSMDoc
|
|||
|
||||
private:
|
||||
|
||||
VFS::Manager* mVFS;
|
||||
boost::filesystem::path mSavePath;
|
||||
std::vector<boost::filesystem::path> mContentFiles;
|
||||
bool mNew;
|
||||
|
@ -102,17 +102,15 @@ namespace CSMDoc
|
|||
|
||||
public:
|
||||
|
||||
Document (VFS::Manager* vfs, const Files::ConfigurationManager& configuration,
|
||||
Document (const Files::ConfigurationManager& configuration,
|
||||
const std::vector< boost::filesystem::path >& files, bool new_,
|
||||
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
|
||||
const Fallback::Map* fallback,
|
||||
ToUTF8::FromType encoding, CSMWorld::ResourcesManager& resourcesManager,
|
||||
const std::vector<std::string>& blacklistedScripts);
|
||||
const Fallback::Map* fallback, ToUTF8::FromType encoding,
|
||||
const std::vector<std::string>& blacklistedScripts,
|
||||
bool fsStrict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives);
|
||||
|
||||
~Document();
|
||||
|
||||
const VFS::Manager* getVFS() const;
|
||||
|
||||
QUndoStack& getUndoStack();
|
||||
|
||||
int getState() const;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "document.hpp"
|
||||
|
||||
CSMDoc::DocumentManager::DocumentManager (const Files::ConfigurationManager& configuration)
|
||||
: mConfiguration (configuration), mEncoding (ToUTF8::WINDOWS_1252), mVFS(NULL)
|
||||
: mConfiguration (configuration), mEncoding (ToUTF8::WINDOWS_1252)
|
||||
{
|
||||
boost::filesystem::path projectPath = configuration.getUserDataPath() / "projects";
|
||||
|
||||
|
@ -62,7 +62,7 @@ CSMDoc::Document *CSMDoc::DocumentManager::makeDocument (
|
|||
const std::vector< boost::filesystem::path >& files,
|
||||
const boost::filesystem::path& savePath, bool new_)
|
||||
{
|
||||
return new Document (mVFS, mConfiguration, files, new_, savePath, mResDir, &mFallbackMap, mEncoding, mResourcesManager, mBlacklistedScripts);
|
||||
return new Document (mConfiguration, files, new_, savePath, mResDir, &mFallbackMap, mEncoding, mBlacklistedScripts, mFsStrict, mDataPaths, mArchives);
|
||||
}
|
||||
|
||||
void CSMDoc::DocumentManager::insertDocument (CSMDoc::Document *document)
|
||||
|
@ -127,8 +127,9 @@ void CSMDoc::DocumentManager::documentNotLoaded (Document *document, const std::
|
|||
removeDocument (document);
|
||||
}
|
||||
|
||||
void CSMDoc::DocumentManager::setVFS(VFS::Manager *vfs)
|
||||
void CSMDoc::DocumentManager::setFileData(bool strict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives)
|
||||
{
|
||||
mResourcesManager.setVFS(vfs);
|
||||
mVFS = vfs;
|
||||
mFsStrict = strict;
|
||||
mDataPaths = dataPaths;
|
||||
mArchives = archives;
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
#include <components/fallback/fallback.hpp>
|
||||
|
||||
#include "../world/resourcesmanager.hpp"
|
||||
#include <components/files/multidircollection.hpp>
|
||||
|
||||
#include "loader.hpp"
|
||||
|
||||
|
@ -39,9 +38,14 @@ namespace CSMDoc
|
|||
QThread mLoaderThread;
|
||||
Loader mLoader;
|
||||
ToUTF8::FromType mEncoding;
|
||||
CSMWorld::ResourcesManager mResourcesManager;
|
||||
std::vector<std::string> mBlacklistedScripts;
|
||||
VFS::Manager* mVFS;
|
||||
|
||||
boost::filesystem::path mResDir;
|
||||
Fallback::Map mFallbackMap;
|
||||
|
||||
bool mFsStrict;
|
||||
Files::PathContainer mDataPaths;
|
||||
std::vector<std::string> mArchives;
|
||||
|
||||
DocumentManager (const DocumentManager&);
|
||||
DocumentManager& operator= (const DocumentManager&);
|
||||
|
@ -74,15 +78,11 @@ namespace CSMDoc
|
|||
|
||||
void setBlacklistedScripts (const std::vector<std::string>& scriptIds);
|
||||
|
||||
void setVFS(VFS::Manager* vfs);
|
||||
/// Sets the file data that gets passed to newly created documents.
|
||||
void setFileData(bool strict, const Files::PathContainer& dataPaths, const std::vector<std::string>& archives);
|
||||
|
||||
bool isEmpty();
|
||||
|
||||
private:
|
||||
|
||||
boost::filesystem::path mResDir;
|
||||
Fallback::Map mFallbackMap;
|
||||
|
||||
private slots:
|
||||
|
||||
void documentLoaded (Document *document);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
#include <components/resource/scenemanager.hpp>
|
||||
#include <components/vfs/manager.hpp>
|
||||
#include <components/vfs/registerarchives.hpp>
|
||||
|
||||
#include "idtable.hpp"
|
||||
#include "idtree.hpp"
|
||||
|
@ -62,11 +63,18 @@ int CSMWorld::Data::count (RecordBase::State state, const CollectionBase& collec
|
|||
return number;
|
||||
}
|
||||
|
||||
CSMWorld::Data::Data (ToUTF8::FromType encoding, VFS::Manager* vfs, ResourcesManager& resourcesManager, const Fallback::Map* fallback, const boost::filesystem::path& resDir)
|
||||
CSMWorld::Data::Data (ToUTF8::FromType encoding, bool fsStrict, const Files::PathContainer& dataPaths,
|
||||
const std::vector<std::string>& archives, const Fallback::Map* fallback, const boost::filesystem::path& resDir)
|
||||
: mEncoder (encoding), mPathgrids (mCells), mRefs (mCells),
|
||||
mVFS(vfs), mResourcesManager (resourcesManager), mFallbackMap(fallback),
|
||||
mReader (0), mDialogue (0), mReaderIndex(1), mResourceSystem(new Resource::ResourceSystem(resourcesManager.getVFS()))
|
||||
mFallbackMap(fallback), mReader (0), mDialogue (0), mReaderIndex(1),
|
||||
mFsStrict(fsStrict), mDataPaths(dataPaths), mArchives(archives)
|
||||
{
|
||||
mVFS.reset(new VFS::Manager(mFsStrict));
|
||||
VFS::registerArchives(mVFS.get(), Files::Collections(mDataPaths, !mFsStrict), mArchives, true);
|
||||
|
||||
mResourcesManager.setVFS(mVFS.get());
|
||||
mResourceSystem.reset(new Resource::ResourceSystem(mVFS.get()));
|
||||
|
||||
mResourceSystem->getSceneManager()->setShaderPath((resDir / "shaders").string());
|
||||
|
||||
int index = 0;
|
||||
|
@ -1218,7 +1226,8 @@ std::vector<std::string> CSMWorld::Data::getIds (bool listDeleted) const
|
|||
|
||||
void CSMWorld::Data::assetsChanged()
|
||||
{
|
||||
mVFS->rebuildIndex();
|
||||
mVFS.get()->reset();
|
||||
VFS::registerArchives(mVFS.get(), Files::Collections(mDataPaths, !mFsStrict), mArchives, true);
|
||||
|
||||
const UniversalId assetTableIds[] = {
|
||||
UniversalId::Type_Meshes,
|
||||
|
@ -1265,7 +1274,7 @@ void CSMWorld::Data::rowsChanged (const QModelIndex& parent, int start, int end)
|
|||
|
||||
const VFS::Manager* CSMWorld::Data::getVFS() const
|
||||
{
|
||||
return mVFS;
|
||||
return mVFS.get();
|
||||
}
|
||||
|
||||
const Fallback::Map* CSMWorld::Data::getFallbackMap() const
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include <components/resource/resourcesystem.hpp>
|
||||
|
||||
#include <components/files/multidircollection.hpp>
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
#include "../doc/stage.hpp"
|
||||
|
@ -46,6 +47,7 @@
|
|||
#include "infocollection.hpp"
|
||||
#include "nestedinfocollection.hpp"
|
||||
#include "pathgrid.hpp"
|
||||
#include "resourcesmanager.hpp"
|
||||
#include "metadata.hpp"
|
||||
#ifndef Q_MOC_RUN
|
||||
#include "subcellcollection.hpp"
|
||||
|
@ -108,8 +110,6 @@ namespace CSMWorld
|
|||
RefCollection mRefs;
|
||||
IdCollection<ESM::Filter> mFilters;
|
||||
Collection<MetaData> mMetaData;
|
||||
VFS::Manager* mVFS;
|
||||
ResourcesManager& mResourcesManager;
|
||||
const Fallback::Map* mFallbackMap;
|
||||
std::vector<QAbstractItemModel *> mModels;
|
||||
std::map<UniversalId::Type, QAbstractItemModel *> mModelIndex;
|
||||
|
@ -120,6 +120,11 @@ namespace CSMWorld
|
|||
std::map<std::string, std::map<ESM::RefNum, std::string> > mRefLoadCache;
|
||||
int mReaderIndex;
|
||||
|
||||
bool mFsStrict;
|
||||
Files::PathContainer mDataPaths;
|
||||
std::vector<std::string> mArchives;
|
||||
std::unique_ptr<VFS::Manager> mVFS;
|
||||
ResourcesManager mResourcesManager;
|
||||
std::shared_ptr<Resource::ResourceSystem> mResourceSystem;
|
||||
|
||||
std::vector<std::shared_ptr<ESM::ESMReader> > mReaders;
|
||||
|
@ -141,7 +146,9 @@ namespace CSMWorld
|
|||
|
||||
public:
|
||||
|
||||
Data (ToUTF8::FromType encoding, VFS::Manager* vfs, ResourcesManager& resourcesManager, const Fallback::Map* fallback, const boost::filesystem::path& resDir);
|
||||
Data (ToUTF8::FromType encoding, bool fsStrict, const Files::PathContainer& dataPaths,
|
||||
const std::vector<std::string>& archives, const Fallback::Map* fallback,
|
||||
const boost::filesystem::path& resDir);
|
||||
|
||||
virtual ~Data();
|
||||
|
||||
|
|
|
@ -21,9 +21,6 @@ namespace VFS
|
|||
public:
|
||||
virtual ~Archive() {}
|
||||
|
||||
/// Clears cached data.
|
||||
virtual void reset() = 0;
|
||||
|
||||
/// List all resources contained in this archive, and run the resource names through the given normalize function.
|
||||
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char)) = 0;
|
||||
};
|
||||
|
|
|
@ -10,12 +10,6 @@ BsaArchive::BsaArchive(const std::string &filename)
|
|||
load();
|
||||
}
|
||||
|
||||
void BsaArchive::reset()
|
||||
{
|
||||
mResources.clear();
|
||||
load();
|
||||
}
|
||||
|
||||
void BsaArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char))
|
||||
{
|
||||
for (std::vector<BsaArchiveFile>::iterator it = mResources.begin(); it != mResources.end(); ++it)
|
||||
|
|
|
@ -24,8 +24,6 @@ namespace VFS
|
|||
public:
|
||||
BsaArchive(const std::string& filename);
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char));
|
||||
|
||||
private:
|
||||
|
|
|
@ -12,12 +12,6 @@ namespace VFS
|
|||
|
||||
}
|
||||
|
||||
void FileSystemArchive::reset()
|
||||
{
|
||||
mIndex.clear();
|
||||
mBuiltIndex = false;
|
||||
}
|
||||
|
||||
void FileSystemArchive::listResources(std::map<std::string, File *> &out, char (*normalize_function)(char))
|
||||
{
|
||||
if (!mBuiltIndex)
|
||||
|
|
|
@ -23,8 +23,6 @@ namespace VFS
|
|||
public:
|
||||
FileSystemArchive(const std::string& path);
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual void listResources(std::map<std::string, File*>& out, char (*normalize_function) (char));
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,12 @@ namespace VFS
|
|||
|
||||
Manager::~Manager()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void Manager::reset()
|
||||
{
|
||||
mIndex.clear();
|
||||
for (std::vector<Archive*>::iterator it = mArchives.begin(); it != mArchives.end(); ++it)
|
||||
delete *it;
|
||||
mArchives.clear();
|
||||
|
@ -57,14 +63,6 @@ namespace VFS
|
|||
(*it)->listResources(mIndex, mStrict ? &strict_normalize_char : &nonstrict_normalize_char);
|
||||
}
|
||||
|
||||
void Manager::rebuildIndex()
|
||||
{
|
||||
for (std::vector<Archive*>::const_iterator it = mArchives.begin(); it != mArchives.end(); ++it)
|
||||
(*it)->reset();
|
||||
|
||||
buildIndex();
|
||||
}
|
||||
|
||||
Files::IStreamPtr Manager::get(const std::string &name) const
|
||||
{
|
||||
std::string normalized = name;
|
||||
|
|
|
@ -26,6 +26,9 @@ namespace VFS
|
|||
|
||||
~Manager();
|
||||
|
||||
// Empty the file index and unregister archives.
|
||||
void reset();
|
||||
|
||||
/// Register the given archive. All files contained in it will be added to the index on the next buildIndex() call.
|
||||
/// @note Takes ownership of the given pointer.
|
||||
void addArchive(Archive* archive);
|
||||
|
@ -33,9 +36,6 @@ namespace VFS
|
|||
/// Build the file index. Should be called when all archives have been registered.
|
||||
void buildIndex();
|
||||
|
||||
/// Rebuild the file index. New/deleted files (actual files, not bsa's) will be reflected.
|
||||
void rebuildIndex();
|
||||
|
||||
/// Does a file with this name exist?
|
||||
/// @note May be called from any thread once the index has been built.
|
||||
bool exists(const std::string& name) const;
|
||||
|
|
Loading…
Reference in a new issue