diff options
author | Antoine Cellerier <dionoea@videolan.org> | 2008-06-10 16:24:25 +0000 |
---|---|---|
committer | Antoine Cellerier <dionoea@videolan.org> | 2008-06-10 16:24:25 +0000 |
commit | 05a0b22de0a1c5975b6be7fef5b2f3b850787b6c (patch) | |
tree | 3c9c86cf35abe66c5d0668c854e1dac79b10420b | |
parent | 239c8054ae955dac891ac1a5a9de1844bfbdfdc1 (diff) | |
download | rockbox-05a0b22de0a1c5975b6be7fef5b2f3b850787b6c.tar.gz rockbox-05a0b22de0a1c5975b6be7fef5b2f3b850787b6c.zip |
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
-rw-r--r-- | apps/plugins/md5sum.c | 145 |
1 files changed, 84 insertions, 61 deletions
diff --git a/apps/plugins/md5sum.c b/apps/plugins/md5sum.c index e5149a641e..65cc0c0a5e 100644 --- a/apps/plugins/md5sum.c +++ b/apps/plugins/md5sum.c | |||
@@ -26,13 +26,15 @@ static const struct plugin_api *rb; | |||
26 | 26 | ||
27 | MEM_FUNCTION_WRAPPERS(rb); | 27 | MEM_FUNCTION_WRAPPERS(rb); |
28 | 28 | ||
29 | int hash( char *string, const char *path ) | 29 | static int count = 0; |
30 | static int done = 0; | ||
31 | |||
32 | static int hash( char *string, const char *path ) | ||
30 | { | 33 | { |
31 | char *buffer[512]; | 34 | char *buffer[512]; |
32 | ssize_t len; | 35 | ssize_t len; |
33 | struct md5_s md5; | 36 | struct md5_s md5; |
34 | int in = rb->open( path, O_RDONLY ); | 37 | int in = rb->open( path, O_RDONLY ); |
35 | rb->splash( 0, path ); | ||
36 | if( in < 0 ) return -1; | 38 | if( in < 0 ) return -1; |
37 | 39 | ||
38 | InitMD5( &md5 ); | 40 | InitMD5( &md5 ); |
@@ -46,20 +48,27 @@ int hash( char *string, const char *path ) | |||
46 | return 0; | 48 | return 0; |
47 | } | 49 | } |
48 | 50 | ||
49 | void hash_file( int out, const char *path ) | 51 | static void hash_file( int out, const char *path ) |
50 | { | 52 | { |
51 | char string[MD5_STRING_LENGTH+1]; | 53 | if( out < 0 ) |
52 | if( hash( string, path ) ) | 54 | count++; |
53 | rb->write( out, "error", 5 ); | ||
54 | else | 55 | else |
55 | rb->write( out, string, MD5_STRING_LENGTH ); | 56 | { |
56 | rb->write( out, " ", 2 ); | 57 | char string[MD5_STRING_LENGTH+1]; |
57 | rb->write( out, path, rb->strlen( path ) ); | 58 | done++; |
58 | rb->write( out, "\n", 1 ); | 59 | rb->splash( 0, "%d / %d : %s", done, count, path ); |
60 | if( hash( string, path ) ) | ||
61 | rb->write( out, "error", 5 ); | ||
62 | else | ||
63 | rb->write( out, string, MD5_STRING_LENGTH ); | ||
64 | rb->write( out, " ", 2 ); | ||
65 | rb->write( out, path, rb->strlen( path ) ); | ||
66 | rb->write( out, "\n", 1 ); | ||
67 | } | ||
59 | } | 68 | } |
60 | 69 | ||
61 | void hash_dir( int out, const char *path ); | 70 | static void hash_dir( int out, const char *path ); |
62 | void hash_dir( int out, const char *path ) | 71 | static void hash_dir( int out, const char *path ) |
63 | { | 72 | { |
64 | DIR *dir; | 73 | DIR *dir; |
65 | struct dirent *entry; | 74 | struct dirent *entry; |
@@ -91,7 +100,7 @@ void hash_dir( int out, const char *path ) | |||
91 | } | 100 | } |
92 | } | 101 | } |
93 | 102 | ||
94 | void hash_list( int out, const char *path ) | 103 | static void hash_list( int out, const char *path ) |
95 | { | 104 | { |
96 | int list = rb->open( path, O_RDONLY ); | 105 | int list = rb->open( path, O_RDONLY ); |
97 | char newpath[MAX_PATH]; | 106 | char newpath[MAX_PATH]; |
@@ -114,7 +123,7 @@ void hash_list( int out, const char *path ) | |||
114 | rb->close( list ); | 123 | rb->close( list ); |
115 | } | 124 | } |
116 | 125 | ||
117 | void hash_check( int out, const char *path ) | 126 | static void hash_check( int out, const char *path ) |
118 | { | 127 | { |
119 | int list = rb->open( path, O_RDONLY ); | 128 | int list = rb->open( path, O_RDONLY ); |
120 | char line[MD5_STRING_LENGTH+1+MAX_PATH+1]; | 129 | char line[MD5_STRING_LENGTH+1+MAX_PATH+1]; |
@@ -123,28 +132,37 @@ void hash_check( int out, const char *path ) | |||
123 | 132 | ||
124 | while( ( len = rb->read_line( list, line, MD5_STRING_LENGTH+1+MAX_PATH+1 ) ) > 0 ) | 133 | while( ( len = rb->read_line( list, line, MD5_STRING_LENGTH+1+MAX_PATH+1 ) ) > 0 ) |
125 | { | 134 | { |
126 | const char *filename = rb->strchr( line, ' ' ); | 135 | if( out < 0 ) |
127 | if( !filename || len < MD5_STRING_LENGTH + 2 ) | 136 | count++; |
128 | { | ||
129 | const char error[] = "Malformed input line ... skipping"; | ||
130 | rb->write( out, error, rb->strlen( error ) ); | ||
131 | } | ||
132 | else | 137 | else |
133 | { | 138 | { |
134 | char string[MD5_STRING_LENGTH+1]; | 139 | const char *filename = rb->strchr( line, ' ' ); |
135 | while( *filename == ' ' ) | 140 | done++; |
136 | filename++; | 141 | rb->splash( 0, "%d / %d : %s", done, count, filename ); |
137 | rb->write( out, filename, rb->strlen( filename ) ); | 142 | if( !filename || len < MD5_STRING_LENGTH + 2 ) |
138 | rb->write( out, ": ", 2 ); | 143 | { |
139 | if( hash( string, filename ) ) | 144 | const char error[] = "Malformed input line ... skipping"; |
140 | rb->write( out, "FAILED open or read", 19 ); | 145 | rb->write( out, error, rb->strlen( error ) ); |
141 | else if( rb->strncasecmp( line, string, MD5_STRING_LENGTH ) ) | 146 | } |
142 | rb->write( out, "FAILED", 6 ); | ||
143 | else | 147 | else |
144 | rb->write( out, "OK", 2 ); | 148 | { |
149 | char string[MD5_STRING_LENGTH+1]; | ||
150 | while( *filename == ' ' ) | ||
151 | filename++; | ||
152 | rb->write( out, filename, rb->strlen( filename ) ); | ||
153 | rb->write( out, ": ", 2 ); | ||
154 | if( hash( string, filename ) ) | ||
155 | rb->write( out, "FAILED open or read", 19 ); | ||
156 | else if( rb->strncasecmp( line, string, MD5_STRING_LENGTH ) ) | ||
157 | rb->write( out, "FAILED", 6 ); | ||
158 | else | ||
159 | rb->write( out, "OK", 2 ); | ||
160 | } | ||
161 | rb->write( out, "\n", 1 ); | ||
145 | } | 162 | } |
146 | rb->write( out, "\n", 1 ); | ||
147 | } | 163 | } |
164 | |||
165 | rb->close( list ); | ||
148 | } | 166 | } |
149 | 167 | ||
150 | enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) | 168 | 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 | |||
153 | int out = -1; /* output file descriptor */ | 171 | int out = -1; /* output file descriptor */ |
154 | char filename[MAX_PATH]; /* output file name */ | 172 | char filename[MAX_PATH]; /* output file name */ |
155 | 173 | ||
174 | void (*action)( int, const char * ) = NULL; | ||
175 | |||
156 | md5_init( api ); | 176 | md5_init( api ); |
157 | rb = api; | 177 | rb = api; |
158 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 178 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
@@ -164,59 +184,62 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* parame | |||
164 | const char *ext = rb->strrchr( arg, '.' ); | 184 | const char *ext = rb->strrchr( arg, '.' ); |
165 | DIR *dir; | 185 | DIR *dir; |
166 | rb->snprintf( filename, MAX_PATH, "%s.md5sum", arg ); | 186 | rb->snprintf( filename, MAX_PATH, "%s.md5sum", arg ); |
167 | out = rb->open( filename, O_WRONLY|O_CREAT ); | ||
168 | if( out < 0 ) | ||
169 | { | ||
170 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
171 | rb->cpu_boost( false ); | ||
172 | #endif | ||
173 | return PLUGIN_ERROR; | ||
174 | } | ||
175 | 187 | ||
176 | if( ext ) | 188 | if( ext ) |
177 | { | 189 | { |
178 | if( !rb->strcmp( ext, ".md5" ) || !rb->strcmp( ext, ".md5sum" ) ) | 190 | if( !rb->strcmp( ext, ".md5" ) || !rb->strcmp( ext, ".md5sum" ) ) |
179 | { | 191 | { |
192 | rb->snprintf( filename + ( ext - arg ), | ||
193 | MAX_PATH + rb->strlen( ext ) - rb->strlen( arg ), | ||
194 | ".md5check" ); | ||
180 | /* Lets check the sums */ | 195 | /* Lets check the sums */ |
181 | hash_check( out, arg ); | 196 | action = hash_check; |
182 | goto exit; | ||
183 | } | 197 | } |
184 | else if( !rb->strcmp( ext, ".md5list" ) ) /* ugly */ | 198 | else if( !rb->strcmp( ext, ".md5list" ) ) /* ugly */ |
185 | { | 199 | { |
186 | /* Hash listed files */ | 200 | /* Hash listed files */ |
187 | hash_list( out, arg ); | 201 | action = hash_list; |
188 | goto exit; | ||
189 | } | 202 | } |
190 | } | 203 | } |
191 | 204 | ||
192 | dir = rb->opendir( arg ); | 205 | if( !action ) |
193 | if( dir ) | ||
194 | { | 206 | { |
195 | api->closedir( dir ); | 207 | dir = rb->opendir( arg ); |
208 | if( dir ) | ||
209 | { | ||
210 | api->closedir( dir ); | ||
196 | 211 | ||
197 | /* Hash the directory's content recursively */ | 212 | /* Hash the directory's content recursively */ |
198 | hash_dir( out, arg ); | 213 | action = hash_dir; |
199 | } | 214 | } |
200 | else | 215 | else |
201 | { | 216 | { |
202 | /* Hash the file */ | 217 | /* Hash the file */ |
203 | hash_file( out, arg ); | 218 | action = hash_file; |
219 | } | ||
204 | } | 220 | } |
205 | } | 221 | } |
206 | else | 222 | else |
207 | { | 223 | { |
208 | rb->snprintf( filename, MAX_PATH, "/everything.md5sum" ); | 224 | rb->snprintf( filename, MAX_PATH, "/everything.md5sum" ); |
209 | out = rb->open( filename, O_WRONLY|O_CREAT ); | ||
210 | if( out < 0 ) return PLUGIN_ERROR; | ||
211 | |||
212 | /* Hash the whole filesystem */ | 225 | /* Hash the whole filesystem */ |
213 | hash_dir( out, "/" ); | 226 | action = hash_dir; |
227 | arg = "/"; | ||
214 | } | 228 | } |
215 | 229 | ||
216 | exit: | 230 | rb->lcd_puts( 0, 1, "Output file:" ); |
217 | rb->close( out ); | 231 | rb->lcd_puts( 0, 2, filename ); |
232 | |||
233 | count = 0; | ||
234 | done = 0; | ||
235 | action( out, arg ); | ||
236 | |||
237 | out = rb->open( filename, O_WRONLY|O_CREAT ); | ||
238 | if( out < 0 ) return PLUGIN_ERROR; | ||
239 | action( out, arg ); | ||
240 | rb->close( out ); | ||
218 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 241 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
219 | rb->cpu_boost( false ); | 242 | rb->cpu_boost( false ); |
220 | #endif | 243 | #endif |
221 | return PLUGIN_OK; | 244 | return PLUGIN_OK; |
222 | } | 245 | } |