amx_copy <source file> <destination file>
amx_copy "plugins.ini" "plugins_ini_backup.ini"
PHP Code:
#include <amxmodx>
#include <amxmisc>
new const Version[] = "0.1";
enum ReturnVals
{
FILE_COPY_SUCCESSFUL,
ERROR_FILE_DOES_NOT_EXIST,
ERROR_OPENING_SOURCE,
ERROR_CREATING_DEST,
ERROR_ARGS
}
public plugin_init()
{
register_plugin( "Copy Config Dir File" , Version , "bugsy" );
register_concmd( "amx_copy" , "CopyFileCmd" );
}
public CopyFileCmd( id )
{
if ( ( get_user_flags( id ) & ADMIN_RCON ) )
{
switch ( CopyFile( id ) )
{
case FILE_COPY_SUCCESSFUL: console_print( id , "* File copy successful" );
case ERROR_FILE_DOES_NOT_EXIST: console_print( id , "* The source file does not exist in your configs directory." );
case ERROR_OPENING_SOURCE: console_print( id , "* There was an error opening the source file." );
case ERROR_CREATING_DEST: console_print( id , "* There was an error creating the destination file." );
case ERROR_ARGS: console_print( id , "* Must use command as follows: amx_copy [source filename] [destination filename]" );
}
}
}
public ReturnVals:CopyFile( id )
{
new szSource[ 64 ] , szDest[ 64 ] , iDirLen , ReturnVals:rvResult , iSource , iDest , iBytesRead , FileBuffer[ 1024 ];
iDirLen = get_configsdir( szSource , charsmax( szSource ) );
copy( szDest , charsmax( szDest ) , szSource );
szSource[ iDirLen ] = '/';
szDest[ iDirLen ] = '/';
iDirLen++;
if ( !read_argv( 1 , szSource[ iDirLen ] , charsmax( szSource ) - iDirLen ) || !read_argv( 2 , szDest[ iDirLen ] , charsmax( szDest ) - iDirLen ) )
{
rvResult = ERROR_ARGS;
}
else
{
if ( file_exists( szSource ) )
{
if ( ( iSource = fopen( szSource , "rb" ) ) )
{
if ( ( iDest = fopen( szDest , "wb" ) ) )
{
while( ( iBytesRead = fread_blocks( iSource , FileBuffer , sizeof( FileBuffer ) , BLOCK_BYTE ) ) )
{
fwrite_blocks( iDest , FileBuffer , iBytesRead , BLOCK_BYTE );
}
fclose( iSource );
fclose( iDest );
}
else
{
fclose( iSource );
rvResult = ERROR_CREATING_DEST;
}
}
else
{
rvResult = ERROR_OPENING_SOURCE;
}
}
else
{
rvResult = ERROR_FILE_DOES_NOT_EXIST;
}
}
return rvResult;
}
__________________