This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
353 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. | ||
|
||
#include "VaRest.h" | ||
|
||
#include "VaRestDefines.h" | ||
#include "VaRestJsonObject.h" | ||
#include "VaRestJsonValue.h" | ||
#include "VaRestRequestController.h" | ||
#include "VaRestRequestJSON.h" | ||
#include "VaRestSettings.h" | ||
|
||
#include "Developer/Settings/Public/ISettingsModule.h" | ||
|
||
#define LOCTEXT_NAMESPACE "FVaRestModule" | ||
|
||
void FVaRestModule::StartupModule() | ||
{ | ||
// @HACK Force classes to be compiled on shipping build | ||
UVaRestJsonObject::StaticClass(); | ||
UVaRestJsonValue::StaticClass(); | ||
UVaRestRequestJSON::StaticClass(); | ||
|
||
VaRestSettings = NewObject<UVaRestSettings>(GetTransientPackage(), "VaRestSettings", RF_Standalone); | ||
VaRestSettings->AddToRoot(); | ||
|
||
// Register settings | ||
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings")) | ||
{ | ||
SettingsModule->RegisterSettings("Project", "Plugins", "VaRest", | ||
LOCTEXT("RuntimeSettingsName", "VaRest"), | ||
LOCTEXT("RuntimeSettingsDescription", "Configure VaRest plugin settings"), | ||
VaRestSettings); | ||
} | ||
|
||
FWorldDelegates::OnWorldCleanup.AddLambda([this](UWorld* World, bool bSessionEnded, bool bCleanupResources) { | ||
RequestControllers.Remove(World); | ||
|
||
UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is removed for: %s"), *VA_FUNC_LINE, *World->GetName()); | ||
}); | ||
|
||
FWorldDelegates::OnPostWorldInitialization.AddLambda([this](UWorld* World, const UWorld::InitializationValues IVS) { | ||
auto Controller = NewObject<UVaRestRequestController>(GetTransientPackage()); | ||
Controller->SetFlags(RF_Standalone); | ||
Controller->AddToRoot(); | ||
|
||
Controller->Initialize(); | ||
|
||
RequestControllers.Add(World, Controller); | ||
|
||
UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is created for: %s"), *VA_FUNC_LINE, *World->GetName()); | ||
}); | ||
|
||
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) | ||
{ | ||
VaRestSettings->RemoveFromRoot(); | ||
|
||
// If we're in exit purge, this object has already been destroyed | ||
for (auto Controller : RequestControllers) | ||
{ | ||
Controller.Value->RemoveFromRoot(); | ||
} | ||
} | ||
else | ||
{ | ||
VaRestSettings = nullptr; | ||
} | ||
|
||
RequestControllers.Empty(); | ||
} | ||
|
||
UVaRestSettings* FVaRestModule::GetSettings() const | ||
{ | ||
check(VaRestSettings); | ||
return VaRestSettings; | ||
} | ||
|
||
UVaRestRequestController* FVaRestModule::GetRequestController(UWorld* World) const | ||
{ | ||
return RequestControllers.FindChecked(World); | ||
} | ||
|
||
IMPLEMENT_MODULE(FVaRestModule, VaRest) | ||
|
||
DEFINE_LOG_CATEGORY(LogVaRest); | ||
|
||
#undef LOCTEXT_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...VaRestPlugin/Private/VaRestJsonObject.cpp → Source/VaRest/Private/VaRestJsonObject.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
9 changes: 5 additions & 4 deletions
9
.../VaRestPlugin/Private/VaRestJsonValue.cpp → Source/VaRest/Private/VaRestJsonValue.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. | ||
|
||
#include "VaRestLibrary.h" | ||
|
||
#include "VaRestDefines.h" | ||
#include "VaRestJsonObject.h" | ||
#include "VaRestRequestJSON.h" | ||
|
||
#include "Misc/Base64.h" | ||
#include "Misc/FileHelper.h" | ||
#include "Misc/Paths.h" | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
// Helpers | ||
|
||
FString UVaRestLibrary::PercentEncode(const FString& Source) | ||
{ | ||
return FGenericPlatformHttp::UrlEncode(Source); | ||
} | ||
|
||
FString UVaRestLibrary::Base64Encode(const FString& Source) | ||
{ | ||
return FBase64::Encode(Source); | ||
} | ||
|
||
bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest) | ||
{ | ||
return FBase64::Decode(Source, Dest); | ||
} | ||
|
||
bool UVaRestLibrary::Base64EncodeData(const TArray<uint8>& Data, FString& Dest) | ||
{ | ||
if (Data.Num() > 0) | ||
{ | ||
Dest = FBase64::Encode(Data); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray<uint8>& Dest) | ||
{ | ||
return FBase64::Decode(Source, Dest); | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
// File system integration | ||
|
||
class UVaRestJsonObject* UVaRestLibrary::LoadJsonFromFile(UObject* WorldContextObject, const FString& Path, const bool bIsRelativeToContentDir) | ||
{ | ||
UVaRestJsonObject* Json = UVaRestJsonObject::ConstructJsonObject(WorldContextObject); | ||
|
||
FString JSONString; | ||
if (FFileHelper::LoadFileToString(JSONString, *(bIsRelativeToContentDir ? FPaths::ProjectContentDir() / Path : Path))) | ||
{ | ||
if (Json->DecodeJson(JSONString)) | ||
{ | ||
return Json; | ||
} | ||
else | ||
{ | ||
UE_LOG(LogVaRest, Error, TEXT("%s: Can't decode json from file %s"), *VA_FUNC_LINE, *Path); | ||
} | ||
} | ||
else | ||
{ | ||
UE_LOG(LogVaRest, Error, TEXT("%s: Can't open file %s"), *VA_FUNC_LINE, *Path); | ||
} | ||
|
||
return nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. | ||
|
||
#include "VaRestRequestController.h" | ||
|
||
#include "VaRestDefines.h" | ||
|
||
UVaRestRequestController::UVaRestRequestController(const FObjectInitializer& ObjectInitializer) | ||
: Super(ObjectInitializer) | ||
{ | ||
} | ||
|
||
void UVaRestRequestController::Initialize() | ||
{ | ||
} |
5 changes: 3 additions & 2 deletions
5
...aRestPlugin/Private/VaRestRequestJSON.cpp → Source/VaRest/Private/VaRestRequestJSON.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...e/VaRestPlugin/Private/VaRestSettings.cpp → Source/VaRest/Private/VaRestSettings.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "Modules/ModuleManager.h" | ||
|
||
class UVaRestRequestController; | ||
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. | ||
* | ||
* @return Returns singleton instance, loading the module on demand if needed | ||
*/ | ||
static inline FVaRestModule& Get() | ||
{ | ||
return FModuleManager::LoadModuleChecked<FVaRestModule>("VaRest"); | ||
} | ||
|
||
/** | ||
* Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true. | ||
* | ||
* @return True if the module is loaded and ready to use | ||
*/ | ||
static inline bool IsAvailable() | ||
{ | ||
return FModuleManager::Get().IsModuleLoaded("VaRest"); | ||
} | ||
|
||
/** Getter for internal settings object to support runtime configuration changes */ | ||
UVaRestSettings* GetSettings() const; | ||
|
||
/** Get global request controller */ | ||
UVaRestRequestController* GetRequestController(UWorld* World) const; | ||
|
||
protected: | ||
/** Module settings */ | ||
UVaRestSettings* VaRestSettings; | ||
|
||
/** Request controllers (one for each World we have) */ | ||
TMap<UWorld*, UVaRestRequestController*> RequestControllers; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.