GameCrashHandler.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // LY Editor Crashpad Hook
  9. #include <CrashReporting/GameCrashHandler.h>
  10. #include <CrashSupport.h>
  11. #include <AzCore/Component/ComponentApplicationBus.h>
  12. #include <AzCore/IO/FileIO.h>
  13. #include <AzCore/IO/SystemFile.h>
  14. #include <AzCore/Module/Module.h>
  15. namespace CrashHandler
  16. {
  17. void GameCrashHandler::InitCrashHandler(const std::string& moduleTag, const std::string& devRoot, const std::string& crashUrl, const std::string& crashToken, const std::string& handlerFolder, const CrashHandlerAnnotations& baseAnnotations, const CrashHandlerArguments& argumentVec)
  18. {
  19. GameCrashHandler crashHandler;
  20. crashHandler.Initialize( moduleTag, devRoot, crashUrl, crashToken, handlerFolder, baseAnnotations, argumentVec);
  21. }
  22. std::string GameCrashHandler::GetCrashSubmissionURL() const
  23. {
  24. #if defined(CRASH_HANDLER_URL)
  25. return MAKE_DEFINE_STRING(CRASH_HANDLER_URL);
  26. #else
  27. return "https://lumberyard.sp.backtrace.io:8443/";
  28. #endif
  29. }
  30. std::string GameCrashHandler::GetCrashSubmissionToken() const
  31. {
  32. std::string configToken = GetConfigSubmissionToken();
  33. if (configToken.length())
  34. {
  35. return configToken;
  36. }
  37. #if defined(CRASH_HANDLER_TOKEN)
  38. return MAKE_DEFINE_STRING(CRASH_HANDLER_TOKEN);
  39. #else
  40. // Add your crash upload token here
  41. return "";
  42. #endif
  43. }
  44. std::string GameCrashHandler::DetermineAppPath() const
  45. {
  46. AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
  47. if (fileIO)
  48. {
  49. // If our user alias is available, use that
  50. const char* userAlias = fileIO->GetAlias("@user@");
  51. if (userAlias)
  52. {
  53. return userAlias;
  54. }
  55. }
  56. return GetAppRootFromCWD();
  57. }
  58. std::string GameCrashHandler::GetCrashHandlerPath(const std::string& basePath) const
  59. {
  60. std::string returnPath;
  61. if (basePath.length())
  62. {
  63. returnPath = basePath.c_str();
  64. }
  65. else
  66. {
  67. AZStd::string enginePath;
  68. AZ::ComponentApplicationBus::BroadcastResult(enginePath, &AZ::ComponentApplicationBus::Events::GetExecutableFolder);
  69. if (enginePath.length())
  70. {
  71. returnPath = enginePath.c_str();
  72. }
  73. else
  74. {
  75. GetExecutableFolder(returnPath);
  76. }
  77. }
  78. returnPath += GetCrashHandlerExecutableName();
  79. return returnPath;
  80. }
  81. }
  82. #if defined(O3DE_GEM_NAME)
  83. AZ_DECLARE_MODULE_CLASS(AZ_JOIN(Gem_, O3DE_GEM_NAME), AZ::Module)
  84. #else
  85. AZ_DECLARE_MODULE_CLASS(Gem_CrashReporting, AZ::Module)
  86. #endif