X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/blobdiff_plain/6da75a17cd321ca5d9e39a690e3cbdd548d4e5b1..8b7714707e87d73b90ca8772f379c1ab1751433c:/application/settings.c diff --git a/application/settings.c b/application/settings.c index d651a81..22793b4 100644 --- a/application/settings.c +++ b/application/settings.c @@ -31,10 +31,13 @@ #include #include +#include "main.h" #include "utils.h" #include #include +#include +#include #define CONFIG_BASE_DIR ".config" #define UWP_CONFIG_DIR "uwplayer" @@ -84,18 +87,20 @@ int load_settings(void) { char *cfgfile_path = util_concat_path(uwp_config_dir, UWP_CONFIG_FILE); FILE *cfgfile = fopen(cfgfile_path, "r"); free(cfgfile_path); - if(!cfgfile) return 0; int ret = 0; - if(ucx_properties_load(uwp_settings, cfgfile)) { - fprintf(stderr, "Error: Cannot read uwplayer settings\n"); - ret = 1; - } - fclose(cfgfile); - - if(ret) { - return ret; + if(cfgfile) { + if(ucx_properties_load(uwp_settings, cfgfile)) { + fprintf(stderr, "Error: Cannot read uwplayer settings\n"); + ret = 1; + } + fclose(cfgfile); + + if(ret) { + return ret; + } } + // check if mpv or mplayer binaries are configured char *player_bin = ucx_map_cstr_get(uwp_settings, UWP_PLAYER_BIN); @@ -112,9 +117,59 @@ int load_settings(void) { return 0; } +static char* get_which_output(FILE *f, UcxBuffer *buf) { + buf->pos = 0; + buf->size = 0; + ucx_stream_copy(f, buf, (read_func)fread, (write_func)ucx_buffer_write); + if(!pclose(f)) { + ucx_buffer_putc(buf, 0); + size_t i; + for(i=0;ipos;i++) { + if(buf->space[i] == '\n') { + buf->space[i] = 0; + break; + } + } + return buf->space; + } + return NULL; +} + +static void finish_bin_search(XtPointer data, XtIntervalId *id) { + PlayerInfo *playerInfo = data; + ucx_map_cstr_put(uwp_settings, UWP_PLAYER_BIN, playerInfo->bin); + ucx_map_cstr_put(uwp_settings, UWP_PLAYER_TYPE, playerInfo->type); + free(playerInfo); +} + static void* player_bin_search_thread(void *data) { - // TODO: - //printf("search\n"); + UcxBuffer *buf = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOEXTEND); + + FILE *f = popen("which mpv", "r"); + if(f) { + char *bin = get_which_output(f, buf); + if(bin) { + PlayerInfo *playerInfo = malloc(sizeof(PlayerInfo)); + playerInfo->bin = strdup(bin); + playerInfo->type = strdup("mpv"); + AppAddTimeOut(0, finish_bin_search, playerInfo); + + ucx_buffer_free(buf); + return NULL; + } + } + + f = popen("which mplayer", "r"); + if(f) { + char *bin = get_which_output(f, buf); + if(bin) { + PlayerInfo *playerInfo = malloc(sizeof(PlayerInfo)); + playerInfo->bin = strdup(bin); + playerInfo->type = strdup("mplayer"); + AppAddTimeOut(0, finish_bin_search, playerInfo); + } + } + ucx_buffer_free(buf); return NULL; }