Lister les lecteurs

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
Progi1984
Messages : 2659
Inscription : mar. 14/déc./2004 13:56
Localisation : France > Rennes
Contact :

Lister les lecteurs

Message par Progi1984 »

Et voilà, toujours dans mes codes multi plateformes, voici un code qui permet de lister les différents lecteurs d'un poste.

Code : Tout sélectionner

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Linux ;{
    Structure mntent
      mnt_fsname.s
      mnt_dir.s
      mnt_type.s
      mnt_opts.s
      mnt_freq.l
      mnt_passno.l
    EndStructure
  ;}
CompilerEndSelect
Structure S_Drives
  drive.s{255}
  options.s{255}
  
  unix_fsname.s{255}
  unix_type.s{255}
  unix_freq.l
  unix_passno.l
  
  windows_type.l
EndStructure
Structure S_ListDrives
  nb.l
  ptrMem.l
EndStructure
ProcedureDLL System_GetDrives()
  Protected Dim MyDrives.S_Drives(0)
  Protected *ListDrives.S_ListDrives = AllocateMemory(SizeOf(S_ListDrives))
  Protected lSize.l

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Windows ;{
      Protected sDrives.s = Space(255)
      Protected lRes.l = GetLogicalDriveStrings_(255, sDrives)
      Protected lOffset.l
      Repeat
        MyDrives(lSize)\drive = PeekS(@sDrives+lOffset,4)
        MyDrives(lSize)\windows_type = GetDriveType_(@MyDrives(lSize)\drive)
        lOffset + 4
        lSize +1
        ReDim MyDrives.S_Drives(lSize)
      Until PeekS(@sDrives+lOffset,4)="" 
    ;}
    CompilerCase #PB_OS_Linux ;{
      ; http://man.developpez.com/man3/getmntent.3.php
      Protected hMtab.l, hPointer.l
      Protected *info.mntent
    
      hMtab = setmntent_("/etc/mtab", "r")
      If hMtab
        hPointer = getmntent_(hMtab)
        While hPointer
          *info = hPointer
          
          MyDrives(lSize)\drive = *info\mnt_dir
          MyDrives(lSize)\options = *info\mnt_opts
          MyDrives(lSize)\unix_fsname = *info\mnt_fsname
          MyDrives(lSize)\unix_type = *info\mnt_type
          MyDrives(lSize)\unix_freq = *info\mnt_freq
          MyDrives(lSize)\unix_passno = *info\mnt_passno
          
          lSize +1
          ReDim MyDrives.S_Drives(lSize)
          hPointer = getmntent_(hMtab)
        Wend
        endmntent_(hMtab)
      Else
        ProcedureReturn #False
      EndIf 
    ;}
  CompilerEndSelect

  *ListDrives\nb = lSize
  *ListDrives\ptrMem = AllocateMemory(lSize * SizeOf(S_Drives))
  MoveMemory(@MyDrives(), *ListDrives\ptrMem, lSize * SizeOf(S_Drives))
  ProcedureReturn *ListDrives
EndProcedure

lMem = System_GetDrives()

Define.S_ListDrives DrivesListing
MoveMemory(lMem, @DrivesListing, SizeOf(S_ListDrives))
Dim Drives.S_Drives(DrivesListing\nb)

MoveMemory(DrivesListing\ptrMem, @Drives(), DrivesListing\nb * SizeOf(S_Drives))

For Inc = 0 To DrivesListing\nb -1
  Debug "Drive >" + Drives(Inc)\drive
  Debug "Options > " + Drives(Inc)\options
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_Linux ;{
      Debug Drives(Inc)\unix_fsname
    ;}
    CompilerCase #PB_OS_Windows ;{
      Debug "Type > "+Str(Drives(Inc)\windows_type)
    ;}
  CompilerEndSelect
  
Next
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Message par Ar-S »

merci pour ce partage :D
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Répondre