|
|
|
|
@ -31,7 +31,7 @@ namespace AZ
|
|
|
|
|
// Platform specific get exe path: http://stackoverflow.com/a/1024937
|
|
|
|
|
// https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getmodulefilenamea
|
|
|
|
|
wchar_t pathBufferW[AZ::IO::MaxPathLength] = { 0 };
|
|
|
|
|
const DWORD pathLen = GetModuleFileNameW(nullptr, pathBufferW, static_cast<DWORD>(exeStorageSize));
|
|
|
|
|
const DWORD pathLen = GetModuleFileNameW(nullptr, pathBufferW, static_cast<DWORD>(AZStd::size(pathBufferW)));
|
|
|
|
|
const DWORD errorCode = GetLastError();
|
|
|
|
|
if (pathLen == exeStorageSize && errorCode == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
|
{
|
|
|
|
|
@ -43,7 +43,15 @@ namespace AZ
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AZStd::to_string(exeStorageBuffer, exeStorageSize, pathBufferW);
|
|
|
|
|
size_t utf8PathSize = Utf8::Unchecked::utf16ToUtf8BytesRequired(pathBufferW, pathBufferW + pathLen);
|
|
|
|
|
if (utf8PathSize >= exeStorageSize)
|
|
|
|
|
{
|
|
|
|
|
result.m_pathStored = ExecutablePathResult::BufferSizeNotLargeEnough;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AZStd::to_string(exeStorageBuffer, exeStorageSize, pathBufferW);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|