1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

- minor refactoring for filesystem, moved checksum calculation to

loading stage from initialization
- fixes for launcher
This commit is contained in:
Ivan Savenko 2013-12-11 17:12:39 +00:00
parent 69eee05ccc
commit ed329c5a1f
5 changed files with 44 additions and 31 deletions

View File

@ -536,11 +536,8 @@ void CModListView::installMods(QStringList archives)
for (int i=0; i<modNames.size(); i++)
manager->installMod(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);

View File

@ -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");

View File

@ -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);

View File

@ -16,7 +16,7 @@
CFilesystemList * CResourceHandler::resourceLoader = nullptr;
CFilesystemList * CResourceHandler::initialLoader = nullptr;
CFilesystemList * CResourceHandler::coreDataLoader = nullptr;
std::map<std::string, ISimpleResourceLoader*> CResourceHandler::knownLoaders = std::map<std::string, ISimpleResourceLoader*>();
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);

View File

@ -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<std::string> getAvailableMods();
private:
/** Instance of resource loader */
static std::map<std::string, ISimpleResourceLoader*> knownLoaders;
static CFilesystemList * resourceLoader;
static CFilesystemList * initialLoader;
static CFilesystemList * coreDataLoader;
};