diff --git a/frontend/widgets/OBSBasic.cpp b/frontend/widgets/OBSBasic.cpp index e56b7e27791392..71cc70b668d294 100644 --- a/frontend/widgets/OBSBasic.cpp +++ b/frontend/widgets/OBSBasic.cpp @@ -195,6 +195,19 @@ static void SetSafeModuleNames() #endif } +static void SetDefaultModuleNames() +{ +#ifndef SAFE_MODULES + return; +#else + string module; + stringstream modules(SAFE_MODULES); + + while (getline(modules, module, '|')) + obs_add_default_module(module.c_str()); +#endif +} + extern void setupDockAction(QDockWidget *dock); OBSBasic::OBSBasic(QWidget *parent) : OBSMainWindow(parent), undo_s(ui), ui(new Ui::OBSBasic) @@ -952,6 +965,9 @@ void OBSBasic::OBSInit() #endif struct obs_module_failure_info mfi; + if (!portable_mode) + SetDefaultModuleNames(); + /* Safe Mode disables third-party plugins so we don't need to add earch * paths outside the OBS bundle/installation. */ if (safe_mode || disable_3p_plugins) { diff --git a/libobs/obs-cocoa.m b/libobs/obs-cocoa.m index 08b64ef1b0aa01..d0b718fd3c8003 100644 --- a/libobs/obs-cocoa.m +++ b/libobs/obs-cocoa.m @@ -41,7 +41,7 @@ void add_default_module_paths(void) NSString *pluginModulePath = [[pluginURL path] stringByAppendingString:@"/%module%.plugin/Contents/MacOS/"]; NSString *pluginDataPath = [[pluginURL path] stringByAppendingString:@"/%module%.plugin/Contents/Resources/"]; - obs_add_module_path(pluginModulePath.UTF8String, pluginDataPath.UTF8String); + obs_add_default_module_path(pluginModulePath.UTF8String, pluginDataPath.UTF8String); } char *find_libobs_data_file(const char *file) diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index 26d67d24e41cea..603c0d15672eec 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -133,6 +133,7 @@ extern void free_module(struct obs_module *mod); struct obs_module_path { char *bin; char *data; + bool is_default; }; static inline void free_module_path(struct obs_module_path *omp) @@ -489,6 +490,7 @@ struct obs_core { struct obs_module *first_module; DARRAY(struct obs_module_path) module_paths; DARRAY(char *) safe_modules; + DARRAY(char *) default_modules; obs_source_info_array_t source_types; obs_source_info_array_t input_types; diff --git a/libobs/obs-module.c b/libobs/obs-module.c index 5fe3b8a8f1ad4f..64d2088e41eb3d 100644 --- a/libobs/obs-module.c +++ b/libobs/obs-module.c @@ -264,6 +264,20 @@ void obs_add_module_path(const char *bin, const char *data) omp.bin = bstrdup(bin); omp.data = bstrdup(data); + omp.is_default = false; + da_push_back(obs->module_paths, &omp); +} + +void obs_add_default_module_path(const char *bin, const char *data) +{ + struct obs_module_path omp; + + if (!obs || !bin || !data) + return; + + omp.bin = bstrdup(bin); + omp.data = bstrdup(data); + omp.is_default = true; da_push_back(obs->module_paths, &omp); } @@ -276,6 +290,15 @@ void obs_add_safe_module(const char *name) da_push_back(obs->safe_modules, &item); } +void obs_add_default_module(const char *name) +{ + if (!obs || !name) + return; + + char *item = bstrdup(name); + da_push_back(obs->default_modules, &item); +} + extern void get_plugin_info(const char *path, bool *is_obs_plugin, bool *can_load); struct fail_info { @@ -296,6 +319,30 @@ static bool is_safe_module(const char *name) return false; } +static bool is_default_module(const char *name) +{ + if (!obs->default_modules.num) + return true; + + for (size_t i = 0; i < obs->default_modules.num; i++) { + if (strcmp(name, obs->default_modules.array[i]) == 0) + return true; + } + + return false; +} + +static bool is_default_path(const char *name) +{ + for (size_t i = 0; i < obs->module_paths.num; i++) { + if (strstr(name, obs->module_paths.array[i].bin) != NULL && + obs->module_paths.array[i].is_default == true) + return true; + } + + return false; +} + static void load_all_callback(void *param, const struct obs_module_info2 *info) { struct fail_info *fail_info = param; @@ -311,6 +358,11 @@ static void load_all_callback(void *param, const struct obs_module_info2 *info) return; } + if (is_default_path(info->bin_path) && !is_default_module(info->name)) { + blog(LOG_WARNING, "Skipping module '%s', not a default plugin in the default directory", info->name); + return; + } + if (!is_safe_module(info->name)) { blog(LOG_WARNING, "Skipping module '%s', not on safe list", info->name); return; diff --git a/libobs/obs-nix.c b/libobs/obs-nix.c index d28269687ff241..6a492c1a7239dc 100644 --- a/libobs/obs-nix.c +++ b/libobs/obs-nix.c @@ -86,7 +86,7 @@ void add_default_module_paths(void) bfree(module_data_path); for (int i = 0; i < module_patterns_size; i++) { - obs_add_module_path(module_bin[i], module_data[i]); + obs_add_default_module_path(module_bin[i], module_data[i]); } } diff --git a/libobs/obs-windows.c b/libobs/obs-windows.c index 90fb343052eea2..eb46631ba5cd9c 100644 --- a/libobs/obs-windows.c +++ b/libobs/obs-windows.c @@ -43,7 +43,7 @@ static const int module_patterns_size = sizeof(module_bin) / sizeof(module_bin[0 void add_default_module_paths(void) { for (int i = 0; i < module_patterns_size; i++) - obs_add_module_path(module_bin[i], module_data[i]); + obs_add_default_module_path(module_bin[i], module_data[i]); } /* on windows, points to [base directory]/data/libobs */ diff --git a/libobs/obs.c b/libobs/obs.c index 51fa5dc4c01016..6496f385be077b 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -1420,6 +1420,10 @@ void obs_shutdown(void) bfree(obs->safe_modules.array[i]); da_free(obs->safe_modules); + for (size_t i = 0; i < obs->default_modules.num; i++) + bfree(obs->default_modules.array[i]); + da_free(obs->default_modules); + if (obs->name_store_owned) profiler_name_store_free(obs->name_store); diff --git a/libobs/obs.h b/libobs/obs.h index ca49835d46711a..e6f46036675a40 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -525,6 +525,14 @@ EXPORT const char *obs_get_module_data_path(obs_module_t *module); */ EXPORT void obs_add_module_path(const char *bin, const char *data); +/** + * Adds a search path for default modules. + * + * @param bin Specifies the default module's binary directory search path. + * @param data Specifies the default module's data directory search path. + */ +EXPORT void obs_add_default_module_path(const char *bin, const char *data); + /** * Adds a module to the list of modules allowed to load in Safe Mode. * If the list is empty, all modules are allowed. @@ -533,6 +541,13 @@ EXPORT void obs_add_module_path(const char *bin, const char *data); */ EXPORT void obs_add_safe_module(const char *name); +/** + * Adds a module to the list of default modules + * + * @param name Specifies the module's name (filename sans extension). + */ +EXPORT void obs_add_default_module(const char *name); + /** Automatically loads all modules from module paths (convenience function) */ EXPORT void obs_load_all_modules(void);