summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/stats.c136
2 files changed, 137 insertions, 0 deletions
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index 4810553d8d..dc68510863 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -11,6 +11,7 @@ rockbox_flash.c
11search.c 11search.c
12snow.c 12snow.c
13sort.c 13sort.c
14stats.c
14stopwatch.c 15stopwatch.c
15vbrfix.c 16vbrfix.c
16viewer.c 17viewer.c
diff --git a/apps/plugins/stats.c b/apps/plugins/stats.c
new file mode 100644
index 0000000000..b0610010ec
--- /dev/null
+++ b/apps/plugins/stats.c
@@ -0,0 +1,136 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Jonas Haggqvist
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "plugin.h"
20
21static struct plugin_api* rb;
22static int files, dirs;
23static int lasttick;
24static bool abort;
25#ifdef HAVE_LCD_BITMAP
26static int fontwidth, fontheight;
27#endif
28
29#if CONFIG_KEYPAD == PLAYER_PAD
30#define STATS_STOP BUTTON_STOP
31#else
32#define STATS_STOP BUTTON_OFF
33#endif
34
35void update_screen(void)
36{
37 char buf[15];
38#ifdef HAVE_LCD_BITMAP
39 rb->lcd_clear_display();
40 rb->lcd_putsxy(0,0,"Files:");
41 rb->lcd_putsxy(0,fontheight,"Dirs:");
42 rb->snprintf(buf, sizeof(buf), "%d", files);
43 rb->lcd_putsxy(fontwidth,0,buf);
44 rb->snprintf(buf, sizeof(buf), "%d", dirs);
45 rb->lcd_putsxy(fontwidth,fontheight,buf);
46 rb->lcd_update();
47#else
48 rb->snprintf(buf, sizeof(buf), "Files:%5d", files);
49 rb->lcd_puts(0,0,buf);
50 rb->snprintf(buf, sizeof(buf), "Dirs: %5d", dirs);
51 rb->lcd_puts(0,1,buf);
52#endif
53}
54
55void traversedir(char* location, char* name)
56{
57 int button;
58 struct dirent *entry;
59 DIR* dir;
60 char fullpath[MAX_PATH];
61
62 rb->snprintf(fullpath, sizeof(fullpath), "%s/%s", location, name);
63 dir = rb->opendir(fullpath);
64 if (dir) {
65 entry = rb->readdir(dir);
66 while (entry) {
67 if (abort == true)
68 break;
69 /* Skip .. and . */
70 if (rb->strcmp(entry->d_name, ".") && rb->strcmp(entry->d_name, ".."))
71 {
72 if (entry->attribute & ATTR_DIRECTORY) {
73 traversedir(fullpath, entry->d_name);
74 dirs += 1;
75 }
76 else
77 /* Might want to only count .mp3, .ogg etc. */
78 files++;
79 }
80 if (*rb->current_tick - lasttick > (HZ/2)) {
81 update_screen();
82 lasttick = *rb->current_tick;
83 button = rb->button_get(false);
84 if (button == STATS_STOP) {
85 abort = true;
86 break;
87 }
88 }
89
90 entry = rb->readdir(dir);
91 }
92 rb->closedir(dir);
93 }
94}
95
96enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
97{
98 int button;
99 TEST_PLUGIN_API(api);
100
101 (void)parameter;
102
103 rb = api;
104 files = 0;
105 dirs = 0;
106 abort = false;
107
108#ifdef HAVE_LCD_BITMAP
109 rb->lcd_getstringsize("Files: ", &fontwidth, &fontheight);
110#endif
111 rb->splash(HZ, true, "Counting..");
112 update_screen();
113 lasttick = *rb->current_tick;
114
115 traversedir("", "");
116 if (abort == true) {
117 rb->splash(HZ, true, "Aborted");
118 return PLUGIN_OK;
119 }
120 rb->splash(HZ, true, "Done");
121 update_screen();
122 button = rb->button_get(true);
123 while (1) {
124 switch (button) {
125 case STATS_STOP:
126 return PLUGIN_OK;
127 break;
128 default:
129 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
130 return PLUGIN_USB_CONNECTED;
131 }
132 break;
133 }
134 return PLUGIN_OK;
135 }
136}