#define cTDiskInfoVer "Seguridad Check - 2006 ©"
#include "FiveWin.ch"
CLASS TDiskInfo
DATA nBBSector AS NUMERIC
DATA nUsedSpace AS NUMERIC
DATA nSBCluster AS NUMERIC
DATA nFreeSpace AS NUMERIC
DATA nTotalSpace AS NUMERIC
DATA cLabel AS CHARACTER
DATA cDrive AS CHARACTER
DATA cNumSerie AS CHARACTER
DATA cDriveType AS CHARACTER
DATA cFileSystem AS CHARACTER
METHOD New( cDrive ) CONSTRUCTOR
METHOD TDIVer() INLINE;
MsgInfo("By Multimax Ltda, Iquique - Chile" + CRLF +;
" For FiveWin + xHarbour. 32 Bits " + CRLF +;
" email:
elmoceballos@multimax.cl ",cTDiskInfoVer)
METHOD Default() // Default
METHOD Drive( cNewDrive ) // Drive
METHOD Label() INLINE ::cLabel // Label
METHOD DriveType() INLINE ::cDriveType // Drive Type
METHOD NumSerie() INLINE ::cNumSerie // Num Serie - Type DOS
METHOD FileSystem() INLINE Upper( ::cFileSystem ) // File System
METHOD BBSector() INLINE fFormat( ::nBBSector ) // Bytes by Sector
METHOD SBCluster() INLINE fFormat( ::nSBCluster ) // Sector by Cluster
METHOD UsedSpace() INLINE fFormat( ::nUsedSpace ) // Used Space
METHOD FreeSpace() INLINE fFormat( ::nFreeSpace ) // Free Space
METHOD TotalSpace() INLINE fFormat( ::nTotalSpace ) // Total Space
METHOD SUSpace() INLINE fFormat( ::nUsedSpace, .T. ) // Short Use Space
METHOD SFSpace() INLINE fFormat( ::nFreeSpace, .T. ) // Short Free Space
METHOD STSpace() INLINE fFormat( ::nTotalSpace, .T. ) // Short Total Space
METHOD PUSpace() // Porcent Used Space
METHOD PFSpace() // Porcent Free Space
ENDCLASS
//----------------------------------------------------------------------------//
// METHOD TDiskInfo:New | Versión 1.0 ENE - 2003 //
//----------------------------------------------------------------------------//
METHOD New( cDrive ) CLASS TDiskInfo // New
Default cDrive := "C:\"
cDrive := Left( AllTrim( cDrive ), 1 ) + ":\"
::cDrive := Upper( cDrive )
::Default()
Return Self
//----------------------------------------------------------------------------//
// METHOD TDiskInfo:Default() | Versión 1.0 ENE - 2003 //
//----------------------------------------------------------------------------//
METHOD Default() CLASS TDiskInfo
Local cDrive, cLabel, nSerial, cFileSystem
Local nSBCluster, nBBSector, nFreeClusters, nTotalClusters, nDiskType
Local acDrive := { "No Instalado",;
"Disco Removible",;
"Disco Local" ,;
"Disco de Red",;
"Unidad de CD",;
"Disco Virtual"}
cDrive := ::cDrive
nDiskType := GetDriveInfo( cDrive )
If nDiskType = 1
::cDrive := ""
::cLabel := ""
::cFileSystem := ""
::cNumSerie := ""
::cDriveType := acDrive[ nDiskType ]
::nBBSector := 0
::nSBCluster := 0
::nTotalSpace := 0
::nFreeSpace := 0
::nUsedSpace := 0
ELse
cLabel := Space(32)
cFileSystem := Space(32)
GetDiskInfo( cDrive, @nSBCluster, @nBBSector,;
@nFreeClusters, @nTotalClusters )
GetVolInfo( cDrive, @cLabel, Len( cLabel ), @nSerial,;
0, 0, @cFileSystem, Len( cFileSystem ) )
::cLabel := StrToken( cLabel , 1, Chr( 0 ) )
::cFileSystem := StrToken( cFileSystem, 1, Chr( 0 ) )
::cDriveType := acDrive[ nDiskType ]
::cNumSerie := Left ( L2Hex( nSerial ), 4) + "-" +;
Right( I2Hex( nSerial ), 4 )
::nBBSector := nBBSector
::nSBCluster := nSBCluster
::nTotalSpace := nTotalClusters * nSBCluster * nBBSector
::nFreeSpace := nSBCluster * nBBSector * nFreeClusters
::nUsedSpace := ::nTotalSpace - ::nFreeSpace
End If
Return Self
//----------------------------------------------------------------------------//
// METHOD TDiskInfo:Drive() | Versión 1.0 ENE - 2003 //
//----------------------------------------------------------------------------//
METHOD Drive( cNewDrive ) CLASS TDiskInfo // Drive
If !Empty( cNewDrive )
::cDrive:= Upper( cNewDrive )
::Default()
EndIf
Return ::cDrive
//----------------------------------------------------------------------------//
// METHOD TDiskInfo:PUSpace() | Versión 1.0 ENE - 2003 //
//----------------------------------------------------------------------------//
METHOD PUSpace() CLASS TDiskInfo // Porcent Used Space
Local cTotal := "0%"
If ::nFreeSpace <> 0
cTotal := AllTrim( Str( Round( ::nFreeSpace * 100 /;
::nTotalSpace, 0 ) ) ) + "%"
EndIf
Return cTotal
//----------------------------------------------------------------------------//
// METHOD TDiskInfo:PFSpace() | Versión 1.0 ENE - 2003 //
//----------------------------------------------------------------------------//
METHOD PFSpace() CLASS TDiskInfo // Porcent Free Space
Local cTotal := "0%"
If ::nUsedSpace <> 0
cTotal := AllTrim( Str( Round( ::nUsedSpace * 100 /;
::nTotalSpace, 0 ) ) ) + "%"
EndIf
Return cTotal
//----------------------------------------------------------------------------//
//FUNCTION Format() | Versión 1.0 ENE - 2003 //
//----------------------------------------------------------------------------//
Function fFormat( nValue, lShortFormat )
Local cTmp := " Bytes", cFormat
Local nBT, nKB, nMB, nGB, nTB, nPB, nTmp
Local cPicture := "999,999,999,999,999,999"
Default lShortFormat := .F.
If lShortFormat
nBT := 1024
nKB := nBT * nBT
nMB := nKB * nBT
nGB := nMB * nBT
nTB := nGB * nBT
nPB := nTB * nBT
Do Case
Case nValue < nKB
cTmp := " KB"
nTmp := nValue / nBT
Case nValue >= nKB .And. nValue < nMB
cTmp := " MB"
nTmp := nValue / nKB
Case nValue >= nMB .And. nValue < nGB
cTmp := " GB"
nTmp := nValue / nMB
Case nValue >= nGB .And. nValue < nTB
cTmp := " TB"
nTmp := nValue / nGB
Case nValue >= nTB .And. nValue < nPB
cTmp := " PB"
nTmp := nValue / nTB
OtherWise
cTmp := " N/D"
nTmp := nValue / ( nPB * nPB )
EndCase
cFormat := StrTran( Left( AllTrim( Str( nTmp ) ), 4 ), ".", "," ) + cTmp
Else
cFormat := StrTran( AllTrim( Transform( nValue, cPicture ) ), ",", "." ) + cTmp
EndIf
Return cFormat
//----------------------------------------------------------------------------//
// ******************** DECLARACIONES - API ******************** //
//----------------------------------------------------------------------------//
DLL32 Function GetDiskInfo(sDrive As STRING,;
@lSBCluster As LONG,;
@lBBSector As LONG,;
@lFreeClusters As LONG,;
@lTotalClusters As LONG);
;
AS LONG PASCAL;
FROM "GetDiskFreeSpaceA";
LIB "kernel32"
DLL32 Function GetVolInfo(sDrive AS STRING,;
@sVolName AS STRING,;
lVolSize AS LONG,;
@lVolSerial AS LONG,;
lMaxCompLength AS LONG,;
lFileSystFlags AS LONG,;
@sFileSystName AS STRING,;
lFileSystSize AS LONG);
;
AS LONG PASCAL;
FROM "GetVolumeInformationA";
LIB "kernel32"
DLL32 Function GetDriveInfo(sDrive AS STRING);
;
AS LONG PASCAL;
FROM "GetDriveTypeA";
LIB "kernel32"