static void rmInitMovieCapture() { // Don't do it twice. if (rmMovieCapture.outputBase) return; // But do it the first time. char buf[256]; snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), RACE_ENG_CFG); void* hparmRaceEng = GfParmReadFile(buf, GFPARM_RMODE_REREAD | GFPARM_RMODE_CREAT); rmMovieCapture.enabled = strcmp(GfParmGetStr(hparmRaceEng, RM_SECT_MOVIE_CAPTURE, RM_ATT_CAPTURE_ENABLE, RM_VAL_NO), RM_VAL_NO) ? true : false; rmMovieCapture.active = false; if (!rmMovieCapture.enabled) { rmMovieCapture.outputBase = 0; GfLogInfo("Movie capture disabled (see raceengine.xml)\n"); } else { rmMovieCapture.frameRate = GfParmGetNum(hparmRaceEng, RM_SECT_MOVIE_CAPTURE, RM_ATT_CAPTURE_FPS, NULL, 25.0); rmMovieCapture.simuRate = 1.0 / RCM_MAX_DT_SIMU; char pszDefOutputBase[256]; snprintf(pszDefOutputBase, sizeof(pszDefOutputBase), "%s%s", GfLocalDir(), GfParmGetStr(hparmRaceEng, RM_SECT_MOVIE_CAPTURE, RM_ATT_CAPTURE_OUT_DIR, "captures")); rmMovieCapture.outputBase = strdup(pszDefOutputBase); GfDirCreate(pszDefOutputBase); // In case not already done. GfLogInfo("Movie capture enabled (%.0f FPS, PNG frames in %s)\n", rmMovieCapture.frameRate, rmMovieCapture.outputBase); } }
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 ); }