Exemplo n.º 1
0
bool GfModule::isPresent(const std::string& strModCatName, const std::string& strModName)
{
	std::ostringstream ossModLibPathName;
	
	ossModLibPathName << GfLibDir() << "modules/" << strModCatName << "/"
					  <<  strModName << '.' << DLLEXT;

	return GfFileExists(ossModLibPathName.str().c_str());
}
Exemplo n.º 2
0
static void loadSimuCfg(void)
{
	const char *simuVersionName;
	const char *multiThreadSchemeName;
	const char *threadAffinitySchemeName;
	int i;

	char buf[1024];
	snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), RACE_ENG_CFG);

	void *paramHandle = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT);

	// Simulation engine name.
	simuVersionName = GfParmGetStr(paramHandle, RM_SECT_MODULES, RM_ATTR_MOD_SIMU, SimuVersionList[DefaultSimuVersion]);
	for (i = 0; i < NbSimuVersions; i++) {
		if (strcmp(simuVersionName, SimuVersionList[i]) == 0) {
			CurSimuVersion = i;
			break;
		}
	}

	// Check if the selected simulation module is there, and fall back to the default one if not.
	snprintf(buf, sizeof(buf), "%smodules/simu/%s.%s", GfLibDir(), SimuVersionList[CurSimuVersion], DLLEXT);
	if (!GfFileExists(buf))
	{
		GfLogWarning("User settings %s physics engine module not found ; falling back to %s\n",
					 SimuVersionList[CurSimuVersion], SimuVersionList[DefaultSimuVersion]);
		CurSimuVersion = DefaultSimuVersion;
	}

	// Multi-threading.
	multiThreadSchemeName = GfParmGetStr(paramHandle, RM_SECT_RACE_ENGINE, RM_ATTR_MULTI_THREADING, MultiThreadSchemeList[0]);
	for (i = 0; i < NbMultiThreadSchemes; i++) {
		if (strcmp(multiThreadSchemeName, MultiThreadSchemeList[i]) == 0) {
			CurMultiThreadScheme = i;
			break;
		}
	}

	// Thread affinity.
	threadAffinitySchemeName = GfParmGetStr(paramHandle, RM_SECT_RACE_ENGINE, RM_ATTR_THREAD_AFFINITY, ThreadAffinitySchemeList[0]);
	for (i = 0; i < NbThreadAffinitySchemes; i++) {
		if (strcmp(threadAffinitySchemeName, ThreadAffinitySchemeList[i]) == 0) {
			CurThreadAffinityScheme = i;
			break;
		}
	}

	GfParmReleaseHandle(paramHandle);

	GfuiLabelSetText(ScrHandle, SimuVersionId, SimuVersionDispNameList[CurSimuVersion]);
	GfuiLabelSetText(ScrHandle, MultiThreadSchemeId, MultiThreadSchemeList[CurMultiThreadScheme]);
	GfuiLabelSetText(ScrHandle, ThreadAffinitySchemeId, ThreadAffinitySchemeList[CurThreadAffinityScheme]);
}
Exemplo n.º 3
0
static std::string
GetTrackOutlineFileName(const char *pszCategory,const char *pszTrack)
{
	char buf[256];

    snprintf(buf, sizeof(buf), "tracks/%s/%s/outline.png", pszCategory, pszTrack);
	
	if (!GfFileExists(buf))
		strncpy(buf, "data/img/transparent.png", sizeof(buf));
	
	return std::string(buf);
}
Exemplo n.º 4
0
static std::string
GetTrackPreviewFileName(const char *pszCategory, const char *pszTrack)
{
	char buf[256];

	// Try JPEG first.
    snprintf(buf, sizeof(buf), "tracks/%s/%s/%s.jpg", pszCategory, pszTrack, pszTrack);
    buf[255] = 0; /* snprinf manual is not clear about that ... */

	// Then PNG if not found.
	if (!GfFileExists(buf))
	{
		snprintf(buf, sizeof(buf), "tracks/%s/%s/%s.png", pszCategory, pszTrack, pszTrack);
		buf[255] = 0; /* snprinf manual is not clear about that ... */
	}

	// Then fallback.
	if (!GfFileExists(buf))
		strncpy(buf, "data/img/splash-networkrace.jpg", sizeof(buf));
	
	return std::string(buf);
}
Exemplo n.º 5
0
bool GfTrack::load() const
{
	// Check if the track loader is ready.
	ITrackLoader* piTrackLoader = GfTracks::self()->getTrackLoader();
    if (!piTrackLoader)
	{
		GfLogError("Track loader not yet initialized ; failed to load any track\n");
        return false;
    }
	
    // Load track data from the XML file.
    tTrack* pTrack = piTrackLoader->load(_strDescFile.c_str());
    if (!pTrack)
	{
		GfLogWarning("Unusable track %s : failed to build track data from %s\n",
					 _strId.c_str(), _strDescFile.c_str());
        return false;
    }

	// Check if the track 3D model file exists.
	std::ostringstream ossFileName;
	ossFileName << "tracks/" << _strCatId << '/' << _strId << '/'
				<< (pTrack->graphic.model3d ? pTrack->graphic.model3d : "track.ac");
    if (!GfFileExists(ossFileName.str().c_str()))
	{
		GfLogWarning("Unusable track %s : could not find 3D model %s\n",
					 _strId.c_str(), ossFileName.str().c_str());
        return false;
    }

	// All right now : let's read last needed infos.
	_strName = pTrack->name;
	_strDesc = pTrack->descr;
	_strAuthors = pTrack->authors;
	_fLength = pTrack->length;
	_fWidth = pTrack->width;
	_nMaxPitSlots = pTrack->pits.nMaxPits;

    // Unload track data.
    piTrackLoader->unload();

	// Now, the track seems usable (hm ... OK, we didn't check the 3D file contents ...).
	_bUsable = true;
	
	return true;
}
Exemplo n.º 6
0
// TODO: Tests (not yet used, see #809).
std::vector<GfModule*> GfModule::loadFromDir(const std::string& strDirPath,
											 bool bUseChildDirs)
{
	std::vector<GfModule*> vecModules;

	GfLogDebug("GfModule::loadFromDir(%s)\n", strDirPath.c_str());

	// Get the list of files/sub-dirs in the folder.
	tFList* lstFilesOrDirs = GfDirGetList(strDirPath.c_str());
	if (lstFilesOrDirs)
	{
		// Filter module shared libraries and try and load each of them.
		tFList* pFileOrDir = lstFilesOrDirs;
		do 
		{
			// Ignore "." and ".." folders.
			if (pFileOrDir->name[0] == '.') 
				continue;
			
			GfLogDebug("  Examining %s\n", pFileOrDir->name);
		
			// Build module shared library path-name (consider only foders, not files).
			std::ostringstream ossShLibPath;
			ossShLibPath << strDirPath << '/' << pFileOrDir->name;
			if (bUseChildDirs)
				ossShLibPath << '/' << pFileOrDir->name;
			ossShLibPath << DLLEXT;

			// Check existence.
			if (!GfFileExists(ossShLibPath.str().c_str()))
				continue;

			// Try and load.
			GfModule* pModule = GfModule::load(ossShLibPath.str().c_str());
			if (pModule)
				vecModules.push_back(pModule);
			else
				GfLogWarning("Failed to load module %s\n", ossShLibPath.str().c_str());
			
		}
		while ((pFileOrDir = pFileOrDir->next) != lstFilesOrDirs);
	}
	
	return vecModules;
}
Exemplo n.º 7
0
/* Change the simulation version (but only show really available modules) */
static void
onChangeSimuVersion(void *vp)
{
	char buf[1024];

	if (!vp)
		return;

	const int oldSimuVersion = CurSimuVersion;
	do
	{
		CurSimuVersion = (CurSimuVersion + NbSimuVersions + (int)(long)vp) % NbSimuVersions;
	
		snprintf(buf, sizeof(buf), "%smodules/simu/%s.%s", GfLibDir(), SimuVersionList[CurSimuVersion], DLLEXT);
	}
	while (!GfFileExists(buf) && CurSimuVersion != oldSimuVersion);

	GfuiLabelSetText(ScrHandle, SimuVersionId, SimuVersionDispNameList[CurSimuVersion]);
}
Exemplo n.º 8
0
std::vector<GfDriverSkin> GfDriver::getPossibleSkins(const std::string& strAltCarId) const
{
	const std::string strCarId = strAltCarId.empty() ? _pCar->getId() : strAltCarId;

	GfLogDebug("Checking skins for %s ...\n", strCarId.c_str());

	// Clear the skin and preview lists.
	std::vector<GfDriverSkin> vecPossSkins;

	// Get/check skins/skin targets/previews from the directories in the search path
	// WARNING: Must be consistent with the search paths used in grcar.cpp, grboard.cpp,
	//          grscene.cpp ... etc ... but it is not currently 100% achieved
	//          (pit door logos are not searched by the graphics engine
	//           in the car-dedicated folders ... so they may be "over-detected" here).
	std::ostringstream ossDirPath;
	ossDirPath << GfLocalDir() << "drivers/" << _strModName
			   << '/' << _nItfIndex << '/' << strCarId;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << GfLocalDir() << "drivers/" << _strModName
			   << '/' << _nItfIndex;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << GfLocalDir() << "drivers/" << _strModName
			   << '/' << strCarId;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << GfLocalDir() << "drivers/" << _strModName;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << "drivers/" << _strModName
			   << '/' << _nItfIndex << '/' << strCarId;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << "drivers/" << _strModName
			   << '/' << _nItfIndex;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << "drivers/" << _strModName
			   << '/' << strCarId;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << "drivers/" << _strModName;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	ossDirPath.str("");
	ossDirPath << "cars/models/" << strCarId;
	getPossibleSkinsInFolder(strCarId, ossDirPath.str(), vecPossSkins);

	// If we have at least 1 skin, make sure that, if the standard one is inside,
	// it is the first one.
	if (!vecPossSkins.empty())
	{
		std::vector<GfDriverSkin>::iterator itSkin;
		for (itSkin = vecPossSkins.begin(); itSkin != vecPossSkins.end(); itSkin++)
		{
			if (itSkin->getName().empty() && itSkin != vecPossSkins.begin())
			{
				GfDriverSkin stdSkin = *itSkin;
				vecPossSkins.erase(itSkin);
				vecPossSkins.insert(vecPossSkins.begin(), stdSkin);
				break;
			}
		}
	}
	
	// If no skin was found, add the car's standard one
	// (that way, the skin list will never be empty, and that's safer)
	else
	{
		GfLogError("No skin at all found for '%s/%d/%s' : adding dummy '%s' one\n",
				   _strModName.c_str(), _nItfIndex, strCarId.c_str(), "standard");
		
		GfDriverSkin stdSkin;
		std::ostringstream ossPreviewName;
		ossPreviewName << "cars/models/" << strCarId << '/' << strCarId << pszPreviewTexSufx;
		stdSkin.setCarPreviewFileName(ossPreviewName.str());

		if (!GfFileExists(ossPreviewName.str().c_str()))
			GfLogWarning("No preview file %s found for dummy '%s' skin\n",
						 ossPreviewName.str().c_str(), "standard");

		vecPossSkins.push_back(stdSkin);
	}

	return vecPossSkins;
}
Exemplo n.º 9
0
void GfDriver::getPossibleSkinsInFolder(const std::string& strCarId,
										const std::string& strFolderPath,
										std::vector<GfDriverSkin>& vecPossSkins) const
{
	//GfLogDebug("  getPossibleSkinsInFolder(%s, %s) ...\n",
	//		   strCarId.c_str(), strFolderPath.c_str());

	// Search for skinned livery files, and associated preview files if any.
	tFList *pLiveryFileList =
		GfDirGetListFiltered(strFolderPath.c_str(), strCarId.c_str(), pszLiveryTexExt);
	if (pLiveryFileList)
	{
		tFList *pCurLiveryFile = pLiveryFileList;
		do
		{
			pCurLiveryFile = pCurLiveryFile->next;

			// Extract the skin name from the livery file name.
			const int nSkinNameLen = // Expecting "<car name>-<skin name>.png"
				strlen(pCurLiveryFile->name) - strCarId.length() - 1 - strlen(pszLiveryTexExt);
			std::string strSkinName;
			if (nSkinNameLen > 0) // Otherwise, default/standard "<car name>.png"
			{
				strSkinName =
					std::string(pCurLiveryFile->name)
					.substr(strCarId.length() + 1, nSkinNameLen);
				
				// Ignore skins with an excluded prefix.
				int nExclPrfxInd = 0;
				for (; nExclPrfxInd < nExcludedSkinNamePrefixes; nExclPrfxInd++)
					if (strSkinName.find(apszExcludedSkinNamePrefixes[nExclPrfxInd]) == 0)
						break;
				if (nExclPrfxInd < nExcludedSkinNamePrefixes)
					continue;
			}
			
			// Ignore skins that are already in the list (path search priority).
			if (findSkin(vecPossSkins, strSkinName) == vecPossSkins.end())
			{
				// Create the new skin.
				GfDriverSkin skin(strSkinName);

				// Add the whole car livery to the skin targets.
				skin.addTargets(RM_CAR_SKIN_TARGET_WHOLE_LIVERY);
				
				GfLogDebug("  Found %s%s livery\n",
						   strSkinName.empty() ? "standard" : strSkinName.c_str(),
						   strSkinName.empty() ? "" : "-skinned");
				
				// Add associated preview image, without really checking file existence
				// (warn only ; up to the client GUI to do what to do if it doesn't exist).
				std::ostringstream ossPreviewName;
				ossPreviewName << strFolderPath << '/' << strCarId;
				if (!strSkinName.empty())
					ossPreviewName << '-' << strSkinName;
				ossPreviewName << pszPreviewTexSufx;
				skin.setCarPreviewFileName(ossPreviewName.str());

				if (!GfFileExists(ossPreviewName.str().c_str()))
					GfLogWarning("Preview file not found for %s %s skin (%s)\n",
								 strCarId.c_str(), strSkinName.c_str(), ossPreviewName.str().c_str());
				//else
				//	GfLogDebug("* found skin=%s, preview=%s\n",
				//			   strSkinName.c_str(), ossPreviewName.str().c_str());

				// Add the new skin to the list.
				vecPossSkins.push_back(skin);
			}

		}
		while (pCurLiveryFile != pLiveryFileList);
	}
	
	GfDirFreeList(pLiveryFileList, NULL, true, true);
	
	// Search for skinned interior files, if any.
	std::string strInteriorPrefix(strCarId);
	strInteriorPrefix += pszInteriorTexSufx;
	tFList *pIntFileList =
		GfDirGetListFiltered(strFolderPath.c_str(), strInteriorPrefix.c_str(), pszInteriorTexExt);
	if (pIntFileList)
	{
		tFList *pCurIntFile = pIntFileList;
		do
		{
			pCurIntFile = pCurIntFile->next;

			// Extract the skin name from the interior file name.
			const int nSkinNameLen = // Expecting "<car name>-int-<skin name>.png"
				strlen(pCurIntFile->name) - strInteriorPrefix.length()
				- 1 - strlen(pszInteriorTexExt);
			std::string strSkinName;
			if (nSkinNameLen > 0)
			{
				strSkinName =
					std::string(pCurIntFile->name)
					.substr(strInteriorPrefix.length() + 1, nSkinNameLen);

				// If a skin with such name already exists in the list, update it.
				std::vector<GfDriverSkin>::iterator itSkin =
					findSkin(vecPossSkins, strSkinName);
				if (itSkin != vecPossSkins.end())
				{
					itSkin->addTargets(RM_CAR_SKIN_TARGET_INTERIOR);
					GfLogDebug("  Found %s-skinned interior (targets:%x)\n",
							   strSkinName.c_str(), itSkin->getTargets());
				}
			}
		}
		while (pCurIntFile != pIntFileList);
	}
	
	GfDirFreeList(pIntFileList, NULL, true, true);
	
	// Search for skinned logo files if any.
	tFList *pLogoFileList =
		GfDirGetListFiltered(strFolderPath.c_str(), pszLogoTexName, pszLogoTexExt);
	if (pLogoFileList)
	{
		tFList *pCurLogoFile = pLogoFileList;
		do
		{
			pCurLogoFile = pCurLogoFile->next;

			// Extract the skin name from the logo file name.
			const int nSkinNameLen = // Expecting "logo-<skin name>.png"
				strlen(pCurLogoFile->name) - strlen(pszLogoTexName)
				- 1 - strlen(pszLogoTexExt);
			if (nSkinNameLen > 0)
			{
				const std::string strSkinName =
					std::string(pCurLogoFile->name)
					.substr(strlen(pszLogoTexName) + 1, nSkinNameLen);
			
				// If a skin with such name already exists in the list, update it.
				std::vector<GfDriverSkin>::iterator itSkin = findSkin(vecPossSkins, strSkinName);
				if (itSkin != vecPossSkins.end())
				{
					itSkin->addTargets(RM_CAR_SKIN_TARGET_PIT_DOOR);
					GfLogDebug("  Found %s-skinned logo (targets:%x)\n",
							   strSkinName.c_str(), itSkin->getTargets());
				}
			}
				
		}
		while (pCurLogoFile != pLogoFileList);
	}
	
	GfDirFreeList(pLogoFileList, NULL, true, true);
	
	// Search for skinned 3D wheel files if any.
	tFList *pWheel3DFileList =
		GfDirGetListFiltered(strFolderPath.c_str(), pszWheel3DTexName, pszWheel3DTexExt);
	if (pWheel3DFileList)
	{
		tFList *pCurWheel3DFile = pWheel3DFileList;
		do
		{
			pCurWheel3DFile = pCurWheel3DFile->next;

			// Extract the skin name from the 3D wheel texture file name.
			const int nSkinNameLen = // Expecting "wheel3d-<skin name>.png"
				strlen(pCurWheel3DFile->name) - strlen(pszWheel3DTexName)
				- 1 - strlen(pszWheel3DTexExt);
			if (nSkinNameLen > 0)
			{
				const std::string strSkinName =
					std::string(pCurWheel3DFile->name)
					.substr(strlen(pszWheel3DTexName) + 1, nSkinNameLen);
			
				// If a skin with such name already exists in the list, update it.
				std::vector<GfDriverSkin>::iterator itSkin = findSkin(vecPossSkins, strSkinName);
				if (itSkin != vecPossSkins.end())
				{
					itSkin->addTargets(RM_CAR_SKIN_TARGET_3D_WHEELS);
					GfLogDebug("  Found %s-skinned 3D wheels (targets:%x)\n",
							   strSkinName.c_str(), itSkin->getTargets());
				}
			}
		}
		while (pCurWheel3DFile != pWheel3DFileList);
	}
	
	GfDirFreeList(pWheel3DFileList, NULL, true, true);
	
	// Search for skinned driver files if any.
	tFList *pDriverFileList =
		GfDirGetListFiltered(strFolderPath.c_str(), pszDriverTexName, pszDriverTexExt);
	if (pDriverFileList)
	{
		tFList *pCurDriverFile = pDriverFileList;
		do
		{
			pCurDriverFile = pCurDriverFile->next;

			// Extract the skin name from the 3D wheel texture file name.
			const int nSkinNameLen = // Expecting "driver-<skin name>.png"
				strlen(pCurDriverFile->name) - strlen(pszDriverTexName)
				- 1 - strlen(pszDriverTexExt);
			if (nSkinNameLen > 0)
			{
				const std::string strSkinName =
					std::string(pCurDriverFile->name)
					.substr(strlen(pszDriverTexName) + 1, nSkinNameLen);
			
				// If a skin with such name already exists in the list, update it.
				std::vector<GfDriverSkin>::iterator itSkin = findSkin(vecPossSkins, strSkinName);
				if (itSkin != vecPossSkins.end())
				{
					itSkin->addTargets(RM_CAR_SKIN_TARGET_DRIVER);
					GfLogDebug("  Found %s-skinned driver (targets:%x)\n",
							   strSkinName.c_str(), itSkin->getTargets());
				}
			}
		}
		while (pCurDriverFile != pDriverFileList);
	}
	
	GfDirFreeList(pDriverFileList, NULL, true, true);
}
Exemplo n.º 10
0
GfTracks::GfTracks()
{
	_pPrivate = new GfTracks::Private;

	// Get the list of sub-dirs in the "tracks" folder (the track categories).
	tFList* lstCatFolders = GfDirGetList("tracks");
	if (!lstCatFolders)
	{
		GfLogFatal("No track category available in the 'tracks' folder\n");
		return;
	}
	
	tFList* pCatFolder = lstCatFolders;
	do 
	{
		//GfLogDebug("GfTracks::GfTracks() : Examining category %s\n", pCatFolder->name);
		
		// Ignore "." and ".." folders.
		const char* pszCatId = pCatFolder->name;
		if (pszCatId[0] == '.') 
			continue;
			
		// Get the list of sub-dirs in the "tracks" folder (the track categories).
		std::string strDirName("tracks/");
		strDirName += pszCatId;
		tFList* lstTrackFolders = GfDirGetList(strDirName.c_str());
		if (!lstTrackFolders)
		{
			GfLogWarning("No track available in the '%s' folder\n", strDirName.c_str());
			continue;
		}

		// Add new category.
		_pPrivate->vecCatIds.push_back(pszCatId);

		// Look at the tracks in this category.
		tFList* pTrackFolder = lstTrackFolders;
		do 
		{
			//GfLogDebug("GfTracks::GfTracks() : Examining track %s\n", pTrackFolder->name);
		
			// Determine and check the XML file of the track.
			const char* pszTrackId = pTrackFolder->name;
			
			std::ostringstream ossFileName;
			ossFileName << "tracks/" << pszCatId << '/' << pszTrackId
						<< '/' << pszTrackId << '.' << TRKEXT;
			const std::string strTrackFileName(ossFileName.str());
			if (!GfFileExists(strTrackFileName.c_str()))
			{
				GfLogInfo("Ignoring track %s : %s not found\n",
							 pszTrackId, strTrackFileName.c_str());
				continue;
			}

			// Get 1st level track info (those which don't need to open any file).
			ossFileName.str("");
			ossFileName << "tracks/" << pszCatId << '/' << pszTrackId
						<< '/' << pszTrackId << ".jpg";
			std::string strPreviewFileName(ossFileName.str());
			if (!GfFileExists(strPreviewFileName.c_str()))
			{
				ossFileName.str("");
				ossFileName << "tracks/" << pszCatId << '/' << pszTrackId
							<< '/' << pszTrackId << ".png";
				strPreviewFileName = ossFileName.str();
			}
			if (!GfFileExists(strPreviewFileName.c_str()))
				strPreviewFileName = "data/img/splash-trackselect.jpg";
			
			ossFileName.str("");
			ossFileName << "tracks/" << pszCatId << '/' << pszTrackId << '/' << "outline.png";
			std::string strOutlineFileName(ossFileName.str());
			if (!GfFileExists(strOutlineFileName.c_str()))
				strOutlineFileName = "data/img/notrackoutline.png";
			
			// Store track info in the GfTrack structure.
			GfTrack* pTrack = new GfTrack;
			pTrack->setId(pszTrackId);
			pTrack->setCategoryId(pszCatId);
			pTrack->setDescriptorFile(strTrackFileName);
			pTrack->setPreviewFile(strPreviewFileName);
			pTrack->setOutlineFile(strOutlineFileName);

			// Update the GfTracks singleton.
			_pPrivate->vecTracks.push_back(pTrack);
			_pPrivate->mapTracksById[pszTrackId] = pTrack;
		}
		while ((pTrackFolder = pTrackFolder->next) != lstTrackFolders);
		
		GfDirFreeList(lstTrackFolders, NULL, true, true);
	} 
	while ((pCatFolder = pCatFolder->next) != lstCatFolders);
	
	GfDirFreeList(lstCatFolders, NULL, true, true);
	
	// Sort the car category ids and driver types vectors.
	std::sort(_pPrivate->vecCatIds.begin(), _pPrivate->vecCatIds.end());

	// Trace what we got.
	print(false); // No verbose here, otherwise infinite recursion.
}
Exemplo n.º 11
0
void GfFileSetup()
{
	void *dataVersionHandle;
	void *localVersionHandle;
	char *filename;
	size_t filenameLength;
	char *dataLocation;
	char *localLocation;
	char *absLocalLocation;
	char *absDataLocation;
	bool *isIndexUsed;
	int isIndexUsedLen;
	int index;
	bool anyLocalChange, fileFound;
	int major;
	int minor;
	struct stat st;

	// Open data (installation) version.xml.
	filenameLength = strlen(GfDataDir()) + 12 + 40;
	filename = (char*)malloc( sizeof(char) * filenameLength );
	sprintf( filename, "%sversion.xml", GfDataDir() );
	dataVersionHandle = GfParmReadFile( filename, GFPARM_RMODE_STD );
	if( !dataVersionHandle )
	{
		free( filename );
		return;
	}

	// Exit if nothing inside.
	if( GfParmListSeekFirst( dataVersionHandle, "versions" ) != 0 )
	{
		free( filename );
		GfParmReleaseHandle( dataVersionHandle );
		return;
	}

	// Create LocalDir (user settings root) if not already done.
	GfDirCreate( GfLocalDir() );

	// Open local (user settings) version.xml (create it if not there).
	if( filenameLength < strlen(GfLocalDir()) + 12 )
	{
		free( filename );
		filenameLength = strlen(GfLocalDir()) + 12 + 40;
		filename = (char*)malloc( sizeof(char) * filenameLength );
	}

	sprintf( filename, "%sversion.xml", GfLocalDir() );
	anyLocalChange = !GfFileExists(filename);
	localVersionHandle = GfParmReadFile( filename, GFPARM_RMODE_CREAT );

	// Exit if open/creation failed.
	if( !localVersionHandle )
	{
		free( filename );
		GfParmReleaseHandle( dataVersionHandle );
		return;
	}

	// Setup the index of the XML files referenced in the local version.xml.
	isIndexUsedLen = GfParmGetEltNb( localVersionHandle, "versions" )
		             + GfParmGetEltNb( dataVersionHandle, "versions" ) + 2;
	isIndexUsed = (bool*)malloc( sizeof(bool) * isIndexUsedLen );
	for( index = 0; index < isIndexUsedLen; index++ )
		isIndexUsed[index] = false;
	if( GfParmListSeekFirst( localVersionHandle, "versions" ) == 0 )
	{
		do
		{
			index = atoi( GfParmListGetCurEltName( localVersionHandle, "versions" ) );
			if( 0 <= index && index < isIndexUsedLen )
				isIndexUsed[index] = true;
		} while( GfParmListSeekNext( localVersionHandle, "versions" ) == 0 );
	}

	// For each file referenced in the installation version.xml
	do
	{
		fileFound = false;

		// Get its installation path (data), user settings path (local),
		// and new major and minor version numbers
		dataLocation = strdup( GfParmGetCurStr( dataVersionHandle, "versions", "Data location", "" ) );
		localLocation = strdup( GfParmGetCurStr( dataVersionHandle, "versions", "Local location", "" ) );
		major = (int)GfParmGetCurNum( dataVersionHandle, "versions", "Major version", NULL, 0 );
		minor = (int)GfParmGetCurNum( dataVersionHandle, "versions", "Minor version", NULL, 0 );

		absLocalLocation = (char*)malloc( sizeof(char)*(strlen(GfLocalDir())+strlen(localLocation)+3) );
		sprintf( absLocalLocation, "%s%s", GfLocalDir(), localLocation );

		absDataLocation = (char*)malloc( sizeof(char)*(strlen(GfDataDir())+strlen(dataLocation)+3) );
		sprintf( absDataLocation, "%s%s", GfDataDir(), dataLocation );

		GfLogTrace("Checking %s : user settings version ", localLocation);

		// Search for its old major and minor version numbers in the user settings.
		if( GfParmListSeekFirst( localVersionHandle, "versions" ) == 0 )
		{
			do
			{
				if( strcmp( absLocalLocation, GfParmGetCurStr( localVersionHandle, "versions", "Local location", "" ) ) == 0 )
				{
					fileFound = true;
					const int locMinor = (int)GfParmGetCurNum( localVersionHandle, "versions", "Minor version", NULL, 0 );
					const int locMajor = (int)GfParmGetCurNum( localVersionHandle, "versions", "Major version", NULL, 0 );

					GfLogTrace("%d.%d is ", locMajor, locMinor);

					if( locMajor != major || locMinor < minor)
					{
						GfLogTrace("obsolete (installed one is %d.%d) => updating ...\n",
								   major, minor);
						if ( gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, -1 ) )
							anyLocalChange = true;
					}
					else
					{
					    GfLogTrace("up-to-date");
						if (stat(absLocalLocation, &st))
						{
							GfLogTrace(", but not there => installing ...\n");
							if ( gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, -1 ) )
								anyLocalChange = true;
						}
						else
							GfLogTrace(".\n");
					}
					
					break;
				}
			} while( GfParmListSeekNext( localVersionHandle, "versions" ) == 0 );
		}

		if( !fileFound)
		{
			index = 0;
			while( isIndexUsed[index] )
				++index;
			GfLogTrace("not found => installing ...\n");
			if ( gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, index ) )
				anyLocalChange = true;
			isIndexUsed[index] = true;
		}

		free( dataLocation );
		free( localLocation );
		free( absDataLocation );
		free( absLocalLocation );

	} while( GfParmListSeekNext( dataVersionHandle, "versions" ) == 0 );

	// Write the user settings version.xml if changed.
	if (anyLocalChange)
		GfParmWriteFile( NULL, localVersionHandle, "versions" );

	GfParmReleaseHandle( localVersionHandle );
	GfParmReleaseHandle( dataVersionHandle );
	free( isIndexUsed );
	free( filename );
}