|
| 1 | +// Copyright 2023 BugSplat. All Rights Reserved. |
| 2 | + |
| 3 | +#include "BugSplatCrashReportClient.h" |
| 4 | +#include <Developer/DesktopPlatform/Public/DesktopPlatformModule.h> |
| 5 | +#include <Modules/BuildVersion.h> |
| 6 | +#include <Runtime/Core/Public/Misc/EngineVersionComparison.h> |
| 7 | + |
| 8 | +#include "BugSplatEditorSettings.h" |
| 9 | +#include "BugSplatRuntime.h" |
| 10 | + |
| 11 | +FBugSplatCrashReportClient::FBugSplatCrashReportClient() |
| 12 | +{ |
| 13 | + |
| 14 | +} |
| 15 | + |
| 16 | +FString FBugSplatCrashReportClient::CreateBugSplatEndpointUrl(FString Database, FString App, FString Version) |
| 17 | +{ |
| 18 | + FStringFormatOrderedArguments args; |
| 19 | + |
| 20 | + FString Space = " "; |
| 21 | + FString EncodedSpace = "%20"; |
| 22 | + args.Add(Database); |
| 23 | + args.Add(App.Replace(*Space, *EncodedSpace)); |
| 24 | + args.Add(Version.Replace(*Space, *EncodedSpace)); |
| 25 | + |
| 26 | + return *FString::Format(*BUGSPLAT_ENDPOINT_URL_FORMAT, args); |
| 27 | +} |
| 28 | + |
| 29 | +void FBugSplatCrashReportClient::UpdateCrashReportClientIni(FString Database, FString App, FString Version, FString DefaultEngineIniFilePath) |
| 30 | +{ |
| 31 | + if (!FPaths::FileExists(DefaultEngineIniFilePath)) |
| 32 | + { |
| 33 | + FMessageDialog::Debugf(FText::FromString("Could not find DefaultEngine.ini!")); |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + FConfigCacheIni ini(EConfigCacheType::DiskBacked); |
| 38 | + |
| 39 | + ini.LoadFile(DefaultEngineIniFilePath); |
| 40 | + |
| 41 | + FString SectionTag = FString(TEXT("CrashReportClient")); |
| 42 | + |
| 43 | + FString DataRouterUrlConfigTag = FString(TEXT("DataRouterUrl")); |
| 44 | + FString DataRouterUrlValue = CreateBugSplatEndpointUrl(Database, App, Version); |
| 45 | + |
| 46 | + FString CrashReportClientVersionConfigTag = FString(TEXT("CrashReportClientVersion")); |
| 47 | + FString CrashReportClientVersionValue = FString(TEXT("1.0")); |
| 48 | + |
| 49 | + ini.SetString(*SectionTag, *DataRouterUrlConfigTag, *DataRouterUrlValue, DefaultEngineIniFilePath); |
| 50 | + ini.SetString(*SectionTag, *CrashReportClientVersionConfigTag, *CrashReportClientVersionValue, DefaultEngineIniFilePath); |
| 51 | +} |
| 52 | + |
| 53 | +void FBugSplatCrashReportClient::UpdateEngineSettings() |
| 54 | +{ |
| 55 | + UBugSplatEditorSettings* RuntimeSettings = FBugSplatRuntimeModule::Get().GetSettings(); |
| 56 | + |
| 57 | + if (!RuntimeSettings->HasValidCrashReporterSettings()) |
| 58 | + { |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + if (!RuntimeSettings->bUpdateEngineDataRouterUrl) |
| 63 | + { |
| 64 | + return; |
| 65 | + } |
| 66 | + |
| 67 | + UpdateCrashReportClientIni( |
| 68 | + RuntimeSettings->BugSplatDatabase, |
| 69 | + RuntimeSettings->BugSplatApp, |
| 70 | + RuntimeSettings->BugSplatVersion, |
| 71 | + *GLOBAL_CRASH_REPORT_CLIENT_CONFIG_PATH |
| 72 | + ); |
| 73 | +} |
| 74 | + |
| 75 | +void FBugSplatCrashReportClient::UpdatePackagedBuildSettings() |
| 76 | +{ |
| 77 | + FString PackagedBuildFolderPath; |
| 78 | + |
| 79 | + if (!FDesktopPlatformModule::Get()->OpenDirectoryDialog( |
| 80 | + FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr), |
| 81 | + FString("Packaged Directory"), |
| 82 | + FPaths::GetProjectFilePath(), |
| 83 | + PackagedBuildFolderPath)) |
| 84 | + { |
| 85 | + return; |
| 86 | + } |
| 87 | + |
| 88 | + UBugSplatEditorSettings* RuntimeSettings = FBugSplatRuntimeModule::Get().GetSettings(); |
| 89 | + |
| 90 | + if (!RuntimeSettings->HasValidCrashReporterSettings()) |
| 91 | + { |
| 92 | + FMessageDialog::Debugf(FText::FromString("Invalid settings, update plugin fields and try again.")); |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + FString Platforms[] = { |
| 97 | + TEXT("Windows"), |
| 98 | + TEXT("Linux"), |
| 99 | + TEXT("Mac") |
| 100 | + }; |
| 101 | + bool FoundAnyValidFolders = false; |
| 102 | + |
| 103 | + for (auto &Platform : Platforms) |
| 104 | + { |
| 105 | + FString PlatformTarget = GetPackagedBuildPlatformTarget(Platform); |
| 106 | + FString PlatformTargetPath = *FPaths::Combine(PackagedBuildFolderPath, PlatformTarget); |
| 107 | + |
| 108 | + if (!FPaths::DirectoryExists(PlatformTargetPath)) |
| 109 | + { |
| 110 | + continue; |
| 111 | + } |
| 112 | + |
| 113 | + FoundAnyValidFolders = true; |
| 114 | + FString DefaultEngineIniRelativePath = GetPackagedBuildDefaultEngineIniRelativePath(); |
| 115 | + FString DefaultEngineIniFolderPath = *FPaths::Combine(PackagedBuildFolderPath, *PlatformTarget, *DefaultEngineIniRelativePath); |
| 116 | + FString DefaultEngineIniFilePath = *FPaths::Combine(*DefaultEngineIniFolderPath, *INI_FILE_NAME); |
| 117 | + |
| 118 | + if (!FPaths::DirectoryExists(DefaultEngineIniFolderPath)) |
| 119 | + { |
| 120 | + IPlatformFile &PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); |
| 121 | + PlatformFile.CreateDirectoryTree(*DefaultEngineIniFolderPath); |
| 122 | + |
| 123 | + if (!FPaths::DirectoryExists(DefaultEngineIniFolderPath)) |
| 124 | + { |
| 125 | + FMessageDialog::Debugf(FText::FromString("Failed to create " + DefaultEngineIniFolderPath)); |
| 126 | + return; |
| 127 | + } |
| 128 | + |
| 129 | + CreateEmptyTextFile(DefaultEngineIniFilePath); |
| 130 | + |
| 131 | + if (!FPaths::FileExists(DefaultEngineIniFilePath)) |
| 132 | + { |
| 133 | + FMessageDialog::Debugf(FText::FromString("Failed to create " + DefaultEngineIniFilePath)); |
| 134 | + return; |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + UpdateCrashReportClientIni( |
| 139 | + RuntimeSettings->BugSplatDatabase, |
| 140 | + RuntimeSettings->BugSplatApp, |
| 141 | + RuntimeSettings->BugSplatVersion, |
| 142 | + DefaultEngineIniFilePath |
| 143 | + ); |
| 144 | + } |
| 145 | + |
| 146 | + if (!FoundAnyValidFolders) |
| 147 | + { |
| 148 | + FMessageDialog::Debugf(FText::FromString("Could not find any packaged build directories to update. Please specify the root directory of a valid packaged build.")); |
| 149 | + return; |
| 150 | + } |
| 151 | + |
| 152 | + FMessageDialog::Debugf(FText::FromString("Packaged build settings updated successfully!")); |
| 153 | +} |
| 154 | + |
| 155 | +void FBugSplatCrashReportClient::CreateEmptyTextFile(FString FullPath) |
| 156 | +{ |
| 157 | + FString Empty = FString(""); |
| 158 | + FFileHelper::SaveStringToFile(Empty, *FullPath); |
| 159 | +} |
| 160 | + |
| 161 | +FString FBugSplatCrashReportClient::GetPackagedBuildPlatformTarget(FString Platform) |
| 162 | +{ |
| 163 | + return ENGINE_MAJOR_VERSION >= 5 ? Platform : Platform + TEXT("NoEditor"); |
| 164 | +} |
| 165 | + |
| 166 | +FString FBugSplatCrashReportClient::GetPackagedBuildDefaultEngineIniRelativePath() |
| 167 | +{ |
| 168 | + if (ENGINE_MAJOR_VERSION == 5) |
| 169 | + { |
| 170 | + return PACKAGED_BUILD_CONFIG_PATH_5; |
| 171 | + } |
| 172 | + else if (ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION >= 26) |
| 173 | + { |
| 174 | + return PACKAGED_BUILD_CONFIG_PATH_4_26_TO_5; |
| 175 | + } |
| 176 | + |
| 177 | + return PACKAGED_BUILD_CONFIG_PATH_4_25_AND_OLDER; |
| 178 | +} |
0 commit comments