remove of UNICODE/_UNICODE

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
Esteban Papp
2021-07-29 15:49:44 -07:00
parent 63d2f34ad6
commit 56eda61828
8 changed files with 5 additions and 144 deletions
@@ -61,16 +61,12 @@ namespace AZ
void OutputToDebugger(const char* window, const char* message)
{
AZ_UNUSED(window);
#ifdef _UNICODE
wchar_t messageW[g_maxMessageLength];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, messageW, message, g_maxMessageLength - 1) == 0)
{
OutputDebugStringW(messageW);
}
#else // !_UNICODE
OutputDebugString(message);
#endif // !_UNICODE
}
}
}
@@ -28,7 +28,6 @@ namespace
//=========================================================================
DWORD GetAttributes(const char* fileName)
{
#ifdef _UNICODE
wchar_t fileNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, fileNameW, fileName, AZ_ARRAY_SIZE(fileNameW) - 1) == 0)
@@ -39,9 +38,6 @@ namespace
{
return INVALID_FILE_ATTRIBUTES;
}
#else //!_UNICODE
return GetFileAttributes(fileName);
#endif // !_UNICODE
}
//=========================================================================
@@ -51,7 +47,6 @@ namespace
//=========================================================================
BOOL SetAttributes(const char* fileName, DWORD fileAttributes)
{
#ifdef _UNICODE
wchar_t fileNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, fileNameW, fileName, AZ_ARRAY_SIZE(fileNameW) - 1) == 0)
@@ -62,9 +57,6 @@ namespace
{
return FALSE;
}
#else //!_UNICODE
return SetFileAttributes(fileName, fileAttributes);
#endif // !_UNICODE
}
//=========================================================================
@@ -76,7 +68,6 @@ namespace
// * GetLastError() on Windows-like platforms
// * errno on Unix platforms
//=========================================================================
#if defined(_UNICODE)
bool CreateDirRecursive(wchar_t* dirPath)
{
if (CreateDirectoryW(dirPath, nullptr))
@@ -112,53 +103,6 @@ namespace
}
return false;
}
#else
bool CreateDirRecursive(char* dirPath)
{
if (CreateDirectory(dirPath, nullptr))
{
return true; // Created without error
}
DWORD error = GetLastError();
if (error == ERROR_PATH_NOT_FOUND)
{
// try to create our parent hierarchy
for (size_t i = strlen(dirPath); i > 0; --i)
{
if (dirPath[i] == '/' || dirPath[i] == '\\')
{
char delimiter = dirPath[i];
dirPath[i] = 0; // null-terminate at the previous slash
bool ret = CreateDirRecursive(dirPath);
dirPath[i] = delimiter; // restore slash
if (ret)
{
// now that our parent is created, try to create again
if (CreateDirectory(dirPath, nullptr))
{
return true;
}
DWORD creationError = GetLastError();
if (creationError == ERROR_ALREADY_EXISTS)
{
DWORD attributes = GetFileAttributes(dirPath);
return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
return false;
}
return false;
}
}
// if we reach here then there was no parent folder to create, so we failed for other reasons
}
else if (error == ERROR_ALREADY_EXISTS)
{
DWORD attributes = GetFileAttributes(dirPath);
return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
return false;
}
#endif
static const SystemFile::FileHandleType PlatformSpecificInvalidHandle = INVALID_HANDLE_VALUE;
}
@@ -208,7 +152,6 @@ bool SystemFile::PlatformOpen(int mode, int platformFlags)
CreatePath(m_fileName.c_str());
}
# ifdef _UNICODE
wchar_t fileNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
m_handle = INVALID_HANDLE_VALUE;
@@ -216,9 +159,6 @@ bool SystemFile::PlatformOpen(int mode, int platformFlags)
{
m_handle = CreateFileW(fileNameW, dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0);
}
# else //!_UNICODE
m_handle = CreateFile(m_fileName.c_str(), dwDesiredAccess, dwShareMode, 0, dwCreationDisposition, dwFlagsAndAttributes, 0);
# endif // !_UNICODE
if (m_handle == INVALID_HANDLE_VALUE)
{
@@ -417,7 +357,6 @@ namespace Platform
HANDLE hFile;
int lastError;
#ifdef _UNICODE
wchar_t filterW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
hFile = INVALID_HANDLE_VALUE;
@@ -425,39 +364,28 @@ namespace Platform
{
hFile = FindFirstFile(filterW, &fd);
}
#else // !_UNICODE
hFile = FindFirstFile(filter, &fd);
#endif // !_UNICODE
if (hFile != INVALID_HANDLE_VALUE)
{
const char* fileName;
#ifdef _UNICODE
char fileNameA[AZ_MAX_PATH_LEN];
fileName = NULL;
if (wcstombs_s(&numCharsConverted, fileNameA, fd.cFileName, AZ_ARRAY_SIZE(fileNameA) - 1) == 0)
{
fileName = fileNameA;
}
#else // !_UNICODE
fileName = fd.cFileName;
#endif // !_UNICODE
cb(fileName, (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0);
// List all the other files in the directory.
while (FindNextFile(hFile, &fd) != 0)
while (FindNextFileW(hFile, &fd) != 0)
{
#ifdef _UNICODE
fileName = NULL;
if (wcstombs_s(&numCharsConverted, fileNameA, fd.cFileName, AZ_ARRAY_SIZE(fileNameA) - 1) == 0)
{
fileName = fileNameA;
}
#else // !_UNICODE
fileName = fd.cFileName;
#endif // !_UNICODE
cb(fileName, (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0);
}
@@ -483,16 +411,12 @@ namespace Platform
{
HANDLE handle = nullptr;
#ifdef _UNICODE
wchar_t fileNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, fileNameW, fileName, AZ_ARRAY_SIZE(fileNameW) - 1) == 0)
{
handle = CreateFileW(fileNameW, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
}
#else // !_UNICODE
handle = CreateFileA(fileName, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
#endif // !_UNICODE
if (handle == INVALID_HANDLE_VALUE)
{
@@ -524,16 +448,12 @@ namespace Platform
WIN32_FILE_ATTRIBUTE_DATA data = { 0 };
BOOL result = FALSE;
#ifdef _UNICODE
wchar_t fileNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, fileNameW, fileName, AZ_ARRAY_SIZE(fileNameW) - 1) == 0)
{
result = GetFileAttributesExW(fileNameW, GetFileExInfoStandard, &data);
}
#else // !_UNICODE
result = GetFileAttributesExA(fileName, GetFileExInfoStandard, &data);
#endif // !_UNICODE
if (result)
{
@@ -553,7 +473,6 @@ namespace Platform
bool Delete(const char* fileName)
{
#ifdef _UNICODE
wchar_t fileNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, fileNameW, fileName, AZ_ARRAY_SIZE(fileNameW) - 1) == 0)
@@ -568,20 +487,12 @@ namespace Platform
{
return false;
}
#else // !_UNICODE
if (DeleteFile(fileName) == 0)
{
EBUS_EVENT(FileIOEventBus, OnError, nullptr, fileName, (int)GetLastError());
return false;
}
#endif // !_UNICODE
return true;
}
bool Rename(const char* sourceFileName, const char* targetFileName, bool overwrite)
{
#ifdef _UNICODE
wchar_t sourceFileNameW[AZ_MAX_PATH_LEN];
wchar_t targetFileNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
@@ -598,13 +509,6 @@ namespace Platform
{
return false;
}
#else // !_UNICODE
if (MoveFileEx(sourceFileName, targetFileName, overwrite ? MOVEFILE_REPLACE_EXISTING : 0) == 0)
{
EBUS_EVENT(FileIOEventBus, OnError, nullptr, sourceFileName, (int)GetLastError());
return false;
}
#endif // !_UNICODE
return true;
}
@@ -639,7 +543,6 @@ namespace Platform
{
if (dirName)
{
#if defined(_UNICODE)
wchar_t dirPath[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, dirPath, dirName, AZ_ARRAY_SIZE(dirPath) - 1) == 0)
@@ -651,18 +554,6 @@ namespace Platform
}
return success;
}
#else
char dirPath[AZ_MAX_PATH_LEN];
if (azstrcpy(dirPath, AZ_ARRAY_SIZE(dirPath), dirName) == 0)
{
bool success = CreateDirRecursive(dirPath);
if (!success)
{
EBUS_EVENT(FileIOEventBus, OnError, nullptr, dirName, (int)GetLastError());
}
return success;
}
#endif
}
return false;
}
@@ -671,16 +562,12 @@ namespace Platform
{
if (dirName)
{
#if defined(_UNICODE)
wchar_t dirNameW[AZ_MAX_PATH_LEN];
size_t numCharsConverted;
if (mbstowcs_s(&numCharsConverted, dirNameW, dirName, AZ_ARRAY_SIZE(dirNameW) - 1) == 0)
{
return RemoveDirectory(dirNameW) != 0;
}
#else
return RemoveDirectory(dirName) != 0;
#endif
}
return false;
@@ -98,7 +98,6 @@ namespace AZ
bool alreadyLoaded = false;
# ifdef _UNICODE
wchar_t fileNameW[MAX_PATH];
size_t numCharsConverted;
errno_t wcharResult = mbstowcs_s(&numCharsConverted, fileNameW, m_fileName.c_str(), AZ_ARRAY_SIZE(fileNameW) - 1);
@@ -114,10 +113,6 @@ namespace AZ
m_handle = NULL;
return LoadStatus::LoadFailure;
}
# else //!_UNICODE
alreadyLoaded = NULL != GetModuleHandleA(m_fileName.c_str());
m_handle = LoadLibraryA(m_fileName.c_str());
# endif // !_UNICODE
if (m_handle)
{
@@ -75,22 +75,14 @@ extern "C"
AZ_DLL_IMPORT HANDLE _stdcall CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName);
AZ_DLL_IMPORT BOOL _stdcall ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCount);
#ifndef CreateSemaphore
#ifdef UNICODE
#define CreateSemaphore CreateSemaphoreW
#else
#define CreateSemaphore CreateSemaphoreA
#endif
#define CreateSemaphore CreateSemaphoreW
#endif
// Event
AZ_DLL_IMPORT HANDLE _stdcall CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCSTR lpName);
AZ_DLL_IMPORT HANDLE _stdcall CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCWSTR lpName);
#ifndef CreateEvent
#ifdef UNICODE
#define CreateEvent CreateEventW
#else
#define CreateEvent CreateEventA
#endif
#define CreateEvent CreateEventW
#endif
AZ_DLL_IMPORT BOOL _stdcall SetEvent(HANDLE);
}
@@ -9,6 +9,7 @@
#pragma once
#define WIN32_LEAN_AND_MEAN
#define UNICODE
//#define NOGDICAPMASKS //- CC_*, LC_*, PC_*, CP_*, TC_*, RC_
//#define NOVIRTUALKEYCODES //- VK_*
//#define NOWINMESSAGES //- WM_*, EM_*, LB_*, CB_*
-5
View File
@@ -192,13 +192,8 @@ typedef WCHAR* LPUWSTR, * PUWSTR;
typedef const WCHAR* LPCWSTR, * PCWSTR;
typedef const WCHAR* LPCUWSTR, * PCUWSTR;
#ifdef UNICODE
typedef LPCWSTR LPCTSTR;
typedef LPWSTR LPTSTR;
#else
typedef LPCSTR LPCTSTR;
typedef LPSTR LPTSTR;
#endif
typedef DWORD COLORREF;
#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16)))
-5
View File
@@ -156,13 +156,8 @@ typedef WCHAR* LPUWSTR, * PUWSTR;
typedef const WCHAR* LPCWSTR, * PCWSTR;
typedef const WCHAR* LPCUWSTR, * PCUWSTR;
#ifdef UNICODE
typedef LPCWSTR LPCTSTR;
typedef LPWSTR LPTSTR;
#else
typedef LPCSTR LPCTSTR;
typedef LPSTR LPTSTR;
#endif
typedef char TCHAR;
typedef DWORD COLORREF;
+1 -1
View File
@@ -176,7 +176,7 @@
// In Win32 Release we use static linkage
#ifdef WIN32
#if !defined(_RELEASE) || defined(RESOURCE_COMPILER) || defined(EDITOR) || defined(_FORCEDLL)
#if !defined(_RELEASE) || defined(EDITOR) || defined(_FORCEDLL)
// All windows targets not in Release built as DLLs.
#ifndef _USRDLL
#define _USRDLL