Skip to content

Config keys update #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class UAndroidPlugin : public UActorComponent
void OnSessionEnd();

FString C3DSettingsPath;
FString C3DKeysPath;

FString FolderPath;
FString FolderPathCrashLog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ void URemoteControls::FetchRemoteControlVariable(FString ParticipantId)
//UE_LOG(LogTemp, Log, TEXT("REMOTE CONTROL VARIABLE Fetching: QUERY REMOTE CONTROL VARIABLE: %s"), *ParticipantId);

FString C3DSettingsPath = cog->GetSettingsFilePathRuntime();
FString C3DKeysPath = cog->GetKeysFilePathRuntime();
GConfig->LoadFile(C3DSettingsPath);
FString Gateway = FAnalytics::Get().GetConfigValueFromIni(C3DSettingsPath, "/Script/Cognitive3D.Cognitive3DSettings", "Gateway", false);
FString Url = "https://" + Gateway + "/v" + FString::FromInt(0) + "/remotevariables?identifier=" + ParticipantId;

GConfig->LoadFile(C3DKeysPath);
if (cog->ApplicationKey.IsEmpty())
{
cog->ApplicationKey = FAnalytics::Get().GetConfigValueFromIni(C3DSettingsPath, "Analytics", "ApiKey", false);
Expand All @@ -138,10 +139,11 @@ void URemoteControls::FetchRemoteControlVariable()
//UE_LOG(LogTemp, Log, TEXT("REMOTE CONTROL VARIABLE Fetching: QUERY REMOTE CONTROL VARIABLE: %s"), *cog->GetDeviceID());

FString C3DSettingsPath = cog->GetSettingsFilePathRuntime();
FString C3DKeysPath = cog->GetKeysFilePathRuntime();
GConfig->LoadFile(C3DSettingsPath);
FString Gateway = FAnalytics::Get().GetConfigValueFromIni(C3DSettingsPath, "/Script/Cognitive3D.Cognitive3DSettings", "Gateway", false);
FString Url = "https://" + Gateway + "/v" + FString::FromInt(0) + "/remotevariables?identifier=" + cog->GetDeviceID();

GConfig->LoadFile(C3DKeysPath);
if (cog->ApplicationKey.IsEmpty())
{
cog->ApplicationKey = FAnalytics::Get().GetConfigValueFromIni(C3DSettingsPath, "Analytics", "ApiKey", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ bool FAnalyticsProviderCognitive3D::StartSession(const TArray<FAnalyticsEventAtt
}

FString C3DSettingsPath = GetSettingsFilePathRuntime();
FString C3DKeysPath = GetKeysFilePathRuntime();

ApplicationKey = FAnalytics::Get().GetConfigValueFromIni(C3DSettingsPath, "Analytics", "ApiKey", false);
AttributionKey = FAnalytics::Get().GetConfigValueFromIni(C3DSettingsPath, "Analytics", "AttributionKey", false);
Expand Down Expand Up @@ -1010,6 +1011,37 @@ FString FAnalyticsProviderCognitive3D::GetSettingsFilePathRuntime() const
return ConfigFilePath;
}

FString FAnalyticsProviderCognitive3D::GetKeysFilePathRuntime() const
{
// Get the project's Config directory.
FString BaseConfigDir = FPaths::ProjectConfigDir();
FString BaseProjectDir = FPaths::ProjectDir();

// Define the subfolder and ensure it exists.
FString CustomFolder = FPaths::Combine(BaseProjectDir, TEXT("c3dlocal"));
if (!FPaths::DirectoryExists(CustomFolder))
{
// Create the directory if it doesn't exist.
IFileManager::Get().MakeDirectory(*CustomFolder);
}

// Combine the subfolder path with your INI file name.
FString ConfigFilePath = FPaths::Combine(CustomFolder, TEXT("Cognitive3DKeys.ini"));

// If the file doesn't exist, create it with some default content.
if (!FPaths::FileExists(ConfigFilePath))
{
FString DefaultContent = TEXT("; Cognitive3D Plugin Keys\n[General]\n");
if (!FFileHelper::SaveStringToFile(DefaultContent, *ConfigFilePath))
{
UE_LOG(LogTemp, Error, TEXT("Failed to create config file: %s"), *ConfigFilePath);
return FString();
}
}
//ConfigFilePath = FConfigCacheIni::NormalizeConfigIniPath(ConfigFilePath);
return ConfigFilePath;
}

FString FAnalyticsProviderCognitive3D::GetCurrentSceneId()
{
auto currentData = GetCurrentSceneData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
FString AttributionKey = "";

FString GetSettingsFilePathRuntime() const;
FString GetKeysFilePathRuntime() const;

FString GetCurrentSceneId();
FString GetCurrentSceneVersionNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ void FCognitive3DEditorModule::StartupModule()
FCognitiveEditorTools::Initialize();

FString C3DSettingsPath = FCognitiveEditorTools::GetInstance()->GetSettingsFilePath();
FString C3DKeysPath = FCognitiveEditorTools::GetInstance()->GetKeysFilePath();
GConfig->LoadFile(C3DSettingsPath);
GConfig->LoadFile(C3DKeysPath);
GConfig->GetString(TEXT("Analytics"), TEXT("ApiKey"), FCognitiveEditorTools::GetInstance()->ApplicationKey, C3DSettingsPath);
GConfig->GetString(TEXT("Analytics"), TEXT("AttributionKey"), FCognitiveEditorTools::GetInstance()->AttributionKey, C3DSettingsPath);
GConfig->GetString(TEXT("Analytics"), TEXT("DeveloperKey"), FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DSettingsPath);
GConfig->GetString(TEXT("Analytics"), TEXT("DeveloperKey"), FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DKeysPath);
GConfig->GetString(TEXT("Analytics"), TEXT("ExportPath"), FCognitiveEditorTools::GetInstance()->BaseExportDirectory, C3DSettingsPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);

if (FCognitiveEditorTools::GetInstance()->DeveloperKey.IsEmpty() || FCognitiveEditorTools::GetInstance()->ApplicationKey.IsEmpty()
|| FCognitiveEditorTools::GetInstance()->BaseExportDirectory.IsEmpty())
Expand All @@ -89,9 +92,10 @@ void FCognitive3DEditorModule::StartupModule()

GConfig->SetString(TEXT("Analytics"), TEXT("ApiKey"), *FCognitiveEditorTools::GetInstance()->ApplicationKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("AttributionKey"), *FCognitiveEditorTools::GetInstance()->AttributionKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DKeysPath);
GConfig->SetString(TEXT("Analytics"), TEXT("ExportPath"), *FCognitiveEditorTools::GetInstance()->BaseExportDirectory, C3DSettingsPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);
#else
GConfig->GetString(TEXT("Analytics"), TEXT("ApiKey"), FCognitiveEditorTools::GetInstance()->ApplicationKey, EngineIni);
GConfig->GetString(TEXT("Analytics"), TEXT("AttributionKey"), FCognitiveEditorTools::GetInstance()->AttributionKey, EngineIni);
Expand All @@ -100,9 +104,10 @@ void FCognitive3DEditorModule::StartupModule()

GConfig->SetString(TEXT("Analytics"), TEXT("ApiKey"), *FCognitiveEditorTools::GetInstance()->ApplicationKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("AttributionKey"), *FCognitiveEditorTools::GetInstance()->AttributionKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DKeysPath);
GConfig->SetString(TEXT("Analytics"), TEXT("ExportPath"), *FCognitiveEditorTools::GetInstance()->BaseExportDirectory, C3DSettingsPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);
#endif // ENGINE_MAJOR_VERSION == 4
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,37 @@ FString FCognitiveEditorTools::GetSettingsFilePath() const
return ConfigFilePath;
}

FString FCognitiveEditorTools::GetKeysFilePath() const
{
// Get the project's Config directory.
FString BaseConfigDir = FPaths::ProjectConfigDir();
FString BaseProjectDir = FPaths::ProjectDir();

// Define the subfolder and ensure it exists.
FString CustomFolder = FPaths::Combine(BaseProjectDir, TEXT("c3dlocal"));
if (!FPaths::DirectoryExists(CustomFolder))
{
// Create the directory if it doesn't exist.
IFileManager::Get().MakeDirectory(*CustomFolder);
}

// Combine the subfolder path with your INI file name.
FString ConfigFilePath = FPaths::Combine(CustomFolder, TEXT("Cognitive3DKeys.ini"));

// If the file doesn't exist, create it with some default content.
if (!FPaths::FileExists(ConfigFilePath))
{
FString DefaultContent = TEXT("; Cognitive3D Plugin Settings\n[General]\n");
if (!FFileHelper::SaveStringToFile(DefaultContent, *ConfigFilePath))
{
UE_LOG(LogTemp, Error, TEXT("Failed to create config file: %s"), *ConfigFilePath);
return FString();
}
}
//ConfigFilePath = FConfigCacheIni::NormalizeConfigIniPath(ConfigFilePath);
return ConfigFilePath;
}

FProcHandle FCognitiveEditorTools::ExportNewDynamics()
{
FProcHandle fph;
Expand Down Expand Up @@ -3587,11 +3618,14 @@ TArray<TSharedPtr<FEditorSceneData>> FCognitiveEditorTools::GetSceneData() const
FReply FCognitiveEditorTools::SaveAPIDeveloperKeysToFile()
{
FString C3DSettingsPath = GetSettingsFilePath();
FString C3DKeysPath = GetKeysFilePath();
GConfig->LoadFile(C3DSettingsPath);
GConfig->LoadFile(C3DKeysPath);
GConfig->SetString(TEXT("Analytics"), TEXT("ApiKey"), *ApplicationKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("AttributionKey"), *AttributionKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *DeveloperKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *DeveloperKey, C3DKeysPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);

ConfigFileHasChanged = true;

Expand All @@ -3601,9 +3635,12 @@ FReply FCognitiveEditorTools::SaveAPIDeveloperKeysToFile()
void FCognitiveEditorTools::SaveApplicationKeyToFile(FString key)
{
FString C3DSettingsPath = GetSettingsFilePath();
FString C3DKeysPath = GetKeysFilePath();
GConfig->LoadFile(C3DSettingsPath);
GConfig->LoadFile(C3DKeysPath);
GConfig->SetString(TEXT("Analytics"), TEXT("ApiKey"), *key, C3DSettingsPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);

ConfigFileHasChanged = true;

Expand All @@ -3613,9 +3650,12 @@ void FCognitiveEditorTools::SaveApplicationKeyToFile(FString key)
void FCognitiveEditorTools::SaveDeveloperKeyToFile(FString key)
{
FString C3DSettingsPath = GetSettingsFilePath();
FString C3DKeysPath = GetKeysFilePath();
GConfig->LoadFile(C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *key, C3DSettingsPath);
GConfig->LoadFile(C3DKeysPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *key, C3DKeysPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);

ConfigFileHasChanged = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ class FCognitiveEditorTools
bool HasApplicationKey() const;

FString GetSettingsFilePath() const;
FString GetKeysFilePath() const;

//send a http request to get the scene version data for current scene from sceneexplorer
FReply ButtonCurrentSceneVersionRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,16 @@ void ICognitiveSettingsCustomization::CustomizeDetails(IDetailLayoutBuilder& Det
FCognitiveEditorTools::GetInstance()->CurrentSceneVersionRequest();

FString C3DSettingsPath = FCognitiveEditorTools::GetInstance()->GetSettingsFilePath();
FString C3DKeysPath = FCognitiveEditorTools::GetInstance()->GetKeysFilePath();
// Explicitly load the custom config file into GConfig.
GConfig->LoadFile(C3DSettingsPath);
GConfig->LoadFile(C3DKeysPath);
GConfig->GetString(TEXT("Analytics"), TEXT("AttributionKey"), FCognitiveEditorTools::GetInstance()->AttributionKey, C3DSettingsPath);
GConfig->GetString(TEXT("Analytics"), TEXT("ApiKey"), FCognitiveEditorTools::GetInstance()->ApplicationKey, C3DSettingsPath);
GConfig->GetString(TEXT("Analytics"), TEXT("DeveloperKey"), FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DSettingsPath);
GConfig->GetString(TEXT("Analytics"), TEXT("DeveloperKey"), FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DKeysPath);

GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);

if (FCognitiveEditorTools::GetInstance()->DeveloperKey.IsEmpty() || FCognitiveEditorTools::GetInstance()->ApplicationKey.IsEmpty()
|| FCognitiveEditorTools::GetInstance()->BaseExportDirectory.IsEmpty())
Expand All @@ -263,9 +266,10 @@ void ICognitiveSettingsCustomization::CustomizeDetails(IDetailLayoutBuilder& Det

GConfig->SetString(TEXT("Analytics"), TEXT("ApiKey"), *FCognitiveEditorTools::GetInstance()->ApplicationKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("AttributionKey"), *FCognitiveEditorTools::GetInstance()->AttributionKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DKeysPath);
GConfig->SetString(TEXT("Analytics"), TEXT("ExportPath"), *FCognitiveEditorTools::GetInstance()->BaseExportDirectory, C3DSettingsPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);
#else
GConfig->GetString(TEXT("Analytics"), TEXT("ApiKey"), FCognitiveEditorTools::GetInstance()->ApplicationKey, EngineIni);
GConfig->GetString(TEXT("Analytics"), TEXT("AttributionKey"), FCognitiveEditorTools::GetInstance()->AttributionKey, EngineIni);
Expand All @@ -274,9 +278,10 @@ void ICognitiveSettingsCustomization::CustomizeDetails(IDetailLayoutBuilder& Det

GConfig->SetString(TEXT("Analytics"), TEXT("ApiKey"), *FCognitiveEditorTools::GetInstance()->ApplicationKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("AttributionKey"), *FCognitiveEditorTools::GetInstance()->AttributionKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DSettingsPath);
GConfig->SetString(TEXT("Analytics"), TEXT("DeveloperKey"), *FCognitiveEditorTools::GetInstance()->DeveloperKey, C3DKeysPath);
GConfig->SetString(TEXT("Analytics"), TEXT("ExportPath"), *FCognitiveEditorTools::GetInstance()->BaseExportDirectory, C3DSettingsPath);
GConfig->Flush(false, C3DSettingsPath);
GConfig->Flush(false, C3DKeysPath);
#endif // ENGINE_MAJOR_VERSION == 4
}

Expand Down