mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-10-14 10:33:09 +08:00
With this change module loading in the application is managed by the plugin manager and allows the application to explicitly load core modules independantly from 3rd party (plugin) modules. The implementation is split into separate files for different platforms to allow for cleaner code handling the different possible locations and path schemes used, including all possible legacy locations and plugin bundle formats. This change introduces new locations and directory formats for plugins: * WINDOWS: Portable plugins need to be placed in a directory called "plugins" adjacent to the "bin" directory of an OBS Studio installation. * WINDOWS: Plugins need to be packaged into their own directory "bundles", with the associated DLL in the root of the bundle and the associated "data" directory next to it. * WINDOWS: The "obs-plugins" directory adjacent to the "bin" directory is deprecated and considered a legacy location for all plugins. * MACOS: No changes in locations or formats. * LINUX: Plugins distributed via system package managers now need to use the "obs-modules/plugins" directory in the system library directory for binaries, and the "obs/obs-modules/plugins" directory in the system data directory for resources. * LINUX: The "obs-plugins" directories in the system library and system data directories are deprecated. * LINUX: Plugins distributed outside of system packages need to use the same directory format as plugins for Windows (see above). * LINUX: A "portable" plugin location like on Windows is not supported. * LINUX: Proper XDG directory locations are scanned for plugins, using XDG_CONFIG_HOME for the legacy plugin format and XDG_DATA_HOME for the new plugin structure. * LINUX: Changes Flatpak plugin loading to use the new plugin structure (while still supporting the legacy structure), and moves Flatpak specific plugin loading to its own source files. * ALL PLATFORMS: A single environment variable "OBS_PLUGINS_PATH" can now be used to provide a highest-priority location from which to load plugins. This directory needs to contain plugin bundles per the new format. The one exception is Flatpak which does not support loading plugins from an env provided location. * ALL PLATFORMS: A custom legacy plugin locations can still be provided via the "OBS_LEGACY_PLUGINS_PATH" and "OBS_LEGACY_PLUGINS_DATA_PATH" environment variables. These are only compatible with plugins using the legacy format and are considered deprecated. The one exception is Flatpak which does not support loading plugins from an env provided location. Co-authored-by: PatTheMav <PatTheMav@users.noreply.github.com>
197 lines
6.3 KiB
C++
197 lines
6.3 KiB
C++
/******************************************************************************
|
|
Copyright (C) 2026 by FiniteSingularity <finitesingularityttv@gmail.com>
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
******************************************************************************/
|
|
|
|
#include "PluginModuleLoader.hpp"
|
|
#include "PluginManager.hpp"
|
|
|
|
#include <obs.h>
|
|
#include <util/dstr.h>
|
|
#include <util/platform.h>
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <vector>
|
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
#define WIN32_LEAN_AND_MEAN
|
|
#endif
|
|
#include <windows.h>
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
// Windows Third-Party Plugin Locations
|
|
//
|
|
// * User Path: <Environment Variable>
|
|
// * Binary: <Environment Variable>/<Plugin>/<Plugin>.dll
|
|
// * Data: <Environment Variable>/<Plugin>/data
|
|
//
|
|
// * Root Path: C:/ProgramData
|
|
// * Binary: <Root Path>/obs-studio/plugins/<Plugin>/<Plugin>.dll
|
|
// * Data: <Root Path>/obs-studio/plugins/<Plugin>/data
|
|
//
|
|
// * Portable Root Path: <OBS Binary Location>
|
|
// * Binary: <Portable Root Path>/../../plugins/<Plugin>/<Plugin>.dll
|
|
// * Data: <Portable Root Path>/../../plugins/<Plugin>/data
|
|
//
|
|
// * Legacy User Path: <Environment Variable> + <Environment Data Variable>
|
|
// * Binary: <Environment Variable>/<Plugin>.dll
|
|
// * Data: <Environment Data Variable>/<Plugin>/data
|
|
//
|
|
// * Legacy Root Path: <OBS Binary Location>
|
|
// * Binary: <Legacy Root Path>/../../obs-plugins/<Plugin>.dll
|
|
// * Data: <Legacy Root Path>/../../data/obs-plugins/<Plugin>
|
|
//
|
|
// * Legacy Portable Path: <OBS Binary Location>
|
|
// * Binary: <Legacy Root Path>/../../obs-plugins/<Plugin>.dll
|
|
// * Data: <Legacy Root Path>/../../data/obs-plugins/<Plugin>
|
|
//
|
|
// * Legacy System Path: C:/ProgramData
|
|
// * Binary: <Legacy System Path>/obs-studio/plugins/<Plugin>/bin/<Plugin>.dll
|
|
// * Data: <Legacy System Path>/obs-studio/plugins/<Plugin>/data
|
|
//
|
|
|
|
using State = OBS::PluginManager::State;
|
|
using ModuleType = obs_runtime_module_type;
|
|
|
|
constexpr std::string_view kPluginPathSuffix{"obs-studio/plugins/%module%"};
|
|
constexpr std::string_view kUserPluginPathSuffix{"/%module%"};
|
|
constexpr std::string_view kPortablePluginPath{"../../plugins/%module%"};
|
|
|
|
constexpr std::string_view kLegacyPortableBinaryPath{"../../obs-plugins/64bit/"};
|
|
constexpr std::string_view kLegacyPortableDataPath{"../../data/obs-plugins/%module%"};
|
|
|
|
namespace {
|
|
State loadPluginsFromPath(const std::string &pathString, ModuleType type, ModuleList &failedModules)
|
|
{
|
|
std::string binaryPath{pathString};
|
|
std::string dataPath{pathString};
|
|
|
|
switch (type) {
|
|
case OBS_MODULE_TYPE_LEGACY_PLUGIN: {
|
|
binaryPath.append("/bin/64bit");
|
|
dataPath.append("/data");
|
|
break;
|
|
}
|
|
default: {
|
|
dataPath.append("/data");
|
|
break;
|
|
}
|
|
}
|
|
|
|
ModuleLoadInfo info = {0};
|
|
info.path_info.binary = binaryPath.c_str();
|
|
info.path_info.data = dataPath.c_str();
|
|
info.type = type;
|
|
info.name = nullptr;
|
|
|
|
int failedModuleCount = loadPluginsByInfo(info, failedModules);
|
|
|
|
State result = (failedModuleCount > 0) ? State::PartialFailure : State::Success;
|
|
|
|
return result;
|
|
}
|
|
} // namespace
|
|
|
|
namespace OBS {
|
|
State PluginManager::loadPlugins(bool usePortableMode)
|
|
{
|
|
State userPluginState = State::Failure;
|
|
std::string userPluginPath = getEnvironmentVariable(kPathVariable);
|
|
|
|
if (!userPluginPath.empty()) {
|
|
userPluginPath.append(kUserPluginPathSuffix);
|
|
|
|
userPluginState = loadPluginsFromPath(userPluginPath, OBS_MODULE_TYPE_PLUGIN, failedModules_);
|
|
} else {
|
|
userPluginState = State::Success;
|
|
}
|
|
|
|
State libraryPluginState = State::Failure;
|
|
std::string appLibraryPath{};
|
|
|
|
if (!usePortableMode) {
|
|
appLibraryPath.resize(MAX_PATH);
|
|
int bufferSize = os_get_program_data_path(appLibraryPath.data(), appLibraryPath.size(),
|
|
kPluginPathSuffix.data());
|
|
if (bufferSize > 0) {
|
|
appLibraryPath.resize(bufferSize);
|
|
}
|
|
} else {
|
|
appLibraryPath = kPortablePluginPath;
|
|
}
|
|
|
|
libraryPluginState = loadPluginsFromPath(appLibraryPath, OBS_MODULE_TYPE_PLUGIN, failedModules_);
|
|
|
|
return (userPluginState && libraryPluginState) ? State::Success : State::PartialFailure;
|
|
}
|
|
|
|
State PluginManager::loadLegacyPlugins(bool usePortableMode)
|
|
{
|
|
State userPluginState = State::Failure;
|
|
|
|
std::string userPluginPath = getEnvironmentVariable(kLegacyBinaryPathVariable);
|
|
std::string userDataPath = getEnvironmentVariable(kLegacyDataPathVariable);
|
|
|
|
if (!userPluginPath.empty() && !userDataPath.empty()) {
|
|
userDataPath.append(kUserPluginPathSuffix);
|
|
|
|
ModuleLoadInfo info = {0};
|
|
info.path_info.binary = userPluginPath.c_str();
|
|
info.path_info.data = userDataPath.c_str();
|
|
info.type = OBS_MODULE_TYPE_LEGACY_PLUGIN;
|
|
info.name = nullptr;
|
|
|
|
int failedModuleCount = loadPluginsByInfo(info, failedModules_);
|
|
|
|
userPluginState = (failedModuleCount > 0) ? State::PartialFailure : State::Success;
|
|
} else {
|
|
userPluginState = State::Success;
|
|
}
|
|
|
|
State portablePluginState = State::Failure;
|
|
|
|
{
|
|
ModuleLoadInfo info = {0};
|
|
info.path_info.binary = kLegacyPortableBinaryPath.data();
|
|
info.path_info.data = kLegacyPortableDataPath.data();
|
|
info.type = OBS_MODULE_TYPE_LEGACY_PLUGIN;
|
|
info.name = nullptr;
|
|
|
|
int failedModuleCount = loadPluginsByInfo(info, failedModules_);
|
|
|
|
portablePluginState = (failedModuleCount > 0) ? State::PartialFailure : State::Success;
|
|
}
|
|
|
|
State libraryPluginState = State::Failure;
|
|
|
|
if (!usePortableMode) {
|
|
std::string appLibraryPath{};
|
|
appLibraryPath.resize(MAX_PATH);
|
|
int bufferSize = os_get_program_data_path(appLibraryPath.data(), appLibraryPath.size(),
|
|
kPluginPathSuffix.data());
|
|
if (bufferSize > 0) {
|
|
appLibraryPath.resize(bufferSize);
|
|
libraryPluginState =
|
|
loadPluginsFromPath(appLibraryPath, OBS_MODULE_TYPE_LEGACY_PLUGIN, failedModules_);
|
|
}
|
|
} else {
|
|
libraryPluginState = State::Success;
|
|
}
|
|
|
|
return (userPluginState && portablePluginState && libraryPluginState) ? State::Success : State::PartialFailure;
|
|
}
|
|
} // namespace OBS
|