[271] | 1 | Namespace System
|
---|
| 2 | Namespace IO
|
---|
| 3 |
|
---|
| 4 |
|
---|
[83] | 5 | Class FileSystemInfo
|
---|
[84] | 6 | m_CreationTime As FILETIME
|
---|
| 7 | m_LastAccessTime As FILETIME
|
---|
| 8 | m_LastWriteTime As FILETIME
|
---|
| 9 | m_FileAttributes As DWord
|
---|
[345] | 10 |
|
---|
| 11 | m_IsFreshed As Boolean
|
---|
[83] | 12 | Protected
|
---|
| 13 | FullPath As String
|
---|
| 14 | OriginalPath As String
|
---|
| 15 | Public
|
---|
[345] | 16 | Sub FileSystemInfo()
|
---|
| 17 | m_IsFreshed = False
|
---|
| 18 | End Sub
|
---|
[318] | 19 |
|
---|
[345] | 20 | Sub ~FileSystemInfo()
|
---|
| 21 | End Sub
|
---|
| 22 |
|
---|
[318] | 23 | Override Function Equals( object As Object ) As Boolean
|
---|
| 24 | If This.ToString = object.ToString Then
|
---|
| 25 | Return True
|
---|
| 26 | Else
|
---|
| 27 | Return False
|
---|
| 28 | End If
|
---|
| 29 | End Function
|
---|
| 30 |
|
---|
| 31 | Override Function ToString() As String
|
---|
| 32 | Return FullPath
|
---|
| 33 | End Function
|
---|
| 34 |
|
---|
[83] | 35 | 'Public Properties
|
---|
[318] | 36 | Function Attributes() As DWord'FileAttributes
|
---|
[345] | 37 | If Not m_IsFreshed Then Refresh()
|
---|
[318] | 38 | Return m_FileAttributes
|
---|
[83] | 39 | End Function
|
---|
| 40 |
|
---|
[318] | 41 | Sub Attributes(value As DWord)
|
---|
| 42 | If SetFileAttributes(FullPath, value) = FALSE Then
|
---|
[83] | 43 | 'Exception
|
---|
| 44 | Debug
|
---|
| 45 | End If
|
---|
| 46 | End Sub
|
---|
| 47 |
|
---|
| 48 | Function CreationTime() As DateTime
|
---|
[345] | 49 | If Not m_IsFreshed Then Refresh()
|
---|
[84] | 50 | Return DateTime.FromFileTime(m_CreationTime)
|
---|
[83] | 51 | End Function
|
---|
| 52 |
|
---|
| 53 | Sub CreationTime(ByRef value As DateTime)
|
---|
[84] | 54 | m_CreationTime = value.ToFileTimeUtc()
|
---|
[333] | 55 | setFileTime()
|
---|
[83] | 56 | End Sub
|
---|
| 57 |
|
---|
| 58 | Function CreationTimeUtc() As DateTime
|
---|
[333] | 59 | Return CreationTime.ToUniversalTime()
|
---|
[83] | 60 | End Function
|
---|
| 61 |
|
---|
| 62 | Sub CreationTimeUtc(ByRef value As DateTime)
|
---|
| 63 | CreationTime = value
|
---|
| 64 | End Sub
|
---|
| 65 |
|
---|
| 66 | Function LastAccessTime() As DateTime
|
---|
[345] | 67 | If Not m_IsFreshed Then Refresh()
|
---|
[84] | 68 | Return DateTime.FromFileTime(m_LastAccessTime)
|
---|
[83] | 69 | End Function
|
---|
| 70 |
|
---|
| 71 | Sub LastAccessTime(ByRef value As DateTime)
|
---|
[84] | 72 | m_LastAccessTime = value.ToFileTimeUtc()
|
---|
[333] | 73 | setFileTime()
|
---|
[83] | 74 | End Sub
|
---|
| 75 |
|
---|
| 76 | Function LastAccessTimeUtc() As DateTime
|
---|
[333] | 77 | Return LastAccessTime.ToUniversalTime()
|
---|
[83] | 78 | End Function
|
---|
| 79 |
|
---|
| 80 | Sub LastAccessTimeUtc(ByRef value As DateTime)
|
---|
| 81 | LastAccessTime = value
|
---|
| 82 | End Sub
|
---|
| 83 |
|
---|
| 84 | Function LastWriteTime() As DateTime
|
---|
[345] | 85 | If Not m_IsFreshed Then Refresh()
|
---|
[84] | 86 | Return DateTime.FromFileTime(m_LastWriteTime)
|
---|
[83] | 87 | End Function
|
---|
| 88 |
|
---|
| 89 | Sub LastWriteTime(ByRef value As DateTime)
|
---|
[84] | 90 | m_LastWriteTime = value.ToFileTimeUtc()
|
---|
[333] | 91 | setFileTime()
|
---|
[83] | 92 | End Sub
|
---|
| 93 |
|
---|
| 94 | Function LastWriteTimeUtc() As DateTime
|
---|
[333] | 95 | Return LastWriteTime.ToUniversalTime()
|
---|
[83] | 96 | End Function
|
---|
| 97 |
|
---|
| 98 | Sub LastWriteTimeUtc(ByRef value As DateTime)
|
---|
| 99 | LastWriteTime = value
|
---|
| 100 | End Sub
|
---|
| 101 |
|
---|
| 102 | Function Exists() As Boolean
|
---|
[345] | 103 | If Not m_IsFreshed Then Refresh()
|
---|
[84] | 104 | If m_FileAttributes = 0 Then
|
---|
| 105 | Return False
|
---|
| 106 | Else
|
---|
| 107 | Return True
|
---|
| 108 | End If
|
---|
[83] | 109 | End Function
|
---|
| 110 |
|
---|
| 111 | Function Extension() As String
|
---|
| 112 | Return Path.GetExtension(FullPath)
|
---|
| 113 | End Function
|
---|
| 114 |
|
---|
| 115 | Function FullName() As String
|
---|
| 116 | Return FullPath
|
---|
| 117 | End Function
|
---|
| 118 |
|
---|
| 119 | Function Name() As String
|
---|
| 120 | Return Path.GetFileName(FullPath)
|
---|
| 121 | End Function
|
---|
| 122 |
|
---|
| 123 | 'Public Methods
|
---|
| 124 | Virtual Sub Delete()
|
---|
| 125 | If DeleteFile(FullPath) = FALSE Then
|
---|
| 126 | 'Exception
|
---|
| 127 | debug
|
---|
| 128 | End If
|
---|
| 129 | End Sub
|
---|
| 130 |
|
---|
[130] | 131 | Virtual Sub Refresh()
|
---|
[84] | 132 | Dim data As WIN32_FIND_DATA
|
---|
[142] | 133 | Dim hFind = FindFirstFile(ToTCStr(FullPath), data)
|
---|
[130] | 134 | FindClose(hFind)
|
---|
[84] | 135 |
|
---|
| 136 | m_FileAttributes = data.dwFileAttributes
|
---|
| 137 | m_CreationTime = data.ftCreationTime
|
---|
| 138 | m_LastAccessTime = data.ftLastAccessTime
|
---|
| 139 | m_LastWriteTime = data.ftLastWriteTime
|
---|
[346] | 140 |
|
---|
| 141 | m_IsFreshed = True
|
---|
[83] | 142 | End Sub
|
---|
| 143 | Private
|
---|
[333] | 144 | Sub setFileTime()
|
---|
[345] | 145 | If Not m_IsFreshed Then Refresh()
|
---|
[142] | 146 | Dim hFile = CreateFile(ToTCStr(FullPath), GENERIC_WRITE, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)
|
---|
[83] | 147 | If hFile = INVALID_HANDLE_VALUE Then
|
---|
[333] | 148 | debug 'Exception
|
---|
[83] | 149 | Exit Function
|
---|
| 150 | End If
|
---|
| 151 |
|
---|
[333] | 152 | If SetFileTime(hFile, m_CreationTime, m_LastAccessTime, m_LastWriteTime) = False Then
|
---|
| 153 | debug 'Exception
|
---|
[83] | 154 | End If
|
---|
[84] | 155 |
|
---|
| 156 | CloseHandle(hFile)
|
---|
[333] | 157 | End Sub
|
---|
[271] | 158 | End Class
|
---|
| 159 |
|
---|
| 160 |
|
---|
| 161 | End Namespace
|
---|
| 162 | End Namespace
|
---|