#ifndef _WIN32
-
#include <OSD_Environment.hxx>
#include <OSD_OSDError.hxx>
#include <OSD_Path.hxx>
}
-void OSD_Process::Spawn (const TCollection_AsciiString& cmd,
- const Standard_Boolean /*ShowWindow*/)
-{
- system(cmd.ToCString());
-}
-
-
void OSD_Process::TerminalType(TCollection_AsciiString& Name){
TCollection_AsciiString which="TERM";
OSD_Environment term (which,"");
return (getpid());
}
-
-Standard_Integer OSD_Process::UserId(){
- return (getuid());
-}
-
-
-TCollection_AsciiString OSD_Process::UserName(){
- struct passwd *infos;
- infos = getpwuid(getuid());
- TCollection_AsciiString result=infos->pw_name;
-
- return(result);
+TCollection_AsciiString OSD_Process::UserName()
+{
+ struct passwd *anInfos = getpwuid (getuid());
+ return TCollection_AsciiString (anInfos ? anInfos->pw_name : "");
}
Standard_Boolean OSD_Process::IsSuperUser (){
#endif
#include <windows.h>
-#ifdef SetCurrentDirectory
-# undef SetCurrentDirectory /* undefine SetCurrentDirectory from <winbase.h> to correctly include <OSD_Process.hxx> */
-#endif
#include <OSD_Process.hxx>
#include <OSD_Path.hxx>
#include <Standard_PExtCharacter.hxx>
#include <TCollection_ExtendedString.hxx>
-#include <OSD_WNT_1.hxx>
-#include <LMCONS.H> /// pour UNLEN ( see MSDN about GetUserName() )
-
-
-#pragma warning( disable : 4700 )
+#include <OSD_WNT.hxx>
+#include <lmcons.h> // for UNLEN - maximum user name length GetUserName()
void _osd_wnt_set_error ( OSD_Error&, OSD_WhoAmI, ... );
-OSD_Process :: OSD_Process () {
-
-} // end constructor
-
-void OSD_Process :: Spawn ( const TCollection_AsciiString& cmd ,
- const Standard_Boolean ShowWindow /* = Standard_True */) {
-
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
-
- ZeroMemory ( &si, sizeof ( STARTUPINFO ) );
-
- 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 );
-
- else {
-
- CloseHandle ( pi.hThread );
-
- WaitForSingleObject ( pi.hProcess, INFINITE );
-
- CloseHandle ( pi.hProcess );
-
- } // end else
-
-} // end OSD_Process :: Spawn
+// =======================================================================
+// function : OSD_Process
+// purpose :
+// =======================================================================
+OSD_Process::OSD_Process()
+{
+ //
+}
void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) {
} // end OSD_Process :: SystemDate
-Standard_Integer OSD_Process :: UserId () {
-
- PSID retVal = NULL;
- HANDLE hProcessToken = INVALID_HANDLE_VALUE;
- PTOKEN_OWNER pTKowner = NULL;
-
- if ( !OpenProcessToken (
- GetCurrentProcess (),
- TOKEN_QUERY, &hProcessToken
- ) ||
- ( pTKowner = ( PTOKEN_OWNER )GetTokenInformationEx (
- hProcessToken, TokenOwner
- )
- ) == NULL ||
- ( retVal = CopySidEx ( pTKowner -> Owner ) ) == NULL
- )
-
- _osd_wnt_set_error ( myError, OSD_WProcess );
-
- if ( hProcessToken != INVALID_HANDLE_VALUE ) CloseHandle ( hProcessToken );
- if ( pTKowner != NULL ) FreeTokenInformation ( pTKowner );
-
- return ( Standard_Integer )retVal;
-
-} // end OSD_Process :: UserId
-
-TCollection_AsciiString OSD_Process :: UserName ()
+// =======================================================================
+// function : UserName
+// purpose :
+// =======================================================================
+TCollection_AsciiString OSD_Process::UserName()
{
- 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;
-} // end OSD_Process :: UserName
+#ifndef OCCT_UWP
+ 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 TCollection_AsciiString();
+#endif
+}
Standard_Boolean OSD_Process :: IsSuperUser () {
-
+#ifndef OCCT_UWP
Standard_Boolean retVal = FALSE;
PSID pSIDadmin;
HANDLE hProcessToken = INVALID_HANDLE_VALUE;
if ( pTKgroups != NULL ) FreeTokenInformation ( pTKgroups );
return retVal;
-
+#else
+ return FALSE;
+#endif
} // end OSD_Process :: IsSuperUser
-Standard_Integer OSD_Process :: ProcessId () {
-
- return ( Standard_Integer )GetCurrentProcessId ();
-
-} // end OSD_Process :: ProcessId
-
-OSD_Path OSD_Process :: CurrentDirectory () {
+// =======================================================================
+// function : ProcessId
+// purpose :
+// =======================================================================
+Standard_Integer OSD_Process::ProcessId()
+{
+ return (Standard_Integer )GetCurrentProcessId();
+}
+// =======================================================================
+// function : CurrentDirectory
+// purpose :
+// =======================================================================
+OSD_Path OSD_Process::CurrentDirectory()
+{
OSD_Path anCurrentDirectory;
-
- DWORD dwSize = PATHLEN + 1;
- Standard_WideChar* pBuff = new wchar_t[dwSize];
-
- if ( GetCurrentDirectoryW(dwSize, (wchar_t*)pBuff) > 0 )
+#ifndef OCCT_UWP
+ const DWORD aBuffLen = GetCurrentDirectoryW (0, NULL);
+ if (aBuffLen > 0)
{
- // conversion to UTF-8 is performed inside
- TCollection_AsciiString aPath(TCollection_ExtendedString((Standard_ExtString)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 ) {
where.SystemName ( path );
TCollection_ExtendedString pathW(path);
- if ( !::SetCurrentDirectoryW ( (const wchar_t*) pathW.ToExtString () ) )
+ if (!::SetCurrentDirectoryW (pathW.ToWideString()))
_osd_wnt_set_error ( myError, OSD_WProcess );