SMDFile *SMDFile::Load(std::string mapName, bool bLoadWarpsAndRegeneEvents /*= false*/)
{
#ifdef WIN32 // case insensitive filenames, allowing for database inconsistency...
	STRTOLOWER(mapName);
#endif

	// Look to see if that SMD file has been loaded already
	SMDMap::iterator itr = s_loadedMaps.find(mapName);

	// If it's been loaded already, we don't need to do anything.
	if (itr != s_loadedMaps.end())
	{
		// Add another reference.
		itr->second->IncRef();
		return itr->second;
	}

	// Map hasn't already been loaded
	std::string filename = string_format(MAP_DIR "%s", mapName.c_str());

	// Does this file exist/can it be opened?
	FILE *fp = fopen(filename.c_str(), "rb");
	if (fp == nullptr)
	{
		printf("ERROR: %s does not exist or no permission to access.\n", filename.c_str());
		return nullptr;
	}

	// Try to load the file now.
	SMDFile *smd = new SMDFile();
	if (!smd->LoadMap(fp, mapName, bLoadWarpsAndRegeneEvents))
	{
		// Problem? Make sure we clean up after ourselves.
		smd->DecRef(); // it's the only reference anyway
		smd = nullptr;
	}
	else
	{
		// Loaded fine, so now add it to the map.
		s_loadedMaps.insert(std::make_pair(mapName, smd));
	}

	fclose(fp);
	return smd;
}
Beispiel #2
0
SMDFile *SMDFile::Load(std::string mapName)
{
#ifdef WIN32 // case insensitive filenames, allowing for database inconsistency...
	STRTOLOWER(mapName);
#endif

	// Look to see if that SMD file has been loaded already
	SMDMap::iterator itr = s_loadedMaps.find(mapName);

	// If it's been loaded already, we don't need to do anything.
	if (itr != s_loadedMaps.end())
	{
		// Add another reference.
		itr->second->IncRef();
		return itr->second;
	}

	// Map hasn't already been loaded
	std::string filename = ".\\MAP\\" + mapName;

	// Does this file exist/can it be opened?
	FILE *fp = fopen(filename.c_str(), "rb");
	if (fp == NULL)
		return NULL;

	// Try to load the file now.
	SMDFile *smd = new SMDFile();
	if (!smd->LoadMap(fp))
	{
		// Problem? Make sure we clean up after ourselves.
		smd->DecRef(); // it's the only reference anyway
		smd = NULL;
	}
	else
	{
		// Loaded fine, so now add it to the map.
		s_loadedMaps.insert(std::make_pair(mapName, smd));
	}

	fclose(fp);
	return smd;
}