Files
UnrealEngineUWP/Engine/Source/Runtime/Projects/Private/PluginManager.cpp
Ben Marsh 3e80336791 Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3092544)
#lockdown Nick.Penwarden
#rb none

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3079316 on 2016/08/05 by Ben.Marsh

	Better PCH selection in ShaderFormatOpenGL and MetalShaderFormat - make sure Core is the first included header.

Change 3080579 on 2016/08/08 by Ben.Marsh

	Slate: Move DEBUG_TAB_MANAGEMENT into SDockingTabStack.h to remove circular include dependency with DockingPrivate.h.

Change 3080587 on 2016/08/08 by Ben.Marsh

	StandaloneRenderer: Move platform includes into a separate header so we can make individual headers self-contained, without having a circular dependency on StandaloneRendererPrivate.h.

Change 3080789 on 2016/08/08 by Ben.Marsh

	Move BuildGraph tasks for chunking, posting builds, labeling builds, and merging manifests into the MCP project. While we do provide public interfaces for this functionality, we don't currently expect anyone outside Epic to be using them.

Change 3080815 on 2016/08/08 by Ben.Marsh

	BuildGraph: Add a -GenerateDocs option, which writes out an HTML file constructed from C# XML documentation containing all the task information.

Change 3081374 on 2016/08/08 by Ben.Marsh

	UBT: Invalidate the makefile if any UHT headers are deleted. Should fix issue where files are moved from one module to another, and the original module no longer contains any generated headers. Its include path needs to be removed from the compile environment.

Change 3083152 on 2016/08/09 by Ben.Marsh

	PR #2667: Add Intel C++ Compiler support to Windows build (Contributed by JeffRous)

Change 3084039 on 2016/08/10 by Ben.Marsh

	BuildGraph: Add additional markup for parameter attributes. Also improve some documation.

Change 3084240 on 2016/08/10 by Ben.Marsh

	Plugins: Allow plugins in the project folder to replace plugins in the engine folder with the same name. Prohibit multiple plugins with the same name at other times.

Change 3084337 on 2016/08/10 by Ben.Marsh

	UBT: Specify the -precompile option when generating project files for a target, so we include all valid modules for intellisense.

Change 3085594 on 2016/08/11 by Ben.Marsh

	Change modules which reference a public header for their PCH to use a private PCH instead, even if it just includes the public header for now.

Change 3085999 on 2016/08/11 by Ben.Marsh

	Add some missing #pragma once directives.

Change 3086146 on 2016/08/11 by Ben.Marsh

	Core: Move prototype and linkage specifier for ConsoleCommandLibrary_* functions into header matching cpp file.

Change 3086172 on 2016/08/11 by Ben.Marsh

	Fixup some C-style header guards to use #pragma once instead.

