2021-05-03 02:47:29 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "VirtualizationUtilities.h"
|
|
|
|
|
|
2022-02-02 02:21:24 -05:00
|
|
|
#include "IO/IoHash.h"
|
2021-05-03 02:47:29 -04:00
|
|
|
#include "Misc/StringBuilder.h"
|
|
|
|
|
|
|
|
|
|
namespace UE::Virtualization::Utils
|
|
|
|
|
{
|
|
|
|
|
|
2022-02-02 02:21:24 -05:00
|
|
|
void PayloadIdToPath(const FIoHash& Id, FStringBuilderBase& OutPath)
|
2021-05-03 02:47:29 -04:00
|
|
|
{
|
|
|
|
|
OutPath.Reset();
|
|
|
|
|
OutPath << Id;
|
|
|
|
|
|
|
|
|
|
TStringBuilder<10> Directory;
|
|
|
|
|
Directory << OutPath.ToView().Left(2) << TEXT("/");
|
|
|
|
|
Directory << OutPath.ToView().Mid(2, 2) << TEXT("/");
|
|
|
|
|
Directory << OutPath.ToView().Mid(4, 2) << TEXT("/");
|
|
|
|
|
|
|
|
|
|
OutPath.ReplaceAt(0, 6, Directory);
|
|
|
|
|
|
2022-02-25 16:06:09 -05:00
|
|
|
OutPath << TEXT(".upayload");
|
2021-05-03 02:47:29 -04:00
|
|
|
}
|
|
|
|
|
|
2022-02-02 02:21:24 -05:00
|
|
|
FString PayloadIdToPath(const FIoHash& Id)
|
2021-05-03 02:47:29 -04:00
|
|
|
{
|
|
|
|
|
TStringBuilder<52> Path;
|
|
|
|
|
PayloadIdToPath(Id, Path);
|
|
|
|
|
|
|
|
|
|
return FString(Path);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 21:21:22 -04:00
|
|
|
void GetFormattedSystemError(FStringBuilderBase& SystemErrorMessage)
|
|
|
|
|
{
|
|
|
|
|
SystemErrorMessage.Reset();
|
|
|
|
|
|
|
|
|
|
const uint32 SystemError = FPlatformMisc::GetLastError();
|
|
|
|
|
// If we have a system error we can give a more informative error message but don't output it if the error is zero as
|
|
|
|
|
// this can lead to very confusing error messages.
|
|
|
|
|
if (SystemError != 0)
|
|
|
|
|
{
|
|
|
|
|
TCHAR SystemErrorMsg[MAX_SPRINTF] = { 0 };
|
|
|
|
|
FPlatformMisc::GetSystemErrorMessage(SystemErrorMsg, sizeof(SystemErrorMsg), SystemError);
|
|
|
|
|
|
|
|
|
|
SystemErrorMessage.Appendf(TEXT("'%s' (%d)"), SystemErrorMsg, SystemError);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SystemErrorMessage << TEXT("'unknown reason' (0)");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-03 02:47:29 -04:00
|
|
|
} // namespace UE::Virtualization::Utils
|