[271] | 1 | Namespace System
|
---|
| 2 | Namespace IO
|
---|
| 3 |
|
---|
| 4 |
|
---|
[64] | 5 | Enum DriveType
|
---|
| 6 | Unknown = 0
|
---|
| 7 | NoRootDirectory
|
---|
| 8 | Removable
|
---|
| 9 | Fixed
|
---|
| 10 | CDRom
|
---|
| 11 | Network
|
---|
| 12 | Ram
|
---|
| 13 | End Enum
|
---|
| 14 |
|
---|
| 15 | Class DriveInfo
|
---|
| 16 | m_DriveName As String
|
---|
| 17 | Public
|
---|
| 18 | Sub DriveInfo(driveName As String)
|
---|
[409] | 19 | m_DriveName = driveName.ToUpper()
|
---|
[64] | 20 | End Sub
|
---|
| 21 |
|
---|
| 22 | Sub ~DriveInfo()
|
---|
| 23 | End Sub
|
---|
| 24 |
|
---|
| 25 | 'property
|
---|
| 26 | Function AvailableFreeSpace() As QWord
|
---|
[400] | 27 | If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal VarPtr(AvailableFreeSpace) As *ULARGE_INTEGER, ByVal 0, ByVal 0) = FALSE Then
|
---|
| 28 | Throw New IOException("DriveInfo.AvailableFreeSpace: Failed to GetDiskFreeSpaceEx.")
|
---|
[64] | 29 | End If
|
---|
| 30 | End Function
|
---|
| 31 |
|
---|
| 32 | Function DriveFormat() As String
|
---|
[142] | 33 | Dim systemName[15] As TCHAR
|
---|
[400] | 34 | If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, systemName, Len (systemName) \ SizeOf (TCHAR)) Then
|
---|
| 35 | DriveFormat = New String( systemName )
|
---|
[64] | 36 | Else
|
---|
[400] | 37 | Throw New IOException("DriveInfo.DriveFormat: Failed to GetVolumeInformation.")
|
---|
[64] | 38 | End If
|
---|
| 39 | End Function
|
---|
| 40 |
|
---|
| 41 | Function DriveType() As Long
|
---|
[400] | 42 | Return GetDriveType(ToTCStr(m_DriveName))
|
---|
[64] | 43 | End Function
|
---|
| 44 |
|
---|
[142] | 45 | Function IsReady() As Boolean
|
---|
[400] | 46 | If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, NULL, 0) Then
|
---|
[142] | 47 | Return True
|
---|
[64] | 48 | Else
|
---|
[142] | 49 | Return False
|
---|
[64] | 50 | End If
|
---|
| 51 | End Function
|
---|
| 52 |
|
---|
| 53 | Function Name() As String
|
---|
| 54 | Return m_DriveName
|
---|
| 55 | End Function
|
---|
| 56 |
|
---|
| 57 | /* Function RootDirectory() As DirectoryInfo
|
---|
| 58 | End Function*/
|
---|
| 59 |
|
---|
| 60 | Function TotalFreeSpace() As QWord
|
---|
[400] | 61 | If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal 0, ByVal VarPtr(TotalFreeSpace) As *ULARGE_INTEGER) = FALSE Then
|
---|
| 62 | Throw New IOException("DriveInfo.TotalFreeSpace: Failed to GetDiskFreeSpaceEx.")
|
---|
[64] | 63 | End If
|
---|
| 64 | End Function
|
---|
| 65 |
|
---|
| 66 | Function TotalSize() As QWord
|
---|
[400] | 67 | If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal VarPtr(TotalSize) As *ULARGE_INTEGER, ByVal 0) = FALSE Then
|
---|
| 68 | Throw New IOException("DriveInfo.TotalSize: Failed to GetDiskFreeSpaceEx.")
|
---|
[64] | 69 | End If
|
---|
| 70 | End Function
|
---|
| 71 |
|
---|
| 72 | Function VolumeLabel() As String
|
---|
[288] | 73 | Dim volumeName[63] As TCHAR
|
---|
[400] | 74 | If GetVolumeInformation(ToTCStr(m_DriveName), volumeName, Len (volumeName) \ SizeOf (TCHAR), NULL, NULL, NULL, NULL, 0) Then
|
---|
| 75 | VolumeLabel = New String( volumeName )
|
---|
[64] | 76 | Else
|
---|
[400] | 77 | Throw New IOException("DriveInfo.VolumeLabel: Failed to GetVolumeInformation.")
|
---|
[64] | 78 | End If
|
---|
| 79 | End Function
|
---|
[142] | 80 | End Class
|
---|
[271] | 81 |
|
---|
| 82 |
|
---|
| 83 | End Namespace
|
---|
| 84 | End Namespace
|
---|