Change 3087289 on 2016/08/12 by Ben.Marsh

	Split out UPackage and UMetaData into their own headers (they're already implemented in separate CPP files)

Change 3087310 on 2016/08/12 by Ben.Marsh

	Move method stubs for FNullSlateSoundDevice into a CPP file, since they're exported from the SlateCore module.

Change 3087341 on 2016/08/12 by Ben.Marsh

	UdpMessaging: Move PCH before #if PLATFORM_DESKTOP; it will only be defined if the definition is included.

Change 3087457 on 2016/08/12 by Ben.Marsh

	Core: Reorganize the FTransform and FMatrix headers: Transform.h now includes TransformNonVectorized.h or TransformVectorized.h as appropriate, and UnrealMatrix.h is now Matrix.inl (and included from Matrix.h).

Change 3088407 on 2016/08/13 by Ben.Marsh

	Replace use of Windows SIZE_T define with the regular C++ size_t.

Change 3088416 on 2016/08/13 by Ben.Marsh

	Include a header from all .generated.cpp files (GeneratedCppIncludes.h) which includes all the basic types required to compile them, rather than assuming that the module PCH will include everything.

	Also include the real declarations of noexport classes in Object.h (now renamed to NoExportTypes.h for clarity) when the CPP macro is defined, so the .generated.deps.h file will automatically have the correct definitions for them at compile time rather than relying on them being in the private PCH.

	Finally, rename UObject.h to Object.h for consistency with the naming convention for all other UObject classes. UObject.h still exists for now, but outputs a deprecated message if included.

Change 3088544 on 2016/08/14 by Ben.Marsh

	Core: Move the definition of the TEXT() macro into Platform.h, to avoid having to include OS headers to get it.

Change 3088552 on 2016/08/14 by Ben.Marsh

	Fix compile errors for some modules that don't already include CoreUObject.h.

Change 3088925 on 2016/08/15 by Ben.Marsh

	Remove circular include dependencies from VulkanRHI.

Change 3088926 on 2016/08/15 by Ben.Marsh

	Remove duplicate definition for WITH_FIXED_AREA_ENTERING_COST from EngineDefines.h - always uses the definition from DetourNavMeshQuery.h instead.

Change 3088930 on 2016/08/15 by Ben.Marsh

	Remove circular include dependency from PhysX.

Change 3088935 on 2016/08/15 by Ben.Marsh

	OnlineSubsystemUtils: Move CPP files out of public header directory.

Change 3088965 on 2016/08/15 by Ben.Marsh

	Add private PCH to Landscape, MoviePlayer, TaskGraph, XAudio2 and RealtimeProfiler modules.

Change 3088966 on 2016/08/15 by Ben.Marsh

	Engine: Move CPP files out of public header directories.

Change 3089520 on 2016/08/15 by Ben.Marsh

	BuildGraph: Change documentation command to output markdown.

Change 3090299 on 2016/08/16 by Ben.Marsh

	D3D12RHI: Move around some implementations to fix circular header dependencies which are masked by delayed template instantiation.

Change 3090303 on 2016/08/16 by Ben.Marsh

	Engine: Add a template specialization for TPointerIsConvertibleFromTo<AActor, const volatile UObject> to fix dependency on complete AActor definition for static assert in TWeakPointer<AActor>, which only appears if including Level.h without Actor.h. Delayed template instantiation usually masks this issue.

Change 3091861 on 2016/08/17 by Ben.Marsh

	Remove circular header dependencies, and fix ambiguous include paths in OSVR.

Change 3092068 on 2016/08/17 by Ben.Marsh

	Moving VulkanDynamicRHI into its own header.

Change 3093133 on 2016/08/18 by Ben.Marsh

	EC: Include additional context lines for Clang errors.

Change 3093147 on 2016/08/18 by Ben.Marsh

	UBT: Add an error message when attempting to do a single-file compile with the wrong target selected.

Change 3093228 on 2016/08/18 by Ben.Marsh

	Remove redundant setting for remote server name from XML config, and set it to a valid machine in the engine config.

[CL 3093264 by Ben Marsh in Main branch]
2016-08-18 10:28:43 -04:00

754 lines
24 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "ProjectsPrivatePCH.h"
DEFINE_LOG_CATEGORY_STATIC( LogPluginManager, Log, All );
#define LOCTEXT_NAMESPACE "PluginManager"
namespace PluginSystemDefs
{
/** File extension of plugin descriptor files.
NOTE: This constant exists in UnrealBuildTool code as well. */
static const TCHAR PluginDescriptorFileExtension[] = TEXT( ".uplugin" );
/**
* Parsing the command line and loads any foreign plugins that were
* specified using the -PLUGIN= command.
*
* @param CommandLine The commandline used to launch the editor.
* @param SearchPathsOut
* @return The number of plugins that were specified using the -PLUGIN param.
*/
static int32 GetAdditionalPluginPaths(TSet<FString>& PluginPathsOut)
{
const TCHAR* SwitchStr = TEXT("PLUGIN=");
const int32 SwitchLen = FCString::Strlen(SwitchStr);
int32 PluginCount = 0;
const TCHAR* SearchStr = FCommandLine::Get();
do
{
FString PluginPath;
SearchStr = FCString::Strfind(SearchStr, SwitchStr);
if (FParse::Value(SearchStr, SwitchStr, PluginPath))
{
FString PluginDir = FPaths::GetPath(PluginPath);
PluginPathsOut.Add(PluginDir);
++PluginCount;
SearchStr += SwitchLen + PluginPath.Len();
}
else
{
break;
}
} while (SearchStr != nullptr);
#if IS_PROGRAM
// For programs that have the project dir set, look for plugins under the project directory
const FProjectDescriptor *Project = IProjectManager::Get().GetCurrentProject();
if (Project != nullptr)
{
PluginPathsOut.Add(FPaths::GetPath(FPaths::GetProjectFilePath()) / TEXT("Plugins"));
}
#endif
return PluginCount;
}
}
FPlugin::FPlugin(const FString& InFileName, const FPluginDescriptor& InDescriptor, EPluginLoadedFrom InLoadedFrom)
: Name(FPaths::GetBaseFilename(InFileName))
, FileName(InFileName)
, Descriptor(InDescriptor)
, LoadedFrom(InLoadedFrom)
, bEnabled(false)
{
}
FPlugin::~FPlugin()
{
}
FString FPlugin::GetName() const
{
return Name;
}
FString FPlugin::GetDescriptorFileName() const
{
return FileName;
}
FString FPlugin::GetBaseDir() const
{
return FPaths::GetPath(FileName);
}
FString FPlugin::GetContentDir() const
{
return FPaths::GetPath(FileName) / TEXT("Content");
}
FString FPlugin::GetMountedAssetPath() const
{
return FString::Printf(TEXT("/%s/"), *Name);
}
bool FPlugin::IsEnabled() const
{
return bEnabled;
}
bool FPlugin::CanContainContent() const
{
return Descriptor.bCanContainContent;
}
EPluginLoadedFrom FPlugin::GetLoadedFrom() const
{
return LoadedFrom;
}
const FPluginDescriptor& FPlugin::GetDescriptor() const
{
return Descriptor;
}
bool FPlugin::UpdateDescriptor(const FPluginDescriptor& NewDescriptor, FText& OutFailReason)
{
if(!NewDescriptor.Save(FileName, OutFailReason))
{
return false;
}
Descriptor = NewDescriptor;
return true;
}
FPluginManager::FPluginManager()
: bHaveConfiguredEnabledPlugins(false)
, bHaveAllRequiredPlugins(false)
{
DiscoverAllPlugins();
}
FPluginManager::~FPluginManager()
{
// NOTE: All plugins and modules should be cleaned up or abandoned by this point
// @todo plugin: Really, we should "reboot" module manager's unloading code so that it remembers at which startup phase
// modules were loaded in, so that we can shut groups of modules down (in reverse-load order) at the various counterpart
// shutdown phases. This will fix issues where modules that are loaded after game modules are shutdown AFTER many engine
// systems are already killed (like GConfig.) Currently the only workaround is to listen to global exit events, or to
// explicitly unload your module somewhere. We should be able to handle most cases automatically though!
}
void FPluginManager::RefreshPluginsList()
{
// Read a new list of all plugins
TMap<FString, TSharedRef<FPlugin>> NewPlugins;
ReadAllPlugins(NewPlugins, PluginDiscoveryPaths);
// Build a list of filenames for plugins which are enabled, and remove the rest
TArray<FString> EnabledPluginFileNames;
for(TMap<FString, TSharedRef<FPlugin>>::TIterator Iter(AllPlugins); Iter; ++Iter)
{
const TSharedRef<FPlugin>& Plugin = Iter.Value();
if(Plugin->bEnabled)
{
EnabledPluginFileNames.Add(Plugin->FileName);
}
else
{
Iter.RemoveCurrent();
}
}
// Add all the plugins which aren't already enabled
for(const TPair<FString, TSharedRef<FPlugin>>& NewPluginPair: NewPlugins)
{
const TSharedRef<FPlugin>& NewPlugin = NewPluginPair.Value;
if(!EnabledPluginFileNames.Contains(NewPlugin->FileName))
{
AllPlugins.Add(NewPlugin->GetName(), NewPlugin);
}
}
}
void FPluginManager::DiscoverAllPlugins()
{
ensure( AllPlugins.Num() == 0 ); // Should not have already been initialized!
PluginSystemDefs::GetAdditionalPluginPaths(PluginDiscoveryPaths);
ReadAllPlugins(AllPlugins, PluginDiscoveryPaths);
}
void FPluginManager::ReadAllPlugins(TMap<FString, TSharedRef<FPlugin>>& Plugins, const TSet<FString>& ExtraSearchPaths)
{
#if (WITH_ENGINE && !IS_PROGRAM) || WITH_PLUGIN_SUPPORT
// Find "built-in" plugins. That is, plugins situated right within the Engine directory.
ReadPluginsInDirectory(FPaths::EnginePluginsDir(), EPluginLoadedFrom::Engine, Plugins);
// Find plugins in the game project directory (<MyGameProject>/Plugins). If there are any engine plugins matching the name of a game plugin,
// assume that the game plugin version is preferred.
if( FApp::HasGameName() )
{
ReadPluginsInDirectory(FPaths::GamePluginsDir(), EPluginLoadedFrom::GameProject, Plugins);
}
for (const FString& ExtraSearchPath : ExtraSearchPaths)
{
ReadPluginsInDirectory(ExtraSearchPath, EPluginLoadedFrom::GameProject, Plugins);
}
#endif
}
void FPluginManager::ReadPluginsInDirectory(const FString& PluginsDirectory, const EPluginLoadedFrom LoadedFrom, TMap<FString, TSharedRef<FPlugin>>& Plugins)
{
// Make sure the directory even exists
if(FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*PluginsDirectory))
{
TArray<FString> FileNames;
FindPluginsInDirectory(PluginsDirectory, FileNames);
for(const FString& FileName: FileNames)
{
FPluginDescriptor Descriptor;
FText FailureReason;
if ( Descriptor.Load(FileName, FailureReason) )
{
TSharedRef<FPlugin> Plugin = MakeShareable(new FPlugin(FileName, Descriptor, LoadedFrom));
FString FullPath = FPaths::ConvertRelativePathToFull(FileName);
UE_LOG(LogPluginManager, Log, TEXT("Loaded Plugin %s, From %s"), *Plugin->GetName(), *FullPath);
const TSharedRef<FPlugin>* ExistingPlugin = Plugins.Find(Plugin->GetName());
if (ExistingPlugin == nullptr)
{
Plugins.Add(Plugin->GetName(), Plugin);
}
else if ((*ExistingPlugin)->LoadedFrom == EPluginLoadedFrom::Engine && LoadedFrom == EPluginLoadedFrom::GameProject)
{
Plugins[Plugin->GetName()] = Plugin;
UE_LOG(LogPluginManager, Log, TEXT("Replacing engine version of '%s' plugin with game version"), *Plugin->GetName());
}
else if( (*ExistingPlugin)->LoadedFrom != EPluginLoadedFrom::GameProject || LoadedFrom != EPluginLoadedFrom::Engine)
{
UE_LOG(LogPluginManager, Warning, TEXT("Plugin '%s' exists at '%s' and '%s' - second location will be ignored"), *Plugin->GetName(), *(*ExistingPlugin)->FileName, *Plugin->FileName);
}
}
else
{
// NOTE: Even though loading of this plugin failed, we'll keep processing other plugins
FString FullPath = FPaths::ConvertRelativePathToFull(FileName);
FText FailureMessage = FText::Format(LOCTEXT("FailureFormat", "{0} ({1})"), FailureReason, FText::FromString(FullPath));
FText DialogTitle = LOCTEXT("PluginFailureTitle", "Failed to load Plugin");
UE_LOG(LogPluginManager, Error, TEXT("%s"), *FailureMessage.ToString());
FMessageDialog::Open(EAppMsgType::Ok, FailureMessage, &DialogTitle);
}
}
}
}
void FPluginManager::FindPluginsInDirectory(const FString& PluginsDirectory, TArray<FString>& FileNames)
{
// Class to enumerate the contents of a directory, and find all sub-directories and plugin descriptors within it
struct FPluginDirectoryVisitor : public IPlatformFile::FDirectoryVisitor
{
TArray<FString> SubDirectories;
TArray<FString> PluginDescriptors;
virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory) override
{
FString FilenameOrDirectoryStr = FilenameOrDirectory;
if(bIsDirectory)
{
SubDirectories.Add(FilenameOrDirectoryStr);
}
else if(FilenameOrDirectoryStr.EndsWith(TEXT(".uplugin")))
{
PluginDescriptors.Add(FilenameOrDirectoryStr);
}
return true;
}
};
// Enumerate the contents of the current directory
FPluginDirectoryVisitor Visitor;
FPlatformFileManager::Get().GetPlatformFile().IterateDirectory(*PluginsDirectory, Visitor);
// If there's no plugins in this directory, recurse through all the child directories
if(Visitor.PluginDescriptors.Num() == 0)
{
for(const FString& SubDirectory: Visitor.SubDirectories)
{
FindPluginsInDirectory(SubDirectory, FileNames);
}
}
else
{
for(const FString& PluginDescriptor: Visitor.PluginDescriptors)
{
FileNames.Add(PluginDescriptor);
}
}
}
// Helper class to find all pak files.
class FPakFileSearchVisitor : public IPlatformFile::FDirectoryVisitor
{
TArray<FString>& FoundFiles;
public:
FPakFileSearchVisitor(TArray<FString>& InFoundFiles)
: FoundFiles(InFoundFiles)
{}
virtual bool Visit(const TCHAR* FilenameOrDirectory, bool bIsDirectory)
{
if (bIsDirectory == false)
{
FString Filename(FilenameOrDirectory);
if (Filename.MatchesWildcard(TEXT("*.pak")))
{
FoundFiles.Add(Filename);
}
}
return true;
}
};
bool FPluginManager::IsPluginSupportedByCurrentTarget(TSharedRef<FPlugin> Plugin) const
{
bool bSupported = false;
if (Plugin->GetDescriptor().Modules.Num())
{
for (const FModuleDescriptor& Module : Plugin->GetDescriptor().Modules)
{
// Programs support only program type plugins
// Non-program targets don't support from plugins
#if IS_PROGRAM
if (Module.Type == EHostType::Program)
{
bSupported = true;
}
#else
if (Module.Type != EHostType::Program)
{
bSupported = true;
}
#endif
}
}
else
{
bSupported = true;
}
return bSupported;
}
bool FPluginManager::ConfigureEnabledPlugins()
{
if(!bHaveConfiguredEnabledPlugins)
{
// Don't need to run this again
bHaveConfiguredEnabledPlugins = true;
// If a current project is set, check that we know about any plugin that's explicitly enabled
const FProjectDescriptor *Project = IProjectManager::Get().GetCurrentProject();
const bool bHasProjectFile = Project != nullptr;
// Get all the enabled plugin names
TArray< FString > EnabledPluginNames;
#if IS_PROGRAM
// Programs can also define the list of enabled plugins in ini
GConfig->GetArray(TEXT("Plugins"), TEXT("ProgramEnabledPlugins"), EnabledPluginNames, GEngineIni);
#endif
#if !IS_PROGRAM || HACK_HEADER_GENERATOR
if (!FParse::Param(FCommandLine::Get(), TEXT("NoEnginePlugins")))
{
FProjectManager::Get().GetEnabledPlugins(EnabledPluginNames);
}
#endif
// Build a set from the array
TSet< FString > AllEnabledPlugins;
AllEnabledPlugins.Append(MoveTemp(EnabledPluginNames));
// Enable all the plugins by name
for (const TPair<FString, TSharedRef< FPlugin >> PluginPair : AllPlugins)
{
const TSharedRef<FPlugin>& Plugin = PluginPair.Value;
if (AllEnabledPlugins.Contains(Plugin->Name))
{
#if IS_PROGRAM
Plugin->bEnabled = !bHasProjectFile || IsPluginSupportedByCurrentTarget(Plugin);
if (!Plugin->bEnabled)
{
AllEnabledPlugins.Remove(Plugin->Name);
}
#else
Plugin->bEnabled = true;
#endif
}
}
if (bHasProjectFile)
{
// Take a copy of the Project's plugins as we may remove some
TArray<FPluginReferenceDescriptor> PluginsCopy = Project->Plugins;
for(const FPluginReferenceDescriptor& Plugin: PluginsCopy)
{
bool bShouldBeEnabled = Plugin.bEnabled && Plugin.IsEnabledForPlatform(FPlatformMisc::GetUBTPlatform()) && Plugin.IsEnabledForTarget(FPlatformMisc::GetUBTTarget());
if (bShouldBeEnabled && !FindPluginInstance(Plugin.Name).IsValid() && !Plugin.bOptional
#if IS_PROGRAM
&& AllEnabledPlugins.Contains(Plugin.Name) // skip if this is a program and the plugin is not enabled
#endif
)
{
FText Caption(LOCTEXT("PluginMissingCaption", "Plugin missing"));
if(Plugin.MarketplaceURL.Len() > 0)
{
if(FMessageDialog::Open(EAppMsgType::YesNo, FText::Format(LOCTEXT("PluginMissingError", "This project requires the {0} plugin.\n\nWould you like to download it from the the Marketplace?"), FText::FromString(Plugin.Name)), &Caption) == EAppReturnType::Yes)
{
FString Error;
FPlatformProcess::LaunchURL(*Plugin.MarketplaceURL, nullptr, &Error);
if(Error.Len() > 0) FMessageDialog::Open(EAppMsgType::Ok, FText::FromString(Error));
return false;
}
}
else
{
FString Description = (Plugin.Description.Len() > 0) ? FString::Printf(TEXT("\n\n%s"), *Plugin.Description) : FString();
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(LOCTEXT("PluginRequiredError", "This project requires the {0} plugin. {1}"), FText::FromString(Plugin.Name), FText::FromString(Description)), &Caption);
if (FMessageDialog::Open(EAppMsgType::YesNo, FText::Format(LOCTEXT("PluginMissingDisable", "Would you like to disable {0}? You will no longer be able to open any assets created using it."), FText::FromString(Plugin.Name)), &Caption) == EAppReturnType::No)
{
return false;
}
FText FailReason;
if (!IProjectManager::Get().SetPluginEnabled(*Plugin.Name, false, FailReason))
{
FMessageDialog::Open(EAppMsgType::Ok, FailReason);
}
}
}
}
}
// If we made it here, we have all the required plugins
bHaveAllRequiredPlugins = true;
for(const TPair<FString, TSharedRef<FPlugin>>& PluginPair: AllPlugins)
{
const TSharedRef<FPlugin>& Plugin = PluginPair.Value;
if (Plugin->bEnabled)
{
// Add the plugin binaries directory
const FString PluginBinariesPath = FPaths::Combine(*FPaths::GetPath(Plugin->FileName), TEXT("Binaries"), FPlatformProcess::GetBinariesSubdirectory());
FModuleManager::Get().AddBinariesDirectory(*PluginBinariesPath, Plugin->LoadedFrom == EPluginLoadedFrom::GameProject);
#if !IS_MONOLITHIC
// Only check this when in a non-monolithic build where modules could be in separate binaries
if (Project != NULL && Project->Modules.Num() == 0)
{
// Content only project - check whether any plugins are incompatible and offer to disable instead of trying to build them later
TArray<FString> IncompatibleFiles;
if (!FModuleDescriptor::CheckModuleCompatibility(Plugin->Descriptor.Modules, Plugin->LoadedFrom == EPluginLoadedFrom::GameProject, IncompatibleFiles))
{
// Ask whether to disable plugin if incompatible
FText Caption(LOCTEXT("IncompatiblePluginCaption", "Plugin missing or incompatible"));
if (FMessageDialog::Open(EAppMsgType::YesNo, FText::Format(LOCTEXT("IncompatiblePluginText", "Missing or incompatible modules in {0} plugin - would you like to disable it? You will no longer be able to open any assets created using it."), FText::FromString(Plugin->Name)), &Caption) == EAppReturnType::No)
{
return false;
}
FText FailReason;
if (!IProjectManager::Get().SetPluginEnabled(*Plugin->Name, false, FailReason))
{
FMessageDialog::Open(EAppMsgType::Ok, FailReason);
}
}
}
#endif //!IS_MONOLITHIC
// Build the list of content folders
if (Plugin->Descriptor.bCanContainContent)
{
if (FConfigFile* EngineConfigFile = GConfig->Find(GEngineIni, false))
{
if (FConfigSection* CoreSystemSection = EngineConfigFile->Find(TEXT("Core.System")))
{
CoreSystemSection->AddUnique("Paths", Plugin->GetContentDir());
}
}
}
// Load Default<PluginName>.ini config file if it exists
FString PluginConfigDir = FPaths::GetPath(Plugin->FileName) / TEXT("Config/");
FConfigFile PluginConfig;
FConfigCacheIni::LoadExternalIniFile(PluginConfig, *Plugin->Name, *FPaths::EngineConfigDir(), *PluginConfigDir, true);
if (PluginConfig.Num() > 0)
{
FString PlaformName = FPlatformProperties::PlatformName();
FString PluginConfigFilename = FString::Printf(TEXT("%s%s/%s.ini"), *FPaths::GeneratedConfigDir(), *PlaformName, *Plugin->Name);
FConfigFile& NewConfigFile = GConfig->Add(PluginConfigFilename, FConfigFile());
NewConfigFile.AddMissingProperties(PluginConfig);
NewConfigFile.Write(PluginConfigFilename);
}
}
}
// Mount all the plugin content folders and pak files
TArray<FString> FoundPaks;
FPakFileSearchVisitor PakVisitor(FoundPaks);
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
for(TSharedRef<IPlugin> Plugin: GetEnabledPlugins())
{
if (Plugin->CanContainContent() && ensure(RegisterMountPointDelegate.IsBound()))
{
FString ContentDir = Plugin->GetContentDir();
RegisterMountPointDelegate.Execute(Plugin->GetMountedAssetPath(), ContentDir);
// Pak files are loaded from <PluginName>/Content/Paks/<PlatformName>
if (FPlatformProperties::RequiresCookedData())
{
FoundPaks.Reset();
PlatformFile.IterateDirectoryRecursively(*(ContentDir / TEXT("Paks") / FPlatformProperties::PlatformName()), PakVisitor);
for (const FString& PakPath : FoundPaks)
{
if (FCoreDelegates::OnMountPak.IsBound())
{
FCoreDelegates::OnMountPak.Execute(PakPath, 0, nullptr);
}
}
}
}
}
}
return bHaveAllRequiredPlugins;
}
TSharedPtr<FPlugin> FPluginManager::FindPluginInstance(const FString& Name)
{
const TSharedRef<FPlugin>* Instance = AllPlugins.Find(Name);
if (Instance == nullptr)
{
return TSharedPtr<FPlugin>();
}
else
{
return TSharedPtr<FPlugin>(*Instance);
}
}
bool FPluginManager::LoadModulesForEnabledPlugins( const ELoadingPhase::Type LoadingPhase )
{
// Figure out which plugins are enabled
if(!ConfigureEnabledPlugins())
{
return false;
}
FScopedSlowTask SlowTask(AllPlugins.Num());
// Load plugins!
for( const TPair<FString, TSharedRef< FPlugin >> PluginPair : AllPlugins )
{
const TSharedRef<FPlugin> &Plugin = PluginPair.Value;
SlowTask.EnterProgressFrame(1);
if ( Plugin->bEnabled )
{
TMap<FName, EModuleLoadResult> ModuleLoadFailures;
FModuleDescriptor::LoadModulesForPhase(LoadingPhase, Plugin->Descriptor.Modules, ModuleLoadFailures);
FText FailureMessage;
for( auto FailureIt( ModuleLoadFailures.CreateConstIterator() ); FailureIt; ++FailureIt )
{
const FName ModuleNameThatFailedToLoad = FailureIt.Key();
const EModuleLoadResult FailureReason = FailureIt.Value();
if( FailureReason != EModuleLoadResult::Success )
{
const FText PluginNameText = FText::FromString(Plugin->Name);
const FText TextModuleName = FText::FromName(FailureIt.Key());
if ( FailureReason == EModuleLoadResult::FileNotFound )
{
FailureMessage = FText::Format( LOCTEXT("PluginModuleNotFound", "Plugin '{0}' failed to load because module '{1}' could not be found. Please ensure the plugin is properly installed, otherwise consider disabling the plugin for this project."), PluginNameText, TextModuleName );
}
else if ( FailureReason == EModuleLoadResult::FileIncompatible )
{
FailureMessage = FText::Format( LOCTEXT("PluginModuleIncompatible", "Plugin '{0}' failed to load because module '{1}' does not appear to be compatible with the current version of the engine. The plugin may need to be recompiled."), PluginNameText, TextModuleName );
}
else if ( FailureReason == EModuleLoadResult::CouldNotBeLoadedByOS )
{
FailureMessage = FText::Format( LOCTEXT("PluginModuleCouldntBeLoaded", "Plugin '{0}' failed to load because module '{1}' could not be loaded. There may be an operating system error or the module may not be properly set up."), PluginNameText, TextModuleName );
}
else if ( FailureReason == EModuleLoadResult::FailedToInitialize )
{
FailureMessage = FText::Format( LOCTEXT("PluginModuleFailedToInitialize", "Plugin '{0}' failed to load because module '{1}' could be initialized successfully after it was loaded."), PluginNameText, TextModuleName );
}
else
{
ensure(0); // If this goes off, the error handling code should be updated for the new enum values!
FailureMessage = FText::Format( LOCTEXT("PluginGenericLoadFailure", "Plugin '{0}' failed to load because module '{1}' could not be loaded for an unspecified reason. This plugin's functionality will not be available. Please report this error."), PluginNameText, TextModuleName );
}
// Don't need to display more than one module load error per plugin that failed to load
break;
}
}
if( !FailureMessage.IsEmpty() )
{
FMessageDialog::Open(EAppMsgType::Ok, FailureMessage);
return false;
}
}
}
return true;
}
void FPluginManager::GetLocalizationPathsForEnabledPlugins( TArray<FString>& OutLocResPaths )
{
// Figure out which plugins are enabled
if (!ConfigureEnabledPlugins())
{
return;
}
// Gather the paths from all plugins that have localization targets that are loaded based on the current runtime environment
for (const TPair<FString, TSharedRef<FPlugin>>& PluginPair : AllPlugins)
{
const TSharedRef<FPlugin>& Plugin = PluginPair.Value;
if (!Plugin->bEnabled || Plugin->GetDescriptor().LocalizationTargets.Num() == 0)
{
continue;
}
const FString PluginLocDir = Plugin->GetContentDir() / TEXT("Localization");
for (const FLocalizationTargetDescriptor& LocTargetDesc : Plugin->GetDescriptor().LocalizationTargets)
{
if (LocTargetDesc.ShouldLoadLocalizationTarget())
{
OutLocResPaths.Add(PluginLocDir / LocTargetDesc.Name);
}
}
}
}
void FPluginManager::SetRegisterMountPointDelegate( const FRegisterMountPointDelegate& Delegate )
{
RegisterMountPointDelegate = Delegate;
}
bool FPluginManager::AreRequiredPluginsAvailable()
{
return ConfigureEnabledPlugins();
}
bool FPluginManager::CheckModuleCompatibility(TArray<FString>& OutIncompatibleModules)
{
if(!ConfigureEnabledPlugins())
{
return false;
}
bool bResult = true;
for(const TPair<FString, TSharedRef<FPlugin>>& PluginPair : AllPlugins)
{
const TSharedRef< FPlugin > &Plugin = PluginPair.Value;
if (Plugin->bEnabled && !FModuleDescriptor::CheckModuleCompatibility(Plugin->Descriptor.Modules, Plugin->LoadedFrom == EPluginLoadedFrom::GameProject, OutIncompatibleModules))
{
bResult = false;
}
}
return bResult;
}
IPluginManager& IPluginManager::Get()
{
// Single instance of manager, allocated on demand and destroyed on program exit.
static FPluginManager* PluginManager = NULL;
if( PluginManager == NULL )
{
PluginManager = new FPluginManager();
}
return *PluginManager;
}
TSharedPtr<IPlugin> FPluginManager::FindPlugin(const FString& Name)
{
const TSharedRef<FPlugin>* Instance = AllPlugins.Find(Name);
if (Instance == nullptr)
{
return TSharedPtr<IPlugin>();
}
else
{
return TSharedPtr<IPlugin>(*Instance);
}
}
TArray<TSharedRef<IPlugin>> FPluginManager::GetEnabledPlugins()
{
TArray<TSharedRef<IPlugin>> Plugins;
for(TPair<FString, TSharedRef<FPlugin>>& PluginPair : AllPlugins)
{
TSharedRef<FPlugin>& PossiblePlugin = PluginPair.Value;
if(PossiblePlugin->bEnabled)
{
Plugins.Add(PossiblePlugin);
}
}
return Plugins;
}
TArray<TSharedRef<IPlugin>> FPluginManager::GetDiscoveredPlugins()
{
TArray<TSharedRef<IPlugin>> Plugins;
for (TPair<FString, TSharedRef<FPlugin>>& PluginPair : AllPlugins)
{
Plugins.Add(PluginPair.Value);
}
return Plugins;
}
TArray< FPluginStatus > FPluginManager::QueryStatusForAllPlugins() const
{
TArray< FPluginStatus > PluginStatuses;
for( const TPair<FString, TSharedRef<FPlugin>>& PluginPair : AllPlugins )
{
const TSharedRef< FPlugin >& Plugin = PluginPair.Value;
FPluginStatus PluginStatus;
PluginStatus.Name = Plugin->Name;
PluginStatus.PluginDirectory = FPaths::GetPath(Plugin->FileName);
PluginStatus.bIsEnabled = Plugin->bEnabled;
PluginStatus.Descriptor = Plugin->Descriptor;
PluginStatus.LoadedFrom = Plugin->LoadedFrom;
PluginStatuses.Add( PluginStatus );
}
return PluginStatuses;
}
void FPluginManager::AddPluginSearchPath(const FString& ExtraDiscoveryPath, bool bRefresh)
{
PluginDiscoveryPaths.Add(ExtraDiscoveryPath);
if (bRefresh)
{
RefreshPluginsList();
}
}
#undef LOCTEXT_NAMESPACE