summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-07-25 20:47:29 +0200
committerChristian Soffke <christian.soffke@gmail.com>2024-07-26 21:16:13 +0200
commita64faae09e5bec90e4a6d625e62fca61a432d459 (patch)
tree775009b36b5f066b531a4472056a505b0fdaefef
parentb52e72db36469fab813f63d0e69ced2e9d241b61 (diff)
downloadrockbox-a64faae09e5bec90e4a6d625e62fca61a432d459.tar.gz
rockbox-a64faae09e5bec90e4a6d625e62fca61a432d459.zip
plugins: properties: optimize slightly
- We only have to update stats->dirname when entering a new directory, or when id3cb needs to be called - Reduce frequency for calling get_action and LCD update - Replace dir_stats->len and hardcoded MAX_PATH with sizeof - Don't show paths in Properties during scanning - Don't show error when user cancels Change-Id: I4afbeba561e69188e8039fa8d91eb1e91318bdab
-rw-r--r--apps/plugins/properties.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c
index dc55b8128b..1156bd5ca9 100644
--- a/apps/plugins/properties.c
+++ b/apps/plugins/properties.c
@@ -27,11 +27,11 @@
27 27
28struct dir_stats { 28struct dir_stats {
29 char dirname[MAX_PATH]; 29 char dirname[MAX_PATH];
30 int len;
31 unsigned int dir_count; 30 unsigned int dir_count;
32 unsigned int file_count; 31 unsigned int file_count;
33 unsigned int audio_file_count; 32 unsigned int audio_file_count;
34 unsigned long long byte_count; 33 unsigned long long byte_count;
34 bool canceled;
35}; 35};
36 36
37enum props_types { 37enum props_types {
@@ -147,7 +147,7 @@ static bool file_properties(const char* selected_file)
147static bool _dir_properties(struct dir_stats *stats, bool (*id3_cb)(const char*)) 147static bool _dir_properties(struct dir_stats *stats, bool (*id3_cb)(const char*))
148{ 148{
149 bool result = true; 149 bool result = true;
150 static long last_tick = 0; 150 static unsigned long last_lcd_update, last_get_action;
151 struct dirent* entry; 151 struct dirent* entry;
152 int dirlen = rb->strlen(stats->dirname); 152 int dirlen = rb->strlen(stats->dirname);
153 DIR* dir = rb->opendir(stats->dirname); 153 DIR* dir = rb->opendir(stats->dirname);
@@ -161,31 +161,28 @@ static bool _dir_properties(struct dir_stats *stats, bool (*id3_cb)(const char*)
161 while(result && (0 != (entry = rb->readdir(dir)))) 161 while(result && (0 != (entry = rb->readdir(dir))))
162 { 162 {
163 struct dirinfo info = rb->dir_get_info(dir, entry); 163 struct dirinfo info = rb->dir_get_info(dir, entry);
164
165 rb->snprintf(stats->dirname + dirlen, stats->len - dirlen, "/%s",
166 entry->d_name); /* append name to current directory */
167
168 if (info.attribute & ATTR_DIRECTORY) 164 if (info.attribute & ATTR_DIRECTORY)
169 { 165 {
170 if (!rb->strcmp((char *)entry->d_name, ".") || 166 if (!rb->strcmp((char *)entry->d_name, ".") ||
171 !rb->strcmp((char *)entry->d_name, "..")) 167 !rb->strcmp((char *)entry->d_name, ".."))
172 continue; /* skip these */ 168 continue; /* skip these */
173 169
170 rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen,
171 "/%s", entry->d_name); /* append name to current directory */
172
174 if (!id3_cb) 173 if (!id3_cb)
175 { 174 {
176 stats->dir_count++; /* new directory */ 175 stats->dir_count++; /* new directory */
177 if (*rb->current_tick - last_tick > (HZ/8)) 176 if (*rb->current_tick - last_lcd_update > (HZ/2))
178 { 177 {
179 unsigned int log; 178 unsigned int log;
180 last_tick = *(rb->current_tick); 179 last_lcd_update = *(rb->current_tick);
181 rb->lcd_clear_display(); 180 rb->lcd_clear_display();
182 rb->lcd_puts(0, 0, "SCANNING..."); 181 rb->lcd_putsf(0, 0, "Directories: %d", stats->dir_count);
183 rb->lcd_puts(0, 1, stats->dirname); 182 rb->lcd_putsf(0, 1, "Files: %d (Audio: %d)",
184 rb->lcd_putsf(0, 2, "Directories: %d", stats->dir_count);
185 rb->lcd_putsf(0, 3, "Files: %d (Audio: %d)",
186 stats->file_count, stats->audio_file_count); 183 stats->file_count, stats->audio_file_count);
187 log = human_size_log(stats->byte_count); 184 log = human_size_log(stats->byte_count);
188 rb->lcd_putsf(0, 4, "Size: %lu %s", 185 rb->lcd_putsf(0, 2, "Size: %lu %s",
189 (unsigned long)(stats->byte_count >> (10*log)), 186 (unsigned long)(stats->byte_count >> (10*log)),
190 rb->str(units[log])); 187 rb->str(units[log]));
191 rb->lcd_update(); 188 rb->lcd_update();
@@ -205,11 +202,20 @@ static bool _dir_properties(struct dir_stats *stats, bool (*id3_cb)(const char*)
205 { 202 {
206 rb->splash_progress(mul_id3_count, stats->audio_file_count, "%s (%s)", 203 rb->splash_progress(mul_id3_count, stats->audio_file_count, "%s (%s)",
207 rb->str(LANG_WAIT), rb->str(LANG_OFF_ABORT)); 204 rb->str(LANG_WAIT), rb->str(LANG_OFF_ABORT));
205 rb->snprintf(stats->dirname + dirlen, sizeof(stats->dirname) - dirlen,
206 "/%s", entry->d_name); /* append name to current directory */
208 id3_cb(stats->dirname); /* allow metadata to be collected */ 207 id3_cb(stats->dirname); /* allow metadata to be collected */
209 } 208 }
210 209
211 if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK)) 210 if (TIME_AFTER(*(rb->current_tick), last_get_action + HZ/8))
212 result = false; 211 {
212 if(ACTION_STD_CANCEL == rb->get_action(CONTEXT_STD,TIMEOUT_NOBLOCK))
213 {
214 stats->canceled = true;
215 result = false;
216 }
217 last_get_action = *(rb->current_tick);
218 }
213 rb->yield(); 219 rb->yield();
214 } 220 }
215 rb->closedir(dir); 221 rb->closedir(dir);
@@ -230,7 +236,7 @@ static bool dir_properties(const char* selected_file, struct dir_stats *stats,
230 unsigned int log; 236 unsigned int log;
231 bool success; 237 bool success;
232 238
233 rb->strlcpy(stats->dirname, selected_file, MAX_PATH); 239 rb->strlcpy(stats->dirname, selected_file, sizeof(stats->dirname));
234 if (id3_cb) 240 if (id3_cb)
235 rb->splash_progress_set_delay(HZ / 2); /* hide progress bar for 0.5s */ 241 rb->splash_progress_set_delay(HZ / 2); /* hide progress bar for 0.5s */
236 242
@@ -248,7 +254,7 @@ static bool dir_properties(const char* selected_file, struct dir_stats *stats,
248 254
249 if (!id3_cb) 255 if (!id3_cb)
250 { 256 {
251 rb->strlcpy(str_dirname, selected_file, MAX_PATH); 257 rb->strlcpy(str_dirname, selected_file, sizeof(str_dirname));
252 rb->snprintf(str_dircount, sizeof str_dircount, "%d", stats->dir_count); 258 rb->snprintf(str_dircount, sizeof str_dircount, "%d", stats->dir_count);
253 rb->snprintf(str_filecount, sizeof str_filecount, "%d", stats->file_count); 259 rb->snprintf(str_filecount, sizeof str_filecount, "%d", stats->file_count);
254 rb->snprintf(str_audio_filecount, sizeof str_filecount, "%d", 260 rb->snprintf(str_audio_filecount, sizeof str_filecount, "%d",
@@ -475,14 +481,7 @@ static bool assemble_track_info(const char *filename, struct dir_stats *stats)
475enum plugin_status plugin_start(const void* parameter) 481enum plugin_status plugin_start(const void* parameter)
476{ 482{
477 int ret; 483 int ret;
478 static struct dir_stats stats = 484 static struct dir_stats stats;
479 {
480 .len = MAX_PATH,
481 .dir_count = 0,
482 .file_count = 0,
483 .audio_file_count = 0,
484 .byte_count = 0,
485 };
486 485
487 const char *file = parameter; 486 const char *file = parameter;
488 if(!parameter) 487 if(!parameter)
@@ -498,7 +497,7 @@ enum plugin_status plugin_start(const void* parameter)
498 int dirlen = (file_name - file); 497 int dirlen = (file_name - file);
499 498
500 rb->strlcpy(str_dirname, file, dirlen + 1); 499 rb->strlcpy(str_dirname, file, dirlen + 1);
501 rb->snprintf(str_filename, sizeof str_filename, "%s", file+dirlen); 500 rb->snprintf(str_filename, sizeof str_filename, "%s", file + dirlen);
502 501
503 if(!determine_file_or_dir()) 502 if(!determine_file_or_dir())
504 { 503 {
@@ -514,9 +513,12 @@ enum plugin_status plugin_start(const void* parameter)
514 if(!(props_type == PROPS_DIR ? 513 if(!(props_type == PROPS_DIR ?
515 dir_properties(file, &stats, NULL) : file_properties(file))) 514 dir_properties(file, &stats, NULL) : file_properties(file)))
516 { 515 {
517 /* something went wrong (to do: tell user what it was (nesting,...) */ 516 if (!stats.canceled)
518 rb->splash(0, ID2P(LANG_PROPERTIES_FAIL)); 517 {
519 rb->action_userabort(TIMEOUT_BLOCK); 518 /* something went wrong (to do: tell user what it was (nesting,...) */
519 rb->splash(0, ID2P(LANG_PROPERTIES_FAIL));
520 rb->action_userabort(TIMEOUT_BLOCK);
521 }
520 return PLUGIN_OK; 522 return PLUGIN_OK;
521 } 523 }
522 } 524 }
@@ -534,7 +536,8 @@ enum plugin_status plugin_start(const void* parameter)
534 ret = rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count); /* database tracks */ 536 ret = rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count); /* database tracks */
535 else if ((ret = browse_file_or_dir(&stats)) < 0) 537 else if ((ret = browse_file_or_dir(&stats)) < 0)
536 ret = assemble_track_info(file, &stats) ? /* playlist or folder tracks */ 538 ret = assemble_track_info(file, &stats) ? /* playlist or folder tracks */
537 rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count) : -1; 539 rb->browse_id3(&id3, 0, 0, NULL, mul_id3_count) :
540 (stats.canceled ? 0 : -1);
538 541
539 FOR_NB_SCREENS(i) 542 FOR_NB_SCREENS(i)
540 rb->viewportmanager_theme_undo(i, false); 543 rb->viewportmanager_theme_undo(i, false);