Index: apps/plugins/m3u_cleaner.c =================================================================== --- apps/plugins/m3u_cleaner.c (revision 0) +++ apps/plugins/m3u_cleaner.c (revision 0) @@ -0,0 +1,105 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: m3u_cleaner.c 12807 2007-11-11 $ + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "plugin.h" +PLUGIN_HEADER + +static struct plugin_api* rb; + +void clean_playlist(const unsigned char* playlist_name){ + rb->splash(HZ,"Clean %s",playlist_name); + size_t size=PLUGIN_BUFFER_SIZE; + int entries_size=0; + bool have_bad_entries=false; + char* entry=rb->plugin_get_buffer(&size); + char* first=entry; + char* str; + int len; + int entry_fd; + int fd=rb->open(playlist_name, O_RDWR); + if(fd>=0){ + /* check playlist entries */ + while((len=rb->read_line(fd, entry, MAX_PATH))>0){ + str=entry; + while (*str!=0){ /* replace \ with / */ + if ( *str == '\\' ) *str = '/'; + str++; + } + if((entry_fd=rb->open(entry, O_RDONLY))>0){ /* entry o.k. */ + rb->close(entry_fd); /* close it again */ + entries_size+=str-entry+1; /* cannot use len, because of \r\n */ + entry=str+1; /* next entry points to the end of the current entry */ + *str='\n'; /* replace 0 with \n */ + } + else{ + rb->splash(HZ,"Invalid: '%s'",entry); + have_bad_entries=true; + } + if(rb->button_get(false)!=BUTTON_NONE){ /* press any button to abort */ + have_bad_entries=false; + break; + } + } + if(have_bad_entries){ /* only modify file if it has invalid entries */ + /* preparing */ + rb->ftruncate(fd,entries_size); + rb->lseek(fd, 0, SEEK_SET); + rb->write(fd,first,entries_size); + } + rb->close(fd); + } + int i; + FOR_NB_SCREENS(i){ + rb->screens[i]->clear_display(); + rb->screens[i]->update(); + } +} +void clean_playlist_dir(const unsigned char* playlist_dir){ + struct dirent *entry; + DIR* dir; + unsigned char* ext; + char fullpath[MAX_PATH]; + dir = rb->opendir(playlist_dir); + if (dir) { + while((entry=rb->readdir(dir))!=0){ /* looking for playlists in dir */ + if(rb->button_get(false)!=BUTTON_NONE) break; /* press any button to abort */ + ext=rb->strrchr(entry->d_name,'.')+1; + if(rb->strncasecmp(ext, "m3u",3)==0){ /* check if it's a playlist */ + rb->snprintf(fullpath,MAX_PATH,"%s/%s",playlist_dir,entry->d_name); + clean_playlist(fullpath); + } + } + rb->closedir(dir); + } + else + rb->splash(HZ,"Directory '%s' not found!",playlist_dir); +} + +/* this is the plugin entry point */ +enum plugin_status plugin_start(struct plugin_api* api, void* parameter) +{ + /* if you don't use the parameter, you can do like + this to avoid the compiler warning about it */ + (void)parameter; + + /* if you are using a global api pointer, don't forget to copy it! + otherwise you will get lovely "I04: IllInstr" errors... :-) */ + rb = api; + + clean_playlist_dir("/Playlists"); + + return PLUGIN_OK; +} Property changes on: apps/plugins/m3u_cleaner.c ___________________________________________________________________ Name: svn:executable + * Index: apps/plugins/SOURCES =================================================================== --- apps/plugins/SOURCES (revision 15578) +++ apps/plugins/SOURCES (working copy) @@ -19,6 +19,7 @@ stopwatch.c vbrfix.c viewer.c +m3u_cleaner.c #ifdef OLYMPUS_MROBE_500 /* remove these once the plugins before it are compileable */ Index: apps/plugins/CATEGORIES =================================================================== --- apps/plugins/CATEGORIES (revision 15578) +++ apps/plugins/CATEGORIES (working copy) @@ -91,3 +91,4 @@ wormlet,games xobox,games zxbox,viewers +m3u_cleaner,apps \ No newline at end of file