diff --git a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/AndroidPlugin.h b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/AndroidPlugin.h index 1559be94..e6b8b8ac 100644 --- a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/AndroidPlugin.h +++ b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/AndroidPlugin.h @@ -31,6 +31,7 @@ class UAndroidPlugin : public UActorComponent void OnSessionEnd(); FString C3DSettingsPath; + FString C3DKeysPath; FString FolderPath; FString FolderPathCrashLog; diff --git a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/RemoteControls.cpp b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/RemoteControls.cpp index 9d68fc4d..aed6bd16 100644 --- a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/RemoteControls.cpp +++ b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/C3DComponents/RemoteControls.cpp @@ -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); @@ -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); diff --git a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/Cognitive3D.cpp b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/Cognitive3D.cpp index b7818de9..6e768787 100644 --- a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/Cognitive3D.cpp +++ b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3D/Private/Cognitive3D.cpp @@ -428,6 +428,7 @@ bool FAnalyticsProviderCognitive3D::StartSession(const TArrayGetSettingsFilePath(); + 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()) @@ -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); @@ -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 } diff --git a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.cpp b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.cpp index 90a1ea5a..3925ecbc 100644 --- a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.cpp +++ b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.cpp @@ -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; @@ -3587,11 +3618,14 @@ TArray> 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; @@ -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; @@ -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; diff --git a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.h b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.h index e1fdc09b..14806be1 100644 --- a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.h +++ b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveEditorTools.h @@ -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(); diff --git a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveSettingsCustomization.cpp b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveSettingsCustomization.cpp index 2edaf9e5..d72b6a41 100644 --- a/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveSettingsCustomization.cpp +++ b/Cognitive3DTest/Plugins/Cognitive3D/Source/Cognitive3DEditor/Private/CognitiveSettingsCustomization.cpp @@ -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()) @@ -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); @@ -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 }