source: Include/Classes/System/Environment.ab@ 152

Last change on this file since 152 was 152, checked in by dai, 17 years ago

")" 抜けと "String" タイプミスを修正。

File size: 3.2 KB
Line 
1' System/Environment.ab
2
3#require <Classes/System/OperatingSystem.ab>
4
5Class Environment
6Public
7 ' Properties
8
9 Static Function CommandLine() As String
10 If cmdLine = Nothing Then
11#ifdef __STRING_IS_NOT_UNICODE
12 cmdLine = New String(GetCommandLineA())
13#else
14 cmdLine = New String(GetCommandLineW())
15#endif
16 End If
17 Return cmdLine
18 End Function
19
20 Static Function CurrentDirectory() As String
21 Dim size = GetCurrentDirectory(0, 0)
22 Dim p = _System_malloc(SizeOf (TCHAR) * size) As PCTSTR
23 GetCurrentDirectory(size, p)
24 CurrentDirectory = p
25 _System_free(p)
26 End Function
27
28 Static Sub CurrentDirectory(cd As String)
29 SetCurrentDirectory(ToTCStr(cd))
30 End Sub
31
32 Static Function ExitCode() As Long
33 Return exitCode
34 End Function
35
36 Static Sub ExitCode(code As Long)
37 exitCode = code
38 End Sub
39
40 Static Sub HasShutdownStarted() As Boolean
41 Return False
42 End Sub
43
44 ' MachineName
45
46 Static Function NewLine() As String
47 Return Ex"\r\n"
48 End Function
49
50 Static Function OSVersion() As OperatingSystem
51 If osVer = Nothing Then
52 Dim vi As OSVERSIONINFO
53 GetVersionInfoEx(vi)
54 osVer = New OperatingSystem(vi)
55 End If
56 Return osVer
57 End Function
58
59 Static Function ProcessorCount() As Long
60 If processorCount = 0 Then
61 Dim si As SYSTEM_INFO
62 GetSystemInfo(si)
63 processorCount = si.dwNumberOfProcessors
64 End If
65 Return processorCount
66 End Function
67
68 ' StackTrace
69
70 Static Function SystemDirectory() As String
71 If sysDir = Nothing Then
72 Dim size = GetSystemDirectory(0, 0)
73 Dim p = _System_malloc(SizeOf (TCHAR) * size)
74 GetSystemDirectory(size, p)
75 sysDir = p
76 _System_free(p)
77 End IF
78 Return sysDir
79 End Function
80
81 Static Function TickCount() As Long
82 Return GetTickCount() As Long
83 End Function
84
85 ' UserDomainName
86
87 ' UserInteractive
88
89 ' UserName
90
91 ' Version
92
93 Static Function WorkingSet() As Int64
94 Dim pGetProcessMemoryInfo As *Function(Process As HANDLE, ByRef mc As PPROCESS_MEMORY_COUNTERS, cb As DWord) As BOOL
95 Dim hmodPSAPI = LoadLibrary("PSAPI.DLL")
96 If hmodPSAPI = 0 Then Return 0
97 pGetProcessMemoryInfo = GetProcAddress(hmodPSAPI, ToMBStr("GetProcessMemoryInfo"))
98 If pGetProcessMemoryInfo <> 0 Then
99 Dim mc As PPROCESS_MEMORY_COUNTERS
100 If pGetProcessMemoryInfo(GetCurrentProcess(), mc, Len (mc)) <> FALSE Then
101 WorkingSet = mc.WorkingSetSize
102 End If
103 End If
104 FreeLibrary(hmodPSAPI)
105 End Function
106
107 ' Methods
108
109 Static Sub Exit(exitCode As Long)
110 Environment.exitCode = exitCode
111 End
112 End Sub
113
114 Static Function ExpandEnvironmentVariables(s As String) As String
115 Dim src = ToTCStr(s)
116 Dim size = ExpandEnvironmentStrings(src, 0, 0)
117 Dim dst = _System_malloc(SizeOf (TCHAR) * size)
118 ExpandEnvironmentStrings(src, dst, size)
119 ExpandEnvironmentVariables = dst
120 _System_free(dst)
121 End Function
122
123 Static Sub FailFast(message As String)
124 OutputDebugString(ToTCStr(message))
125 ExitProcess(-1)
126 End Sub
127
128 ' GetCommandLineArgs
129
130 ' GetEnvironmentVariable
131
132 ' GetEnvironmentVariables
133
134 ' GetLogicalDrives
135
136 ' SetEnvironmentVariable
137
138Private
139 Static cmdLine = Nothing As String
140 Static exitCode = 0 As Long
141 Static osVer = Nothing As OperatingSystem
142 Static processorCount = 0 As Long
143 Static sysDir = Nothing As String
144End Class
Note: See TracBrowser for help on using the repository browser.