Load fallback archives listed in openmw.cfg at startup

actorid
Emanuel Guevel 12 years ago
parent 4b25ae30fd
commit 289bbc64f7

@ -149,16 +149,22 @@ OMW::Engine::~Engine()
delete mOgre; delete mOgre;
} }
// Load all BSA files in data directory. // Load BSA files
void OMW::Engine::loadBSA() void OMW::Engine::loadBSA()
{ {
const Files::MultiDirCollection& bsa = mFileCollections.getCollection (".bsa"); for (std::vector<std::string>::const_iterator archive = mArchives.begin(); archive != mArchives.end(); ++archive)
for (Files::MultiDirCollection::TIter iter(bsa.begin()); iter!=bsa.end(); ++iter)
{ {
std::cout << "Adding " << iter->second.string() << std::endl; if (mFileCollections.doesExist(*archive))
Bsa::addBSA(iter->second.string()); {
const std::string archivePath = mFileCollections.getPath(*archive).string();
std::cout << "Adding BSA archive " << archivePath << std::endl;
Bsa::addBSA(archivePath);
}
else
{
std::cout << "Archive " << *archive << " not found" << std::endl;
}
} }
const Files::PathContainer& dataDirs = mFileCollections.getPaths(); const Files::PathContainer& dataDirs = mFileCollections.getPaths();
@ -199,6 +205,11 @@ void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs)
mFileCollections = Files::Collections (dataDirs, !mFSStrict); mFileCollections = Files::Collections (dataDirs, !mFSStrict);
} }
// Add BSA archive
void OMW::Engine::addArchive (const std::string& archive) {
mArchives.push_back(archive);
}
// Set resource dir // Set resource dir
void OMW::Engine::setResourceDir (const boost::filesystem::path& parResDir) void OMW::Engine::setResourceDir (const boost::filesystem::path& parResDir)
{ {

@ -64,6 +64,7 @@ namespace OMW
ToUTF8::FromType mEncoding; ToUTF8::FromType mEncoding;
ToUTF8::Utf8Encoder* mEncoder; ToUTF8::Utf8Encoder* mEncoder;
Files::PathContainer mDataDirs; Files::PathContainer mDataDirs;
std::vector<std::string> mArchives;
boost::filesystem::path mResDir; boost::filesystem::path mResDir;
OEngine::Render::OgreRenderer *mOgre; OEngine::Render::OgreRenderer *mOgre;
std::string mCellName; std::string mCellName;
@ -99,7 +100,7 @@ namespace OMW
/// add a .zip resource /// add a .zip resource
void addZipResource (const boost::filesystem::path& path); void addZipResource (const boost::filesystem::path& path);
/// Load all BSA files in data directory. /// Load BSA files
void loadBSA(); void loadBSA();
void executeLocalScripts(); void executeLocalScripts();
@ -126,6 +127,9 @@ namespace OMW
/// Set data dirs /// Set data dirs
void setDataDirs(const Files::PathContainer& dataDirs); void setDataDirs(const Files::PathContainer& dataDirs);
/// Add BSA archive
void addArchive(const std::string& archive);
/// Set resource dir /// Set resource dir
void setResourceDir(const boost::filesystem::path& parResDir); void setResourceDir(const boost::filesystem::path& parResDir);

@ -100,6 +100,9 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
("data-local", bpo::value<std::string>()->default_value(""), ("data-local", bpo::value<std::string>()->default_value(""),
"set local data directory (highest priority)") "set local data directory (highest priority)")
("fallback-archive", bpo::value<StringsVector>()->default_value(StringsVector(), "fallback-archive")
->multitoken(), "set fallback BSA archives (later archives have higher priority)")
("resources", bpo::value<std::string>()->default_value("resources"), ("resources", bpo::value<std::string>()->default_value("resources"),
"set resources directory") "set resources directory")
@ -201,6 +204,13 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
engine.setDataDirs(dataDirs); engine.setDataDirs(dataDirs);
// fallback archives
StringsVector archives = variables["fallback-archive"].as<StringsVector>();
for (StringsVector::const_iterator it = archives.begin(); it != archives.end(); it++)
{
engine.addArchive(*it);
}
engine.setResourceDir(variables["resources"].as<std::string>()); engine.setResourceDir(variables["resources"].as<std::string>());
// master and plugin // master and plugin

@ -31,6 +31,32 @@ namespace Files
return iter->second; return iter->second;
} }
boost::filesystem::path Collections::getPath(const std::string& file) const
{
for (Files::PathContainer::const_iterator iter = mDirectories.begin();
iter != mDirectories.end(); ++iter)
{
const boost::filesystem::path path = *iter / file;
if (boost::filesystem::exists(path))
return path.string();
}
throw std::runtime_error ("file " + file + " not found");
}
bool Collections::doesExist(const std::string& file) const
{
for (Files::PathContainer::const_iterator iter = mDirectories.begin();
iter != mDirectories.end(); ++iter)
{
const boost::filesystem::path path = *iter / file;
if (boost::filesystem::exists(path))
return true;
}
return false;
}
const Files::PathContainer& Collections::getPaths() const const Files::PathContainer& Collections::getPaths() const
{ {
return mDirectories; return mDirectories;

@ -19,6 +19,16 @@ namespace Files
/// leading dot and must be all lower-case. /// leading dot and must be all lower-case.
const MultiDirCollection& getCollection(const std::string& extension) const; const MultiDirCollection& getCollection(const std::string& extension) const;
boost::filesystem::path getPath(const std::string& file) const;
///< Return full path (including filename) of \a file.
///
/// If the file does not exist in any of the collection's
/// directories, an exception is thrown. \a file must include the
/// extension.
bool doesExist(const std::string& file) const;
///< \return Does a file with the given name exist?
const Files::PathContainer& getPaths() const; const Files::PathContainer& getPaths() const;
private: private:

Loading…
Cancel
Save