Suggestions for the Packer library

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mowen
User
User
Posts: 48
Joined: Tue Oct 07, 2003 1:04 pm
Location: Belgium

Suggestions for the Packer library

Post by Mowen »

These both new functions would be usefull:

- CountPackFile(packfile.s) : return the number of elements of the pack file
- GetPackFile(packfile.s, index.l, target.s) : extract the x element and save it to the specified file

Something like this: :wink:

Code: Select all

Procedure.l CountPackFile(file.s)
  Protected cpt.l = 0

  If OpenPack(file)
    While NextPackFile()
      cpt + 1
    Wend
    ClosePack()
  EndIf
  ProcedureReturn cpt
EndProcedure

Procedure.l GetPackFile(src_file.s, index.l, trg_file.s)
  Protected i.l, *mem.l, fic.l, size.l

  size = 0
  If (index > 0) And (index <= CountPackFile(src_file))
    If OpenPack(src_file)
      For i = 1 To index
        *mem = NextPackFile()
      Next i
      size = PackFileSize()
      fic = CreateFile(#PB_Any, trg_file)
      If fic
        WriteData(fic, *mem, size)
        CloseFile(fic)
      EndIf
      ClosePack()
    EndIf  
  EndIf
  ProcedureReturn size
EndProcedure
and also an AppendPackFile function to add files at the end of the packer file that already exists.
PureBasic: one of the best programming tools ever ! PB is light, easy, crossplatform, powerfull, fast, extendable, enjoyable and... tasty ;-)