From ed329c5a1feeb50d0f81a2522cb4186e39dcf943 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 11 Dec 2013 17:12:39 +0000 Subject: [PATCH] - minor refactoring for filesystem, moved checksum calculation to loading stage from initialization - fixes for launcher --- launcher/modManager/cmodlistview_moc.cpp | 7 ++---- launcher/modManager/cmodmanager.cpp | 6 +++-- lib/CModHandler.cpp | 14 +++++++----- lib/filesystem/Filesystem.cpp | 28 ++++++++++++++---------- lib/filesystem/Filesystem.h | 20 ++++++++++++----- 5 files changed, 44 insertions(+), 31 deletions(-) diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index a407a94bd..432f8c85e 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -536,11 +536,8 @@ void CModListView::installMods(QStringList archives) for (int i=0; iinstallMod(modNames[i], archives[i]); - if (settings["launcher"]["enableInstalledMods"].Bool()) - { - for (QString mod : modNames) - manager->enableMod(mod); - } + for (QString mod : modsToEnable) + manager->enableMod(mod); for (QString archive : archives) QFile::remove(archive); diff --git a/launcher/modManager/cmodmanager.cpp b/launcher/modManager/cmodmanager.cpp index cb66889f9..4eb303629 100644 --- a/launcher/modManager/cmodmanager.cpp +++ b/launcher/modManager/cmodmanager.cpp @@ -212,8 +212,10 @@ bool CModManager::doInstallMod(QString modname, QString archivePath) if (!QFile(archivePath).exists()) return addError(modname, "Mod archive is missing"); - if (QDir(destDir + modname).exists()) // FIXME: recheck wog/vcmi data behavior - they have bits of data in our trunk - return addError(modname, "Mod with such name is already installed"); + // FIXME: recheck wog/vcmi data behavior - they have bits of data in our trunk + // FIXME: breaks when there is Era mod with same name + //if (QDir(destDir + modname).exists()) + // return addError(modname, "Mod with such name is already installed"); if (localMods.contains(modname)) return addError(modname, "Mod with such name is already installed"); diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index d9d27251c..2a291f7c0 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -699,16 +699,12 @@ static ui32 calculateModChecksum(const std::string modName, ISimpleResourceLoade void CModHandler::loadModFilesystems() { - coreMod.updateChecksum(calculateModChecksum("core", CResourceHandler::getCoreData())); + coreMod.updateChecksum(calculateModChecksum("core", CResourceHandler::get("core"))); for(std::string & modName : activeMods) { CModInfo & mod = allMods[modName]; - auto filesystem = genModFilesystem(modName, mod.config); - - CResourceHandler::get()->addLoader(filesystem, false); - logGlobal->traceStream() << "Generating checksum for " << modName; - mod.updateChecksum(calculateModChecksum(modName, filesystem)); + CResourceHandler::addFilesystem(modName, genModFilesystem(modName, mod.config)); } } @@ -731,6 +727,12 @@ void CModHandler::load() CContentHandler content; logGlobal->infoStream() << "\tInitializing content handler: " << timer.getDiff() << " ms"; + for(const TModID & modName : activeMods) + { + logGlobal->traceStream() << "Generating checksum for " << modName; + allMods[modName].updateChecksum(calculateModChecksum(modName, CResourceHandler::get(modName))); + } + // first - load virtual "core" mod that contains all data // TODO? move all data into real mods? RoE, AB, SoD, WoG content.preloadData(coreMod); diff --git a/lib/filesystem/Filesystem.cpp b/lib/filesystem/Filesystem.cpp index c8ecb54c6..4236e30a4 100644 --- a/lib/filesystem/Filesystem.cpp +++ b/lib/filesystem/Filesystem.cpp @@ -16,7 +16,7 @@ CFilesystemList * CResourceHandler::resourceLoader = nullptr; CFilesystemList * CResourceHandler::initialLoader = nullptr; -CFilesystemList * CResourceHandler::coreDataLoader = nullptr; +std::map CResourceHandler::knownLoaders = std::map(); CFilesystemGenerator::CFilesystemGenerator(std::string prefix): filesystem(new CFilesystemList()), @@ -151,40 +151,44 @@ void CResourceHandler::initialize() recurseInDir("MODS", 2); // look for mods. Depth 2 is required for now but won't cause speed issues if no mods present } -CFilesystemList * CResourceHandler::get() +ISimpleResourceLoader * CResourceHandler::get() { assert(resourceLoader); return resourceLoader; } -CFilesystemList * CResourceHandler::getInitial() +ISimpleResourceLoader * CResourceHandler::get(std::string identifier) +{ + return knownLoaders.at(identifier); +} + +ISimpleResourceLoader * CResourceHandler::getInitial() { assert(initialLoader); return initialLoader; } -CFilesystemList * CResourceHandler::getCoreData() -{ - assert(coreDataLoader); - return coreDataLoader; -} - void CResourceHandler::load(const std::string &fsConfigURI) { auto fsConfigData = initialLoader->load(ResourceID(fsConfigURI, EResType::TEXT))->readAll(); const JsonNode fsConfig((char*)fsConfigData.first.get(), fsConfigData.second); - coreDataLoader = createFileSystem("", fsConfig["filesystem"]); resourceLoader = new CFilesystemList(); - resourceLoader->addLoader(coreDataLoader, false); + addFilesystem("core", createFileSystem("", fsConfig["filesystem"])); // hardcoded system-specific path, may not be inside any of data directories resourceLoader->addLoader(new CFilesystemLoader("SAVES/", VCMIDirs::get().userSavePath()), true); resourceLoader->addLoader(new CFilesystemLoader("CONFIG/", VCMIDirs::get().userConfigPath()), true); } -CFilesystemList * CResourceHandler::createFileSystem(const std::string & prefix, const JsonNode &fsConfig) +void CResourceHandler::addFilesystem(const std::string & identifier, ISimpleResourceLoader * loader) +{ + resourceLoader->addLoader(loader, false); + knownLoaders[identifier] = loader; +} + +ISimpleResourceLoader * CResourceHandler::createFileSystem(const std::string & prefix, const JsonNode &fsConfig) { CFilesystemGenerator generator(prefix); generator.loadConfig(fsConfig); diff --git a/lib/filesystem/Filesystem.h b/lib/filesystem/Filesystem.h index fe9b02cd1..85e919c2a 100644 --- a/lib/filesystem/Filesystem.h +++ b/lib/filesystem/Filesystem.h @@ -11,9 +11,10 @@ */ #include "CInputStream.h" -#include "AdapterLoaders.h" +#include "ISimpleResourceLoader.h" #include "ResourceID.h" +class CFilesystemList; class JsonNode; /// Helper class that allows generation of a ISimpleResourceLoader entry out of Json config(s) @@ -59,9 +60,9 @@ public: * * @return Returns an instance of resource loader. */ - static CFilesystemList * get(); - static CFilesystemList * getInitial(); - static CFilesystemList * getCoreData(); + static ISimpleResourceLoader * get(); + static ISimpleResourceLoader * get(std::string identifier); + static ISimpleResourceLoader * getInitial(); /** * Creates instance of initial resource loader. @@ -83,13 +84,20 @@ public: */ static void load(const std::string & fsConfigURI); + /** + * @brief addFilesystem adds filesystem into global resource loader + * @param identifier name of this loader by which it can be retrieved later + * @param loader resource loader to add + */ + static void addFilesystem(const std::string & identifier, ISimpleResourceLoader * loader); + /** * @brief createModFileSystem - creates filesystem out of config file * @param prefix - prefix for all paths in filesystem config * @param fsConfig - configuration to load * @return generated filesystem that contains all config entries */ - static CFilesystemList * createFileSystem(const std::string &prefix, const JsonNode & fsConfig); + static ISimpleResourceLoader * createFileSystem(const std::string &prefix, const JsonNode & fsConfig); /** * Checks all subfolders of MODS directory for presence of mods @@ -98,7 +106,7 @@ public: static std::vector getAvailableMods(); private: /** Instance of resource loader */ + static std::map knownLoaders; static CFilesystemList * resourceLoader; static CFilesystemList * initialLoader; - static CFilesystemList * coreDataLoader; };