If you want to use this native on big files it is a possiblity that it will block the HLDS server! So watch out!
I will also add the copy folder stocks after I will finish with block wallhack.
Code: Select all
#define BUFFERSIZE 256
enum FWrite
{
FW_NONE = 0,
FW_DELETESOURCE = (1<<0),
FW_CANOVERRIDE = (1<<1)
}
stock fcopy(read_path[300], dest_path[300], FWrite:flags = FW_NONE)
{
// Prepare for read
new fp_read = fopen(read_path, "rb")
// No file to read, errors!
if (!fp_read)
{
fclose(fp_read)
return 0
}
// If the native cannot override
if (file_exists(dest_path) && !(flags & FW_CANOVERRIDE))
{
return 0
}
// Prepare for write
new fp_write = fopen(dest_path, "wb")
// Used for copying
static buffer[BUFFERSIZE]
static readsize
// Find the size of the files
fseek(fp_read, 0, SEEK_END);
new fsize = ftell(fp_read);
fseek(fp_read, 0, SEEK_SET);
// Here we copy the info
for (new j = 0; j < fsize; j += BUFFERSIZE)
{
readsize = fread_blocks(fp_read, buffer, BUFFERSIZE, BLOCK_CHAR);
fwrite_blocks(fp_write, buffer, readsize, BLOCK_CHAR);
}
// Close the files
fclose(fp_read)
fclose(fp_write)
// Can delete source?
if (flags & FW_DELETESOURCE)
delete_file(read_path)
// Success
return 1
} 