- Timestamp:
- May 23, 2007, 9:33:58 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/Classes/System/IO/FileStream.ab
r256 r260 1 1 2 /* ほんとはmisc かファイルを分けたほうがいいかもしれないが一先ず実装 */2 /* ほんとはmiscに入れるかかファイルを分けたほうがいいかもしれないが一先ず実装 */ 3 3 Enum FileOptions 4 4 Asynchronous … … 17 17 18 18 /* 19 ファイルハンドルからこれらを取得できれば 入らないが19 ファイルハンドルからこれらを取得できれば、これらは入らないが 20 20 今のところは不明なので自前で実装するしかない 21 21 */ … … 30 30 31 31 Public 32 /* コンストラクタ.NETと同じように実装は難しい、一先ず動くものを実装したが 要変更だと思う */32 /* コンストラクタ.NETと同じように実装は難しい、一先ず動くものを実装したが変更が必要だと思う */ 33 33 Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare, options As FileOptions) 34 Dim ac cAs DWord35 Dim mo dAs DWord36 Dim sh aAs DWord37 Dim op tAs DWord34 Dim ac As DWord 35 Dim mo As DWord 36 Dim sh As DWord 37 Dim op As DWord 38 38 39 39 Select Case access 40 40 Case FileAccess.Read 41 ac c=GENERIC_READ41 ac=GENERIC_READ 42 42 Case FileAccess.ReadWrite 43 ac c=GENERIC_READ or GENERIC_WRITE43 ac=GENERIC_READ or GENERIC_WRITE 44 44 Case FileAccess.Write 45 ac c=GENERIC_WRITE45 ac=GENERIC_WRITE 46 46 End Select 47 47 48 48 Select Case share 49 49 Case FileShare.DeleteFile 50 sh a=FILE_SHARE_DELETE50 sh=FILE_SHARE_DELETE 51 51 Case FileShare.None 52 sh a=052 sh=0 53 53 Case FileShare.Read 54 sh a=FILE_SHARE_READ54 sh=FILE_SHARE_READ 55 55 Case FileShare.ReadWrite 56 sh a=FILE_SHARE_READ or FILE_SHARE_WRITE57 Case Write58 sh a=FILE_SHARE_WRITE56 sh=FILE_SHARE_READ or FILE_SHARE_WRITE 57 Case FileShare.Write 58 sh=FILE_SHARE_WRITE 59 59 End Select 60 60 … … 75 75 76 76 Select Case options 77 Case FileOption .Asynchronous78 op t=FILE_FLAG_OVERLAPPED77 Case FileOptions.Asynchronous 78 op=FILE_FLAG_OVERLAPPED 79 79 Case FileOptions.DeleteOnClose 80 op t=FILE_FLAG_DELETE_ON_CLOSE80 op=FILE_FLAG_DELETE_ON_CLOSE 81 81 Case FileOptions.Encrypted 82 82 Case FileOptions.None 83 op t=083 op=0 84 84 Case FileOptions.RandomAccess 85 op t=FILE_FLAG_RANDOM_ACCESS85 op=FILE_FLAG_RANDOM_ACCESS 86 86 Case FileOptions.SequentialScan 87 op t=FILE_FLAG_SEQUENTIAL_SCAN87 op=FILE_FLAG_SEQUENTIAL_SCAN 88 88 Case FileOptions.WriteThrough 89 op t=FILE_FLAG_WRITE_THROUGH90 End Select 91 92 This.handle=CreateFile(path.Chars As PSTR,ac c,sha,ByVal NULL,mo,opt,0)93 If This.handle= HANDLE_INVALIDATE Then89 op=FILE_FLAG_WRITE_THROUGH 90 End Select 91 92 This.handle=CreateFile(path.Chars As PSTR,ac,sh,ByVal NULL,mo,op,0) 93 If This.handle=INVALID_HANDLE_VALUE Then 94 94 'エラー処理 95 95 'Throw ArgumentException 96 96 'Throw IOException 97 97 'Throw System.IO.FileNotFoundException 98 This.handle=0 98 99 Exit Sub 99 100 End If 100 101 101 fileMode = mod 102 fileAccess = acc 103 fileShare = sha 104 fileOptions = opt 102 filePath = path 103 fileMode = mo 104 fileAccess = ac 105 fileShare = sh 106 fileOptions = op 107 End Sub 108 Sub FileStream(path As String, mode As FileMode, access As FileAccess, share As FileShare) 109 FileStream(path,mode,access,share,FileOptions.None) 110 End Sub 111 Sub FileStream(path As String, mode As FileMode, access As FileAccess) 112 FileStream(path,mode,access,FileShare.None,FileOptions.None) 105 113 End Sub 106 114 Sub FileStream(path As String, mode As FileMode) 107 Dim acc As DWord 108 Dim mo As DWord 115 Dim access As FileAccess 109 116 Select Case mode 110 117 Case FileMode.Append 111 acc=GENERIC_WRITE 112 mo=OPEN_ALWAYS 113 ' OutputDebugString(Ex"append\n") 118 access=FileAccess.Write 114 119 Case FileMode.Create 115 acc=GENERIC_READ or GENERIC_WRITE 116 mo=CREATE_ALWAYS 117 ' OutputDebugString(Ex"create\n") 120 access=FileAccess.ReadWrite 118 121 Case FileMode.CreateNew 119 acc=GENERIC_READ or GENERIC_WRITE 120 mo=CREATE_NEW 121 ' OutputDebugString(Ex"create new\n") 122 access=FileAccess.ReadWrite 122 123 Case FileMode.Open 123 acc=GENERIC_READ or GENERIC_WRITE 124 mo=OPEN_EXISTING 125 ' OutputDebugString(Ex"open\n") 124 access=FileAccess.ReadWrite 126 125 Case FileMode.OpenOrCreate 127 acc=GENERIC_READ or GENERIC_WRITE 128 mo=OPEN_ALWAYS 129 ' OutputDebugString(Ex"open or create\n") 126 access=FileAccess.ReadWrite 130 127 Case FileMode.Truncate 131 acc=GENERIC_WRITE 132 mo=TRUNCATE_EXISTING 133 ' OutputDebugString(Ex"truncate\n") 134 End Select 135 136 'ファイルを作成または開く 137 This.handle=CreateFile(path.Chars As PSTR,acc,0,ByVal NULL,mo,0,0) 138 139 'エラー処理 140 'Throw ArgumentException 141 'Throw IOException 142 'Throw System.IO.FileNotFoundException 143 144 145 'ファイルを作成または開いた後の処理 146 If mode=FileMode.Append Then 147 SetFilePointer(This.handle,0,NULL,FILE_END) 148 End If 128 access=FileAccess.Write 129 End Select 130 FileStream(path,mode,access,FileShare.None,FileOptions.None) 149 131 End Sub 150 132
Note:
See TracChangeset
for help on using the changeset viewer.