Menu map lists (map and votemap) now fall back to the contents of maps folder if the menu_maplist.ini isn't found

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401586
This commit is contained in:
Matt Woodrow 2007-10-15 21:12:52 +00:00
parent 7f667a58d0
commit 0600be8c3a
3 changed files with 94 additions and 15 deletions

View File

@ -2,4 +2,5 @@
//
// List maps here to be added to the map and votemap sections of the admin menu
//
// Leave this file empty, or delete it, to use the contents of your /maps/ folder

View File

@ -88,15 +88,13 @@ LoadMaps(Handle:menu)
BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/menu_maplist.ini");
if (!FileExists(mapPath))
{
LogError("Unable to locate menu_maplist, no maps loaded.");
{
if (g_MapList != INVALID_HANDLE)
{
RemoveAllMenuItems(menu);
}
return;
return LoadMapFolder(menu);
}
// If the file hasn't changed, there's no reason to reload
@ -104,7 +102,7 @@ LoadMaps(Handle:menu)
new fileTime = GetFileTime(mapPath, FileTime_LastChange);
if (g_mapFileTime == fileTime)
{
return;
return GetMenuItemCount(menu);
}
g_mapFileTime = fileTime;
@ -120,8 +118,8 @@ LoadMaps(Handle:menu)
new Handle:file = OpenFile(mapPath, "rt");
if (file == INVALID_HANDLE)
{
LogError("[SM] Could not open file: %s", mapPath);
return;
LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
return LoadMapFolder(menu);
}
decl String:buffer[64], len;
@ -143,5 +141,46 @@ LoadMaps(Handle:menu)
}
CloseHandle(file);
return;
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;
while(ReadDirEntry(mapDir, mapName, sizeof(mapName), fileType))
{
if(fileType == FileType_File)
{
len = strlen(mapName);
if(SplitString(mapName, ".bsp", buffer, sizeof(buffer)) == len)
{
AddMenuItem(menu, buffer, buffer);
}
}
}
CloseHandle(mapDir);
return GetMenuItemCount(menu);
}

View File

@ -203,15 +203,13 @@ LoadMaps(Handle:menu)
BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/menu_maplist.ini");
if (!FileExists(mapPath))
{
LogError("Unable to locate menu_maplist, no maps loaded.");
{
if (g_MapList != INVALID_HANDLE)
{
RemoveAllMenuItems(menu);
}
return 0;
return LoadMapFolder(menu);
}
// If the file hasn't changed, there's no reason to reload
@ -235,8 +233,8 @@ LoadMaps(Handle:menu)
new Handle:file = OpenFile(mapPath, "rt");
if (file == INVALID_HANDLE)
{
LogError("[SM] Could not open file: %s", mapPath);
return 0;
LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
return LoadMapFolder(menu);
}
decl String:buffer[64], len;
@ -258,5 +256,46 @@ LoadMaps(Handle:menu)
}
CloseHandle(file);
return GetMenuItemCount(menu);
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;
while(ReadDirEntry(mapDir, mapName, sizeof(mapName), fileType))
{
if(fileType == FileType_File)
{
len = strlen(mapName);
if(SplitString(mapName, ".bsp", buffer, sizeof(buffer)) == len)
{
AddMenuItem(menu, buffer, buffer);
}
}
}
CloseHandle(mapDir);
return GetMenuItemCount(menu);
}