- added beefy new ReadMapList() native
- admin menu now uses ReadMapList() - added UTIL_TrimWhitespace() to stringutils - moved GetFileTime() implementation to ILibrarySys - cleaned up sorting include a bit - removed adminmenu_maplist.ini, since it's specified by maplists.cfg - added maplists.cfg --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401744
This commit is contained in:
+21
-93
@@ -82,109 +82,37 @@ public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
|
||||
return Plugin_Stop;
|
||||
}
|
||||
|
||||
new Handle:g_map_array = INVALID_HANDLE;
|
||||
new g_map_serial = -1;
|
||||
|
||||
LoadMapList(Handle:menu)
|
||||
{
|
||||
decl String:mapPath[256];
|
||||
BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/adminmenu_maplist.ini");
|
||||
new Handle:map_array;
|
||||
|
||||
if (!FileExists(mapPath))
|
||||
{
|
||||
if (g_MapList != INVALID_HANDLE)
|
||||
{
|
||||
RemoveAllMenuItems(menu);
|
||||
}
|
||||
|
||||
return LoadMapFolder(menu);
|
||||
}
|
||||
|
||||
// If the file hasn't changed, there's no reason to reload
|
||||
// all of the maps.
|
||||
new fileTime = GetFileTime(mapPath, FileTime_LastChange);
|
||||
if (g_mapFileTime == fileTime)
|
||||
if ((map_array = ReadMapList(g_map_array,
|
||||
g_map_serial,
|
||||
"admin menu",
|
||||
MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
|
||||
!= INVALID_HANDLE)
|
||||
{
|
||||
return GetMenuItemCount(menu);
|
||||
g_map_array = map_array;
|
||||
}
|
||||
|
||||
g_mapFileTime = fileTime;
|
||||
|
||||
// Reset the array
|
||||
if (g_MapList != INVALID_HANDLE)
|
||||
if (g_map_array == INVALID_HANDLE)
|
||||
{
|
||||
RemoveAllMenuItems(menu);
|
||||
}
|
||||
|
||||
new Handle:file = OpenFile(mapPath, "rt");
|
||||
if (file == INVALID_HANDLE)
|
||||
{
|
||||
LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
|
||||
return LoadMapFolder(menu);
|
||||
}
|
||||
|
||||
decl String:buffer[256], len;
|
||||
while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
|
||||
{
|
||||
TrimString(buffer);
|
||||
|
||||
if ((len = StrContains(buffer, ".bsp", false)) != -1)
|
||||
{
|
||||
buffer[len] = '\0';
|
||||
}
|
||||
|
||||
if (buffer[0] == '\0'
|
||||
|| buffer[0] == ';'
|
||||
|| buffer[0] == '/'
|
||||
|| !IsValidConVarChar(buffer[0]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (IsMapValid(buffer))
|
||||
{
|
||||
AddMenuItem(menu, buffer, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(file);
|
||||
|
||||
new count = GetMenuItemCount(menu);
|
||||
|
||||
if (!count)
|
||||
return LoadMapFolder(menu);
|
||||
else
|
||||
return count;
|
||||
}
|
||||
|
||||
LoadMapFolder(Handle:menu)
|
||||
{
|
||||
LogMessage("[SM] Loading menu map list from maps folder");
|
||||
|
||||
new Handle:mapDir = OpenDirectory("maps/");
|
||||
|
||||
if (mapDir == INVALID_HANDLE)
|
||||
{
|
||||
LogError("[SM] Could not open map directory for reading");
|
||||
return 0;
|
||||
}
|
||||
|
||||
new String:mapName[64];
|
||||
new String:buffer[64];
|
||||
new FileType:fileType;
|
||||
new len;
|
||||
RemoveAllMenuItems(menu);
|
||||
|
||||
while(ReadDirEntry(mapDir, mapName, sizeof(mapName), fileType))
|
||||
decl String:map_name[64];
|
||||
new map_count = GetArraySize(g_map_array);
|
||||
|
||||
for (new i = 0; i < map_count; i++)
|
||||
{
|
||||
if(fileType == FileType_File)
|
||||
{
|
||||
len = strlen(mapName);
|
||||
|
||||
if(SplitString(mapName, ".bsp", buffer, sizeof(buffer)) == len)
|
||||
{
|
||||
AddMenuItem(menu, buffer, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CloseHandle(mapDir);
|
||||
|
||||
return GetMenuItemCount(menu);
|
||||
GetArrayString(g_map_array, i, map_name, sizeof(map_name));
|
||||
AddMenuItem(menu, map_name, map_name);
|
||||
}
|
||||
|
||||
return map_count;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user