StandaloneToolsApplication.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "StandaloneToolsApplication.h"
  9. #include <AzCore/IO/Streamer/StreamerComponent.h>
  10. #include <AzCore/Jobs/JobManagerComponent.h>
  11. #include <AzCore/UserSettings/UserSettingsComponent.h>
  12. #include <AzCore/std/containers/array.h>
  13. #include <AzFramework/API/ApplicationAPI.h>
  14. #include <AzFramework/Asset/AssetCatalogComponent.h>
  15. #include <AzFramework/Network/IRemoteTools.h>
  16. #include <AzFramework/Script/ScriptRemoteDebuggingConstants.h>
  17. #include <AzFramework/StringFunc/StringFunc.h>
  18. #include <AzNetworking/Framework/INetworkInterface.h>
  19. #include <AzNetworking/Framework/INetworking.h>
  20. #include <AzNetworking/Framework/NetworkingSystemComponent.h>
  21. #include <AzToolsFramework/UI/LegacyFramework/Core/IPCComponent.h>
  22. namespace StandaloneTools
  23. {
  24. BaseApplication::BaseApplication(int argc, char** argv)
  25. : LegacyFramework::Application(argc, argv)
  26. {
  27. AZ::UserSettingsFileLocatorBus::Handler::BusConnect();
  28. }
  29. BaseApplication::~BaseApplication()
  30. {
  31. AZ::UserSettingsFileLocatorBus::Handler::BusDisconnect();
  32. }
  33. void BaseApplication::RegisterCoreComponents()
  34. {
  35. LegacyFramework::Application::RegisterCoreComponents();
  36. RegisterComponentDescriptor(LegacyFramework::IPCComponent::CreateDescriptor());
  37. RegisterComponentDescriptor(AzNetworking::NetworkingSystemComponent::CreateDescriptor());
  38. RegisterComponentDescriptor(AZ::UserSettingsComponent::CreateDescriptor());
  39. RegisterComponentDescriptor(AZ::JobManagerComponent::CreateDescriptor());
  40. RegisterComponentDescriptor(AZ::StreamerComponent::CreateDescriptor());
  41. }
  42. void BaseApplication::CreateSystemComponents()
  43. {
  44. LegacyFramework::Application::CreateSystemComponents();
  45. // AssetCatalogComponent was moved to the Application Entity to fulfil service requirements.
  46. EnsureComponentRemoved(AzFramework::AssetCatalogComponent::RTTI_Type());
  47. }
  48. void BaseApplication::CreateApplicationComponents()
  49. {
  50. EnsureComponentCreated(AZ::StreamerComponent::RTTI_Type());
  51. EnsureComponentCreated(AZ::JobManagerComponent::RTTI_Type());
  52. EnsureComponentCreated(AzNetworking::NetworkingSystemComponent::RTTI_Type());
  53. EnsureComponentCreated(LegacyFramework::IPCComponent::RTTI_Type());
  54. // Check for user settings components already added (added by the app descriptor
  55. AZStd::array<bool, AZ::UserSettings::CT_MAX> userSettingsAdded;
  56. userSettingsAdded.fill(false);
  57. for (const auto& component : m_applicationEntity->GetComponents())
  58. {
  59. if (const auto userSettings = azrtti_cast<AZ::UserSettingsComponent*>(component))
  60. {
  61. userSettingsAdded[userSettings->GetProviderId()] = true;
  62. }
  63. }
  64. // For each provider not already added, add it.
  65. for (AZ::u32 providerId = 0; providerId < userSettingsAdded.size(); ++providerId)
  66. {
  67. if (!userSettingsAdded[providerId])
  68. {
  69. // Don't need to add one for global, that's added by someone else
  70. m_applicationEntity->AddComponent(aznew AZ::UserSettingsComponent(providerId));
  71. }
  72. }
  73. }
  74. bool BaseApplication::StartDebugService()
  75. {
  76. #if defined(ENABLE_REMOTE_TOOLS)
  77. auto* remoteToolsInterface = AzFramework::RemoteToolsInterface::Get();
  78. if (remoteToolsInterface)
  79. {
  80. remoteToolsInterface->RegisterToolingServiceHost(
  81. AzFramework::LuaToolsKey, AzFramework::LuaToolsName, AzFramework::LuaToolsPort);
  82. return true;
  83. }
  84. #endif
  85. return false;
  86. }
  87. void BaseApplication::OnApplicationEntityActivated()
  88. {
  89. [[maybe_unused]] bool launched = StartDebugService();
  90. AZ_Warning("EditorApplication", launched, "Could not start hosting; Only replay is available.");
  91. }
  92. void BaseApplication::SetSettingsRegistrySpecializations(AZ::SettingsRegistryInterface::Specializations& specializations)
  93. {
  94. ComponentApplication::SetSettingsRegistrySpecializations(specializations);
  95. specializations.Append("luaide");
  96. }
  97. AZStd::string BaseApplication::GetStoragePath() const
  98. {
  99. AZStd::string storagePath;
  100. FrameworkApplicationMessages::Bus::BroadcastResult(storagePath, &FrameworkApplicationMessages::GetApplicationGlobalStoragePath);
  101. if (storagePath.empty())
  102. {
  103. FrameworkApplicationMessages::Bus::BroadcastResult(storagePath, &FrameworkApplicationMessages::GetApplicationDirectory);
  104. }
  105. return storagePath;
  106. }
  107. AZStd::string BaseApplication::ResolveFilePath(AZ::u32 providerId)
  108. {
  109. AZStd::string appName;
  110. FrameworkApplicationMessages::Bus::BroadcastResult(appName, &FrameworkApplicationMessages::GetApplicationName);
  111. AZStd::string userStoragePath = GetStoragePath();
  112. AzFramework::StringFunc::Path::Join(userStoragePath.c_str(), appName.c_str(), userStoragePath);
  113. AZ::IO::SystemFile::CreateDir(userStoragePath.c_str());
  114. AZStd::string fileName;
  115. switch (providerId)
  116. {
  117. case AZ::UserSettings::CT_LOCAL:
  118. fileName = AZStd::string::format("%s_UserSettings.xml", appName.c_str());
  119. break;
  120. case AZ::UserSettings::CT_GLOBAL:
  121. fileName = "GlobalUserSettings.xml";
  122. break;
  123. }
  124. AzFramework::StringFunc::Path::Join(userStoragePath.c_str(), fileName.c_str(), userStoragePath);
  125. return userStoragePath;
  126. }
  127. } // namespace StandaloneTools