char *obs_module_get_config_path(obs_module_t *module, const char *file) { struct dstr output = {0}; dstr_copy(&output, obs->module_config_path); if (!dstr_is_empty(&output) && dstr_end(&output) != '/') dstr_cat_ch(&output, '/'); dstr_cat(&output, module->mod_name); dstr_cat_ch(&output, '/'); dstr_cat(&output, file); return output.array; }
static void gl_write_main_storage_assign(struct gl_shader_parser *glsp, struct shader_var *var, const char *dst, const char *src, bool input) { struct shader_struct *st; struct dstr dst_copy = {0}; char ch_left = input ? '.' : '_'; char ch_right = input ? '_' : '.'; if (dst) { dstr_copy(&dst_copy, dst); dstr_cat_ch(&dst_copy, ch_left); } else { dstr_copy(&dst_copy, "\t"); } dstr_cat(&dst_copy, var->name); st = shader_parser_getstruct(&glsp->parser, var->type); if (st) { struct dstr src_copy = {0}; size_t i; if (src) dstr_copy(&src_copy, src); dstr_cat(&src_copy, var->name); dstr_cat_ch(&src_copy, ch_right); for (i = 0; i < st->vars.num; i++) { struct shader_var *st_var = st->vars.array+i; gl_write_main_storage_assign(glsp, st_var, dst_copy.array, src_copy.array, input); } dstr_free(&src_copy); } else { if (!dstr_isempty(&dst_copy)) dstr_cat_dstr(&glsp->gl_string, &dst_copy); dstr_cat(&glsp->gl_string, " = "); if (src) dstr_cat(&glsp->gl_string, src); dstr_cat(&glsp->gl_string, var->name); dstr_cat(&glsp->gl_string, ";\n"); if (!input) gl_write_main_interface_assign(glsp, var, src); } dstr_free(&dst_copy); }
static bool parse_binary_from_directory(struct dstr *parsed_bin_path, const char *bin_path, const char *file) { struct dstr directory = {0}; bool found = true; dstr_copy(&directory, bin_path); dstr_replace(&directory, "%module%", file); if (dstr_end(&directory) != '/') dstr_cat_ch(&directory, '/'); dstr_copy_dstr(parsed_bin_path, &directory); dstr_cat(parsed_bin_path, file); dstr_cat(parsed_bin_path, get_module_extension()); if (!os_file_exists(parsed_bin_path->array)) { /* if the file doesn't exist, check with 'lib' prefix */ dstr_copy_dstr(parsed_bin_path, &directory); dstr_cat(parsed_bin_path, "lib"); dstr_cat(parsed_bin_path, file); dstr_cat(parsed_bin_path, get_module_extension()); /* if neither exist, don't include this as a library */ if (!os_file_exists(parsed_bin_path->array)) { dstr_free(parsed_bin_path); found = false; } } dstr_free(&directory); return found; }
static obs_properties_t *color_grade_filter_properties(void *data) { struct lut_filter_data *s = data; struct dstr path = {0}; const char *slash; obs_properties_t *props = obs_properties_create(); struct dstr filter_str = {0}; dstr_cat(&filter_str, "(*.png)"); if (s && s->file && *s->file) { dstr_copy(&path, s->file); } else { dstr_copy(&path, obs_module_file("LUTs")); dstr_cat_ch(&path, '/'); } dstr_replace(&path, "\\", "/"); slash = strrchr(path.array, '/'); if (slash) dstr_resize(&path, slash - path.array + 1); obs_properties_add_path(props, SETTING_IMAGE_PATH, TEXT_IMAGE_PATH, OBS_PATH_FILE, filter_str.array, path.array); obs_properties_add_float_slider(props, SETTING_CLUT_AMOUNT, TEXT_AMOUNT, 0, 1, 0.01); dstr_free(&filter_str); UNUSED_PARAMETER(data); return props; }
void dstr_insert_ch(struct dstr *dst, const size_t idx, const char ch) { if (idx == dst->len) { dstr_cat_ch(dst, ch); return; } dstr_ensure_capacity(dst, (++dst->len+1)); memmove(dst->array+idx+1, dst->array+idx, dst->len - idx + 1); dst->array[idx] = ch; }
static char *get_path(const char *dir, const char *file) { struct dstr str = {0}; dstr_copy(&str, dir); if (str.array && dstr_end(&str) != '/' && dstr_end(&str) != '\\') dstr_cat_ch(&str, '/'); dstr_cat(&str, file); return str.array; }
static void find_modules_in_path(struct obs_module_path *omp, obs_find_module_callback_t callback, void *param) { struct dstr search_path = {0}; char *module_start; bool search_directories = false; os_glob_t *gi; dstr_copy(&search_path, omp->bin); module_start = strstr(search_path.array, "%module%"); if (module_start) { dstr_resize(&search_path, module_start - search_path.array); search_directories = true; } if (!dstr_is_empty(&search_path) && dstr_end(&search_path) != '/') dstr_cat_ch(&search_path, '/'); dstr_cat_ch(&search_path, '*'); if (!search_directories) dstr_cat(&search_path, get_module_extension()); if (os_glob(search_path.array, 0, &gi) == 0) { for (size_t i = 0; i < gi->gl_pathc; i++) { if (search_directories == gi->gl_pathv[i].directory) process_found_module(omp, gi->gl_pathv[i].path, search_directories, callback, param); } os_globfree(gi); } dstr_free(&search_path); }
update_info_t *update_info_create( const char *log_prefix, const char *user_agent, const char *update_url, const char *local_dir, const char *cache_dir, confirm_file_callback_t confirm_callback, void *param) { struct update_info *info; struct dstr dir = {0}; if (!log_prefix) log_prefix = ""; if (os_mkdir(cache_dir) < 0) { blog(LOG_WARNING, "%sCould not create cache directory %s", log_prefix, cache_dir); return NULL; } dstr_copy(&dir, cache_dir); if (dstr_end(&dir) != '/' && dstr_end(&dir) != '\\') dstr_cat_ch(&dir, '/'); dstr_cat(&dir, ".temp"); if (os_mkdir(dir.array) < 0) { blog(LOG_WARNING, "%sCould not create temp directory %s", log_prefix, cache_dir); dstr_free(&dir); return NULL; } info = bzalloc(sizeof(*info)); info->log_prefix = bstrdup(log_prefix); info->user_agent = bstrdup(user_agent); info->temp = dir.array; info->local = bstrdup(local_dir); info->cache = bstrdup(cache_dir); info->url = get_path(update_url, "package.json"); info->callback = confirm_callback; info->param = param; if (pthread_create(&info->thread, NULL, update_thread, info) == 0) info->thread_created = true; return info; }
char *obs_find_module_file(obs_module_t module, const char *file) { struct dstr output = {0}; if (!module) return NULL; dstr_copy(&output, module->data_path); if (!dstr_is_empty(&output) && dstr_end(&output) != '/') dstr_cat_ch(&output, '/'); dstr_cat(&output, file); if (!os_file_exists(output.array)) dstr_free(&output); return output.array; }