Use date and time rather than size and starting cluster to detect installation of...
[Rockbox.git] / apps / misc.c
blobf95abb862f92b4d9c69ff08dc51df232fbb74c43
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Daniel Stenberg
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include <stdlib.h>
20 #include <ctype.h>
21 #include "lang.h"
22 #include "string.h"
23 #include "config.h"
24 #include "file.h"
25 #include "dir.h"
26 #include "lcd.h"
27 #include "lcd-remote.h"
28 #include "sprintf.h"
29 #include "errno.h"
30 #include "system.h"
31 #include "timefuncs.h"
32 #include "screens.h"
33 #include "talk.h"
34 #include "mpeg.h"
35 #include "audio.h"
36 #include "mp3_playback.h"
37 #include "settings.h"
38 #include "ata.h"
39 #include "ata_idle_notify.h"
40 #include "kernel.h"
41 #include "power.h"
42 #include "powermgmt.h"
43 #include "backlight.h"
44 #include "atoi.h"
45 #include "version.h"
46 #include "font.h"
47 #include "splash.h"
48 #include "tagcache.h"
49 #include "scrobbler.h"
50 #ifdef HAVE_MMC
51 #include "ata_mmc.h"
52 #endif
53 #include "tree.h"
54 #include "eeprom_settings.h"
56 #ifdef HAVE_LCD_BITMAP
57 #include "bmp.h"
58 #include "icons.h"
59 #endif /* End HAVE_LCD_BITMAP */
60 #include "gui/gwps-common.h"
62 #include "misc.h"
64 #ifdef BOOTFILE
65 #ifndef USB_IPODSTYLE
66 #include "textarea.h"
67 #include "rolo.h"
68 #include "yesno.h"
69 #endif
70 #endif
72 /* Format a large-range value for output, using the appropriate unit so that
73 * the displayed value is in the range 1 <= display < 1000 (1024 for "binary"
74 * units) if possible, and 3 significant digits are shown. If a buffer is
75 * given, the result is snprintf()'d into that buffer, otherwise the result is
76 * voiced.*/
77 char *output_dyn_value(char *buf, int buf_size, int value,
78 const unsigned char **units, bool bin_scale)
80 int scale = bin_scale ? 1024 : 1000;
81 int fraction = 0;
82 int unit_no = 0;
83 int i;
84 char tbuf[5];
86 while (value >= scale)
88 fraction = value % scale;
89 value /= scale;
90 unit_no++;
92 if (bin_scale)
93 fraction = fraction * 1000 / 1024;
95 if (value >= 100 || !unit_no)
96 tbuf[0] = '\0';
97 else if (value >= 10)
98 snprintf(tbuf, sizeof(tbuf), "%01d", fraction / 100);
99 else
100 snprintf(tbuf, sizeof(tbuf), "%02d", fraction / 10);
102 if (buf)
104 if (strlen(tbuf))
105 snprintf(buf, buf_size, "%d%s%s%s", value, str(LANG_POINT),
106 tbuf, P2STR(units[unit_no]));
107 else
108 snprintf(buf, buf_size, "%d%s", value, P2STR(units[unit_no]));
110 else
112 /* strip trailing zeros from the fraction */
113 for (i = strlen(tbuf) - 1; (i >= 0) && (tbuf[i] == '0'); i--)
114 tbuf[i] = '\0';
116 talk_number(value, true);
117 if (tbuf[0] != 0)
119 talk_id(LANG_POINT, true);
120 talk_spell(tbuf, true);
122 talk_id(P2ID(units[unit_no]), true);
124 return buf;
127 /* Create a filename with a number part in a way that the number is 1
128 * higher than the highest numbered file matching the same pattern.
129 * It is allowed that buffer and path point to the same memory location,
130 * saving a strcpy(). Path must always be given without trailing slash.
131 * "num" can point to an int specifying the number to use or NULL or a value
132 * less than zero to number automatically. The final number used will also
133 * be returned in *num. If *num is >= 0 then *num will be incremented by
134 * one. */
135 char *create_numbered_filename(char *buffer, const char *path,
136 const char *prefix, const char *suffix,
137 int numberlen IF_CNFN_NUM_(, int *num))
139 DIR *dir;
140 struct dirent *entry;
141 int max_num;
142 int pathlen;
143 int prefixlen = strlen(prefix);
144 char fmtstring[12];
146 if (buffer != path)
147 strncpy(buffer, path, MAX_PATH);
149 pathlen = strlen(buffer);
151 #ifdef IF_CNFN_NUM
152 if (num && *num >= 0)
154 /* number specified */
155 max_num = *num;
157 else
158 #endif
160 /* automatic numbering */
161 max_num = 0;
163 dir = opendir(pathlen ? buffer : "/");
164 if (!dir)
165 return NULL;
167 while ((entry = readdir(dir)))
169 int curr_num;
171 if (strncasecmp((char *)entry->d_name, prefix, prefixlen)
172 || strcasecmp((char *)entry->d_name + prefixlen + numberlen, suffix))
173 continue;
175 curr_num = atoi((char *)entry->d_name + prefixlen);
176 if (curr_num > max_num)
177 max_num = curr_num;
180 closedir(dir);
183 max_num++;
185 snprintf(fmtstring, sizeof(fmtstring), "/%%s%%0%dd%%s", numberlen);
186 snprintf(buffer + pathlen, MAX_PATH - pathlen, fmtstring, prefix,
187 max_num, suffix);
189 #ifdef IF_CNFN_NUM
190 if (num)
191 *num = max_num;
192 #endif
194 return buffer;
197 /* Format time into buf.
199 * buf - buffer to format to.
200 * buf_size - size of buffer.
201 * t - time to format, in milliseconds.
203 void format_time(char* buf, int buf_size, long t)
205 if ( t < 3600000 )
207 snprintf(buf, buf_size, "%d:%02d",
208 (int) (t / 60000), (int) (t % 60000 / 1000));
210 else
212 snprintf(buf, buf_size, "%d:%02d:%02d",
213 (int) (t / 3600000), (int) (t % 3600000 / 60000),
214 (int) (t % 60000 / 1000));
218 #if CONFIG_RTC
219 /* Create a filename with a date+time part.
220 It is allowed that buffer and path point to the same memory location,
221 saving a strcpy(). Path must always be given without trailing slash.
222 unique_time as true makes the function wait until the current time has
223 changed. */
224 char *create_datetime_filename(char *buffer, const char *path,
225 const char *prefix, const char *suffix,
226 bool unique_time)
228 struct tm *tm = get_time();
229 static struct tm last_tm;
230 int pathlen;
232 while (unique_time && !memcmp(get_time(), &last_tm, sizeof (struct tm)))
233 sleep(HZ/10);
235 last_tm = *tm;
237 if (buffer != path)
238 strncpy(buffer, path, MAX_PATH);
240 pathlen = strlen(buffer);
241 snprintf(buffer + pathlen, MAX_PATH - pathlen,
242 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix,
243 tm->tm_year % 100, tm->tm_mon + 1, tm->tm_mday,
244 tm->tm_hour, tm->tm_min, tm->tm_sec, suffix);
246 return buffer;
248 #endif /* CONFIG_RTC */
250 /* Read (up to) a line of text from fd into buffer and return number of bytes
251 * read (which may be larger than the number of bytes stored in buffer). If
252 * an error occurs, -1 is returned (and buffer contains whatever could be
253 * read). A line is terminated by a LF char. Neither LF nor CR chars are
254 * stored in buffer.
256 int read_line(int fd, char* buffer, int buffer_size)
258 int count = 0;
259 int num_read = 0;
261 errno = 0;
263 while (count < buffer_size)
265 unsigned char c;
267 if (1 != read(fd, &c, 1))
268 break;
270 num_read++;
272 if ( c == '\n' )
273 break;
275 if ( c == '\r' )
276 continue;
278 buffer[count++] = c;
281 buffer[MIN(count, buffer_size - 1)] = 0;
283 return errno ? -1 : num_read;
286 /* Performance optimized version of the previous function. */
287 int fast_readline(int fd, char *buf, int buf_size, void *parameters,
288 int (*callback)(int n, const char *buf, void *parameters))
290 char *p, *next;
291 int rc, pos = 0;
292 int count = 0;
294 while ( 1 )
296 next = NULL;
298 rc = read(fd, &buf[pos], buf_size - pos - 1);
299 if (rc >= 0)
300 buf[pos+rc] = '\0';
302 if ( (p = strchr(buf, '\r')) != NULL)
304 *p = '\0';
305 next = ++p;
307 else
308 p = buf;
310 if ( (p = strchr(p, '\n')) != NULL)
312 *p = '\0';
313 next = ++p;
316 rc = callback(count, buf, parameters);
317 if (rc < 0)
318 return rc;
320 count++;
321 if (next)
323 pos = buf_size - ((long)next - (long)buf) - 1;
324 memmove(buf, next, pos);
326 else
327 break ;
330 return 0;
333 #ifdef HAVE_LCD_BITMAP
335 #if LCD_DEPTH == 16
336 #define BMP_COMPRESSION 3 /* BI_BITFIELDS */
337 #define BMP_NUMCOLORS 3
338 #else
339 #define BMP_COMPRESSION 0 /* BI_RGB */
340 #if LCD_DEPTH <= 8
341 #define BMP_NUMCOLORS (1 << LCD_DEPTH)
342 #else
343 #define BMP_NUMCOLORS 0
344 #endif
345 #endif
347 #if LCD_DEPTH == 1
348 #define BMP_BPP 1
349 #define BMP_LINESIZE ((LCD_WIDTH/8 + 3) & ~3)
350 #elif LCD_DEPTH <= 4
351 #define BMP_BPP 4
352 #define BMP_LINESIZE ((LCD_WIDTH/2 + 3) & ~3)
353 #elif LCD_DEPTH <= 8
354 #define BMP_BPP 8
355 #define BMP_LINESIZE ((LCD_WIDTH + 3) & ~3)
356 #elif LCD_DEPTH <= 16
357 #define BMP_BPP 16
358 #define BMP_LINESIZE ((LCD_WIDTH*2 + 3) & ~3)
359 #else
360 #define BMP_BPP 24
361 #define BMP_LINESIZE ((LCD_WIDTH*3 + 3) & ~3)
362 #endif
364 #define BMP_HEADERSIZE (54 + 4 * BMP_NUMCOLORS)
365 #define BMP_DATASIZE (BMP_LINESIZE * LCD_HEIGHT)
366 #define BMP_TOTALSIZE (BMP_HEADERSIZE + BMP_DATASIZE)
368 #define LE16_CONST(x) (x)&0xff, ((x)>>8)&0xff
369 #define LE32_CONST(x) (x)&0xff, ((x)>>8)&0xff, ((x)>>16)&0xff, ((x)>>24)&0xff
371 static const unsigned char bmpheader[] =
373 0x42, 0x4d, /* 'BM' */
374 LE32_CONST(BMP_TOTALSIZE), /* Total file size */
375 0x00, 0x00, 0x00, 0x00, /* Reserved */
376 LE32_CONST(BMP_HEADERSIZE), /* Offset to start of pixel data */
378 0x28, 0x00, 0x00, 0x00, /* Size of (2nd) header */
379 LE32_CONST(LCD_WIDTH), /* Width in pixels */
380 LE32_CONST(LCD_HEIGHT), /* Height in pixels */
381 0x01, 0x00, /* Number of planes (always 1) */
382 LE16_CONST(BMP_BPP), /* Bits per pixel 1/4/8/16/24 */
383 LE32_CONST(BMP_COMPRESSION),/* Compression mode */
384 LE32_CONST(BMP_DATASIZE), /* Size of bitmap data */
385 0xc4, 0x0e, 0x00, 0x00, /* Horizontal resolution (pixels/meter) */
386 0xc4, 0x0e, 0x00, 0x00, /* Vertical resolution (pixels/meter) */
387 LE32_CONST(BMP_NUMCOLORS), /* Number of used colours */
388 LE32_CONST(BMP_NUMCOLORS), /* Number of important colours */
390 #if LCD_DEPTH == 1
391 0x90, 0xee, 0x90, 0x00, /* Colour #0 */
392 0x00, 0x00, 0x00, 0x00 /* Colour #1 */
393 #elif LCD_DEPTH == 2
394 0xe6, 0xd8, 0xad, 0x00, /* Colour #0 */
395 0x99, 0x90, 0x73, 0x00, /* Colour #1 */
396 0x4c, 0x48, 0x39, 0x00, /* Colour #2 */
397 0x00, 0x00, 0x00, 0x00 /* Colour #3 */
398 #elif LCD_DEPTH == 16
399 0x00, 0xf8, 0x00, 0x00, /* red bitfield mask */
400 0xe0, 0x07, 0x00, 0x00, /* green bitfield mask */
401 0x1f, 0x00, 0x00, 0x00 /* blue bitfield mask */
402 #endif
405 static void (*screen_dump_hook)(int fh) = NULL;
407 void screen_dump(void)
409 int fh;
410 char filename[MAX_PATH];
411 int bx, by;
412 #if LCD_DEPTH == 1
413 static unsigned char line_block[8][BMP_LINESIZE];
414 #elif LCD_DEPTH == 2
415 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
416 static unsigned char line_block[BMP_LINESIZE];
417 #else
418 static unsigned char line_block[4][BMP_LINESIZE];
419 #endif
420 #elif LCD_DEPTH == 16
421 static unsigned short line_block[BMP_LINESIZE/2];
422 #endif
424 #if CONFIG_RTC
425 create_datetime_filename(filename, "", "dump ", ".bmp", false);
426 #else
427 create_numbered_filename(filename, "", "dump_", ".bmp", 4
428 IF_CNFN_NUM_(, NULL));
429 #endif
431 fh = creat(filename);
432 if (fh < 0)
433 return;
435 if (screen_dump_hook)
437 screen_dump_hook(fh);
439 else
441 write(fh, bmpheader, sizeof(bmpheader));
443 /* BMP image goes bottom up */
444 #if LCD_DEPTH == 1
445 for (by = LCD_FBHEIGHT - 1; by >= 0; by--)
447 unsigned char *src = &lcd_framebuffer[by][0];
448 unsigned char *dst = &line_block[0][0];
450 memset(line_block, 0, sizeof(line_block));
451 for (bx = LCD_WIDTH/8; bx > 0; bx--)
453 unsigned dst_mask = 0x80;
454 int ix;
456 for (ix = 8; ix > 0; ix--)
458 unsigned char *dst_blk = dst;
459 unsigned src_byte = *src++;
460 int iy;
462 for (iy = 8; iy > 0; iy--)
464 if (src_byte & 0x80)
465 *dst_blk |= dst_mask;
466 src_byte <<= 1;
467 dst_blk += BMP_LINESIZE;
469 dst_mask >>= 1;
471 dst++;
474 write(fh, line_block, sizeof(line_block));
476 #elif LCD_DEPTH == 2
477 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
478 for (by = LCD_FBHEIGHT - 1; by >= 0; by--)
480 unsigned char *src = &lcd_framebuffer[by][0];
481 unsigned char *dst = line_block;
483 memset(line_block, 0, sizeof(line_block));
484 for (bx = LCD_FBWIDTH; bx > 0; bx--)
486 unsigned src_byte = *src++;
488 *dst++ = ((src_byte >> 2) & 0x30) | ((src_byte >> 4) & 0x03);
489 *dst++ = ((src_byte << 2) & 0x30) | (src_byte & 0x03);
492 write(fh, line_block, sizeof(line_block));
494 #else /* VERTICAL_PACKING */
495 for (by = LCD_FBHEIGHT - 1; by >= 0; by--)
497 unsigned char *src = &lcd_framebuffer[by][0];
498 unsigned char *dst = &line_block[3][0];
500 memset(line_block, 0, sizeof(line_block));
501 for (bx = LCD_WIDTH/2; bx > 0; bx--)
503 unsigned char *dst_blk = dst++;
504 unsigned src_byte0 = *src++;
505 unsigned src_byte1 = *src++;
506 int iy;
508 for (iy = 4; iy > 0; iy--)
510 *dst_blk = ((src_byte0 & 3) << 4) | (src_byte1 & 3);
511 src_byte0 >>= 2;
512 src_byte1 >>= 2;
513 dst_blk -= BMP_LINESIZE;
517 write(fh, line_block, sizeof(line_block));
519 #endif
520 #elif LCD_DEPTH == 16
521 for (by = LCD_HEIGHT - 1; by >= 0; by--)
523 unsigned short *src = &lcd_framebuffer[by][0];
524 unsigned short *dst = line_block;
526 memset(line_block, 0, sizeof(line_block));
527 for (bx = LCD_WIDTH; bx > 0; bx--)
529 #if (LCD_PIXELFORMAT == RGB565SWAPPED)
530 /* iPod LCD data is big endian although the CPU is not */
531 *dst++ = htobe16(*src++);
532 #else
533 *dst++ = htole16(*src++);
534 #endif
537 write(fh, line_block, sizeof(line_block));
539 #endif /* LCD_DEPTH */
542 close(fh);
545 void screen_dump_set_hook(void (*hook)(int fh))
547 screen_dump_hook = hook;
550 #endif /* HAVE_LCD_BITMAP */
552 /* parse a line from a configuration file. the line format is:
554 name: value
556 Any whitespace before setting name or value (after ':') is ignored.
557 A # as first non-whitespace character discards the whole line.
558 Function sets pointers to null-terminated setting name and value.
559 Returns false if no valid config entry was found.
562 bool settings_parseline(char* line, char** name, char** value)
564 char* ptr;
566 while ( isspace(*line) )
567 line++;
569 if ( *line == '#' )
570 return false;
572 ptr = strchr(line, ':');
573 if ( !ptr )
574 return false;
576 *name = line;
577 *ptr = 0;
578 ptr++;
579 while (isspace(*ptr))
580 ptr++;
581 *value = ptr;
582 return true;
585 static void system_flush(void)
587 tree_flush();
588 call_ata_idle_notifys(true); /*doesnt work on usb and shutdown from ata thread */
591 static void system_restore(void)
593 tree_restore();
596 static bool clean_shutdown(void (*callback)(void *), void *parameter)
598 #ifdef SIMULATOR
599 (void)callback;
600 (void)parameter;
601 call_ata_idle_notifys(true);
602 exit(0);
603 #else
604 int i;
606 #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING)
607 if(!charger_inserted())
608 #endif
610 bool batt_crit = battery_level_critical();
611 int audio_stat = audio_status();
613 FOR_NB_SCREENS(i)
614 screens[i].clear_display();
615 #ifdef X5_BACKLIGHT_SHUTDOWN
616 x5_backlight_shutdown();
617 #endif
618 if (!battery_level_safe())
619 gui_syncsplash(3*HZ, "%s %s",
620 str(LANG_WARNING_BATTERY_EMPTY),
621 str(LANG_SHUTTINGDOWN));
622 else if (battery_level_critical())
623 gui_syncsplash(3*HZ, "%s %s",
624 str(LANG_WARNING_BATTERY_LOW),
625 str(LANG_SHUTTINGDOWN));
626 else {
627 #ifdef HAVE_TAGCACHE
628 if (!tagcache_prepare_shutdown())
630 cancel_shutdown();
631 gui_syncsplash(HZ, str(LANG_TAGCACHE_BUSY));
632 return false;
634 #endif
635 gui_syncsplash(0, str(LANG_SHUTTINGDOWN));
638 if (global_settings.fade_on_stop
639 && (audio_stat & AUDIO_STATUS_PLAY))
641 fade(0);
644 #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
645 if (!batt_crit && (audio_stat & AUDIO_STATUS_RECORD))
647 audio_stop_recording();
648 while(audio_status() & AUDIO_STATUS_RECORD)
649 sleep(1);
652 audio_close_recording();
653 #endif
654 /* audio_stop_recording == audio_stop for HWCODEC */
656 audio_stop();
657 while (audio_status())
658 sleep(1);
660 if (callback != NULL)
661 callback(parameter);
663 if (!batt_crit) /* do not save on critical battery */
664 system_flush();
665 #ifdef HAVE_EEPROM_SETTINGS
666 if (firmware_settings.initialized)
668 firmware_settings.disk_clean = true;
669 firmware_settings.bl_version = 0;
670 eeprom_settings_store();
672 #endif
673 shutdown_hw();
675 #endif
676 return false;
679 #if CONFIG_CHARGING
680 static bool waiting_to_resume_play = false;
681 static long play_resume_tick;
683 static void car_adapter_mode_processing(bool inserted)
685 if (global_settings.car_adapter_mode)
687 if(inserted)
690 * Just got plugged in, delay & resume if we were playing
692 if (audio_status() & AUDIO_STATUS_PAUSE)
694 /* delay resume a bit while the engine is cranking */
695 play_resume_tick = current_tick + HZ*5;
696 waiting_to_resume_play = true;
699 else
702 * Just got unplugged, pause if playing
704 if ((audio_status() & AUDIO_STATUS_PLAY) &&
705 !(audio_status() & AUDIO_STATUS_PAUSE))
707 if (global_settings.fade_on_stop)
708 fade(0);
709 else
710 audio_pause();
716 static void car_adapter_tick(void)
718 if (waiting_to_resume_play)
720 if (TIME_AFTER(current_tick, play_resume_tick))
722 if (audio_status() & AUDIO_STATUS_PAUSE)
724 audio_resume();
726 waiting_to_resume_play = false;
731 void car_adapter_mode_init(void)
733 tick_add_task(car_adapter_tick);
735 #endif
737 #ifdef HAVE_HEADPHONE_DETECTION
738 static void unplug_change(bool inserted)
740 if (global_settings.unplug_mode)
742 if (inserted)
744 if ( global_settings.unplug_mode > 1 )
745 audio_resume();
746 backlight_on();
747 } else {
748 audio_pause();
750 if (global_settings.unplug_rw)
752 if ( audio_current_track()->elapsed >
753 (unsigned long)(global_settings.unplug_rw*1000))
754 audio_ff_rewind(audio_current_track()->elapsed -
755 (global_settings.unplug_rw*1000));
756 else
757 audio_ff_rewind(0);
762 #endif
764 long default_event_handler_ex(long event, void (*callback)(void *), void *parameter)
766 switch(event)
768 case SYS_USB_CONNECTED:
769 if (callback != NULL)
770 callback(parameter);
771 #ifdef HAVE_MMC
772 if (!mmc_touched() || (mmc_remove_request() == SYS_MMC_EXTRACTED))
773 #endif
775 scrobbler_flush_cache();
776 system_flush();
777 #ifdef BOOTFILE
778 #ifndef USB_IPODSTYLE
779 check_bootfile(false); /* gets initial size */
780 #endif
781 #endif
782 usb_screen();
783 #ifdef BOOTFILE
784 #ifndef USB_IPODSTYLE
785 check_bootfile(true);
786 #endif
787 #endif
788 system_restore();
790 return SYS_USB_CONNECTED;
791 case SYS_POWEROFF:
792 if (!clean_shutdown(callback, parameter))
793 return SYS_POWEROFF;
794 break;
795 #if CONFIG_CHARGING
796 case SYS_CHARGER_CONNECTED:
797 car_adapter_mode_processing(true);
798 return SYS_CHARGER_CONNECTED;
800 case SYS_CHARGER_DISCONNECTED:
801 car_adapter_mode_processing(false);
802 return SYS_CHARGER_DISCONNECTED;
803 #endif
804 #ifdef HAVE_HEADPHONE_DETECTION
805 case SYS_PHONE_PLUGGED:
806 unplug_change(true);
807 return SYS_PHONE_PLUGGED;
809 case SYS_PHONE_UNPLUGGED:
810 unplug_change(false);
811 return SYS_PHONE_UNPLUGGED;
812 #endif
814 return 0;
817 long default_event_handler(long event)
819 return default_event_handler_ex(event, NULL, NULL);
822 int show_logo( void )
824 #ifdef HAVE_LCD_BITMAP
825 char version[32];
826 int font_h, font_w;
828 lcd_clear_display();
829 lcd_bitmap(rockboxlogo, 0, 10, BMPWIDTH_rockboxlogo, BMPHEIGHT_rockboxlogo);
831 #ifdef HAVE_REMOTE_LCD
832 lcd_remote_clear_display();
833 lcd_remote_bitmap(remote_rockboxlogo, 0, 10, BMPWIDTH_remote_rockboxlogo,
834 BMPHEIGHT_remote_rockboxlogo);
835 #endif
837 snprintf(version, sizeof(version), "Ver. %s", appsversion);
838 lcd_setfont(FONT_SYSFIXED);
839 lcd_getstringsize((unsigned char *)"A", &font_w, &font_h);
840 lcd_putsxy((LCD_WIDTH/2) - ((strlen(version)*font_w)/2),
841 LCD_HEIGHT-font_h, (unsigned char *)version);
842 lcd_update();
844 #ifdef HAVE_REMOTE_LCD
845 lcd_remote_setfont(FONT_SYSFIXED);
846 lcd_remote_getstringsize((unsigned char *)"A", &font_w, &font_h);
847 lcd_remote_putsxy((LCD_REMOTE_WIDTH/2) - ((strlen(version)*font_w)/2),
848 LCD_REMOTE_HEIGHT-font_h, (unsigned char *)version);
849 lcd_remote_update();
850 #endif
852 #else
853 char *rockbox = " ROCKbox!";
854 lcd_clear_display();
855 lcd_double_height(true);
856 lcd_puts(0, 0, rockbox);
857 lcd_puts_scroll(0, 1, appsversion);
858 #endif
860 return 0;
863 #if CONFIG_CODEC == SWCODEC
864 int get_replaygain_mode(bool have_track_gain, bool have_album_gain)
866 int type;
868 bool track = ((global_settings.replaygain_type == REPLAYGAIN_TRACK)
869 || ((global_settings.replaygain_type == REPLAYGAIN_SHUFFLE)
870 && global_settings.playlist_shuffle));
872 type = (!track && have_album_gain) ? REPLAYGAIN_ALBUM
873 : have_track_gain ? REPLAYGAIN_TRACK : -1;
875 return type;
877 #endif
879 #ifdef BOOTFILE
880 #ifndef USB_IPODSTYLE
882 memorize/compare details about the BOOTFILE
883 we don't use dircache because it may not be up to date after
884 USB disconnect (scanning in the background)
886 void check_bootfile(bool do_rolo)
888 static int wrtdate = 0;
889 static int wrttime = 0;
890 DIR* dir = NULL;
891 struct dirent* entry = NULL;
893 /* 1. open BOOTDIR and find the BOOTFILE dir entry */
894 dir = opendir(BOOTDIR);
896 if(!dir) return; /* do we want an error splash? */
898 /* loop all files in BOOTDIR */
899 while(0 != (entry = readdir(dir)))
901 if(!strcasecmp(entry->d_name, BOOTFILE))
903 /* found the bootfile */
904 if(wrtdate && do_rolo)
906 if((entry->wrtdate != wrtdate) ||
907 (entry->wrttime != wrttime))
909 char *lines[] = { str(LANG_BOOT_CHANGED),
910 str(LANG_REBOOT_NOW) };
911 struct text_message message={ lines, 2 };
912 button_clear_queue(); /* Empty the keyboard buffer */
913 if(gui_syncyesno_run(&message, NULL, NULL) == YESNO_YES)
914 rolo_load(BOOTDIR "/" BOOTFILE);
917 wrtdate = entry->wrtdate;
918 wrttime = entry->wrttime;
921 closedir(dir);
923 #endif
924 #endif