···40404141static struct multiple_tracks_id3 mul_id3;
42424343+static const int32_t units[] =
4444+{
4545+ LANG_BYTE,
4646+ LANG_KIBIBYTE,
4747+ LANG_MEBIBYTE,
4848+ LANG_GIBIBYTE
4949+};
43504451/* Calculate modified FNV hash of string
4552 * has good avalanche behaviour and uniform distribution
···130137 mul_id3.filesize += id3->filesize;
131138}
132139133133-/* (!) Note scale factor applied to returned metadata:
134134- * - Unit for filesize will be KiB instead of Bytes
135135- * - Unit for length will be s instead of ms
140140+/* (!) Note unit conversion below
136141 *
137142 * Use result only as input for browse_id3,
138143 * with the track_ct parameter set to > 1.
···159164 id3->track_string = NULL;
160165 id3->year_string = NULL;
161166 id3->year = mul_id3.year;
162162- mul_id3.length /= 1000;
163163- mul_id3.filesize >>= 10;
167167+ mul_id3.length /= 1000; /* convert from ms to s */
168168+ mul_id3.filesize >>= 10; /* convert from B to KiB */
164169 id3->length = mul_id3.length > ULONG_MAX ? 0 : mul_id3.length;
165170 id3->filesize = mul_id3.filesize > INT_MAX ? 0 : mul_id3.filesize;
166171 id3->frequency = mul_id3.frequency;
···172177 id3->track_level = 0;
173178 id3->album_level = 0;
174179}
180180+181181+unsigned long human_size(unsigned long long byte_count, int32_t *unit_lang_id)
182182+{
183183+ const size_t n = sizeof(units)/sizeof(units[0]);
184184+ unsigned int i;
185185+186186+ /* margin set at 10K boundary: 10239 B +1 => 10 KB */
187187+ for(i = 0; i < n-1 && byte_count >= 10*1024; i++)
188188+ byte_count >>= 10; /* div by 1024 */
189189+190190+ *unit_lang_id = units[i];
191191+ return (unsigned long)byte_count;
192192+}
193193+194194+/* missing filetype attribute for images */
195195+static const char *image_exts[] = {"bmp","jpg","jpe","jpeg","png","ppm"};
196196+/* and videos */
197197+static const char *video_exts[] = {"mpg","mpeg","mpv","m2v"};
198198+199199+static void prn(const char *str, int y)
200200+{
201201+ rb->lcd_puts(0, y, str);
202202+#ifdef HAVE_REMOTE_LCD
203203+ rb->lcd_remote_puts(0, y, str);
204204+#endif
205205+}
206206+207207+void display_dir_stats(struct dir_stats *stats)
208208+{
209209+ char buf[32];
210210+ int32_t lang_size_unit;
211211+ unsigned long display_size = human_size(stats->byte_count, &lang_size_unit);
212212+ rb->lcd_clear_display();
213213+#ifdef HAVE_REMOTE_LCD
214214+ rb->lcd_remote_clear_display();
215215+#endif
216216+ rb->snprintf(buf, sizeof(buf), "Files: %d (%lu %s)", stats->file_count,
217217+ display_size, rb->str(lang_size_unit));
218218+ prn(buf, 0);
219219+ rb->snprintf(buf, sizeof(buf), "Audio: %d", stats->audio_file_count);
220220+ prn(buf, 1);
221221+ if (stats->count_all)
222222+ {
223223+ rb->snprintf(buf, sizeof(buf), "Playlists: %d", stats->m3u_file_count);
224224+ prn(buf, 2);
225225+ rb->snprintf(buf, sizeof(buf), "Images: %d", stats->img_file_count);
226226+ prn(buf, 3);
227227+ rb->snprintf(buf, sizeof(buf), "Videos: %d", stats->vid_file_count);
228228+ prn(buf, 4);
229229+ rb->snprintf(buf, sizeof(buf), "Directories: %d", stats->dir_count);
230230+ prn(buf, 5);
231231+ rb->snprintf(buf, sizeof(buf), "Max files in Dir: %d",
232232+ stats->max_files_in_dir);
233233+ prn(buf, 6);
234234+ }
235235+ else
236236+ {
237237+ rb->snprintf(buf, sizeof(buf), "Directories: %d", stats->dir_count);
238238+ prn(buf, 2);
239239+ }
240240+ rb->lcd_update();
241241+#ifdef HAVE_REMOTE_LCD
242242+ rb->lcd_remote_update();
243243+#endif
244244+245245+}
246246+247247+/* Recursively scans directories in search of files
248248+ * and informs the user of the progress.
249249+ */
250250+bool collect_dir_stats(struct dir_stats *stats, bool (*id3_cb)(const char*))
251251+{
252252+ bool result = true;
253253+ unsigned int files_in_dir = 0;
254254+ static unsigned int id3_count;
255255+ static unsigned long last_displayed, last_get_action;
256256+ struct dirent* entry;
257257+ int dirlen = rb->strlen(stats->dirname);
258258+ DIR* dir = rb->opendir(stats->dirname);
259259+ if (!dir)
260260+ {
261261+ rb->splashf(HZ*2, "open error: %s", stats->dirname);
262262+ return false;
263263+ }
264264+ else if (!stats->dirname[1]) /* root dir */
265265+ stats->dirname[0] = dirlen = 0;
266266+267267+ /* walk through the directory content */
268268+ while(result && (0 != (entry = rb->readdir(dir))))
269269+ {
270270+ struct dirinfo info = rb->dir_get_info(dir, entry);
271271+ if (info.attribute & ATTR_DIRECTORY)
272272+ {
273273+ if (!rb->strcmp((char *)entry->d_name, ".") ||
274274+ !rb->strcmp((char *)entry->d_name, ".."))
275275+ continue; /* skip these */
276276+277277+ rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen,
278278+ "/%s", entry->d_name); /* append name to current directory */
279279+ if (!id3_cb)
280280+ {
281281+ stats->dir_count++; /* new directory */
282282+ if (*rb->current_tick - last_displayed > (HZ/2))
283283+ {
284284+ if (last_displayed)
285285+ display_dir_stats(stats);
286286+ last_displayed = *(rb->current_tick);
287287+ }
288288+ }
289289+ result = collect_dir_stats(stats, id3_cb); /* recursion */
290290+ }
291291+ else if (!id3_cb)
292292+ {
293293+ char *ptr;
294294+ stats->file_count++; /* new file */
295295+ files_in_dir++;
296296+ stats->byte_count += info.size;
297297+298298+ int attr = rb->filetype_get_attr(entry->d_name);
299299+ if (attr == FILE_ATTR_AUDIO)
300300+ stats->audio_file_count++;
301301+ else if (attr == FILE_ATTR_M3U)
302302+ stats->m3u_file_count++;
303303+ /* image or video file attributes have to be compared manually */
304304+ else if (stats->count_all &&
305305+ (ptr = rb->strrchr(entry->d_name,'.')))
306306+ {
307307+ unsigned int i;
308308+ ptr++;
309309+ for(i = 0; i < ARRAYLEN(image_exts); i++)
310310+ {
311311+ if(!rb->strcasecmp(ptr, image_exts[i]))
312312+ {
313313+ stats->img_file_count++;
314314+ break;
315315+ }
316316+ }
317317+ if (i >= ARRAYLEN(image_exts)) {
318318+ for(i = 0; i < ARRAYLEN(video_exts); i++) {
319319+ if(!rb->strcasecmp(ptr, video_exts[i])) {
320320+ stats->vid_file_count++;
321321+ break;
322322+ }
323323+ }
324324+ }
325325+ }
326326+ }
327327+ else if (rb->filetype_get_attr(entry->d_name) == FILE_ATTR_AUDIO)
328328+ {
329329+ rb->splash_progress(id3_count++, stats->audio_file_count,
330330+ "%s (%s)",
331331+ rb->str(LANG_WAIT), rb->str(LANG_OFF_ABORT));
332332+ rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen,
333333+ "/%s", entry->d_name); /* append name to current directory */
334334+ id3_cb(stats->dirname); /* allow metadata to be collected */
335335+ }
336336+337337+ if (TIME_AFTER(*(rb->current_tick), last_get_action + HZ/8))
338338+ {
339339+ if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
340340+ {
341341+ stats->canceled = true;
342342+ result = false;
343343+ }
344344+ last_get_action = *(rb->current_tick);
345345+ }
346346+ rb->yield();
347347+ }
348348+ rb->closedir(dir);
349349+ if (stats->max_files_in_dir < files_in_dir)
350350+ stats->max_files_in_dir = files_in_dir;
351351+ return result;
352352+}
+32
apps/plugins/lib/mul_id3.h
···2121#ifndef MUL_ID3_H
2222#define MUL_ID3_H
23232424+struct dir_stats {
2525+ char dirname[MAX_PATH];
2626+ unsigned int dir_count;
2727+ unsigned int file_count;
2828+ unsigned int audio_file_count;
2929+ unsigned int m3u_file_count;
3030+ unsigned int img_file_count;
3131+ unsigned int vid_file_count;
3232+ unsigned int max_files_in_dir;
3333+ unsigned long long byte_count;
3434+ bool count_all;
3535+ bool canceled;
3636+};
3737+3838+/* create mp3entry that contains matching metadata from multiple tracks */
2439void collect_id3(struct mp3entry *id3, bool is_first_track);
2540void finalize_id3(struct mp3entry *id3);
4141+4242+/* Traverse directory, collecting stats/track metadata.
4343+ *
4444+ * 1) If id3_cb is null, dir_properties calculates all dir stats, including the
4545+ * audio file count.
4646+ *
4747+ * 2) If id3_cb points to a function, dir_properties will call it for every audio
4848+ * file encountered, to allow the file's metadata to be collected. The displayed
4949+ * progress bar's maximum value is set to the audio file count.
5050+ * Stats are assumed to have already been generated by a preceding run.
5151+ *
5252+ * If the count_all parameter is set to false, images and videos are not counted,
5353+ * nor is the playlist, image, video or max file in dir count displayed.
5454+ */
5555+bool collect_dir_stats(struct dir_stats *stats, bool (*id3_cb)(const char*));
5656+void display_dir_stats(struct dir_stats *stats);
5757+unsigned long human_size(unsigned long long byte_count, int32_t *unit_lang_id);
26582759#endif /* MUL_ID3_H */
+14-141
apps/plugins/properties.c
···2525 #define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0]))
2626#endif
27272828-struct dir_stats {
2929- char dirname[MAX_PATH];
3030- unsigned int dir_count;
3131- unsigned int file_count;
3232- unsigned int audio_file_count;
3333- unsigned long long byte_count;
3434- bool canceled;
3535-};
3636-3728enum props_types {
3829 PROPS_FILE = 0,
3930 PROPS_PLAYLIST,
···4233 PROPS_DIR
4334};
44354545-static int props_type = PROPS_FILE;
3636+static int props_type;
46374738static struct mp3entry id3;
4839static int mul_id3_count;
···5748static char str_date[64];
5849static char str_time[64];
59506060-static unsigned long nsize;
6161-static int32_t size_unit;
5151+static unsigned long display_size;
5252+static int32_t lang_size_unit;
6253static struct tm tm;
63546455#define NUM_FILE_PROPERTIES 5
···8677 ID2P(LANG_MENU_SHOW_ID3_INFO), str_audio_filecount,
8778};
88798989-static const int32_t units[] =
9090-{
9191- LANG_BYTE,
9292- LANG_KIBIBYTE,
9393- LANG_MEBIBYTE,
9494- LANG_GIBIBYTE
9595-};
9696-9797-static unsigned int human_size_log(unsigned long long size)
9898-{
9999- const size_t n = sizeof(units)/sizeof(units[0]);
100100-101101- unsigned int i;
102102- /* margin set at 10K boundary: 10239 B +1 => 10 KB */
103103- for(i=0; i < n-1 && size >= 10*1024; i++)
104104- size >>= 10; /* div by 1024 */
105105-106106- return i;
107107-}
108108-10980static bool file_properties(const char* selected_file)
11081{
11182 bool found = false;
···11889 struct dirinfo info = rb->dir_get_info(dir, entry);
11990 if(!rb->strcmp(entry->d_name, str_filename))
12091 {
121121- unsigned int log;
122122- log = human_size_log((unsigned long)info.size);
123123- nsize = ((unsigned long)info.size) >> (log*10);
124124- size_unit = units[log];
9292+ display_size = human_size(info.size, &lang_size_unit);
12593 rb->snprintf(str_size, sizeof str_size, "%lu %s",
126126- nsize, rb->str(size_unit));
9494+ display_size, rb->str(lang_size_unit));
12795 rb->gmtime_r(&info.mtime, &tm);
12896 rb->snprintf(str_date, sizeof str_date, "%04d/%02d/%02d",
12997 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
···141109 return found;
142110}
143111144144-/* Recursively scans directories in search of files
145145- * and informs the user of the progress.
146146- */
147147-static bool _dir_properties(struct dir_stats *stats, bool (*id3_cb)(const char*))
148148-{
149149- bool result = true;
150150- static unsigned long last_lcd_update, last_get_action;
151151- struct dirent* entry;
152152- int dirlen = rb->strlen(stats->dirname);
153153- DIR* dir = rb->opendir(stats->dirname);
154154- if (!dir)
155155- {
156156- rb->splashf(HZ*2, "open error: %s", stats->dirname);
157157- return false;
158158- }
159112160160- /* walk through the directory content */
161161- while(result && (0 != (entry = rb->readdir(dir))))
162162- {
163163- struct dirinfo info = rb->dir_get_info(dir, entry);
164164- if (info.attribute & ATTR_DIRECTORY)
165165- {
166166- if (!rb->strcmp((char *)entry->d_name, ".") ||
167167- !rb->strcmp((char *)entry->d_name, ".."))
168168- continue; /* skip these */
169169-170170- rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen,
171171- "/%s", entry->d_name); /* append name to current directory */
172172-173173- if (!id3_cb)
174174- {
175175- stats->dir_count++; /* new directory */
176176- if (*rb->current_tick - last_lcd_update > (HZ/2))
177177- {
178178- unsigned int log;
179179- last_lcd_update = *(rb->current_tick);
180180- rb->lcd_clear_display();
181181- rb->lcd_putsf(0, 0, "Directories: %d", stats->dir_count);
182182- rb->lcd_putsf(0, 1, "Files: %d (Audio: %d)",
183183- stats->file_count, stats->audio_file_count);
184184- log = human_size_log(stats->byte_count);
185185- rb->lcd_putsf(0, 2, "Size: %lu %s",
186186- (unsigned long)(stats->byte_count >> (10*log)),
187187- rb->str(units[log]));
188188- rb->lcd_update();
189189- }
190190- }
191191-192192- result = _dir_properties(stats, id3_cb); /* recursion */
193193- }
194194- else if (!id3_cb)
195195- {
196196- stats->file_count++; /* new file */
197197- stats->byte_count += info.size;
198198- if (rb->filetype_get_attr(entry->d_name) == FILE_ATTR_AUDIO)
199199- stats->audio_file_count++;
200200- }
201201- else if (rb->filetype_get_attr(entry->d_name) == FILE_ATTR_AUDIO)
202202- {
203203- rb->splash_progress(mul_id3_count, stats->audio_file_count, "%s (%s)",
204204- rb->str(LANG_WAIT), rb->str(LANG_OFF_ABORT));
205205- rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen,
206206- "/%s", entry->d_name); /* append name to current directory */
207207- id3_cb(stats->dirname); /* allow metadata to be collected */
208208- }
209209-210210- if (TIME_AFTER(*(rb->current_tick), last_get_action + HZ/8))
211211- {
212212- if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
213213- {
214214- stats->canceled = true;
215215- result = false;
216216- }
217217- last_get_action = *(rb->current_tick);
218218- }
219219- rb->yield();
220220- }
221221- rb->closedir(dir);
222222- return result;
223223-}
224224-225225-/* 1) If id3_cb is null, dir_properties calculates all dir stats, including the
226226- * audio file count.
227227- *
228228- * 2) If id3_cb points to a function, dir_properties will call it for every audio
229229- * file encountered, to allow the file's metadata to be collected. The displayed
230230- * progress bar's maximum value is set to the audio file count.
231231- * Stats are assumed to have already been generated by a preceding run.
232232- */
233113static bool dir_properties(const char* selected_file, struct dir_stats *stats,
234114 bool (*id3_cb)(const char*))
235115{
236236- unsigned int log;
237116 bool success;
238117239118 rb->strlcpy(stats->dirname, selected_file, sizeof(stats->dirname));
···243122#ifdef HAVE_ADJUSTABLE_CPU_FREQ
244123 rb->cpu_boost(true);
245124#endif
246246- success = _dir_properties(stats, id3_cb);
247247-125125+ success = collect_dir_stats(stats, id3_cb);
126126+248127#ifdef HAVE_ADJUSTABLE_CPU_FREQ
249128 rb->cpu_boost(false);
250129#endif
···259138 rb->snprintf(str_filecount, sizeof str_filecount, "%d", stats->file_count);
260139 rb->snprintf(str_audio_filecount, sizeof str_filecount, "%d",
261140 stats->audio_file_count);
262262- log = human_size_log(stats->byte_count);
263263- nsize = (long) (stats->byte_count >> (log*10));
264264- size_unit = units[log];
265265- rb->snprintf(str_size, sizeof str_size, "%ld %s", nsize, rb->str(size_unit));
141141+ display_size = human_size(stats->byte_count, &lang_size_unit);
142142+ rb->snprintf(str_size, sizeof str_size, "%lu %s", display_size,
143143+ rb->str(lang_size_unit));
266144 }
267145 return true;
268146}
···320198 rb->talk_file_or_spell(str_dirname, str_filename, NULL, true);
321199 break;
322200 case LANG_PROPERTIES_SIZE:
323323- rb->talk_number(nsize, true);
324324- rb->talk_id(size_unit, true);
201201+ rb->talk_number(display_size, true);
202202+ rb->talk_id(lang_size_unit, true);
325203 break;
326204 case LANG_PROPERTIES_DATE:
327205 rb->talk_date(&tm, true);
···399277400278static bool determine_file_or_dir(void)
401279{
402402- DIR* dir;
403280 struct dirent* entry;
404404-405405- dir = rb->opendir(str_dirname);
281281+ DIR* dir = rb->opendir(str_dirname);
406282 if (dir)
407283 {
408284 while(0 != (entry = rb->readdir(dir)))
···482358{
483359 int ret;
484360 static struct dir_stats stats;
485485-486361 const char *file = parameter;
487362 if(!parameter)
488363 return PLUGIN_ERROR;
···490365#ifdef HAVE_TOUCHSCREEN
491366 rb->touchscreen_set_mode(rb->global_settings->touch_mode);
492367#endif
493493-494368 if (file[0] == '/') /* single file or folder selected */
495369 {
496370 const char* file_name = rb->strrchr(file, '/') + 1;
497497- int dirlen = (file_name - file);
498498-371371+ const int dirlen = (file_name - file);
499372 rb->strlcpy(str_dirname, file, dirlen + 1);
500373 rb->snprintf(str_filename, sizeof str_filename, "%s", file + dirlen);
501374
···55(the total number as well as the number
66of audio, playlist, image and video files)
77on your \dap{}.
88-Press
99-\nopt{IPOD_4G_PAD,IPOD_3G_PAD}{\PluginCancel{} or \PluginExit{}}
1010-\opt{IPOD_4G_PAD,IPOD_3G_PAD}{\ButtonMenu}
1111-to abort counting and
1212-exit the plugin. Press it again to quit after counting has
1313-finished.
88+Press \ActionStdCancel{} to exit the plugin.