forked from len0rd/rockbox
Print some more usefull info on screen. (Should be the last commit for this plugin)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17712 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
239c8054ae
commit
05a0b22de0
1 changed files with 84 additions and 61 deletions
|
@ -26,13 +26,15 @@ static const struct plugin_api *rb;
|
|||
|
||||
MEM_FUNCTION_WRAPPERS(rb);
|
||||
|
||||
int hash( char *string, const char *path )
|
||||
static int count = 0;
|
||||
static int done = 0;
|
||||
|
||||
static int hash( char *string, const char *path )
|
||||
{
|
||||
char *buffer[512];
|
||||
ssize_t len;
|
||||
struct md5_s md5;
|
||||
int in = rb->open( path, O_RDONLY );
|
||||
rb->splash( 0, path );
|
||||
if( in < 0 ) return -1;
|
||||
|
||||
InitMD5( &md5 );
|
||||
|
@ -46,9 +48,15 @@ int hash( char *string, const char *path )
|
|||
return 0;
|
||||
}
|
||||
|
||||
void hash_file( int out, const char *path )
|
||||
static void hash_file( int out, const char *path )
|
||||
{
|
||||
if( out < 0 )
|
||||
count++;
|
||||
else
|
||||
{
|
||||
char string[MD5_STRING_LENGTH+1];
|
||||
done++;
|
||||
rb->splash( 0, "%d / %d : %s", done, count, path );
|
||||
if( hash( string, path ) )
|
||||
rb->write( out, "error", 5 );
|
||||
else
|
||||
|
@ -56,10 +64,11 @@ void hash_file( int out, const char *path )
|
|||
rb->write( out, " ", 2 );
|
||||
rb->write( out, path, rb->strlen( path ) );
|
||||
rb->write( out, "\n", 1 );
|
||||
}
|
||||
}
|
||||
|
||||
void hash_dir( int out, const char *path );
|
||||
void hash_dir( int out, const char *path )
|
||||
static void hash_dir( int out, const char *path );
|
||||
static void hash_dir( int out, const char *path )
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
@ -91,7 +100,7 @@ void hash_dir( int out, const char *path )
|
|||
}
|
||||
}
|
||||
|
||||
void hash_list( int out, const char *path )
|
||||
static void hash_list( int out, const char *path )
|
||||
{
|
||||
int list = rb->open( path, O_RDONLY );
|
||||
char newpath[MAX_PATH];
|
||||
|
@ -114,7 +123,7 @@ void hash_list( int out, const char *path )
|
|||
rb->close( list );
|
||||
}
|
||||
|
||||
void hash_check( int out, const char *path )
|
||||
static void hash_check( int out, const char *path )
|
||||
{
|
||||
int list = rb->open( path, O_RDONLY );
|
||||
char line[MD5_STRING_LENGTH+1+MAX_PATH+1];
|
||||
|
@ -122,8 +131,14 @@ void hash_check( int out, const char *path )
|
|||
if( list < 0 ) return;
|
||||
|
||||
while( ( len = rb->read_line( list, line, MD5_STRING_LENGTH+1+MAX_PATH+1 ) ) > 0 )
|
||||
{
|
||||
if( out < 0 )
|
||||
count++;
|
||||
else
|
||||
{
|
||||
const char *filename = rb->strchr( line, ' ' );
|
||||
done++;
|
||||
rb->splash( 0, "%d / %d : %s", done, count, filename );
|
||||
if( !filename || len < MD5_STRING_LENGTH + 2 )
|
||||
{
|
||||
const char error[] = "Malformed input line ... skipping";
|
||||
|
@ -145,6 +160,9 @@ void hash_check( int out, const char *path )
|
|||
}
|
||||
rb->write( out, "\n", 1 );
|
||||
}
|
||||
}
|
||||
|
||||
rb->close( list );
|
||||
}
|
||||
|
||||
enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
|
||||
|
@ -153,6 +171,8 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame
|
|||
int out = -1; /* output file descriptor */
|
||||
char filename[MAX_PATH]; /* output file name */
|
||||
|
||||
void (*action)( int, const char * ) = NULL;
|
||||
|
||||
md5_init( api );
|
||||
rb = api;
|
||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||
|
@ -164,56 +184,59 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame
|
|||
const char *ext = rb->strrchr( arg, '.' );
|
||||
DIR *dir;
|
||||
rb->snprintf( filename, MAX_PATH, "%s.md5sum", arg );
|
||||
out = rb->open( filename, O_WRONLY|O_CREAT );
|
||||
if( out < 0 )
|
||||
{
|
||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||
rb->cpu_boost( false );
|
||||
#endif
|
||||
return PLUGIN_ERROR;
|
||||
}
|
||||
|
||||
if( ext )
|
||||
{
|
||||
if( !rb->strcmp( ext, ".md5" ) || !rb->strcmp( ext, ".md5sum" ) )
|
||||
{
|
||||
rb->snprintf( filename + ( ext - arg ),
|
||||
MAX_PATH + rb->strlen( ext ) - rb->strlen( arg ),
|
||||
".md5check" );
|
||||
/* Lets check the sums */
|
||||
hash_check( out, arg );
|
||||
goto exit;
|
||||
action = hash_check;
|
||||
}
|
||||
else if( !rb->strcmp( ext, ".md5list" ) ) /* ugly */
|
||||
{
|
||||
/* Hash listed files */
|
||||
hash_list( out, arg );
|
||||
goto exit;
|
||||
action = hash_list;
|
||||
}
|
||||
}
|
||||
|
||||
if( !action )
|
||||
{
|
||||
dir = rb->opendir( arg );
|
||||
if( dir )
|
||||
{
|
||||
api->closedir( dir );
|
||||
|
||||
/* Hash the directory's content recursively */
|
||||
hash_dir( out, arg );
|
||||
action = hash_dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Hash the file */
|
||||
hash_file( out, arg );
|
||||
action = hash_file;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rb->snprintf( filename, MAX_PATH, "/everything.md5sum" );
|
||||
out = rb->open( filename, O_WRONLY|O_CREAT );
|
||||
if( out < 0 ) return PLUGIN_ERROR;
|
||||
|
||||
/* Hash the whole filesystem */
|
||||
hash_dir( out, "/" );
|
||||
action = hash_dir;
|
||||
arg = "/";
|
||||
}
|
||||
|
||||
exit:
|
||||
rb->lcd_puts( 0, 1, "Output file:" );
|
||||
rb->lcd_puts( 0, 2, filename );
|
||||
|
||||
count = 0;
|
||||
done = 0;
|
||||
action( out, arg );
|
||||
|
||||
out = rb->open( filename, O_WRONLY|O_CREAT );
|
||||
if( out < 0 ) return PLUGIN_ERROR;
|
||||
action( out, arg );
|
||||
rb->close( out );
|
||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||
rb->cpu_boost( false );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue