Extrafunktionen für ZipPacker (Crossplattform)

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Extrafunktionen für ZipPacker (Crossplattform)

Beitrag von ts-soft »

Hier ein paar Extra-Funktionen für die ZipPacker-Lib, die mit PB5.10 kommt

Alle Betriebssystem sollten jetzt unterstützt sein, mal abgesehen vom Amiga :wink:
- Windows: Komplett getested
- Linux: Keine Unicode-Unterstützung
- MacOS: Ungetested, mangels Möglichkeit :wink:

Functions:
- ZIP_AddDir(zip, dir.s) ; add a empty directory to archiv
- ZIP_CountEntries(zip, flags = 0) ; returns the number of files in the zip archive, or -1 if archive is NULL
- ZIP_GetIndex(zip, FileName.s, flags = 0) ; Found index by Name
- ZIP_GetArchComment(zip, flags = 0) ; reads the archiv comment
- ZIP_GetFileComment(zip, index, flags = 0) ; reads the file comment
- ZIP_SetArchComment(zip, comment.s) ; add a comment to archiv
- ZIP_SetFileComment(zip, index, comment.s) ; add a comment to file
- ZIP_SetDefaultPassword(zip, password.s) ; works only for unpacking!

Includefile mit Beispiel:

Code: Alles auswählen

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
  CompilerIf #PB_Compiler_Unicode
    Debug "Please disable " + #DQUOTE$ + "Unicode" + #DQUOTE$ +
            "! Unicode is not supported!"
    End
  CompilerEndIf
CompilerEndIf

UseZipPacker()

#ZIP_FL_NOCASE = 1
#ZIP_FL_NODIR =	2
#ZIP_FL_UNCHANGED = 8

ImportC ""
  zip_add_dir(hZip.i, dir.p-Ascii)
  zip_get_num_entries(hZip.i, flags.l = 0)
  zip_get_archive_comment(hZip.i, *lenp, flags.l = 0)
  zip_set_archive_comment(hZip.i, comment.p-Ascii, length.l)
  zip_get_file_comment(hZip.i, index.q, *lenp, flags.l = 0)
  zip_set_file_comment(hZip.i, index.q, comment.p-Ascii, length.l)
  zip_name_locate(hZip.i, fname.p-Ascii, flags.l = 0)
  zip_set_default_password(hZip.i, password.p-Ascii)
EndImport

Procedure ZIP_AddDir(*zip.Integer, dir.s) ; add a empty directory to archiv
  ProcedureReturn zip_add_dir(*zip\i, dir)
EndProcedure

Procedure ZIP_CountEntries(*zip.Integer, flags = 0) ; returns the number of files in the zip archive, or -1 if archive is NULL
  ; Supported Flags:
  ;   #ZIP_FL_UNCHANGED = use original data, ignoring changes
  ProcedureReturn zip_get_num_entries(*zip\i, flags)
EndProcedure

Procedure.l ZIP_GetIndex(*zip.Integer, FileName.s, flags = 0) ; Found index by Name
  ; Directories are denoted by a trailing slash
  ; Supported Flags:
  ;   #ZIP_FL_NOCASE = case insensitive search
  ;   #ZIP_FL_NODIR  = ignore the path
  
  ;   Result = -1 is an error!
  ProcedureReturn zip_name_locate(*zip\i, FileName, flags)
EndProcedure

