* removed some more unused stuff in the simulator makefile
[kugel-rb.git] / apps / plugins / favorites.c
blob949eeeae313226d14b67321996840bf29b5388e3
1 #include "plugin.h"
2 #define FAVORITES_FILE "/favorites.m3u"
4 static struct plugin_api* rb;
6 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
8 struct mp3entry* id3;
9 char track_path[MAX_PATH+1];
10 int fd, seek, result, len;
12 /* this macro should be called as the first thing you do in the plugin.
13 it test that the api version and model the plugin was compiled for
14 matches the machine it is running on */
15 TEST_PLUGIN_API(api);
17 /* if you don't use the parameter, you can do like
18 this to avoid the compiler warning about it */
19 (void)parameter;
21 rb = api;
23 id3 = rb->mpeg_current_track();
24 if (!id3) {
25 rb->splash(HZ*2, true, "Nothing To Save");
26 return PLUGIN_OK;
29 fd = rb->open(FAVORITES_FILE, O_WRONLY);
31 // creat the file if it does not return on open.
32 if (fd < 0)
33 fd = rb->creat(FAVORITES_FILE, 0);
35 if (fd > 0) {
36 rb->strcpy(track_path, id3->path);
37 len = rb->strlen(track_path);
39 // seek to the end of file
40 seek = rb->lseek(fd, 0, SEEK_END);
41 // append the current mp3 path
42 track_path[len] = '\n';
43 result = rb->write(fd, track_path, len + 1);
44 track_path[len] = '\0';
45 rb->close(fd);
48 rb->splash(HZ*2, true, "Saved Favorite");
50 return PLUGIN_OK;