Index: apps/plugins/md5sum.c =================================================================== --- apps/plugins/md5sum.c (revision 18163) +++ apps/plugins/md5sum.c (working copy) @@ -21,9 +21,50 @@ #include "plugin.h" #include "lib/md5.h" +#include "pluginlib_actions.h" PLUGIN_HEADER +/*********************************************************************** + * Buttons + ***********************************************************************/ + +#if CONFIG_KEYPAD == IRIVER_H300_PAD +#define MD5SUM_QUIT BUTTON_OFF + +#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \ + (CONFIG_KEYPAD == IPOD_1G2G_PAD) +#define MD5SUM_QUIT ( ~BUTTON_MAIN ) + +#elif ( CONFIG_KEYPAD == IAUDIO_X5M5_PAD ) +#define MD5SUM_QUIT BUTTON_POWER + +#elif CONFIG_KEYPAD == GIGABEAT_PAD +#define MD5SUM_QUIT BUTTON_POWER + +#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ +(CONFIG_KEYPAD == SANSA_C200_PAD) +#define MD5SUM_QUIT BUTTON_POWER + +#elif ( CONFIG_KEYPAD == IRIVER_H10_PAD ) +#define MD5SUM_QUIT BUTTON_POWER + +#elif CONFIG_KEYPAD == GIGABEAT_S_PAD +#define MD5SUM_QUIT BUTTON_BACK + +#elif ( CONFIG_KEYPAD == COWOND2_PAD ) +#define MD5SUM_QUIT BUTTON_POWER + +#else +#error "Please define keys for this keypad" +#endif + +#ifdef HAVE_TOUCHPAD +#ifndef MD5SUM_QUIT +#define MD5SUM_QUIT BUTTON_TOPLEFT +#endif +#endif + static const struct plugin_api *rb; MEM_FUNCTION_WRAPPERS(rb); @@ -31,6 +72,14 @@ static int count = 0; static int done = 0; +static bool userquit( void ) +{ + static bool quit = false; + if (!quit && rb->button_get(false) == MD5SUM_QUIT) + quit = true; + return quit; +} + static int hash( char *string, const char *path ) { char *buffer[512]; @@ -40,13 +89,15 @@ if( in < 0 ) return -1; InitMD5( &md5 ); - while( ( len = rb->read( in, buffer, 512 ) ) > 0 ) + while( !userquit() && ( len = rb->read( in, buffer, 512 ) ) > 0 ) AddMD5( &md5, buffer, len ); EndMD5( &md5 ); psz_md5_hash( string, &md5 ); rb->close( in ); + if (userquit()) + return -1; return 0; } @@ -66,10 +117,11 @@ rb->write( out, " ", 2 ); rb->write( out, path, rb->strlen( path ) ); rb->write( out, "\n", 1 ); + + rb->yield(); } } -static void hash_dir( int out, const char *path ); static void hash_dir( int out, const char *path ) { DIR *dir; @@ -78,7 +130,7 @@ dir = rb->opendir( path ); if( dir ) { - while( ( entry = rb->readdir( dir ) ) ) + while( !userquit() && ( entry = rb->readdir( dir ) ) ) { char childpath[MAX_PATH]; rb->snprintf( childpath, MAX_PATH, "%s/%s", @@ -108,7 +160,7 @@ char newpath[MAX_PATH]; if( list < 0 ) return; - while( rb->read_line( list, newpath, MAX_PATH ) > 0 ) + while( !userquit() && rb->read_line( list, newpath, MAX_PATH ) > 0 ) { DIR *dir = rb->opendir( newpath ); if( dir ) @@ -132,7 +184,8 @@ int len; if( list < 0 ) return; - while( ( len = rb->read_line( list, line, MD5_STRING_LENGTH+1+MAX_PATH+1 ) ) > 0 ) + while( !userquit() + && ( len = rb->read_line( list, line, MD5_STRING_LENGTH+1+MAX_PATH+1 ) ) > 0 ) { if( out < 0 ) count++; @@ -236,7 +289,7 @@ done = 0; action( out, arg ); - out = rb->open( filename, O_WRONLY|O_CREAT ); + out = rb->open( filename, O_WRONLY|O_CREAT|O_TRUNC ); if( out < 0 ) return PLUGIN_ERROR; action( out, arg ); rb->close( out );