/* *************************** */
FUNCTION cSelectUSB( lMensaje )
Local aDriveUSB := {}
Local nDriveUSB := 0
Local cDriveUSB := ""
Local nContador := 0
aDriveUSB := aUSBDrive()
If Len( aDriveUSB ) = 0
If lMensaje
MsgAlert( GetTrad("No hi han unitats USB disponibles, insereixi una unitat USB."), GetTrad("A T E N C I Ó !" ) )
EndIf
Else
nDriveUSB := MsgList( aDriveUSB, GetTrad("Unitats USB disponibles:"), Nil, Nil, Nil, 15, "Seleccionar", nDriveUSB, .T., Nil )
//Traza( 1, nDriveUSB := MsgList( aDriveUSB, GetTrad("Unitats USB disponibles:"), Nil, Nil, Nil, 15, "Seleccionar", nDriveUSB, .T., Nil ) )
If nDriveUSB > 0
cDriveUSB := SubStr( aDriveUSB[ nDriveUSB ], 1, 3 )
//Traza(1, "aDriveUSB[ nDriveUSB ]=", aDriveUSB[ nDriveUSB ])
EndIf
EndIf
//Traza(1, "cDriveUSB=", cDriveUSB)
Return cDriveUSB
/* *************************** */
/* ************************************
Torna una array dels USB connectats.
--------------------------------- */
#define DRIVE_REMOVABLE 2
STATIC FUNCTION aUSBDrive()
Local nBitDrives := GetLogicalDrives()
Local nContador := 0
Local cDrive := ""
Local aDrives := {}
For nContador := 1 to 32
If lAnd( nBitDrives, 2 ^ ( nContador - 1 ) )
cDrive = Chr( Asc( "A" ) - 1 + nContador ) + ":\"
If nContador != 1 .and. GetDriveType( cDrive ) == DRIVE_REMOVABLE
If lExistUSB( cDrive )
AAdd( aDrives, cDrive )
EndIf
Endif
Endif
Next
Return aDrives
/* *************************** */
/* *************************** */
FUNCTION lExistUSB( cDisk )
/* Se da el caso de que con un PenDrive (al menos el que yo he usado) las
funciones IsDisk() y lIsDir() dan .F..
Cuando se trata de una tarjeta de memoria (por ejemplo XD) insertada en
un lector de tarjetas externo conectado a un puerto USB, la IsDisk() sigue
dando .F. y la lIsDir() da .T..
Como lo que se pretende es poder saber que unidades USB son susceptibles de
usarse independientemente de PenDrive o tarjetas de memoria, se opta por
la función GetDiskFreeSpace() que da .T. tanto para PenDrive como para
tarjetas de memoria.
22/08/2010
*/
Local lExist := .F.
Local nSetErrorMode := 0
//Traza( 1, "cDisk=", cDisk )
//Traza( 1, "1-SETERRORMODE=", SETERRORMODE() )
nSetErrorMode := SETERRORMODE( 1 )
//Traza( 1, "1-nSetErrorMode=", nSetErrorMode )
//lExist := IsDisk( Left( cDisk, 1) + ":" )
//Traza( 1, "1-lExist=", lExist )
//lExist := lIsDir( Left( cDisk, 1) + ":\" )
//Traza( 1, "2-lExist=", lExist )
lExist := GetDiskFreeSpace( Left( cDisk, 1) + ":\" )
//Traza( 1, "3-lExist=", lExist )
nSetErrorMode := SETERRORMODE( nSetErrorMode )
//Traza( 1, "2-nSetErrorMode=", nSetErrorMode )
//Traza( 1, "2-SETERRORMODE=", SETERRORMODE() )
Return lExist
/* *************************** */#pragma BEGINDUMP
#include "hbapi.h"
#include "windows.h"
HB_FUNC( SETERRORMODE )
{
hb_retni( SetErrorMode( hb_parni( 1 ) ) ) ;
}
HB_FUNC( GETDISKFREESPACE ) // cRootPathName, @nSectorsByCluster, @nBytesPerSector,
// @nNumberOfFreeClusters, @nTotalNumberOfClusters --> lResult
{
LPSTR lpRootPathName = hb_parc( 1 );
DWORD SectorsPerCluster;
DWORD BytesPerSector;
DWORD NumberOfFreeClusters;
DWORD TotalNumberOfClusters;
hb_retl( GetDiskFreeSpace( lpRootPathName, &SectorsPerCluster,
&BytesPerSector, &NumberOfFreeClusters,
&TotalNumberOfClusters ) );
hb_stornl( SectorsPerCluster, 2 );
hb_stornl( BytesPerSector, 3 );
hb_stornl( NumberOfFreeClusters, 4 );
hb_stornl( TotalNumberOfClusters, 5 );
}
#pragma ENDDUMP