Volumes
Volumes is a small cross-platform module which provides useful volume/device information support for BlitzMax.
The module is essentially split into two parts, that of volume information, and some functions which give user-specific directory paths.
Volume Information
Enables access to all volumes on the system, as well as drive-details such as free and total space for the volume.
To get a list of volumes on the current system, simply call ListVolumes which returns
a list of TVolume objects, from which you have access to the extra information.
You can also retrieve size information directly using GetVolumeSize and GetVolumeFreeSpace.
User Directories
Useful for the application developer is access to user-specific directories, like their home and document directories. The Volumes module provides access to four of these for all supported platforms: GetUserAppDir, GetUserDesktopDir, GetUserDocumentsDir, and GetUserHomeDir.
Functions Summary
Types Summary
Functions
| Function GetCustomDir:String(dirType:Int) |
| Description | Returns the custom directory path. |
| Information | The following table lists valid dirType -
| Platform | dirType | Description |
| Mac | DT_SHAREDUSERDATA | The Shared documents folder. |
Returns Null if dirType is not valid for the platform. |
| Function GetUserAppDir:String() |
| Description | Returns the user directory for application data. |
| Information | The table lists examples for the various platforms -
| Platform | Example | Equivalent |
| Linux | /home/username | ~ |
| Mac OS | /Users/username/Library/Application Support | ~/Library/Application Support |
| Win32 | C:\Documents and Settings\username\Application Data | |
|
| Example | SuperStrict
Framework BaH.Volumes
Import BRL.Standardio
Print GetUserAppDir() |
| Function GetUserDesktopDir:String() |
| Description | Returns the user Desktop directory. |
| Information | The table lists examples for the various platforms -
| Platform | Example | Equivalent |
| Linux | /home/username/Desktop | ~/Desktop |
| Mac OS | /Users/username/Desktop | ~/Desktop |
| Win32 | C:\Documents and Settings\username\Desktop | |
|
| Example | SuperStrict
Framework BaH.Volumes
Import BRL.Standardio
Print GetUserDesktopDir() |
| Function GetUserDocumentsDir:String() |
| Description | Returns the user Documents directory. |
| Information | The table lists examples for the various platforms -
| Platform | Example | Equivalent |
| Linux | /home/username/Documents | ~/Documents |
| Mac OS | /Users/username/Documents | ~/Documents |
| Win32 | C:\Documents and Settings\username\My Documents | |
|
| Example | SuperStrict
Framework BaH.Volumes
Import BRL.Standardio
Print GetUserDocumentsDir() |
| Function GetUserHomeDir:String() |
| Description | Returns the user home directory. |
| Information | The table lists examples for the various platforms -
| Platform | Example | Equivalent |
| Linux | /home/username | ~ |
| Mac OS | /Users/username | ~ |
| Win32 | C:\Documents and Settings\username | |
|
| Example | SuperStrict
Framework BaH.Volumes
Import BRL.Standardio
Print GetUserHomeDir() |
| Function GetVolumeFreeSpace:Long(vol:String) |
| Description | Returns the amount of free space (in bytes) on the given volume. |
| Information | Parameters:
- vol : the name of the volume
|
| Example | SuperStrict
Framework bah.volumes
Import brl.standardio
Local vol:String
?win32
vol = "C:\"
?linux
vol = "/"
?macos
vol = "/"
?
Print "Freespace :"
Print vol + " = " + (GetVolumeFreeSpace(vol) / 1024) + " kb" |
| Function GetVolumeInfo:TVolume(vol:String) |
| Description | Populates and returns a TVolume object. |
| Information | Parameters:
- vol : the name of the volume
|
| Function GetVolumeSize:Long(vol:String) |
| Description | Returns the size (in bytes) of the given volume. |
| Information | Parameters:
- vol : the name of the volume
|
| Example | SuperStrict
Framework bah.volumes
Import brl.standardio
Local vol:String
?win32
vol = "C:\"
?linux
vol = "/"
?macos
vol = "/"
?
Print "Total space :"
Print vol + " = " + (GetVolumeSize(vol) / 1024) + " kb" |
| Function ListVolumes:TList() |
| Description | Returns a list of volumes on the system. |
| Example | SuperStrict
Framework bah.volumes
Import brl.standardio
Local list:TList = ListVolumes()
If list Then
Print "Volumes :"
For Local v:TVolume = EachIn list
'If v.available Then
Print "~t" + v.volumeName + " - " + v.volumeDevice + " (" + v.volumeType + ") - " + ((v.volumeFree / 1024) / 1024) + "mb"
'End If
Next
End If |
Types
| Type TVolume |
| Description | A system Volume. |
| Methods Summary |
| Refresh |
Refreshes size/free info for the volume.
|
| Field available:Int |
| Description | True if available, false if not. |
| Field volumeDevice:String |
| Description | The device name. |
| Field volumeFree:Long |
| Description | Cached free space (in bytes) |
| Information | For the current free space, Refresh first. |
| Field volumeName:String |
| Description | The volume name. |
| Field volumeSize:Long |
| Description | Cached volume size (in bytes) |
| Information | For the current size, Refresh first. |
| Field volumeType:String |
| Description | The system type. |
| Method Refresh() Abstract |
| Description | Refreshes size/free info for the volume. |
Module Information
| Version | 1.05 |
| License | Free for commercial and personal use |
| Author | Bruce A Henderson |
| Copyright | (c) 2006, 2007 Bruce A Henderson |
| Modserver | BRL |
| History | 1.05 |
| History | Added GetCustomDir function. |
| History | 1.04 |
| History | Updated Win32 to use SHGetFolderPathW instead of SHGetFolderPathA |
| History | 1.03 |
| History | Added new functions : GetUserHomeDir, GetUserDesktopDir, GetUserAppDir, GetUserDocumentsDir. |
| History | 1.02 |
| History | Added Mac support. |
| History | 1.01 |
| History | Fixed win32 type returning the wrong string. |
| History | 1.00 Initial Release |