Skip to content

Commit

Permalink
Fix Settins issue and close #276. Non-unity build fixed too, close #277
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Feb 26, 2020
1 parent 06ab9c0 commit 11adacd
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 61 deletions.
47 changes: 47 additions & 0 deletions Source/VaRest/Private/VaRest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,54 @@
#include "VaRest.h"

#include "VaRestDefines.h"
#include "VaRestSettings.h"

#include "Developer/Settings/Public/ISettingsModule.h"

#define LOCTEXT_NAMESPACE "FVaRestModule"

void FVaRestModule::StartupModule()
{
ModuleSettings = NewObject<UVaRestSettings>(GetTransientPackage(), "VaRestSettings", RF_Standalone);
ModuleSettings->AddToRoot();

// Register settings
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->RegisterSettings("Project", "Plugins", "VaRest",
LOCTEXT("RuntimeSettingsName", "VaRest"),
LOCTEXT("RuntimeSettingsDescription", "Configure VaRest plugin settings"),
ModuleSettings);
}

UE_LOG(LogVaRest, Log, TEXT("%s: VaRest module started"), *VA_FUNC_LINE);
}

void FVaRestModule::ShutdownModule()
{
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->UnregisterSettings("Project", "Plugins", "VaRest");
}

if (!GExitPurge)
{
ModuleSettings->RemoveFromRoot();
}
else
{
ModuleSettings = nullptr;
}
}

UVaRestSettings* FVaRestModule::GetSettings() const
{
check(ModuleSettings);
return ModuleSettings;
}

IMPLEMENT_MODULE(FVaRestModule, VaRest)

DEFINE_LOG_CATEGORY(LogVaRest);

#undef LOCTEXT_NAMESPACE
8 changes: 6 additions & 2 deletions Source/VaRest/Private/VaRestLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

#include "VaRestLibrary.h"

#include "VaRest.h"
#include "VaRestDefines.h"
#include "VaRestJsonObject.h"
#include "VaRestRequestJSON.h"
#include "VaRestSettings.h"

#include "Misc/Base64.h"

//////////////////////////////////////////////////////////////////////////
// Helpers
UVaRestSettings* UVaRestLibrary::GetVaRestSettings()
{
return FVaRestModule::Get().GetSettings();
}

FString UVaRestLibrary::PercentEncode(const FString& Source)
{
Expand Down
19 changes: 3 additions & 16 deletions Source/VaRest/Private/VaRestRequestJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "VaRestJsonObject.h"
#include "VaRestLibrary.h"
#include "VaRestSettings.h"
#include "VaRestSubsystem.h"

#include "Json.h"
#include "Kismet/GameplayStatics.h"
Expand Down Expand Up @@ -338,7 +337,7 @@ void UVaRestRequestJSON::ProcessRequest()
}

// Check extended log to avoid security vulnerability (#133)
if (GetSettings()->bExtendedLog)
if (UVaRestLibrary::GetVaRestSettings()->bExtendedLog)
{
UE_LOG(LogVaRest, Log, TEXT("%s: Request (urlencoded): %s %s %s %s"), *VA_FUNC_LINE, *HttpRequest->GetVerb(), *HttpRequest->GetURL(), *UrlParams, *StringRequestContent);
}
Expand Down Expand Up @@ -375,7 +374,7 @@ void UVaRestRequestJSON::ProcessRequest()
HttpRequest->SetContentAsString(UrlParams);

// Check extended log to avoid security vulnerability (#133)
if (GetSettings()->bExtendedLog)
if (UVaRestLibrary::GetVaRestSettings()->bExtendedLog)
{
UE_LOG(LogVaRest, Log, TEXT("%s: Request (url body): %s %s %s"), *VA_FUNC_LINE, *HttpRequest->GetVerb(), *HttpRequest->GetURL(), *UrlParams);
}
Expand Down Expand Up @@ -472,7 +471,7 @@ void UVaRestRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttp
}
}

