Procedure GetDeviceList()

AmigaOS specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.

Hi,

here a procedure called GetDeviceList(). The procedure is based on the procedure
CheckDevice(), just a little extension.
With this procedure you can create a list of the devices, directories and volumes
which are available in the system. For that the procedure creates a Shared list
called MyDev(), so that you can access it from the main program.

Parameter: kind.l what we are searching for
0 = devices
1 = directories (means assigns)
2 = volumes
3 or higher = a complete list (devices + directories + volumes)

Return : number of found entries

The list MyDev() contains two variables:
MyDev()\typedev = long, 0 = the following string is a device
1 = the following string is a directory
2 = the following string is a volume
MyDev()\namedev = string, the name of the device/directory/volume
Before leaving the procedure it sets the List to the first one.

The procedure is nearly the same like CheckDevice(), so have a look there if
you are need some further infos. For using the procedure just see the example.


Procedure.b GetDeviceList(kind.l)
Structure MyList
typedev.l
namedev.s
EndStructure
NewList MyDev.MyList()
Shared MyDev
info.l=PeekL(PeekL(DosBase()+34)+24)*4
devinfo.l=PeekL(info+4)*4
texte.l=PeekL(devinfo+40)*4
type.l=PeekL(devinfo+4)
While devinfo0
If kind>=3
AddElement(MyDev())
MyDev()\typedev=type
MyDev()\namedev=PeekS(texte+1)
Else
IF type=kind
AddElement(MyDev())
MyDev()\typedev=type
MyDev()\namedev=PeekS(texte+1)
EndIf
EndIf
If PeekL(devinfo)
devinfo=PeekL(devinfo)*4
texte=PeekL(devinfo+40)*4
type=PeekL(devinfo+4)
Else
devinfo=0
EndIf
Wend
FirstElement(MyDev())
ProcedureReturn CountList(MyDev())
EndProcedure



PrintN("First we search for Devices:")
zahl.l=GetDeviceList(0)
Print("We have found "):PrintNumber(zahl):PrintN(" Devices. Here the list:")
For i.b=1 To zahl
PrintNumber(MyDev()\typedev):Print(" means Device. The name is "):PrintN(" "+MyDev()\namedev)
NextElement(MyDev())
Next
PrintN("press mousebutton"):PrintN("")
MouseWait()

PrintN("Now we search for Directories:")
zahl.l=GetDeviceList(1)
Print("We have found "):PrintNumber(zahl):PrintN(" Directories. Here the list:")
For i=1 To zahl
PrintNumber(MyDev()\typedev):Print(" means Directory. The name is "):PrintN(" "+MyDev()\namedev)
NextElement(MyDev())
Next
PrintN("press mousebutton"):PrintN("")
MouseWait()

PrintN("Next we search for Volumes:")
zahl.l=GetDeviceList(2)
Print("We have found "):PrintNumber(zahl):PrintN(" Volumes. Here the list:")
For i=1 To zahl
PrintNumber(MyDev()\typedev):Print(" means Volume. The name is "):PrintN(" "+MyDev()\namedev)
NextElement(MyDev())
Next
PrintN("press mousebutton"):PrintN("")
MouseWait()

PrintN("Now we get the hole list:")
zahl.l=GetDeviceList(3)
Print("We have found "):PrintNumber(zahl):PrintN(" entries. Here the list:")
For i=1 To zahl
PrintNumber(MyDev()\typedev):PrintN(" "+MyDev()\namedev)
NextElement(MyDev())
Next
End


Greetings ..
Roxxler