Procedure.s  ZIP_GetArchComment(*zip.Integer, flags = 0) ; reads the archiv comment
  ; Supported Flags:
  ;   #ZIP_FL_UNCHANGED = use original data, ignoring changes
  Protected length.l, result.i
  result = zip_get_archive_comment(*zip\i, @length, flags)
  If result And length > 0
    ProcedureReturn PeekS(result, length, #PB_Ascii)
  EndIf
EndProcedure

Procedure.s  ZIP_GetFileComment(*zip.Integer, index, flags = 0) ; reads the file comment
  ; Supported Flags:
  ;   #ZIP_FL_UNCHANGED = use original data, ignoring changes
  Protected length.l, result.i
  result = zip_get_file_comment(*zip\i, index, @length, flags)
  If result And length > 0
    ProcedureReturn PeekS(result, length, #PB_Ascii)
  EndIf
EndProcedure

Procedure ZIP_SetArchComment(*zip.Integer, comment.s) ; add a comment to archiv
  If zip_set_archive_comment(*zip\i, comment, Len(comment)) = 0
    ProcedureReturn #True
  EndIf
EndProcedure

Procedure ZIP_SetFileComment(*zip.Integer, index, comment.s) ; add a comment to file
  If zip_set_file_comment(*zip\i, index, comment, Len(comment)) = 0
    ProcedureReturn #True
  EndIf
EndProcedure

Procedure ZIP_SetDefaultPassword(*zip.Integer, password.s) ; works only for unpacking!
  If zip_set_default_password(*zip\i, password) = 0
    ProcedureReturn #True
  EndIf
EndProcedure

CompilerIf Not #PB_Compiler_IsIncludeFile
  ; Example
  Define zip
  zip = CreatePack(0, GetTemporaryDirectory() + "myzip.zip")
  AddPackFile(0, #PB_Compiler_Home + "sdk/compilerinterface.txt", "CompilerInterface.txt")
  ZIP_SetFileComment(zip, ZIP_GetIndex(zip, "compilerinterface.txt", #ZIP_FL_NOCASE), "File from SDK")
  ZIP_AddDir(zip, "test/")
  ZIP_SetFileComment(zip, ZIP_GetIndex(zip, "test/"), "My empty dir")
  ZIP_SetArchComment(zip, "Feel the ..Pure.. Power")
  ClosePack(0)
  
  zip = OpenPack(0, GetTemporaryDirectory() + "myzip.zip")
  
  Define i
  If ExaminePack(0)
    While NextPackEntry(0)
      Debug PackEntryName(0)
      Select PackEntryType(0)
        Case #PB_Packer_File
          Debug "Is a File"
        Case #PB_Packer_Directory
          Debug "Is a Directory"
      EndSelect
      Debug ZIP_GetFileComment(zip, i)
      Debug "---------------"
      i + 1
    Wend
  EndIf
  MessageRequester("Archiv Comment", ZIP_GetArchComment(zip))
  ClosePack(0)
CompilerEndIf
Zuletzt geändert von ts-soft am 14.01.2013 15:17, insgesamt 2-mal geändert.
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
RSBasic
Admin
Beiträge: 8047
Registriert: 05.10.2006 18:55
Wohnort: Gernsbach
Kontaktdaten:

Re: Extrafunktionen für ZipPacker

Beitrag von RSBasic »

Danke fürs Teilen. :allright:
Aus privaten Gründen habe ich leider nicht mehr so viel Zeit wie früher. Bitte habt Verständnis dafür.
Bild
Bild
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Extrafunktionen für ZipPacker (Crossplattform)

Beitrag von ts-soft »

Update:

Include ist jetzt Crossplattform.

+ ZIP_CountEntries()
+ ZIP_SetDefaultPassword()
Das Password funktioniert nur beim Entpacken, eines mit einem anderem Tools gepackten Zip-Archives.

Gruß
Thomas
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Extrafunktionen für ZipPacker (Crossplattform)

Beitrag von ts-soft »

Mit PB5.10 Beta 4 funktioniert der Code leider nicht mehr.

Ich hoffe mal, noch einen Weg zu finden, um an das hWnd der Zip zu kommen, kann aber
nichts versprechen :cry:
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Extrafunktionen für ZipPacker (Crossplattform)

Beitrag von ts-soft »

Hab jetzt erstmal einen Weg gefunden (danke an edel), die Include unter Windows
lauffähig zu bekommen. Den Code im erstem Thread werde ich erst updaten, wenn
zumindest auch Linux wieder funktioniert. Hier also der WinOnly Code:

Code: Alles auswählen

EnableExplicit

UseZipPacker()

#ZIP_FL_NOCASE = 1
#ZIP_FL_NODIR =	2
#ZIP_FL_UNCHANGED = 8

Import ""
  PB_Object_IsObject(object, id)
  PB_Packer_Objects
EndImport

ImportC ""
  zip_add_dir(hZip.i, dir.p-ascii)
  zip_get_num_entries(hZip.i, flags.l = 0)
  zip_get_archive_comment(hZip.i, *lenp, flags.l = 0)
  zip_set_archive_comment(hZip.i, comment.p-Ascii, length.l)
  zip_get_file_comment(hZip.i, index.q, *lenp, flags.l = 0)
  zip_set_file_comment(hZip.i, index.q, comment.p-Ascii, length.l)
  zip_name_locate(hZip.i, fname.p-Ascii, flags.l = 0)
  zip_set_default_password(hZip.i, password.p-Ascii)
EndImport

Procedure ZIP_PackerID(id)
 Protected obj, hZip
 obj = PB_Object_IsObject(PB_Packer_Objects, id) 
 If obj
  hZip = PeekI(obj + 4 * SizeOf(integer))
 EndIf
 
 ProcedureReturn hZip 
EndProcedure

Procedure ZIP_AddDir(ID, dir.s) ; add a empty directory to archiv
  Protected hZip = ZIP_PackerID(ID)
  ProcedureReturn zip_add_dir(hZip, dir)
EndProcedure

Procedure ZIP_CountEntries(ID, flags = 0) ; returns the number of files in the zip archive, or -1 if archive is NULL
  Protected hZip = ZIP_PackerID(ID)
  ; Supported Flags:
  ;   #ZIP_FL_UNCHANGED = use original data, ignoring changes
  ProcedureReturn zip_get_num_entries(hZip, flags)
EndProcedure

Procedure.l ZIP_GetIndex(ID, FileName.s, flags = 0) ; Found index by Name
  Protected hZip = ZIP_PackerID(ID)
  ; Directories are denoted by a trailing slash
  ; Supported Flags:
  ;   #ZIP_FL_NOCASE = case insensitive search
  ;   #ZIP_FL_NODIR  = ignore the path
  
  ;   Result = -1 is an error!
  ProcedureReturn zip_name_locate(hZip, FileName, flags)
EndProcedure

Procedure.s  ZIP_GetArchComment(ID, flags = 0) ; reads the archiv comment
  Protected hZip = ZIP_PackerID(ID)
  ; Supported Flags:
  ;   #ZIP_FL_UNCHANGED = use original data, ignoring changes
  Protected length.l, result.i
  result = zip_get_archive_comment(hZip, @length, flags)
  If result And length > 0
    ProcedureReturn PeekS(result, length, #PB_Ascii)
  EndIf
EndProcedure

Procedure.s  ZIP_GetFileComment(ID, index, flags = 0) ; reads the file comment
  Protected hZip = ZIP_PackerID(ID)
  ; Supported Flags:
  ;   #ZIP_FL_UNCHANGED = use original data, ignoring changes
  Protected length.l, result.i
  result = zip_get_file_comment(hZip, index, @length, flags)
  If result And length > 0
    ProcedureReturn PeekS(result, length, #PB_Ascii)
  EndIf
EndProcedure

Procedure ZIP_SetArchComment(ID, comment.s) ; add a comment to archiv
  Protected hZip = ZIP_PackerID(ID)
  If zip_set_archive_comment(hZip, comment, Len(comment)) = 0
    ProcedureReturn #True
  EndIf
EndProcedure

Procedure ZIP_SetFileComment(ID, index, comment.s) ; add a comment to file
  Protected hZip = ZIP_PackerID(ID)
  If zip_set_file_comment(hZip, index, comment, Len(comment)) = 0
    ProcedureReturn #True
  EndIf
EndProcedure

Procedure ZIP_SetDefaultPassword(ID, password.s) ; works only for unpacking!
  Protected hZip = ZIP_PackerID(ID)
  If zip_set_default_password(hZip, password) = 0
    ProcedureReturn #True
  EndIf
EndProcedure

CompilerIf Not #PB_Compiler_IsIncludeFile
  ; Example
  CreatePack(0, GetTemporaryDirectory() + "myzip.zip")
  AddPackFile(0, #PB_Compiler_Home + "sdk/compilerinterface.txt", "CompilerInterface.txt")
  ZIP_SetFileComment(0, ZIP_GetIndex(0, "compilerinterface.txt", #ZIP_FL_NOCASE), "File from SDK")
  ZIP_AddDir(0, "test/")
  ZIP_SetFileComment(0, ZIP_GetIndex(0, "test/"), "My empty dir")
  ZIP_SetArchComment(0, "Feel the ..Pure.. Power")
  ClosePack(0)
  
  Define zip = OpenPack(#PB_Any, GetTemporaryDirectory() + "myzip.zip")
  
  Define i
  If ExaminePack(zip)
    While NextPackEntry(zip)
      Debug PackEntryName(zip)
      Select PackEntryType(zip)
        Case #PB_Packer_File
          Debug "Is a File"
        Case #PB_Packer_Directory
          Debug "Is a Directory"
      EndSelect
      Debug ZIP_GetFileComment(zip, i)
      Debug "---------------"
      i + 1
    Wend
    Debug ZIP_CountEntries(zip)
  EndIf
  MessageRequester("Archiv Comment", ZIP_GetArchComment(zip))
  ClosePack(zip)
CompilerEndIf
Gruß
Thomas
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Antworten