Skip to content

Commit

Permalink
Fixed code execution cannot proceed error message for packaged builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjon2040 committed Dec 20, 2017
1 parent e1d647f commit 83b4923
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 40 deletions.
5 changes: 3 additions & 2 deletions GameLiftClientSDK/Source/AWSCore/AWSCore.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public AWSCore(ReadOnlyTargetRules Target ): base(Target)
PrivateIncludePaths.AddRange(new string[] { "AWSCore/Private" });
PublicIncludePaths.AddRange(new string[] { "AWSCore/Public" });

PublicDependencyModuleNames.AddRange(new string[] { "Engine", "Core", "CoreUObject", "Engine", "InputCore"});
PublicDependencyModuleNames.AddRange(new string[] { "Engine", "Core", "CoreUObject", "InputCore", "Projects"});
PrivateDependencyModuleNames.AddRange(new string[] { });

string BaseDirectory = System.IO.Path.GetFullPath(System.IO.Path.Combine(ModuleDirectory, "..", ".."));
Expand All @@ -31,7 +31,8 @@ public AWSCore(ReadOnlyTargetRules Target ): base(Target)
string AWSCoreDLLFile = System.IO.Path.Combine(ThirdPartyPath, "aws-cpp-sdk-core.dll");
if (File.Exists(AWSCoreDLLFile))
{
RuntimeDependencies.Add(new RuntimeDependency(AWSCoreDLLFile));
PublicDelayLoadDLLs.Add("aws-cpp-sdk-core.dll");
RuntimeDependencies.Add(new RuntimeDependency(AWSCoreDLLFile));
}
else
{
Expand Down
67 changes: 64 additions & 3 deletions GameLiftClientSDK/Source/AWSCore/Private/AWSCoreModule.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,75 @@
#include "AWSCoreModulePrivatePCH.h"
#include "AWSCoreModule.h"
#include "GameLiftClientSDK/Public/GameLiftClientGlobals.h"
#include "IPluginManager.h"

void AWSCoreModuleImpl::StartupModule()
#define LOCTEXT_NAMESPACE "FAWSCoreModule"

void* FAWSCoreModule::AWSCoreLibraryHandle = nullptr;

void FAWSCoreModule::StartupModule()
{
#if PLATFORM_WINDOWS && PLATFORM_64BITS
LOG_NORMAL("Starting AWSCore Module...");

const FString BaseDir = IPluginManager::Get().FindPlugin("GameLiftClientSDK")->GetBaseDir();
LOG_NORMAL(FString::Printf(TEXT("Base directory is %s"), *BaseDir));

const FString ThirdPartyDir = FPaths::Combine(*BaseDir, TEXT("ThirdParty"), TEXT("GameLiftClientSDK"), TEXT("Win64"));
LOG_NORMAL(FString::Printf(TEXT("ThirdParty directory is %s"), *ThirdPartyDir));

static const FString CoreDLLName = "aws-cpp-sdk-core";
const bool bDependencyLoaded = LoadDependency(ThirdPartyDir, CoreDLLName, AWSCoreLibraryHandle);
if (bDependencyLoaded == false)
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("Name"), FText::FromString(CoreDLLName));
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(LOCTEXT("LoadDependencyError", "Failed to load {Name}. Plugin will not be functional"), Arguments));
FreeDependency(AWSCoreLibraryHandle);
return;
}

Aws::InitAPI(options);
LOG_NORMAL("Aws::InitAPI called.");
#endif
}

void AWSCoreModuleImpl::ShutdownModule()
void FAWSCoreModule::ShutdownModule()
{
Aws::ShutdownAPI(options);
LOG_NORMAL("Aws::ShutdownAPI called.");
FreeDependency(AWSCoreLibraryHandle);
LOG_NORMAL("Shutting down AWSCore Module...");
}

IMPLEMENT_MODULE(AWSCoreModuleImpl, AWSCore);
bool FAWSCoreModule::LoadDependency(const FString& Dir, const FString& Name, void*& Handle)
{
FString Lib = Name + TEXT(".") + FPlatformProcess::GetModuleExtension();
FString Path = Dir.IsEmpty() ? *Lib : FPaths::Combine(*Dir, *Lib);

Handle = FPlatformProcess::GetDllHandle(*Path);

if (Handle == nullptr)
{
LOG_ERROR(FString::Printf(TEXT("Dependency %s failed to load in directory %s"), *Lib, *Dir));
return false;
}

LOG_NORMAL(FString::Printf(TEXT("Dependency %s successfully loaded from directory %s"), *Lib, *Dir));
return true;
}

void FAWSCoreModule::FreeDependency(void*& Handle)
{
#if !PLATFORM_LINUX
if (Handle != nullptr)
{
FPlatformProcess::FreeDllHandle(Handle);
Handle = nullptr;
}
#endif
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FAWSCoreModule, AWSCore);
5 changes: 4 additions & 1 deletion GameLiftClientSDK/Source/AWSCore/Public/AWSCoreModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
#include "aws/core/client/ClientConfiguration.h"
#include "aws/core/utils/Outcome.h"

