plugins/basecommands/map.sp
changeset 1738 cb3be0b31d99
parent 1658 2a449596c3a8
child 1740 e5f6bd502cb7
     1.1 --- a/plugins/basecommands/map.sp	Sun Dec 02 02:05:55 2007 +0000
     1.2 +++ b/plugins/basecommands/map.sp	Sun Dec 02 02:10:37 2007 +0000
     1.3 @@ -82,109 +82,37 @@
     1.4  	return Plugin_Stop;
     1.5  }
     1.6  
     1.7 +new Handle:g_map_array = INVALID_HANDLE;
     1.8 +new g_map_serial = -1;
     1.9 +
    1.10  LoadMapList(Handle:menu)
    1.11  {
    1.12 -	decl String:mapPath[256];
    1.13 -	BuildPath(Path_SM, mapPath, sizeof(mapPath), "configs/adminmenu_maplist.ini");
    1.14 +	new Handle:map_array;
    1.15  	
    1.16 -	if (!FileExists(mapPath))
    1.17 -	{	
    1.18 -		if (g_MapList != INVALID_HANDLE)
    1.19 -		{
    1.20 -			RemoveAllMenuItems(menu);
    1.21 -		}
    1.22 -		
    1.23 -		return LoadMapFolder(menu);		
    1.24 -	}
    1.25 -
    1.26 -	// If the file hasn't changed, there's no reason to reload
    1.27 -	// all of the maps.
    1.28 -	new fileTime =  GetFileTime(mapPath, FileTime_LastChange);
    1.29 -	if (g_mapFileTime == fileTime)
    1.30 +	if ((map_array = ReadMapList(g_map_array,
    1.31 +			g_map_serial,
    1.32 +			"admin menu",
    1.33 +			MAPLIST_FLAG_CLEARARRAY|MAPLIST_FLAG_NO_DEFAULT|MAPLIST_FLAG_MAPSFOLDER))
    1.34 +		!= INVALID_HANDLE)
    1.35  	{
    1.36 -		return GetMenuItemCount(menu);
    1.37 -	}
    1.38 -	
    1.39 -	g_mapFileTime = fileTime;
    1.40 -	
    1.41 -	// Reset the array
    1.42 -	if (g_MapList != INVALID_HANDLE)
    1.43 -	{
    1.44 -		RemoveAllMenuItems(menu);
    1.45 -	}
    1.46 -
    1.47 -	new Handle:file = OpenFile(mapPath, "rt");
    1.48 -	if (file == INVALID_HANDLE)
    1.49 -	{
    1.50 -		LogError("[SM] Could not open file: %s, reverting to map folder", mapPath);
    1.51 -		return LoadMapFolder(menu);
    1.52 +		g_map_array = map_array;
    1.53  	}
    1.54  	
    1.55 -	decl String:buffer[256], len;
    1.56 -	while (!IsEndOfFile(file) && ReadFileLine(file, buffer, sizeof(buffer)))
    1.57 +	if (g_map_array == INVALID_HANDLE)
    1.58  	{
    1.59 -		TrimString(buffer);
    1.60 -		
    1.61 -		if ((len = StrContains(buffer, ".bsp", false)) != -1)
    1.62 -		{
    1.63 -			buffer[len] = '\0';
    1.64 -		}
    1.65 -
    1.66 -		if (buffer[0] == '\0' 
    1.67 -			|| buffer[0] == ';'
    1.68 -			|| buffer[0] == '/'
    1.69 -			|| !IsValidConVarChar(buffer[0]))
    1.70 -		{
    1.71 -			continue;
    1.72 -		}
    1.73 -		
    1.74 -		if (IsMapValid(buffer))
    1.75 -		{
    1.76 -			AddMenuItem(menu, buffer, buffer);
    1.77 -		}
    1.78 -	}
    1.79 -
    1.80 -	CloseHandle(file);
    1.81 -	
    1.82 -	new count = GetMenuItemCount(menu);
    1.83 -	
    1.84 -	if (!count)
    1.85 -		return LoadMapFolder(menu);
    1.86 -	else
    1.87 -		return count;
    1.88 -}
    1.89 -
    1.90 -LoadMapFolder(Handle:menu)
    1.91 -{
    1.92 -	LogMessage("[SM] Loading menu map list from maps folder");
    1.93 -	
    1.94 -	new Handle:mapDir = OpenDirectory("maps/");
    1.95 -	
    1.96 -	if (mapDir == INVALID_HANDLE)
    1.97 -	{
    1.98 -		LogError("[SM] Could not open map directory for reading");
    1.99  		return 0;
   1.100  	}
   1.101  	
   1.102 -	new String:mapName[64];
   1.103 -	new String:buffer[64];
   1.104 -	new FileType:fileType;
   1.105 -	new len;
   1.106 +	RemoveAllMenuItems(menu);
   1.107  	
   1.108 -	while(ReadDirEntry(mapDir, mapName, sizeof(mapName), fileType))
   1.109 +	decl String:map_name[64];
   1.110 +	new map_count = GetArraySize(g_map_array);
   1.111 +	
   1.112 +	for (new i = 0; i < map_count; i++)
   1.113  	{
   1.114 -		if(fileType == FileType_File)
   1.115 -		{
   1.116 -			len = strlen(mapName);
   1.117 -
   1.118 -			if(SplitString(mapName, ".bsp", buffer, sizeof(buffer)) == len)
   1.119 -			{
   1.120 -				AddMenuItem(menu, buffer, buffer);
   1.121 -			}
   1.122 -		}
   1.123 -  	}
   1.124 -  	
   1.125 -  	CloseHandle(mapDir);
   1.126 -  	
   1.127 -  	return GetMenuItemCount(menu);
   1.128 +		GetArrayString(g_map_array, i, map_name, sizeof(map_name));
   1.129 +		AddMenuItem(menu, map_name, map_name);
   1.130 +	}
   1.131 +	
   1.132 +	return map_count;
   1.133  }