/* * CArchiveScanner::ArchiveData */ CArchiveScanner::ArchiveData::ArchiveData(const LuaTable& archiveTable) { if (!archiveTable.IsValid()) { return; } std::vector<std::string> keys; if (!archiveTable.GetKeys(keys)) { return; } std::vector<std::string>::const_iterator key; for (key = keys.begin(); key != keys.end(); ++key) { const std::string& keyLower = StringToLower(*key); if (!ArchiveData::IsReservedKey(keyLower)) { if (keyLower == "modtype") { SetInfoItemValueInteger(*key, archiveTable.GetInt(*key, 0)); continue; } const int luaType = archiveTable.GetType(*key); switch (luaType) { case LuaTable::STRING: { SetInfoItemValueString(*key, archiveTable.GetString(*key, "")); } break; case LuaTable::NUMBER: { SetInfoItemValueFloat(*key, archiveTable.GetFloat(*key, 0.0f)); } break; case LuaTable::BOOLEAN: { SetInfoItemValueBool(*key, archiveTable.GetBool(*key, false)); } break; default: { // just ignore unsupported types (most likely to be lua-tables) //throw content_error("Lua-type " + IntToString(luaType) + " not supported in archive-info, but it is used on key \"" + *key + "\""); } break; } } } const LuaTable _dependencies = archiveTable.SubTable("depend"); for (int dep = 1; _dependencies.KeyExists(dep); ++dep) { dependencies.push_back(_dependencies.GetString(dep, "")); } const LuaTable _replaces = archiveTable.SubTable("replace"); for (int rep = 1; _replaces.KeyExists(rep); ++rep) { replaces.push_back(_replaces.GetString(rep, "")); } //! FIXME //! XXX HACK needed until lobbies, lobbyserver and unitsync are sorted out //! so they can uniquely identify different versions of the same mod. //! (at time of this writing they use name only) //! NOTE when changing this, this function is used both by the code that //! reads ArchiveCache.lua and the code that reads modinfo.lua from the mod. //! so make sure it doesn't keep adding stuff to the name everytime //! Spring/unitsync is loaded. const std::string& name = GetName(); const std::string& version = GetVersion(); if ((name.find(version) == std::string::npos) && !version.empty()) { SetInfoItemValueString("name", name + " " + version); } }
/* * CArchiveScanner::ArchiveData */ CArchiveScanner::ArchiveData::ArchiveData(const LuaTable& archiveTable, bool fromCache) { if (!archiveTable.IsValid()) return; std::vector<std::string> keys; if (!archiveTable.GetKeys(keys)) return; for (std::string& key: keys) { const std::string& keyLower = StringToLower(key); if (ArchiveData::IsReservedKey(keyLower)) continue; if (keyLower == "modtype") { SetInfoItemValueInteger(key, archiveTable.GetInt(key, 0)); continue; } switch (archiveTable.GetType(key)) { case LuaTable::STRING: { SetInfoItemValueString(key, archiveTable.GetString(key, "")); } break; case LuaTable::NUMBER: { SetInfoItemValueFloat(key, archiveTable.GetFloat(key, 0.0f)); } break; case LuaTable::BOOLEAN: { SetInfoItemValueBool(key, archiveTable.GetBool(key, false)); } break; default: { // just ignore unsupported types (most likely to be lua-tables) //throw content_error("Lua-type " + IntToString(luaType) + " not supported in archive-info, but it is used on key \"" + *key + "\""); } break; } } const LuaTable& _dependencies = archiveTable.SubTable("depend"); const LuaTable& _replaces = archiveTable.SubTable("replace"); for (int dep = 1; _dependencies.KeyExists(dep); ++dep) { dependencies.push_back(_dependencies.GetString(dep, "")); } for (int rep = 1; _replaces.KeyExists(rep); ++rep) { replaces.push_back(_replaces.GetString(rep, "")); } // FIXME // XXX HACK needed until lobbies, lobbyserver and unitsync are sorted out // so they can uniquely identify different versions of the same mod. // (at time of this writing they use name only) // NOTE when changing this, this function is used both by the code that // reads ArchiveCache.lua and the code that reads modinfo.lua from the mod. // so make sure it doesn't keep adding stuff to the name everytime // Spring/unitsync is loaded. const std::string& name = GetNameVersioned(); const std::string& version = GetVersion(); if (!version.empty()) { if (name.find(version) == std::string::npos) { SetInfoItemValueString("name", name + " " + version); } else if (!fromCache) { LOG_L(L_WARNING, "[%s] version \"%s\" included in name \"%s\"", __func__, version.c_str(), name.c_str()); } } if (GetName().empty()) SetInfoItemValueString("name_pure", name); }