class AWSCoreModuleImpl : public IModuleInterface
class FAWSCoreModule : public IModuleInterface
{
public:
void StartupModule();
void ShutdownModule();

private:
Aws::SDKOptions options;
static void* AWSCoreLibraryHandle;
static bool LoadDependency(const FString& Dir, const FString& Name, void*& Handle);
static void FreeDependency(void*& Handle);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public CognitoIdentity(ReadOnlyTargetRules Target) : base(Target)
PrivateIncludePaths.AddRange(new string[] { "CognitoIdentity/Private" });
PublicIncludePaths.AddRange(new string[] { "CognitoIdentity/Public" });

PublicDependencyModuleNames.AddRange(new string[] { "Engine", "Core", "CoreUObject", "Engine", "InputCore" });
PublicDependencyModuleNames.AddRange(new string[] { "Engine", "Core", "CoreUObject", "InputCore", "Projects" });

string BaseDirectory = System.IO.Path.GetFullPath(System.IO.Path.Combine(ModuleDirectory, "..", ".."));
string ThirdPartyPath = System.IO.Path.Combine(BaseDirectory, "ThirdParty", "GameLiftClientSDK", Target.Platform.ToString());
Expand All @@ -31,7 +31,8 @@ public CognitoIdentity(ReadOnlyTargetRules Target) : base(Target)
string CognitoDLLFile = System.IO.Path.Combine(ThirdPartyPath, "aws-cpp-sdk-cognito-identity.dll");
if (File.Exists(CognitoDLLFile))
{
RuntimeDependencies.Add(new RuntimeDependency(CognitoDLLFile));
PublicDelayLoadDLLs.Add("aws-cpp-sdk-cognito-identity.dll");
RuntimeDependencies.Add(new RuntimeDependency(CognitoDLLFile));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,69 @@
#include "CognitoIdentityModulePrivatePCH.h"
#include "CognitoIdentityModule.h"
#include "GameLiftClientSDK/Public/GameLiftClientGlobals.h"
#include "IPluginManager.h"

void CognitoIdentityModuleImpl::StartupModule()
#define LOCTEXT_NAMESPACE "FCognitoIdentityModule"

void* FCognitoIdentityModule::CognitoIdentityLibraryHandle = nullptr;

void FCognitoIdentityModule::StartupModule()
{
#if PLATFORM_WINDOWS && PLATFORM_64BITS
LOG_NORMAL("Starting CognitoIdentity Module...");

const FString BaseDir = IPluginManager::Get().FindPlugin("GameLiftClientSDK")->GetBaseDir();
LOG_NORMAL(FString::Printf(TEXT("Base directory is %s"), *BaseDir));

const FString ThirdPartyDir = FPaths::Combine(*BaseDir, TEXT("ThirdParty"), TEXT("GameLiftClientSDK"), TEXT("Win64"));
LOG_NORMAL(FString::Printf(TEXT("ThirdParty directory is %s"), *ThirdPartyDir));

static const FString CognitoIdentityDLLName = "aws-cpp-sdk-cognito-identity";
const bool bDependencyLoaded = LoadDependency(ThirdPartyDir, CognitoIdentityDLLName, CognitoIdentityLibraryHandle);
if (bDependencyLoaded == false)
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("Name"), FText::FromString(CognitoIdentityDLLName));
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(LOCTEXT("LoadDependencyError", "Failed to load {Name}. Plugin will not be functional"), Arguments));
FreeDependency(CognitoIdentityLibraryHandle);
}
#endif
}

void CognitoIdentityModuleImpl::ShutdownModule()
void FCognitoIdentityModule::ShutdownModule()
{
FreeDependency(CognitoIdentityLibraryHandle);
LOG_NORMAL("Shutting down CognitoIdentity Module...");
}

IMPLEMENT_MODULE(CognitoIdentityModuleImpl, CognitoIdentity);
bool FCognitoIdentityModule::LoadDependency(const FString& Dir, const FString& Name, void*& Handle)
{
FString Lib = Name + TEXT(".") + FPlatformProcess::GetModuleExtension();
FString Path = Dir.IsEmpty() ? *Lib : FPaths::Combine(*Dir, *Lib);

Handle = FPlatformProcess::GetDllHandle(*Path);

if (Handle == nullptr)
{
LOG_ERROR(FString::Printf(TEXT("Dependency %s failed to load in directory %s"), *Lib, *Dir));
return false;
}

LOG_NORMAL(FString::Printf(TEXT("Dependency %s successfully loaded from directory %s"), *Lib, *Dir));
return true;
}

void FCognitoIdentityModule::FreeDependency(void*& Handle)
{
#if !PLATFORM_LINUX
if (Handle != nullptr)
{
FPlatformProcess::FreeDllHandle(Handle);
Handle = nullptr;
}
#endif
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FCognitoIdentityModule, CognitoIdentity);
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

