コード例 #1
0
void CModInfoManager::Refresh()
{
#ifndef _WIN32
	assert(0 && "Calling Windows-specific code");
	return;
#endif

	if (!gEnv || !gEnv->pCryPak)
	{
		assert(0);
		return;
	}

	ICryPak* pCryPak = gEnv->pCryPak;

	m_mods.clear();

	// look for MODs
	{
		_finddata_t fd;
		intptr_t h = pCryPak->FindFirst ("Mods\\*", &fd, 0, true);
		if (h != -1)
		{
			CryStackStringT<char, _MAX_PATH*2> path;
			do 
			{
				if ((fd.attrib & _A_SUBDIR) == 0)
					continue;
				if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0)
					continue;

				path = "Mods\\";
				path += fd.name;

				ModInfo mod;

				if (ModInfo_LoadFromFile(&mod, (path + "\\info.xml").c_str()) && mod.modType != eMIT_SPLEVEL)
				{
					mod.keyName = fd.name;
					if (mod.displayName.empty())
						mod.displayName = mod.keyName;
					path.replace('\\', '/');
					path.insert(0, '/');
					mod.mainImage = (path + "/modpreview.jpg").c_str();
					mod.logoImage = (path + "/modteamlogo.jpg").c_str();
					m_mods.push_back(mod);
				}
			}
			while(0 == pCryPak->FindNext(h, &fd));

			pCryPak->FindClose (h);
		}
	}

	// look for SP-levels
	{
		CryStackStringT<char, _MAX_PATH*2> path;
		path += PathUtil::GetGameFolder();
		path += "\\Levels\\*";

		_finddata_t fd;
		intptr_t h = pCryPak->FindFirst (path.c_str(), &fd, 0, true);
		if (h != -1)
		{
			do 
			{
				if ((fd.attrib & _A_SUBDIR) == 0)
					continue;
				if (strcmp(fd.name, ".") == 0 || strcmp(fd.name, "..") == 0)
					continue;

				path = PathUtil::GetGameFolder();
				path += "\\Levels\\";
				path += fd.name;

				ModInfo mod;

				if (ModInfo_LoadFromFile(&mod, (path + "\\info.xml").c_str()))
				{
					mod.modType = eMIT_SPLEVEL;
					mod.keyName = fd.name;
					path = "/Levels/";
					path += fd.name;
					mod.mainImage = (path + "/modpreview.jpg").c_str();
					mod.logoImage = (path + "/modteamlogo.jpg").c_str();
					if (mod.displayName.empty())
						mod.displayName = mod.keyName;
					m_mods.push_back(mod);
				}
			}
			while(0 == pCryPak->FindNext(h, &fd));

			pCryPak->FindClose (h);
		}
	}

	// look for MOD levels
	{
		m_modLevels.clear();

		CryStackStringT<char, _MAX_PATH*2> path;

		ILevelSystem* pLevelSystem = g_pGame->GetIGameFramework()->GetILevelSystem();
		size_t levelCount = pLevelSystem->GetLevelCount();
		for (size_t i = 0; i < levelCount; ++i)
		{
			ILevelInfo* pInfo = pLevelSystem->GetLevelInfo(i);
			if (!pInfo)
				continue;
			if (pInfo->GetIsModLevel() && (!pInfo->HasGameRules() || pInfo->SupportsGameType("SinglePlayer")))
			{
				ModInfo mod;
				const char* szLevelInfoDisplayName = pInfo->GetDisplayName();
				if (strcmp(szLevelInfoDisplayName, "") != 0)
				{
					mod.displayName = szLevelInfoDisplayName;
				}
				else // Fallback to directory name
				{
					mod.displayName = pInfo->GetName();
				}

				// load info.xml as well
				path = pInfo->GetPath();
				path.replace('/', '\\');
				if (ModInfo_LoadFromFile(&mod, (path + "\\info.xml").c_str()))
				{
					path.replace('\\', '/');
					path.insert(0, '/');
					mod.mainImage = (path + "/modpreview.jpg").c_str();
					mod.logoImage = (path + "/modteamlogo.jpg").c_str();
				}

				mod.keyName = pInfo->GetName();
				mod.modType = eMIT_SPLEVEL;

				m_modLevels.push_back(mod);
			}
		}
	}
}