zBin Packer SDK - Crossplattform

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

zBin Packer SDK - Crossplattform

Post by ts-soft »

zBin Packer SDK - Crossplattform

Features supported:
  • MacOS, Linux and Windows
    ASCII and Unicode
    32-Bit and 64-Bit
    restores Filedate
    restores Fileattributes (only on same os)
    Paths in Archiv
    Encrypt Fileinfoheader with AES 256-Bit
    Catch to memory
    Find Pack included in File (IncludeBinary, Append or in a windows-resource Section)
Full-Crossplattform-Source included!

Interface Packroutines:

Code: Select all

Interface zBinPackObject
  AddPackFile.i(File.s, level = 9, PathInArchiv.s = "")
  ; Add a file to pack.
  ;   Parameters:
  ;     File.s = File name with path.
  ;     level (optional) = Pack level (between 0 and 9)
  ;     PathInArchiv.s (optional) = Relative path in archive. When extracting this path will be restored.  

  AddPackDir.i(Dir.s, level = 9, contentonly.i = #False)
  ; Add a folder to pack.
  ;   Parameters:
  ;     Dir.s = Absolute Path to folder which should be added in pack.
  ;     level (optional) = Pack level (between 0 and 9)
  ;     contentonly.i = If #TRUE then only content of specified folder will be added.
  ;                     Otherwise packs also the folder. (PathInArchiv.s is considered to be packed!)

  GetError.i()
  ; Returns Errorcode for some Methode
  
  ClosePack.i()
  ; zBin file will be closed and the object will be destroyed.
EndInterface
Interface Unpackroutines:

Code: Select all

Interface zBinUnPackObject
  CountFiles.i()
  ; Returns the number of files that resides in a pack.
  
  GetFileNumber.i(Name.s)
  ; Returns the pack number with specified name. Warning: It finds only the first file matching the name!
  
  GetFileName.s(Number)
  ; Returns the file name of pack number.
  
  GetFilePath.s(Number)
  ; Returns the path of pack number.
  
  GetUnpackedSize.i(Number)
  ; Returns the file size of pack number.
  
  CatchFile.i(Number)
  ; Unpacks the pack of number and returns memory address.
  ; FreeMemory() frees the memory.
    
  ExtractFile.i(Number, Path.s = "")
  ; Restores specified pack file in directory path.
  ; Subdirectories are also restored.
    
  ExtractArchiv.i(Path.s = "")
  ; Restores complete pack with subdirectories in directory path.

  GetError.i()
  ; Returns Errorcode for some Methode
      
  ClosePack.i()
  ; Closes the zBin file and destroys the object.
EndInterface
Source for simple PackerGUI (Crossplattform) included.
Preview:
Image

Download: http://www.realsource.de/downloads/doc_ ... packer-sdk

Feedback welcome
Last edited by ts-soft on Fri Aug 03, 2012 9:58 pm, edited 1 time in total.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: zBin Packer SDK - Crossplattform

Post by skywalk »

Very nice ts-soft 8)
I would change default compression level to 6 instead of 9.
I find very little return in compressed sizes for the extra time of '9'.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

skywalk wrote:Very nice ts-soft 8)
I would change default compression level to 6 instead of 9.
I find very little return in compressed sizes for the extra time of '9'.
you are welcome

i think, in most situations, only the unpack time is relevant and unpacking doesn't require extra time,
but this is a source paket, you can change anything to your own needs :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: zBin Packer SDK - Crossplattform

Post by KJ67 »

I have a small tool to insert packed datasection and I normally just want 'best' compression size so it searches for this before the insert.
The interesting thing is that it often seems to end up somewhere in the PackLevel= [6...7] zone. Too high level actually often increase both size and un-pack time.

Example for compression testing:

Code: Select all

; Test size and time to pack a file.
; Used DroopyLib

Declare main(void)

Define thread
thread=CreateThread(@main(), 0)
ThreadPriority(thread, 31)
WaitThread(thread)

