' System/Environment.ab #require #require Class Environment Public ' Properties Static Function CommandLine() As String If Object.ReferenceEquals(cmdLine, Nothing) Then #ifdef __STRING_IS_NOT_UNICODE cmdLine = New String(GetCommandLineA()) #else cmdLine = New String(GetCommandLineW()) #endif End If Return cmdLine End Function Static Function CurrentDirectory() As String Dim size = GetCurrentDirectory(0, 0) Dim p = _System_malloc(SizeOf (TCHAR) * size) As PCTSTR Dim len = GetCurrentDirectory(size, p) If len < size Then CurrentDirectory = New String(p, size As Long) _System_free(p) End If End Function Static Sub CurrentDirectory(cd As String) SetCurrentDirectory(ToTCStr(cd)) End Sub Static Function ExitCode() As Long Return exitCode End Function Static Sub ExitCode(code As Long) exitCode = code End Sub Static Function HasShutdownStarted() As Boolean Return False End Function ' MachineName Static Function NewLine() As String Return Ex"\r\n" End Function Static Function OSVersion() As OperatingSystem If Object.ReferenceEquals(osVer, Nothing) Then Dim vi As OSVERSIONINFO GetVersionEx(vi) osVer = New OperatingSystem(vi) End If Return osVer End Function Static Function ProcessorCount() As Long If processorCount = 0 Then Dim si As SYSTEM_INFO GetSystemInfo(si) processorCount = si.dwNumberOfProcessors End If Return processorCount End Function ' StackTrace Static Function SystemDirectory() As String If Object.ReferenceEquals(sysDir, Nothing) Then Dim size = GetSystemDirectory(0, 0) Dim p = _System_malloc(SizeOf (TCHAR) * size) As PTSTR Dim len = GetSystemDirectory(p, size) sysDir = New String(p, len As Long) _System_free(p) End IF Return sysDir End Function Static Function TickCount() As Long Return GetTickCount() As Long End Function ' UserDomainName ' UserInteractive ' UserName ' Version Static Function WorkingSet() As Int64 TypeDef PFNGetProcessMemoryInfo = *Function(Process As HANDLE, ByRef mc As PROCESS_MEMORY_COUNTERS, cb As DWord) As BOOL Dim pGetProcessMemoryInfo As PFNGetProcessMemoryInfo Dim hmodPSAPI = LoadLibrary("PSAPI.DLL") If hmodPSAPI = 0 Then Return 0 pGetProcessMemoryInfo = GetProcAddress(hmodPSAPI, ToMBStr("GetProcessMemoryInfo")) As PFNGetProcessMemoryInfo If pGetProcessMemoryInfo <> 0 Then Dim mc As PROCESS_MEMORY_COUNTERS If pGetProcessMemoryInfo(GetCurrentProcess(), mc, Len (mc)) <> FALSE Then WorkingSet = mc.WorkingSetSize End If End If FreeLibrary(hmodPSAPI) End Function ' Methods Static Sub Exit(exitCode As Long) Environment.exitCode = exitCode End End Sub Static Function ExpandEnvironmentVariables(s As String) As String Dim src = ToTCStr(s) Dim size = ExpandEnvironmentStrings(src, 0, 0) Dim dst = _System_malloc(SizeOf (TCHAR) * size) As PTSTR ExpandEnvironmentStrings(src, dst, size) ExpandEnvironmentVariables = New String(dst, size - 1) _System_free(dst) End Function Static Sub FailFast(message As String) FatalAppExit(0, ToTCStr(message)) End Sub ' GetCommandLineArgs ' GetEnvironmentVariable ' GetEnvironmentVariables ' GetLogicalDrives ' SetEnvironmentVariable Private Static cmdLine = Nothing As String Static exitCode = 0 As Long Static osVer = Nothing As OperatingSystem Static processorCount = 0 As Long Static sysDir = Nothing As String End Class