Namespace System
Namespace IO


Enum DriveType
	Unknown = 0
	NoRootDirectory
	Removable
	Fixed
	CDRom
	Network
	Ram
End Enum

Class DriveInfo
	m_DriveName As String
Public
	Sub DriveInfo(driveName As String)
		m_DriveName = driveName.ToUpper()
	End Sub

	Sub ~DriveInfo()
	End Sub

	'property
	Function AvailableFreeSpace() As QWord
		If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal VarPtr(AvailableFreeSpace) As *ULARGE_INTEGER, ByVal 0, ByVal 0) = FALSE Then
			Throw New IOException("DriveInfo.AvailableFreeSpace: Failed to GetDiskFreeSpaceEx.")
		End If
	End Function

	Function DriveFormat() As String
		Dim systemName[15] As TCHAR
		If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, systemName, Len (systemName) \ SizeOf (TCHAR)) Then
			DriveFormat = New String( systemName )
		Else
			Throw New IOException("DriveInfo.DriveFormat: Failed to GetVolumeInformation.")
		End If
	End Function

	Function DriveType() As Long
		Return GetDriveType(ToTCStr(m_DriveName))
	End Function

	Function IsReady() As Boolean
		If GetVolumeInformation(ToTCStr(m_DriveName), NULL, 0, NULL, NULL, NULL, NULL, 0) Then
			Return True
		Else
			Return False
		End If
	End Function

	Function Name() As String
		Return m_DriveName
	End Function

/*	Function RootDirectory() As DirectoryInfo
	End Function*/

	Function TotalFreeSpace() As QWord
		If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal 0, ByVal VarPtr(TotalFreeSpace) As *ULARGE_INTEGER) = FALSE Then
			Throw New IOException("DriveInfo.TotalFreeSpace: Failed to GetDiskFreeSpaceEx.")
		End If
	End Function

	Function TotalSize() As QWord
		If GetDiskFreeSpaceEx(ToTCStr(m_DriveName), ByVal 0, ByVal VarPtr(TotalSize) As *ULARGE_INTEGER, ByVal 0) = FALSE Then
			Throw New IOException("DriveInfo.TotalSize: Failed to GetDiskFreeSpaceEx.")
		End If
	End Function

	Function VolumeLabel() As String
		Dim volumeName[63] As TCHAR
		If GetVolumeInformation(ToTCStr(m_DriveName), volumeName, Len (volumeName) \ SizeOf (TCHAR), NULL, NULL, NULL, NULL, 0) Then
			VolumeLabel = New String( volumeName )
		Else
			Throw New IOException("DriveInfo.VolumeLabel: Failed to GetVolumeInformation.")
		End If
	End Function
End Class


End Namespace
End Namespace