if (GetSettings()->bUseChunkedParser)
if (UVaRestLibrary::GetVaRestSettings()->bUseChunkedParser)
{
// Try to deserialize data to JSON
const TArray<uint8>& Bytes = Response->GetContent();
Expand Down Expand Up @@ -583,15 +582,3 @@ FString UVaRestRequestJSON::GetResponseContentAsString(bool bCacheResponseConten
// Return previously cached content now
return ResponseContent;
}

const UVaRestSettings* UVaRestRequestJSON::GetSettings() const
{
auto GI = UGameplayStatics::GetGameInstance(this);
if (GI)
{
return GI->GetSubsystem<UVaRestSubsystem>()->GetSettings();
}

UE_LOG(LogVaRest, Warning, TEXT("%s: No World is provided for Outer object, Default settings will be used"), *VA_FUNC_LINE);
return GetDefault<UVaRestSettings>();
}
22 changes: 0 additions & 22 deletions Source/VaRest/Private/VaRestSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
#include "VaRestDefines.h"
#include "VaRestJsonObject.h"
#include "VaRestJsonValue.h"
#include "VaRestSettings.h"

#include "Developer/Settings/Public/ISettingsModule.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"

#define LOCTEXT_NAMESPACE "FVaRest"

UVaRestSubsystem::UVaRestSubsystem()
: UGameInstanceSubsystem()
{
Expand All @@ -22,17 +19,6 @@ void UVaRestSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);

Settings = NewObject<UVaRestSettings>(GetTransientPackage(), "VaRestSettings", RF_Standalone);

// Register settings
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
{
SettingsModule->RegisterSettings("Project", "Plugins", "VaRest",
LOCTEXT("RuntimeSettingsName", "VaRest"),
LOCTEXT("RuntimeSettingsDescription", "Configure VaRest plugin settings"),
Settings);
}

UE_LOG(LogVaRest, Log, TEXT("%s: VaRest subsystem initialized"), *VA_FUNC_LINE);
}

Expand Down Expand Up @@ -198,11 +184,3 @@ class UVaRestJsonObject* UVaRestSubsystem::LoadJsonFromFile(const FString& Path,

return nullptr;
}

UVaRestSettings* UVaRestSubsystem::GetSettings() const
{
check(Settings);
return Settings;
}

#undef LOCTEXT_NAMESPACE
13 changes: 13 additions & 0 deletions Source/VaRest/Public/VaRest.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@

#include "Modules/ModuleManager.h"

class UVaRestSettings;

class FVaRestModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;

/**
* Singleton-like access to this module's interface. This is just for convenience!
* Beware of calling this during the shutdown phase, though. Your module might have been unloaded already.
Expand All @@ -27,4 +33,11 @@ class FVaRestModule : public IModuleInterface
{
return FModuleManager::Get().IsModuleLoaded("VaRest");
}

/** Getter for internal settings object to support runtime configuration changes */
UVaRestSettings* GetSettings() const;

protected:
/** Module settings */
UVaRestSettings* ModuleSettings;
};
3 changes: 2 additions & 1 deletion Source/VaRest/Public/VaRestJsonObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class VAREST_API UVaRestJsonObject : public UObject
{
GENERATED_UCLASS_BODY()

public:
/** Reset all internal data */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void Reset();
Expand Down Expand Up @@ -161,10 +162,10 @@ class VAREST_API UVaRestJsonObject : public UObject
}
}

private:
//////////////////////////////////////////////////////////////////////////
// Array fields helpers (uniform arrays)

public:
/** Get the field named FieldName as a Number Array. Use it only if you're sure that array is uniform!
* Attn.!! float used instead of double to make the function blueprintable! */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
Expand Down
9 changes: 9 additions & 0 deletions Source/VaRest/Public/VaRestLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include "VaRestLibrary.generated.h"

class UVaRestSettings;

/**
* Useful tools for REST communications
*/
Expand All @@ -17,6 +19,13 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

//////////////////////////////////////////////////////////////////////////
// Data Accessors
public:
/** Direct access to the plugin settings */
UFUNCTION(BlueprintPure, Category = "VaRest|Common")
static UVaRestSettings* GetVaRestSettings();

//////////////////////////////////////////////////////////////////////////
// Helpers

Expand Down
3 changes: 0 additions & 3 deletions Source/VaRest/Public/VaRestRequestJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,4 @@ class VAREST_API UVaRestRequestJSON : public UObject
public:
/** Returns reference to internal request object */
TSharedRef<IHttpRequest> GetHttpRequest() const { return HttpRequest; };

/** Helper function to get runtime settings */
const UVaRestSettings* GetSettings() const;
};
18 changes: 1 addition & 17 deletions Source/VaRest/Public/VaRestSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#pragma once

#include "VaRestJsonValue.h"
#include "VaRestRequestJSON.h"

#include "Delegates/DelegateCombinations.h"
Expand All @@ -10,10 +11,6 @@

#include "VaRestSubsystem.generated.h"

class UVaRestRequestJSON;
class UVaRestSettings;
class UVaRestJsonValue;

DECLARE_DYNAMIC_DELEGATE_OneParam(FVaRestCallDelegate, UVaRestRequestJSON*, Request);

USTRUCT()
Expand Down Expand Up @@ -114,17 +111,4 @@ class VAREST_API UVaRestSubsystem : public UGameInstanceSubsystem
*/
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility")
class UVaRestJsonObject* LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir = true);

//////////////////////////////////////////////////////////////////////////
// Data getters and helpers

public:
/** Getter for internal settings object to support runtime configuration changes */
UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem")
UVaRestSettings* GetSettings() const;

private:
/** Plugin settings */
UPROPERTY()
UVaRestSettings* Settings;
};

0 comments on commit 11adacd

Please sign in to comment.