Changeset 583
- Timestamp:
- Aug 10, 2008, 11:42:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/System/Environment.ab
r497 r583 19 19 20 20 Static Function CommandLine() As String 21 If Object.ReferenceEquals(cmdLine, Nothing) Then22 21 #ifdef UNICODE 23 cmdLine = New String(GetCommandLineW())22 CommandLine = New String(GetCommandLineW()) 24 23 #else 25 cmdLine = New String(GetCommandLineA())24 CommandLine = New String(GetCommandLineA()) 26 25 #endif 27 End If28 Return cmdLine29 26 End Function 30 27 31 28 Static Function CurrentDirectory() As String 32 29 Dim size = GetCurrentDirectory(0, 0) 33 Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PCTSTR 34 Dim len = GetCurrentDirectory(size, p) 30 Dim buf = New Text.StringBuilder 31 buf.Length = size As Long 32 Dim len = GetCurrentDirectory(size, StrPtr(buf)) 35 33 If len < size Then 36 CurrentDirectory = New String(p, len As Long)34 CurrentDirectory = buf.ToString 37 35 End If 38 36 End Function … … 55 53 56 54 Static Function MachineName() As String 57 If Object.ReferenceEquals(machineName, Nothing) Then 58 Dim buf[MAX_COMPUTERNAME_LENGTH] As TCHAR 59 Dim len = (MAX_COMPUTERNAME_LENGTH + 1) As DWord 60 GetComputerName(buf, len) 61 machineName = New String(buf, len As Long) 62 End If 63 Return machineName 55 Dim len = (MAX_COMPUTERNAME_LENGTH + 1) As DWord 56 Dim buf = New Text.StringBuilder 57 With buf 58 .Length = MAX_COMPUTERNAME_LENGTH 59 GetComputerName(StrPtr(buf), len) 60 .Length = len 61 MachineName = .ToString 62 End With 64 63 End Function 65 64 … … 69 68 70 69 Static Function OSVersion() As OperatingSystem 71 If Object.ReferenceEquals(osVer, Nothing) Then 72 Dim vi As OSVERSIONINFO 73 GetVersionEx(vi) 74 osVer = New OperatingSystem(vi) 75 End If 76 Return osVer 70 Dim vi As OSVERSIONINFO 71 GetVersionEx(vi) 72 OSVersion = New OperatingSystem(vi) 77 73 End Function 78 74 79 75 Static Function ProcessorCount() As Long 80 If processorCount = 0 Then 81 Dim si As SYSTEM_INFO 82 GetSystemInfo(si) 83 processorCount = si.dwNumberOfProcessors 84 End If 85 Return processorCount 76 Dim si As SYSTEM_INFO 77 GetSystemInfo(si) 78 ProcessorCount = si.dwNumberOfProcessors 86 79 End Function 87 80 … … 89 82 90 83 Static Function SystemDirectory() As String 91 If Object.ReferenceEquals(sysDir, Nothing) Then 92 Dim size = GetSystemDirectory(0, 0) 93 Dim p = GC_malloc_atomic(SizeOf (TCHAR) * size) As PTSTR 94 Dim len = GetSystemDirectory(p, size) 95 sysDir = New String(p, len As Long) 96 End If 97 Return sysDir 84 Dim size = GetSystemDirectory(0, 0) 85 Dim buf = New Text.StringBuilder 86 With buf 87 .Length = size 88 Dim len = GetSystemDirectory(StrPtr(buf), len) 89 .Length = len 90 MachineName = .ToString 91 End With 98 92 End Function 99 93 … … 107 101 108 102 Static Function UserName() As String 109 If Object.ReferenceEquals(userName, Nothing) Then 110 Dim buf[UNLEN] As TCHAR 111 Dim len = (UNLEN + 1) As DWord 112 GetUserName(buf, len) 113 userName = New String(buf, len As Long) 114 End If 115 Return userName 103 Dim len = (MAX_COMPUTERNAME_LENGTH + 1) As DWord 104 Dim buf = New Text.StringBuilder 105 With buf 106 .Length = MAX_COMPUTERNAME_LENGTH 107 GetUserName(StrPtr(buf), len) 108 .Length = len 109 UserName = .ToString 110 End With 116 111 End Function 117 112 … … 192 187 193 188 Private 194 Static cmdLine = Nothing As String195 189 Static exitCode = 0 As Long 196 Static machineName = Nothing As String197 Static osVer = Nothing As OperatingSystem198 Static processorCount = 0 As Long199 Static sysDir = Nothing As String200 Static userName = Nothing As String201 190 End Class 202 191
Note:
See TracChangeset
for help on using the changeset viewer.