VFS: Add SetFilePermissions native
This commit is contained in:
		| @@ -1101,6 +1101,42 @@ static cell AMX_NATIVE_CALL GetFileTime(AMX *amx, cell *params) | ||||
| 	return static_cast<cell>(time_val); | ||||
| } | ||||
|  | ||||
| #define FPERM_U_READ       0x0100   /* User can read.    */ | ||||
| #define FPERM_U_WRITE      0x0080   /* User can write.   */ | ||||
| #define FPERM_U_EXEC       0x0040   /* User can exec.    */ | ||||
| #define FPERM_G_READ       0x0020   /* Group can read.   */ | ||||
| #define FPERM_G_WRITE      0x0010   /* Group can write.  */ | ||||
| #define FPERM_G_EXEC       0x0008   /* Group can exec.   */ | ||||
| #define FPERM_O_READ       0x0004   /* Anyone can read.  */ | ||||
| #define FPERM_O_WRITE      0x0002   /* Anyone can write. */ | ||||
| #define FPERM_O_EXEC       0x0001   /* Anyone can exec.  */ | ||||
|  | ||||
| // native bool:SetFilePermissions(const path[], int mode); | ||||
| static cell SetFilePermissions(AMX *amx, cell *params) | ||||
| { | ||||
| 	int length; | ||||
| 	const char* realpath = build_pathname(get_amxstring(amx, params[1], 0, length)); | ||||
|  | ||||
| #if defined PLATFORM_WINDOWS | ||||
|  | ||||
| 	int mask = 0; | ||||
|  | ||||
| 	if (params[2] & (FPERM_U_WRITE | FPERM_G_WRITE | FPERM_O_WRITE)) | ||||
| 	{ | ||||
| 		mask |= _S_IWRITE; | ||||
| 	} | ||||
|  | ||||
| 	if (params[2] & (FPERM_U_READ | FPERM_G_READ | FPERM_O_READ | FPERM_U_EXEC | FPERM_G_EXEC | FPERM_O_EXEC)) | ||||
| 	{ | ||||
| 		mask |= _S_IREAD; | ||||
| 	} | ||||
|  | ||||
| 	return _chmod(realpath, mask) == 0; | ||||
| #elif  | ||||
| 	return chmod(realpath, params[2]) == 0; | ||||
| #endif | ||||
| } | ||||
|  | ||||
| AMX_NATIVE_INFO file_Natives[] = | ||||
| { | ||||
| 	{"read_dir",		read_dir}, | ||||
| @@ -1147,6 +1183,8 @@ AMX_NATIVE_INFO file_Natives[] = | ||||
|  | ||||
| 	{"LoadFileForMe",	LoadFileForMe}, | ||||
| 	{"GetFileTime",		GetFileTime}, | ||||
| 	{"SetFilePermissions", SetFilePermissions}, | ||||
|  | ||||
| 	{NULL,				NULL} | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -59,7 +59,7 @@ enum FileTimeType | ||||
| #define BLOCK_BYTE  1 | ||||
|  | ||||
| /** | ||||
|  * File permissions flags for use with mkdir(). | ||||
|  * File permissions flags for use with mkdir() and SetFilePermissions(). | ||||
|  */ | ||||
| #define FPERM_U_READ       0x0100   /* User can read.    */ | ||||
| #define FPERM_U_WRITE      0x0080   /* User can write.   */ | ||||
| @@ -227,14 +227,14 @@ native file_size(const file[], flag = FSOPT_BYTES_COUNT, bool:use_valve_fs = fal | ||||
|  * | ||||
|  * @note Registered paths ID are (in priority order) : | ||||
|  *         GAME           All paths related to current mod, including fallback | ||||
|  *                        Depending settings, it includes: <gamedir>_lv/_addon/_<language>/_hd  | ||||
|  *                        Depending settings, it includes: <gamedir>_lv/_addon/_<language>/_hd | ||||
|  *                        and <gamedir> itself | ||||
|  *         GAMECONFIG     The default writable directory (<gamedir>) | ||||
|  *         GAMEDOWNLOAD   The download directory (<gamedir>_download) | ||||
|  *         GAME_FALLBACK  All paths related to fallback game, same as GAME | ||||
|  *         DEFAULTGAME    All paths related to the default game which is "valve", same as GAME | ||||
|  *         BASE           The base path where server is installed | ||||
|  *          | ||||
|  * | ||||
|  *         Note that some paths are non-writable. It includes all <gamedir>_* (expect _download) | ||||
|  *         and DEFAULTGAME. Any file inside a non-writable path will be ignored if you try to open | ||||
|  *         it in writing mode. | ||||
| @@ -556,3 +556,13 @@ native LoadFileForMe(const file[], buffer[], maxlength, &length = 0); | ||||
|  * @return              Returns a file timestamp as a unix timestamp | ||||
|  */ | ||||
| native GetFileTime(const file[], FileTimeType:tmode); | ||||
|  | ||||
| /** | ||||
|  * Changes a file or directories permissions. | ||||
|  * | ||||
|  * @param path          Path to the file | ||||
|  * @param mode          Permissions to set, see FPERM_* constants | ||||
|  * | ||||
|  * @return              True on success, false otherwise | ||||
|  */ | ||||
| native bool:SetFilePermissions(const path[], mode); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user