A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
ApexSDKSettings.cpp
Go to the documentation of this file.
1// Copyright 2022 PixoVR Corp. All Rights Reserved.
2
3#include "ApexSDKSettings.h"
4
5#if WITH_EDITORONLY_DATA
6#include "GeneralProjectSettings.h"
7#include "AndroidRuntimeSettings.h"
8#endif
9
10DEFINE_LOG_CATEGORY_STATIC(LogApexSDKSettings, Log, All);
11
12#define LogAPEX(pmt, ...) UE_LOG(LogApexSDKSettings, Log, TEXT(pmt), ##__VA_ARGS__)
13#define WarnAPEX(pmt, ...) UE_LOG(LogApexSDKSettings, Warning, TEXT(pmt), ##__VA_ARGS__)
14#define ErrorAPEX(pmt, ...) UE_LOG(LogApexSDKSettings, Error, TEXT(pmt), ##__VA_ARGS__)
15#define FatalAPEX(pmt, ...) UE_LOG(LogApexSDKSettings, Fatal, TEXT(pmt), ##__VA_ARGS__)
16
17UApexSDKSettings::UApexSDKSettings(const FObjectInitializer& ObjectInitializer)
18 : Super(ObjectInitializer)
19{
20 ServerURI = "";
21 ModuleId = -1;
22 ModuleVersion = "1.00.00";
23 bSyncVersion = true;
24}
25
27{
28 TArray<FString> ModuleVersionArray;
29 return GetModuleVersionArray(ModuleVersion, ModuleVersionArray);
30}
31
32bool UApexSDKSettings::GetModuleVersionArray(FString Version, TArray<FString>& ModuleVersionArray)
33{
34 int VersionPartCount = Version.ParseIntoArray(ModuleVersionArray, TEXT("."));
35
36 if (VersionPartCount != 3)
37 {
38 return false;
39 }
40
41 if (ModuleVersionArray[0].Len() <= 0 || ModuleVersionArray[0].StartsWith("0") || !ModuleVersionArray[0].IsNumeric())
42 {
43 return false;
44 }
45
46 if (ModuleVersionArray[1].Len() != 2 || !ModuleVersionArray[1].IsNumeric())
47 {
48 return false;
49 }
50
51 if (ModuleVersionArray[2].Len() != 2 || !ModuleVersionArray[2].IsNumeric())
52 {
53 return false;
54 }
55
56 return true;
57}
58
59#if WITH_EDITORONLY_DATA
60void UApexSDKSettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
61{
62 if (PropertyChangedEvent.Property != nullptr)
63 {
64 const FName PropertyName(PropertyChangedEvent.Property->GetFName());
65 if (PropertyName == GET_MEMBER_NAME_CHECKED(UApexSDKSettings, ModuleVersion) ||
66 PropertyName == GET_MEMBER_NAME_CHECKED(UApexSDKSettings, bSyncVersion) ||
67 PropertyName == GET_MEMBER_NAME_CHECKED(UApexSDKSettings, AdditionalVersionFields))
68 {
69 TArray<FString> ModuleVersionParts;
70 if (GetModuleVersionArray(ModuleVersion, ModuleVersionParts))
71 {
72 if (bSyncVersion)
73 {
74 UpdateVersion(ModuleVersionParts, AdditionalVersionFields);
75 }
76 }
77 else
78 {
79 ErrorAPEX("Module Version %s is invalid.", *ModuleVersion);
80 }
81 }
82 }
83 Super::PostEditChangeProperty(PropertyChangedEvent);
84}
85
86void UApexSDKSettings::UpdateVersion(const TArray<FString>& VersionParts, const TArray<EPVRVersionFields>& Fields)
87{
88 int MajorVerison = FCString::Atoi(*VersionParts[0]);
89 int MinorVersion = FCString::Atoi(*VersionParts[1]);
90 int PatchVersion = FCString::Atoi(*VersionParts[2]);
91
92 FString FullVersion = FString::Printf(TEXT("%i.%.2i.%.2i"), MajorVerison, MinorVersion, PatchVersion);
93
94 if (UGeneralProjectSettings* Settings = GetMutableDefault<UGeneralProjectSettings>())
95 {
96 Settings->ProjectVersion = FullVersion;
97 Settings->UpdateSinglePropertyInConfigFile(Settings->GetClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(UGeneralProjectSettings, ProjectVersion)), Settings->GetDefaultConfigFilename());
98 }
99
100 if (UAndroidRuntimeSettings* Settings = GetMutableDefault<UAndroidRuntimeSettings>())
101 {
102 Settings->VersionDisplayName = FullVersion;
103 Settings->UpdateSinglePropertyInConfigFile(Settings->GetClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(UAndroidRuntimeSettings, VersionDisplayName)), Settings->GetDefaultConfigFilename());
104 }
105
106 if (Fields.Contains(EPVRVersionFields::AndroidStoreVersion))
107 {
108 FString AndroidVersionNumber = FString::Printf(TEXT("%i%.2i%.2i"), MajorVerison, MinorVersion, PatchVersion);
109 if (UAndroidRuntimeSettings* Settings = GetMutableDefault<UAndroidRuntimeSettings>())
110 {
111 Settings->StoreVersion = FCString::Atoi(*AndroidVersionNumber);
112 Settings->UpdateSinglePropertyInConfigFile(Settings->GetClass()->FindPropertyByName(GET_MEMBER_NAME_CHECKED(UAndroidRuntimeSettings, VersionDisplayName)), Settings->GetDefaultConfigFilename());
113 }
114 }
115
116 if (Fields.Contains(EPVRVersionFields::PixoVRPluginVersion))
117 {
118 if (GConfig)
119 {
120 static const FString DefaultGamePath = FString::Printf(TEXT("%sDefaultGame.ini"), *FPaths::SourceConfigDir());
121 FString Setting;
122
123 if (GConfig->GetString(TEXT("/Script/PixoVR.PixoVRSettings"), TEXT("ModuleVersion"), Setting, DefaultGamePath))
124 {
125 GConfig->SetString(TEXT("/Script/PixoVR.PixoVRSettings"), TEXT("ModuleVersion"), *FullVersion, DefaultGamePath);
126 }
127
128 GConfig->Flush(false, DefaultGamePath);
129 }
130 }
131}
132#endif
133
134#undef FatalAPEX
135#undef ErrorAPEX
136#undef WarnAPEX
137#undef LogAPEX
#define ErrorAPEX(pmt,...)
Definition ApexAPI.cpp:15
DEFINE_LOG_CATEGORY_STATIC(LogApexSDKSettings, Log, All)
UCLASS(config = Engine, defaultconfig)
bool bSyncVersion
UPROPERTY(Config, EditAnywhere, Category = "Apex", meta = (DisplayName = "Sync Module Version",...
bool GetModuleVersionArray(FString Version, TArray< FString > &ModuleVersionArray)
FString ModuleVersion
UPROPERTY(Config, EditAnywhere, Category = "Apex", meta = (DisplayName = "Module Version"))
TArray< EPVRVersionFields > AdditionalVersionFields
UPROPERTY(Config, EditAnywhere, Category = "Apex", meta = (DisplayName = "Additional Synchronized Ver...