A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VaRestLibrary.cpp
Go to the documentation of this file.
1// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.
2
3#include "VaRestLibrary.h"
4
5#include "VaRest.h"
6#include "VaRestDefines.h"
7#include "VaRestRequestJSON.h"
8
9#include "Engine/World.h"
10#include "GenericPlatform/GenericPlatformHttp.h"
11#include "Interfaces/IPluginManager.h"
12#include "Misc/Base64.h"
13
18
19FString UVaRestLibrary::PercentEncode(const FString& Source)
20{
21 return FGenericPlatformHttp::UrlEncode(Source);
22}
23
24FString UVaRestLibrary::Base64Encode(const FString& Source)
25{
26 TArray<uint8> ByteArray;
27 const FTCHARToUTF8 StringSrc = FTCHARToUTF8(Source.GetCharArray().GetData());
28 ByteArray.Append((uint8*)StringSrc.Get(), StringSrc.Length());
29
30 return FBase64::Encode(ByteArray);
31}
32
33bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest)
34{
35 TArray<uint8> ByteArray;
36 const bool Success = FBase64::Decode(Source, ByteArray);
37
38 const FUTF8ToTCHAR StringSrc = FUTF8ToTCHAR((const ANSICHAR*)ByteArray.GetData(), ByteArray.Num());
39 Dest = FString();
40 Dest.AppendChars(StringSrc.Get(), StringSrc.Length());
41
42 return Success;
43}
44
45bool UVaRestLibrary::Base64EncodeData(const TArray<uint8>& Data, FString& Dest)
46{
47 if (Data.Num() > 0)
48 {
49 Dest = FBase64::Encode(Data);
50 return true;
51 }
52
53 Dest = FString();
54 return false;
55}
56
57bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray<uint8>& Dest)
58{
59 return FBase64::Decode(Source, Dest);
60}
61
62FString UVaRestLibrary::StringToMd5(const FString& StringToHash)
63{
64 return FMD5::HashAnsiString(*StringToHash);
65}
66
67FString UVaRestLibrary::StringToSha1(const FString& StringToHash)
68{
69 FSHA1 Sha1Gen;
70
71 Sha1Gen.Update((unsigned char*)TCHAR_TO_ANSI(*StringToHash), FCString::Strlen(*StringToHash));
72 Sha1Gen.Final();
73
74 FString Sha1String;
75 for (int32 i = 0; i < 20; i++)
76 {
77 Sha1String += FString::Printf(TEXT("%02x"), Sha1Gen.m_digest[i]);
78 }
79
80 return Sha1String;
81}
82
84{
85 const auto PluginRef = IPluginManager::Get().FindPlugin("VaRest");
86
87 return !PluginRef.IsValid() ? FString("invalid") : PluginRef->GetDescriptor().VersionName;
88}
89
91{
92 if (WorldContextObject)
93 {
94 if (UWorld* World = WorldContextObject->GetWorld())
95 {
96 return FVaRestURL(World->URL);
97 }
98 }
99
100 return FVaRestURL();
101}
static FVaRestModule & Get()
Definition VaRest.h:22
UVaRestSettings * GetSettings() const
Definition VaRest.cpp:48
static FString GetVaRestVersion()
UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (DisplayName = "Get VaRest Version"))
static FVaRestURL GetWorldURL(UObject *WorldContextObject)
UFUNCTION(BlueprintPure, Category = "VaRest|Utility", meta = (WorldContext = "WorldContextObject"))
static UVaRestSettings * GetVaRestSettings()
UFUNCTION(BlueprintPure, Category = "VaRest|Common")
static FString Base64Encode(const FString &Source)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Encode"))
static bool Base64DecodeData(const FString &Source, TArray< uint8 > &Dest)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Decode Data")...
static bool Base64EncodeData(const TArray< uint8 > &Data, FString &Dest)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Encode Data")...
static FString StringToMd5(const FString &StringToHash)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to MD5"))
static FString StringToSha1(const FString &StringToHash)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "String to SHA1"))
static FString PercentEncode(const FString &Source)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility")
static bool Base64Decode(const FString &Source, FString &Dest)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Decode"))
UCLASS(config = Engine, defaultconfig)
USTRUCT(BlueprintType)