|
Rockbox mail archiveSubject: [Patch] hidden files/dirs and dotfiles[Patch] hidden files/dirs and dotfiles
From: Bill Napier <napier_at_pobox.com>
Date: 21 Aug 2002 14:27:50 -0400 This patch provides two things (in order of importance): 1. Has an option to ignore any file/dir that has a "." as the first character in the filename. This can come in handy with the above feature to hide "hidden" files. Can also come in handy if you have no easy way to set the "hidden" bit on a file (ie. you're doing stuff from the command line or from a UNIX OS and can't set those attributes on a file). Just give it a name starting with "." and it won't be shown in the list (unless you want it to). 2. Has an option to show any file/dir that has the "hidden" attribute set to show up with a "." in front of thier name (as if you mapped a FAT filesystem into an UNIX environment). Both of these options default to "on". Things I had to change to get this working: 1. Had to remove the mp3filter option's check for the hidden attribute. Was this an unadvertised feature? 2. Had to fix the check for "." and ".." as file's in tree.c. The previous code was checking for any file that begins with "." or ".." rather than checking for a file named just "." or "..". This has been tested on on my Player, but I don't have a Recorder to test it on. And as promised, here's a patch: ----------- Begin patch ----------- Index: apps/settings.c =================================================================== RCS file: /cvsroot/rockbox/apps/settings.c,v retrieving revision 1.35 diff -u -b -r1.35 settings.c --- apps/settings.c 21 Aug 2002 06:23:22 -0000 1.35 +++ apps/settings.c 21 Aug 2002 18:23:58 -0000 _at__at_ -259,7 +259,9 _at__at_ ((global_settings.mp3filter & 1) << 1) | ((global_settings.sort_case & 1) << 2) | ((global_settings.discharge & 1) << 3) | - ((global_settings.statusbar & 1) << 4)); + ((global_settings.statusbar & 1) << 4) | + ((global_settings.hidden_as_dotfile & 1) << 5) | + ((global_settings.hide_dotfiles & 1) << 6)); config_block[0xf] = (unsigned char) ((global_settings.scroll_speed << 3) | _at__at_ -345,6 +347,8 _at__at_ global_settings.sort_case = (config_block[0xe] >> 2) & 1; global_settings.discharge = (config_block[0xe] >> 3) & 1; global_settings.statusbar = (config_block[0xe] >> 4) & 1; + global_settings.hidden_as_dotfile = (config_block[0xe] >> 5) & 1; + global_settings.hide_dotfiles = (config_block[0xe] >> 6) & 1; } c = config_block[0xf] >> 3; _at__at_ -410,6 +414,15 _at__at_ global_settings.discharge = 0; global_settings.total_uptime = 0; global_settings.scroll_speed = 8; + global_settings.hidden_as_dotfile = true; + global_settings.hide_dotfiles = true; +#ifndef SIMULATOR + /* It's safer to set it then to ensure that the firware default + * stays matched up with the app default (without having the + * firmware depend on the application) + */ + fat_usedotfiles(global_settings.hidden_as_dotfile); +#endif global_settings.ff_rewind = DEFAULT_FF_REWIND_SETTING; global_settings.resume_index = -1; global_settings.resume_offset = -1; Index: apps/settings.h =================================================================== RCS file: /cvsroot/rockbox/apps/settings.h,v retrieving revision 1.22 diff -u -b -r1.22 settings.h --- apps/settings.h 19 Aug 2002 10:57:55 -0000 1.22 +++ apps/settings.h 21 Aug 2002 18:23:58 -0000 _at__at_ -69,6 +69,10 _at__at_ /* show status bar */ bool statusbar; /* 0=hide, 1=show */ + + /* Hidden and dotfile settings */ + bool hidden_as_dotfile; /* 0=not as dotfile, 1=as dotfile */ + bool hide_dotfiles; /* 0=show dotilfes, 1=hide dotfiles */ /* geeky persistent statistics */ unsigned int total_uptime; /* total uptime since rockbox was first booted */ Index: apps/settings_menu.c =================================================================== RCS file: /cvsroot/rockbox/apps/settings_menu.c,v retrieving revision 1.20 diff -u -b -r1.20 settings_menu.c --- apps/settings_menu.c 19 Aug 2002 10:57:55 -0000 1.20 +++ apps/settings_menu.c 21 Aug 2002 18:23:58 -0000 _at__at_ -32,9 +32,22 _at__at_ #include "settings_menu.h" #include "backlight.h" #include "playlist.h" /* for playlist_shuffle */ +#include "fat.h" /* For dotfile settings */ #include "powermgmt.h" #include "rtc.h" +static void hide_dotfiles_set(void) +{ + set_bool( "[Hide dotfiles]", &global_settings.hide_dotfiles ); +} + +static void hidden_to_dot_set(void) +{ + set_bool( "[Hidden to dotfile]", &global_settings.hidden_as_dotfile ); +#ifndef SIMULATOR + fat_usedotfiles(global_settings.hidden_as_dotfile); +#endif +} static void contrast(void) { _at__at_ -163,6 +176,8 _at__at_ #ifdef HAVE_RTC { "Time/Date", timedate_set }, #endif + { "Hide dotfiles", hide_dotfiles_set }, + { "Hidden to dotfile", hidden_to_dot_set}, { "FF/Rewind", ff_rewind }, { "Resume", resume }, }; Index: apps/tree.c =================================================================== RCS file: /cvsroot/rockbox/apps/tree.c,v retrieving revision 1.95 diff -u -b -r1.95 tree.c --- apps/tree.c 21 Aug 2002 08:13:58 -0000 1.95 +++ apps/tree.c 21 Aug 2002 18:24:00 -0000 _at__at_ -190,15 +190,26 _at__at_ if (!entry) break; + len = strlen(entry->d_name); + /* skip directories . and .. */ if ((entry->attribute & ATTR_DIRECTORY) && - (!strncmp(entry->d_name, ".", 1) || - !strncmp(entry->d_name, "..", 2))) { + (((len == 1) && + (!strncmp(entry->d_name, ".", 1))) || + ((len == 2) && + (!strncmp(entry->d_name, "..", 2))))) { + i--; + continue; + } + + /* Skip dotfiles if set to skip them */ + if (global_settings.hide_dotfiles && + entry->d_name[0]=='.') { i--; continue; } + dptr->attr = entry->attribute; - len = strlen(entry->d_name); /* mark mp3 and m3u files as such */ if ( !(dptr->attr & ATTR_DIRECTORY) && (len > 4) ) { _at__at_ -209,10 +220,9 _at__at_ dptr->attr |= TREE_ATTR_M3U; } - /* filter hidden files and directories and non-mp3 or m3u files */ + /* filter non-mp3 or m3u files */ if ( global_settings.mp3filter && - ((dptr->attr & ATTR_HIDDEN) || - !(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MP3|TREE_ATTR_M3U))) ) { + (!(dptr->attr & (ATTR_DIRECTORY|TREE_ATTR_MP3|TREE_ATTR_M3U))) ) { i--; continue; } _at__at_ -616,11 +626,20 _at__at_ case TREE_MENU: { bool lastfilter = global_settings.mp3filter; bool lastsortcase = global_settings.sort_case; + bool lasthidden_as_dotfile = global_settings.hidden_as_dotfile; + bool lasthide_dotfiles = global_settings.hide_dotfiles; + +#ifdef HAVE_LCD_BITMAP + bool laststate=statusbar(false); +#endif + lcd_stop_scroll(); main_menu(); /* do we need to rescan dir? */ if ( lastfilter != global_settings.mp3filter || - lastsortcase != global_settings.sort_case) + lastsortcase != global_settings.sort_case || + lasthidden_as_dotfile != global_settings.hidden_as_dotfile || + lasthide_dotfiles != global_settings.hide_dotfiles) lastdir[0] = 0; restore = true; break; Index: firmware/drivers/fat.c =================================================================== RCS file: /cvsroot/rockbox/firmware/drivers/fat.c,v retrieving revision 1.30 diff -u -b -r1.30 fat.c --- firmware/drivers/fat.c 14 Aug 2002 16:39:39 -0000 1.30 +++ firmware/drivers/fat.c 21 Aug 2002 18:24:03 -0000 _at__at_ -160,6 +160,8 _at__at_ static struct bpb fat_bpb; +static bool use_dot_files = true; + static int first_sector_of_cluster(int cluster); static int bpb_is_sane(void); static void *cache_fat_sector(int secnum); _at__at_ -856,6 +858,11 _at__at_ de->firstcluster = BYTES2INT16(buf,FATDIR_FSTCLUSLO) | (BYTES2INT16(buf,FATDIR_FSTCLUSHI) << 16); + if (use_dot_files && + (de->attr & FAT_ATTR_HIDDEN)) { + de->name[j++]='.'; + } + /* fix the name */ for (i=0; (i<8) && (buf[FATDIR_NAME+i] != ' '); i++) de->name[j++] = buf[FATDIR_NAME+i]; _at__at_ -864,6 +871,7 _at__at_ for (i=8; (i<11) && (buf[FATDIR_NAME+i] != ' '); i++) de->name[j++] = buf[FATDIR_NAME+i]; } + return 1; } _at__at_ -1001,6 +1009,10 _at__at_ return 0; } +void fat_usedotfiles(bool set) { + use_dot_files=set; +} + int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry) { int done = 0; _at__at_ -1044,6 +1056,12 _at__at_ /* replace shortname with longname? */ if ( longs ) { int j,k,l=0; + + if (use_dot_files && + (entry->attr & FAT_ATTR_HIDDEN)) { + entry->name[l++]='.'; + } + /* iterate backwards through the dir entries */ for (j=longs-1; j>=0; j--) { unsigned char* ptr = dir->cached_buf; Index: firmware/drivers/fat.h =================================================================== RCS file: /cvsroot/rockbox/firmware/drivers/fat.h,v retrieving revision 1.12 diff -u -b -r1.12 fat.h --- firmware/drivers/fat.h 13 Aug 2002 13:21:55 -0000 1.12 +++ firmware/drivers/fat.h 21 Aug 2002 18:24:03 -0000 _at__at_ -62,6 +62,8 _at__at_ extern int fat_mount(int startsector); +extern void fat_usedotfiles(bool set); + #ifdef DISK_WRITE extern int fat_create_file(unsigned int currdir, char *name); extern int fat_create_dir(unsigned int currdir, char *name); ----------- End patch ----------- -- space for rentReceived on 2002-08-21 Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy |