Skip to content

Commit

Permalink
Finish v1.1-r28
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Feb 2, 2020
2 parents 2c7c7ef + 0696a08 commit cbbe78f
Show file tree
Hide file tree
Showing 19 changed files with 323 additions and 280 deletions.
2 changes: 2 additions & 0 deletions Config/FilterPlugin.ini
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
[FilterPlugin]
/Config/BaseVaRest.ini
/Config/DefaultVaRest.ini
7 changes: 4 additions & 3 deletions Source/.clang-format
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
---
Language: Cpp
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Always
UseTab: ForContinuationAndIndentation
Standard: Cpp11
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
Expand All @@ -17,5 +17,6 @@ ColumnLimit: 0
PointerAlignment: Left
SpacesInAngles: false
---
Language: ObjC
Language: ObjC
DisableFormat: true
...
87 changes: 0 additions & 87 deletions Source/VaRest/Private/VaRest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,7 @@
#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
9 changes: 0 additions & 9 deletions Source/VaRest/Private/VaRestJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ UVaRestJsonObject::UVaRestJsonObject(const FObjectInitializer& ObjectInitializer
{
}

UVaRestJsonObject* UVaRestJsonObject::ConstructVaRestJsonObject(UObject* WorldContextObject)
{
return NewObject<UVaRestJsonObject>();
}

void UVaRestJsonObject::Reset()
{
JsonObj = MakeShared<FJsonObject>();
Expand Down Expand Up @@ -675,11 +670,7 @@ bool UVaRestJsonObject::WriteToFile(const FString& Path)
for (int i = 0; i < JsonObjectValuePair.Key.Len(); ++i)
{
Str = FString(1, &BufferPtr[i]);
#if PLATFORM_WINDOWS
WriteStringToArchive(Ar, *Str, Str.Len() - 1);
#else
WriteStringToArchive(Ar, *Str, Str.Len());
#endif
}

Str = FString(TEXT("\""));
Expand Down
18 changes: 5 additions & 13 deletions Source/VaRest/Private/VaRestJsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ uint32 FUtf8Helper::CodepointFromUtf8(const ANSICHAR*& SourceString, const uint3
return UNICODE_BOGUS_CHAR_CODEPOINT;
}

++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue.
return UNICODE_BOGUS_CHAR_CODEPOINT; // catch everything else.
}

Expand Down Expand Up @@ -739,9 +739,9 @@ void FJSONReader::UpdateNotation()
{
if (State.CheckTokens(EJSONToken::SQUARE_BEGIN, EJSONToken::SQUARE_END)) // Close array "[]"
{
State.PopToken(2); // remove token "[]"
State.PopToken(2); // remove token "[]"
State.PopValue(false); // remove value if exists
State.PopArray(); // remove array
State.PopArray(); // remove array

if (State.CheckTokens(EJSONToken::COLON)) // Array in object ":"
{
Expand All @@ -761,7 +761,7 @@ void FJSONReader::UpdateNotation()
{
if (State.CheckTokens(EJSONToken::CURLY_BEGIN, EJSONToken::COLON, EJSONToken::COMMA)) // Next record in object "{:,"
{
State.PopToken(2); // remove token ":,"
State.PopToken(2); // remove token ":,"
State.PopValue(false); // remove value
State.Notation = EJSONNotation::OBJECT;
}
Expand All @@ -772,7 +772,7 @@ void FJSONReader::UpdateNotation()
}
else if (State.CheckTokens(EJSONToken::SQUARE_BEGIN, EJSONToken::COMMA)) // Next record in array "[,"
{
State.PopToken(1); // remove token ","
State.PopToken(1); // remove token ","
State.PopValue(false); // remove value
State.Notation = EJSONNotation::ARRAY;
}
Expand Down Expand Up @@ -1071,11 +1071,7 @@ void FJSONWriter::Write(TSharedPtr<FJsonValue> JsonValue, FArchive* Writer, bool
for (int i = 0; i < ChildJsonPair.Key.Len(); ++i)
{
Str = FString(1, &ChildJsonPair.Key[i]);
#if PLATFORM_WINDOWS
UVaRestJsonObject::WriteStringToArchive(Ar, *Str, Str.Len() - 1);
#else
UVaRestJsonObject::WriteStringToArchive(Ar, *Str, Str.Len());
#endif
}

Str = FString(TEXT("\""));
Expand Down Expand Up @@ -1134,11 +1130,7 @@ void FJSONWriter::Write(TSharedPtr<FJsonValue> JsonValue, FArchive* Writer, bool
}
else
{
#if PLATFORM_WINDOWS
UVaRestJsonObject::WriteStringToArchive(Ar, *Str, Str.Len() - 1);
#else
UVaRestJsonObject::WriteStringToArchive(Ar, *Str, Str.Len());
#endif
}
}

Expand Down
29 changes: 0 additions & 29 deletions Source/VaRest/Private/VaRestLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include "VaRestRequestJSON.h"

#include "Misc/Base64.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"

//////////////////////////////////////////////////////////////////////////
// Helpers
Expand Down Expand Up @@ -43,30 +41,3 @@ 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::ConstructVaRestJsonObject(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;
}
14 changes: 0 additions & 14 deletions Source/VaRest/Private/VaRestRequestController.cpp

This file was deleted.

Loading

0 comments on commit cbbe78f

Please sign in to comment.