/** * playlist_free: * @playlist : Playlist handle. * * Frees playlist handle. */ void playlist_free(playlist_t *playlist) { size_t i; if (!playlist) return; if (playlist->conf_path != NULL) free(playlist->conf_path); playlist->conf_path = NULL; for (i = 0; i < playlist->size; i++) { struct playlist_entry *entry = &playlist->entries[i]; if (entry) playlist_free_entry(entry); } free(playlist->entries); playlist->entries = NULL; free(playlist); }
/** * playlist_clear: * @playlist : Playlist handle. * * Clears all playlist entries in playlist. **/ void playlist_clear(playlist_t *playlist) { size_t i; if (!playlist) return; for (i = 0; i < playlist->size; i++) { struct playlist_entry *entry = &playlist->entries[i]; if (entry) playlist_free_entry(entry); } playlist->size = 0; }
/** * playlist_push: * @playlist : Playlist handle. * @path : Path of new playlist entry. * @core_path : Core path of new playlist entry. * @core_name : Core name of new playlist entry. * * Push entry to top of playlist. **/ bool playlist_push(playlist_t *playlist, const char *path, const char *label, const char *core_path, const char *core_name, const char *crc32, const char *db_name) { size_t i; bool core_path_empty = string_is_empty(core_path); bool core_name_empty = string_is_empty(core_name); if (core_path_empty || core_name_empty) { if (core_name_empty && !core_path_empty) { static char base_path[255] = {0}; fill_pathname_base_noext(base_path, core_path, sizeof(base_path)); core_name = base_path; } if (core_path_empty || core_name_empty) { RARCH_ERR("cannot push NULL or empty core name into the playlist.\n"); return false; } } if (string_is_empty(path)) path = NULL; if (!playlist) return false; for (i = 0; i < playlist->size; i++) { struct playlist_entry tmp; bool equal_path; equal_path = (!path && !playlist->entries[i].path) || (path && playlist->entries[i].path && #ifdef _WIN32 /*prevent duplicates on case-insensitive operating systems*/ string_is_equal_noncase(path,playlist->entries[i].path) #else string_is_equal(path,playlist->entries[i].path) #endif ); /* Core name can have changed while still being the same core. * Differentiate based on the core path only. */ if (!equal_path) continue; if (!string_is_equal(playlist->entries[i].core_path, core_path)) continue; /* If top entry, we don't want to push a new entry since * the top and the entry to be pushed are the same. */ if (i == 0) return false; /* Seen it before, bump to top. */ tmp = playlist->entries[i]; memmove(playlist->entries + 1, playlist->entries, i * sizeof(struct playlist_entry)); playlist->entries[0] = tmp; goto success; } if (playlist->size == playlist->cap) { struct playlist_entry *entry = &playlist->entries[playlist->cap - 1]; if (entry) playlist_free_entry(entry); playlist->size--; } if (playlist->entries) { memmove(playlist->entries + 1, playlist->entries, (playlist->cap - 1) * sizeof(struct playlist_entry)); playlist->entries[0].path = NULL; playlist->entries[0].label = NULL; playlist->entries[0].core_path = NULL; playlist->entries[0].core_name = NULL; playlist->entries[0].db_name = NULL; playlist->entries[0].crc32 = NULL; if (!string_is_empty(path)) playlist->entries[0].path = strdup(path); if (!string_is_empty(label)) playlist->entries[0].label = strdup(label); if (!string_is_empty(core_path)) playlist->entries[0].core_path = strdup(core_path); if (!string_is_empty(core_name)) playlist->entries[0].core_name = strdup(core_name); if (!string_is_empty(db_name)) playlist->entries[0].db_name = strdup(db_name); if (!string_is_empty(crc32)) playlist->entries[0].crc32 = strdup(crc32); } playlist->size++; success: playlist->modified = true; return true; }
/** * playlist_push: * @playlist : Playlist handle. * @path : Path of new playlist entry. * @core_path : Core path of new playlist entry. * @core_name : Core name of new playlist entry. * * Push entry to top of playlist. **/ bool playlist_push(playlist_t *playlist, const char *path, const char *label, const char *core_path, const char *core_name, const char *crc32, const char *db_name) { size_t i; if (string_is_empty(core_path) || string_is_empty(core_name)) { if (string_is_empty(core_name) && !string_is_empty(core_path)) { static char base_path[255] = {0}; fill_pathname_base_noext(base_path, core_path, sizeof(base_path)); core_name = base_path; RARCH_LOG("core_name is now: %s\n", core_name); } RARCH_LOG("core_name: %s.\n", string_is_empty(core_name) ? "N/A" : core_name); RARCH_LOG("core_path: %s.\n", string_is_empty(core_path) ? "N/A" : core_path); if (string_is_empty(core_path) || string_is_empty(core_name)) { RARCH_ERR("cannot push NULL or empty core name into the playlist.\n"); return false; } } if (string_is_empty(path)) path = NULL; if (!playlist) return false; for (i = 0; i < playlist->size; i++) { struct playlist_entry tmp; bool equal_path = (!path && !playlist->entries[i].path) || (path && playlist->entries[i].path && string_is_equal(path,playlist->entries[i].path)); /* Core name can have changed while still being the same core. * Differentiate based on the core path only. */ if (!equal_path) continue; if (!string_is_equal(playlist->entries[i].core_path, core_path)) continue; /* If top entry, we don't want to push a new entry since * the top and the entry to be pushed are the same. */ if (i == 0) return false; /* Seen it before, bump to top. */ tmp = playlist->entries[i]; memmove(playlist->entries + 1, playlist->entries, i * sizeof(struct playlist_entry)); playlist->entries[0] = tmp; return true; } if (playlist->size == playlist->cap) { struct playlist_entry *entry = &playlist->entries[playlist->cap - 1]; if (entry) playlist_free_entry(entry); playlist->size--; } memmove(playlist->entries + 1, playlist->entries, (playlist->cap - 1) * sizeof(struct playlist_entry)); playlist->entries[0].path = NULL; playlist->entries[0].label = NULL; playlist->entries[0].core_path = NULL; playlist->entries[0].core_name = NULL; playlist->entries[0].db_name = NULL; playlist->entries[0].crc32 = NULL; if (!string_is_empty(path)) playlist->entries[0].path = strdup(path); if (!string_is_empty(label)) playlist->entries[0].label = strdup(label); if (!string_is_empty(core_path)) playlist->entries[0].core_path = strdup(core_path); if (!string_is_empty(core_name)) playlist->entries[0].core_name = strdup(core_name); if (!string_is_empty(db_name)) playlist->entries[0].db_name = strdup(db_name); if (!string_is_empty(crc32)) playlist->entries[0].crc32 = strdup(crc32); playlist->size++; return true; }