Changeset 583


Ignore:
Timestamp:
Aug 10, 2008, 11:42:54 PM (16 years ago)
Author:
イグトランス (egtra)
Message:

情報のキャッシュを廃止。APIへの文字列バッファをStringBuilderで統一。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ab5.0/ablib/src/Classes/System/Environment.ab

    r497 r583  
    1919
    2020    Static Function CommandLine() As String
    21         If Object.ReferenceEquals(cmdLine, Nothing) Then
    2221#ifdef UNICODE
    23             cmdLine = New String(GetCommandLineW())
     22            CommandLine = New String(GetCommandLineW())
    2423#else
    25             cmdLine = New String(GetCommandLineA())
     24            CommandLine = New String(GetCommandLineA())
    2625#endif
    27         End If
    28         Return cmdLine
    2926    End Function
    3027
    3128    Static Function CurrentDirectory() As String
    3229        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))
    3533        If len < size Then
    36             CurrentDirectory = New String(p, len As Long)
     34            CurrentDirectory = buf.ToString
    3735        End If
    3836    End Function
     
    5553
    5654    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
    6463    End Function
    6564
     
    6968
    7069    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)
    7773    End Function
    7874
    7975    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
    8679    End Function
    8780
     
    8982
    9083    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
    9892    End Function
    9993
     
    107101
    108102    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
    116111    End Function
    117112
     
    192187
    193188Private
    194     Static cmdLine = Nothing As String
    195189    Static exitCode = 0 As Long
    196     Static machineName = Nothing As String
    197     Static osVer = Nothing As OperatingSystem
    198     Static processorCount = 0 As Long
    199     Static sysDir = Nothing As String
    200     Static userName = Nothing As String
    201190End Class
    202191
Note: See TracChangeset for help on using the changeset viewer.