Procedure main(void)
  Protected TestFile$, SaveFile$
  Protected Size1, Size2, i, HS_Timer.f
  Protected *p1, *p2, s1, s2, e

  TestFile$ = OpenFileRequester("Select file to test","","All|*.*",0)
  If TestFile$="": End: EndIf
  SaveFile$ = SaveFileRequester("Save resule as", GetSpecialFolder(#CSIDL_DESKTOP)+"PackerTest.txt","All|*.*",0)
  If SaveFile$="": End: EndIf

  s1  = FileSize(TestFile$)
  *p1 = AllocateMemory(s1)
  *p2 = AllocateMemory(s1+8)
  If OpenFile(0, TestFile$)
    ReadData(0, *p1, s1)
    CloseFile(0)
    OpenWindow(0,#PB_Ignore,#PB_Ignore,180,18,"Compession test")
    TextGadget(0,0,0,180,18,"")
    If CreateFile(0, SaveFile$)
      WriteStringN(0, "Testing file "+TestFile$)
      For i=0 To 9
        SetGadgetText(0,"Compression mode = "+Str(i))
        Repeat
          e=WindowEvent()
          If e=#PB_Event_CloseWindow
            End
          EndIf
        Until e=#False
        ;{
        MeasureHiResIntervalStart()
        s2 = PackMemory(*p1, *p2, s1, i)
        HS_Timer=MeasureHiResIntervalStop()
        ;}
        WriteString(0, "Pack, Level="+Str(i)+", Ratio="+StrF(100.0*s2/s1,3)+"%, Time="+StrF(HS_Timer*1000,1)+"msec. ")
        Repeat
          e=WindowEvent()
          If e=#PB_Event_CloseWindow
            End
          EndIf
        Until e=#False
        MeasureHiResIntervalStart()
        If UnpackMemory(*p2, *p1)
          HS_Timer=MeasureHiResIntervalStop()
          WriteStringN(0, "UnPack Time="+StrF(HS_Timer*1000,3)+"msec.")
        Else
          WriteStringN(0, "UnPack level="+Str(i)+" failed!")
        EndIf
      Next
      CloseFile(0)
      RunProgram(SaveFile$)
    EndIf
  EndIf
EndProcedure
The best preparation for tomorrow is doing your best today.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

@skywalk

for the next update, i have added #zBin_DefaultLevel contant to zBin_Common.pbi.
this make a change to your preferred Level easier.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
idle
Always Here
Always Here
Posts: 5839
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: zBin Packer SDK - Crossplattform

Post by idle »

thanks it'll be very handy for the community.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

Update:
History wrote:; V 1.1 12/06/04
; added #zBin_DefaultLevel constant to zBin_Common.pbi
; Changed Defaultcompresslevel to 6
; added zBin_UnpackGUI
; some bugfixes
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

Update:
History wrote:; V 1.2 12/07/06
; added method GetPackedSize()
; added method GetDate()
; enhanced zBin_UnpackerGUI
; added Callback for AddPackDir() and ExtractArchiv()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

Update:
History wrote:; V 1.3 12/07/10
; added Unpack-DLL (Source) and includefile
; added Unpack-DLL binary for Linux x86 and Windows x86, x64.
; Linux x64 doesn't compile see bugreport here: http://www.purebasic.fr/english/viewtop ... 91#p382691
; small bugfixes
Anyone tested on MacOS? I can't compile for MacOS!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

Update:
History wrote:; V 1.4 12/06/11
; added include files for zBinUnpack.dll supporting: AutoIt3, PureBasic, XProfan
; added Progressbar for zBinPackGUI
; some small bugfixes
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

Update:
History wrote:; V 1.5 12/06/13
; added optional Callback for zBinUnpack()
; fixed bug with numbering in zBinPackGUI and zBinUnpackGUI
; resizing support for zBinPackGUI and zBinUnpackGUI
; show progress in titlebar for for zBinPackGUI and zBinUnpackGUI
; cancel-support for packing in zBinPackGUI (windows only)
; added Progressbar for zBinUnpackGUI
; cancel-support for unpacking in zBinUnpackGUI
History wrote:; V 1.6 12/06/14
; added cancel support for zBinPackGUI on all OS
; fixed bug with path in archive, if you drop more as one dir to zBin_PackerGUI
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

Update:
History wrote:; V 1.6.2 12/06/23
; added Taskbarprogress (Win7) to Packer- and UnpackerGUI
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Poshu
Enthusiast
Enthusiast
Posts: 459
Joined: Tue Jan 25, 2005 7:01 pm
Location: Canada

Re: zBin Packer SDK - Crossplattform

Post by Poshu »

Nice resource here, still looking for some osX test?

I've got a question though: will you add the possibility of working on an existing pack? I mean add/remove files from a previously created pack.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: zBin Packer SDK - Crossplattform

Post by ts-soft »

You can add to existing pack, if it is standalone, but not with the GUI!
Removing is not possible.

Thx
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: zBin Packer SDK - Crossplattform

Post by skywalk »

Hi ts-soft,
Can you check if this is correct?
AESEncoder(*Input, *Output, Size, *Key, Bits, *InitializationVector [, Mode]) wrote:*InitializationVector The InitializationVector is a random data block, used to initialize the ciphering to avoid breach in decoding (only needed when using the #PB_Cipher_CBC mode). Its size depends of the 'Bits' parameter: l6 bytes for 128-bit encryption, 24 bytes for 196-bit and 32 bytes for 256-bit.

Code: Select all

DataSection
  zBin_GUID:
  Data.s "C7DD8C85-4828-45FC-848A-F0D4C2372618"
  zBin_SALT:
  Data.s "_#~57@wtIO*?abc|<<>>[}{]abcdefgh"
  zBin_InitializationVector:
  Data.b $2F, $36, $74, $5C, $E2, $7C, $54, $30, $54, $A1, $9B, $9C, $1E, $E3, $C6, $5B  ;<-- Should be 32 bytes for AES256?
  Data.b $2F, $36, $74, $5C, $E2, $7C, $54, $30, $54, $A1, $9B, $9C, $1E, $E3, $C6, $5B  ;<-- Add another row?
EndDataSection
And PB5 updated to zlib v125, so safe to use internal compressBound() and crc32().

Code: Select all

destLen = compressBound(sourceLen)  ; destLen = sourceLen + 13 + (Int(sourceLen / 100))

FileHeader\crc = crc32(#Null, *mem, size)    ; CRC32Fingerprint(*mem, size)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply