void CMultiplayRules::GetNextLevelName( char *pszNextMap, int bufsize, bool bRandom /* = false */ ) { const char *mapcfile = mapcyclefile.GetString(); Assert( mapcfile != NULL ); // Check the time of the mapcycle file and re-populate the list of level names if the file has been modified const int nMapCycleTimeStamp = filesystem->GetPathTime( mapcfile, "GAME" ); if ( 0 == nMapCycleTimeStamp ) { // Map cycle file does not exist, make a list containing only the current map char *szCurrentMapName = new char[32]; Q_strncpy( szCurrentMapName, STRING(gpGlobals->mapname), 32 ); m_MapList.AddToTail( szCurrentMapName ); } else { // If map cycle file has changed or this is the first time through ... if ( m_nMapCycleTimeStamp != nMapCycleTimeStamp ) { // Reset map index and map cycle timestamp m_nMapCycleTimeStamp = nMapCycleTimeStamp; m_nMapCycleindex = 0; // Clear out existing map list. Not using Purge() because I don't think that it will do a 'delete []' for ( int i = 0; i < m_MapList.Count(); i++ ) { delete [] m_MapList[i]; } m_MapList.RemoveAll(); // Repopulate map list from mapcycle file int nFileLength; char *aFileList = (char*)UTIL_LoadFileForMe( mapcfile, &nFileLength ); if ( aFileList && nFileLength ) { V_SplitString( aFileList, "\n", m_MapList ); for ( int i = 0; i < m_MapList.Count(); i++ ) { bool bIgnore = false; // Strip out the spaces in the name StripChar( m_MapList[i] , '\r'); StripChar( m_MapList[i] , ' '); if ( !engine->IsMapValid( m_MapList[i] ) ) { bIgnore = true; // If the engine doesn't consider it a valid map remove it from the lists char szWarningMessage[MAX_PATH]; V_snprintf( szWarningMessage, MAX_PATH, "Invalid map '%s' included in map cycle file. Ignored.\n", m_MapList[i] ); Warning( szWarningMessage ); } else if ( !Q_strncmp( m_MapList[i], "//", 2 ) ) { bIgnore = true; } if ( bIgnore ) { delete [] m_MapList[i]; m_MapList.Remove( i ); --i; } } UTIL_FreeFile( (byte *)aFileList ); } } } // If somehow we have no maps in the list then add the current one if ( 0 == m_MapList.Count() ) { char *szDefaultMapName = new char[32]; Q_strncpy( szDefaultMapName, STRING(gpGlobals->mapname), 32 ); m_MapList.AddToTail( szDefaultMapName ); } if ( bRandom ) { m_nMapCycleindex = RandomInt( 0, m_MapList.Count() - 1 ); } // Here's the return value Q_strncpy( pszNextMap, m_MapList[m_nMapCycleindex], bufsize); }
void CNB_Select_Level_Panel::UpdateLevelList() { const char *mapcfile = m_pMapListFile; // Check the time of the mapcycle file and re-populate the list of level names if the file has been modified const int nMapCycleTimeStamp = filesystem->GetPathTime( mapcfile, "GAME" ); char *szDefaultMapName = "sdk_teams_hdr"; if ( 0 == nMapCycleTimeStamp ) { // Map cycle file does not exist, make a list containing only the default map m_MapList.AddToTail( szDefaultMapName ); } else { // Clear out existing map list. Not using Purge() because I don't think that it will do a 'delete []' for ( int i = 0; i < m_MapList.Count(); i++ ) { delete [] m_MapList[i]; } m_MapList.RemoveAll(); // Repopulate map list from mapcycle file int nFileLength; char *aFileList = (char*)UTIL_LoadFileForMe( mapcfile, &nFileLength ); if ( aFileList && nFileLength ) { V_SplitString( aFileList, "\n", m_MapList ); for ( int i = 0; i < m_MapList.Count(); i++ ) { bool bIgnore = false; // Strip out the spaces in the name StripChar( m_MapList[i] , '\r'); StripChar( m_MapList[i] , ' '); /* if ( !engine->IsMapValid( m_MapList[i] ) ) { bIgnore = true; // If the engine doesn't consider it a valid map remove it from the lists char szWarningMessage[MAX_PATH]; V_snprintf( szWarningMessage, MAX_PATH, "Invalid map '%s' included in map cycle file. Ignored.\n", m_MapList[i] ); Warning( szWarningMessage ); } else */if ( !Q_strncmp( m_MapList[i], "//", 2 ) ) { bIgnore = true; } if ( bIgnore ) { delete [] m_MapList[i]; m_MapList.Remove( i ); --i; } } UTIL_FreeFile( (byte *)aFileList ); } // If somehow we have no maps in the list then add the default one if ( 0 == m_MapList.Count() ) { m_MapList.AddToTail( szDefaultMapName ); } // Now rebuild the level entry list //m_pHorizList->m_Entries.PurgeAndDeleteElements(); // Create entries for ( int i = 0; i < m_MapList.Count(); i++ ) { if ( m_pHorizList->m_Entries.Count() <= i ) { CNB_Select_Level_Entry *pEntry = new CNB_Select_Level_Entry( NULL, "Select_Level_Entry", m_MapList[i] ); m_pHorizList->AddEntry( pEntry ); } else { CNB_Select_Level_Entry *pEntry = dynamic_cast<CNB_Select_Level_Entry*>( m_pHorizList->m_Entries[i].Get() ); pEntry->SetMap( m_MapList[i] ); } } } }
void ScanGrub2::ScanConfigFile (char *dir, char *file_name) { bool scan_kernel_setup = false; bool added_to_menu = false; bool found = false; bool variables = false; FILE *pf; //int default_boot_number = 0; pf = fopen (file_name, "r"); if (!pf) { Log ("Couldn't open '%s'/'%s'", dir, file_name); ScanDirectory (dir); return; } else { Log ("Parsing '%s'/'%s'", dir, file_name); } MenuEntry menuEntry; menuEntry.Reset(); menuEntry.check_default_boot = true; while (fgets (cfg_line, sizeof (cfg_line), pf)) { RemoveUnneededChars (cfg_line, '#'); TabToSpace (cfg_line); StripChar (cfg_line, '{'); // dirty hack, use menuentry as start if (!variables && FindChar (cfg_line, '$')) { variables = true; } /* if ((strncasecmp (cfg_line, "set default", 11) == 0) && !FindChar (cfg_line, '$')) { GetValue(cfg_line); default_boot_number = atoi (cfg_line); continue; } */ if (strncasecmp (cfg_line, "menuentry ", 10) == 0) { if (variables) { Log ("Warning: Grub2 added menu entry '%s' with variable/s, they were removed.", cfg_line); variables = false; } // when a new label has been found then add the previous collected data to the menu if (!added_to_menu && found) { menu->AddEntry (menuEntry); menuEntry.Reset(); added_to_menu = true; found = false; } StripChar (cfg_line, '"'); menuEntry.SetMenuLabel (cfg_line + 10); scan_kernel_setup = true; } if (scan_kernel_setup) { //if (FindChar (cfg_line, '$')) // Log ("Grub2: Adding initrd/kernel args with variable '%s'", cfg_line); if (strncasecmp (cfg_line, "linux ", 6) == 0) { menuEntry.SetKernel (cfg_line + 6, dir); found = true; added_to_menu = false; char append[1024]; strncpy (append, cfg_line + 6, sizeof (append)); int start = Trim (append); int pos = FindChar (append + start, ' '); if (pos > -1) { menuEntry.SetAppend (append + start + pos); } } else if (strncasecmp (cfg_line, "initrd ", 7) == 0) { menuEntry.SetInitrd (cfg_line, dir); } } } if (!added_to_menu && found) { menu->AddEntry (menuEntry); } fclose (pf); }