Skip to content

Commit 93004f5

Browse files
committed
frontend: Change order of loading modules
Plugins are now required to be installed in %PROGRAMDATA%. Since its module path is added after the default module paths, the plugins in there will be loaded last. With the load modules once PR (#12285), the module added in the default path will be the only one loaded. We want the one in %PROGRAMDATA% to be the one loaded instead.
1 parent d3c5d2c commit 93004f5

2 files changed

Lines changed: 103 additions & 101 deletions

File tree

frontend/OBSApp.cpp

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <windows.h>
4949
#else
5050
#include <unistd.h>
51+
#include <unordered_set>
5152
#include <sys/socket.h>
5253
#endif
5354

@@ -79,6 +80,100 @@ extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 1;
7980
extern "C" __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
8081
#endif
8182

83+
namespace {
84+
void addExtraModulePaths()
85+
{
86+
string plugins_path, plugins_data_path;
87+
char *s;
88+
89+
s = getenv("OBS_PLUGINS_PATH");
90+
if (s)
91+
plugins_path = s;
92+
93+
s = getenv("OBS_PLUGINS_DATA_PATH");
94+
if (s)
95+
plugins_data_path = s;
96+
97+
if (!plugins_path.empty() && !plugins_data_path.empty()) {
98+
#if defined(__APPLE__)
99+
plugins_path += "/%module%.plugin/Contents/MacOS";
100+
plugins_data_path += "/%module%.plugin/Contents/Resources";
101+
obs_add_module_path(plugins_path.c_str(), plugins_data_path.c_str());
102+
#else
103+
string data_path_with_module_suffix;
104+
data_path_with_module_suffix += plugins_data_path;
105+
data_path_with_module_suffix += "/%module%";
106+
obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str());
107+
#endif
108+
}
109+
110+
if (portable_mode)
111+
return;
112+
113+
char base_module_dir[512];
114+
#if defined(_WIN32)
115+
int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
116+
#elif defined(__APPLE__)
117+
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%.plugin");
118+
#else
119+
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
120+
#endif
121+
122+
if (ret <= 0)
123+
return;
124+
125+
string path = base_module_dir;
126+
#if defined(__APPLE__)
127+
/* User Application Support Search Path */
128+
obs_add_module_path((path + "/Contents/MacOS").c_str(), (path + "/Contents/Resources").c_str());
129+
130+
#ifndef __aarch64__
131+
/* Legacy System Library Search Path */
132+
char system_legacy_module_dir[PATH_MAX];
133+
GetProgramDataPath(system_legacy_module_dir, sizeof(system_legacy_module_dir), "obs-studio/plugins/%module%");
134+
std::string path_system_legacy = system_legacy_module_dir;
135+
obs_add_module_path((path_system_legacy + "/bin").c_str(), (path_system_legacy + "/data").c_str());
136+
137+
/* Legacy User Application Support Search Path */
138+
char user_legacy_module_dir[PATH_MAX];
139+
GetAppConfigPath(user_legacy_module_dir, sizeof(user_legacy_module_dir), "obs-studio/plugins/%module%");
140+
std::string path_user_legacy = user_legacy_module_dir;
141+
obs_add_module_path((path_user_legacy + "/bin").c_str(), (path_user_legacy + "/data").c_str());
142+
#endif
143+
#else
144+
#if ARCH_BITS == 64
145+
obs_add_module_path((path + "/bin/64bit").c_str(), (path + "/data").c_str());
146+
#else
147+
obs_add_module_path((path + "/bin/32bit").c_str(), (path + "/data").c_str());
148+
#endif
149+
#endif
150+
}
151+
152+
/* First-party modules considered to be potentially unsafe to load in Safe Mode
153+
* due to them allowing external code (e.g. scripts) to modify OBS's state. */
154+
const unordered_set<string> unsafe_modules = {
155+
"frontend-tools", // Scripting
156+
"obs-websocket", // Allows outside modifications
157+
};
158+
159+
void setSafeModuleNames()
160+
{
161+
#ifndef SAFE_MODULES
162+
return;
163+
#else
164+
string module;
165+
stringstream modules(SAFE_MODULES);
166+
167+
while (getline(modules, module, '|')) {
168+
/* When only disallowing third-party plugins, still add
169+
* "unsafe" bundled modules to the safe list. */
170+
if (disable_3p_plugins || !unsafe_modules.count(module))
171+
obs_add_safe_module(module.c_str());
172+
}
173+
#endif
174+
}
175+
} // namespace
176+
82177
QObject *CreateShortcutFilter()
83178
{
84179
return new OBSEventFilter([](QObject *obj, QEvent *event) {
@@ -1086,6 +1181,14 @@ bool OBSApp::OBSInit()
10861181
setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
10871182
#endif
10881183

1184+
/* Safe Mode disables third-party plugins so we don't need to add earch
1185+
* paths outside the OBS bundle/installation. */
1186+
if (safe_mode || disable_3p_plugins) {
1187+
setSafeModuleNames();
1188+
} else {
1189+
addExtraModulePaths();
1190+
}
1191+
10891192
if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
10901193
return false;
10911194

frontend/widgets/OBSBasic.cpp

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#include <sstream>
6161
#endif
6262
#include <string>
63-
#include <unordered_set>
6463

6564
#ifdef _WIN32
6665
#define WIN32_LEAN_AND_MEAN
@@ -103,98 +102,6 @@ extern bool cef_js_avail;
103102
extern void DestroyPanelCookieManager();
104103
extern void CheckExistingCookieId();
105104

106-
static void AddExtraModulePaths()
107-
{
108-
string plugins_path, plugins_data_path;
109-
char *s;
110-
111-
s = getenv("OBS_PLUGINS_PATH");
112-
if (s)
113-
plugins_path = s;
114-
115-
s = getenv("OBS_PLUGINS_DATA_PATH");
116-
if (s)
117-
plugins_data_path = s;
118-
119-
if (!plugins_path.empty() && !plugins_data_path.empty()) {
120-
#if defined(__APPLE__)
121-
plugins_path += "/%module%.plugin/Contents/MacOS";
122-
plugins_data_path += "/%module%.plugin/Contents/Resources";
123-
obs_add_module_path(plugins_path.c_str(), plugins_data_path.c_str());
124-
#else
125-
string data_path_with_module_suffix;
126-
data_path_with_module_suffix += plugins_data_path;
127-
data_path_with_module_suffix += "/%module%";
128-
obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str());
129-
#endif
130-
}
131-
132-
if (portable_mode)
133-
return;
134-
135-
char base_module_dir[512];
136-
#if defined(_WIN32)
137-
int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
138-
#elif defined(__APPLE__)
139-
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%.plugin");
140-
#else
141-
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
142-
#endif
143-
144-
if (ret <= 0)
145-
return;
146-
147-
string path = base_module_dir;
148-
#if defined(__APPLE__)
149-
/* User Application Support Search Path */
150-
obs_add_module_path((path + "/Contents/MacOS").c_str(), (path + "/Contents/Resources").c_str());
151-
152-
#ifndef __aarch64__
153-
/* Legacy System Library Search Path */
154-
char system_legacy_module_dir[PATH_MAX];
155-
GetProgramDataPath(system_legacy_module_dir, sizeof(system_legacy_module_dir), "obs-studio/plugins/%module%");
156-
std::string path_system_legacy = system_legacy_module_dir;
157-
obs_add_module_path((path_system_legacy + "/bin").c_str(), (path_system_legacy + "/data").c_str());
158-
159-
/* Legacy User Application Support Search Path */
160-
char user_legacy_module_dir[PATH_MAX];
161-
GetAppConfigPath(user_legacy_module_dir, sizeof(user_legacy_module_dir), "obs-studio/plugins/%module%");
162-
std::string path_user_legacy = user_legacy_module_dir;
163-
obs_add_module_path((path_user_legacy + "/bin").c_str(), (path_user_legacy + "/data").c_str());
164-
#endif
165-
#else
166-
#if ARCH_BITS == 64
167-
obs_add_module_path((path + "/bin/64bit").c_str(), (path + "/data").c_str());
168-
#else
169-
obs_add_module_path((path + "/bin/32bit").c_str(), (path + "/data").c_str());
170-
#endif
171-
#endif
172-
}
173-
174-
/* First-party modules considered to be potentially unsafe to load in Safe Mode
175-
* due to them allowing external code (e.g. scripts) to modify OBS's state. */
176-
static const unordered_set<string> unsafe_modules = {
177-
"frontend-tools", // Scripting
178-
"obs-websocket", // Allows outside modifications
179-
};
180-
181-
static void SetSafeModuleNames()
182-
{
183-
#ifndef SAFE_MODULES
184-
return;
185-
#else
186-
string module;
187-
stringstream modules(SAFE_MODULES);
188-
189-
while (getline(modules, module, '|')) {
190-
/* When only disallowing third-party plugins, still add
191-
* "unsafe" bundled modules to the safe list. */
192-
if (disable_3p_plugins || !unsafe_modules.count(module))
193-
obs_add_safe_module(module.c_str());
194-
}
195-
#endif
196-
}
197-
198105
extern void setupDockAction(QDockWidget *dock);
199106

200107
OBSBasic::OBSBasic(QWidget *parent) : OBSMainWindow(parent), undo_s(ui), ui(new Ui::OBSBasic)
@@ -952,14 +859,6 @@ void OBSBasic::OBSInit()
952859
#endif
953860
struct obs_module_failure_info mfi;
954861

955-
/* Safe Mode disables third-party plugins so we don't need to add earch
956-
* paths outside the OBS bundle/installation. */
957-
if (safe_mode || disable_3p_plugins) {
958-
SetSafeModuleNames();
959-
} else {
960-
AddExtraModulePaths();
961-
}
962-
963862
/* Modules can access frontend information (i.e. profile and scene collection data) during their initialization, and some modules (e.g. obs-websockets) are known to use the filesystem location of the current profile in their own code.
964863
965864
Thus the profile and scene collection discovery needs to happen before any access to that information (but after intializing global settings) to ensure legacy code gets valid path information.

0 commit comments

Comments
 (0)