1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0028110: Configuration - specify Unicode charset instead of multibyte in project files for Visual Studio

Eliminated usage of ANSI methods.
All Visual Studio projects generated by genproj or CMake use Unicode character set.

Draw Harness now handles Unicode input on Windows.
Tcl test scripts are now expected in UTF-8 encoding by default.
This commit is contained in:
ski
2016-11-14 14:31:00 +03:00
committed by apn
parent 0a40a30da5
commit ad03c23449
27 changed files with 728 additions and 755 deletions

View File

@@ -14,7 +14,6 @@
#ifndef _WIN32
#include <OSD_Environment.hxx>
#include <OSD_OSDError.hxx>
#include <OSD_WhoAmI.hxx>
@@ -234,20 +233,16 @@ Standard_Integer OSD_Environment::Error() const
//------------------------------------------------------------------------
#define STRICT
#include <windows.h>
#include <OSD_Environment.hxx>
#include <OSD_WNT.hxx>
#include <windows.h>
#include <NCollection_DataMap.hxx>
#include <NCollection_UtfString.hxx>
#include <Standard_Mutex.hxx>
#if defined(_MSC_VER)
#pragma warning( disable : 4700 )
#endif
#ifdef OCCT_UWP
namespace
{
@@ -381,28 +376,22 @@ Standard_Integer OSD_Environment :: Error () const {
} // end OSD_Environment :: Error
#ifndef OCCT_UWP
static void __fastcall _set_error ( OSD_Error& err, DWORD code ) {
DWORD errCode;
Standard_Character buffer[ 2048 ];
errCode = code ? code : GetLastError ();
if ( !FormatMessage (
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
0, errCode, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ),
buffer, 2048, NULL
)
) {
sprintf ( buffer, "error code %d", (Standard_Integer)errCode );
SetLastError ( errCode );
} // end if
err.SetValue ( errCode, OSD_WEnvironment, buffer );
} // end _set_error
static void __fastcall _set_error (OSD_Error& theErr, DWORD theCode)
{
wchar_t aBuffer[2048];
const DWORD anErrCode = theCode != 0 ? theCode : GetLastError();
if (!FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
0, anErrCode, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ),
aBuffer, 2048, NULL))
{
theErr.SetValue (anErrCode, OSD_WEnvironment, TCollection_AsciiString ("error code ") + (Standard_Integer)anErrCode);
SetLastError (anErrCode);
}
else
{
theErr.SetValue (anErrCode, OSD_WEnvironment, TCollection_AsciiString (aBuffer));
}
}
#endif
#endif

View File