#include "ModuleManager.h"

class CognitoIdentityModuleImpl : public IModuleInterface
class FCognitoIdentityModule : public IModuleInterface
{
public:
void StartupModule();
void ShutdownModule();

private:
static void* CognitoIdentityLibraryHandle;
static bool LoadDependency(const FString& Dir, const FString& Name, void*& Handle);
static void FreeDependency(void*& Handle);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public GameLiftClientSDK(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicDependencyModuleNames.AddRange(new string[] { "Engine", "Core", "CoreUObject", "Engine", "InputCore", "Projects", "AWSCore" });
PublicDependencyModuleNames.AddRange(new string[] { "Engine", "Core", "CoreUObject", "InputCore", "Projects", "AWSCore" });

PublicIncludePaths.AddRange(new string[] {"GameLiftClientSDK/Public"});
PrivateIncludePaths.AddRange(new string[] {"GameLiftClientSDK/Private"});
Expand All @@ -36,7 +36,8 @@ public GameLiftClientSDK(ReadOnlyTargetRules Target) : base(Target)
string GameLiftDLLFile = System.IO.Path.Combine(ThirdPartyPath, "aws-cpp-sdk-gamelift.dll");
if(File.Exists(GameLiftDLLFile))
{
RuntimeDependencies.Add(new RuntimeDependency(GameLiftDLLFile));
PublicDelayLoadDLLs.Add("aws-cpp-sdk-gamelift.dll");
RuntimeDependencies.Add(new RuntimeDependency(GameLiftDLLFile));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

#define LOCTEXT_NAMESPACE "FGameLiftClientSDKModule"

void* FGameLiftClientSDKModule::AWSCoreLibraryHandle = nullptr;
void* FGameLiftClientSDKModule::GameLiftClientSDKLibraryHandle = nullptr;
void* FGameLiftClientSDKModule::CognitoIdentiryLibraryHandle = nullptr;

void FGameLiftClientSDKModule::StartupModule()
{
Expand All @@ -25,33 +23,24 @@ void FGameLiftClientSDKModule::StartupModule()
const FString ThirdPartyDir = FPaths::Combine(*BaseDir, TEXT("ThirdParty"), TEXT("GameLiftClientSDK"), TEXT("Win64"));
LOG_NORMAL(FString::Printf(TEXT("ThirdParty directory is %s"), *ThirdPartyDir));

TryLoadDependency(ThirdPartyDir, TEXT("aws-cpp-sdk-core"), AWSCoreLibraryHandle);
TryLoadDependency(ThirdPartyDir, TEXT("aws-cpp-sdk-gamelift"), GameLiftClientSDKLibraryHandle);
TryLoadDependency(ThirdPartyDir, TEXT("aws-cpp-sdk-cognito-identity"), CognitoIdentiryLibraryHandle);
static const FString GameLiftDLLName = "aws-cpp-sdk-gamelift";
const bool bDependencyLoaded = LoadDependency(ThirdPartyDir, GameLiftDLLName, GameLiftClientSDKLibraryHandle);
if (!bDependencyLoaded)
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("Name"), FText::FromString(GameLiftDLLName));
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(LOCTEXT("LoadDependencyError", "Failed to load {Name}."), Arguments));
FreeDependency(GameLiftClientSDKLibraryHandle);
}
#endif
}

void FGameLiftClientSDKModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.

FreeDependency(AWSCoreLibraryHandle);
FreeDependency(GameLiftClientSDKLibraryHandle);
FreeDependency(CognitoIdentiryLibraryHandle);
}

bool FGameLiftClientSDKModule::TryLoadDependency(FString ThirdPartyDir, FString Name, void* Handle)
{
const bool bDependencyLoaded = LoadDependency(ThirdPartyDir, Name, Handle);
if (!bDependencyLoaded)
{
FFormatNamedArguments Arguments;
Arguments.Add(TEXT("Name"), FText::FromString(Name));
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(LOCTEXT("LoadDependencyError", "Failed to load {Name}."), Arguments));
FreeDependency(Handle);
}
return bDependencyLoaded;
// we call this function before unloading the module.
FreeDependency(GameLiftClientSDKLibraryHandle);
LOG_NORMAL("Shutting down GameLift Module...");
}

bool FGameLiftClientSDKModule::LoadDependency(const FString& Dir, const FString& Name, void*& Handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class FGameLiftClientSDKModule : public IModuleInterface
private:

static void* GameLiftClientSDKLibraryHandle;
static void* AWSCoreLibraryHandle;
static void* CognitoIdentiryLibraryHandle;
static bool TryLoadDependency(FString ThirdPartyDir, FString Name, void* Handle);
static bool LoadDependency(const FString& Dir, const FString& Name, void*& Handle);
static void FreeDependency(void*& Handle);
};

0 comments on commit 83b4923

Please sign in to comment.