' System/Environment.ab #require Class Environment Public ' Properties Static Function CommandLine() As String If 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 GetCurrentDirectory(size, p) CurrentDirectory = p _System_free(p) 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 osVer = Nothing Then Dim vi As OSVERSIONINFO GetVersionInfoEx(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 sysDir = Nothing Then Dim size = GetSystemDirectory(0, 0) Dim p = _System_malloc(SizeOf (TCHAR) * size) GetSystemDirectory(size, p) sysDir = p _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 Dim pGetProcessMemoryInfo As *Function(Process As HANDLE, ByRef mc As PPROCESS_MEMORY_COUNTERS, cb As DWord) As BOOL Dim hmodPSAPI = LoadLibrary("PSAPI.DLL") If hmodPSAPI = 0 Then Return 0 pGetProcessMemoryInfo = GetProcAddress(hmodPSAPI, ToMBStr("GetProcessMemoryInfo")) If pGetProcessMemoryInfo <> 0 Then Dim mc As PPROCESS_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) ExpandEnvironmentStrings(src, dst, size) ExpandEnvironmentVariables = dst _System_free(dst) End Function Static Sub FailFast(message As String) OutputDebugString(ToTCStr(message)) ExitProcess(-1) 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