void clients_player_disappeared(context_t *ctx, const char *name) { clients_t *clients; player_t *player, *removed; if (ctx && (clients = ctx->clients) && clients->player.name) { if ((player = mrp_htbl_lookup(clients->player.name, (void *)name))) { removed = mrp_htbl_remove(clients->player.addr, (void *)player->address, FALSE); if (player != removed) { mrp_log_error("mpris2 client: confused with data structures " "when removing '%s'", player->address); } else { mrp_free((void *)player->address); player->address = NULL; player->state = UNKNOWN; player->ready = false; playlist_free(player->nlist, player->lists); player->nlist = 0; player->lists = NULL; player->active_list = NULL; mrp_log_info("mrpis2 client '%s' disappeared", name); } } } }
void MainWindow::deleteCurrentPlaylistItem() { QString playlistPath = getCurrentPlaylistPath(); QByteArray playlistArray; QHash<QString, QString> contentHash = getCurrentContentHash(); playlist_t *playlist = NULL; const char *playlistData = NULL; unsigned index = 0; bool ok = false; if (playlistPath.isEmpty()) return; if (contentHash.isEmpty()) return; playlistArray = playlistPath.toUtf8(); playlistData = playlistArray.constData(); index = contentHash.value("index").toUInt(&ok); if (!ok) return; if (!showMessageBox(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST_ITEM)).arg(contentHash["label"]), MainWindow::MSGBOX_TYPE_QUESTION_YESNO, Qt::ApplicationModal, false)) return; playlist = playlist_init(playlistData, COLLECTION_SIZE); playlist_delete_index(playlist, index); playlist_write_file(playlist); playlist_free(playlist); reloadPlaylists(); }
void clients_playlist_changed(player_t *player, size_t nlist,playlist_t *lists) { context_t *ctx; playlist_t *list, *active; size_t i, idx_of_active_list; if (!player || !(ctx = player->ctx)) return; idx_of_active_list = 0; if ((active = player->active_list)) { for (i = 0; i < nlist; i++) { list = lists + i; if (!strcmp(active->id, list->id)) { idx_of_active_list = i; break; } } } playlist_free(player->nlist, player->lists); player->nlist = nlist; player->lists = playlist_dup(nlist, lists); player->active_list = player->lists + idx_of_active_list; }
static void player_free(void *key, void *object) { player_t *player = (player_t *)object; context_t *ctx; srs_plugin_t *pl; srs_context_t *srs; pa_mainloop_api *api; if (strcmp(key, player->name)) mrp_log_error("mpris2-client: corrupt hashtable (key '%s')", (char *)key); else { if (player->timer && (ctx = player->ctx) && (pl = ctx->plugin) && (srs = pl->srs) && (api = srs->pa)) { api->time_free(player->timer); } mrp_free((void *)player->name); mrp_free((void *)player->service); mrp_free((void *)player->object); mrp_free((void *)player); playlist_free(player->nlist, player->lists); } }
/* * Deletes playlist from disk and destroy's the object, free()'ing all * memory. */ void playlist_delete(playlist *p) { /* delete file if the playlist is stored in a file */ if (p->filename != NULL && unlink(p->filename) != 0) err(1, "playlist_delete: failed to delete playlist \"%s\"", p->filename); /* destroy/free() all memory */ playlist_free(p); }
static void dynamic_destroy(void) { wchain_free(); songlist_free(songlist); directory_free(directory); playlist_free(playlist); visualizer_free(visualizer); }
playlist_t * playlist_program(const char *filename) { playlist_t *pl; #ifdef HAVE_STAT struct stat st; #else FILE *filep; #endif pl = playlist_create(filename); pl->program = 1; #ifdef HAVE_STAT if (stat(filename, &st) == -1) { printf("%s: %s: %s\n", __progname, filename, strerror(errno)); playlist_free(&pl); return (NULL); } if (st.st_mode & (S_IWGRP | S_IWOTH)) { printf("%s: Error: %s is group and/or world writeable\n", __progname, filename); playlist_free(&pl); return (NULL); } if (!(st.st_mode & (S_IEXEC | S_IXGRP | S_IXOTH))) { printf("%s: %s: Not an executable program\n", __progname, filename); playlist_free(&pl); return (NULL); } #else if ((filep = fopen(filename, "r")) == NULL) { printf("%s: %s: %s\n", __progname, filename, strerror(errno)); playlist_free(&pl); return (NULL); } fclose(filep); #endif /* HAVE_STAT */ return (pl); }
static int task_database_iterate_playlist_lutro( db_handle_t *_db, database_state_handle_t *db_state, database_info_handle_t *db, const char *path) { char *db_playlist_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); playlist_t *playlist = NULL; db_playlist_path[0] = '\0'; if (!string_is_empty(_db->playlist_directory)) fill_pathname_join(db_playlist_path, _db->playlist_directory, file_path_str(FILE_PATH_LUTRO_PLAYLIST), PATH_MAX_LENGTH * sizeof(char)); playlist = playlist_init(db_playlist_path, COLLECTION_SIZE); free(db_playlist_path); if(!playlist_entry_exists(playlist, path, file_path_str(FILE_PATH_DETECT))) { char *game_title = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); game_title[0] = '\0'; fill_short_pathname_representation_noext(game_title, path, PATH_MAX_LENGTH * sizeof(char)); playlist_push(playlist, path, game_title, file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_LUTRO_PLAYLIST)); free(game_title); } playlist_write_file(playlist); playlist_free(playlist); return 0; }
int cmd_filter(int argc, char *argv[]) { playlist *results; char *search_phrase; bool match; int i; if (argc == 1) { paint_error("usage: filter[!] token [token2 ...]"); return 1; } /* determine what kind of filter we're doing */ match = argv[0][strlen(argv[0]) - 1] != '!'; /* set the raw query */ search_phrase = argv2str(argc - 1, argv + 1); mi_query_setraw(search_phrase); free(search_phrase); /* clear existing global query & set new one */ mi_query_clear(); for (i = 1; i < argc; i++) mi_query_add_token(argv[i]); /* do actual filter */ results = playlist_filter(viewing_playlist, match); /* swap necessary bits of results with filter playlist */ swap(meta_info **, results->files, mdb.filter_results->files); swap(int, results->nfiles, mdb.filter_results->nfiles); swap(int, results->capacity, mdb.filter_results->capacity); playlist_free(results); /* redraw */ setup_viewing_playlist(mdb.filter_results); paint_library(); paint_playlist(); return 0; }
static int task_database_iterate_playlist_lutro( database_state_handle_t *db_state, database_info_handle_t *db, const char *path) { char db_playlist_path[PATH_MAX_LENGTH]; playlist_t *playlist = NULL; settings_t *settings = config_get_ptr(); db_playlist_path[0] = '\0'; fill_pathname_join(db_playlist_path, settings->directory.playlist, file_path_str(FILE_PATH_LUTRO_PLAYLIST), sizeof(db_playlist_path)); playlist = playlist_init(db_playlist_path, COLLECTION_SIZE); if(!playlist_entry_exists(playlist, path, file_path_str(FILE_PATH_DETECT))) { char game_title[PATH_MAX_LENGTH]; game_title[0] = '\0'; fill_short_pathname_representation_noext(game_title, path, sizeof(game_title)); playlist_push(playlist, path, game_title, file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_LUTRO_PLAYLIST)); } playlist_write_file(playlist); playlist_free(playlist); return 0; }
/** * playlist_init: * @path : Path to playlist contents file. * @size : Maximum capacity of playlist size. * * Creates and initializes a playlist. * * Returns: handle to new playlist if successful, otherwise NULL **/ playlist_t *playlist_init(const char *path, size_t size) { playlist_t *playlist = (playlist_t*) calloc(1, sizeof(*playlist)); if (!playlist) return NULL; playlist->entries = (struct playlist_entry*)calloc(size, sizeof(*playlist->entries)); if (!playlist->entries) goto error; playlist->cap = size; playlist_read_file(playlist, path); playlist->conf_path = strdup(path); return playlist; error: playlist_free(playlist); return NULL; }
int playlist_reread(playlist_t **plist) { playlist_t *new_pl, *pl; if (plist == NULL || *plist == NULL) { printf("%s: playlist_reread(): Internal error: NULL argument\n", __progname); exit(1); } pl = *plist; if (pl->program) return (0); if ((new_pl = playlist_read(pl->filename)) == NULL) return (0); playlist_free(&pl); *plist = new_pl; return (1); }
QVector<QHash<QString, QString> > MainWindow::getPlaylistItems(QString pathString) { QByteArray pathArray; QVector<QHash<QString, QString> > items; const char *pathData = NULL; playlist_t *playlist = NULL; unsigned playlistSize = 0; unsigned i = 0; pathArray.append(pathString); pathData = pathArray.constData(); playlist = playlist_init(pathData, COLLECTION_SIZE); playlistSize = playlist_get_size(playlist); for (i = 0; i < playlistSize; i++) { const char *path = NULL; const char *label = NULL; const char *core_path = NULL; const char *core_name = NULL; const char *crc32 = NULL; const char *db_name = NULL; QHash<QString, QString> hash; playlist_get_index(playlist, i, &path, &label, &core_path, &core_name, &crc32, &db_name); if (string_is_empty(path)) continue; else hash["path"] = path; hash["index"] = QString::number(i); if (string_is_empty(label)) { hash["label"] = path; hash["label_noext"] = path; } else { hash["label"] = label; hash["label_noext"] = label; } if (!string_is_empty(core_path)) hash["core_path"] = core_path; if (!string_is_empty(core_name)) hash["core_name"] = core_name; if (!string_is_empty(crc32)) hash["crc32"] = crc32; if (!string_is_empty(db_name)) { hash["db_name"] = db_name; hash["db_name"].remove(file_path_str(FILE_PATH_LPL_EXTENSION)); } items.append(hash); } playlist_free(playlist); playlist = NULL; return items; }
bool MainWindow::updateCurrentPlaylistEntry(const QHash<QString, QString> &contentHash) { QString playlistPath = getCurrentPlaylistPath(); QString path; QString label; QString corePath; QString coreName; QString dbName; QString crc32; QByteArray playlistPathArray; QByteArray pathArray; QByteArray labelArray; QByteArray corePathArray; QByteArray coreNameArray; QByteArray dbNameArray; QByteArray crc32Array; const char *playlistPathData = NULL; const char *pathData = NULL; const char *labelData = NULL; const char *corePathData = NULL; const char *coreNameData = NULL; const char *dbNameData = NULL; const char *crc32Data = NULL; playlist_t *playlist = NULL; unsigned index = 0; bool ok = false; if (playlistPath.isEmpty() || contentHash.isEmpty() || !contentHash.contains("index")) return false; index = contentHash.value("index").toUInt(&ok); if (!ok) return false; path = contentHash.value("path"); label = contentHash.value("label"); coreName = contentHash.value("core_name"); corePath = contentHash.value("core_path"); dbName = contentHash.value("db_name"); crc32 = contentHash.value("crc32"); if (path.isEmpty() || label.isEmpty() || coreName.isEmpty() || corePath.isEmpty() || dbName.isEmpty() || crc32.isEmpty() ) return false; playlistPathArray = playlistPath.toUtf8(); pathArray = QDir::toNativeSeparators(path).toUtf8(); labelArray = label.toUtf8(); coreNameArray = coreName.toUtf8(); corePathArray = QDir::toNativeSeparators(corePath).toUtf8(); dbNameArray = (dbName + file_path_str(FILE_PATH_LPL_EXTENSION)).toUtf8(); crc32Array = crc32.toUtf8(); playlistPathData = playlistPathArray.constData(); pathData = pathArray.constData(); labelData = labelArray.constData(); coreNameData = coreNameArray.constData(); corePathData = corePathArray.constData(); dbNameData = dbNameArray.constData(); crc32Data = crc32Array.constData(); if (path_is_compressed_file(pathData)) { struct string_list *list = file_archive_get_file_list(pathData, NULL); if (list) { if (list->size == 1) { /* assume archives with one file should have that file loaded directly */ pathArray = QDir::toNativeSeparators(QString(pathData) + "#" + list->elems[0].data).toUtf8(); pathData = pathArray.constData(); } string_list_free(list); } } playlist = playlist_init(playlistPathData, COLLECTION_SIZE); playlist_update(playlist, index, pathData, labelData, corePathData, coreNameData, crc32Data, dbNameData); playlist_write_file(playlist); playlist_free(playlist); reloadPlaylists(); return true; }
static int database_info_list_iterate_found_match( database_state_handle_t *db_state, database_info_handle_t *db, const char *zip_name ) { char db_crc[PATH_MAX_LENGTH] = {0}; char db_playlist_path[PATH_MAX_LENGTH] = {0}; char db_playlist_base_str[PATH_MAX_LENGTH] = {0}; char entry_path_str[PATH_MAX_LENGTH] = {0}; playlist_t *playlist = NULL; settings_t *settings = config_get_ptr(); const char *db_path = db_state->list->elems[ db_state->list_index].data; const char *entry_path = db ? db->list->elems[ db->list_ptr].data : NULL; database_info_t *db_info_entry = &db_state->info->list[ db_state->entry_index]; fill_short_pathname_representation(db_playlist_base_str, db_path, sizeof(db_playlist_base_str)); path_remove_extension(db_playlist_base_str); strlcat(db_playlist_base_str, ".lpl", sizeof(db_playlist_base_str)); fill_pathname_join(db_playlist_path, settings->directory.playlist, db_playlist_base_str, sizeof(db_playlist_path)); playlist = playlist_init(db_playlist_path, COLLECTION_SIZE); snprintf(db_crc, sizeof(db_crc), "%08X|crc", db_info_entry->crc32); if (entry_path) strlcpy(entry_path_str, entry_path, sizeof(entry_path_str)); if (!string_is_empty(zip_name)) fill_pathname_join_delim(entry_path_str, entry_path_str, zip_name, '#', sizeof(entry_path_str)); #if 0 RARCH_LOG("Found match in database !\n"); RARCH_LOG("Path: %s\n", db_path); RARCH_LOG("CRC : %s\n", db_crc); RARCH_LOG("Playlist Path: %s\n", db_playlist_path); RARCH_LOG("Entry Path: %s\n", entry_path); RARCH_LOG("Playlist not NULL: %d\n", playlist != NULL); RARCH_LOG("ZIP entry: %s\n", zip_name); RARCH_LOG("entry path str: %s\n", entry_path_str); #endif if(!playlist_entry_exists(playlist, entry_path_str, db_crc)) { playlist_push(playlist, entry_path_str, db_info_entry->name, "DETECT", "DETECT", db_crc, db_playlist_base_str); } playlist_write_file(playlist); playlist_free(playlist); database_info_list_free(db_state->info); db_state->info = NULL; db_state->crc = 0; return 0; }
static int database_info_list_iterate_found_match( db_handle_t *_db, database_state_handle_t *db_state, database_info_handle_t *db, const char *archive_name ) { char *db_crc = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *db_playlist_base_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *db_playlist_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *entry_path_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); playlist_t *playlist = NULL; const char *db_path = database_info_get_current_name(db_state); const char *entry_path = database_info_get_current_element_name(db); database_info_t *db_info_entry = &db_state->info->list[db_state->entry_index]; char *hash; db_crc[0] = '\0'; db_playlist_path[0] = '\0'; db_playlist_base_str[0] = '\0'; entry_path_str[0] = '\0'; fill_short_pathname_representation_noext(db_playlist_base_str, db_path, PATH_MAX_LENGTH * sizeof(char)); strlcat(db_playlist_base_str, file_path_str(FILE_PATH_LPL_EXTENSION), PATH_MAX_LENGTH * sizeof(char)); if (!string_is_empty(_db->playlist_directory)) fill_pathname_join(db_playlist_path, _db->playlist_directory, db_playlist_base_str, PATH_MAX_LENGTH * sizeof(char)); playlist = playlist_init(db_playlist_path, COLLECTION_SIZE); snprintf(db_crc, PATH_MAX_LENGTH * sizeof(char), "%08X|crc", db_info_entry->crc32); if (entry_path) strlcpy(entry_path_str, entry_path, PATH_MAX_LENGTH * sizeof(char)); if (!string_is_empty(archive_name)) fill_pathname_join_delim(entry_path_str, entry_path_str, archive_name, '#', PATH_MAX_LENGTH * sizeof(char)); if (core_info_database_match_archive_member( db_state->list->elems[db_state->list_index].data) && (hash = strchr(entry_path_str, '#'))) *hash = '\0'; #if defined(RARCH_INTERNAL) #if 0 RARCH_LOG("Found match in database !\n"); RARCH_LOG("Path: %s\n", db_path); RARCH_LOG("CRC : %s\n", db_crc); RARCH_LOG("Playlist Path: %s\n", db_playlist_path); RARCH_LOG("Entry Path: %s\n", entry_path); RARCH_LOG("Playlist not NULL: %d\n", playlist != NULL); RARCH_LOG("ZIP entry: %s\n", archive_name); RARCH_LOG("entry path str: %s\n", entry_path_str); #endif #else fprintf(stderr, "Found match in database !\n"); fprintf(stderr, "Path: %s\n", db_path); fprintf(stderr, "CRC : %s\n", db_crc); fprintf(stderr, "Playlist Path: %s\n", db_playlist_path); fprintf(stderr, "Entry Path: %s\n", entry_path); fprintf(stderr, "Playlist not NULL: %d\n", playlist != NULL); fprintf(stderr, "ZIP entry: %s\n", archive_name); fprintf(stderr, "entry path str: %s\n", entry_path_str); #endif if(!playlist_entry_exists(playlist, entry_path_str, db_crc)) { playlist_push(playlist, entry_path_str, db_info_entry->name, file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), db_crc, db_playlist_base_str); } playlist_write_file(playlist); playlist_free(playlist); database_info_list_free(db_state->info); free(db_state->info); db_state->info = NULL; db_state->crc = 0; free(entry_path_str); free(db_playlist_path); free(db_playlist_base_str); free(db_crc); /* Move database to start since we are likely to match against it again */ if (db_state->list_index != 0) { struct string_list_elem entry = db_state->list->elems[db_state->list_index]; memmove(&db_state->list->elems[1], &db_state->list->elems[0], sizeof(entry) * db_state->list_index); db_state->list->elems[0] = entry; } return 0; }
int main(int argc, char *argv[]) { int c; char *configFile = NULL; char *host = NULL; unsigned short port = 0; char *mount = NULL; shout_t *shout; extern char *optarg; extern int optind; #ifdef HAVE_SIGNALS struct sigaction act; unsigned int i; #endif #ifdef XALLOC_DEBUG xalloc_initialize_debug(2, NULL); #else xalloc_initialize(); #endif /* XALLOC_DEBUG */ playlist_init(); shout_init(); __progname = getProgname(argv[0]); pezConfig = getEZConfig(); mFlag = 0; nFlag = 0; qFlag = 0; vFlag = 0; while ((c = local_getopt(argc, argv, "c:hmnqsVv")) != -1) { switch (c) { case 'c': if (configFile != NULL) { printf("Error: multiple -c arguments given\n"); usage(); return (ez_shutdown(2)); } configFile = xstrdup(optarg); break; case 'h': usage(); usageHelp(); return (ez_shutdown(0)); case 'm': mFlag = 1; break; case 'n': nFlag = 1; break; case 'q': qFlag = 1; break; case 's': sFlag = 1; break; case 'V': printf("%s\n", PACKAGE_STRING); return (ez_shutdown(0)); case 'v': vFlag++; break; case '?': usage(); return (ez_shutdown(2)); default: break; } } argc -= optind; argv += optind; if (sFlag) { playlist_t *pl; const char *entry; switch (argc) { case 0: pl = playlist_read(NULL); if (pl == NULL) return (ez_shutdown(1)); break; case 1: pl = playlist_read(argv[0]); if (pl == NULL) return (ez_shutdown(1)); break; default: printf("Error: Too many arguments.\n"); return (ez_shutdown(2)); } playlist_shuffle(pl); while ((entry = playlist_get_next(pl)) != NULL) printf("%s\n", entry); playlist_free(&pl); return (ez_shutdown(0)); } if (configFile == NULL) { printf("You must supply a config file with the -c argument.\n"); usage(); return (ez_shutdown(2)); } else { /* * Attempt to open configFile here for a more meaningful error * message. Where possible, do it with stat() and check for * safe config file permissions. */ #ifdef HAVE_STAT struct stat st; if (stat(configFile, &st) == -1) { printf("%s: %s\n", configFile, strerror(errno)); usage(); return (ez_shutdown(2)); } if (vFlag && (st.st_mode & (S_IRGRP | S_IROTH))) printf("%s: Warning: %s is group and/or world readable\n", __progname, configFile); if (st.st_mode & (S_IWGRP | S_IWOTH)) { printf("%s: Error: %s is group and/or world writeable\n", __progname, configFile); return (ez_shutdown(2)); } #else FILE *tmp; if ((tmp = fopen(configFile, "r")) == NULL) { printf("%s: %s\n", configFile, strerror(errno)); usage(); return (ez_shutdown(2)); } fclose(tmp); #endif /* HAVE_STAT */ } if (!parseConfig(configFile)) return (ez_shutdown(2)); if (pezConfig->URL == NULL) { printf("%s: Error: Missing <url>\n", configFile); return (ez_shutdown(2)); } if (!urlParse(pezConfig->URL, &host, &port, &mount)) { printf("Must be of the form ``http://server:port/mountpoint''\n"); return (ez_shutdown(2)); } if (strlen(host) == 0) { printf("%s: Error: Invalid <url>: Missing server:\n", configFile); printf("Must be of the form ``http://server:port/mountpoint''\n"); return (ez_shutdown(2)); } if (strlen(mount) == 0) { printf("%s: Error: Invalid <url>: Missing mountpoint:\n", configFile); printf("Must be of the form ``http://server:port/mountpoint''\n"); return (ez_shutdown(2)); } if (pezConfig->password == NULL) { printf("%s: Error: Missing <sourcepassword>\n", configFile); return (ez_shutdown(2)); } if (pezConfig->fileName == NULL) { printf("%s: Error: Missing <filename>\n", configFile); return (ez_shutdown(2)); } if (pezConfig->format == NULL) { printf("%s: Warning: Missing <format>:\n", configFile); printf("Specify a stream format of either MP3, VORBIS or THEORA\n"); } xfree(configFile); if ((shout = stream_setup(host, port, mount)) == NULL) return (ez_shutdown(1)); if (pezConfig->metadataProgram != NULL) metadataFromProgram = 1; else metadataFromProgram = 0; #ifdef HAVE_SIGNALS memset(&act, 0, sizeof(act)); act.sa_handler = sig_handler; # ifdef SA_RESTART act.sa_flags = SA_RESTART; # endif for (i = 0; i < sizeof(ezstream_signals) / sizeof(int); i++) { if (sigaction(ezstream_signals[i], &act, NULL) == -1) { printf("%s: sigaction(): %s\n", __progname, strerror(errno)); return (ez_shutdown(1)); } } /* * Ignore SIGPIPE, which has been seen to give a long-running ezstream * process trouble. EOF and/or EPIPE are also easier to handle. */ act.sa_handler = SIG_IGN; if (sigaction(SIGPIPE, &act, NULL) == -1) { printf("%s: sigaction(): %s\n", __progname, strerror(errno)); return (ez_shutdown(1)); } #endif /* HAVE_SIGNALS */ if (shout_open(shout) == SHOUTERR_SUCCESS) { int ret; printf("%s: Connected to http://%s:%hu%s\n", __progname, host, port, mount); if (pezConfig->fileNameIsProgram || strrcasecmp(pezConfig->fileName, ".m3u") == 0 || strrcasecmp(pezConfig->fileName, ".txt") == 0) playlistMode = 1; else playlistMode = 0; if (vFlag && pezConfig->fileNameIsProgram) printf("%s: Using program '%s' to get filenames for streaming\n", __progname, pezConfig->fileName); do { if (playlistMode) { ret = streamPlaylist(shout, pezConfig->fileName); } else { ret = streamFile(shout, pezConfig->fileName); } if (quit) break; if (pezConfig->streamOnce) break; } while (ret); shout_close(shout); } else printf("%s: Connection to http://%s:%hu%s failed: %s\n", __progname, host, port, mount, shout_get_error(shout)); if (quit) printf("\r%s: SIGINT or SIGTERM received\n", __progname); if (vFlag) printf("%s: Exiting ...\n", __progname); xfree(host); xfree(mount); playlist_free(&playlist); return (ez_shutdown(0)); }
playlist_t * playlist_read(const char *filename) { playlist_t *pl; unsigned long line; FILE *filep; char buf[PATH_MAX]; if (filename != NULL) { pl = playlist_create(filename); if ((filep = fopen(filename, "r")) == NULL) { printf("%s: %s: %s\n", __progname, filename, strerror(errno)); playlist_free(&pl); return (NULL); } } else { pl = playlist_create("stdin"); if ((filep = fdopen(STDIN_FILENO, "r")) == NULL) { printf("%s: stdin: %s\n", __progname, strerror(errno)); playlist_free(&pl); return (NULL); } } line = 0; while (fgets(buf, (int)sizeof(buf), filep) != NULL) { line++; if (strlen(buf) == sizeof(buf) - 1) { char skip_buf[2]; printf("%s[%lu]: File or path name too long\n", pl->filename, line); /* Discard any excess chars in that line. */ while (fgets(skip_buf, (int)sizeof(skip_buf), filep) != NULL) { if (skip_buf[0] == '\n') break; } continue; } /* * fgets() would happily fill a buffer with * { '\0', ..., '\n', '\0' }. Also skip lines that begin with * a '#', which is considered a comment. */ if (buf[0] == '\0' || buf[0] == '#') continue; /* Trim any trailing newlines and carriage returns. */ buf[strcspn(buf, "\n")] = '\0'; buf[strcspn(buf, "\r")] = '\0'; /* Skip lines that are empty after the trimming. */ if (buf[0] == '\0') continue; /* We got one. */ if (!playlist_add(pl, buf)) { fclose(filep); playlist_free(&pl); return (NULL); } } if (ferror(filep)) { printf("%s: playlist_read(): Error while reading %s: %s\n", __progname, pl->filename, strerror(errno)); fclose(filep); playlist_free(&pl); return (NULL); } fclose(filep); return (pl); }
bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) { static struct retro_system_info menu_driver_system; static bool menu_driver_pending_quick_menu = false; static bool menu_driver_pending_action = false; static bool menu_driver_prevent_populate = false; static bool menu_driver_load_no_content = false; static bool menu_driver_alive = false; static bool menu_driver_data_own = false; static bool menu_driver_pending_quit = false; static bool menu_driver_pending_shutdown = false; static playlist_t *menu_driver_playlist = NULL; static struct video_shader *menu_driver_shader = NULL; static menu_handle_t *menu_driver_data = NULL; static const menu_ctx_driver_t *menu_driver_ctx = NULL; static void *menu_userdata = NULL; settings_t *settings = config_get_ptr(); switch (state) { case RARCH_MENU_CTL_IS_PENDING_ACTION: if (!menu_driver_pending_action) return false; menu_driver_ctl(RARCH_MENU_CTL_UNSET_PENDING_ACTION, NULL); break; case RARCH_MENU_CTL_SET_PENDING_ACTION: menu_driver_pending_action = true; break; case RARCH_MENU_CTL_UNSET_PENDING_ACTION: menu_driver_pending_action = false; break; case RARCH_MENU_CTL_DRIVER_DATA_GET: { menu_handle_t **driver_data = (menu_handle_t**)data; if (!driver_data) return false; *driver_data = menu_driver_data; } break; case RARCH_MENU_CTL_IS_PENDING_QUICK_MENU: return menu_driver_pending_quick_menu; case RARCH_MENU_CTL_SET_PENDING_QUICK_MENU: menu_driver_pending_quick_menu = true; break; case RARCH_MENU_CTL_UNSET_PENDING_QUICK_MENU: menu_driver_pending_quick_menu = false; break; case RARCH_MENU_CTL_IS_PENDING_QUIT: return menu_driver_pending_quit; case RARCH_MENU_CTL_SET_PENDING_QUIT: menu_driver_pending_quit = true; break; case RARCH_MENU_CTL_UNSET_PENDING_QUIT: menu_driver_pending_quit = false; break; case RARCH_MENU_CTL_IS_PENDING_SHUTDOWN: return menu_driver_pending_shutdown; case RARCH_MENU_CTL_SET_PENDING_SHUTDOWN: menu_driver_pending_shutdown = true; break; case RARCH_MENU_CTL_UNSET_PENDING_SHUTDOWN: menu_driver_pending_shutdown = false; break; case RARCH_MENU_CTL_DESTROY: menu_driver_pending_quick_menu = false; menu_driver_pending_action = false; menu_driver_pending_quit = false; menu_driver_pending_shutdown = false; menu_driver_prevent_populate = false; menu_driver_load_no_content = false; menu_driver_alive = false; menu_driver_data_own = false; menu_driver_ctx = NULL; menu_userdata = NULL; break; case RARCH_MENU_CTL_PLAYLIST_FREE: if (menu_driver_playlist) playlist_free(menu_driver_playlist); menu_driver_playlist = NULL; break; case RARCH_MENU_CTL_FIND_DRIVER: { int i; driver_ctx_info_t drv; settings_t *settings = config_get_ptr(); drv.label = "menu_driver"; drv.s = settings->menu.driver; driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv); i = drv.len; if (i >= 0) menu_driver_ctx = (const menu_ctx_driver_t*) menu_driver_find_handle(i); else { unsigned d; RARCH_WARN("Couldn't find any menu driver named \"%s\"\n", settings->menu.driver); RARCH_LOG_OUTPUT("Available menu drivers are:\n"); for (d = 0; menu_driver_find_handle(d); d++) RARCH_LOG_OUTPUT("\t%s\n", menu_driver_find_ident(d)); RARCH_WARN("Going to default to first menu driver...\n"); menu_driver_ctx = (const menu_ctx_driver_t*) menu_driver_find_handle(0); if (!menu_driver_ctx) { retroarch_fail(1, "find_menu_driver()"); return false; } } } break; case RARCH_MENU_CTL_PLAYLIST_INIT: { const char *path = (const char*)data; if (string_is_empty(path)) return false; menu_driver_playlist = playlist_init(path, COLLECTION_SIZE); } break; case RARCH_MENU_CTL_PLAYLIST_GET: { playlist_t **playlist = (playlist_t**)data; if (!playlist) return false; *playlist = menu_driver_playlist; } break; case RARCH_MENU_CTL_SYSTEM_INFO_GET: { struct retro_system_info **system = (struct retro_system_info**)data; if (!system) return false; *system = &menu_driver_system; } break; case RARCH_MENU_CTL_SYSTEM_INFO_DEINIT: libretro_free_system_info(&menu_driver_system); memset(&menu_driver_system, 0, sizeof(struct retro_system_info)); break; case RARCH_MENU_CTL_RENDER_MESSAGEBOX: if (menu_driver_ctx->render_messagebox) menu_driver_ctx->render_messagebox(menu_userdata, menu_driver_data->menu_state.msg); break; case RARCH_MENU_CTL_BLIT_RENDER: if (menu_driver_ctx->render) menu_driver_ctx->render(menu_userdata); break; case RARCH_MENU_CTL_RENDER: if (!menu_driver_data) return false; if (BIT64_GET(menu_driver_data->state, MENU_STATE_RENDER_FRAMEBUFFER) != BIT64_GET(menu_driver_data->state, MENU_STATE_RENDER_MESSAGEBOX)) BIT64_SET(menu_driver_data->state, MENU_STATE_RENDER_FRAMEBUFFER); if (BIT64_GET(menu_driver_data->state, MENU_STATE_RENDER_FRAMEBUFFER)) menu_display_set_framebuffer_dirty_flag(); if (BIT64_GET(menu_driver_data->state, MENU_STATE_RENDER_MESSAGEBOX) && !string_is_empty(menu_driver_data->menu_state.msg)) { menu_driver_ctl(RARCH_MENU_CTL_RENDER_MESSAGEBOX, NULL); if (ui_companion_is_on_foreground()) { const ui_companion_driver_t *ui = ui_companion_get_ptr(); if (ui->render_messagebox) ui->render_messagebox(menu_driver_data->menu_state.msg); } } if (BIT64_GET(menu_driver_data->state, MENU_STATE_BLIT)) { menu_animation_ctl(MENU_ANIMATION_CTL_UPDATE_TIME, NULL); menu_driver_ctl(RARCH_MENU_CTL_BLIT_RENDER, NULL); } if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL) && !runloop_ctl(RUNLOOP_CTL_IS_IDLE, NULL)) menu_display_libretro(); menu_driver_ctl(RARCH_MENU_CTL_SET_TEXTURE, NULL); menu_driver_data->state = 0; break; case RARCH_MENU_CTL_SHADER_DEINIT: #ifdef HAVE_SHADER_MANAGER if (menu_driver_shader) free(menu_driver_shader); menu_driver_shader = NULL; #endif break; case RARCH_MENU_CTL_SHADER_INIT: #ifdef HAVE_SHADER_MANAGER menu_driver_shader = (struct video_shader*) calloc(1, sizeof(struct video_shader)); if (!menu_driver_shader) return false; #endif break; case RARCH_MENU_CTL_SHADER_GET: { struct video_shader **shader = (struct video_shader**)data; if (!shader) return false; *shader = menu_driver_shader; } break; case RARCH_MENU_CTL_FRAME: if (!menu_driver_alive) return false; if (menu_driver_ctx->frame) menu_driver_ctx->frame(menu_userdata); break; case RARCH_MENU_CTL_SET_PREVENT_POPULATE: menu_driver_prevent_populate = true; break; case RARCH_MENU_CTL_UNSET_PREVENT_POPULATE: menu_driver_prevent_populate = false; break; case RARCH_MENU_CTL_IS_PREVENT_POPULATE: return menu_driver_prevent_populate; case RARCH_MENU_CTL_SET_TOGGLE: menu_driver_toggle(true); break; case RARCH_MENU_CTL_UNSET_TOGGLE: menu_driver_toggle(false); break; case RARCH_MENU_CTL_SET_ALIVE: menu_driver_alive = true; break; case RARCH_MENU_CTL_UNSET_ALIVE: menu_driver_alive = false; break; case RARCH_MENU_CTL_IS_ALIVE: return menu_driver_alive; case RARCH_MENU_CTL_SET_OWN_DRIVER: menu_driver_data_own = true; break; case RARCH_MENU_CTL_UNSET_OWN_DRIVER: if (!content_is_inited()) return false; menu_driver_data_own = false; break; case RARCH_MENU_CTL_SET_TEXTURE: if (menu_driver_ctx->set_texture) menu_driver_ctx->set_texture(); break; case RARCH_MENU_CTL_IS_SET_TEXTURE: if (!menu_driver_ctx) return false; return menu_driver_ctx->set_texture; case RARCH_MENU_CTL_OWNS_DRIVER: return menu_driver_data_own; case RARCH_MENU_CTL_DEINIT: menu_driver_ctl(RARCH_MENU_CTL_CONTEXT_DESTROY, NULL); if (menu_driver_ctl(RARCH_MENU_CTL_OWNS_DRIVER, NULL)) return true; if (menu_driver_data) { menu_driver_ctl(RARCH_MENU_CTL_PLAYLIST_FREE, NULL); menu_shader_free(menu_driver_data); menu_input_ctl(MENU_INPUT_CTL_DEINIT, NULL); menu_navigation_ctl(MENU_NAVIGATION_CTL_DEINIT, NULL); if (menu_driver_ctx && menu_driver_ctx->free) menu_driver_ctx->free(menu_userdata); if (menu_userdata) free(menu_userdata); menu_userdata = NULL; menu_driver_ctl(RARCH_MENU_CTL_SYSTEM_INFO_DEINIT, NULL); menu_display_deinit(); menu_entries_ctl(MENU_ENTRIES_CTL_DEINIT, NULL); command_event(CMD_EVENT_HISTORY_DEINIT, NULL); core_info_deinit_list(); core_info_free_current_core(); free(menu_driver_data); } menu_driver_data = NULL; break; case RARCH_MENU_CTL_INIT: if (menu_driver_data) return true; menu_driver_data = (menu_handle_t*) menu_driver_ctx->init(&menu_userdata); if (!menu_driver_data || !menu_init(menu_driver_data)) { retroarch_fail(1, "init_menu()"); return false; } strlcpy(settings->menu.driver, menu_driver_ctx->ident, sizeof(settings->menu.driver)); if (menu_driver_ctx->lists_init) { if (!menu_driver_ctx->lists_init(menu_driver_data)) { retroarch_fail(1, "init_menu()"); return false; } } break; case RARCH_MENU_CTL_LOAD_NO_CONTENT_GET: { bool **ptr = (bool**)data; if (!ptr) return false; *ptr = (bool*)&menu_driver_load_no_content; } break; case RARCH_MENU_CTL_HAS_LOAD_NO_CONTENT: return menu_driver_load_no_content; case RARCH_MENU_CTL_SET_LOAD_NO_CONTENT: menu_driver_load_no_content = true; break; case RARCH_MENU_CTL_UNSET_LOAD_NO_CONTENT: menu_driver_load_no_content = false; break; case RARCH_MENU_CTL_NAVIGATION_INCREMENT: if (menu_driver_ctx->navigation_increment) menu_driver_ctx->navigation_increment(menu_userdata); break; case RARCH_MENU_CTL_NAVIGATION_DECREMENT: if (menu_driver_ctx->navigation_decrement) menu_driver_ctx->navigation_decrement(menu_userdata); break; case RARCH_MENU_CTL_NAVIGATION_SET: { bool *scroll = (bool*)data; if (!scroll) return false; if (menu_driver_ctx->navigation_set) menu_driver_ctx->navigation_set(menu_userdata, *scroll); } break; case RARCH_MENU_CTL_NAVIGATION_SET_LAST: if (menu_driver_ctx->navigation_set_last) menu_driver_ctx->navigation_set_last(menu_userdata); break; case RARCH_MENU_CTL_NAVIGATION_ASCEND_ALPHABET: { size_t *ptr_out = (size_t*)data; if (!ptr_out) return false; if (menu_driver_ctx->navigation_ascend_alphabet) menu_driver_ctx->navigation_ascend_alphabet( menu_userdata, ptr_out); } case RARCH_MENU_CTL_NAVIGATION_DESCEND_ALPHABET: { size_t *ptr_out = (size_t*)data; if (!ptr_out) return false; if (menu_driver_ctx->navigation_descend_alphabet) menu_driver_ctx->navigation_descend_alphabet( menu_userdata, ptr_out); } break; case RARCH_MENU_CTL_NAVIGATION_CLEAR: { bool *pending_push = (bool*)data; if (!pending_push) return false; if (menu_driver_ctx->navigation_clear) menu_driver_ctx->navigation_clear( menu_userdata, pending_push); } break; case RARCH_MENU_CTL_POPULATE_ENTRIES: { menu_displaylist_info_t *info = (menu_displaylist_info_t*)data; if (!info) return false; if (menu_driver_ctx->populate_entries) menu_driver_ctx->populate_entries( menu_userdata, info->path, info->label, info->type); } break; case RARCH_MENU_CTL_LIST_GET_ENTRY: { menu_ctx_list_t *list = (menu_ctx_list_t*)data; if (!menu_driver_ctx || !menu_driver_ctx->list_get_entry) { list->entry = NULL; return false; } list->entry = menu_driver_ctx->list_get_entry(menu_userdata, list->type, list->idx); } break; case RARCH_MENU_CTL_LIST_GET_SIZE: { menu_ctx_list_t *list = (menu_ctx_list_t*)data; if (!menu_driver_ctx || !menu_driver_ctx->list_get_size) { list->size = 0; return false; } list->size = menu_driver_ctx->list_get_size(menu_userdata, list->type); } break; case RARCH_MENU_CTL_LIST_GET_SELECTION: { menu_ctx_list_t *list = (menu_ctx_list_t*)data; if (!menu_driver_ctx || !menu_driver_ctx->list_get_selection) { list->selection = 0; return false; } list->selection = menu_driver_ctx->list_get_selection(menu_userdata); } break; case RARCH_MENU_CTL_LIST_FREE: { menu_ctx_list_t *list = (menu_ctx_list_t*)data; if (menu_driver_ctx) { if (menu_driver_ctx->list_free) menu_driver_ctx->list_free(list->list, list->idx, list->list_size); } if (list->list) { file_list_free_userdata (list->list, list->idx); file_list_free_actiondata(list->list, list->idx); } } break; case RARCH_MENU_CTL_LIST_PUSH: { menu_ctx_displaylist_t *disp_list = (menu_ctx_displaylist_t*)data; if (menu_driver_ctx->list_push) if (menu_driver_ctx->list_push(menu_driver_data, menu_userdata, disp_list->info, disp_list->type) == 0) return true; } return false; case RARCH_MENU_CTL_LIST_CLEAR: { file_list_t *list = (file_list_t*)data; if (!list) return false; if (menu_driver_ctx->list_clear) menu_driver_ctx->list_clear(list); } break; case RARCH_MENU_CTL_TOGGLE: { bool *latch = (bool*)data; if (!latch) return false; if (menu_driver_ctx && menu_driver_ctx->toggle) menu_driver_ctx->toggle(menu_userdata, *latch); } break; case RARCH_MENU_CTL_REFRESH: { #if 0 bool refresh = false; menu_entries_ctl(MENU_ENTRIES_CTL_LIST_DEINIT, NULL); menu_entries_ctl(MENU_ENTRIES_CTL_SETTINGS_DEINIT, NULL); menu_entries_ctl(MENU_ENTRIES_CTL_INIT, NULL); menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); #endif } break; case RARCH_MENU_CTL_CONTEXT_RESET: if (!menu_driver_ctx || !menu_driver_ctx->context_reset) return false; menu_driver_ctx->context_reset(menu_userdata); break; case RARCH_MENU_CTL_CONTEXT_DESTROY: if (!menu_driver_ctx || !menu_driver_ctx->context_destroy) return false; menu_driver_ctx->context_destroy(menu_userdata); break; case RARCH_MENU_CTL_SHADER_MANAGER_INIT: menu_shader_manager_init(menu_driver_data); break; case RARCH_MENU_CTL_LIST_SET_SELECTION: { file_list_t *list = (file_list_t*)data; if (!list) return false; if (!menu_driver_ctx || !menu_driver_ctx->list_set_selection) return false; menu_driver_ctx->list_set_selection(menu_userdata, list); } break; case RARCH_MENU_CTL_LIST_CACHE: { menu_ctx_list_t *list = (menu_ctx_list_t*)data; if (!list || !menu_driver_ctx || !menu_driver_ctx->list_cache) return false; menu_driver_ctx->list_cache(menu_userdata, list->type, list->action); } break; case RARCH_MENU_CTL_LIST_INSERT: { menu_ctx_list_t *list = (menu_ctx_list_t*)data; if (!list || !menu_driver_ctx || !menu_driver_ctx->list_insert) return false; menu_driver_ctx->list_insert(menu_userdata, list->list, list->path, list->label, list->idx); } break; case RARCH_MENU_CTL_LOAD_IMAGE: { menu_ctx_load_image_t *load_image_info = (menu_ctx_load_image_t*)data; if (!menu_driver_ctx || !menu_driver_ctx->load_image) return false; return menu_driver_ctx->load_image(menu_userdata, load_image_info->data, load_image_info->type); } case RARCH_MENU_CTL_ITERATE: { bool retcode = false; menu_ctx_iterate_t *iterate = (menu_ctx_iterate_t*)data; if (menu_driver_ctl(RARCH_MENU_CTL_IS_PENDING_QUICK_MENU, NULL)) { menu_driver_ctl(RARCH_MENU_CTL_UNSET_PENDING_QUICK_MENU, NULL); menu_entries_flush_stack(NULL, MENU_SETTINGS); menu_display_set_msg_force(true); generic_action_ok_displaylist_push("", "", 0, 0, 0, ACTION_OK_DL_CONTENT_SETTINGS); if (menu_driver_ctl(RARCH_MENU_CTL_IS_PENDING_QUIT, NULL)) { menu_driver_ctl(RARCH_MENU_CTL_UNSET_PENDING_QUIT, NULL); return false; } return true; } if (menu_driver_ctl(RARCH_MENU_CTL_IS_PENDING_QUIT, NULL)) { menu_driver_ctl(RARCH_MENU_CTL_UNSET_PENDING_QUIT, NULL); return false; } if (menu_driver_ctl(RARCH_MENU_CTL_IS_PENDING_SHUTDOWN, NULL)) { menu_driver_ctl(RARCH_MENU_CTL_UNSET_PENDING_SHUTDOWN, NULL); if (!command_event(CMD_EVENT_QUIT, NULL)) return false; return true; } if (!menu_driver_ctx || !menu_driver_ctx->iterate) return false; if (menu_driver_ctl(RARCH_MENU_CTL_IS_PENDING_ACTION, &retcode)) { iterate->action = pending_iter.action; pending_iter.action = MENU_ACTION_NOOP; } if (menu_driver_ctx->iterate(menu_driver_data, menu_userdata, iterate->action) == -1) return false; } break; case RARCH_MENU_CTL_ENVIRONMENT: { menu_ctx_environment_t *menu_environ = (menu_ctx_environment_t*)data; if (menu_driver_ctx->environ_cb) { if (menu_driver_ctx->environ_cb(menu_environ->type, menu_environ->data, menu_userdata) == 0) return true; } } return false; case RARCH_MENU_CTL_POINTER_TAP: { menu_ctx_pointer_t *point = (menu_ctx_pointer_t*)data; if (!menu_driver_ctx || !menu_driver_ctx->pointer_tap) { point->retcode = 0; return false; } point->retcode = menu_driver_ctx->pointer_tap(menu_userdata, point->x, point->y, point->ptr, point->cbs, point->entry, point->action); } break; case RARCH_MENU_CTL_BIND_INIT: { menu_ctx_bind_t *bind = (menu_ctx_bind_t*)data; if (!menu_driver_ctx || !menu_driver_ctx->bind_init) { bind->retcode = 0; return false; } bind->retcode = menu_driver_ctx->bind_init( bind->cbs, bind->path, bind->label, bind->type, bind->idx, bind->elem0, bind->elem1, bind->label_hash, bind->menu_label_hash); } break; case RARCH_MENU_CTL_UPDATE_THUMBNAIL_PATH: { size_t selection; if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection)) return false; if (!menu_driver_ctx || !menu_driver_ctx->update_thumbnail_path) return false; menu_driver_ctx->update_thumbnail_path(menu_userdata, selection); } break; case RARCH_MENU_CTL_UPDATE_THUMBNAIL_IMAGE: { if (!menu_driver_ctx || !menu_driver_ctx->update_thumbnail_image) return false; menu_driver_ctx->update_thumbnail_image(menu_userdata); } break; default: case RARCH_MENU_CTL_NONE: break; } return true; }
static int database_info_list_iterate_found_match( db_handle_t *_db, database_state_handle_t *db_state, database_info_handle_t *db, const char *archive_name ) { char *db_crc = (char*)malloc(128 * sizeof(char)); char *db_playlist_base_str = (char*)malloc(128 * sizeof(char)); char *db_playlist_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); char *entry_path_str = (char*)malloc(PATH_MAX_LENGTH * sizeof(char)); playlist_t *playlist = NULL; const char *db_path = database_info_get_current_name(db_state); const char *entry_path = database_info_get_current_element_name(db); database_info_t *db_info_entry = &db_state->info->list[db_state->entry_index]; db_crc[0] = '\0'; db_playlist_path[0] = '\0'; db_playlist_base_str[0] = '\0'; entry_path_str[0] = '\0'; fill_short_pathname_representation_noext(db_playlist_base_str, db_path, 128 * sizeof(char)); strlcat(db_playlist_base_str, file_path_str(FILE_PATH_LPL_EXTENSION), 128 * sizeof(char)); fill_pathname_join(db_playlist_path, _db->playlist_directory, db_playlist_base_str, PATH_MAX_LENGTH * sizeof(char)); playlist = playlist_init(db_playlist_path, COLLECTION_SIZE); snprintf(db_crc, 128 * sizeof(char), "%08X|crc", db_info_entry->crc32); if (entry_path) strlcpy(entry_path_str, entry_path, 128 * sizeof(char)); if (!string_is_empty(archive_name)) fill_pathname_join_delim(entry_path_str, entry_path_str, archive_name, '#', 128 * sizeof(char)); #if 0 RARCH_LOG("Found match in database !\n"); RARCH_LOG("Path: %s\n", db_path); RARCH_LOG("CRC : %s\n", db_crc); RARCH_LOG("Playlist Path: %s\n", db_playlist_path); RARCH_LOG("Entry Path: %s\n", entry_path); RARCH_LOG("Playlist not NULL: %d\n", playlist != NULL); RARCH_LOG("ZIP entry: %s\n", archive_name); RARCH_LOG("entry path str: %s\n", entry_path_str); #endif if(!playlist_entry_exists(playlist, entry_path_str, db_crc)) { playlist_push(playlist, entry_path_str, db_info_entry->name, file_path_str(FILE_PATH_DETECT), file_path_str(FILE_PATH_DETECT), db_crc, db_playlist_base_str); } playlist_write_file(playlist); playlist_free(playlist); database_info_list_free(db_state->info); free(db_state->info); db_state->info = NULL; db_state->crc = 0; free(entry_path_str); free(db_playlist_path); free(db_playlist_base_str); free(db_crc); return 0; }
/* Takes a list of files and folders and adds them to the currently selected playlist. Folders will have their contents added recursively. */ void MainWindow::addFilesToPlaylist(QStringList files) { QStringList list; QString currentPlaylistPath; QListWidgetItem *currentItem = m_listWidget->currentItem(); QByteArray currentPlaylistArray; QScopedPointer<QProgressDialog> dialog(NULL); PlaylistEntryDialog *playlistDialog = playlistEntryDialog(); QHash<QString, QString> selectedCore; QHash<QString, QString> itemToAdd; QString selectedDatabase; QString selectedName; QString selectedPath; const char *currentPlaylistData = NULL; playlist_t *playlist = NULL; int i; /* Assume a blank list means we will manually enter in all fields. */ if (files.isEmpty()) { /* Make sure hash isn't blank, that would mean there's multiple entries to add at once. */ itemToAdd["label"] = ""; itemToAdd["path"] = ""; } else if (files.count() == 1) { QString path = files.at(0); QFileInfo info(path); if (info.isFile()) { itemToAdd["label"] = info.completeBaseName(); itemToAdd["path"] = path; } } if (currentItem) { currentPlaylistPath = currentItem->data(Qt::UserRole).toString(); if (!currentPlaylistPath.isEmpty()) { currentPlaylistArray = currentPlaylistPath.toUtf8(); currentPlaylistData = currentPlaylistArray.constData(); } } if (currentPlaylistPath == ALL_PLAYLISTS_TOKEN) { showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_CANNOT_ADD_TO_ALL_PLAYLISTS), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); return; } /* a blank itemToAdd means there will be multiple */ if (!playlistDialog->showDialog(itemToAdd)) return; selectedName = m_playlistEntryDialog->getSelectedName(); selectedPath = m_playlistEntryDialog->getSelectedPath(); selectedCore = m_playlistEntryDialog->getSelectedCore(); selectedDatabase = m_playlistEntryDialog->getSelectedDatabase(); if (selectedDatabase.isEmpty()) selectedDatabase = QFileInfo(currentPlaylistPath).fileName(); else selectedDatabase += file_path_str(FILE_PATH_LPL_EXTENSION); dialog.reset(new QProgressDialog(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_GATHERING_LIST_OF_FILES), "Cancel", 0, 0, this)); dialog->setWindowModality(Qt::ApplicationModal); if (selectedName.isEmpty() || selectedPath.isEmpty() || selectedDatabase.isEmpty()) { showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_PLEASE_FILL_OUT_REQUIRED_FIELDS), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); return; } if (files.isEmpty()) files.append(selectedPath); for (i = 0; i < files.count(); i++) { QString path(files.at(i)); QFileInfo fileInfo(path); if (dialog->wasCanceled()) return; if (i % 25 == 0) { /* Needed to update progress dialog while doing a lot of stuff on the main thread. */ qApp->processEvents(); } if (fileInfo.isDir()) { QDir dir(path); addDirectoryFilesToList(list, dir); continue; } if (fileInfo.isFile()) list.append(fileInfo.absoluteFilePath()); else if (files.count() == 1) { /* If adding a single file, tell user that it doesn't exist. */ showMessageBox(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_FILE_DOES_NOT_EXIST), MainWindow::MSGBOX_TYPE_ERROR, Qt::ApplicationModal, false); return; } } dialog->setLabelText(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_ADDING_FILES_TO_PLAYLIST)); dialog->setMaximum(list.count()); playlist = playlist_init(currentPlaylistData, COLLECTION_SIZE); for (i = 0; i < list.count(); i++) { QString fileName = list.at(i); QFileInfo fileInfo; QByteArray fileBaseNameArray; QByteArray pathArray; QByteArray corePathArray; QByteArray coreNameArray; QByteArray databaseArray; const char *pathData = NULL; const char *fileNameNoExten = NULL; const char *corePathData = NULL; const char *coreNameData = NULL; const char *databaseData = NULL; if (dialog->wasCanceled()) { playlist_free(playlist); return; } if (fileName.isEmpty()) continue; fileInfo = fileName; if (files.count() == 1 && list.count() == 1 && i == 0) { fileBaseNameArray = selectedName.toUtf8(); pathArray = QDir::toNativeSeparators(selectedPath).toUtf8(); } else { fileBaseNameArray = fileInfo.completeBaseName().toUtf8(); pathArray = QDir::toNativeSeparators(fileName).toUtf8(); } fileNameNoExten = fileBaseNameArray.constData(); /* a modal QProgressDialog calls processEvents() automatically in setValue() */ dialog->setValue(i + 1); pathData = pathArray.constData(); if (selectedCore.isEmpty()) { corePathData = "DETECT"; coreNameData = "DETECT"; } else { corePathArray = QDir::toNativeSeparators(selectedCore.value("core_path")).toUtf8(); coreNameArray = selectedCore.value("core_name").toUtf8(); corePathData = corePathArray.constData(); coreNameData = coreNameArray.constData(); } databaseArray = selectedDatabase.toUtf8(); databaseData = databaseArray.constData(); if (path_is_compressed_file(pathData)) { struct string_list *list = file_archive_get_file_list(pathData, NULL); if (list) { if (list->size == 1) { /* assume archives with one file should have that file loaded directly */ pathArray = QDir::toNativeSeparators(QString(pathData) + "#" + list->elems[0].data).toUtf8(); pathData = pathArray.constData(); } string_list_free(list); } } playlist_push(playlist, pathData, fileNameNoExten, corePathData, coreNameData, "00000000|crc", databaseData); } playlist_write_file(playlist); playlist_free(playlist); reloadPlaylists(); }