in Ambit/Source/Ambit/Mode/ConfigImportExport.cpp [754:826]
bool UConfigImportExport::WriteJsonFile(const TSharedPtr<FJsonObject>& OutputContents, const FString& FileName,
const FString& FileExtension, bool bToS3)
{
const FAmbitMode* AmbitMode = FAmbitMode::GetEditorMode();
const FString& OutputString = FJsonHelpers::SerializeJson(OutputContents);
if (OutputString.IsEmpty() || FileName.IsEmpty() || FileExtension.IsEmpty())
{
FMenuHelpers::LogErrorAndPopup("Error Serializing File.");
return false;
}
const FString OutputFileName = FileName + FileExtension;
if (bToS3)
{
try
{
FString AwsRegion;
FString BucketName;
const bool bFoundBucket = GetAwsSettings(AwsRegion, BucketName, true);
if (!bFoundBucket)
{
return false;
}
FString BscConfigurationName = GetDefaultConfigurationName();
if (!AmbitMode->UISettings->ConfigurationName.IsEmpty())
{
BscConfigurationName = AmbitMode->UISettings->ConfigurationName;
}
// Write the file into the specified path. For SDF, we layer one step down into the sub-folder.
FString S3Path;
if (FileExtension == FileExtensions::KSDFExtension)
{
S3Path = FPaths::Combine(GetS3ExportFolderPrefix() + BscConfigurationName, OutputFileName);
}
else
{
S3Path = OutputFileName;
}
UE_LOG(LogAmbit, Display, TEXT("Writing Json object to Amazon S3 Path: %s"), *S3Path);
return LambdaPutS3Object(AwsRegion, BucketName, S3Path, OutputString);
}
catch (const std::invalid_argument& Ia)
{
const FString ErrorMessage = "WriteJsonFile failed with invalid argument error: " + FString(Ia.what());
FMenuHelpers::LogErrorAndPopup(ErrorMessage);
return false;
}
catch (const std::runtime_error& Re)
{
const FString ErrorMessage = "WriteJsonFile failed with runtime error: " + FString(Re.what());
FMenuHelpers::LogErrorAndPopup(ErrorMessage);
return false;
}
}
const FString OutFile = LambdaGetPathFromPopup(FileExtension, "", OutputFileName);
if (!OutFile.IsEmpty())
{
LambdaWriteFileToDisk(OutFile, OutputString);
}
else
{
return false;
}
return true;
}