IdentityProvider.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <DefaultClientIdProvider.h>
  9. #include <AzCore/IO/SystemFile.h>
  10. #include <AzCore/Settings/SettingsRegistryImpl.h>
  11. #include <AzCore/Settings/SettingsRegistryMergeUtils.h>
  12. #include <AzCore/Utils/Utils.h>
  13. namespace AWSMetrics
  14. {
  15. constexpr const char* EngineVersionJsonKeyFileFormat1 = "O3DEVersion";
  16. constexpr const char* EngineVersionJsonKeyFileFormat2 = "display_version";
  17. AZStd::unique_ptr<IdentityProvider> IdentityProvider::CreateIdentityProvider()
  18. {
  19. return AZStd::make_unique<DefaultClientIdProvider>(GetEngineVersion());
  20. }
  21. AZStd::string IdentityProvider::GetEngineVersion()
  22. {
  23. constexpr auto rootKey = AZ::SettingsRegistryInterface::FixedValueString(AZ::SettingsRegistryMergeUtils::EngineSettingsRootKey);
  24. constexpr auto engineVersionKeyFileFormat1 = rootKey + "/" + EngineVersionJsonKeyFileFormat1;
  25. constexpr auto engineVersionKeyFileFormat2 = rootKey + "/" + EngineVersionJsonKeyFileFormat2;
  26. AZStd::string engineVersion;
  27. if(auto settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry != nullptr)
  28. {
  29. // prefer latest file format
  30. if(settingsRegistry->Get(engineVersion, engineVersionKeyFileFormat2))
  31. {
  32. return engineVersion;
  33. }
  34. else if(settingsRegistry->Get(engineVersion, engineVersionKeyFileFormat1))
  35. {
  36. return engineVersion;
  37. }
  38. }
  39. auto engineSettingsPath = AZ::IO::FixedMaxPath{ AZ::Utils::GetEnginePath() } / "engine.json";
  40. if (AZ::IO::SystemFile::Exists(engineSettingsPath.c_str()))
  41. {
  42. AZ::SettingsRegistryImpl settingsRegistry;
  43. if (settingsRegistry.MergeSettingsFile(
  44. engineSettingsPath.Native(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, AZ::SettingsRegistryMergeUtils::EngineSettingsRootKey))
  45. {
  46. if(!settingsRegistry.Get(engineVersion, engineVersionKeyFileFormat2))
  47. {
  48. settingsRegistry.Get(engineVersion, engineVersionKeyFileFormat1);
  49. }
  50. }
  51. }
  52. return engineVersion;
  53. }
  54. }