diff options
author | Jonas Häggqvist <rasher@rasher.dk> | 2005-08-20 19:56:01 +0000 |
---|---|---|
committer | Jonas Häggqvist <rasher@rasher.dk> | 2005-08-20 19:56:01 +0000 |
commit | 5d0fe30feb022030c2f43f44b0ccca35ddef3446 (patch) | |
tree | 4fc3dc7e3b3cb624ace12586e7444b89c1c24611 /apps/plugins | |
parent | e3dc61e0b9393d263240a716e2bf5ac63ebff80c (diff) | |
download | rockbox-5d0fe30feb022030c2f43f44b0ccca35ddef3446.tar.gz rockbox-5d0fe30feb022030c2f43f44b0ccca35ddef3446.zip |
Plugin that counds files and folders on harddisk. Works on all models.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7364 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/SOURCES | 1 | ||||
-rw-r--r-- | apps/plugins/stats.c | 136 |
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 | |||
11 | search.c | 11 | search.c |
12 | snow.c | 12 | snow.c |
13 | sort.c | 13 | sort.c |
14 | stats.c | ||
14 | stopwatch.c | 15 | stopwatch.c |
15 | vbrfix.c | 16 | vbrfix.c |
16 | viewer.c | 17 | viewer.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 | |||
21 | static struct plugin_api* rb; | ||
22 | static int files, dirs; | ||
23 | static int lasttick; | ||
24 | static bool abort; | ||
25 | #ifdef HAVE_LCD_BITMAP | ||
26 | static 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 | |||
35 | void 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 | |||
55 | void 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 | |||
96 | enum 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 | } | ||