Changeset 388 for trunk/Include/Classes/System/IO
- Timestamp:
- Nov 25, 2007, 4:31:35 PM (17 years ago)
- Location:
- trunk/Include/Classes/System/IO
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Include/Classes/System/IO/FileStream.ab
r349 r388 1 1 Namespace System 2 2 Namespace IO 3 4 3 5 4 /* ほんとはmiscに入れるかかファイルを分けたほうがいいかもしれないが一先ず実装 */ … … 28 27 fileShare As DWord 29 28 fileOptions As DWord 30 fileReadOverlapped As OVERLAPPED31 fileWriteOverlapped As OVERLAPPED29 30 offset As QWord 'オーバーラップドIO用 32 31 33 32 Public … … 108 107 This.fileShare = sh 109 108 This.fileOptions = op 109 This.offset = 0 110 110 End Sub 111 111 Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare) … … 133 133 This.FileStream(path,mode,access,FileShare.None,FileOptions.None) 134 134 End Sub 135 136 Sub ~FileStream()137 This.Flush()138 This.Close()139 End Sub140 141 135 Public 142 136 Override Function CanRead() As Boolean … … 176 170 Function IsAsync() As Boolean 177 171 /* ファイルが非同期操作に対応しているかを返す */ 178 If This.fileOptions =FILE_FLAG_OVERLAPPED/*FileOptions.Asynchronous*/ Then172 If This.fileOptions And FILE_FLAG_OVERLAPPED /*FileOptions.Asynchronous*/ Then 179 173 Return True 180 174 Else … … 187 181 Dim length As LARGE_INTEGER 188 182 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 190 184 End If 191 185 End Function 192 186 193 187 Function Name() As String 194 Return New String(This.filePath)188 Return This.filePath 195 189 End Function 196 190 … … 198 192 If This.CanSeek() Then 199 193 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 204 195 Else 205 196 Dim position As LARGE_INTEGER … … 213 204 If This.CanSeek() Then 214 205 If This.IsAsync() Then 215 Return MAKEQWORD(fileReadOverlapped.Offset,fileReadOverlapped.OffsetHigh)206 Return offset As Int64 216 207 Else 217 208 Dim position As LARGE_INTEGER 218 209 ZeroMemory(VarPtr(position),SizeOf(LARGE_INTEGER)) 219 210 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 221 212 End If 222 213 End If … … 257 248 End Function 258 249 259 Override Sub Close()260 This.Dispose()261 End Sub262 263 250 /* CreateObjRef*/ 264 251 265 Override Sub Dispose() 252 Override Sub Dispose(disposing As Boolean) 253 Flush() 266 254 CloseHandle(InterlockedExchangePointer(VarPtr(This.handle),NULL)) 267 255 End Sub 268 256 269 Override Function EndRead( ByRefasyncResult As System.IAsyncResult) As Long270 'TODO 271 End Function 272 273 Override Sub EndWrite( ByRefasyncResult 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) 274 262 'TODO 275 263 End Sub … … 298 286 299 287 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)) 300 295 End Sub 301 296 302 297 Override Function Read( buffer As *Byte, offset As Long, count As Long) As Long 303 298 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 318 314 End If 319 315 End Function … … 326 322 Select Case origin 327 323 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 332 325 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 337 327 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 342 329 End Select 343 330 Else … … 379 366 380 367 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 382 377 383 378 Override Sub Write(buffer As *Byte, offset As Long, count As Long) 384 379 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) 396 393 End If 397 394 End If -
trunk/Include/Classes/System/IO/Path.ab
r296 r388 10 10 Class Path 11 11 Public 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 ': 16 16 17 17 Static Function GetFileName(path As String) As String … … 121 121 122 122 Static Function Combine(path1 As String, path2 As String) As String 123 If path1.LastIndexOf( Chr$(VolumeSeparatorChar)) And path1.Length = 2 Then123 If path1.LastIndexOf(VolumeSeparatorChar) And path1.Length = 2 Then 124 124 Return path1 + path2 125 125 End If 126 126 127 If path1.LastIndexOf( Chr$(DirectorySeparatorChar), ELM(path1.Length), 1) = -1 Then127 If path1.LastIndexOf(DirectorySeparatorChar, ELM(path1.Length), 1) = -1 Then 128 128 Return path1 + Chr$(DirectorySeparatorChar) + path2 129 129 Else … … 133 133 134 134 Private 135 Static Function getExtensionPosition( ByRefpath As String) As Long135 Static Function getExtensionPosition(path As String) As Long 136 136 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) 138 141 End Function 139 142 140 Static Function getLastSeparatorPosision( ByRefpath As String) As Long141 Dim lastSepPos = path.LastIndexOf( Chr$(DirectorySeparatorChar)) As Long143 Static Function getLastSeparatorPosision(path As String) As Long 144 Dim lastSepPos = path.LastIndexOf(DirectorySeparatorChar) As Long 142 145 If lastSepPos <> -1 Then Return lastSepPos 143 146 144 lastSepPos = path.LastIndexOf( Chr$(VolumeSeparatorChar))147 lastSepPos = path.LastIndexOf(VolumeSeparatorChar) 145 148 Return lastSepPos 146 149 End Function -
trunk/Include/Classes/System/IO/Stream.ab
r381 r388 10 10 Public 11 11 Virtual Sub ~Stream() 12 This. Close()12 This.Dispose(False) 13 13 End Sub 14 14 Public … … 49 49 End Function 50 50 Virtual Sub Close() 51 This.Dispose()51 Dispose(True) 52 52 End Sub 53 Virtual Sub Dispose() 54 Dispose(True) 55 End Sub 56 Virtual Sub Dispose(disposing As Boolean): End Sub 53 57 Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long: End Function 54 58 Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult): End Sub
Note:
See TracChangeset
for help on using the changeset viewer.