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