1 ' Licensed to the .NET Foundation under one or more agreements.
2 ' The .NET Foundation licenses this file to you under the MIT license.
3 ' See the LICENSE file in the project root for more information.
7 Imports System.Security
9 Imports Microsoft.VisualBasic.CompilerServices.ExceptionUtils
10 Imports Microsoft.VisualBasic.CompilerServices.Utils
12 Namespace Microsoft.VisualBasic.CompilerServices
14 <System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)>
15 Friend Class VB6OutputFile
17 '============================================================================
19 '============================================================================
22 '============================================================================
24 '============================================================================
29 Friend Sub New(ByVal FileName As String, ByVal share As OpenShare, ByVal fAppend As Boolean)
30 MyBase.New(FileName, OpenAccess.Write, share, -1)
34 '============================================================================
36 '============================================================================
37 Friend Overrides Sub OpenFile()
42 'consider checking WRITE if cannot open READWRITE
43 If File.Exists(m_sFullPath) Then
44 m_file = New FileStream(m_sFullPath, FileMode.Open, CType(m_access, FileAccess), CType(m_share, FileShare))
46 m_file = New FileStream(m_sFullPath, FileMode.Create, CType(m_access, FileAccess), CType(m_share, FileShare))
49 m_file = New FileStream(m_sFullPath, FileMode.Create, CType(m_access, FileAccess), CType(m_share, FileShare))
51 Catch ex As FileNotFoundException
52 Throw VbMakeException(ex, vbErrors.FileNotFound)
53 Catch ex As SecurityException
54 Throw VbMakeException(ex, vbErrors.FileNotFound)
55 Catch ex As DirectoryNotFoundException
56 Throw VbMakeException(ex, vbErrors.PathNotFound)
57 Catch ex As IOException
58 Throw VbMakeException(ex, vbErrors.PathFileAccess)
61 m_Encoding = GetFileIOEncoding()
62 m_sw = New StreamWriter(m_file, m_Encoding)
66 'Now position at end of file
67 Dim lEndOfFile As Long
68 lEndOfFile = m_file.Length
69 m_file.Position = lEndOfFile
70 m_position = lEndOfFile
74 Friend Overrides Sub WriteLine(ByVal s As String)
79 If m_bPrint AndAlso (m_lWidth <> 0) Then
80 If m_lCurrentColumn >= m_lWidth Then
87 Diagnostics.Debug.Assert(Not m_Encoding Is Nothing)
88 m_position += m_Encoding.GetByteCount(s) + 2
94 Friend Overrides Sub WriteString(ByVal s As String)
95 If (s Is Nothing) OrElse (s.Length = 0) Then
99 If m_bPrint AndAlso (m_lWidth <> 0) Then
100 If (m_lCurrentColumn >= m_lWidth) OrElse
101 (m_lCurrentColumn <> 0 AndAlso (m_lCurrentColumn + s.Length) > m_lWidth) Then
109 Diagnostics.Debug.Assert(Not m_Encoding Is Nothing)
110 Dim ByteLength As Integer = m_Encoding.GetByteCount(s)
111 m_position += ByteLength
112 m_lCurrentColumn += s.Length
115 Friend Overrides Function CanWrite() As Boolean
119 Public Overrides Function GetMode() As OpenMode
121 GetMode = OpenMode.Append
123 GetMode = OpenMode.Output
127 Friend Overrides Function EOF() As Boolean
131 Friend Overrides Function LOC() As Long
132 Return ((m_position + 127) \ 128)