Ignore:
Timestamp:
Nov 25, 2007, 4:31:35 PM (17 years ago)
Author:
イグトランス (egtra)
Message:

Stringなどで例外を投げるようにした。
#147の解決。
CType ASCII文字判定関数群の追加。

Location:
trunk/Include/Classes/System/IO
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Include/Classes/System/IO/FileStream.ab

    r349 r388  
    11Namespace System
    22Namespace IO
    3 
    43
    54/* ほんとはmiscに入れるかかファイルを分けたほうがいいかもしれないが一先ず実装 */
     
    2827    fileShare As DWord
    2928    fileOptions As DWord
    30     fileReadOverlapped As OVERLAPPED
    31     fileWriteOverlapped As OVERLAPPED
     29   
     30    offset As QWord 'オーバーラップドIO用
    3231
    3332Public
     
    108107        This.fileShare = sh
    109108        This.fileOptions = op
     109        This.offset = 0
    110110    End Sub
    111111    Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare)
     
    133133        This.FileStream(path,mode,access,FileShare.None,FileOptions.None)
    134134    End Sub
    135 
    136     Sub ~FileStream()
    137         This.Flush()
    138         This.Close()
    139     End Sub
    140 
    141135Public
    142136    Override Function CanRead() As Boolean
     
    176170    Function IsAsync() As Boolean
    177171        /* ファイルが非同期操作に対応しているかを返す */
    178         If This.fileOptions=FILE_FLAG_OVERLAPPED/*FileOptions.Asynchronous*/ Then
     172        If This.fileOptions And FILE_FLAG_OVERLAPPED /*FileOptions.Asynchronous*/ Then
    179173            Return True
    180174        Else
     
    187181            Dim length As LARGE_INTEGER
    188182            length.LowPart=GetFileSize(This.handle,VarPtr(length.HighPart) As *DWord)
    189             Return MAKEQWORD(length.LowPart,length.HighPart)
     183            Return MAKEQWORD(length.LowPart,length.HighPart) As Int64
    190184        End If
    191185    End Function
    192186
    193187    Function Name() As String
    194         Return New String(This.filePath)
     188        Return This.filePath
    195189    End Function
    196190   
     
    198192        If This.CanSeek() Then
    199193            If This.IsAsync() Then
    200                 fileReadOverlapped.Offset=LODWORD(value)
    201                 fileReadOverlapped.OffsetHigh=HIDWORD(value)
    202                 fileWriteOverlapped.OffsetHigh=LODWORD(value)
    203                 fileWriteOverlapped.OffsetHigh=HIDWORD(value)
     194                offset = value As QWord
    204195            Else
    205196                Dim position As LARGE_INTEGER
     
    213204        If This.CanSeek() Then
    214205            If This.IsAsync() Then
    215                 Return MAKEQWORD(fileReadOverlapped.Offset,fileReadOverlapped.OffsetHigh)
     206                Return offset As Int64
    216207            Else
    217208                Dim position As LARGE_INTEGER
    218209                ZeroMemory(VarPtr(position),SizeOf(LARGE_INTEGER))
    219210                position.LowPart=SetFilePointer(This.handle,position.LowPart,VarPtr(position.HighPart) As *DWord,FILE_CURRENT)
    220                 Return MAKEQWORD(position.LowPart,position.HighPart)
     211                Return MAKEQWORD(position.LowPart,position.HighPart) As Int64
    221212            End If
    222213        End If
     
    257248    End Function
    258249
    259     Override Sub Close()
    260         This.Dispose()
    261     End Sub
    262 
    263250/*  CreateObjRef*/
    264251   
    265     Override Sub Dispose()
     252    Override Sub Dispose(disposing As Boolean)
     253        Flush()
    266254        CloseHandle(InterlockedExchangePointer(VarPtr(This.handle),NULL))
    267255    End Sub
    268256
    269     Override Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long
    270         'TODO
    271     End Function
    272 
    273     Override Sub EndWrite(ByRef asyncResult As System.IAsyncResult)
     257    Override Function EndRead(asyncResult As System.IAsyncResult) As Long
     258        'TODO
     259    End Function
     260
     261    Override Sub EndWrite(asyncResult As System.IAsyncResult)
    274262        'TODO
    275263    End Sub
     
    298286
    299287    Sub Lock(position As Int64, length As Int64)
     288        If position < 0 Then
     289            Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position")
     290        ElseIf length < 0 Then
     291            Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(length), "length")
     292        End If
     293        LockFile(handle, LODWORD(position As QWord), HIDWORD(position As QWord),
     294            LODWORD(length As QWord), HIDWORD(length As QWord))
    300295    End Sub
    301296
    302297    Override Function Read( buffer As *Byte, offset As Long, count As Long) As Long
    303298        If This.CanRead() Then
    304             Dim ret As DWord
    305             If This.IsAsync() Then
    306                 ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),This.fileReadOverlapped)
    307                 While This.fileReadOverlapped.Internal=STATUS_PENDING
    308                 Wend
    309                 fileReadOverlapped.Offset+=LODWORD(ret)
    310                 fileReadOverlapped.OffsetHigh+=HIDWORD(ret)
    311                 fileWriteOverlapped.Offset+=LODWORD(ret)
    312                 fileWriteOverlapped.OffsetHigh+=HIDWORD(ret)
    313                 Return ret
    314             Else
    315                 ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),ByVal NULL)
    316                 Return ret
    317             End If
     299            Dim readBytes As DWord
     300            If This.IsAsync() Then
     301                Dim overlapped As OVERLAPPED
     302                SetQWord(VarPtr(overlapped.Offset), offset)
     303                Dim ret = ReadFile(This.handle, VarPtr(buffer[offset]), count, 0, overlapped)
     304                If ret = FALSE Then
     305                    If GetLastError() = ERROR_IO_PENDING Then
     306                        GetOverlappedResult(This.handle, overlapped, readBytes, TRUE)
     307                    End If
     308                End If
     309                offset += Read
     310            Else
     311                ReadFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(readBytes),ByVal NULL)
     312            End If
     313            Read = readBytes As Long
    318314        End If
    319315    End Function
     
    326322                Select Case origin
    327323                    Case SeekOrigin.Begin
    328                         fileReadOverlapped.Offset=LODWORD(offset)
    329                         fileReadOverlapped.OffsetHigh=HIDWORD(offset)
    330                         fileWriteOverlapped.OffsetHigh=LODWORD(offset)
    331                         fileWriteOverlapped.OffsetHigh=HIDWORD(offset)
     324                        This.offset = offset
    332325                    Case SeekOrigin.Current
    333                         fileReadOverlapped.Offset+=LODWORD(offset)
    334                         fileReadOverlapped.OffsetHigh+=HIDWORD(offset)
    335                         fileWriteOverlapped.Offset+=LODWORD(offset)
    336                         fileWriteOverlapped.OffsetHigh+=HIDWORD(offset)
     326                        This.offset += offset
    337327                    Case SeekOrigin.End
    338                         fileReadOverlapped.Offset=LODWORD(This.Length()+offset)
    339                         fileReadOverlapped.OffsetHigh=HIDWORD(This.Length()+offset)
    340                         fileWriteOverlapped.Offset=LODWORD(This.Length()+offset)
    341                         fileWriteOverlapped.OffsetHigh=HIDWORD(This.Length()+offset)
     328                        This.offset = This.Length + offset
    342329                End Select
    343330            Else
     
    379366
    380367    Sub Unlock(position As Int64, length As Int64)
    381     End Sub
     368        If position < 0 Then
     369            Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(position), "position")
     370        ElseIf length < 0 Then
     371            Throw New ArgumentOutOfRangeException("FileStream.Lock: An argument is negative value.", New System.Int64(length), "length")
     372        End If
     373        UnlockFile(handle, LODWORD(position As QWord), HIDWORD(position As QWord),
     374            LODWORD(length As QWord), HIDWORD(length As QWord))
     375    End Sub
     376
    382377
    383378    Override Sub Write(buffer As *Byte, offset As Long, count As Long)
    384379        If This.CanWrite() Then
    385             Dim ret As DWord
    386             If This.IsAsync() Then
    387                 WriteFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),This.fileWriteOverlapped)
    388                 While This.fileReadOverlapped.Internal=STATUS_PENDING
    389                 Wend
    390                 This.fileReadOverlapped.Offset+=LODWORD(ret)
    391                 This.fileReadOverlapped.OffsetHigh+=HIDWORD(ret)
    392                 This.fileWriteOverlapped.Offset+=LODWORD(ret)
    393                 This.fileWriteOverlapped.OffsetHigh+=HIDWORD(ret)
    394             Else
    395                 WriteFile(This.handle,VarPtr(buffer[offset]),count,VarPtr(ret),ByVal NULL)
     380            Dim writeBytes As DWord
     381            If This.IsAsync() Then
     382                Dim overlapped As OVERLAPPED
     383                SetQWord(VarPtr(overlapped.Offset), offset)
     384                Dim ret = WriteFile(This.handle, VarPtr(buffer[offset]), count, 0, overlapped)
     385                If ret = FALSE Then
     386                    If GetLastError() = ERROR_IO_PENDING Then
     387                        GetOverlappedResult(This.handle, overlapped, writeBytes, TRUE)
     388                    End If
     389                End If
     390                offset += writeBytes
     391            Else
     392                WriteFile(This.handle, VarPtr(buffer[offset]), count, VarPtr(writeBytes), ByVal NULL)
    396393            End If
    397394        End If
  • trunk/Include/Classes/System/IO/Path.ab

    r296 r388  
    1010Class Path
    1111Public
    12     Static AltDirectorySeparatorChar = &H2F As Char '/
    13     Static DirectorySeparatorChar = &H5C As Char    '\
    14     Static PathSeparator = &H3B As Char             ';
    15     Static VolumeSeparatorChar = &H3A As Char       ':
     12    Static AltDirectorySeparatorChar = &H2F As StrChar '/
     13    Static DirectorySeparatorChar = &H5C As StrChar    '\
     14    Static PathSeparator = &H3B As StrChar             ';
     15    Static VolumeSeparatorChar = &H3A As StrChar       ':
    1616
    1717    Static Function GetFileName(path As String) As String
     
    121121
    122122    Static Function Combine(path1 As String, path2 As String) As String
    123         If path1.LastIndexOf(Chr$(VolumeSeparatorChar)) And path1.Length = 2 Then
     123        If path1.LastIndexOf(VolumeSeparatorChar) And path1.Length = 2 Then
    124124            Return path1 + path2
    125125        End If
    126126
    127         If path1.LastIndexOf(Chr$(DirectorySeparatorChar), ELM(path1.Length), 1) = -1 Then
     127        If path1.LastIndexOf(DirectorySeparatorChar, ELM(path1.Length), 1) = -1 Then
    128128            Return path1 + Chr$(DirectorySeparatorChar) + path2
    129129        Else
     
    133133
    134134Private
    135     Static Function getExtensionPosition(ByRef path As String) As Long
     135    Static Function getExtensionPosition(path As String) As Long
    136136        Dim lastSepPos = getLastSeparatorPosision(path) As Long
    137         getExtensionPosition = path.LastIndexOf(".", ELM(path.Length), path.Length - lastSepPos)
     137        If lastSepPos = -1 Then
     138            lastSepPos = 0
     139        End If
     140        getExtensionPosition = path.LastIndexOf(Asc("."), ELM(path.Length), path.Length - lastSepPos)
    138141    End Function
    139142
    140     Static Function getLastSeparatorPosision(ByRef path As String) As Long
    141         Dim lastSepPos = path.LastIndexOf(Chr$(DirectorySeparatorChar)) As Long
     143    Static Function getLastSeparatorPosision(path As String) As Long
     144        Dim lastSepPos = path.LastIndexOf(DirectorySeparatorChar) As Long
    142145        If lastSepPos <> -1 Then Return lastSepPos
    143146
    144         lastSepPos = path.LastIndexOf(Chr$(VolumeSeparatorChar))
     147        lastSepPos = path.LastIndexOf(VolumeSeparatorChar)
    145148        Return lastSepPos
    146149    End Function
  • trunk/Include/Classes/System/IO/Stream.ab

    r381 r388  
    1010Public
    1111    Virtual Sub ~Stream()
    12         This.Close()
     12        This.Dispose(False)
    1313    End Sub
    1414Public
     
    4949    End Function
    5050    Virtual Sub Close()
    51         This.Dispose()
     51        Dispose(True)
    5252    End Sub
     53    Virtual Sub Dispose()
     54        Dispose(True)
     55    End Sub
     56    Virtual Sub Dispose(disposing As Boolean):  End Sub
    5357    Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long: End Function
    5458    Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult): End Sub
Note: See TracChangeset for help on using the changeset viewer.