This include should work crossplattform:
- windows full tested
- linux works only in ascii-mode
- macos not tested!
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 with example:
Code: Select all
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