2 * Copyright 2022 Olaf Wintermann
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
37 #include <ucx/properties.h>
39 #define CONFIG_BASE_DIR ".config"
40 #define UWP_CONFIG_DIR "uwplayer"
41 #define UWP_CONFIG_FILE "uwplayer.properties"
43 static void* player_bin_search_thread(void *data);
45 static char *uwp_config_dir;
46 static UcxMap *uwp_settings;
48 static int check_config_dir(void) {
49 char *home = getenv("HOME");
54 char *cfg_dir = util_concat_path(home, CONFIG_BASE_DIR);
56 if(mkdir(cfg_dir, S_IRWXU)) {
58 fprintf(stderr, "Error: Cannot access %s: %s\n", cfg_dir, strerror(errno));
64 uwp_config_dir = util_concat_path(cfg_dir, UWP_CONFIG_DIR);
65 if(mkdir(uwp_config_dir, S_IRWXU)) {
67 fprintf(stderr, "Error: Cannot access %s: %s\n", uwp_config_dir, strerror(errno));
77 int load_settings(void) {
78 if(check_config_dir()) {
82 uwp_settings = ucx_map_new(16);
84 char *cfgfile_path = util_concat_path(uwp_config_dir, UWP_CONFIG_FILE);
85 FILE *cfgfile = fopen(cfgfile_path, "r");
87 if(!cfgfile) return 0;
90 if(ucx_properties_load(uwp_settings, cfgfile)) {
91 fprintf(stderr, "Error: Cannot read uwplayer settings\n");
100 // check if mpv or mplayer binaries are configured
101 char *player_bin = ucx_map_cstr_get(uwp_settings, UWP_PLAYER_BIN);
102 char *player_type = ucx_map_cstr_get(uwp_settings, UWP_PLAYER_TYPE);
105 // try to find the mpv or mplayer binary path
107 pthread_create(&st, NULL, player_bin_search_thread, NULL);
108 } else if(!player_type) {
109 fprintf(stderr, "Warning: unknown player type (mplayer, mpv)\n");
115 static void* player_bin_search_thread(void *data) {
117 //printf("search\n");