diff --git a/Code/Editor/BaseLibrary.cpp b/Code/Editor/BaseLibrary.cpp index ee1c85756d..3c3ccfe13d 100644 --- a/Code/Editor/BaseLibrary.cpp +++ b/Code/Editor/BaseLibrary.cpp @@ -258,9 +258,8 @@ bool CBaseLibrary::SaveLibrary(const char* name, bool saveEmptyLibrary) } if (!bRes) { - string strMessage; QByteArray filenameUtf8 = fileName.toUtf8(); - strMessage.Format("The file %s is read-only and the save of the library couldn't be performed. Try to remove the \"read-only\" flag or check-out the file and then try again.", filenameUtf8.data()); + AZStd::string strMessage = AZStd::string::format("The file %s is read-only and the save of the library couldn't be performed. Try to remove the \"read-only\" flag or check-out the file and then try again.", filenameUtf8.data()); CryMessageBox(strMessage.c_str(), "Saving Error", MB_OK | MB_ICONWARNING); } return bRes; diff --git a/Code/Editor/Core/QtEditorApplication.cpp b/Code/Editor/Core/QtEditorApplication.cpp index 46e789cd7c..9ec3b57e29 100644 --- a/Code/Editor/Core/QtEditorApplication.cpp +++ b/Code/Editor/Core/QtEditorApplication.cpp @@ -206,11 +206,8 @@ namespace static void LogToDebug([[maybe_unused]] QtMsgType Type, [[maybe_unused]] const QMessageLogContext& Context, const QString& message) { -#if defined(WIN32) || defined(WIN64) - OutputDebugStringW(L"Qt: "); - OutputDebugStringW(reinterpret_cast(message.utf16())); - OutputDebugStringW(L"\n"); -#endif + AZ::Debug::Platform::OutputToDebugger("Qt", message.utf8()); + AZ::Debug::Platform::OutputToDebugger(nullptr, "\n"); } } diff --git a/Code/Editor/IEditorImpl.cpp b/Code/Editor/IEditorImpl.cpp index c09c0a8e62..2e755bd36a 100644 --- a/Code/Editor/IEditorImpl.cpp +++ b/Code/Editor/IEditorImpl.cpp @@ -1109,7 +1109,7 @@ void CEditorImpl::DetectVersion() char ver[1024 * 8]; - GetModuleFileName(NULL, exe, _MAX_PATH); + AZ::Utils::GetExecutablePath(exe, _MAX_PATH); int verSize = GetFileVersionInfoSize(exe, &dwHandle); if (verSize > 0) diff --git a/Code/Editor/Include/IFileUtil.h b/Code/Editor/Include/IFileUtil.h index f402786e67..8cb86b812e 100644 --- a/Code/Editor/Include/IFileUtil.h +++ b/Code/Editor/Include/IFileUtil.h @@ -8,7 +8,6 @@ #pragma once -#include "StringUtils.h" #include "../Include/SandboxAPI.h" class QWidget; diff --git a/Code/Editor/QtUtil.h b/Code/Editor/QtUtil.h index bb1f8ba427..a9aaadc491 100644 --- a/Code/Editor/QtUtil.h +++ b/Code/Editor/QtUtil.h @@ -10,8 +10,6 @@ #pragma once #include -#include -#include "UnicodeFunctions.h" #include #include @@ -36,28 +34,6 @@ public: namespace QtUtil { - // From QString to CryString - inline CryStringT ToString(const QString& str) - { - return Unicode::Convert >(str); - } - - // From CryString to QString - inline QString ToQString(const CryStringT& str) - { - return Unicode::Convert(str); - } - - // From const char * to QString - inline QString ToQString(const char* str, size_t len = -1) - { - if (len == -1) - { - len = strlen(str); - } - return Unicode::Convert(str, str + len); - } - // Replacement for CString::trimRight() inline QString trimRight(const QString& str) { diff --git a/Code/Editor/Util/FileUtil.h b/Code/Editor/Util/FileUtil.h index 000215e98d..06cceaaafc 100644 --- a/Code/Editor/Util/FileUtil.h +++ b/Code/Editor/Util/FileUtil.h @@ -10,7 +10,6 @@ #pragma once #include "CryThread.h" -#include "StringUtils.h" #include "../Include/SandboxAPI.h" #include #include diff --git a/Code/Editor/Util/PathUtil.cpp b/Code/Editor/Util/PathUtil.cpp index 4bb5c20ece..e91d85e4d2 100644 --- a/Code/Editor/Util/PathUtil.cpp +++ b/Code/Editor/Util/PathUtil.cpp @@ -15,24 +15,20 @@ #include // for ebus events #include #include +#include #include -namespace -{ - string g_currentModName; // folder name only! -} - namespace Path { ////////////////////////////////////////////////////////////////////////// void SplitPath(const QString& rstrFullPathFilename, QString& rstrDriveLetter, QString& rstrDirectory, QString& rstrFilename, QString& rstrExtension) { - string strFullPathString(rstrFullPathFilename.toUtf8().data()); - string strDriveLetter; - string strDirectory; - string strFilename; - string strExtension; + AZStd::string strFullPathString(rstrFullPathFilename.toUtf8().data()); + AZStd::string strDriveLetter; + AZStd::string strDirectory; + AZStd::string strFilename; + AZStd::string strExtension; char* szPath((char*)strFullPathString.c_str()); char* pchLastPosition(szPath); @@ -81,16 +77,16 @@ namespace Path strFilename.assign(pchLastPosition, pchCurrentPosition); } - rstrDriveLetter = strDriveLetter; - rstrDirectory = strDirectory; - rstrFilename = strFilename; - rstrExtension = strExtension; + rstrDriveLetter = strDriveLetter.c_str(); + rstrDirectory = strDirectory.c_str(); + rstrFilename = strFilename.c_str(); + rstrExtension = strExtension.c_str(); } ////////////////////////////////////////////////////////////////////////// void GetDirectoryQueue(const QString& rstrSourceDirectory, QStringList& rcstrDirectoryTree) { - string strCurrentDirectoryName; - string strSourceDirectory(rstrSourceDirectory.toUtf8().data()); + AZStd::string strCurrentDirectoryName; + AZStd::string strSourceDirectory(rstrSourceDirectory.toUtf8().data()); const char* szSourceDirectory(strSourceDirectory.c_str()); const char* pchCurrentPosition(szSourceDirectory); const char* pchLastPosition(szSourceDirectory); @@ -207,7 +203,9 @@ namespace Path bool IsFolder(const char* pPath) { - DWORD attrs = GetFileAttributes(pPath); + AZStd::wstring pPathW; + AZStd::to_wstring(pPathW, pPath); + DWORD attrs = GetFileAttributes(pPathW.c_str()); if (attrs == FILE_ATTRIBUTE_DIRECTORY) { @@ -255,16 +253,17 @@ namespace Path /// Get the data folder AZStd::string GetEditingGameDataFolder() { + static AZStd::string s_currentModName; // query the editor root. The bus exists in case we want tools to be able to override this. - if (g_currentModName.empty()) + if (s_currentModName.empty()) { return GetGameAssetsFolder(); } AZStd::string str(GetGameAssetsFolder()); str += "Mods\\"; - str += g_currentModName; + str += s_currentModName; return str; } diff --git a/Code/Editor/Util/PathUtil.h b/Code/Editor/Util/PathUtil.h index 98f484ec94..30887e698b 100644 --- a/Code/Editor/Util/PathUtil.h +++ b/Code/Editor/Util/PathUtil.h @@ -93,7 +93,7 @@ namespace Path #endif file = path_buffer; } - inline void Split(const string& filepath, string& path, string& file) + inline void Split(const AZStd::string& filepath, AZStd::string& path, AZStd::string& file) { char path_buffer[_MAX_PATH]; char drive[_MAX_DRIVE]; @@ -101,7 +101,7 @@ namespace Path char fname[_MAX_FNAME]; char ext[_MAX_EXT]; #ifdef AZ_COMPILER_MSVC - _splitpath_s(filepath, drive, AZ_ARRAY_SIZE(drive), dir, AZ_ARRAY_SIZE(dir), 0, 0, 0, 0); + _splitpath_s(filepath.c_str(), drive, AZ_ARRAY_SIZE(drive), dir, AZ_ARRAY_SIZE(dir), 0, 0, 0, 0); _makepath_s(path_buffer, AZ_ARRAY_SIZE(path_buffer), drive, dir, 0, 0); path = path_buffer; _makepath_s(path_buffer, AZ_ARRAY_SIZE(path_buffer), 0, 0, fname, ext); @@ -137,7 +137,7 @@ namespace Path filename = fname; fext = ext; } - inline void Split(const string& filepath, string& path, string& filename, string& fext) + inline void Split(const AZStd::string& filepath, AZStd::string& path, AZStd::string& filename, AZStd::string& fext) { char path_buffer[_MAX_PATH]; char drive[_MAX_DRIVE]; @@ -145,7 +145,7 @@ namespace Path char fname[_MAX_FNAME]; char ext[_MAX_EXT]; #ifdef AZ_COMPILER_MSVC - _splitpath_s(filepath, drive, AZ_ARRAY_SIZE(drive), dir, AZ_ARRAY_SIZE(dir), fname, AZ_ARRAY_SIZE(fname), ext, AZ_ARRAY_SIZE(ext)); + _splitpath_s(filepath.c_str(), drive, AZ_ARRAY_SIZE(drive), dir, AZ_ARRAY_SIZE(dir), fname, AZ_ARRAY_SIZE(fname), ext, AZ_ARRAY_SIZE(ext)); _makepath_s(path_buffer, AZ_ARRAY_SIZE(path_buffer), drive, dir, 0, 0); #else _splitpath(filepath, drive, dir, fname, ext); @@ -271,7 +271,7 @@ namespace Path } template - inline void AddBackslash(AZstd::fixed_string* path) + inline void AddBackslash(AZStd::fixed_string* path) { if (path->empty()) { @@ -284,7 +284,7 @@ namespace Path } template - inline void AddSlash(AZstd::fixed_string* path) + inline void AddSlash(AZStd::fixed_string* path) { if (path->empty()) { @@ -357,7 +357,7 @@ namespace Path { return CaselessPaths(GetRelativePath(path, true)); } - inline string FullPathToGamePath(const char* path) + inline AZStd::string FullPathToGamePath(const char* path) { return CaselessPaths(GetRelativePath(path, true)).toUtf8().data(); } @@ -394,7 +394,7 @@ namespace Path inline QString GetAudioLocalizationFolder(bool returnAbsolutePath) { // Omit the trailing slash! - QString sLocalizationFolder(QString(PathUtil::GetLocalizationFolder()).left(static_cast(PathUtil::GetLocalizationFolder().size()) - 1)); + QString sLocalizationFolder(QString(PathUtil::GetLocalizationFolder().c_str()).left(static_cast(PathUtil::GetLocalizationFolder().size()) - 1)); if (!sLocalizationFolder.isEmpty()) { diff --git a/Code/Framework/AzCore/AzCore/std/string/conversions.h b/Code/Framework/AzCore/AzCore/std/string/conversions.h index cb90881933..fcfe82ba5f 100644 --- a/Code/Framework/AzCore/AzCore/std/string/conversions.h +++ b/Code/Framework/AzCore/AzCore/std/string/conversions.h @@ -80,9 +80,7 @@ namespace AZStd } else { - // Workaround to defer static_assert evaluation until this function is invoked by using the template parameter - using StringType = AZStd::basic_string; - static_assert(!AZStd::is_same_v, "only wchar_t types of size 2 or 4 can be converted to utf8"); + static_assert(false, "only wchar_t types of size 2 or 4 can be converted to utf8"); } } @@ -123,6 +121,22 @@ namespace AZStd static_assert(!AZStd::is_same_v, "Cannot convert a utf8 string to a wchar_t that isn't size 2 or 4"); } } + + static inline void to_wstring(wchar_t* dest, size_t destSize, const char* first, const char* last) + { + if constexpr (Size == 2) + { + Utf8::Unchecked::utf8to16(first, last, dest, destSize); + } + else if constexpr (Size == 4) + { + Utf8::Unchecked::utf8to32(first, last, dest, destSize); + } + else + { + static_assert(false, "Cannot convert a utf8 string to a wchar_t that isn't size 2 or 4"); + } + } }; } // 21.5: numeric conversions @@ -348,7 +362,7 @@ namespace AZStd { if (srcLen == 0) { - srcLen = wcslen(str) + 1; + srcLen = wcslen(str); } if (srcLen > 0) @@ -497,6 +511,19 @@ namespace AZStd return to_wstring(dest, src.c_str(), src.length()); } + inline void to_wstring(wchar_t* dest, size_t destSize, const char* str, size_t srcLen = 0) + { + if (srcLen == 0) + { + srcLen = strlen(str) + 1; + } + + if (srcLen > 0) + { + Internal::WCharTPlatformConverter<>::to_wstring(dest, destSize, str, str + srcLen + 1); // copy null terminator + } + } + // Convert a range of chars to lower case #if defined(AZSTD_USE_OLD_RW_STL) template diff --git a/Code/Legacy/CryCommon/IStatObj.h b/Code/Legacy/CryCommon/IStatObj.h index ff3bbc41e3..4921ab3a25 100644 --- a/Code/Legacy/CryCommon/IStatObj.h +++ b/Code/Legacy/CryCommon/IStatObj.h @@ -201,7 +201,7 @@ struct IStreamable virtual void StartStreaming(bool bFinishNow, IReadStream_AutoPtr* ppStream) = 0; virtual int GetStreamableContentMemoryUsage(bool bJustForDebug = false) = 0; virtual void ReleaseStreamableContent() = 0; - virtual void GetStreamableName(string& sName) = 0; + virtual void GetStreamableName(AZStd::string& sName) = 0; virtual uint32 GetLastDrawMainFrameId() = 0; virtual bool IsUnloadable() const = 0; @@ -239,8 +239,8 @@ struct IStatObj SSubObject() { bShadowProxy = 0; } EStaticSubObjectType nType; - string name; - string properties; + AZStd::string name; + AZStd::string properties; int nParent; // Index of the parent sub object, if there`s hierarchy between them. Matrix34 tm; // Transformation matrix. Matrix34 localTM; // Local transformation matrix, relative to parent. @@ -510,10 +510,10 @@ struct IStatObj virtual bool IsUnloadable() const = 0; virtual void SetCanUnload(bool value) = 0; - virtual string& GetFileName() = 0; - virtual const string& GetFileName() const = 0; + virtual AZStd::string& GetFileName() = 0; + virtual const AZStd::string& GetFileName() const = 0; - virtual const string& GetCGFNodeName() const = 0; + virtual const AZStd::string& GetCGFNodeName() const = 0; // Summary: // Returns the filename of the object diff --git a/Code/Legacy/CryCommon/IXml.h b/Code/Legacy/CryCommon/IXml.h index a380ce167b..80c2415f9c 100644 --- a/Code/Legacy/CryCommon/IXml.h +++ b/Code/Legacy/CryCommon/IXml.h @@ -101,7 +101,13 @@ public: XmlString(const char* str) : AZStd::string(str) {}; - operator const char*() const { + size_t GetAllocatedMemory() const + { + return sizeof(XmlString) + capacity() * sizeof(AZStd::string::value_type); + } + + operator const char*() const + { return c_str(); } }; diff --git a/Code/Tools/CrashHandler/Support/platform/win/CrashSupport_win.cpp b/Code/Tools/CrashHandler/Support/platform/win/CrashSupport_win.cpp index 3933b5ea91..6010ac8e17 100644 --- a/Code/Tools/CrashHandler/Support/platform/win/CrashSupport_win.cpp +++ b/Code/Tools/CrashHandler/Support/platform/win/CrashSupport_win.cpp @@ -10,13 +10,14 @@ #include #include +#include #include namespace CrashHandler { - void GetExecutablePathA(char* pathBuffer, int& bufferSize) + void GetExecutablePath(char* pathBuffer, int& bufferSize) { - GetModuleFileNameA(nullptr, pathBuffer, bufferSize); + AZ::Utils::GetExecutablePath(pathBuffer, bufferSize); } void GetExecutablePathW(wchar_t* pathBuffer, int& bufferSize) diff --git a/Code/Tools/GridHub/GridHub/gridhub.cpp b/Code/Tools/GridHub/GridHub/gridhub.cpp index 3dbecf681f..978589ab74 100644 --- a/Code/Tools/GridHub/GridHub/gridhub.cpp +++ b/Code/Tools/GridHub/GridHub/gridhub.cpp @@ -358,13 +358,11 @@ GridHubComponent::GridHubComponent() m_isLogToFile = false; #ifdef AZ_PLATFORM_WINDOWS - TCHAR name[MAX_COMPUTERNAME_LENGTH + 1]; + wchar_t name[MAX_COMPUTERNAME_LENGTH + 1]; DWORD dwCompNameLen = AZ_ARRAY_SIZE(name); - if ( GetComputerName(name, &dwCompNameLen) != 0 ) + if (GetComputerName(name, &dwCompNameLen) != 0) { - char c[MAX_COMPUTERNAME_LENGTH + 1]; - wcstombs(c, name, AZ_ARRAY_SIZE(c)); - m_hubName = c; + AZStd::to_string(m_hubName, name); } else #endif diff --git a/Code/Tools/GridHub/GridHub/main.cpp b/Code/Tools/GridHub/GridHub/main.cpp index f02906e0d4..670367bf06 100644 --- a/Code/Tools/GridHub/GridHub/main.cpp +++ b/Code/Tools/GridHub/GridHub/main.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #endif #include "gridhub.hxx" @@ -39,6 +38,7 @@ AZ_POP_DISABLE_WARNING #include #include #include +#include #ifdef AZ_PLATFORM_WINDOWS #include @@ -53,9 +53,9 @@ AZ_POP_DISABLE_WARNING #endif #ifdef AZ_PLATFORM_WINDOWS -#define GRIDHUB_TSR_SUFFIX _T("_copyapp_") -#define GRIDHUB_TSR_NAME _T("GridHub_copyapp_.exe") -#define GRIDHUB_IMAGE_NAME _T("GridHub.exe") +#define GRIDHUB_TSR_SUFFIX L"_copyapp_" +#define GRIDHUB_TSR_NAME L"GridHub_copyapp_.exe" +#define GRIDHUB_IMAGE_NAME L"GridHub.exe" #else #define GRIDHUB_TSR_SUFFIX "_copyapp_" #define GRIDHUB_TSR_NAME "GridHub_copyapp_" @@ -191,7 +191,7 @@ protected: specializations.Append("gridhub"); } - QString m_originalExeFileName; + QString m_originalExeFileName; QDateTime m_originalExeLastModified; bool m_monitorForExeChanges; bool m_needToRelaunch; @@ -305,22 +305,22 @@ public: { #ifdef AZ_PLATFORM_WINDOWS HRESULT hres; - TCHAR startupFolder[MAX_PATH] = {0}; - TCHAR fullLinkName[MAX_PATH] = {0}; + wchar_t startupFolder[MAX_PATH] = {0}; + wchar_t fullLinkName[MAX_PATH] = {0}; LPITEMIDLIST pidlFolder = NULL; hres = SHGetFolderLocation(0,/*CSIDL_COMMON_STARTUP all users required admin access*/CSIDL_STARTUP,NULL,0,&pidlFolder); if (SUCCEEDED(hres)) { - if( SHGetPathFromIDList(pidlFolder,startupFolder) ) + if (SHGetPathFromIDList(pidlFolder, startupFolder)) { - _tcscat_s(fullLinkName,startupFolder); - _tcscat_s(fullLinkName,"\\Amazon Grid Hub.lnk"); + wcscat_s(fullLinkName, startupFolder); + wcscat_s(fullLinkName, L"\\Amazon Grid Hub.lnk"); } CoTaskMemFree(pidlFolder); } - if( moduleFilename.isEmpty() || _tcslen(fullLinkName) == 0 ) + if( moduleFilename.isEmpty() || wcslen(fullLinkName) == 0 ) return; // for development, never autoadd to startup @@ -342,8 +342,8 @@ public: IPersistFile* ppf; // Set the path to the shortcut target and add the description. - psl->SetPath(moduleFilename.toUtf8().data()); - psl->SetDescription("Amazon Grid Hub"); + psl->SetPath(moduleFilename.toStdWString().c_str()); + psl->SetDescription(L"Amazon Grid Hub"); // Query IShellLink for the IPersistFile interface, used for saving the // shortcut in persistent storage. @@ -351,16 +351,8 @@ public: if (SUCCEEDED(hres)) { - WCHAR wsz[MAX_PATH]; - - // Ensure that the string is Unicode. - MultiByteToWideChar(CP_ACP, 0, fullLinkName, -1, wsz, MAX_PATH); - - // Add code here to check return value from MultiByteWideChar - // for success. - // Save the link by calling IPersistFile::Save. - hres = ppf->Save(wsz, TRUE); + hres = ppf->Save(fullLinkName, TRUE); ppf->Release(); } psl->Release(); @@ -412,13 +404,17 @@ GridHubApplication::Create(const Descriptor& descriptor, const StartupParameters { bool isError = false; #ifdef AZ_PLATFORM_WINDOWS - TCHAR originalExeFileName[MAX_PATH]; - if (GetModuleFileName(NULL, originalExeFileName, AZ_ARRAY_SIZE(originalExeFileName))) + char originalExeFileName[MAX_PATH]; + if (AZ::Utils::GetExecutablePath(originalExeFileName, AZ_ARRAY_SIZE(originalExeFileName)).m_pathStored == AZ::Utils::ExecutablePathResult::Success) { - PathRemoveFileSpec(originalExeFileName); - PathAppend(originalExeFileName, GRIDHUB_IMAGE_NAME); + wchar_t originalExeFileNameW[MAX_PATH]; + AZStd::to_wstring(originalExeFileNameW, MAX_PATH, originalExeFileName, MAX_PATH); + PathRemoveFileSpec(originalExeFileNameW); + PathAppend(originalExeFileNameW, GRIDHUB_IMAGE_NAME); - m_originalExeFileName = originalExeFileName; + AZStd::string finalExeFileName; + AZStd::to_string(finalExeFileName, originalExeFileNameW); + m_originalExeFileName = finalExeFileName.c_str(); m_originalExeLastModified = QFileInfo(m_originalExeFileName).lastModified(); } @@ -489,18 +485,20 @@ void GridHubApplication::RegisterCoreComponents() void CopyAndRun(bool failSilently) { #ifdef AZ_PLATFORM_WINDOWS - TCHAR myFileName[MAX_PATH] = { _T(0) }; - if (GetModuleFileName(NULL, myFileName, MAX_PATH )) + char myFileName[MAX_PATH] = { 0 }; + if (AZ::Utils::GetExecutablePath(myFileName, MAX_PATH).m_pathStored == AZ::Utils::ExecutablePathResult::Success) { - TCHAR sourceProcPath[MAX_PATH] = { _T(0) }; - TCHAR targetProcPath[MAX_PATH] = { _T(0) }; - TCHAR procDrive[MAX_PATH] = { _T(0) }; - TCHAR procDir[MAX_PATH] = { _T(0) }; - TCHAR procFname[MAX_PATH] = { _T(0) }; - TCHAR procExt[MAX_PATH] = { _T(0) }; - _tsplitpath_s(myFileName, procDrive, procDir, procFname, procExt); - _tmakepath_s(sourceProcPath, procDrive, procDir, GRIDHUB_IMAGE_NAME, NULL); - _tmakepath_s(targetProcPath, procDrive, procDir, GRIDHUB_TSR_NAME, NULL); + wchar_t myFileNameW[MAX_PATH] = { 0 }; + AZStd::to_wstring(myFileNameW, MAX_PATH, myFileName, MAX_PATH); + wchar_t sourceProcPath[MAX_PATH] = { 0 }; + wchar_t targetProcPath[MAX_PATH] = { 0 }; + wchar_t procDrive[MAX_PATH] = { 0 }; + wchar_t procDir[MAX_PATH] = { 0 }; + wchar_t procFname[MAX_PATH] = { 0 }; + wchar_t procExt[MAX_PATH] = { 0 }; + _wsplitpath_s(myFileNameW, procDrive, procDir, procFname, procExt); + _wmakepath_s(sourceProcPath, procDrive, procDir, GRIDHUB_IMAGE_NAME, NULL); + _wmakepath_s(targetProcPath, procDrive, procDir, GRIDHUB_TSR_NAME, NULL); if (CopyFileEx(sourceProcPath, targetProcPath, NULL, NULL, NULL, 0)) { STARTUPINFO si; @@ -527,9 +525,9 @@ void CopyAndRun(bool failSilently) { if (!failSilently) { - TCHAR errorMsg[1024] = { _T(0) }; - _stprintf_s(errorMsg, _T("Failed to copy GridHub. Make sure that %s%s is writable!"), procFname, procExt); - MessageBox(NULL, errorMsg, NULL, MB_ICONSTOP|MB_OK); + wchar_t errorMsg[1024] = { 0 }; + swprintf_s(errorMsg, L"Failed to copy GridHub. Make sure that %s%s is writable!", procFname, procExt); + MessageBoxW(NULL, errorMsg, NULL, MB_ICONSTOP|MB_OK); } } } @@ -565,16 +563,18 @@ void CopyAndRun(bool failSilently) void RelaunchImage() { #ifdef AZ_PLATFORM_WINDOWS - TCHAR myFileName[MAX_PATH] = { _T(0) }; - if (GetModuleFileName(NULL, myFileName, MAX_PATH)) + char myFileName[MAX_PATH] = { 0 }; + if (AZ::Utils::GetExecutablePath(myFileName, MAX_PATH).m_pathStored == AZ::Utils::ExecutablePathResult::Success) { - TCHAR targetProcPath[MAX_PATH] = { _T(0) }; - TCHAR procDrive[MAX_PATH] = { _T(0) }; - TCHAR procDir[MAX_PATH] = { _T(0) }; - TCHAR procFname[MAX_PATH] = { _T(0) }; - TCHAR procExt[MAX_PATH] = { _T(0) }; - _tsplitpath_s(myFileName, procDrive, procDir, procFname, procExt); - _tmakepath_s(targetProcPath, procDrive, procDir, GRIDHUB_IMAGE_NAME, NULL); + wchar_t myFileNameW[MAX_PATH] = { 0 }; + AZStd::to_wstring(myFileNameW, MAX_PATH, myFileName, MAX_PATH); + wchar_t targetProcPath[MAX_PATH] = { 0 }; + wchar_t procDrive[MAX_PATH] = { 0 }; + wchar_t procDir[MAX_PATH] = { 0 }; + wchar_t procFname[MAX_PATH] = { 0 }; + wchar_t procExt[MAX_PATH] = { 0 }; + _wsplitpath_s(myFileNameW, procDrive, procDir, procFname, procExt); + _wmakepath_s(targetProcPath, procDrive, procDir, GRIDHUB_IMAGE_NAME, NULL); STARTUPINFO si; PROCESS_INFORMATION pi; @@ -635,8 +635,8 @@ int main(int argc, char *argv[]) { #ifdef AZ_PLATFORM_WINDOWS - TCHAR exeFileName[MAX_PATH]; - if( GetModuleFileName(NULL,exeFileName,AZ_ARRAY_SIZE(exeFileName)) ) + char exeFileName[MAX_PATH]; + if (AZ::Utils::GetExecutablePath(exeFileName, AZ_ARRAY_SIZE(exeFileName)).m_pathStored == AZ::Utils::ExecutablePathResult::Success) #elif defined AZ_PLATFORM_LINUX //KDAB_TODO char exeFileName[MAXPATHLEN]; @@ -661,7 +661,7 @@ int main(int argc, char *argv[]) { #ifdef AZ_PLATFORM_WINDOWS // Create a OS named mutex while the OS is running - HANDLE hInstanceMutex = CreateMutex(NULL,TRUE,"Global\\GridHub-Instance"); + HANDLE hInstanceMutex = CreateMutex(NULL, TRUE, L"Global\\GridHub-Instance"); AZ_Assert(hInstanceMutex!=NULL,"Failed to create OS mutex [GridHub-Instance]\n"); if( hInstanceMutex != NULL && GetLastError() == ERROR_ALREADY_EXISTS) { diff --git a/Gems/Atom/Feature/Common/Code/Source/LuxCore/LuxCoreRenderer.cpp b/Gems/Atom/Feature/Common/Code/Source/LuxCore/LuxCoreRenderer.cpp index 40fcbc7f31..c753079d5b 100644 --- a/Gems/Atom/Feature/Common/Code/Source/LuxCore/LuxCoreRenderer.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/LuxCore/LuxCoreRenderer.cpp @@ -19,7 +19,7 @@ namespace LuxCoreUI { - void LaunchLuxCoreUI(const AZStd::string& luxCoreExeFullPath, AZStd::string& commandLine); + void LaunchLuxCoreUI(const AZStd::string& luxCoreExeFullPath, const AZStd::string& commandLine); } namespace AZ diff --git a/Gems/Atom/Feature/Common/Code/Source/Platform/Windows/LaunchLuxCoreUI_Windows.cpp b/Gems/Atom/Feature/Common/Code/Source/Platform/Windows/LaunchLuxCoreUI_Windows.cpp index 3c8f304cb6..7f15949201 100644 --- a/Gems/Atom/Feature/Common/Code/Source/Platform/Windows/LaunchLuxCoreUI_Windows.cpp +++ b/Gems/Atom/Feature/Common/Code/Source/Platform/Windows/LaunchLuxCoreUI_Windows.cpp @@ -7,11 +7,12 @@ */ #include +#include #include namespace LuxCoreUI { - void LaunchLuxCoreUI(const AZStd::string& luxCoreExeFullPath, AZStd::string& commandLine) + void LaunchLuxCoreUI(const AZStd::string& luxCoreExeFullPath, const AZStd::string& commandLine) { STARTUPINFO si; PROCESS_INFORMATION pi; @@ -20,9 +21,14 @@ namespace LuxCoreUI si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); + AZStd::wstring luxCoreExeFullPathW; + AZStd::to_wstring(luxCoreExeFullPathW, luxCoreExeFullPath.c_str()); + AZStd::wstring commandLineW; + AZStd::to_wstring(commandLineW, commandLine.c_str()); + // start the program up - CreateProcess(luxCoreExeFullPath.data(), // the path - commandLine.data(), // Command line + CreateProcessW(luxCoreExeFullPathW.c_str(), // the path + commandLineW.data(), // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE diff --git a/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/PhysicalDevice_Windows.cpp b/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/PhysicalDevice_Windows.cpp index 6e5206fc00..2c56a860e8 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/PhysicalDevice_Windows.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/PhysicalDevice_Windows.cpp @@ -78,7 +78,7 @@ namespace AZ } constexpr uint32_t SubKeyLength = 256; - char subKeyName[SubKeyLength]; + wchar_t subKeyName[SubKeyLength]; uint32_t driverVersion = 0; diff --git a/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/WindowsVersionQuery.cpp b/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/WindowsVersionQuery.cpp index 0301d48454..91f0a712dd 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/WindowsVersionQuery.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/Platform/Windows/RHI/WindowsVersionQuery.cpp @@ -18,7 +18,7 @@ namespace AZ bool GetWindowsVersionFromSystemDLL(WindowsVersion* windowsVersion) { // We get the file version of one of the system DLLs to get the OS version. - constexpr const char* dllName = "Kernel32.dll"; + constexpr const wchar_t* dllName = L"Kernel32.dll"; VS_FIXEDFILEINFO* fileInfo = nullptr; DWORD handle; DWORD infoSize = GetFileVersionInfoSize(dllName, &handle); @@ -28,7 +28,7 @@ namespace AZ if (GetFileVersionInfo(dllName, handle, infoSize, versionData.data()) != 0) { UINT len; - const char* subBlock = "\\"; + const wchar_t* subBlock = L"\\"; if (VerQueryValue(versionData.data(), subBlock, reinterpret_cast(&fileInfo), &len) != 0) { windowsVersion->m_majorVersion = HIWORD(fileInfo->dwProductVersionMS); diff --git a/Gems/Atom/RHI/DX12/Code/Source/RHI/Fence.cpp b/Gems/Atom/RHI/DX12/Code/Source/RHI/Fence.cpp index db15930c01..f61aa3f67f 100644 --- a/Gems/Atom/RHI/DX12/Code/Source/RHI/Fence.cpp +++ b/Gems/Atom/RHI/DX12/Code/Source/RHI/Fence.cpp @@ -13,9 +13,13 @@ namespace AZ namespace DX12 { FenceEvent::FenceEvent(const char* name) - : m_EventHandle(CreateEvent(nullptr, false, false, name)) + : m_EventHandle(nullptr) , m_name(name) - {} + { + AZStd::wstring nameW; + AZStd::to_wstring(nameW, name); + m_EventHandle = CreateEvent(nullptr, false, false, nameW.c_str()); + } FenceEvent::~FenceEvent() { diff --git a/Gems/CrashReporting/Code/CMakeLists.txt b/Gems/CrashReporting/Code/CMakeLists.txt index 37224ea1aa..b12b5d8944 100644 --- a/Gems/CrashReporting/Code/CMakeLists.txt +++ b/Gems/CrashReporting/Code/CMakeLists.txt @@ -28,6 +28,7 @@ ly_add_target( BUILD_DEPENDENCIES PRIVATE AZ::CrashHandler + AZ::AzCore ) # Load the "Gem::CrashReporting" module in Clients and Servers diff --git a/Gems/EMotionFX/Code/Tests/AnimGraphCopyPasteTests.cpp b/Gems/EMotionFX/Code/Tests/AnimGraphCopyPasteTests.cpp index eb16a1a57c..4feb8cd86a 100644 --- a/Gems/EMotionFX/Code/Tests/AnimGraphCopyPasteTests.cpp +++ b/Gems/EMotionFX/Code/Tests/AnimGraphCopyPasteTests.cpp @@ -159,7 +159,7 @@ namespace EMotionFX (azrtti_typeid<>(conditionPrototype) != azrtti_typeid())) { AZ::TypeId type = azrtti_typeid<>(conditionPrototype); - OutputDebugString(AZStd::string::format("Condition: Name=%s, Type=%s\n", conditionPrototype->GetPaletteName(), type.ToString().c_str()).c_str()); + AZ::Debug::Platform::OutputToDebugger(nullptr, AZStd::string::format("Condition: Name=%s, Type=%s\n", conditionPrototype->GetPaletteName(), type.ToString().c_str()).c_str()); result.emplace_back(azrtti_typeid<>(conditionPrototype)); } } diff --git a/Gems/Maestro/Code/Source/Cinematics/Movie.cpp b/Gems/Maestro/Code/Source/Cinematics/Movie.cpp index 2d5aa7b410..a6d9e47eb1 100644 --- a/Gems/Maestro/Code/Source/Cinematics/Movie.cpp +++ b/Gems/Maestro/Code/Source/Cinematics/Movie.cpp @@ -1963,7 +1963,7 @@ void CLightAnimWrapper::InvalidateAllNodes() CLightAnimWrapper* CLightAnimWrapper::FindLightAnim(const char* name) { - LightAnimWrapperCache::const_iterator it = ms_lightAnimWrapperCache.find(CONST_TEMP_STRING(name)); + LightAnimWrapperCache::const_iterator it = ms_lightAnimWrapperCache.find(name); return it != ms_lightAnimWrapperCache.end() ? (*it).second : 0; } @@ -1976,7 +1976,7 @@ void CLightAnimWrapper::CacheLightAnim(const char* name, CLightAnimWrapper* p) ////////////////////////////////////////////////////////////////////////// void CLightAnimWrapper::RemoveCachedLightAnim(const char* name) { - ms_lightAnimWrapperCache.erase(CONST_TEMP_STRING(name)); + ms_lightAnimWrapperCache.erase(name); } #ifdef MOVIESYSTEM_SUPPORT_EDITING diff --git a/Gems/Maestro/Code/Source/Cinematics/Movie.h b/Gems/Maestro/Code/Source/Cinematics/Movie.h index cb97cfc40b..6ac857d652 100644 --- a/Gems/Maestro/Code/Source/Cinematics/Movie.h +++ b/Gems/Maestro/Code/Source/Cinematics/Movie.h @@ -48,7 +48,7 @@ public: static void InvalidateAllNodes(); private: - typedef std::map LightAnimWrapperCache; + typedef std::map LightAnimWrapperCache; static StaticInstance ms_lightAnimWrapperCache; static AZStd::intrusive_ptr ms_pLightAnimSet; diff --git a/Gems/SaveData/Code/Source/Platform/Windows/SaveData_SystemComponent_Windows.cpp b/Gems/SaveData/Code/Source/Platform/Windows/SaveData_SystemComponent_Windows.cpp index 236b2f525c..2e473cfea7 100644 --- a/Gems/SaveData/Code/Source/Platform/Windows/SaveData_SystemComponent_Windows.cpp +++ b/Gems/SaveData/Code/Source/Platform/Windows/SaveData_SystemComponent_Windows.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -99,7 +100,7 @@ namespace SaveData AZStd::string GetExecutableName() { char moduleFileName[AZ_MAX_PATH_LEN]; - GetModuleFileNameA(nullptr, moduleFileName, AZ_MAX_PATH_LEN); + AZ::Utils::GetExecutablePath(moduleFileName, AZ_MAX_PATH_LEN); const AZStd::string moduleFileNameString(moduleFileName); const size_t executableNameStart = moduleFileNameString.find_last_of('\\') + 1;