void OBSBasic::DeleteProfile(const char *profileName, const char *profileDir) { char profilePath[512]; char basePath[512]; int ret = GetConfigPath(basePath, 512, "obs-studio/basic/profiles"); if (ret <= 0) { blog(LOG_WARNING, "Failed to get profiles config path"); return; } ret = snprintf(profilePath, 512, "%s/%s/*", basePath, profileDir); if (ret <= 0) { blog(LOG_WARNING, "Failed to get path for profile dir '%s'", profileDir); return; } os_glob_t *glob; if (os_glob(profilePath, 0, &glob) != 0) { blog(LOG_WARNING, "Failed to glob profile dir '%s'", profileDir); return; } for (size_t i = 0; i < glob->gl_pathc; i++) { const char *filePath = glob->gl_pathv[i].path; if (glob->gl_pathv[i].directory) continue; os_unlink(filePath); } os_globfree(glob); ret = snprintf(profilePath, 512, "%s/%s", basePath, profileDir); if (ret <= 0) { blog(LOG_WARNING, "Failed to get path for profile dir '%s'", profileDir); return; } os_rmdir(profilePath); blog(LOG_INFO, "------------------------------------------------"); blog(LOG_INFO, "Removed profile '%s' (%s)", profileName, profileDir); blog(LOG_INFO, "------------------------------------------------"); }
template <typename Func> static void EnumProfiles(Func &&cb) { char path[512]; os_glob_t *glob; int ret = GetConfigPath(path, sizeof(path), "obs-studio/basic/profiles/*"); if (ret <= 0) { blog(LOG_WARNING, "Failed to get profiles config path"); return; } if (os_glob(path, 0, &glob) != 0) { blog(LOG_WARNING, "Failed to glob profiles"); return; } for (size_t i = 0; i < glob->gl_pathc; i++) { const char *filePath = glob->gl_pathv[i].path; const char *dirName = strrchr(filePath, '/') + 1; if (!glob->gl_pathv[i].directory) continue; if (strcmp(dirName, ".") == 0 || strcmp(dirName, "..") == 0) continue; std::string file = filePath; file += "/basic.ini"; ConfigFile config; int ret = config.Open(file.c_str(), CONFIG_OPEN_EXISTING); if (ret != CONFIG_SUCCESS) continue; const char *name = config_get_string(config, "General", "Name"); if (!name) name = strrchr(filePath, '/') + 1; if (!cb(name, filePath)) break; } os_globfree(glob); }
template <typename Func> static void EnumSceneCollections(Func &&cb) { char path[512]; os_glob_t *glob; int ret = GetConfigPath(path, sizeof(path), "obs-studio/basic/scenes/*.json"); if (ret <= 0) { blog(LOG_WARNING, "Failed to get config path for scene " "collections"); return; } if (os_glob(path, 0, &glob) != 0) { blog(LOG_WARNING, "Failed to glob scene collections"); return; } for (size_t i = 0; i < glob->gl_pathc; i++) { const char *filePath = glob->gl_pathv[i].path; if (glob->gl_pathv[i].directory) continue; BPtr<char> fileData = os_quick_read_utf8_file(filePath); if (!fileData) continue; obs_data_t *data = obs_data_create_from_json(fileData); std::string name = obs_data_get_string(data, "name"); /* if no name found, use the file name as the name * (this only happens when switching to the new version) */ if (name.empty()) { name = strrchr(filePath, '/') + 1; name.resize(name.size() - 5); } obs_data_release(data); if (!cb(name.c_str(), filePath)) break; } os_globfree(glob); }
static bool CopyProfile(const char *fromPartial, const char *to) { os_glob_t *glob; char path[512]; int ret; ret = GetConfigPath(path, sizeof(path), "obs-studio/basic/profiles/"); if (ret <= 0) { blog(LOG_WARNING, "Failed to get profiles config path"); return false; } strcat(path, fromPartial); strcat(path, "/*"); if (os_glob(path, 0, &glob) != 0) { blog(LOG_WARNING, "Failed to glob profile '%s'", fromPartial); return false; } for (size_t i = 0; i < glob->gl_pathc; i++) { const char *filePath = glob->gl_pathv[i].path; if (glob->gl_pathv[i].directory) continue; ret = snprintf(path, sizeof(path), "%s/%s", to, strrchr(filePath, '/') + 1); if (ret > 0) { if (os_copyfile(filePath, path) != 0) { blog(LOG_WARNING, "CopyProfile: Failed to " "copy file %s to %s", filePath, path); } } } os_globfree(glob); return true; }
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); }