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

Last change on this file since 224 was 208, checked in by イグトランス (egtra), 18 years ago

[207]参照型変数のNothing初期化に対応する修正

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