summaryrefslogtreecommitdiff
path: root/apps/plugins/favorites.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/favorites.c')
-rw-r--r--apps/plugins/favorites.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/apps/plugins/favorites.c b/apps/plugins/favorites.c
index 949eeeae31..c4b969f920 100644
--- a/apps/plugins/favorites.c
+++ b/apps/plugins/favorites.c
@@ -7,37 +7,35 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
7{ 7{
8 struct mp3entry* id3; 8 struct mp3entry* id3;
9 char track_path[MAX_PATH+1]; 9 char track_path[MAX_PATH+1];
10 int fd, seek, result, len; 10 int fd, result, len;
11 11
12 /* this macro should be called as the first thing you do in the plugin. 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 13 it test that the api version and model the plugin was compiled for
14 matches the machine it is running on */ 14 matches the machine it is running on */
15 TEST_PLUGIN_API(api); 15 TEST_PLUGIN_API(api);
16 16
17 /* if you don't use the parameter, you can do like
18 this to avoid the compiler warning about it */
19 (void)parameter;
20
21 rb = api; 17 rb = api;
22 18
23 id3 = rb->mpeg_current_track(); 19 /* If we were passed a parameter, use that as the file name,
24 if (!id3) { 20 else take the currently playing track */
25 rb->splash(HZ*2, true, "Nothing To Save"); 21 if(parameter) {
26 return PLUGIN_OK; 22 rb->strncpy(track_path, parameter, MAX_PATH);
27 } 23 } else {
28 24 id3 = rb->mpeg_current_track();
29 fd = rb->open(FAVORITES_FILE, O_WRONLY); 25 if (!id3) {
26 rb->splash(HZ*2, true, "Nothing To Save");
27 return PLUGIN_OK;
28 }
29 rb->strncpy(track_path, id3->path, MAX_PATH);
30 }
30 31
31 // creat the file if it does not return on open. 32 track_path[MAX_PATH] = 0;
32 if (fd < 0) 33
33 fd = rb->creat(FAVORITES_FILE, 0); 34 len = rb->strlen(track_path);
34 35
35 if (fd > 0) { 36 fd = rb->open(FAVORITES_FILE, O_CREAT|O_WRONLY|O_APPEND);
36 rb->strcpy(track_path, id3->path);
37 len = rb->strlen(track_path);
38 37
39 // seek to the end of file 38 if (fd >= 0) {
40 seek = rb->lseek(fd, 0, SEEK_END);
41 // append the current mp3 path 39 // append the current mp3 path
42 track_path[len] = '\n'; 40 track_path[len] = '\n';
43 result = rb->write(fd, track_path, len + 1); 41 result = rb->write(fd, track_path, len + 1);
@@ -49,5 +47,3 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
49 47
50 return PLUGIN_OK; 48 return PLUGIN_OK;
51} 49}
52
53