91
95
(strcmp((oi->Filename + strlen(oi->Filename) -4), ".spl") == 0);
101
# define mkstemp(_pattern) _open(_mktemp(_pattern), _O_CREAT | _O_SHORT_LIVED | _O_EXCL)
103
# error Missing mkstemp() function.
95
108
* Take an object ID, a .spl playlist on the MTP device,
96
109
* and convert it to a playlist_t object.
108
121
// Use the Filename as the playlist name, dropping the ".spl" extension
109
122
pl->name = malloc(sizeof(char)*(strlen(oi->Filename) -4 +1));
110
123
memcpy(pl->name, oi->Filename, strlen(oi->Filename) -4);
124
// Set terminating character
125
pl->name[strlen(oi->Filename) - 4] = 0;
111
126
pl->playlist_id = id;
112
127
pl->parent_id = oi->ParentObject;
113
128
pl->storage_id = oi->StorageID;
245
260
* @return 0 on success, any other value means failure.
247
262
int update_spl_playlist(LIBMTP_mtpdevice_t *device,
248
LIBMTP_playlist_t * const new)
263
LIBMTP_playlist_t * const newlist)
250
IF_DEBUG() printf("pl->name='%s'\n",new->name);
265
IF_DEBUG() printf("pl->name='%s'\n",newlist->name);
252
267
// read in the playlist of interest
253
LIBMTP_playlist_t * old = LIBMTP_Get_Playlist(device, new->playlist_id);
268
LIBMTP_playlist_t * old = LIBMTP_Get_Playlist(device, newlist->playlist_id);
270
// check to see if we found it
255
274
// check if the playlists match
258
if(old->no_tracks != new->no_tracks)
277
if(old->no_tracks != newlist->no_tracks)
260
for(i=0;i<new->no_tracks && delta==0;i++) {
261
if(old->tracks[i] != new->tracks[i])
279
for(i=0;i<newlist->no_tracks && delta==0;i++) {
280
if(old->tracks[i] != newlist->tracks[i])
274
if(strcmp(old->name,new->name) == 0)
293
if(strcmp(old->name,newlist->name) == 0)
275
294
printf("name unchanged\n");
277
printf("name is changing too -> %s\n",new->name);
296
printf("name is changing too -> %s\n",newlist->name);
280
return LIBMTP_Create_New_Playlist(device, new);
299
return LIBMTP_Create_New_Playlist(device, newlist);
284
303
// update the name only
285
if(strcmp(old->name,new->name) != 0) {
286
IF_DEBUG() printf("ONLY name is changing -> %s\n",new->name);
304
if(strcmp(old->name,newlist->name) != 0) {
305
IF_DEBUG() printf("ONLY name is changing -> %s\n",newlist->name);
287
306
IF_DEBUG() printf("playlist_id will remain unchanged\n");
288
char* s = malloc(sizeof(char)*(strlen(new->name)+5));
289
strcpy(s, new->name);
307
char* s = malloc(sizeof(char)*(strlen(newlist->name)+5));
308
strcpy(s, newlist->name);
290
309
strcat(s,".spl"); // FIXME check for success
291
int ret = LIBMTP_Set_Playlist_Name(device, new, s);
310
int ret = LIBMTP_Set_Playlist_Name(device, newlist, s);