From e5c03e3c5e53050b4a1eb8b0ce3f7ffb67a3afed Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 12 Feb 2020 06:50:53 +0300 Subject: [PATCH 01/71] Fix the crash on MakeJson --- Source/VaRestEditor/Private/VaRest_BreakJson.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index b61f76af..1ac31e0c 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -336,9 +336,12 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor { return; } + { + UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestSubsystem'"))); + FName FunctionName = TEXT("ConstructVaRestJsonObject"); - UFunction* FunctionPtr = Class->FindFunctionByName(FunctionName); + UFunction* FunctionPtr = SubsystemClass->FindFunctionByName(FunctionName); FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); Statement.Type = KCST_CallFunction; Statement.FunctionToCall = FunctionPtr; From 737fb874913cdade076579cdd2a7ea5b1ce40689 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Thu, 13 Feb 2020 05:08:31 -0500 Subject: [PATCH 02/71] Add StringToMd5 and StringToSha1 --- Source/VaRest/Private/VaRestLibrary.cpp | 21 +++++++++++++++++++++ Source/VaRest/Public/VaRestLibrary.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index d241c00f..e342e447 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -41,3 +41,24 @@ bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray& Dest { return FBase64::Decode(Source, Dest); } + +FString UVaRestLibrary::StringToMd5(const FString& StringToHash) +{ + return FMD5::HashAnsiString(*StringToHash); +} + +FString UVaRestLibrary::StringToSha1(const FString& StringToHash) +{ + FSHA1 Sha1Gen; + + Sha1Gen.Update((unsigned char*)TCHAR_TO_ANSI(*StringToHash), FCString::Strlen(*StringToHash)); + Sha1Gen.Final(); + + FString Sha1String; + for (int32 i = 0; i < 20; i++) + { + Sha1String += FString::Printf(TEXT("%02x"), Sha1Gen.m_digest[i]); + } + + return Sha1String; +} diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 0ef6323f..40da5bc5 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -62,4 +62,10 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Decode Data")) static bool Base64DecodeData(const FString& Source, TArray& Dest); + + UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to MD5")) + static FString StringToMd5(const FString& StringToHash); + + UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to SHA1")) + static FString StringToSha1(const FString& StringToHash); }; From 221f74dd72c7a452a7b696b6d1862300f2b881c2 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 13 Feb 2020 13:58:36 +0300 Subject: [PATCH 03/71] Minor #268 additions --- Source/VaRest/Public/VaRestLibrary.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 40da5bc5..811538e8 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -63,9 +63,17 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Decode Data")) static bool Base64DecodeData(const FString& Source, TArray& Dest); + /** + * Helper to perform the very common case of hashing an ASCII string into a hex representation. + * + * @param String Hex representation of the hash (32 lower-case hex digits) + **/ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to MD5")) static FString StringToMd5(const FString& StringToHash); + /** + * Helper to perform the SHA1 hash operation on string. + **/ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to SHA1")) static FString StringToSha1(const FString& StringToHash); }; From 706b1ec3a7e1f22a2d30149183e39593c3962dbf Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 13 Feb 2020 13:58:56 +0300 Subject: [PATCH 04/71] Fix latest commit #268 --- Source/VaRest/Public/VaRestLibrary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 811538e8..ab85b19c 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -67,13 +67,13 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary * Helper to perform the very common case of hashing an ASCII string into a hex representation. * * @param String Hex representation of the hash (32 lower-case hex digits) - **/ + */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to MD5")) static FString StringToMd5(const FString& StringToHash); /** * Helper to perform the SHA1 hash operation on string. - **/ + */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to SHA1")) static FString StringToSha1(const FString& StringToHash); }; From 35d9ebec266be2fa020a594979b1a86e490f34a5 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 13 Feb 2020 15:39:16 +0300 Subject: [PATCH 05/71] Shame. Shame on me. Fix memory corruption and add UPROPERTY. --- Source/VaRest/Public/VaRestSubsystem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 89fdd36a..15089252 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -100,5 +100,6 @@ class VAREST_API UVaRestSubsystem : public UGameInstanceSubsystem private: /** Plugin settings */ + UPROPERTY() UVaRestSettings* Settings; }; From abd16db578c2efb62b4439e05742f4878f25e3e9 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Fri, 14 Feb 2020 01:22:59 -0500 Subject: [PATCH 06/71] Fix Base64Encode and Base64Decode methods to support --- Source/VaRest/Private/VaRestLibrary.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index e342e447..0a341fe0 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -18,12 +18,22 @@ FString UVaRestLibrary::PercentEncode(const FString& Source) FString UVaRestLibrary::Base64Encode(const FString& Source) { - return FBase64::Encode(Source); + TArray ByteArray; + FTCHARToUTF8 StringSrc = FTCHARToUTF8(Source.GetCharArray().GetData()); + ByteArray.Append((uint8*)StringSrc.Get(), StringSrc.Length()); + + return FBase64::Encode(ByteArray); } bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest) { - return FBase64::Decode(Source, Dest); + TArray ByteArray; + bool Success = FBase64::Decode(Source, ByteArray); + + FUTF8ToTCHAR StringSrc = FUTF8ToTCHAR((const ANSICHAR*)ByteArray.GetData(), ByteArray.Num()); + Dest.AppendChars(StringSrc.Get(), StringSrc.Length() + 1); + + return Success; } bool UVaRestLibrary::Base64EncodeData(const TArray& Data, FString& Dest) From 6a4a2dd2b114687a4b4fd1f0d4168c097fb13553 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Mon, 17 Feb 2020 01:31:09 -0500 Subject: [PATCH 07/71] Add map support --- Source/VaRest/Private/VaRestJsonObject.cpp | 8 ++++++++ Source/VaRest/Public/VaRestJsonObject.h | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 93081d8d..be794d4f 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -366,6 +366,14 @@ void UVaRestJsonObject::SetObjectField(const FString& FieldName, UVaRestJsonObje JsonObj->SetObjectField(FieldName, JsonObject->GetRootObject()); } +void UVaRestJsonObject::SetMapFields(const TMap& Fields) +{ + for (auto& field : Fields) + { + SetStringField(field.Key, field.Value); + } +} + ////////////////////////////////////////////////////////////////////////// // Array fields helpers (uniform arrays) diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 89f5d2a5..14fae480 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -121,6 +121,10 @@ class VAREST_API UVaRestJsonObject : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Json") void SetObjectField(const FString& FieldName, UVaRestJsonObject* JsonObject); + /** Get a map of fields with values. */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void SetMapFields(const TMap& Fields); + ////////////////////////////////////////////////////////////////////////// // Array fields helpers (uniform arrays) From 42a477e38389fcd8fab06cc3135840b6cd717e58 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 17 Feb 2020 10:01:44 +0300 Subject: [PATCH 08/71] Update VaRestJsonObject.h --- Source/VaRest/Public/VaRestJsonObject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 14fae480..1cdc6f3e 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -121,7 +121,7 @@ class VAREST_API UVaRestJsonObject : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Json") void SetObjectField(const FString& FieldName, UVaRestJsonObject* JsonObject); - /** Get a map of fields with values. */ + /** Set a map of fields with String values */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") void SetMapFields(const TMap& Fields); From 1f4eba23fde49934f99581cfbde504e39f359e06 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Mon, 17 Feb 2020 03:53:31 -0500 Subject: [PATCH 09/71] Add in a templated method for setting different types of fields --- Source/VaRest/Private/VaRestJsonObject.cpp | 22 +++++++++++- Source/VaRest/Public/VaRestJsonObject.h | 39 +++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index be794d4f..4d5d914d 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -366,7 +366,7 @@ void UVaRestJsonObject::SetObjectField(const FString& FieldName, UVaRestJsonObje JsonObj->SetObjectField(FieldName, JsonObject->GetRootObject()); } -void UVaRestJsonObject::SetMapFields(const TMap& Fields) +void UVaRestJsonObject::SetMapFields_string(const TMap& Fields) { for (auto& field : Fields) { @@ -374,6 +374,26 @@ void UVaRestJsonObject::SetMapFields(const TMap& Fields) } } +void UVaRestJsonObject::SetMapFields_uint8(const TMap& Fields) +{ + SetMapFields_Impl(Fields); +} + +void UVaRestJsonObject::SetMapFields_int32(const TMap& Fields) +{ + SetMapFields_Impl(Fields); +} + +void UVaRestJsonObject::SetMapFields_int64(const TMap& Fields) +{ + SetMapFields_Impl(Fields); +} + +void UVaRestJsonObject::SetMapFields_bool(const TMap& Fields) +{ + SetMapFields_Impl(Fields); +} + ////////////////////////////////////////////////////////////////////////// // Array fields helpers (uniform arrays) diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 1cdc6f3e..8447b497 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -3,6 +3,7 @@ #pragma once #include "Dom/JsonObject.h" +#include "Templates/UnrealTypeTraits.h" #include "VaRestJsonObject.generated.h" @@ -123,8 +124,44 @@ class VAREST_API UVaRestJsonObject : public UObject /** Set a map of fields with String values */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") - void SetMapFields(const TMap& Fields); + void SetMapFields_string(const TMap& Fields); + /** Set a map of fields with uint8 values */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void SetMapFields_uint8(const TMap& Fields); + + /** Set a map of fields with int32 values */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void SetMapFields_int32(const TMap& Fields); + + /** Set a map of fields with int64 values */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void SetMapFields_int64(const TMap& Fields); + + /** Set a map of fields with bool values */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void SetMapFields_bool(const TMap& Fields); + +private: + /** Internal implementation for setting map fields. */ + template + void SetMapFields_Impl(const TMap& Fields) + { + for (auto& field : Fields) + { + // No need to support all int types as they're not supported by BP + if (TIsSame::Value || TIsSame::Value || TIsSame::Value || TIsSame::Value) + { + SetNumberField(field.Key, field.Value); + } + else if (TIsSame::Value) + { + SetBoolField(field.Key, (bool)field.Value); + } + } + } + +private: ////////////////////////////////////////////////////////////////////////// // Array fields helpers (uniform arrays) From 2e282ac228b333c794774924d877435a98e40e72 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Mon, 17 Feb 2020 05:29:13 -0500 Subject: [PATCH 10/71] Move construction methods from VaRestJsonValue to VaRestSubsystem and update CoreRedirects. --- Config/BaseVaRest.ini | 6 ++ Config/DefaultVaRest.ini | 6 ++ Source/VaRest/Private/VaRestJsonValue.cpp | 67 ---------------------- Source/VaRest/Private/VaRestSubsystem.cpp | 68 +++++++++++++++++++++++ Source/VaRest/Public/VaRestJsonValue.h | 24 -------- Source/VaRest/Public/VaRestSubsystem.h | 27 ++++++++- 6 files changed, 106 insertions(+), 92 deletions(-) diff --git a/Config/BaseVaRest.ini b/Config/BaseVaRest.ini index 22766973..3d2d46a5 100644 --- a/Config/BaseVaRest.ini +++ b/Config/BaseVaRest.ini @@ -12,3 +12,9 @@ +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") +FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueNumber",NewName="VaRestSubsystem.ConstructJsonValueNumber") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueString",NewName="VaRestSubsystem.ConstructJsonValueString") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueBool",NewName="VaRestSubsystem.ConstructJsonValueBool") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueArray",NewName="VaRestSubsystem.ConstructJsonValueArray") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueObject",NewName="VaRestSubsystem.ConstructJsonValueObject") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValue",NewName="VaRestSubsystem.ConstructJsonValue") diff --git a/Config/DefaultVaRest.ini b/Config/DefaultVaRest.ini index 22766973..f7fb26ed 100644 --- a/Config/DefaultVaRest.ini +++ b/Config/DefaultVaRest.ini @@ -12,3 +12,9 @@ +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") +FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueNumber",NewName="VaRestSubsystem.ConstructJsonValueNumber") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueString",NewName="VaRestSubsystem.ConstructJsonValueString") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueBool",NewName="VaRestSubsystem.ConstructJsonValueBool") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueArray",NewName="VaRestSubsystem.ConstructJsonValueArray") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueObject",NewName="VaRestSubsystem.ConstructJsonValueObject") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValue",NewName="VaRestSubsystem.ConstructJsonValue") \ No newline at end of file diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index 3895ae09..8b45a107 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -10,73 +10,6 @@ UVaRestJsonValue::UVaRestJsonValue(const FObjectInitializer& ObjectInitializer) { } -UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueNumber(UObject* WorldContextObject, float Number) -{ - TSharedPtr NewVal = MakeShareable(new FJsonValueNumber(Number)); - - UVaRestJsonValue* NewValue = NewObject(); - NewValue->SetRootValue(NewVal); - - return NewValue; -} - -UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueString(UObject* WorldContextObject, const FString& StringValue) -{ - TSharedPtr NewVal = MakeShareable(new FJsonValueString(StringValue)); - - UVaRestJsonValue* NewValue = NewObject(); - NewValue->SetRootValue(NewVal); - - return NewValue; -} - -UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueBool(UObject* WorldContextObject, bool InValue) -{ - TSharedPtr NewVal = MakeShareable(new FJsonValueBoolean(InValue)); - - UVaRestJsonValue* NewValue = NewObject(); - NewValue->SetRootValue(NewVal); - - return NewValue; -} - -UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueArray(UObject* WorldContextObject, const TArray& InArray) -{ - // Prepare data array to create new value - TArray> ValueArray; - for (auto InVal : InArray) - { - ValueArray.Add(InVal->GetRootValue()); - } - - TSharedPtr NewVal = MakeShareable(new FJsonValueArray(ValueArray)); - - UVaRestJsonValue* NewValue = NewObject(); - NewValue->SetRootValue(NewVal); - - return NewValue; -} - -UVaRestJsonValue* UVaRestJsonValue::ConstructJsonValueObject(UObject* WorldContextObject, UVaRestJsonObject* JsonObject) -{ - TSharedPtr NewVal = MakeShareable(new FJsonValueObject(JsonObject->GetRootObject())); - - UVaRestJsonValue* NewValue = NewObject(); - NewValue->SetRootValue(NewVal); - - return NewValue; -} - -UVaRestJsonValue* ConstructJsonValue(UObject* WorldContextObject, const TSharedPtr& InValue) -{ - TSharedPtr NewVal = InValue; - - UVaRestJsonValue* NewValue = NewObject(); - NewValue->SetRootValue(NewVal); - - return NewValue; -} - TSharedPtr& UVaRestJsonValue::GetRootValue() { return JsonVal; diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index e000da03..1b72b827 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -5,6 +5,7 @@ #include "VaRestDefines.h" #include "VaRestJsonObject.h" #include "VaRestSettings.h" +#include "VaRestJsonValue.h" #include "Developer/Settings/Public/ISettingsModule.h" #include "Misc/FileHelper.h" @@ -107,6 +108,73 @@ UVaRestJsonObject* UVaRestSubsystem::ConstructVaRestJsonObject() return NewObject(this); } +UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueNumber(float Number) +{ + TSharedPtr NewVal = MakeShareable(new FJsonValueNumber(Number)); + + UVaRestJsonValue* NewValue = NewObject(); + NewValue->SetRootValue(NewVal); + + return NewValue; +} + +UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueString(const FString& StringValue) +{ + TSharedPtr NewVal = MakeShareable(new FJsonValueString(StringValue)); + + UVaRestJsonValue* NewValue = NewObject(); + NewValue->SetRootValue(NewVal); + + return NewValue; +} + +UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueBool(bool InValue) +{ + TSharedPtr NewVal = MakeShareable(new FJsonValueBoolean(InValue)); + + UVaRestJsonValue* NewValue = NewObject(); + NewValue->SetRootValue(NewVal); + + return NewValue; +} + +UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueArray(const TArray& InArray) +{ + // Prepare data array to create new value + TArray> ValueArray; + for (auto InVal : InArray) + { + ValueArray.Add(InVal->GetRootValue()); + } + + TSharedPtr NewVal = MakeShareable(new FJsonValueArray(ValueArray)); + + UVaRestJsonValue* NewValue = NewObject(); + NewValue->SetRootValue(NewVal); + + return NewValue; +} + +UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueObject(UVaRestJsonObject* JsonObject) +{ + TSharedPtr NewVal = MakeShareable(new FJsonValueObject(JsonObject->GetRootObject())); + + UVaRestJsonValue* NewValue = NewObject(); + NewValue->SetRootValue(NewVal); + + return NewValue; +} + +UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValue(const TSharedPtr& InValue) +{ + TSharedPtr NewVal = InValue; + + UVaRestJsonValue* NewValue = NewObject(); + NewValue->SetRootValue(NewVal); + + return NewValue; +} + class UVaRestJsonObject* UVaRestSubsystem::LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir) { auto* Json = ConstructVaRestJsonObject(); diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index 1d9ad0f3..ef622b0b 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -32,30 +32,6 @@ class VAREST_API UVaRestJsonValue : public UObject { GENERATED_UCLASS_BODY() - /** Create new Json Number value - * Attn.!! float used instead of double to make the function blueprintable! */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Number Value", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json") - static UVaRestJsonValue* ConstructJsonValueNumber(UObject* WorldContextObject, float Number); - - /** Create new Json String value */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json String Value", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json") - static UVaRestJsonValue* ConstructJsonValueString(UObject* WorldContextObject, const FString& StringValue); - - /** Create new Json Bool value */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Bool Value", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json") - static UVaRestJsonValue* ConstructJsonValueBool(UObject* WorldContextObject, bool InValue); - - /** Create new Json Array value */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Array Value", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json") - static UVaRestJsonValue* ConstructJsonValueArray(UObject* WorldContextObject, const TArray& InArray); - - /** Create new Json Object value */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Object Value", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json") - static UVaRestJsonValue* ConstructJsonValueObject(UObject* WorldContextObject, UVaRestJsonObject* JsonObject); - - /** Create new Json value from FJsonValue (to be used from VaRestJsonObject) */ - static UVaRestJsonValue* ConstructJsonValue(UObject* WorldContextObject, const TSharedPtr& InValue); - /** Get the root Json value */ TSharedPtr& GetRootValue(); diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 15089252..77896d10 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -12,6 +12,7 @@ class UVaRestRequestJSON; class UVaRestSettings; +class UVaRestJsonValue; DECLARE_DYNAMIC_DELEGATE_OneParam(FVaRestCallDelegate, UVaRestRequestJSON*, Request); @@ -79,11 +80,35 @@ class VAREST_API UVaRestSubsystem : public UGameInstanceSubsystem UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Object"), Category = "VaRest|Subsystem") UVaRestJsonObject* ConstructVaRestJsonObject(); + /** Create new Json Number value + * Attn.!! float used instead of double to make the function blueprintable! */ + UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Number Value"), Category = "VaRest|Subsystem") + UVaRestJsonValue* ConstructJsonValueNumber(float Number); + + /** Create new Json String value */ + UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json String Value"), Category = "VaRest|Subsystem") + UVaRestJsonValue* ConstructJsonValueString(const FString& StringValue); + + /** Create new Json Bool value */ + UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Bool Value"), Category = "VaRest|Subsystem") + UVaRestJsonValue* ConstructJsonValueBool(bool InValue); + + /** Create new Json Array value */ + UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Array Value"), Category = "VaRest|Subsystem") + UVaRestJsonValue* ConstructJsonValueArray(const TArray& InArray); + + /** Create new Json Object value */ + UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Object Value"), Category = "VaRest|Subsystem") + UVaRestJsonValue* ConstructJsonValueObject(UVaRestJsonObject* JsonObject); + + /** Create new Json value from FJsonValue (to be used from VaRestJsonObject) */ + UVaRestJsonValue* ConstructJsonValue(const TSharedPtr& InValue); + ////////////////////////////////////////////////////////////////////////// // File system integration public: - /** + /** * Load JSON from formatted text file * @param bIsRelativeToContentDir if set to 'false' path is treated as absolute */ From 6b30aaa4b146e71a547d941f8d6bd322284dc77a Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Mon, 17 Feb 2020 07:54:08 -0500 Subject: [PATCH 11/71] Fix issues from feedback --- Source/VaRest/Private/VaRestSubsystem.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 1b72b827..ef6b9c3c 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -4,8 +4,8 @@ #include "VaRestDefines.h" #include "VaRestJsonObject.h" -#include "VaRestSettings.h" #include "VaRestJsonValue.h" +#include "VaRestSettings.h" #include "Developer/Settings/Public/ISettingsModule.h" #include "Misc/FileHelper.h" @@ -112,7 +112,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueNumber(float Number) { TSharedPtr NewVal = MakeShareable(new FJsonValueNumber(Number)); - UVaRestJsonValue* NewValue = NewObject(); + UVaRestJsonValue* NewValue = NewObject(this); NewValue->SetRootValue(NewVal); return NewValue; @@ -122,7 +122,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueString(const FString& Stri { TSharedPtr NewVal = MakeShareable(new FJsonValueString(StringValue)); - UVaRestJsonValue* NewValue = NewObject(); + UVaRestJsonValue* NewValue = NewObject(this); NewValue->SetRootValue(NewVal); return NewValue; @@ -132,7 +132,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueBool(bool InValue) { TSharedPtr NewVal = MakeShareable(new FJsonValueBoolean(InValue)); - UVaRestJsonValue* NewValue = NewObject(); + UVaRestJsonValue* NewValue = NewObject(this); NewValue->SetRootValue(NewVal); return NewValue; @@ -149,7 +149,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueArray(const TArray NewVal = MakeShareable(new FJsonValueArray(ValueArray)); - UVaRestJsonValue* NewValue = NewObject(); + UVaRestJsonValue* NewValue = NewObject(this); NewValue->SetRootValue(NewVal); return NewValue; @@ -159,7 +159,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueObject(UVaRestJsonObject* { TSharedPtr NewVal = MakeShareable(new FJsonValueObject(JsonObject->GetRootObject())); - UVaRestJsonValue* NewValue = NewObject(); + UVaRestJsonValue* NewValue = NewObject(this); NewValue->SetRootValue(NewVal); return NewValue; @@ -169,7 +169,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValue(const TSharedPtr NewVal = InValue; - UVaRestJsonValue* NewValue = NewObject(); + UVaRestJsonValue* NewValue = NewObject(this); NewValue->SetRootValue(NewVal); return NewValue; From a438e1d93776df1e92bdeb3943464c4ac4e07032 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Thu, 20 Feb 2020 08:13:04 -0500 Subject: [PATCH 12/71] Add HTTPStatusIntToEnum --- Source/VaRest/Public/VaRestLibrary.h | 104 ++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index ab85b19c..8adf4a49 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -9,6 +9,102 @@ #include "VaRestLibrary.generated.h" +#pragma region Enum +// Taken from Interfaces/IHttpResponse.h (had to make BlueprintType :/) +UENUM(BlueprintType) +namespace EHttpStatusCode +{ + /** + * Response codes that can come back from an Http request + */ + enum Type + { + // status code not set yet + Unknown = 0 UMETA(DisplayName = "Unknown = 0"), + // the request can be continued. + Continue = 100 UMETA(DisplayName = "Continue = 100"), + // the server has switched protocols in an upgrade header. + SwitchProtocol = 101 UMETA(DisplayName = "SwitchProtocol = 101"), + // the request completed successfully. + Ok = 200 UMETA(DisplayName = "Ok = 200"), + // the request has been fulfilled and resulted in the creation of a new resource. + Created = 201 UMETA(DisplayName = "Created = 201"), + // the request has been accepted for processing, but the processing has not been completed. + Accepted = 202 UMETA(DisplayName = "Accepted = 202"), + // the returned meta information in the entity-header is not the definitive set available from the origin server. + Partial = 203 UMETA(DisplayName = "Partial = 203"), + // the server has fulfilled the request, but there is no new information to send back. + NoContent = 204 UMETA(DisplayName = "NoContent = 204"), + // the request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action. + ResetContent = 205 UMETA(DisplayName = "ResetContent = 205"), + // the server has fulfilled the partial get request for the resource. + PartialContent = 206 UMETA(DisplayName = "PartialContent = 206"), + // the server couldn't decide what to return. + Ambiguous = 300 UMETA(DisplayName = "Ambiguous = 300"), + // the requested resource has been assigned to a new permanent uri (uniform resource identifier), and any future references to this resource should be done using one of the returned uris. + Moved = 301 UMETA(DisplayName = "Moved = 301"), + // the requested resource resides temporarily under a different uri (uniform resource identifier). + Redirect = 302 UMETA(DisplayName = "Redirect = 302"), + // the response to the request can be found under a different uri (uniform resource identifier) and should be retrieved using a get http verb on that resource. + RedirectMethod = 303 UMETA(DisplayName = "RedirectMethod = 303"), + // the requested resource has not been modified. + NotModified = 304 UMETA(DisplayName = "NotModified = 304"), + // the requested resource must be accessed through the proxy given by the location field. + UseProxy = 305 UMETA(DisplayName = "UseProxy = 305"), + // the redirected request keeps the same http verb. http/1.1 behavior. + RedirectKeepVerb = 307 UMETA(DisplayName = "RedirectKeepVerb = 307"), + // the request could not be processed by the server due to invalid syntax. + BadRequest = 400 UMETA(DisplayName = "BadRequest = 400"), + // the requested resource requires user authentication. + Denied = 401 UMETA(DisplayName = "Denied = 401"), + // not currently implemented in the http protocol. + PaymentReq = 402 UMETA(DisplayName = "PaymentReq = 402"), + // the server understood the request, but is refusing to fulfill it. + Forbidden = 403 UMETA(DisplayName = "Forbidden = 403"), + // the server has not found anything matching the requested uri (uniform resource identifier). + NotFound = 404 UMETA(DisplayName = "NotFound = 404"), + // the http verb used is not allowed. + BadMethod = 405 UMETA(DisplayName = "BadMethod = 405"), + // no responses acceptable to the client were found. + NoneAcceptable = 406 UMETA(DisplayName = "NoneAcceptable = 406"), + // proxy authentication required. + ProxyAuthReq = 407 UMETA(DisplayName = "ProxyAuthReq = 407"), + // the server timed out waiting for the request. + RequestTimeout = 408 UMETA(DisplayName = "RequestTimeout = 408"), + // the request could not be completed due to a conflict with the current state of the resource. the user should resubmit with more information. + Conflict = 409 UMETA(DisplayName = "Conflict = 409"), + // the requested resource is no longer available at the server, and no forwarding address is known. + Gone = 410 UMETA(DisplayName = "Gone = 410"), + // the server refuses to accept the request without a defined content length. + LengthRequired = 411 UMETA(DisplayName = "LengthRequired = 411"), + // the precondition given in one or more of the request header fields evaluated to false when it was tested on the server. + PrecondFailed = 412 UMETA(DisplayName = "PrecondFailed = 412"), + // the server is refusing to process a request because the request entity is larger than the server is willing or able to process. + RequestTooLarge = 413 UMETA(DisplayName = "RequestTooLarge = 413"), + // the server is refusing to service the request because the request uri (uniform resource identifier) is longer than the server is willing to interpret. + UriTooLong = 414 UMETA(DisplayName = "UriTooLong = 414"), + // the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. + UnsupportedMedia = 415 UMETA(DisplayName = "UnsupportedMedia = 415"), + // too many requests, the server is throttling + TooManyRequests = 429 UMETA(DisplayName = "TooManyRequests = 429"), + // the request should be retried after doing the appropriate action. + RetryWith = 449 UMETA(DisplayName = "RetryWith = 449"), + // the server encountered an unexpected condition that prevented it from fulfilling the request. + ServerError = 500 UMETA(DisplayName = "ServerError = 500"), + // the server does not support the functionality required to fulfill the request. + NotSupported = 501 UMETA(DisplayName = "NotSupported = 501"), + // the server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. + BadGateway = 502 UMETA(DisplayName = "BadGateway = 502"), + // the service is temporarily overloaded. + ServiceUnavail = 503 UMETA(DisplayName = "ServiceUnavail = 503"), + // the request was timed out waiting for a gateway. + GatewayTimeout = 504 UMETA(DisplayName = "GatewayTimeout = 504"), + // the server does not support, or refuses to support, the http protocol version that was used in the request message. + VersionNotSup = 505 UMETA(DisplayName = "VersionNotSup = 505") + }; +} // namespace EHttpStatusCode +#pragma endregion Enum + /** * Useful tools for REST communications */ @@ -76,4 +172,10 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to SHA1")) static FString StringToSha1(const FString& StringToHash); -}; + + /** + * Helper method to convert a status code from HTTP to an enum for easier readability + */ + UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "HTTP Status Int To Enum")) + static FORCEINLINE EHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EHttpStatusCode::Type)StatusCode; } +}; \ No newline at end of file From 7e2f5cf112370c7c6937760e24a79ea1bfdd34ab Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Thu, 20 Feb 2020 08:37:48 -0500 Subject: [PATCH 13/71] Apply fixes from feedback --- Source/VaRest/Public/VaRestLibrary.h | 96 ---------------------------- Source/VaRest/Public/VaRestTypes.h | 94 +++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 96 deletions(-) diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 8adf4a49..31211497 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -9,102 +9,6 @@ #include "VaRestLibrary.generated.h" -#pragma region Enum -// Taken from Interfaces/IHttpResponse.h (had to make BlueprintType :/) -UENUM(BlueprintType) -namespace EHttpStatusCode -{ - /** - * Response codes that can come back from an Http request - */ - enum Type - { - // status code not set yet - Unknown = 0 UMETA(DisplayName = "Unknown = 0"), - // the request can be continued. - Continue = 100 UMETA(DisplayName = "Continue = 100"), - // the server has switched protocols in an upgrade header. - SwitchProtocol = 101 UMETA(DisplayName = "SwitchProtocol = 101"), - // the request completed successfully. - Ok = 200 UMETA(DisplayName = "Ok = 200"), - // the request has been fulfilled and resulted in the creation of a new resource. - Created = 201 UMETA(DisplayName = "Created = 201"), - // the request has been accepted for processing, but the processing has not been completed. - Accepted = 202 UMETA(DisplayName = "Accepted = 202"), - // the returned meta information in the entity-header is not the definitive set available from the origin server. - Partial = 203 UMETA(DisplayName = "Partial = 203"), - // the server has fulfilled the request, but there is no new information to send back. - NoContent = 204 UMETA(DisplayName = "NoContent = 204"), - // the request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action. - ResetContent = 205 UMETA(DisplayName = "ResetContent = 205"), - // the server has fulfilled the partial get request for the resource. - PartialContent = 206 UMETA(DisplayName = "PartialContent = 206"), - // the server couldn't decide what to return. - Ambiguous = 300 UMETA(DisplayName = "Ambiguous = 300"), - // the requested resource has been assigned to a new permanent uri (uniform resource identifier), and any future references to this resource should be done using one of the returned uris. - Moved = 301 UMETA(DisplayName = "Moved = 301"), - // the requested resource resides temporarily under a different uri (uniform resource identifier). - Redirect = 302 UMETA(DisplayName = "Redirect = 302"), - // the response to the request can be found under a different uri (uniform resource identifier) and should be retrieved using a get http verb on that resource. - RedirectMethod = 303 UMETA(DisplayName = "RedirectMethod = 303"), - // the requested resource has not been modified. - NotModified = 304 UMETA(DisplayName = "NotModified = 304"), - // the requested resource must be accessed through the proxy given by the location field. - UseProxy = 305 UMETA(DisplayName = "UseProxy = 305"), - // the redirected request keeps the same http verb. http/1.1 behavior. - RedirectKeepVerb = 307 UMETA(DisplayName = "RedirectKeepVerb = 307"), - // the request could not be processed by the server due to invalid syntax. - BadRequest = 400 UMETA(DisplayName = "BadRequest = 400"), - // the requested resource requires user authentication. - Denied = 401 UMETA(DisplayName = "Denied = 401"), - // not currently implemented in the http protocol. - PaymentReq = 402 UMETA(DisplayName = "PaymentReq = 402"), - // the server understood the request, but is refusing to fulfill it. - Forbidden = 403 UMETA(DisplayName = "Forbidden = 403"), - // the server has not found anything matching the requested uri (uniform resource identifier). - NotFound = 404 UMETA(DisplayName = "NotFound = 404"), - // the http verb used is not allowed. - BadMethod = 405 UMETA(DisplayName = "BadMethod = 405"), - // no responses acceptable to the client were found. - NoneAcceptable = 406 UMETA(DisplayName = "NoneAcceptable = 406"), - // proxy authentication required. - ProxyAuthReq = 407 UMETA(DisplayName = "ProxyAuthReq = 407"), - // the server timed out waiting for the request. - RequestTimeout = 408 UMETA(DisplayName = "RequestTimeout = 408"), - // the request could not be completed due to a conflict with the current state of the resource. the user should resubmit with more information. - Conflict = 409 UMETA(DisplayName = "Conflict = 409"), - // the requested resource is no longer available at the server, and no forwarding address is known. - Gone = 410 UMETA(DisplayName = "Gone = 410"), - // the server refuses to accept the request without a defined content length. - LengthRequired = 411 UMETA(DisplayName = "LengthRequired = 411"), - // the precondition given in one or more of the request header fields evaluated to false when it was tested on the server. - PrecondFailed = 412 UMETA(DisplayName = "PrecondFailed = 412"), - // the server is refusing to process a request because the request entity is larger than the server is willing or able to process. - RequestTooLarge = 413 UMETA(DisplayName = "RequestTooLarge = 413"), - // the server is refusing to service the request because the request uri (uniform resource identifier) is longer than the server is willing to interpret. - UriTooLong = 414 UMETA(DisplayName = "UriTooLong = 414"), - // the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. - UnsupportedMedia = 415 UMETA(DisplayName = "UnsupportedMedia = 415"), - // too many requests, the server is throttling - TooManyRequests = 429 UMETA(DisplayName = "TooManyRequests = 429"), - // the request should be retried after doing the appropriate action. - RetryWith = 449 UMETA(DisplayName = "RetryWith = 449"), - // the server encountered an unexpected condition that prevented it from fulfilling the request. - ServerError = 500 UMETA(DisplayName = "ServerError = 500"), - // the server does not support the functionality required to fulfill the request. - NotSupported = 501 UMETA(DisplayName = "NotSupported = 501"), - // the server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. - BadGateway = 502 UMETA(DisplayName = "BadGateway = 502"), - // the service is temporarily overloaded. - ServiceUnavail = 503 UMETA(DisplayName = "ServiceUnavail = 503"), - // the request was timed out waiting for a gateway. - GatewayTimeout = 504 UMETA(DisplayName = "GatewayTimeout = 504"), - // the server does not support, or refuses to support, the http protocol version that was used in the request message. - VersionNotSup = 505 UMETA(DisplayName = "VersionNotSup = 505") - }; -} // namespace EHttpStatusCode -#pragma endregion Enum - /** * Useful tools for REST communications */ diff --git a/Source/VaRest/Public/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h index 5088e60c..38fc6527 100644 --- a/Source/VaRest/Public/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -41,3 +41,97 @@ enum class ERequestStatus : uint8 /** Finished and was successful */ Succeeded }; + +// Taken from Interfaces/IHttpResponse.h (had to make BlueprintType :/) +UENUM(BlueprintType) +namespace EHttpStatusCode +{ +/** + * Response codes that can come back from an Http request + */ +enum Type +{ + // status code not set yet + Unknown = 0 UMETA(DisplayName = "Unknown = 0"), + // the request can be continued. + Continue = 100 UMETA(DisplayName = "Continue = 100"), + // the server has switched protocols in an upgrade header. + SwitchProtocol = 101 UMETA(DisplayName = "SwitchProtocol = 101"), + // the request completed successfully. + Ok = 200 UMETA(DisplayName = "Ok = 200"), + // the request has been fulfilled and resulted in the creation of a new resource. + Created = 201 UMETA(DisplayName = "Created = 201"), + // the request has been accepted for processing, but the processing has not been completed. + Accepted = 202 UMETA(DisplayName = "Accepted = 202"), + // the returned meta information in the entity-header is not the definitive set available from the origin server. + Partial = 203 UMETA(DisplayName = "Partial = 203"), + // the server has fulfilled the request, but there is no new information to send back. + NoContent = 204 UMETA(DisplayName = "NoContent = 204"), + // the request has been completed, and the client program should reset the document view that caused the request to be sent to allow the user to easily initiate another input action. + ResetContent = 205 UMETA(DisplayName = "ResetContent = 205"), + // the server has fulfilled the partial get request for the resource. + PartialContent = 206 UMETA(DisplayName = "PartialContent = 206"), + // the server couldn't decide what to return. + Ambiguous = 300 UMETA(DisplayName = "Ambiguous = 300"), + // the requested resource has been assigned to a new permanent uri (uniform resource identifier), and any future references to this resource should be done using one of the returned uris. + Moved = 301 UMETA(DisplayName = "Moved = 301"), + // the requested resource resides temporarily under a different uri (uniform resource identifier). + Redirect = 302 UMETA(DisplayName = "Redirect = 302"), + // the response to the request can be found under a different uri (uniform resource identifier) and should be retrieved using a get http verb on that resource. + RedirectMethod = 303 UMETA(DisplayName = "RedirectMethod = 303"), + // the requested resource has not been modified. + NotModified = 304 UMETA(DisplayName = "NotModified = 304"), + // the requested resource must be accessed through the proxy given by the location field. + UseProxy = 305 UMETA(DisplayName = "UseProxy = 305"), + // the redirected request keeps the same http verb. http/1.1 behavior. + RedirectKeepVerb = 307 UMETA(DisplayName = "RedirectKeepVerb = 307"), + // the request could not be processed by the server due to invalid syntax. + BadRequest = 400 UMETA(DisplayName = "BadRequest = 400"), + // the requested resource requires user authentication. + Denied = 401 UMETA(DisplayName = "Denied = 401"), + // not currently implemented in the http protocol. + PaymentReq = 402 UMETA(DisplayName = "PaymentReq = 402"), + // the server understood the request, but is refusing to fulfill it. + Forbidden = 403 UMETA(DisplayName = "Forbidden = 403"), + // the server has not found anything matching the requested uri (uniform resource identifier). + NotFound = 404 UMETA(DisplayName = "NotFound = 404"), + // the http verb used is not allowed. + BadMethod = 405 UMETA(DisplayName = "BadMethod = 405"), + // no responses acceptable to the client were found. + NoneAcceptable = 406 UMETA(DisplayName = "NoneAcceptable = 406"), + // proxy authentication required. + ProxyAuthReq = 407 UMETA(DisplayName = "ProxyAuthReq = 407"), + // the server timed out waiting for the request. + RequestTimeout = 408 UMETA(DisplayName = "RequestTimeout = 408"), + // the request could not be completed due to a conflict with the current state of the resource. the user should resubmit with more information. + Conflict = 409 UMETA(DisplayName = "Conflict = 409"), + // the requested resource is no longer available at the server, and no forwarding address is known. + Gone = 410 UMETA(DisplayName = "Gone = 410"), + // the server refuses to accept the request without a defined content length. + LengthRequired = 411 UMETA(DisplayName = "LengthRequired = 411"), + // the precondition given in one or more of the request header fields evaluated to false when it was tested on the server. + PrecondFailed = 412 UMETA(DisplayName = "PrecondFailed = 412"), + // the server is refusing to process a request because the request entity is larger than the server is willing or able to process. + RequestTooLarge = 413 UMETA(DisplayName = "RequestTooLarge = 413"), + // the server is refusing to service the request because the request uri (uniform resource identifier) is longer than the server is willing to interpret. + UriTooLong = 414 UMETA(DisplayName = "UriTooLong = 414"), + // the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. + UnsupportedMedia = 415 UMETA(DisplayName = "UnsupportedMedia = 415"), + // too many requests, the server is throttling + TooManyRequests = 429 UMETA(DisplayName = "TooManyRequests = 429"), + // the request should be retried after doing the appropriate action. + RetryWith = 449 UMETA(DisplayName = "RetryWith = 449"), + // the server encountered an unexpected condition that prevented it from fulfilling the request. + ServerError = 500 UMETA(DisplayName = "ServerError = 500"), + // the server does not support the functionality required to fulfill the request. + NotSupported = 501 UMETA(DisplayName = "NotSupported = 501"), + // the server, while acting as a gateway or proxy, received an invalid response from the upstream server it accessed in attempting to fulfill the request. + BadGateway = 502 UMETA(DisplayName = "BadGateway = 502"), + // the service is temporarily overloaded. + ServiceUnavail = 503 UMETA(DisplayName = "ServiceUnavail = 503"), + // the request was timed out waiting for a gateway. + GatewayTimeout = 504 UMETA(DisplayName = "GatewayTimeout = 504"), + // the server does not support, or refuses to support, the http protocol version that was used in the request message. + VersionNotSup = 505 UMETA(DisplayName = "VersionNotSup = 505") +}; +} // namespace EHttpStatusCode \ No newline at end of file From c11707aeba7dd80180cf4b979a4bde36b11f5dc0 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 20 Feb 2020 17:23:05 +0300 Subject: [PATCH 14/71] Update VaRestLibrary.h --- Source/VaRest/Public/VaRestLibrary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 31211497..7015dc4b 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -82,4 +82,4 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "HTTP Status Int To Enum")) static FORCEINLINE EHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EHttpStatusCode::Type)StatusCode; } -}; \ No newline at end of file +}; From a3c32b82769dca1fc43a0c66b6efbf895bcaffdf Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 20 Feb 2020 17:23:32 +0300 Subject: [PATCH 15/71] Update VaRestTypes.h --- Source/VaRest/Public/VaRestTypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h index 38fc6527..bf0a5534 100644 --- a/Source/VaRest/Public/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -134,4 +134,4 @@ enum Type // the server does not support, or refuses to support, the http protocol version that was used in the request message. VersionNotSup = 505 UMETA(DisplayName = "VersionNotSup = 505") }; -} // namespace EHttpStatusCode \ No newline at end of file +} // namespace EHttpStatusCode From 11adacdedaff00df17a8266ba815a7d285f8a0f6 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 26 Feb 2020 20:57:23 +0300 Subject: [PATCH 16/71] Fix Settins issue and close #276. Non-unity build fixed too, close #277 --- Source/VaRest/Private/VaRest.cpp | 47 +++++++++++++++++++++ Source/VaRest/Private/VaRestLibrary.cpp | 8 +++- Source/VaRest/Private/VaRestRequestJSON.cpp | 19 ++------- Source/VaRest/Private/VaRestSubsystem.cpp | 22 ---------- Source/VaRest/Public/VaRest.h | 13 ++++++ Source/VaRest/Public/VaRestJsonObject.h | 3 +- Source/VaRest/Public/VaRestLibrary.h | 9 ++++ Source/VaRest/Public/VaRestRequestJSON.h | 3 -- Source/VaRest/Public/VaRestSubsystem.h | 18 +------- 9 files changed, 81 insertions(+), 61 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 45944a2f..793b4986 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -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(GetTransientPackage(), "VaRestSettings", RF_Standalone); + ModuleSettings->AddToRoot(); + + // Register settings + if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("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("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 diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index 0a341fe0..ab7efa81 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -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) { diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 8b15c300..bfcb6b4d 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -6,7 +6,6 @@ #include "VaRestJsonObject.h" #include "VaRestLibrary.h" #include "VaRestSettings.h" -#include "VaRestSubsystem.h" #include "Json.h" #include "Kismet/GameplayStatics.h" @@ -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); } @@ -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); } @@ -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& Bytes = Response->GetContent(); @@ -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()->GetSettings(); - } - - UE_LOG(LogVaRest, Warning, TEXT("%s: No World is provided for Outer object, Default settings will be used"), *VA_FUNC_LINE); - return GetDefault(); -} diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index ef6b9c3c..9629a94b 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -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() { @@ -22,17 +19,6 @@ void UVaRestSubsystem::Initialize(FSubsystemCollectionBase& Collection) { Super::Initialize(Collection); - Settings = NewObject(GetTransientPackage(), "VaRestSettings", RF_Standalone); - - // Register settings - if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("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); } @@ -198,11 +184,3 @@ class UVaRestJsonObject* UVaRestSubsystem::LoadJsonFromFile(const FString& Path, return nullptr; } - -UVaRestSettings* UVaRestSubsystem::GetSettings() const -{ - check(Settings); - return Settings; -} - -#undef LOCTEXT_NAMESPACE diff --git a/Source/VaRest/Public/VaRest.h b/Source/VaRest/Public/VaRest.h index c5c37b63..86dade53 100644 --- a/Source/VaRest/Public/VaRest.h +++ b/Source/VaRest/Public/VaRest.h @@ -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. @@ -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; }; diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 8447b497..4872f064 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -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(); @@ -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") diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 7015dc4b..d2c274ce 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -9,6 +9,8 @@ #include "VaRestLibrary.generated.h" +class UVaRestSettings; + /** * Useful tools for REST communications */ @@ -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 diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index 4d643d65..25b66666 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -318,7 +318,4 @@ class VAREST_API UVaRestRequestJSON : public UObject public: /** Returns reference to internal request object */ TSharedRef GetHttpRequest() const { return HttpRequest; }; - - /** Helper function to get runtime settings */ - const UVaRestSettings* GetSettings() const; }; diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 77896d10..3677b7ba 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -2,6 +2,7 @@ #pragma once +#include "VaRestJsonValue.h" #include "VaRestRequestJSON.h" #include "Delegates/DelegateCombinations.h" @@ -10,10 +11,6 @@ #include "VaRestSubsystem.generated.h" -class UVaRestRequestJSON; -class UVaRestSettings; -class UVaRestJsonValue; - DECLARE_DYNAMIC_DELEGATE_OneParam(FVaRestCallDelegate, UVaRestRequestJSON*, Request); USTRUCT() @@ -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; }; From 989a5079b24f4ec83a45282630d00730e801b18f Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 4 Mar 2020 19:11:27 +0300 Subject: [PATCH 17/71] Fix bugs and improve performance a bit --- Source/VaRest/Private/VaRestRequestJSON.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index bfcb6b4d..fb154dc5 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -508,10 +508,8 @@ void UVaRestRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttp } // Broadcast the result events on next tick - AsyncTask(ENamedThreads::GameThread, [this]() { - OnRequestComplete.Broadcast(this); - OnStaticRequestComplete.Broadcast(this); - }); + OnRequestComplete.Broadcast(this); + OnStaticRequestComplete.Broadcast(this); // Finish the latent action if (ContinueAction) From 468423f82574df3232657c2414418b6f34fd4c9f Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 5 Mar 2020 10:21:10 +0300 Subject: [PATCH 18/71] Update plugin descriptor to UE 4.25 --- VaRest.uplugin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VaRest.uplugin b/VaRest.uplugin index 610331b5..d3adbb68 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -6,7 +6,7 @@ "VersionName" : "1.1-r28", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", - "EngineVersion" : "4.24.0", + "EngineVersion" : "4.25.0", "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", "DocsURL": "https://bit.ly/VaRest-Docs", From 9c4c896f71eb1d84b28bfc22bbf46d6bdc58c1e8 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 26 Mar 2020 13:39:41 +0300 Subject: [PATCH 19/71] Avoid possible name collisions with derived plugins. Close #290 --- Config/BaseVaRest.ini | 9 ++++--- Config/DefaultVaRest.ini | 10 ++++--- Source/VaRest/Private/VaRestRequestJSON.cpp | 30 ++++++++++----------- Source/VaRest/Private/VaRestSubsystem.cpp | 4 +-- Source/VaRest/Public/VaRestLibrary.h | 2 +- Source/VaRest/Public/VaRestRequestJSON.h | 10 +++---- Source/VaRest/Public/VaRestSubsystem.h | 4 +-- Source/VaRest/Public/VaRestTypes.h | 10 +++---- 8 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Config/BaseVaRest.ini b/Config/BaseVaRest.ini index 3d2d46a5..7659dd7d 100644 --- a/Config/BaseVaRest.ini +++ b/Config/BaseVaRest.ini @@ -6,9 +6,12 @@ +ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestRequestJSON",NewName="/Script/VaRest.VaRestRequestJSON") +StructRedirects=(OldName="/Script/VaRestPlugin.VaRestCallResponse",NewName="/Script/VaRest.VaRestCallResponse") +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaJson",NewName="/Script/VaRest.EVaJson") -+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestVerb",NewName="/Script/VaRest.ERequestVerb") -+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestContentType",NewName="/Script/VaRest.ERequestContentType") -+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestStatus",NewName="/Script/VaRest.ERequestStatus") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") ++EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") ++EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") ++EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") +FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") diff --git a/Config/DefaultVaRest.ini b/Config/DefaultVaRest.ini index f7fb26ed..8cc9aa52 100644 --- a/Config/DefaultVaRest.ini +++ b/Config/DefaultVaRest.ini @@ -6,9 +6,13 @@ +ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestRequestJSON",NewName="/Script/VaRest.VaRestRequestJSON") +StructRedirects=(OldName="/Script/VaRestPlugin.VaRestCallResponse",NewName="/Script/VaRest.VaRestCallResponse") +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaJson",NewName="/Script/VaRest.EVaJson") -+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestVerb",NewName="/Script/VaRest.ERequestVerb") -+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestContentType",NewName="/Script/VaRest.ERequestContentType") -+EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestStatus",NewName="/Script/VaRest.ERequestStatus") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") ++EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") ++EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") ++EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") ++EnumRedirects=(OldName="/Script/VaRest.EVaRestHttpStatusCode",NewName="/Script/VaRest.EVaRestHttpStatusCode") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") +FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index fb154dc5..9dd4f1dd 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -30,13 +30,13 @@ UVaRestRequestJSON::UVaRestRequestJSON(const class FObjectInitializer& PCIP) { ContinueAction = nullptr; - RequestVerb = ERequestVerb::GET; - RequestContentType = ERequestContentType::x_www_form_urlencoded_url; + RequestVerb = EVaRestRequestVerb::GET; + RequestContentType = EVaRestRequestContentType::x_www_form_urlencoded_url; ResetData(); } -void UVaRestRequestJSON::SetVerb(ERequestVerb Verb) +void UVaRestRequestJSON::SetVerb(EVaRestRequestVerb Verb) { RequestVerb = Verb; } @@ -46,7 +46,7 @@ void UVaRestRequestJSON::SetCustomVerb(FString Verb) CustomVerb = Verb; } -void UVaRestRequestJSON::SetContentType(ERequestContentType ContentType) +void UVaRestRequestJSON::SetContentType(EVaRestRequestContentType ContentType) { RequestContentType = ContentType; } @@ -171,9 +171,9 @@ FString UVaRestRequestJSON::GetURL() const return HttpRequest->GetURL(); } -ERequestStatus UVaRestRequestJSON::GetStatus() const +EVaRestRequestStatus UVaRestRequestJSON::GetStatus() const { - return ERequestStatus((uint8)HttpRequest->GetStatus()); + return EVaRestRequestStatus((uint8)HttpRequest->GetStatus()); } int32 UVaRestRequestJSON::GetResponseCode() const @@ -278,23 +278,23 @@ void UVaRestRequestJSON::ProcessRequest() // Set verb switch (RequestVerb) { - case ERequestVerb::GET: + case EVaRestRequestVerb::GET: HttpRequest->SetVerb(TEXT("GET")); break; - case ERequestVerb::POST: + case EVaRestRequestVerb::POST: HttpRequest->SetVerb(TEXT("POST")); break; - case ERequestVerb::PUT: + case EVaRestRequestVerb::PUT: HttpRequest->SetVerb(TEXT("PUT")); break; - case ERequestVerb::DEL: + case EVaRestRequestVerb::DEL: HttpRequest->SetVerb(TEXT("DELETE")); break; - case ERequestVerb::CUSTOM: + case EVaRestRequestVerb::CUSTOM: HttpRequest->SetVerb(CustomVerb); break; @@ -305,7 +305,7 @@ void UVaRestRequestJSON::ProcessRequest() // Set content-type switch (RequestContentType) { - case ERequestContentType::x_www_form_urlencoded_url: + case EVaRestRequestContentType::x_www_form_urlencoded_url: { HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded")); @@ -348,7 +348,7 @@ void UVaRestRequestJSON::ProcessRequest() break; } - case ERequestContentType::x_www_form_urlencoded_body: + case EVaRestRequestContentType::x_www_form_urlencoded_body: { HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded")); @@ -385,7 +385,7 @@ void UVaRestRequestJSON::ProcessRequest() break; } - case ERequestContentType::binary: + case EVaRestRequestContentType::binary: { HttpRequest->SetHeader(TEXT("Content-Type"), BinaryContentType); HttpRequest->SetContent(RequestBytes); @@ -394,7 +394,7 @@ void UVaRestRequestJSON::ProcessRequest() break; } - case ERequestContentType::json: + case EVaRestRequestContentType::json: { HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json")); diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 9629a94b..48072ced 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -28,7 +28,7 @@ void UVaRestSubsystem::Deinitialize() Super::Deinitialize(); } -void UVaRestSubsystem::CallURL(const FString& URL, ERequestVerb Verb, ERequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback) +void UVaRestSubsystem::CallURL(const FString& URL, EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback) { UWorld* World = GetWorld(); check(World); @@ -79,7 +79,7 @@ UVaRestRequestJSON* UVaRestSubsystem::ConstructVaRestRequest() return NewObject(this); } -UVaRestRequestJSON* UVaRestSubsystem::ConstructVaRestRequestExt(ERequestVerb Verb, ERequestContentType ContentType) +UVaRestRequestJSON* UVaRestSubsystem::ConstructVaRestRequestExt(EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType) { UVaRestRequestJSON* Request = ConstructVaRestRequest(); diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index d2c274ce..722a890e 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -90,5 +90,5 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary * Helper method to convert a status code from HTTP to an enum for easier readability */ UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "HTTP Status Int To Enum")) - static FORCEINLINE EHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EHttpStatusCode::Type)StatusCode; } + static FORCEINLINE EVaRestHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EVaRestHttpStatusCode::Type)StatusCode; } }; diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index 25b66666..57b090b7 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -89,7 +89,7 @@ class VAREST_API UVaRestRequestJSON : public UObject /** Set verb to the request */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") - void SetVerb(ERequestVerb Verb); + void SetVerb(EVaRestRequestVerb Verb); /** Set custom verb to the request */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") @@ -98,7 +98,7 @@ class VAREST_API UVaRestRequestJSON : public UObject /** Set content type to the request. If you're using the x-www-form-urlencoded, * params/constaints should be defined as key=ValueString pairs from Json data */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") - void SetContentType(ERequestContentType ContentType); + void SetContentType(EVaRestRequestContentType ContentType); /** Set content type of the request for binary post data */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") @@ -163,7 +163,7 @@ class VAREST_API UVaRestRequestJSON : public UObject /** Get status of http request */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") - ERequestStatus GetStatus() const; + EVaRestRequestStatus GetStatus() const; /** Get the response code of the last query */ UFUNCTION(BlueprintCallable, Category = "VaRest|Response") @@ -295,10 +295,10 @@ class VAREST_API UVaRestRequestJSON : public UObject UVaRestJsonObject* ResponseJsonObj; /** Verb for making request (GET,POST,etc) */ - ERequestVerb RequestVerb; + EVaRestRequestVerb RequestVerb; /** Content type to be applied for request */ - ERequestContentType RequestContentType; + EVaRestRequestContentType RequestContentType; /** Mapping of header section to values. Used to generate final header string for request */ TMap RequestHeaders; diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 3677b7ba..a15c9a52 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -52,7 +52,7 @@ class VAREST_API UVaRestSubsystem : public UGameInstanceSubsystem public: /** Easy way to process http requests */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility") - void CallURL(const FString& URL, ERequestVerb Verb, ERequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback); + void CallURL(const FString& URL, EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback); /** Called when URL is processed (one for both success/unsuccess events)*/ void OnCallComplete(UVaRestRequestJSON* Request); @@ -71,7 +71,7 @@ class VAREST_API UVaRestSubsystem : public UGameInstanceSubsystem /** Creates new request with defined verb and content type */ UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Request"), Category = "VaRest|Subsystem") - UVaRestRequestJSON* ConstructVaRestRequestExt(ERequestVerb Verb, ERequestContentType ContentType); + UVaRestRequestJSON* ConstructVaRestRequestExt(EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType); /** Create new Json object */ UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Object"), Category = "VaRest|Subsystem") diff --git a/Source/VaRest/Public/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h index bf0a5534..1a5c0d7e 100644 --- a/Source/VaRest/Public/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -4,7 +4,7 @@ /** Verb (GET, PUT, POST) used by the request */ UENUM(BlueprintType) -enum class ERequestVerb : uint8 +enum class EVaRestRequestVerb : uint8 { GET, POST, @@ -17,7 +17,7 @@ enum class ERequestVerb : uint8 // clang-format off /** Content type (json, urlencoded, etc.) used by the request */ UENUM(BlueprintType) -enum class ERequestContentType : uint8 +enum class EVaRestRequestContentType : uint8 { x_www_form_urlencoded_url UMETA(DisplayName = "x-www-form-urlencoded (URL)"), x_www_form_urlencoded_body UMETA(DisplayName = "x-www-form-urlencoded (Request Body)"), @@ -28,7 +28,7 @@ enum class ERequestContentType : uint8 /** Enumerates the current state of an Http request */ UENUM(BlueprintType) -enum class ERequestStatus : uint8 +enum class EVaRestRequestStatus : uint8 { /** Has not been started via ProcessRequest() */ NotStarted, @@ -44,7 +44,7 @@ enum class ERequestStatus : uint8 // Taken from Interfaces/IHttpResponse.h (had to make BlueprintType :/) UENUM(BlueprintType) -namespace EHttpStatusCode +namespace EVaRestHttpStatusCode { /** * Response codes that can come back from an Http request @@ -134,4 +134,4 @@ enum Type // the server does not support, or refuses to support, the http protocol version that was used in the request message. VersionNotSup = 505 UMETA(DisplayName = "VersionNotSup = 505") }; -} // namespace EHttpStatusCode +} // namespace EVaRestHttpStatusCode From a2474e4be58407773fede18a47fe0149891ee222 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Tue, 31 Mar 2020 21:15:07 +0300 Subject: [PATCH 20/71] Override request content for Post/url-encoded-body. Close #268 --- Source/VaRest/Private/VaRestRequestJSON.cpp | 28 +++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 9dd4f1dd..5089fa5f 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -355,19 +355,27 @@ void UVaRestRequestJSON::ProcessRequest() FString UrlParams = ""; uint16 ParamIdx = 0; - // Loop through all the values and prepare additional url part - for (auto RequestIt = RequestJsonObj->GetRootObject()->Values.CreateIterator(); RequestIt; ++RequestIt) + // Add optional string content + if (!StringRequestContent.IsEmpty()) { - FString Key = RequestIt.Key(); - FString Value = RequestIt.Value().Get()->AsString(); - - if (!Key.IsEmpty() && !Value.IsEmpty()) + UrlParams = StringRequestContent; + } + else + { + // Loop through all the values and prepare additional url part + for (auto RequestIt = RequestJsonObj->GetRootObject()->Values.CreateIterator(); RequestIt; ++RequestIt) { - UrlParams += ParamIdx == 0 ? "" : "&"; - UrlParams += UVaRestLibrary::PercentEncode(Key) + "=" + UVaRestLibrary::PercentEncode(Value); - } + FString Key = RequestIt.Key(); + FString Value = RequestIt.Value().Get()->AsString(); - ParamIdx++; + if (!Key.IsEmpty() && !Value.IsEmpty()) + { + UrlParams += ParamIdx == 0 ? "" : "&"; + UrlParams += UVaRestLibrary::PercentEncode(Key) + "=" + UVaRestLibrary::PercentEncode(Value); + } + + ParamIdx++; + } } // Apply params From 0d70a0e5a5f498c29e9f521fddf6ff454fb6a99b Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Tue, 31 Mar 2020 23:03:03 +0300 Subject: [PATCH 21/71] Now it's engine module, not GI one. Subsystems. What could possibly go wrong? Close #287 --- Source/VaRest/Private/VaRestSubsystem.cpp | 2 +- Source/VaRest/Public/VaRestSubsystem.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 48072ced..53e8f0bf 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -11,7 +11,7 @@ #include "Misc/Paths.h" UVaRestSubsystem::UVaRestSubsystem() - : UGameInstanceSubsystem() + : UEngineSubsystem() { } diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index a15c9a52..27265753 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -6,7 +6,7 @@ #include "VaRestRequestJSON.h" #include "Delegates/DelegateCombinations.h" -#include "Subsystems/GameInstanceSubsystem.h" +#include "Subsystems/EngineSubsystem.h" #include "Subsystems/SubsystemCollection.h" #include "VaRestSubsystem.generated.h" @@ -34,7 +34,7 @@ struct FVaRestCallResponse }; UCLASS() -class VAREST_API UVaRestSubsystem : public UGameInstanceSubsystem +class VAREST_API UVaRestSubsystem : public UEngineSubsystem { GENERATED_BODY() From ac130d894ef1426c8b1a59b6a77254ac43d970c7 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 1 Apr 2020 12:42:12 +0300 Subject: [PATCH 22/71] Up plugin version --- README.md | 2 +- VaRest.uplugin | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b13aa22d..9618f361 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 26** (UE 4.19-4.23) +Current version: **1.1 R 29** (UE 4.24) ![SCREENSHOT](SCREENSHOT.jpg) diff --git a/VaRest.uplugin b/VaRest.uplugin index 610331b5..25fbc2c0 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -2,8 +2,8 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 28, - "VersionName" : "1.1-r28", + "Version" : 29, + "VersionName" : "1.1-r29", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", "EngineVersion" : "4.24.0", From 12a71457640f29dc02a75cca9b1367a9cfc703cd Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Tue, 7 Apr 2020 10:36:31 +0300 Subject: [PATCH 23/71] PinName should be FName instead of FText (no l10n now). Close #278 - Make Json does not respect link to String Tables in Blueprints --- Source/VaRestEditor/Private/VaRest_BreakJson.cpp | 11 ++++------- Source/VaRestEditor/Public/VaRest_BreakJson.h | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index 1ac31e0c..a4d44feb 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -254,7 +254,7 @@ FText UVaRest_BreakJson::GetMenuCategory() const if (CachedCategory.IsOutOfDate(this)) { // FText::Format() is slow, so we cache this to save on performance - CachedCategory.SetCachedText(FEditorCategoryUtils::BuildCategoryString(FCommonEditorCategory::Utilities, LOCTEXT("ActionMenuCategory", "Va Rest")), this); + CachedCategory.SetCachedText(FEditorCategoryUtils::BuildCategoryString(FCommonEditorCategory::Utilities, LOCTEXT("ActionMenuCategory", "VaRest")), this); } return CachedCategory; } @@ -273,7 +273,6 @@ void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) #endif UObject* Subtype = nullptr; - FString FieldName = (*it).Name.ToString(); switch ((*it).Type) { @@ -297,7 +296,7 @@ void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) UEdGraphNode::FCreatePinParams OutputPinParams; OutputPinParams.ContainerType = (*it).bIsArray ? EPinContainerType::Array : EPinContainerType::None; - UEdGraphPin* OutputPin = CreatePin(EGPD_Output, Type, TEXT(""), Subtype, FName((*(*it).Name.ToString())), OutputPinParams); + UEdGraphPin* OutputPin = CreatePin(EGPD_Output, Type, TEXT(""), Subtype, (*it).Name, OutputPinParams); } } @@ -360,7 +359,6 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor UEdGraphPin* Pin = Node->Pins[PinIndex]; if (Pin && (EGPD_Input == Pin->Direction)) { - FBPTerminal** Source = Context.NetMap.Find(FEdGraphUtilities::GetNetFromPin(Pin)); #if ENGINE_MINOR_VERSION >= 19 @@ -548,7 +546,7 @@ FText UVaRest_MakeJson::GetMenuCategory() const if (CachedCategory.IsOutOfDate(this)) { // FText::Format() is slow, so we cache this to save on performance - CachedCategory.SetCachedText(FEditorCategoryUtils::BuildCategoryString(FCommonEditorCategory::Utilities, LOCTEXT("ActionMenuCategory", "Va Rest")), this); + CachedCategory.SetCachedText(FEditorCategoryUtils::BuildCategoryString(FCommonEditorCategory::Utilities, LOCTEXT("ActionMenuCategory", "VaRest")), this); } return CachedCategory; } @@ -562,7 +560,6 @@ void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source) { FName Type; UObject* Subtype = nullptr; - FString FieldName = (*it).Name.ToString(); switch ((*it).Type) { @@ -586,7 +583,7 @@ void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source) UEdGraphNode::FCreatePinParams InputPinParams; InputPinParams.ContainerType = (*it).bIsArray ? EPinContainerType::Array : EPinContainerType::None; - UEdGraphPin* InputPin = CreatePin(EGPD_Input, Type, TEXT(""), Subtype, FName((*(*it).Name.ToString())), InputPinParams); + UEdGraphPin* InputPin = CreatePin(EGPD_Input, Type, TEXT(""), Subtype, (*it).Name, InputPinParams); #if ENGINE_MINOR_VERSION >= 20 InputPin->SetSavePinIfOrphaned(false); diff --git a/Source/VaRestEditor/Public/VaRest_BreakJson.h b/Source/VaRestEditor/Public/VaRest_BreakJson.h index dcdf51b5..68efe61f 100644 --- a/Source/VaRestEditor/Public/VaRest_BreakJson.h +++ b/Source/VaRestEditor/Public/VaRest_BreakJson.h @@ -27,10 +27,10 @@ enum class EVaRest_JsonType : uint8 USTRUCT(BlueprintType) struct FVaRest_NamedType { - GENERATED_USTRUCT_BODY(); + GENERATED_USTRUCT_BODY() UPROPERTY(EditAnywhere, Category = NamedType) - FText Name; + FName Name; UPROPERTY(EditAnywhere, Category = NamedType) EVaRest_JsonType Type; From e9e919d7e4b90b43df852496ba2eae3726153f55 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 8 Apr 2020 13:02:16 +0300 Subject: [PATCH 24/71] Fix CallURL crash --- Source/VaRest/Private/VaRestSubsystem.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 53e8f0bf..b5925ba3 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -30,9 +30,6 @@ void UVaRestSubsystem::Deinitialize() void UVaRestSubsystem::CallURL(const FString& URL, EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback) { - UWorld* World = GetWorld(); - check(World); - // Check we have valid data json if (VaRestJson == nullptr) { From 4cd86e6708a4097415d110b22be8641e5f35c84a Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 8 Apr 2020 13:38:08 +0300 Subject: [PATCH 25/71] Fix build compilation with blueprint nativization enabled. Close #293 --- Source/VaRest/Private/VaRestSubsystem.cpp | 7 +++++++ Source/VaRest/Public/VaRestSubsystem.h | 4 ++++ Source/VaRestEditor/Private/VaRest_BreakJson.cpp | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index b5925ba3..f4bb788f 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -9,6 +9,7 @@ #include "Developer/Settings/Public/ISettingsModule.h" #include "Misc/FileHelper.h" #include "Misc/Paths.h" +#include "Subsystems/SubsystemBlueprintLibrary.h" UVaRestSubsystem::UVaRestSubsystem() : UEngineSubsystem() @@ -91,6 +92,12 @@ UVaRestJsonObject* UVaRestSubsystem::ConstructVaRestJsonObject() return NewObject(this); } +UVaRestJsonObject* UVaRestSubsystem::StaticConstructVaRestJsonObject() +{ + auto SelfSystem = CastChecked(USubsystemBlueprintLibrary::GetEngineSubsystem(UVaRestSubsystem::StaticClass()), ECastCheckedType::NullChecked); + return SelfSystem->ConstructVaRestJsonObject(); +} + UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValueNumber(float Number) { TSharedPtr NewVal = MakeShareable(new FJsonValueNumber(Number)); diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 27265753..936c6e47 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -77,6 +77,10 @@ class VAREST_API UVaRestSubsystem : public UEngineSubsystem UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Object"), Category = "VaRest|Subsystem") UVaRestJsonObject* ConstructVaRestJsonObject(); + /** Create new Json object (static one for MakeJson node, hack for #293) */ + UFUNCTION() + static UVaRestJsonObject* StaticConstructVaRestJsonObject(); + /** Create new Json Number value * Attn.!! float used instead of double to make the function blueprintable! */ UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Number Value"), Category = "VaRest|Subsystem") diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index a4d44feb..2e97727d 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -339,7 +339,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor { UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestSubsystem'"))); - FName FunctionName = TEXT("ConstructVaRestJsonObject"); + FName FunctionName = TEXT("StaticConstructVaRestJsonObject"); UFunction* FunctionPtr = SubsystemClass->FindFunctionByName(FunctionName); FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); Statement.Type = KCST_CallFunction; From ad7c6fad4eccbef1ee768e731439c9b8705046ad Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 8 Apr 2020 13:41:56 +0300 Subject: [PATCH 26/71] Up version name --- VaRest.uplugin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VaRest.uplugin b/VaRest.uplugin index 25fbc2c0..9c53ac85 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -3,7 +3,7 @@ "FriendlyName" : "VaRest", "Version" : 29, - "VersionName" : "1.1-r29", + "VersionName" : "1.1-r29.2", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", "EngineVersion" : "4.24.0", From e6bf08be60abcae599bf4620e43c1edf123eceab Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Tue, 14 Apr 2020 12:45:29 +0300 Subject: [PATCH 27/71] PrettyPrint enabled now again. Close #295 --- Source/VaRest/Private/VaRestJsonObject.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 4d5d914d..0466789b 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -46,7 +46,7 @@ void UVaRestJsonObject::SetRootObject(const TSharedPtr& JsonObject) FString UVaRestJsonObject::EncodeJson() const { FString OutputString; - TSharedRef Writer = FCondensedJsonStringWriterFactory::Create(&OutputString); + auto Writer = TJsonWriterFactory<>::Create(&OutputString); FJsonSerializer::Serialize(JsonObj, Writer); return OutputString; @@ -54,13 +54,9 @@ FString UVaRestJsonObject::EncodeJson() const FString UVaRestJsonObject::EncodeJsonToSingleString() const { - FString OutputString = EncodeJson(); - - // Remove line terminators - OutputString.Replace(LINE_TERMINATOR, TEXT("")); - - // Remove tabs - OutputString.Replace(LINE_TERMINATOR, TEXT("\t")); + FString OutputString; + auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString); + FJsonSerializer::Serialize(JsonObj, Writer); return OutputString; } From 8409af94845ac205c58482cb52337e2b5f8c2c01 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 16 Apr 2020 16:46:57 +0300 Subject: [PATCH 28/71] Fix enum-related crash mentioned at #278 --- Config/BaseVaRest.ini | 9 +++++---- Config/DefaultVaRest.ini | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Config/BaseVaRest.ini b/Config/BaseVaRest.ini index 7659dd7d..0ad8fd95 100644 --- a/Config/BaseVaRest.ini +++ b/Config/BaseVaRest.ini @@ -9,9 +9,10 @@ +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") -+EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") -+EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") -+EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") ++EnumRedirects=(OldName="/Script/VaRest.ERequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") ++EnumRedirects=(OldName="/Script/VaRest.ERequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") ++EnumRedirects=(OldName="/Script/VaRest.ERequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") ++EnumRedirects=(OldName="/Script/VaRest.EHttpStatusCode",NewName="/Script/VaRest.EVaRestHttpStatusCode") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") +FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") @@ -20,4 +21,4 @@ +FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueBool",NewName="VaRestSubsystem.ConstructJsonValueBool") +FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueArray",NewName="VaRestSubsystem.ConstructJsonValueArray") +FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValueObject",NewName="VaRestSubsystem.ConstructJsonValueObject") -+FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValue",NewName="VaRestSubsystem.ConstructJsonValue") ++FunctionRedirects=(OldName="VaRestJsonValue.ConstructJsonValue",NewName="VaRestSubsystem.ConstructJsonValue") \ No newline at end of file diff --git a/Config/DefaultVaRest.ini b/Config/DefaultVaRest.ini index 8cc9aa52..0ad8fd95 100644 --- a/Config/DefaultVaRest.ini +++ b/Config/DefaultVaRest.ini @@ -9,10 +9,10 @@ +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") +EnumRedirects=(OldName="/Script/VaRestPlugin.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") -+EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") -+EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") -+EnumRedirects=(OldName="/Script/VaRest.EVaRestRequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") -+EnumRedirects=(OldName="/Script/VaRest.EVaRestHttpStatusCode",NewName="/Script/VaRest.EVaRestHttpStatusCode") ++EnumRedirects=(OldName="/Script/VaRest.ERequestVerb",NewName="/Script/VaRest.EVaRestRequestVerb") ++EnumRedirects=(OldName="/Script/VaRest.ERequestContentType",NewName="/Script/VaRest.EVaRestRequestContentType") ++EnumRedirects=(OldName="/Script/VaRest.ERequestStatus",NewName="/Script/VaRest.EVaRestRequestStatus") ++EnumRedirects=(OldName="/Script/VaRest.EHttpStatusCode",NewName="/Script/VaRest.EVaRestHttpStatusCode") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") +FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") +FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") From 9ec8c8565ef49d4865f859768a15ee8170264a02 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 22 Apr 2020 15:01:17 +0300 Subject: [PATCH 29/71] Fix BP frame stack caching related issue. Close #299 --- Source/VaRest/Private/VaRestLibrary.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index ab7efa81..4b3be13a 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -35,7 +35,8 @@ bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest) bool Success = FBase64::Decode(Source, ByteArray); FUTF8ToTCHAR StringSrc = FUTF8ToTCHAR((const ANSICHAR*)ByteArray.GetData(), ByteArray.Num()); - Dest.AppendChars(StringSrc.Get(), StringSrc.Length() + 1); + Dest = FString(); + Dest.AppendChars(StringSrc.Get(), StringSrc.Length()); return Success; } @@ -48,6 +49,7 @@ bool UVaRestLibrary::Base64EncodeData(const TArray& Data, FString& Dest) return true; } + Dest = FString(); return false; } From 77ab8a981b0cb53c2634e31e83910e2dc22b8bad Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Sun, 3 May 2020 13:28:17 -0400 Subject: [PATCH 30/71] Add version number to the init log --- Source/VaRest/Private/VaRest.cpp | 12 +++++++++++- Source/VaRest/Public/VaRest.h | 3 +++ Source/VaRest/VaRest.Build.cs | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 793b4986..1de6aee2 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -7,6 +7,8 @@ #include "Developer/Settings/Public/ISettingsModule.h" +#include "Interfaces/IPluginManager.h" + #define LOCTEXT_NAMESPACE "FVaRestModule" void FVaRestModule::StartupModule() @@ -23,7 +25,7 @@ void FVaRestModule::StartupModule() ModuleSettings); } - UE_LOG(LogVaRest, Log, TEXT("%s: VaRest module started"), *VA_FUNC_LINE); + UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *GetPluginVersion()); } void FVaRestModule::ShutdownModule() @@ -49,6 +51,14 @@ UVaRestSettings* FVaRestModule::GetSettings() const return ModuleSettings; } +FString FVaRestModule::GetPluginVersion() const +{ + IPluginManager& manager = IPluginManager::Get(); + TSharedPtr const plugin = manager.FindPlugin("VaRest"); + + return !plugin.IsValid() ? FString() : plugin->GetDescriptor().VersionName; +} + IMPLEMENT_MODULE(FVaRestModule, VaRest) DEFINE_LOG_CATEGORY(LogVaRest); diff --git a/Source/VaRest/Public/VaRest.h b/Source/VaRest/Public/VaRest.h index 86dade53..3b6959f5 100644 --- a/Source/VaRest/Public/VaRest.h +++ b/Source/VaRest/Public/VaRest.h @@ -37,6 +37,9 @@ class FVaRestModule : public IModuleInterface /** Getter for internal settings object to support runtime configuration changes */ UVaRestSettings* GetSettings() const; + /** Get the plugin version. */ + FString GetPluginVersion() const; + protected: /** Module settings */ UVaRestSettings* ModuleSettings; diff --git a/Source/VaRest/VaRest.Build.cs b/Source/VaRest/VaRest.Build.cs index 30d13a99..a6563463 100644 --- a/Source/VaRest/VaRest.Build.cs +++ b/Source/VaRest/VaRest.Build.cs @@ -23,7 +23,8 @@ public VaRest(ReadOnlyTargetRules Target) : base(Target) "CoreUObject", "Engine", "HTTP", - "Json" + "Json", + "Projects" // Required by IPluginManager etc (used to get plugin information) // ... add other public dependencies that you statically link with here ... }); } From e0c05ec4f1a06a72f7539904b415c9696838294b Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Sun, 3 May 2020 13:34:16 -0400 Subject: [PATCH 31/71] small fixes --- Source/VaRest/Private/VaRest.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 1de6aee2..d0188c04 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -53,10 +53,9 @@ UVaRestSettings* FVaRestModule::GetSettings() const FString FVaRestModule::GetPluginVersion() const { - IPluginManager& manager = IPluginManager::Get(); - TSharedPtr const plugin = manager.FindPlugin("VaRest"); + TSharedPtr const plugin = IPluginManager::Get().FindPlugin("VaRest"); - return !plugin.IsValid() ? FString() : plugin->GetDescriptor().VersionName; + return !plugin.IsValid() ? FString("Unable to get version number") : plugin->GetDescriptor().VersionName; } IMPLEMENT_MODULE(FVaRestModule, VaRest) From 8cf2494e469db5ff03a1729e6e80323d07e90126 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 7 May 2020 21:06:04 +0300 Subject: [PATCH 32/71] Up version to 1.1-r30 --- README.md | 2 +- VaRest.uplugin | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9618f361..5ecd0d6a 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 29** (UE 4.24) +Current version: **1.1 R 30** (UE 4.25) ![SCREENSHOT](SCREENSHOT.jpg) diff --git a/VaRest.uplugin b/VaRest.uplugin index c1e5dc3f..73fe1182 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -2,8 +2,8 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 29, - "VersionName" : "1.1-r29.2", + "Version" : 30, + "VersionName" : "1.1-r30", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", "EngineVersion" : "4.25.0", From b0f931070b6b7072a187608a04fd043850bf9853 Mon Sep 17 00:00:00 2001 From: Russ Treadwell Date: Sat, 9 May 2020 14:45:10 -0400 Subject: [PATCH 33/71] fixes requested by ufna --- Source/VaRest/Private/VaRest.cpp | 12 ++---------- Source/VaRest/Private/VaRestLibrary.cpp | 8 ++++++++ Source/VaRest/Public/VaRest.h | 3 --- Source/VaRest/Public/VaRestLibrary.h | 6 +++++- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index d0188c04..0c0e3351 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -3,12 +3,11 @@ #include "VaRest.h" #include "VaRestDefines.h" +#include "VaRestLibrary.h" #include "VaRestSettings.h" #include "Developer/Settings/Public/ISettingsModule.h" -#include "Interfaces/IPluginManager.h" - #define LOCTEXT_NAMESPACE "FVaRestModule" void FVaRestModule::StartupModule() @@ -25,7 +24,7 @@ void FVaRestModule::StartupModule() ModuleSettings); } - UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *GetPluginVersion()); + UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetPluginVersion()); } void FVaRestModule::ShutdownModule() @@ -51,13 +50,6 @@ UVaRestSettings* FVaRestModule::GetSettings() const return ModuleSettings; } -FString FVaRestModule::GetPluginVersion() const -{ - TSharedPtr const plugin = IPluginManager::Get().FindPlugin("VaRest"); - - return !plugin.IsValid() ? FString("Unable to get version number") : plugin->GetDescriptor().VersionName; -} - IMPLEMENT_MODULE(FVaRestModule, VaRest) DEFINE_LOG_CATEGORY(LogVaRest); diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index 4b3be13a..c8bfe4ce 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -8,6 +8,7 @@ #include "VaRestRequestJSON.h" #include "VaRestSettings.h" +#include "Interfaces/IPluginManager.h" #include "Misc/Base64.h" UVaRestSettings* UVaRestLibrary::GetVaRestSettings() @@ -78,3 +79,10 @@ FString UVaRestLibrary::StringToSha1(const FString& StringToHash) return Sha1String; } + +FString UVaRestLibrary::GetPluginVersion() +{ + TSharedPtr const Plugin = IPluginManager::Get().FindPlugin("VaRest"); + + return !Plugin.IsValid() ? FString("Unable to get version number") : Plugin->GetDescriptor().VersionName; +} diff --git a/Source/VaRest/Public/VaRest.h b/Source/VaRest/Public/VaRest.h index 3b6959f5..86dade53 100644 --- a/Source/VaRest/Public/VaRest.h +++ b/Source/VaRest/Public/VaRest.h @@ -37,9 +37,6 @@ class FVaRestModule : public IModuleInterface /** Getter for internal settings object to support runtime configuration changes */ UVaRestSettings* GetSettings() const; - /** Get the plugin version. */ - FString GetPluginVersion() const; - protected: /** Module settings */ UVaRestSettings* ModuleSettings; diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 722a890e..e492217b 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -74,7 +74,7 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary /** * Helper to perform the very common case of hashing an ASCII string into a hex representation. - * + * * @param String Hex representation of the hash (32 lower-case hex digits) */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to MD5")) @@ -91,4 +91,8 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "HTTP Status Int To Enum")) static FORCEINLINE EVaRestHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EVaRestHttpStatusCode::Type)StatusCode; } + + /** Get the plugin's version. */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) + static FString GetPluginVersion(); }; From 7079ff4c12ed8731b0ca70121aa20c51e1872db2 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sat, 9 May 2020 21:53:20 +0300 Subject: [PATCH 34/71] Slightly rename functions to avoid possible issues with android linkage --- Source/VaRest/Private/VaRest.cpp | 2 +- Source/VaRest/Private/VaRestLibrary.cpp | 6 +++--- Source/VaRest/Public/VaRestLibrary.h | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 0c0e3351..1c505cda 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -24,7 +24,7 @@ void FVaRestModule::StartupModule() ModuleSettings); } - UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetPluginVersion()); + UE_LOG(LogVaRest, Log, TEXT("%s: VaRest (%s) module started"), *VA_FUNC_LINE, *UVaRestLibrary::GetVaRestVersion()); } void FVaRestModule::ShutdownModule() diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index c8bfe4ce..7f72c78c 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -80,9 +80,9 @@ FString UVaRestLibrary::StringToSha1(const FString& StringToHash) return Sha1String; } -FString UVaRestLibrary::GetPluginVersion() +FString UVaRestLibrary::GetVaRestVersion() { - TSharedPtr const Plugin = IPluginManager::Get().FindPlugin("VaRest"); + const auto PluginRef = IPluginManager::Get().FindPlugin("VaRest"); - return !Plugin.IsValid() ? FString("Unable to get version number") : Plugin->GetDescriptor().VersionName; + return !PluginRef.IsValid() ? FString("invalid") : PluginRef->GetDescriptor().VersionName; } diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index e492217b..e1538e31 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -92,7 +92,9 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "HTTP Status Int To Enum")) static FORCEINLINE EVaRestHttpStatusCode::Type HTTPStatusIntToEnum(int32 StatusCode) { return (EVaRestHttpStatusCode::Type)StatusCode; } - /** Get the plugin's version. */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) - static FString GetPluginVersion(); + /** + * Get the plugin's version + */ + UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) + static FString GetVaRestVersion(); }; From 8f760b9b5c817ead60bfabaa11e65df6329f8e0c Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 24 Sep 2020 22:21:48 +0300 Subject: [PATCH 35/71] Add GetWorldURL helper --- Source/VaRest/Private/VaRestLibrary.cpp | 13 ++++++ Source/VaRest/Public/VaRestLibrary.h | 10 ++++ Source/VaRest/Public/VaRestTypes.h | 62 +++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index 7f72c78c..5847e2f1 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -86,3 +86,16 @@ FString UVaRestLibrary::GetVaRestVersion() return !PluginRef.IsValid() ? FString("invalid") : PluginRef->GetDescriptor().VersionName; } + +FVaRestURL UVaRestLibrary::GetWorldURL(UObject* WorldContextObject) +{ + if (WorldContextObject) + { + if (UWorld* World = WorldContextObject->GetWorld()) + { + return FVaRestURL(World->URL); + } + } + + return FVaRestURL(); +} diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index e1538e31..52ea9ffb 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -97,4 +97,14 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version")) static FString GetVaRestVersion(); + + ////////////////////////////////////////////////////////////////////////// + // Common Network Helpers + +public: + /** + * Get the URL that was used when loading this World + */ + UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject")) + static FVaRestURL GetWorldURL(UObject* WorldContextObject); }; diff --git a/Source/VaRest/Public/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h index 1a5c0d7e..8a3388cc 100644 --- a/Source/VaRest/Public/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -2,6 +2,10 @@ #pragma once +#include "Engine/EngineBaseTypes.h" + +#include "VaRestTypes.generated.h" + /** Verb (GET, PUT, POST) used by the request */ UENUM(BlueprintType) enum class EVaRestRequestVerb : uint8 @@ -135,3 +139,61 @@ enum Type VersionNotSup = 505 UMETA(DisplayName = "VersionNotSup = 505") }; } // namespace EVaRestHttpStatusCode + +/** + * FURL structure wrapper for BP access + */ +USTRUCT(BlueprintType) +struct VAREST_API FVaRestURL +{ + GENERATED_BODY() + + /** Protocol, i.e. "unreal" or "http" */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Protocol; + + /** Optional hostname, i.e. "204.157.115.40" or "unreal.epicgames.com", blank if local. */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Host; + + /** Optional host port */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + int32 Port; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + int32 Valid; + + /** Map name, i.e. "SkyCity", default is "Entry" */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Map; + + /** Optional place to download Map if client does not possess it */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString RedirectURL; + + /** Options */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + TArray Op; + + /** Portal to enter through, default is "" */ + UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + FString Portal; + + FVaRestURL() + : Port(0) + , Valid(0) + { + } + + FVaRestURL(FURL& InUrl) + : Protocol(InUrl.Protocol) + , Host(InUrl.Host) + , Port(InUrl.Port) + , Valid(InUrl.Valid) + , Map(InUrl.Map) + , RedirectURL(InUrl.RedirectURL) + , Op(InUrl.Op) + , Portal(InUrl.Portal) + { + } +}; From ce2195ed7c21b87f5d72df10a2aa21a8f5fbff27 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Sep 2020 12:33:18 +0300 Subject: [PATCH 36/71] Update classes to support UE 4.26 --- Source/VaRest/Public/VaRestRequestJSON.h | 4 ++-- VaRest.uplugin | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index 57b090b7..06c06553 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -313,9 +313,9 @@ class VAREST_API UVaRestRequestJSON : public UObject FString CustomVerb; /** Request we're currently processing */ - TSharedRef HttpRequest = FHttpModule::Get().CreateRequest(); + TSharedRef HttpRequest = FHttpModule::Get().CreateRequest(); public: /** Returns reference to internal request object */ - TSharedRef GetHttpRequest() const { return HttpRequest; }; + TSharedRef GetHttpRequest() const { return HttpRequest; }; }; diff --git a/VaRest.uplugin b/VaRest.uplugin index 73fe1182..e18a41a4 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -6,7 +6,7 @@ "VersionName" : "1.1-r30", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", - "EngineVersion" : "4.25.0", + "EngineVersion" : "4.26.0", "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", "DocsURL": "https://bit.ly/VaRest-Docs", From bb4f16eebcc6abe0ded531c05779c054b7f83815 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Tue, 29 Sep 2020 15:52:58 +0300 Subject: [PATCH 37/71] Add category for vars to fix packaging --- Source/VaRest/Public/VaRestTypes.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/VaRest/Public/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h index 8a3388cc..fbbf94ae 100644 --- a/Source/VaRest/Public/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -149,34 +149,34 @@ struct VAREST_API FVaRestURL GENERATED_BODY() /** Protocol, i.e. "unreal" or "http" */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Protocol; /** Optional hostname, i.e. "204.157.115.40" or "unreal.epicgames.com", blank if local. */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Host; /** Optional host port */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") int32 Port; - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") int32 Valid; /** Map name, i.e. "SkyCity", default is "Entry" */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Map; /** Optional place to download Map if client does not possess it */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString RedirectURL; /** Options */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") TArray Op; /** Portal to enter through, default is "" */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly) + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "URL") FString Portal; FVaRestURL() From 71b99c7aa86850e8a634f19bbb468b2692020640 Mon Sep 17 00:00:00 2001 From: Mirek Kaspar Date: Wed, 30 Sep 2020 10:52:18 +0200 Subject: [PATCH 38/71] Update VaRestLibrary.h Added category to the GetWorldURL node --- Source/VaRest/Public/VaRestLibrary.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index 52ea9ffb..baabcb40 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -105,6 +105,6 @@ class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary /** * Get the URL that was used when loading this World */ - UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject")) + UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (WorldContext = "WorldContextObject")) static FVaRestURL GetWorldURL(UObject* WorldContextObject); }; From 40f509d66fbfa927278325c87eab98dd4ba78d35 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 4 Dec 2020 22:20:16 +0300 Subject: [PATCH 39/71] Up plugin version --- README.md | 2 +- VaRest.uplugin | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ecd0d6a..c9199cf7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 30** (UE 4.25) +Current version: **1.1 R 31** (UE 4.26) ![SCREENSHOT](SCREENSHOT.jpg) diff --git a/VaRest.uplugin b/VaRest.uplugin index e18a41a4..710b23c5 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -2,8 +2,8 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 30, - "VersionName" : "1.1-r30", + "Version" : 31, + "VersionName" : "1.1-r31", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://alyamkin.com", "EngineVersion" : "4.26.0", From 3dd9c4d9d2caf68130d544a3fd5d4df37a1bdcc6 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sun, 20 Dec 2020 01:57:17 +0300 Subject: [PATCH 40/71] Fix headers --- Source/VaRest/Private/VaRest.cpp | 1 + Source/VaRest/Private/VaRestJsonParser.cpp | 1 - Source/VaRest/Private/VaRestLibrary.cpp | 4 ++-- Source/VaRest/Private/VaRestRequestJSON.cpp | 6 ++++-- Source/VaRest/Private/VaRestSubsystem.cpp | 1 - Source/VaRest/Public/VaRestDefines.h | 6 ------ Source/VaRest/Public/VaRestJsonValue.h | 2 -- Source/VaRest/Public/VaRestLibrary.h | 1 - Source/VaRest/Public/VaRestSubsystem.h | 2 -- Source/VaRestEditor/Private/VaRestEditor.cpp | 2 ++ Source/VaRestEditor/Public/VaRestEditor.h | 2 +- 11 files changed, 10 insertions(+), 18 deletions(-) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp index 1c505cda..f4829540 100644 --- a/Source/VaRest/Private/VaRest.cpp +++ b/Source/VaRest/Private/VaRest.cpp @@ -7,6 +7,7 @@ #include "VaRestSettings.h" #include "Developer/Settings/Public/ISettingsModule.h" +#include "UObject/Package.h" #define LOCTEXT_NAMESPACE "FVaRestModule" diff --git a/Source/VaRest/Private/VaRestJsonParser.cpp b/Source/VaRest/Private/VaRestJsonParser.cpp index ee629434..d7b6ba46 100644 --- a/Source/VaRest/Private/VaRestJsonParser.cpp +++ b/Source/VaRest/Private/VaRestJsonParser.cpp @@ -6,7 +6,6 @@ #include "Dom/JsonObject.h" #include "Dom/JsonValue.h" -#include "Logging/LogMacros.h" uint32 FUtf8Helper::CodepointFromUtf8(const ANSICHAR*& SourceString, const uint32 SourceLengthRemaining) { diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index 5847e2f1..df53acd2 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -4,10 +4,10 @@ #include "VaRest.h" #include "VaRestDefines.h" -#include "VaRestJsonObject.h" #include "VaRestRequestJSON.h" -#include "VaRestSettings.h" +#include "Engine/World.h" +#include "GenericPlatform/GenericPlatformHttp.h" #include "Interfaces/IPluginManager.h" #include "Misc/Base64.h" diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 5089fa5f..5b1eb6a3 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -7,9 +7,11 @@ #include "VaRestLibrary.h" #include "VaRestSettings.h" +#include "Engine/Engine.h" +#include "Engine/EngineTypes.h" +#include "Engine/LatentActionManager.h" +#include "Engine/World.h" #include "Json.h" -#include "Kismet/GameplayStatics.h" -#include "Misc/CoreMisc.h" #include "Runtime/Launch/Resources/Version.h" FString UVaRestRequestJSON::DeprecatedResponseString(TEXT("DEPRECATED: Please use GetResponseContentAsString() instead")); diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index f4bb788f..5aba7f7a 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -6,7 +6,6 @@ #include "VaRestJsonObject.h" #include "VaRestJsonValue.h" -#include "Developer/Settings/Public/ISettingsModule.h" #include "Misc/FileHelper.h" #include "Misc/Paths.h" #include "Subsystems/SubsystemBlueprintLibrary.h" diff --git a/Source/VaRest/Public/VaRestDefines.h b/Source/VaRest/Public/VaRestDefines.h index 6e2c698d..d0e0e1f2 100644 --- a/Source/VaRest/Public/VaRestDefines.h +++ b/Source/VaRest/Public/VaRestDefines.h @@ -6,23 +6,17 @@ #if ENGINE_MINOR_VERSION >= 15 #include "CoreMinimal.h" -#include "Engine/Engine.h" -#include "EngineDefines.h" -#include "UObject/Object.h" -#include "UObject/ScriptMacros.h" #else #include "CoreUObject.h" #include "Engine.h" #endif -#include "Delegates/DelegateCombinations.h" #include "Logging/LogCategory.h" #include "Logging/LogMacros.h" #include "Logging/LogVerbosity.h" // You should place include statements to your module's private header files here. You only need to // add includes for headers that are used in most of your module's source files though. -#include "Modules/ModuleManager.h" DECLARE_LOG_CATEGORY_EXTERN(LogVaRest, Log, All); diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index ef622b0b..9975a7bf 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -2,8 +2,6 @@ #pragma once -#include "VaRestDefines.h" - #include "VaRestJsonValue.generated.h" class UVaRestJsonObject; diff --git a/Source/VaRest/Public/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h index baabcb40..11977073 100644 --- a/Source/VaRest/Public/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -4,7 +4,6 @@ #include "Kismet/BlueprintFunctionLibrary.h" -#include "VaRestDefines.h" #include "VaRestTypes.h" #include "VaRestLibrary.generated.h" diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 936c6e47..f4547975 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -5,9 +5,7 @@ #include "VaRestJsonValue.h" #include "VaRestRequestJSON.h" -#include "Delegates/DelegateCombinations.h" #include "Subsystems/EngineSubsystem.h" -#include "Subsystems/SubsystemCollection.h" #include "VaRestSubsystem.generated.h" diff --git a/Source/VaRestEditor/Private/VaRestEditor.cpp b/Source/VaRestEditor/Private/VaRestEditor.cpp index 82d0973e..c3bb7d07 100644 --- a/Source/VaRestEditor/Private/VaRestEditor.cpp +++ b/Source/VaRestEditor/Private/VaRestEditor.cpp @@ -2,6 +2,8 @@ #include "VaRestEditor.h" +#include "Modules/ModuleManager.h" + #define LOCTEXT_NAMESPACE "FVaRestEditorModule" void FVaRestEditorModule::StartupModule() diff --git a/Source/VaRestEditor/Public/VaRestEditor.h b/Source/VaRestEditor/Public/VaRestEditor.h index a51c92c9..a5e0a8ae 100644 --- a/Source/VaRestEditor/Public/VaRestEditor.h +++ b/Source/VaRestEditor/Public/VaRestEditor.h @@ -2,7 +2,7 @@ #pragma once -#include "Modules/ModuleManager.h" +#include "Modules/ModuleInterface.h" class FVaRestEditorModule : public IModuleInterface { From ca39db6d1c2880223f58d9a3cfe388c04699ce4f Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 4 Jan 2021 01:04:27 +0300 Subject: [PATCH 41/71] Minor code fixes --- Source/VaRest/Private/VaRestJsonObject.cpp | 36 ++++++++++----------- Source/VaRest/Private/VaRestRequestJSON.cpp | 1 + Source/VaRest/Public/VaRestJsonObject.h | 2 +- Source/VaRest/Public/VaRestRequestJSON.h | 3 ++ 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 0466789b..11c3f249 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -46,7 +46,7 @@ void UVaRestJsonObject::SetRootObject(const TSharedPtr& JsonObject) FString UVaRestJsonObject::EncodeJson() const { FString OutputString; - auto Writer = TJsonWriterFactory<>::Create(&OutputString); + const auto Writer = TJsonWriterFactory<>::Create(&OutputString); FJsonSerializer::Serialize(JsonObj, Writer); return OutputString; @@ -55,7 +55,7 @@ FString UVaRestJsonObject::EncodeJson() const FString UVaRestJsonObject::EncodeJsonToSingleString() const { FString OutputString; - auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString); + const auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString); FJsonSerializer::Serialize(JsonObj, Writer); return OutputString; @@ -65,7 +65,7 @@ bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrement { if (bUseIncrementalParser) { - int32 BytesRead = DeserializeFromTCHARBytes(JsonString.GetCharArray().GetData(), JsonString.Len()); + const int32 BytesRead = DeserializeFromTCHARBytes(JsonString.GetCharArray().GetData(), JsonString.Len()); // JsonObj is always valid, but read bytes is zero when something went wrong if (BytesRead > 0) @@ -75,7 +75,7 @@ bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrement } else { - TSharedRef> Reader = TJsonReaderFactory<>::Create(*JsonString); + const TSharedRef> Reader = TJsonReaderFactory<>::Create(*JsonString); TSharedPtr OutJsonObj; if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) { @@ -277,7 +277,7 @@ void UVaRestJsonObject::SetArrayField(const FString& FieldName, const TArray JsonVal = InVal->GetRootValue(); + const TSharedPtr JsonVal = InVal->GetRootValue(); switch (InVal->GetType()) { @@ -344,7 +344,7 @@ UVaRestJsonObject* UVaRestJsonObject::GetObjectField(const FString& FieldName) c return nullptr; } - TSharedPtr JsonObjField = JsonObj->GetObjectField(FieldName); + const TSharedPtr JsonObjField = JsonObj->GetObjectField(FieldName); UVaRestJsonObject* OutRestJsonObj = NewObject(); OutRestJsonObj->SetRootObject(JsonObjField); @@ -402,10 +402,10 @@ TArray UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) c return NumberArray; } - TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); + const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) { - auto Value = (*It).Get(); + const auto Value = (*It).Get(); if (Value->Type != EJson::Number) { UE_LOG(LogVaRest, Error, TEXT("Not Number element in array with field name %s"), *FieldName); @@ -443,10 +443,10 @@ TArray UVaRestJsonObject::GetStringArrayField(const FString& FieldName) return StringArray; } - TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); + const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) { - auto Value = (*It).Get(); + const auto Value = (*It).Get(); if (Value->Type != EJson::String) { UE_LOG(LogVaRest, Error, TEXT("Not String element in array with field name %s"), *FieldName); @@ -483,10 +483,10 @@ TArray UVaRestJsonObject::GetBoolArrayField(const FString& FieldName) cons return BoolArray; } - TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); + const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) { - auto Value = (*It).Get(); + const auto Value = (*It).Get(); if (Value->Type != EJson::Boolean) { UE_LOG(LogVaRest, Error, TEXT("Not Boolean element in array with field name %s"), *FieldName); @@ -524,7 +524,7 @@ TArray UVaRestJsonObject::GetObjectArrayField(const FString& } TArray> ValArray = JsonObj->GetArrayField(FieldName); - for (auto Value : ValArray) + for (const auto Value : ValArray) { if (Value->Type != EJson::Object) { @@ -643,11 +643,11 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr& Reader) if (bIsIntelByteOrder) { - Char = CharCast((UCS2CHAR)((uint16)SymbolBytes[0] + (uint16)SymbolBytes[1] * 256)); + Char = CharCast(static_cast(static_cast(SymbolBytes[0]) + static_cast(SymbolBytes[1]) * 256)); } else { - Char = CharCast((UCS2CHAR)((uint16)SymbolBytes[1] + (uint16)SymbolBytes[0] * 256)); + Char = CharCast(static_cast(static_cast(SymbolBytes[1]) + static_cast(SymbolBytes[0]) * 256)); } if (!JsonReader.Read(Char)) @@ -667,7 +667,7 @@ void UVaRestJsonObject::DecodeFromArchive(TUniquePtr& Reader) ////////////////////////////////////////////////////////////////////////// // Serialize -bool UVaRestJsonObject::WriteToFile(const FString& Path) +bool UVaRestJsonObject::WriteToFile(const FString& Path) const { TUniquePtr FileWriter(IFileManager::Get().CreateFileWriter(*Path)); if (!FileWriter) @@ -723,8 +723,8 @@ bool UVaRestJsonObject::WriteToFilePath(const FString& Path, const bool bIsRelat bool UVaRestJsonObject::WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len) { - auto Src = StringCast(StrPtr, Len); - Ar.Serialize((UCS2CHAR*)Src.Get(), Src.Length() * sizeof(UCS2CHAR)); + const auto Src = StringCast(StrPtr, Len); + Ar.Serialize(const_cast(Src.Get()), Src.Length() * sizeof(UCS2CHAR)); return true; } diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 5b1eb6a3..534f4836 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -11,6 +11,7 @@ #include "Engine/EngineTypes.h" #include "Engine/LatentActionManager.h" #include "Engine/World.h" +#include "Interfaces/IHttpResponse.h" #include "Json.h" #include "Runtime/Launch/Resources/Version.h" diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 4872f064..499fd779 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -218,7 +218,7 @@ class VAREST_API UVaRestJsonObject : public UObject public: /** Save json to file */ - bool WriteToFile(const FString& Path); + bool WriteToFile(const FString& Path) const; /** * Blueprint Save json to filepath diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index 06c06553..d74da2b3 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -4,12 +4,15 @@ #include "Engine/LatentActionManager.h" #include "Http.h" +#include "HttpModule.h" +#include "Interfaces/IHttpRequest.h" #include "LatentActions.h" #include "VaRestTypes.h" #include "VaRestRequestJSON.generated.h" +class UVaRestJsonObject; class UVaRestSettings; /** From b12efd01c617e431ec6417db534706a181a213dd Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 4 Jan 2021 01:54:10 +0300 Subject: [PATCH 42/71] In const we trust --- Source/VaRest/Private/VaRestJsonObject.cpp | 2 +- Source/VaRest/Private/VaRestJsonParser.cpp | 26 +++++++++---------- Source/VaRest/Private/VaRestJsonValue.cpp | 2 +- Source/VaRest/Private/VaRestLibrary.cpp | 6 ++--- Source/VaRest/Private/VaRestRequestJSON.cpp | 2 +- Source/VaRest/Private/VaRestSubsystem.cpp | 2 +- .../VaRestEditor/Private/VaRest_BreakJson.cpp | 10 +++---- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 11c3f249..86bb28a4 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -524,7 +524,7 @@ TArray UVaRestJsonObject::GetObjectArrayField(const FString& } TArray> ValArray = JsonObj->GetArrayField(FieldName); - for (const auto Value : ValArray) + for (const auto& Value : ValArray) { if (Value->Type != EJson::Object) { diff --git a/Source/VaRest/Private/VaRestJsonParser.cpp b/Source/VaRest/Private/VaRestJsonParser.cpp index d7b6ba46..5a7a6ded 100644 --- a/Source/VaRest/Private/VaRestJsonParser.cpp +++ b/Source/VaRest/Private/VaRestJsonParser.cpp @@ -293,7 +293,7 @@ void FJSONState::PopObject() { if (Objects.Num() > 0) { - auto Object = Objects.Pop(false); + const auto Object = Objects.Pop(false); if (Object->Type == EJson::Object) { return; @@ -307,7 +307,7 @@ void FJSONState::PopArray() { if (Objects.Num() > 0) { - auto Object = Objects.Pop(false); + const auto Object = Objects.Pop(false); if (Object->Type == EJson::Array) { return; @@ -321,7 +321,7 @@ void FJSONState::PopValue(bool bCheckType) { if (Objects.Num() > 0) { - auto Value = Objects.Last(0); + const auto Value = Objects.Last(0); if (Value->Type == EJson::Object || Value->Type == EJson::Array) { if (bCheckType) @@ -338,7 +338,7 @@ void FJSONState::PopValue(bool bCheckType) { case EJson::Null: { - auto LowerCase = Data.ToLower(); + const auto LowerCase = Data.ToLower(); if (LowerCase != TEXT("null")) { bError = true; @@ -355,7 +355,7 @@ void FJSONState::PopValue(bool bCheckType) } case EJson::Number: { - FString LowerCase = Data.ToLower(); + const FString LowerCase = Data.ToLower(); int32 ePosition = INDEX_NONE; LowerCase.FindChar('e', ePosition); if (ePosition == INDEX_NONE) @@ -371,8 +371,8 @@ void FJSONState::PopValue(bool bCheckType) } else if (LowerCase.Len() > ePosition + 2) { - FString Left = LowerCase.Left(ePosition); - FString Rigth = LowerCase.Right(LowerCase.Len() - ePosition - 1); + const FString Left = LowerCase.Left(ePosition); + const FString Rigth = LowerCase.Right(LowerCase.Len() - ePosition - 1); if (Left.IsNumeric() && Rigth.IsNumeric()) { ((FJsonValueNonConstNumber*)Value.Get())->AsNonConstNumber() = FCString::Atod(*Left) * FMath::Pow(10.f, FCString::Atoi(*Rigth)); @@ -390,7 +390,7 @@ void FJSONState::PopValue(bool bCheckType) } case EJson::Boolean: { - auto LowerCase = Data.ToLower(); + const auto LowerCase = Data.ToLower(); if (LowerCase == TEXT("true")) { ((FJsonValueNonConstBoolean*)Value.Get())->AsNonConstBool() = true; @@ -414,7 +414,7 @@ void FJSONState::PopValue(bool bCheckType) ClearData(); - auto Container = Objects.Last(0); + const auto Container = Objects.Last(0); if (Container->Type == EJson::Object) { if (Key.Len() > 0) @@ -501,7 +501,7 @@ TSharedPtr FJSONState::PushObject(TSharedPtr Obje TSharedPtr FJSONState::PushArray() { - TArray> Empty; + const TArray> Empty; TSharedPtr Result(new FJsonValueNonConstArray(Empty)); Objects.Add(Result); Size += sizeof(TSharedPtr) + sizeof(FJsonValueNonConstArray); @@ -626,7 +626,7 @@ void FJSONReader::UpdateNotation() if (State.Key.Len() > 0) { State.Notation = EJSONNotation::OBJECT; - auto Value = State.GetObject(); + const auto Value = State.GetObject(); if (Value != nullptr) { Value->AsObject()->SetField(State.Key, State.PushObject()); @@ -708,7 +708,7 @@ void FJSONReader::UpdateNotation() State.Notation = EJSONNotation::ARRAY; if (State.Key.Len() > 0) { - auto Value = State.GetObject(); + const auto Value = State.GetObject(); if (Value != nullptr) { Value->AsObject()->SetField(State.Key, State.PushArray()); @@ -1099,7 +1099,7 @@ void FJSONWriter::Write(TSharedPtr JsonValue, FArchive* Writer, bool } default: { - FString Value = JsonValue->AsString(); + const FString Value = JsonValue->AsString(); const TCHAR* BufferPtr = *Value; for (int i = 0; i < Value.Len(); ++i) diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index 8b45a107..74018ded 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -166,7 +166,7 @@ UVaRestJsonObject* UVaRestJsonValue::AsObject() return nullptr; } - TSharedPtr NewObj = JsonVal->AsObject(); + const TSharedPtr NewObj = JsonVal->AsObject(); UVaRestJsonObject* JsonObj = NewObject(); JsonObj->SetRootObject(NewObj); diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp index df53acd2..9c6f16f8 100644 --- a/Source/VaRest/Private/VaRestLibrary.cpp +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -24,7 +24,7 @@ FString UVaRestLibrary::PercentEncode(const FString& Source) FString UVaRestLibrary::Base64Encode(const FString& Source) { TArray ByteArray; - FTCHARToUTF8 StringSrc = FTCHARToUTF8(Source.GetCharArray().GetData()); + const FTCHARToUTF8 StringSrc = FTCHARToUTF8(Source.GetCharArray().GetData()); ByteArray.Append((uint8*)StringSrc.Get(), StringSrc.Length()); return FBase64::Encode(ByteArray); @@ -33,9 +33,9 @@ FString UVaRestLibrary::Base64Encode(const FString& Source) bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest) { TArray ByteArray; - bool Success = FBase64::Decode(Source, ByteArray); + const bool Success = FBase64::Decode(Source, ByteArray); - FUTF8ToTCHAR StringSrc = FUTF8ToTCHAR((const ANSICHAR*)ByteArray.GetData(), ByteArray.Num()); + const FUTF8ToTCHAR StringSrc = FUTF8ToTCHAR((const ANSICHAR*)ByteArray.GetData(), ByteArray.Num()); Dest = FString(); Dest.AppendChars(StringSrc.Get(), StringSrc.Length()); diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 534f4836..bf0e303d 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -499,7 +499,7 @@ void UVaRestRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttp else { // Use default unreal one - TSharedRef> Reader = TJsonReaderFactory<>::Create(*Response->GetContentAsString()); + const TSharedRef> Reader = TJsonReaderFactory<>::Create(*Response->GetContentAsString()); TSharedPtr OutJsonObj; if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) { diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 5aba7f7a..8527b8dd 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -62,7 +62,7 @@ void UVaRestSubsystem::OnCallComplete(UVaRestRequestJSON* Request) return; } - auto Response = RequestMap.Find(Request); + const auto Response = RequestMap.Find(Request); Request->OnStaticRequestComplete.Remove(Response->CompleteDelegateHandle); Request->OnStaticRequestFail.Remove(Response->FailDelegateHandle); diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index 2e97727d..9ac7c144 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -86,7 +86,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); FName FunctionName; - bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; + const bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; if (FieldType == CompilerContext.GetSchema()->PC_Boolean) { FunctionName = bIsArray ? TEXT("GetBoolArrayField") : TEXT("GetBoolField"); @@ -213,7 +213,7 @@ FLinearColor UVaRest_BreakJson::GetNodeTitleColor() const void UVaRest_BreakJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_BreakJson, Outputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || @@ -339,7 +339,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor { UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestSubsystem'"))); - FName FunctionName = TEXT("StaticConstructVaRestJsonObject"); + const FName FunctionName = TEXT("StaticConstructVaRestJsonObject"); UFunction* FunctionPtr = SubsystemClass->FindFunctionByName(FunctionName); FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); Statement.Type = KCST_CallFunction; @@ -388,7 +388,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); FName FunctionName; - bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; + const bool bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array; if (FieldType == CompilerContext.GetSchema()->PC_Boolean) { FunctionName = bIsArray ? TEXT("SetBoolArrayField") : TEXT("SetBoolField"); @@ -505,7 +505,7 @@ FLinearColor UVaRest_MakeJson::GetNodeTitleColor() const void UVaRest_MakeJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_MakeJson, Inputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || From 61b909b47af5b6ba2e1424406c372061ee894155 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 4 Jan 2021 02:13:27 +0300 Subject: [PATCH 43/71] Use nullptr instead of NULL --- .../VaRestEditor/Private/VaRest_BreakJson.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index 9ac7c144..7e8fc586 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -26,7 +26,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor virtual void Compile(FKismetFunctionContext& Context, UEdGraphNode* Node) override { - UEdGraphPin* InputPin = NULL; + UEdGraphPin* InputPin = nullptr; for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { @@ -39,7 +39,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor } UEdGraphPin* InNet = FEdGraphUtilities::GetNetFromPin(InputPin); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); FBPTerminal** SourceTerm = Context.NetMap.Find(InNet); if (SourceTerm == nullptr) @@ -122,7 +122,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor FBPTerminal* RegisterInputTerm(FKismetFunctionContext& Context, UVaRest_BreakJson* Node) { // Find input pin - UEdGraphPin* InputPin = NULL; + UEdGraphPin* InputPin = nullptr; for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { UEdGraphPin* Pin = Node->Pins[PinIndex]; @@ -168,7 +168,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { UEdGraphPin* Pin = Node->Pins[PinIndex]; - if (NULL != Pin && EGPD_Output == Pin->Direction) + if (nullptr != Pin && EGPD_Output == Pin->Direction) { RegisterOutputTerm(Context, Pin, StructContextTerm); } @@ -194,7 +194,7 @@ void UVaRest_BreakJson::AllocateDefaultPins() { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Input, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); #if ENGINE_MINOR_VERSION >= 17 @@ -213,7 +213,7 @@ FLinearColor UVaRest_BreakJson::GetNodeTitleColor() const void UVaRest_BreakJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_BreakJson, Outputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || @@ -262,7 +262,7 @@ FText UVaRest_BreakJson::GetMenuCategory() const void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); for (TArray::TIterator it(Outputs); it; ++it) { @@ -316,7 +316,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor virtual void Compile(FKismetFunctionContext& Context, UEdGraphNode* Node) override { - UEdGraphPin* OutputPin = NULL; + UEdGraphPin* OutputPin = nullptr; for (int32 PinIndex = 0; PinIndex < Node->Pins.Num(); ++PinIndex) { @@ -328,7 +328,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor } } - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); FBPTerminal** TargetTerm = Context.NetMap.Find(OutputPin); if (TargetTerm == nullptr) @@ -337,7 +337,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor } { - UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestSubsystem'"))); + UClass* SubsystemClass = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestSubsystem'"))); const FName FunctionName = TEXT("StaticConstructVaRestJsonObject"); UFunction* FunctionPtr = SubsystemClass->FindFunctionByName(FunctionName); @@ -486,7 +486,7 @@ void UVaRest_MakeJson::AllocateDefaultPins() { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Output, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); #if ENGINE_MINOR_VERSION >= 17 @@ -505,7 +505,7 @@ FLinearColor UVaRest_MakeJson::GetNodeTitleColor() const void UVaRest_MakeJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - const FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; + const FName PropertyName = (PropertyChangedEvent.Property != nullptr) ? PropertyChangedEvent.Property->GetFName() : NAME_None; if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_MakeJson, Inputs) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || @@ -554,7 +554,7 @@ FText UVaRest_MakeJson::GetMenuCategory() const void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source) { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); for (TArray::TIterator it(Inputs); it; ++it) { From df1ce54ede357aca506b273908409579858ab410 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 01:20:17 +0300 Subject: [PATCH 44/71] Int64 support --- Source/VaRest/Private/VaRestJsonObject.cpp | 21 +++++++++++++++++++ Source/VaRest/Private/VaRestJsonValue.cpp | 24 +++++++++++++++++++++- Source/VaRest/Public/VaRestJsonObject.h | 8 ++++++++ Source/VaRest/Public/VaRestJsonValue.h | 10 ++++++++- 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index 86bb28a4..a99930c6 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -197,6 +197,27 @@ void UVaRestJsonObject::SetIntegerField(const FString& FieldName, int32 Number) JsonObj->SetNumberField(FieldName, Number); } +int64 UVaRestJsonObject::GetInt64Field(const FString& FieldName) const +{ + if (!JsonObj->HasTypedField(FieldName)) + { + UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName); + return 0; + } + + return static_cast(JsonObj->GetNumberField(FieldName)); +} + +void UVaRestJsonObject::SetInt64Field(const FString& FieldName, int64 Number) +{ + if (FieldName.IsEmpty()) + { + return; + } + + JsonObj->SetNumberField(FieldName, Number); +} + FString UVaRestJsonObject::GetStringField(const FString& FieldName) const { if (!JsonObj->HasTypedField(FieldName)) diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index 74018ded..f68b1754 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -111,7 +111,29 @@ float UVaRestJsonValue::AsNumber() const return 0.f; } - return JsonVal->AsNumber(); + return static_cast(JsonVal->AsNumber()); +} + +int32 UVaRestJsonValue::AsInt32() const +{ + if (!JsonVal.IsValid()) + { + ErrorMessage(TEXT("Number")); + return 0.f; + } + + return static_cast(JsonVal->AsNumber()); +} + +int32 UVaRestJsonValue::AsInt64() const +{ + if (!JsonVal.IsValid()) + { + ErrorMessage(TEXT("Number")); + return 0.f; + } + + return static_cast(JsonVal->AsNumber()); } FString UVaRestJsonValue::AsString() const diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index 499fd779..d2c115f3 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -99,6 +99,14 @@ class VAREST_API UVaRestJsonObject : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Json") void SetIntegerField(const FString& FieldName, int32 Number); + /** Get the field named FieldName as an Int64. Ensures that the field is present and is of type Json number. */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + int64 GetInt64Field(const FString& FieldName) const; + + /** Add a field named FieldName with Int64 as value. */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void SetInt64Field(const FString& FieldName, int64 Number); + /** Get the field named FieldName as a string. */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") FString GetStringField(const FString& FieldName) const; diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index 9975a7bf..62c9d719 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -56,7 +56,15 @@ class VAREST_API UVaRestJsonValue : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Json") float AsNumber() const; - /** Returns this value as a number, throwing an error if this is not an Json String */ + /** Returns this value as a int32, throwing an error if this is not an Json Number */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + int32 AsInt32() const; + + /** Returns this value as a int64, throwing an error if this is not an Json Number */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + int32 AsInt64() const; + + /** Returns this value as a string, throwing an error if this is not an Json String */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") FString AsString() const; From ecc336aa3853a10155b077b49bfa300dbf6c38b7 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 17:35:35 +0300 Subject: [PATCH 45/71] Make getters pure --- Source/VaRest/Public/VaRestJsonValue.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index 62c9d719..ad2bb0e3 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -40,36 +40,36 @@ class VAREST_API UVaRestJsonValue : public UObject // FJsonValue API /** Get type of Json value (Enum) */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") EVaJson GetType() const; /** Get type of Json value (String) */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") FString GetTypeString() const; /** Returns true if this value is a 'null' */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") bool IsNull() const; /** Returns this value as a double, throwing an error if this is not an Json Number * Attn.!! float used instead of double to make the function blueprintable! */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") float AsNumber() const; /** Returns this value as a int32, throwing an error if this is not an Json Number */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") int32 AsInt32() const; /** Returns this value as a int64, throwing an error if this is not an Json Number */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") int32 AsInt64() const; /** Returns this value as a string, throwing an error if this is not an Json String */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") FString AsString() const; /** Returns this value as a boolean, throwing an error if this is not an Json Bool */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + UFUNCTION(BlueprintPure, Category = "VaRest|Json") bool AsBool() const; /** Returns this value as an array, throwing an error if this is not an Json Array */ From 67331cfb392472630cb81f7edd89d6d936559991 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 17:37:16 +0300 Subject: [PATCH 46/71] Up dev version --- VaRest.uplugin | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VaRest.uplugin b/VaRest.uplugin index 710b23c5..17387246 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -2,10 +2,10 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 31, - "VersionName" : "1.1-r31", + "Version" : 32, + "VersionName" : "1.1-r32", "CreatedBy" : "Vladimir Alyamkin", - "CreatedByURL" : "https://alyamkin.com", + "CreatedByURL" : "https://ufna.dev", "EngineVersion" : "4.26.0", "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", From aae0e2c84df969b5894caa3ca066232150e4294a Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 19:44:13 +0300 Subject: [PATCH 47/71] Add support for top-level arrays. Close #77. Close #116. --- Source/VaRest/Private/VaRestJsonValue.cpp | 5 ++++ Source/VaRest/Private/VaRestRequestJSON.cpp | 27 ++++++++++++++++++--- Source/VaRest/Private/VaRestSubsystem.cpp | 14 +++++++++++ Source/VaRest/Public/VaRestJsonValue.h | 5 ++++ Source/VaRest/Public/VaRestRequestJSON.h | 9 +++++++ Source/VaRest/Public/VaRestSubsystem.h | 8 ++++++ 6 files changed, 65 insertions(+), 3 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index f68b1754..5d1ad085 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -10,6 +10,11 @@ UVaRestJsonValue::UVaRestJsonValue(const FObjectInitializer& ObjectInitializer) { } +void UVaRestJsonValue::Reset() +{ + JsonVal = nullptr; +} + TSharedPtr& UVaRestJsonValue::GetRootValue() { return JsonVal; diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index bf0e303d..f6a2f124 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -4,6 +4,7 @@ #include "VaRestDefines.h" #include "VaRestJsonObject.h" +#include "VaRestJsonValue.h" #include "VaRestLibrary.h" #include "VaRestSettings.h" @@ -112,6 +113,15 @@ void UVaRestRequestJSON::ResetResponseData() ResponseJsonObj = NewObject(); } + if (ResponseJsonValue != nullptr) + { + ResponseJsonValue->Reset(); + } + else + { + ResponseJsonValue = NewObject(); + } + ResponseHeaders.Empty(); ResponseCode = -1; ResponseSize = 0; @@ -166,6 +176,12 @@ void UVaRestRequestJSON::SetResponseObject(UVaRestJsonObject* JsonObject) ResponseJsonObj = JsonObject; } +UVaRestJsonValue* UVaRestRequestJSON::GetResponseValue() const +{ + check(ResponseJsonValue); + return ResponseJsonValue; +} + /////////////////////////////////////////////////////////////////////////// // Response data access @@ -500,11 +516,16 @@ void UVaRestRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttp { // Use default unreal one const TSharedRef> Reader = TJsonReaderFactory<>::Create(*Response->GetContentAsString()); - TSharedPtr OutJsonObj; - if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) + TSharedPtr OutJsonValue; + if (FJsonSerializer::Deserialize(Reader, OutJsonValue)) { - ResponseJsonObj->SetRootObject(OutJsonObj.ToSharedRef()); + ResponseJsonValue->SetRootValue(OutJsonValue); ResponseSize = Response->GetContentLength(); + + if (ResponseJsonValue->GetType() == EVaJson::Object) + { + ResponseJsonObj->SetRootObject(ResponseJsonValue->GetRootValue()->AsObject()); + } } } diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index 8527b8dd..e79653cc 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -8,6 +8,8 @@ #include "Misc/FileHelper.h" #include "Misc/Paths.h" +#include "Serialization/JsonReader.h" +#include "Serialization/JsonSerializer.h" #include "Subsystems/SubsystemBlueprintLibrary.h" UVaRestSubsystem::UVaRestSubsystem() @@ -164,6 +166,18 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValue(const TSharedPtr> Reader = TJsonReaderFactory<>::Create(*JsonString); + TSharedPtr OutJsonValue; + if (FJsonSerializer::Deserialize(Reader, OutJsonValue)) + { + return ConstructJsonValue(OutJsonValue); + } + + return nullptr; +} + class UVaRestJsonObject* UVaRestSubsystem::LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir) { auto* Json = ConstructVaRestJsonObject(); diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index ad2bb0e3..c5e5305c 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -30,6 +30,11 @@ class VAREST_API UVaRestJsonValue : public UObject { GENERATED_UCLASS_BODY() +public: + /** Reset all internal data */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + void Reset(); + /** Get the root Json value */ TSharedPtr& GetRootValue(); diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index d74da2b3..8f39c06e 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -12,6 +12,7 @@ #include "VaRestRequestJSON.generated.h" +class UVaRestJsonValue; class UVaRestJsonObject; class UVaRestSettings; @@ -157,6 +158,10 @@ class VAREST_API UVaRestRequestJSON : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Response") void SetResponseObject(UVaRestJsonObject* JsonObject); + /** Get the Response Json value */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Response") + UVaRestJsonValue* GetResponseValue() const; + /////////////////////////////////////////////////////////////////////////// // Request/response data access @@ -297,6 +302,10 @@ class VAREST_API UVaRestRequestJSON : public UObject UPROPERTY() UVaRestJsonObject* ResponseJsonObj; + /** Response data stored as JSON value */ + UPROPERTY() + UVaRestJsonValue* ResponseJsonValue; + /** Verb for making request (GET,POST,etc) */ EVaRestRequestVerb RequestVerb; diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index f4547975..9773e34f 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -103,6 +103,14 @@ class VAREST_API UVaRestSubsystem : public UEngineSubsystem /** Create new Json value from FJsonValue (to be used from VaRestJsonObject) */ UVaRestJsonValue* ConstructJsonValue(const TSharedPtr& InValue); + ////////////////////////////////////////////////////////////////////////// + // Serialization + +public: + /** Construct Json value from string */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem") + UVaRestJsonValue* DecodeJson(const FString& JsonString); + ////////////////////////////////////////////////////////////////////////// // File system integration From 94f8c293eeb7189af5e4cfdef44a004ebc39e017 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 15 Jan 2021 19:53:03 +0300 Subject: [PATCH 48/71] Decode json should be global and accept a string. Close #115 --- Source/VaRest/Private/VaRestSubsystem.cpp | 16 +++++++++++++++- Source/VaRest/Public/VaRestSubsystem.h | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRestSubsystem.cpp b/Source/VaRest/Private/VaRestSubsystem.cpp index e79653cc..97daab65 100644 --- a/Source/VaRest/Private/VaRestSubsystem.cpp +++ b/Source/VaRest/Private/VaRestSubsystem.cpp @@ -166,7 +166,7 @@ UVaRestJsonValue* UVaRestSubsystem::ConstructJsonValue(const TSharedPtr> Reader = TJsonReaderFactory<>::Create(*JsonString); TSharedPtr OutJsonValue; @@ -178,6 +178,20 @@ UVaRestJsonValue* UVaRestSubsystem::DecodeJson(const FString& JsonString) return nullptr; } +UVaRestJsonObject* UVaRestSubsystem::DecodeJsonObject(const FString& JsonString) +{ + const TSharedRef> Reader = TJsonReaderFactory<>::Create(*JsonString); + TSharedPtr OutJsonObj; + if (FJsonSerializer::Deserialize(Reader, OutJsonObj)) + { + auto NewJsonObj = NewObject(this); + NewJsonObj->SetRootObject(OutJsonObj); + return NewJsonObj; + } + + return nullptr; +} + class UVaRestJsonObject* UVaRestSubsystem::LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir) { auto* Json = ConstructVaRestJsonObject(); diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 9773e34f..33225443 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -109,7 +109,11 @@ class VAREST_API UVaRestSubsystem : public UEngineSubsystem public: /** Construct Json value from string */ UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem") - UVaRestJsonValue* DecodeJson(const FString& JsonString); + UVaRestJsonValue* DecodeJsonValue(const FString& JsonString); + + /** Construct Json object from string */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem") + UVaRestJsonObject* DecodeJsonObject(const FString& JsonString); ////////////////////////////////////////////////////////////////////////// // File system integration From e466709e3ed5b1be4ef92534d165099ee49aed19 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sun, 17 Jan 2021 13:41:31 +0300 Subject: [PATCH 49/71] Use real build plugin plan for status icon --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9199cf7..d2cbf656 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_ClangFormatCheck)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_ClangFormatCheck&guest=1) +[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_BuildPlugin)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_BuildPlugin&guest=1) ![GitHub](https://img.shields.io/github/license/ufna/VaRest) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/ufna/VaRest?include_prereleases) From ed4195f88ae4c76170490b327aedb8424afd0ec0 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sun, 17 Jan 2021 14:10:04 +0300 Subject: [PATCH 50/71] Update version and copyright info --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d2cbf656..e876516b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 31** (UE 4.26) +Current version: **1.1 R 32** (UE 4.26) ![SCREENSHOT](SCREENSHOT.jpg) @@ -26,5 +26,5 @@ Legal info Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere. -Unreal® Engine, Copyright 1998 – 2018, Epic Games, Inc. All rights reserved. +Unreal® Engine, Copyright 1998 – 2021, Epic Games, Inc. All rights reserved. From dc31bd147533e023ae281b75cdfc24d37517a230 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 28 Jan 2021 16:53:56 +0300 Subject: [PATCH 51/71] Fix encode to single string for top-level arrays --- Source/VaRest/Private/VaRestRequestJSON.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index f6a2f124..3b972060 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -520,11 +520,11 @@ void UVaRestRequestJSON::OnProcessRequestComplete(FHttpRequestPtr Request, FHttp if (FJsonSerializer::Deserialize(Reader, OutJsonValue)) { ResponseJsonValue->SetRootValue(OutJsonValue); - ResponseSize = Response->GetContentLength(); if (ResponseJsonValue->GetType() == EVaJson::Object) { ResponseJsonObj->SetRootObject(ResponseJsonValue->GetRootValue()->AsObject()); + ResponseSize = Response->GetContentLength(); } } } From 628c66b79a9bf301cb02ce5188271db8d48f91e1 Mon Sep 17 00:00:00 2001 From: MaxFluffy Date: Tue, 16 Feb 2021 14:52:39 +0100 Subject: [PATCH 52/71] Allow get directly Int Array from json key --- README.md | 1 - Source/VaRest/Private/VaRestJsonObject.cpp | 24 ++++------------- Source/VaRest/Public/VaRestJsonObject.h | 28 +++++++++++++++++++ VaRest.uplugin | 31 +++++++++++----------- 4 files changed, 48 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index e876516b..e6e13c93 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,3 @@ Legal info Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere. Unreal® Engine, Copyright 1998 – 2021, Epic Games, Inc. All rights reserved. - diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index a99930c6..c5177194 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -416,26 +416,12 @@ void UVaRestJsonObject::SetMapFields_bool(const TMap& Fields) TArray UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) const { - TArray NumberArray; - if (!JsonObj->HasTypedField(FieldName) || FieldName.IsEmpty()) - { - UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Array"), *VA_FUNC_LINE, *FieldName); - return NumberArray; - } - - const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); - for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) - { - const auto Value = (*It).Get(); - if (Value->Type != EJson::Number) - { - UE_LOG(LogVaRest, Error, TEXT("Not Number element in array with field name %s"), *FieldName); - } - - NumberArray.Add((*It)->AsNumber()); - } + return GetTypeArrayField(FieldName); +} - return NumberArray; +TArray UVaRestJsonObject::GetIntegerArrayField(const FString& FieldName) const +{ + return GetTypeArrayField(FieldName); } void UVaRestJsonObject::SetNumberArrayField(const FString& FieldName, const TArray& NumberArray) diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index d2c115f3..d3befef9 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -2,6 +2,7 @@ #pragma once +#include "VaRestDefines.h" #include "Dom/JsonObject.h" #include "Templates/UnrealTypeTraits.h" @@ -170,6 +171,31 @@ class VAREST_API UVaRestJsonObject : public UObject } } + template + TArray GetTypeArrayField(const FString& FieldName) const + { + TArray NumberArray; + if (!JsonObj->HasTypedField(FieldName) || FieldName.IsEmpty()) + { + UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Array"), *VA_FUNC_LINE, *FieldName); + return NumberArray; + } + + const TArray> JsonArrayValues = JsonObj->GetArrayField(FieldName); + for (TArray>::TConstIterator It(JsonArrayValues); It; ++It) + { + const auto Value = (*It).Get(); + if (Value->Type != EJson::Number) + { + UE_LOG(LogVaRest, Error, TEXT("Not Number element in array with field name %s"), *FieldName); + } + + NumberArray.Add((*It)->AsNumber()); + } + + return NumberArray; + } + ////////////////////////////////////////////////////////////////////////// // Array fields helpers (uniform arrays) @@ -178,6 +204,8 @@ class VAREST_API UVaRestJsonObject : public UObject * Attn.!! float used instead of double to make the function blueprintable! */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") TArray GetNumberArrayField(const FString& FieldName) const; + UFUNCTION(BlueprintCallable, Category = "VaRest|Json") + TArray GetIntegerArrayField(const FString& FieldName) const; /** Set an ObjectField named FieldName and value of Number Array * Attn.!! float used instead of double to make the function blueprintable! */ diff --git a/VaRest.uplugin b/VaRest.uplugin index 17387246..25e7d5ec 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -1,27 +1,26 @@ { - "FileVersion" : 3, - - "FriendlyName" : "VaRest", - "Version" : 32, - "VersionName" : "1.1-r32", - "CreatedBy" : "Vladimir Alyamkin", + "FileVersion": 3, + "Version": 32, + "VersionName": "1.1-r32", + "FriendlyName": "VaRest", + "Description": "Plugin that makes REST (JSON) server communication easy to use", + "Category": "Network", + "CreatedBy": "Vladimir Alyamkin", "CreatedByURL" : "https://ufna.dev", - "EngineVersion" : "4.26.0", - "Description" : "Plugin that makes REST (JSON) server communication easy to use", - "Category" : "Network", "DocsURL": "https://bit.ly/VaRest-Docs", - "MarketplaceURL" : "com.epicgames.launcher://ue/marketplace/content/e47be161e7a24e928560290abd5dcc4f", + "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/e47be161e7a24e928560290abd5dcc4f", + "EngineVersion": "4.26.0", - "Modules" : - [ + "Modules": [ { - "Name" : "VaRest", - "Type" : "Runtime", + "Name": "VaRest", + "Type": "Runtime", "LoadingPhase": "PreDefault" }, { "Name": "VaRestEditor", - "Type": "UncookedOnly" + "Type": "UncookedOnly", + "LoadingPhase": "Default" } ] -} \ No newline at end of file +} From 4cf3d563538a0ee9ef4710a06fc0d24f6592dbf8 Mon Sep 17 00:00:00 2001 From: Anton Rassadin Date: Thu, 18 Feb 2021 18:40:21 +0300 Subject: [PATCH 53/71] Add VaRestJsonObject include --- Source/VaRest/Public/VaRestSubsystem.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 33225443..5fe6ed72 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -2,6 +2,7 @@ #pragma once +#include "VaRestJsonObject.h" #include "VaRestJsonValue.h" #include "VaRestRequestJSON.h" From 29292016f29134f881010bcf99fd1ecf3564fcc4 Mon Sep 17 00:00:00 2001 From: Anton Rassadin Date: Thu, 18 Feb 2021 18:40:40 +0300 Subject: [PATCH 54/71] Remove redundant forward declaration --- Source/VaRest/Public/VaRestSubsystem.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestSubsystem.h b/Source/VaRest/Public/VaRestSubsystem.h index 5fe6ed72..3fae927e 100644 --- a/Source/VaRest/Public/VaRestSubsystem.h +++ b/Source/VaRest/Public/VaRestSubsystem.h @@ -125,5 +125,5 @@ class VAREST_API UVaRestSubsystem : public UEngineSubsystem * @param bIsRelativeToContentDir if set to 'false' path is treated as absolute */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility") - class UVaRestJsonObject* LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir = true); + UVaRestJsonObject* LoadJsonFromFile(const FString& Path, const bool bIsRelativeToContentDir = true); }; From 7edb88cac79820049fa6f3e07aaa5fbaeeabcaef Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 19 Mar 2021 11:04:06 +0300 Subject: [PATCH 55/71] Make getters pure and add getter for the verb --- Source/VaRest/Private/VaRestRequestJSON.cpp | 5 +++++ Source/VaRest/Public/VaRestRequestJSON.h | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 3b972060..8f7fd625 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -190,6 +190,11 @@ FString UVaRestRequestJSON::GetURL() const return HttpRequest->GetURL(); } +EVaRestRequestVerb UVaRestRequestJSON::GetVerb() const +{ + return RequestVerb; +} + EVaRestRequestStatus UVaRestRequestJSON::GetStatus() const { return EVaRestRequestStatus((uint8)HttpRequest->GetStatus()); diff --git a/Source/VaRest/Public/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h index 8f39c06e..5f65d1b2 100644 --- a/Source/VaRest/Public/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -166,15 +166,19 @@ class VAREST_API UVaRestRequestJSON : public UObject // Request/response data access /** Get url of http request */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Request") + UFUNCTION(BlueprintPure, Category = "VaRest|Request") FString GetURL() const; + /** Get verb to the request */ + UFUNCTION(BlueprintPure, Category = "VaRest|Request") + EVaRestRequestVerb GetVerb() const; + /** Get status of http request */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Request") + UFUNCTION(BlueprintPure, Category = "VaRest|Request") EVaRestRequestStatus GetStatus() const; /** Get the response code of the last query */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Response") + UFUNCTION(BlueprintPure, Category = "VaRest|Response") int32 GetResponseCode() const; /** Get value of desired response header */ @@ -182,7 +186,7 @@ class VAREST_API UVaRestRequestJSON : public UObject FString GetResponseHeader(const FString& HeaderName); /** Get list of all response headers */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Response") + UFUNCTION(BlueprintPure, Category = "VaRest|Response") TArray GetAllResponseHeaders() const; ////////////////////////////////////////////////////////////////////////// From 8384e4dfae83e26156779346d5a959359375a5c7 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sat, 20 Mar 2021 20:39:36 +0300 Subject: [PATCH 56/71] Enable pre-compile for all targets --- Source/VaRest/VaRest.Build.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/VaRest/VaRest.Build.cs b/Source/VaRest/VaRest.Build.cs index a6563463..fb860832 100644 --- a/Source/VaRest/VaRest.Build.cs +++ b/Source/VaRest/VaRest.Build.cs @@ -9,6 +9,7 @@ public class VaRest : ModuleRules public VaRest(ReadOnlyTargetRules Target) : base(Target) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; + PrecompileForTargets = PrecompileTargetsType.Any; PrivateIncludePaths.AddRange( new string[] { From 5550c25f33f5beba157ad8f6580ef972af0f197c Mon Sep 17 00:00:00 2001 From: Anton Rassadin Date: Fri, 9 Apr 2021 18:27:12 +0300 Subject: [PATCH 57/71] Fix AsInt64() return type --- Source/VaRest/Private/VaRestJsonValue.cpp | 2 +- Source/VaRest/Public/VaRestJsonValue.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp index 5d1ad085..043d2d99 100644 --- a/Source/VaRest/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -130,7 +130,7 @@ int32 UVaRestJsonValue::AsInt32() const return static_cast(JsonVal->AsNumber()); } -int32 UVaRestJsonValue::AsInt64() const +int64 UVaRestJsonValue::AsInt64() const { if (!JsonVal.IsValid()) { diff --git a/Source/VaRest/Public/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h index c5e5305c..45ba8b40 100644 --- a/Source/VaRest/Public/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -67,7 +67,7 @@ class VAREST_API UVaRestJsonValue : public UObject /** Returns this value as a int64, throwing an error if this is not an Json Number */ UFUNCTION(BlueprintPure, Category = "VaRest|Json") - int32 AsInt64() const; + int64 AsInt64() const; /** Returns this value as a string, throwing an error if this is not an Json String */ UFUNCTION(BlueprintPure, Category = "VaRest|Json") From 7be2aad19b05bf7f890844bbb483e8ea23cc3aab Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Wed, 26 May 2021 20:58:26 +0300 Subject: [PATCH 58/71] Remove deprecated VaRest stuff (UEV ready now) --- Source/VaRest/Private/VaRestJsonObject.cpp | 4 -- Source/VaRest/Private/VaRestRequestJSON.cpp | 10 ----- Source/VaRest/Public/VaRestDefines.h | 5 --- .../VaRestEditor/Private/VaRest_BreakJson.cpp | 44 ------------------- Source/VaRestEditor/Public/VaRest_BreakJson.h | 4 -- 5 files changed, 67 deletions(-) diff --git a/Source/VaRest/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp index a99930c6..316ba060 100644 --- a/Source/VaRest/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -589,11 +589,7 @@ int32 UVaRestJsonObject::DeserializeFromUTF8Bytes(const ANSICHAR* Bytes, int32 S const ANSICHAR* EndByte = Bytes + Size; while (Bytes < EndByte) { -#if ENGINE_MINOR_VERSION >= 19 TCHAR Char = FUtf8Helper::CodepointFromUtf8(Bytes, EndByte - Bytes); -#else - TCHAR Char = FUTF8ToTCHAR_Convert::utf8codepoint(&Bytes); -#endif if (Char > 0xFFFF) { Char = UNICODE_BOGUS_CHAR_CODEPOINT; diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 8f7fd625..8b6141ed 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -236,13 +236,8 @@ void UVaRestRequestJSON::SetURL(const FString& Url) // Be sure to trim URL because it can break links on iOS FString TrimmedUrl = Url; -#if ENGINE_MINOR_VERSION >= 18 TrimmedUrl.TrimStartInline(); TrimmedUrl.TrimEndInline(); -#else - TrimmedUrl.Trim(); - TrimmedUrl.TrimTrailing(); -#endif HttpRequest->SetURL(TrimmedUrl); } @@ -258,13 +253,8 @@ void UVaRestRequestJSON::ApplyURL(const FString& Url, UVaRestJsonObject*& Result // Be sure to trim URL because it can break links on iOS FString TrimmedUrl = Url; -#if ENGINE_MINOR_VERSION >= 18 TrimmedUrl.TrimStartInline(); TrimmedUrl.TrimEndInline(); -#else - TrimmedUrl.Trim(); - TrimmedUrl.TrimTrailing(); -#endif HttpRequest->SetURL(TrimmedUrl); diff --git a/Source/VaRest/Public/VaRestDefines.h b/Source/VaRest/Public/VaRestDefines.h index d0e0e1f2..ec14ea47 100644 --- a/Source/VaRest/Public/VaRestDefines.h +++ b/Source/VaRest/Public/VaRestDefines.h @@ -4,12 +4,7 @@ #include "Runtime/Launch/Resources/Version.h" -#if ENGINE_MINOR_VERSION >= 15 #include "CoreMinimal.h" -#else -#include "CoreUObject.h" -#include "Engine.h" -#endif #include "Logging/LogCategory.h" #include "Logging/LogMacros.h" diff --git a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp index 7e8fc586..4083062c 100644 --- a/Source/VaRestEditor/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -59,29 +59,15 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor FBPTerminal** Target = Context.NetMap.Find(Pin); -#if ENGINE_MINOR_VERSION >= 19 const FName& FieldName = Pin->PinName; const FName& FieldType = Pin->PinType.PinCategory; -#else - const FString& FieldName = Pin->PinName; - const FString& FieldType = Pin->PinType.PinCategory; -#endif FBPTerminal* FieldNameTerm = Context.CreateLocalTerminal(ETerminalSpecification::TS_Literal); FieldNameTerm->Type.PinCategory = CompilerContext.GetSchema()->PC_String; -#if ENGINE_MINOR_VERSION >= 13 FieldNameTerm->SourcePin = Pin; -#else - FieldNameTerm->Source = Pin; -#endif -#if ENGINE_MINOR_VERSION >= 19 FieldNameTerm->Name = FieldName.ToString(); FieldNameTerm->TextLiteral = FText::FromName(FieldName); -#else - FieldNameTerm->Name = FieldName; - FieldNameTerm->TextLiteral = FText::FromString(FieldName); -#endif FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); FName FunctionName; @@ -197,11 +183,7 @@ void UVaRest_BreakJson::AllocateDefaultPins() UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Input, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); -#if ENGINE_MINOR_VERSION >= 17 K2Schema->SetPinAutogeneratedDefaultValueBasedOnType(Pin); -#else - K2Schema->SetPinDefaultValueBasedOnType(Pin); -#endif CreateProjectionPins(Pin); } @@ -266,11 +248,7 @@ void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) for (TArray::TIterator it(Outputs); it; ++it) { -#if ENGINE_MINOR_VERSION >= 19 FName Type; -#else - FString Type; -#endif UObject* Subtype = nullptr; @@ -361,29 +339,15 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor { FBPTerminal** Source = Context.NetMap.Find(FEdGraphUtilities::GetNetFromPin(Pin)); -#if ENGINE_MINOR_VERSION >= 19 const FName& FieldName = Pin->PinName; const FName& FieldType = Pin->PinType.PinCategory; -#else - const FString& FieldName = Pin->PinName; - const FString& FieldType = Pin->PinType.PinCategory; -#endif FBPTerminal* FieldNameTerm = Context.CreateLocalTerminal(ETerminalSpecification::TS_Literal); FieldNameTerm->Type.PinCategory = CompilerContext.GetSchema()->PC_String; -#if ENGINE_MINOR_VERSION >= 13 FieldNameTerm->SourcePin = Pin; -#else - FieldNameTerm->Source = Pin; -#endif -#if ENGINE_MINOR_VERSION >= 19 FieldNameTerm->Name = FieldName.ToString(); FieldNameTerm->TextLiteral = FText::FromName(FieldName); -#else - FieldNameTerm->Name = FieldName; - FieldNameTerm->TextLiteral = FText::FromString(FieldName); -#endif FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); FName FunctionName; @@ -489,11 +453,7 @@ void UVaRest_MakeJson::AllocateDefaultPins() UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), nullptr, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Output, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); -#if ENGINE_MINOR_VERSION >= 17 K2Schema->SetPinAutogeneratedDefaultValueBasedOnType(Pin); -#else - K2Schema->SetPinDefaultValueBasedOnType(Pin); -#endif CreateProjectionPins(Pin); } @@ -585,11 +545,7 @@ void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source) InputPinParams.ContainerType = (*it).bIsArray ? EPinContainerType::Array : EPinContainerType::None; UEdGraphPin* InputPin = CreatePin(EGPD_Input, Type, TEXT(""), Subtype, (*it).Name, InputPinParams); -#if ENGINE_MINOR_VERSION >= 20 InputPin->SetSavePinIfOrphaned(false); -#else - InputPin->bSavePinIfOrphaned = false; -#endif } } diff --git a/Source/VaRestEditor/Public/VaRest_BreakJson.h b/Source/VaRestEditor/Public/VaRest_BreakJson.h index 68efe61f..dcf2195a 100644 --- a/Source/VaRestEditor/Public/VaRest_BreakJson.h +++ b/Source/VaRestEditor/Public/VaRest_BreakJson.h @@ -5,11 +5,7 @@ #include "Runtime/Launch/Resources/Version.h" -#if ENGINE_MINOR_VERSION >= 15 #include "CoreMinimal.h" -#else -#include "Engine.h" -#endif #include "K2Node.h" #include "VaRest_BreakJson.generated.h" From bd449545f2433525eab7d00c62246357084c4346 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sat, 29 May 2021 22:13:09 +0300 Subject: [PATCH 59/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e876516b..62bb4a38 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 32** (UE 4.26) +Current version: **1.1 R 32** (UE 4.26; please check [5.0](https://github.com/ufna/VaRest/tree/5.0) branch for UE5 EA support). ![SCREENSHOT](SCREENSHOT.jpg) From ce70a176a0c7f2759bd72102b8449f782e501ef8 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Sat, 29 May 2021 22:13:26 +0300 Subject: [PATCH 60/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62bb4a38..261073bd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 32** (UE 4.26; please check [5.0](https://github.com/ufna/VaRest/tree/5.0) branch for UE5 EA support). +Current version: **1.1 R 32** (UE 4.26; please check the [5.0](https://github.com/ufna/VaRest/tree/5.0) branch for UE5 EA support). ![SCREENSHOT](SCREENSHOT.jpg) From 4a159699bfeb387b2317f14ebc50350d1fe8d1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20G=C3=A9linas?= Date: Wed, 23 Jun 2021 15:37:27 -0400 Subject: [PATCH 61/71] Update VaRestRequestJSON.cpp To resolve issue #348 --- Source/VaRest/Private/VaRestRequestJSON.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 8b6141ed..576fc638 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -428,7 +428,14 @@ void UVaRestRequestJSON::ProcessRequest() // Set Json content HttpRequest->SetContentAsString(OutputString); - UE_LOG(LogVaRest, Log, TEXT("Request (json): %s %s %sJSON(%s%s%s)JSON"), *HttpRequest->GetVerb(), *HttpRequest->GetURL(), LINE_TERMINATOR, LINE_TERMINATOR, *OutputString, LINE_TERMINATOR); + if (UVaRestLibrary::GetVaRestSettings()->bExtendedLog) + { + UE_LOG(LogVaRest, Log, TEXT("Request (json): %s %s %sJSON(%s%s%s)JSON"), *HttpRequest->GetVerb(), *HttpRequest->GetURL(), LINE_TERMINATOR, LINE_TERMINATOR, *OutputString, LINE_TERMINATOR); + } + else + { + UE_LOG(LogVaRest, Log, TEXT("Request (json): %s %s (check bExtendedLog for additional data)"), *HttpRequest->GetVerb(), *HttpRequest->GetURL()); + } break; } From c19c938882930fe4ff3e2cfe27869444208728ac Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Jun 2021 23:07:46 +0300 Subject: [PATCH 62/71] Update VaRestJsonObject.h --- Source/VaRest/Public/VaRestJsonObject.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/VaRest/Public/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h index d3befef9..eb176160 100644 --- a/Source/VaRest/Public/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -3,6 +3,7 @@ #pragma once #include "VaRestDefines.h" + #include "Dom/JsonObject.h" #include "Templates/UnrealTypeTraits.h" @@ -171,6 +172,7 @@ class VAREST_API UVaRestJsonObject : public UObject } } + /** Internal implementation to get number arrays of different types */ template TArray GetTypeArrayField(const FString& FieldName) const { @@ -204,8 +206,10 @@ class VAREST_API UVaRestJsonObject : public UObject * Attn.!! float used instead of double to make the function blueprintable! */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") TArray GetNumberArrayField(const FString& FieldName) const; + + /** Get the field named FieldName as a Number Array. Use it only if you're sure that array is uniform! */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") - TArray GetIntegerArrayField(const FString& FieldName) const; + TArray GetIntegerArrayField(const FString& FieldName) const; /** Set an ObjectField named FieldName and value of Number Array * Attn.!! float used instead of double to make the function blueprintable! */ From c539a3fa1e0fe4d312d134252e16ceeb2fb5c8f6 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Jun 2021 23:08:30 +0300 Subject: [PATCH 63/71] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e6e13c93..e876516b 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,4 @@ Legal info Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere. Unreal® Engine, Copyright 1998 – 2021, Epic Games, Inc. All rights reserved. + From 75b61464d44d97af9dab7df671d37e4331ef8ad4 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Jun 2021 23:08:57 +0300 Subject: [PATCH 64/71] Update VaRest.uplugin --- VaRest.uplugin | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/VaRest.uplugin b/VaRest.uplugin index 25e7d5ec..17116be6 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -1,26 +1,27 @@ { - "FileVersion": 3, - "Version": 32, - "VersionName": "1.1-r32", - "FriendlyName": "VaRest", - "Description": "Plugin that makes REST (JSON) server communication easy to use", - "Category": "Network", - "CreatedBy": "Vladimir Alyamkin", + "FileVersion" : 3, + + "FriendlyName" : "VaRest", + "Version" : 32, + "VersionName" : "1.1-r32", + "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://ufna.dev", + "EngineVersion" : "4.26.0", + "Description" : "Plugin that makes REST (JSON) server communication easy to use", + "Category" : "Network", "DocsURL": "https://bit.ly/VaRest-Docs", - "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/e47be161e7a24e928560290abd5dcc4f", - "EngineVersion": "4.26.0", + "MarketplaceURL" : "com.epicgames.launcher://ue/marketplace/content/e47be161e7a24e928560290abd5dcc4f", - "Modules": [ + "Modules" : + [ { - "Name": "VaRest", - "Type": "Runtime", + "Name" : "VaRest", + "Type" : "Runtime", "LoadingPhase": "PreDefault" }, { "Name": "VaRestEditor", - "Type": "UncookedOnly", - "LoadingPhase": "Default" + "Type": "UncookedOnly" } ] } From b3d7ebf94c5241c81b32abacd61f7ea12fb6d369 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Jun 2021 23:09:18 +0300 Subject: [PATCH 65/71] Update VaRest.uplugin From a9b41d1778873d8868d62cb962115164793b1a59 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Jun 2021 23:09:43 +0300 Subject: [PATCH 66/71] Update VaRest.uplugin From 18bf785c2cde55b05b5fd9b9230ab293489f8733 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Jun 2021 23:10:07 +0300 Subject: [PATCH 67/71] Update VaRest.uplugin From d1f7f69ca9f53ca00fe9c5d7f25f4571185af7e8 Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Fri, 25 Jun 2021 23:11:04 +0300 Subject: [PATCH 68/71] Update VaRest.uplugin From 8b673bdf987f4482ba88d2b6a5d3b1f5ddfef98d Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Mon, 23 Aug 2021 12:18:56 +0300 Subject: [PATCH 69/71] Up VaRest version to UE 4.27 --- README.md | 2 +- VaRest.uplugin | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 261073bd..e9ee079f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Key features: Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. -Current version: **1.1 R 32** (UE 4.26; please check the [5.0](https://github.com/ufna/VaRest/tree/5.0) branch for UE5 EA support). +Current version: **1.1.33** (UE 4.27; please check the [5.0](https://github.com/ufna/VaRest/tree/5.0) branch for UE5 EA support). ![SCREENSHOT](SCREENSHOT.jpg) diff --git a/VaRest.uplugin b/VaRest.uplugin index 17116be6..c67a677b 100644 --- a/VaRest.uplugin +++ b/VaRest.uplugin @@ -2,11 +2,11 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 32, - "VersionName" : "1.1-r32", + "Version" : 33, + "VersionName" : "1.1.33", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "https://ufna.dev", - "EngineVersion" : "4.26.0", + "EngineVersion" : "4.27.0", "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", "DocsURL": "https://bit.ly/VaRest-Docs", From acbad678badc37039fb2c41d0d843e40a1db162d Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 26 Aug 2021 19:32:51 +0300 Subject: [PATCH 70/71] Fix content-length issue for get requests. Close #354. Close #99. --- Source/VaRest/Private/VaRestRequestJSON.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index 576fc638..ab998d2d 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -420,6 +420,12 @@ void UVaRestRequestJSON::ProcessRequest() { HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json")); + // Body is ignored for get requests, so we shouldn't place json into it even if it's empty + if(RequestVerb == EVaRestRequestVerb::GET) + { + break; + } + // Serialize data to json string FString OutputString; TSharedRef> Writer = TJsonWriterFactory<>::Create(&OutputString); From 21217cc4ae2380179378809f7919785858c5ee4b Mon Sep 17 00:00:00 2001 From: Vladimir Alyamkin Date: Thu, 26 Aug 2021 19:34:12 +0300 Subject: [PATCH 71/71] Fix clang-format (cherry picked from commit 9e04e7caaec797f33f7cbb35fe3fb6335fd2aaf5) --- Source/VaRest/Private/VaRestRequestJSON.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/VaRest/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp index ab998d2d..cbb68f50 100644 --- a/Source/VaRest/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -421,7 +421,7 @@ void UVaRestRequestJSON::ProcessRequest() HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json")); // Body is ignored for get requests, so we shouldn't place json into it even if it's empty - if(RequestVerb == EVaRestRequestVerb::GET) + if (RequestVerb == EVaRestRequestVerb::GET) { break; }