@@ -1430,7 +1430,7 @@ OSD_KindFile OSD_File :: KindOfFile () const {
typedef struct _osd_wnt_key {
HKEY hKey;
const char* keyPath;
wchar_t* keyPath;
} OSD_WNT_KEY;
@@ -1448,17 +1448,17 @@ typedef struct _osd_wnt_key {
OSD_WNT_KEY regKey[ 2 ] = {
{ HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
L"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"
},
{ HKEY_USERS,
".DEFAULT\\Environment"
L".DEFAULT\\Environment"
}
};
for ( int i = 0; i < 2; ++i ) {
if ( RegOpenKeyEx (
if ( RegOpenKeyExW (
regKey[ i ].hKey, regKey[ i ].keyPath, 0, KEY_QUERY_VALUE, &hKey
) == ERROR_SUCCESS
) {

View File

@@ -14,7 +14,6 @@
#ifndef _WIN32
#include <OSD_Host.hxx>
#include <OSD_OSDError.hxx>
#include <OSD_WhoAmI.hxx>
@@ -202,13 +201,13 @@ static Standard_Integer memSize;
OSD_Host :: OSD_Host () {
#ifndef OCCT_UWP
DWORD nSize;
Standard_Character szHostName[ MAX_COMPUTERNAME_LENGTH + 1 ];
char szHostName[MAX_COMPUTERNAME_LENGTH + 1];
char* hostAddr = 0;
MEMORYSTATUS ms;
WSADATA wd;
PHOSTENT phe;
IN_ADDR inAddr;
OSVERSIONINFO osVerInfo;
OSVERSIONINFOW osVerInfo;
if ( !fInit ) {
@@ -216,25 +215,24 @@ OSD_Host :: OSD_Host () {
osVerInfo.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
ZeroMemory (&ms, sizeof(ms));
ZeroMemory ( szHostName, sizeof ( Standard_Character ) * (MAX_COMPUTERNAME_LENGTH + 1) );
ZeroMemory (szHostName, sizeof(char) * (MAX_COMPUTERNAME_LENGTH + 1));
#ifdef _MSC_VER
// suppress GetVersionEx() deprecation warning
#pragma warning(disable : 4996)
#endif
if ( !GetVersionEx ( &osVerInfo ) ) {
_osd_wnt_set_error ( myError, OSD_WHost );
} else if ( !GetComputerName ( szHostName, &nSize ) ) {
_osd_wnt_set_error ( myError, OSD_WHost );
} else {
ms.dwLength = sizeof ( MEMORYSTATUS );
GlobalMemoryStatus ( &ms );
if (!GetVersionExW (&osVerInfo))
{
_osd_wnt_set_error (myError, OSD_WHost);
}
else if (!GetComputerNameA (szHostName, &nSize))
{
_osd_wnt_set_error (myError, OSD_WHost);
}
else
{
ms.dwLength = sizeof(MEMORYSTATUS);
GlobalMemoryStatus (&ms);
} // end else
#ifdef _MSC_VER
#pragma warning(default : 4996)
@@ -248,7 +246,7 @@ OSD_Host :: OSD_Host () {
_osd_wnt_set_error ( myError, OSD_WHost );
} else if ( ( phe = gethostbyname ( szHostName ) ) == NULL ) {
} else if ( ( phe = gethostbyname (szHostName) ) == NULL ) {
_osd_wnt_set_error ( myError, OSD_WHost );

View File

@@ -14,7 +14,6 @@
#ifndef _WIN32
#include <OSD_Environment.hxx>
#include <OSD_OSDError.hxx>
#include <OSD_Path.hxx>
@@ -195,65 +194,60 @@ Standard_Integer OSD_Process::Error()const{
#include <TCollection_ExtendedString.hxx>
#include <OSD_WNT_1.hxx>
#include <LMCONS.H> /// pour UNLEN ( see MSDN about GetUserName() )
#if defined(_MSC_VER)
#pragma warning( disable : 4700 )
#endif
#include <LMCONS.H> // for UNLEN - maximum user name length GetUserName()
void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
OSD_Process :: OSD_Process () {
// =======================================================================
// function : OSD_Process
// purpose :
// =======================================================================
OSD_Process::OSD_Process()
{
//
}
} // end constructor
Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& cmd,
const Standard_Boolean ShowWindow /* = Standard_True */) {
// =======================================================================
// function : Spawn
// purpose :
// =======================================================================
Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& theCmd,
const Standard_Boolean theToShowWindow)
{
#ifndef OCCT_UWP
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD aRes = 0;
STARTUPINFOW aStartupInfo;
ZeroMemory (&aStartupInfo, sizeof(STARTUPINFO));
aStartupInfo.cb = sizeof(STARTUPINFO);
if (!theToShowWindow)
{
aStartupInfo.dwFlags = STARTF_USESHOWWINDOW;
aStartupInfo.wShowWindow = SW_HIDE;
}
ZeroMemory ( &si, sizeof ( STARTUPINFO ) );
DWORD aRes = 0;
TCollection_ExtendedString aCmdWide (theCmd);
wchar_t* aCmdWidePtr = const_cast<wchar_t*>(aCmdWide.ToWideString()); // CreateProcessW() can modify content of this string
PROCESS_INFORMATION aProcessInfo;
if (!CreateProcessW (NULL, aCmdWidePtr, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &aStartupInfo, &aProcessInfo))
{
_osd_wnt_set_error (myError, OSD_WProcess);
aRes = myError.Error();
}
else
{
CloseHandle (aProcessInfo.hThread);
WaitForSingleObject (aProcessInfo.hProcess, INFINITE);
GetExitCodeProcess (aProcessInfo.hProcess, &aRes);
CloseHandle (aProcessInfo.hProcess);
}
si.cb = sizeof ( STARTUPINFO );
//============================================
//---> Added by Stephane Routelous ( stephane.routelous@altavista.net ) [16.03.01]
//---> Reason : to allow to hide the window
if ( !ShowWindow )
{
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
}
//<--- End Added by Stephane Routelous ( stephane.routelous@altavista.net ) [16.03.01]
//============================================
if (!CreateProcess (
NULL, (char *)cmd.ToCString (), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi
)
) {
_osd_wnt_set_error ( myError, OSD_WProcess );
aRes = myError.Error();
}
else {
CloseHandle ( pi.hThread );
WaitForSingleObject ( pi.hProcess, INFINITE );
GetExitCodeProcess (pi.hProcess, &aRes);
CloseHandle ( pi.hProcess );
} // end else
return aRes;
return aRes;
#else
(void)cmd;
(void)ShowWindow;
(void )theCmd;
(void )theToShowWindow;
return 0;
#endif
} // end OSD_Process :: Spawn
}
void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) {
@@ -276,27 +270,26 @@ Quantity_Date OSD_Process :: SystemDate () {
} // end OSD_Process :: SystemDate
TCollection_AsciiString OSD_Process :: UserName ()
// =======================================================================
// function : UserName
// purpose :
// =======================================================================
TCollection_AsciiString OSD_Process::UserName()
{
#ifndef OCCT_UWP
Standard_PCharacter pBuff = new char[UNLEN + 1];
DWORD dwSize = UNLEN + 1;
TCollection_AsciiString retVal;
if ( !GetUserName ( pBuff, &dwSize ) )
{
_osd_wnt_set_error ( myError, OSD_WProcess );
}
else
{
TCollection_AsciiString theTmpUserName(pBuff,(int)dwSize -1 );
retVal = theTmpUserName;
}
delete [] pBuff;
return retVal;
wchar_t aUserName[UNLEN + 1];
DWORD aNameSize = UNLEN + 1;
TCollection_AsciiString retVal;
if (!GetUserNameW (aUserName, &aNameSize))
{
_osd_wnt_set_error(myError, OSD_WProcess);
return TCollection_AsciiString();
}
return TCollection_AsciiString (aUserName);
#else
return "";
return TCollection_AsciiString();
#endif
} // end OSD_Process :: UserName
}
Standard_Boolean OSD_Process :: IsSuperUser () {
#ifndef OCCT_UWP
@@ -341,31 +334,41 @@ Standard_Boolean OSD_Process :: IsSuperUser () {
#endif
} // end OSD_Process :: IsSuperUser
Standard_Integer OSD_Process :: ProcessId () {
// =======================================================================
// function : ProcessId
// purpose :
// =======================================================================
Standard_Integer OSD_Process::ProcessId()
{
return (Standard_Integer )GetCurrentProcessId();
}
return ( Standard_Integer )GetCurrentProcessId ();
} // end OSD_Process :: ProcessId
OSD_Path OSD_Process :: CurrentDirectory () {
// =======================================================================
// function : CurrentDirectory
// purpose :
// =======================================================================
OSD_Path OSD_Process::CurrentDirectory()
{
OSD_Path anCurrentDirectory;
#ifndef OCCT_UWP
DWORD dwSize = PATHLEN + 1;
Standard_WideChar* pBuff = new wchar_t[dwSize];
if (GetCurrentDirectoryW (dwSize, pBuff) > 0)
const DWORD aBuffLen = GetCurrentDirectoryW (0, NULL);
if (aBuffLen > 0)
{
// conversion to UTF-8 is performed inside
TCollection_AsciiString aPath (pBuff);
anCurrentDirectory = OSD_Path ( aPath );
wchar_t* aBuff = new wchar_t[aBuffLen + 1];
GetCurrentDirectoryW (aBuffLen, aBuff);
aBuff[aBuffLen] = L'\0';
const TCollection_AsciiString aPath (aBuff);
delete[] aBuff;
anCurrentDirectory = OSD_Path (aPath);
}
else
_osd_wnt_set_error ( myError, OSD_WProcess );
delete[] pBuff;
{
_osd_wnt_set_error (myError, OSD_WProcess);
}
#endif
return anCurrentDirectory;
} // end OSD_Process :: CurrentDirectory
}
void OSD_Process :: SetCurrentDirectory ( const OSD_Path& where ) {