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:
parent
7f667a58d0
commit
0600be8c3a
@ -2,4 +2,5 @@
|
|||||||
//
|
//
|
||||||
// List maps here to be added to the map and votemap sections of the admin menu
|
// 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
|
||||||
|
|
||||||
|
@ -89,14 +89,12 @@ LoadMaps(Handle:menu)
|
|||||||
|
|
||||||
if (!FileExists(mapPath))
|
if (!FileExists(mapPath))
|
||||||
{
|
{
|
||||||
LogError("Unable to locate menu_maplist, no maps loaded.");
|
|
||||||
|
|
||||||
if (g_MapList != INVALID_HANDLE)
|
if (g_MapList != INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
RemoveAllMenuItems(menu);
|
RemoveAllMenuItems(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return LoadMapFolder(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file hasn't changed, there's no reason to reload
|
// 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);
|
new fileTime = GetFileTime(mapPath, FileTime_LastChange);
|
||||||
if (g_mapFileTime == fileTime)
|
if (g_mapFileTime == fileTime)
|
||||||
{
|
{
|
||||||
return;
|
return GetMenuItemCount(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mapFileTime = fileTime;
|
g_mapFileTime = fileTime;
|
||||||
@ -120,8 +118,8 @@ LoadMaps(Handle:menu)
|
|||||||
new Handle:file = OpenFile(mapPath, "rt");
|
new Handle:file = OpenFile(mapPath, "rt");
|
||||||
if (file == INVALID_HANDLE)
|
if (file == INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
LogError("[SM] Could not open file: %s", mapPath);
|
LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
|
||||||
return;
|
return LoadMapFolder(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
decl String:buffer[64], len;
|
decl String:buffer[64], len;
|
||||||
@ -143,5 +141,46 @@ LoadMaps(Handle:menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(file);
|
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);
|
||||||
}
|
}
|
@ -204,14 +204,12 @@ LoadMaps(Handle:menu)
|
|||||||
|
|
||||||
if (!FileExists(mapPath))
|
if (!FileExists(mapPath))
|
||||||
{
|
{
|
||||||
LogError("Unable to locate menu_maplist, no maps loaded.");
|
|
||||||
|
|
||||||
if (g_MapList != INVALID_HANDLE)
|
if (g_MapList != INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
RemoveAllMenuItems(menu);
|
RemoveAllMenuItems(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return LoadMapFolder(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the file hasn't changed, there's no reason to reload
|
// 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");
|
new Handle:file = OpenFile(mapPath, "rt");
|
||||||
if (file == INVALID_HANDLE)
|
if (file == INVALID_HANDLE)
|
||||||
{
|
{
|
||||||
LogError("[SM] Could not open file: %s", mapPath);
|
LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
|
||||||
return 0;
|
return LoadMapFolder(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
decl String:buffer[64], len;
|
decl String:buffer[64], len;
|
||||||
@ -258,5 +256,46 @@ LoadMaps(Handle:menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(file);
|
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;
|
||||||
|
|
||||||
|
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);
|
return GetMenuItemCount(menu);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user