• Welcome, Guest. Please login.
 
August 22, 2019, 09:53:37 pm

News:

Welcome to the SQLitening support forums!


ZLib Wrapper Routines

Started by Rolf Brandt, February 23, 2011, 11:08:56 am

Previous topic - Next topic

cj

I went back to that link by Fred at http://www.sqlitening.com/support/index.php?topic=3254.0 and got not found, too.
Glad you downloaded the one I posted, but not sure it was the same thing.

Fredrick Ughimi

Hello CJ,

Here is what I have done so far.


#COMPILE EXE
#DIM ALL
#DEBUG ERROR ON
#INCLUDE "Win32API.inc"

' ==========>>> Equates
   %prZipFileFileLength = 30
   %prZipFileDirLength = 46
   %prZipFileEndDirLength = 22
   %ZLibZip_NO_COMPRESSION         = 0
   %ZLibZip_BEST_SPEED             = 1
   %ZLibZip_BEST_COMPRESSION       = 9
   %ZLibZip_DEFAULT_COMPRESSION    = (-1)
   %ZLibZip_DEFLATED               = 8
   %MaxPath = 260
   $WrdMrk = CHR$(&HF2)    'Word Mark(Words)       - &HF2
   $SegMrk = CHR$(&HFB)    'Segment Mark(Segments) - &HFB

   ' ==========>>> Types
TYPE DateTime_TYPE
  hSecond    AS DWORD
  hMinute      AS DWORD
  hHour      AS DWORD
  hDay      AS DWORD
  hMonth     AS DWORD
  hYear     AS DWORD
END TYPE
TYPE FileInfo_TYPE
  uDateTime    AS DateTime_TYPE
  hDosDate     AS DWORD
  hAttribute   AS DWORD
  hAttribute2  AS DWORD
END TYPE
TYPE FileInfoX_TYPE
  version               AS DWORD
  version_needed        AS DWORD
  flag                  AS DWORD
  compression_method    AS DWORD
  dosDate               AS DWORD
  crc                   AS DWORD
  compressed_size       AS DWORD
  uncompressed_size     AS DWORD
  size_filename         AS DWORD
  size_file_extra       AS DWORD
  size_file_comment     AS DWORD
  disk_num_start        AS DWORD
  internal_fa           AS DWORD
  external_fa           AS DWORD
  tmu_date              AS DateTime_TYPE
END TYPE

   ' ==========>>> Declares
DECLARE FUNCTION ZLibUnzOpen LIB "sqliteningzlib.dll" ALIAS "unzOpen" (rsFileName AS ASCIZ) AS DWORD
DECLARE FUNCTION ZLibUnzClose LIB "sqliteningzlib.dll" ALIAS "unzClose" (BYVAL rhFileHand AS DWORD) AS DWORD
DECLARE FUNCTION ZLibUnzGoToFirstFile LIB "sqliteningzlib.dll" ALIAS "unzGoToFirstFile"(BYVAL rhFileHand AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzGoToNextFile LIB "sqliteningzlib.dll" ALIAS "unzGoToNextFile"(BYVAL rhFileHand AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzGetCurrentFileInfo LIB "sqliteningzlib.dll" ALIAS "unzGetCurrentFileInfo"(BYVAL rhFileHand AS DWORD, BYREF pFile_Info AS FileInfoX_TYPE, BYREF szFileName AS ASCIIZ, _
                              BYVAL FileNameBufLen AS DWORD, BYREF pExtra AS ANY, BYVAL pExtraLen AS DWORD, BYREF szComment AS ASCIIZ, BYVAL szCommentLen AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzOpenCurrentFile LIB "sqliteningzlib.dll" ALIAS "unzOpenCurrentFile"(BYVAL fh AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzCloseCurrentFile LIB "sqliteningzlib.dll" ALIAS "unzCloseCurrentFile"(BYVAL fh AS DWORD) AS LONG
DECLARE FUNCTION ZLibUnzReadCurrentFile LIB "sqliteningzlib.dll" ALIAS "unzReadCurrentFile"(BYVAL fh AS LONG, BYREF buf AS ANY, BYVAL bufLen AS DWORD) AS LONG
DECLARE FUNCTION ZLibZipOpen LIB "sqliteningzlib.dll" ALIAS "zipOpen" (rsFileName AS ASCIZ, BYVAL rlAppend AS LONG) AS DWORD
DECLARE FUNCTION ZLibZipClose LIB "sqliteningzlib.dll" ALIAS "zipClose" (BYVAL rhFileHand AS DWORD, rsGlobalComment AS ASCIZ) AS LONG
DECLARE FUNCTION ZLibZipOpenNewFileInZip LIB "sqliteningzlib.dll" ALIAS "zipOpenNewFileInZip" (BYVAL rhFileHand AS DWORD, BYREF rsFileName AS ASCIZ, _
BYREF ruFileInfo AS FileInfo_TYPE, BYREF rsExtraLocal AS ANY, BYVAL rlExtraSize  AS LONG, BYREF rsExtraGlobal  AS _
ANY, _
                              BYVAL rlExtraSize AS LONG, BYREF rsComment AS ASCIZ, BYVAL rlMethod AS LONG, BYVAL rlLevel AS LONG)AS LONG
DECLARE FUNCTION ZLibZipWriteInFileInZip LIB "sqliteningzlib.dll" ALIAS "zipWriteInFileInZip"(BYVAL rhFileHand AS DWORD, BYREF rsBuffer AS ANY, BYVAL rlBufferSize AS LONG)AS LONG
DECLARE FUNCTION ZLibZipCloseFileInZip LIB "sqliteningzlib.dll" ALIAS "zipCloseFileInZip"(BYVAL rhFileHand AS DWORD)AS LONG
DECLARE FUNCTION FileTimeToSystemTimeMine LIB "KERNEL32.DLL" ALIAS "FileTimeToSystemTime" (lpFileTime AS QUAD, lpSystemTime AS SYSTEMTIME) AS LONG
DECLARE FUNCTION SystemTimeToFileTimeMine LIB "KERNEL32.DLL" ALIAS "SystemTimeToFileTime" (lpSystemTime AS SYSTEMTIME, lpFileTime AS QUAD) AS LONG

SUB axErrorAt (BYVAL rlLineNumber AS LONG)
   MSGBOX "Severe error at line number " & FORMAT$(rlLineNumber)
   ExitProcess 8
END SUB

SUB arZipFileGetFile(rsZipFileName AS STRING, BYVAL rlFileNumber AS LONG, wsFileData AS STRING)
'   Returns, in FileData, uncompressed data from FileNumber in ZipFileName.

   LOCAL lhUnZipFileHandle AS DWORD
   LOCAL luFI AS FileInfoX_TYPE
   LOCAL lzA AS ASCIZ * 1

   lhUnZipFileHandle = ZLibUnzOpen(BYCOPY rsZipFileName)
   DO
      DECR rlFileNumber
      IF rlFileNumber = 0 THEN

         ' This is the file they want
         ZLibUnzGetCurrentFileInfo lhUnZipFileHandle, luFI, lzA, 0, lzA, 0, lzA, 0
         ZLibUnzOpenCurrentFile lhUnZipFileHandle

         wsFileData = SPACE$(luFI.uncompressed_size)
         IF ZLibUnzReadCurrentFile(lhUnZipFileHandle, BYVAL STRPTR(wsFileData), LEN(wsFileData)) <> LEN(wsFileData) THEN axErrorAt 1236
         ZLibUnzCloseCurrentFile lhUnZipFileHandle
         EXIT DO

      END IF
   LOOP WHILE ZLibUnzGoToNextFile(lhUnZipFileHandle) = 0
   IF rlFileNumber THEN axErrorAt 1242

   ' Close it and were done
   ZLibUnzClose lhUnZipFileHandle

END SUB

FUNCTION PBMAIN () AS LONG

    LOCAL lsB AS STRING

    arZipFileGetFile "HopewellHospitalPro.zip", 1, lsB

    ? lsB
END FUNCTION


The output from the messagebox gives MZ. But I can't see the unzipped file.

Any ideas?

Best regards,

Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

Try putting only a text file into a zip file.
It looks like you are displaying an executable binary file using messagebox.

Fredrick Ughimi

CJ,

Quote
Try putting only a text file into a zip file.
It looks like you are displaying an executable binary file using messagebox.


Did that. It displays the content of the text zipped file.

I want to unzip the zipped executable binary file.

Not possible?
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

FUNCTION PBMAIN

LOCAL sData AS STRING, hFile AS LONG

FileToZip "myzip.zip","test.exe"    'put into myzip.zip,text.exe
sData$ = FileFromZip("myzip.zip",1) 'get first file in zip

END FUNCTION

FUNCTION FileToZip(sZipFile AS STRING, sFileIntoZip AS STRING) AS LONG
LOCAL sZipControlBlock AS STRING
LOCAL sGetBuffer       AS STRING
LOCAL sPutBuffer       AS STRING
LOCAL hFile AS LONG
hfile = FREEFILE
OPEN sFileIntoZip FOR BINARY AS hFile
IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
GET$ hfile,LOF(hFile),sPutBuffer
IF ERR THEN ? "get error":CLOSE #hfile:FUNCTION = ERR:EXIT FUNCTION
CLOSE #hFile
arZipFileInsertOpen sZipFile, sZipControlBlock
arZipFileInsertPut sZipControlBlock, sFileIntoZip, sPutBuffer
arZipFileInsertClose sZipControlBlock
END FUNCTION

FUNCTION FileFromZip(sZipFile AS STRING, FileNumber AS LONG) AS STRING
LOCAL sGetBuffer AS STRING
arZipFileGetFile sZipFile, 1, sGetBuffer
FUNCTION = sGetBuffer
END FUNCTION


cj

July 14, 2017, 06:20:23 am #20 Last Edit: July 14, 2017, 06:41:05 am by cj
Looks like the code for the library came from Jim Dunn at PowerBASIC site (not the code I created in the previous post using it.)
It looks like he posted the code after someone used Jose Roca code and had trouble updating/adding archives with multiple files.
https://forum.powerbasic.com/forum/user-to-user-discussions/third-party-addons/29121-litezip-liteunzip/page2?t=28376&page=2



Fredrick Ughimi

Thanks CJ.

Just got back from a short trip.

Would try out the links you provided later on.

Best regards,
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

CJ,

I tried the link you provided above.

Still can't unzip my exe file.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

Can't unzip an executable.  Is it a zip file?

Fredrick Ughimi

Yes. It's a zipped exe file.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet

cj

What is the call statement?
Is there an error message?
Check that the downloaded DLL is not blocked in properties or use SQLiteningZlib.DLL.
Archive file must be closed when you access it.

cj

July 21, 2017, 08:27:21 pm #28 Last Edit: July 22, 2017, 01:56:52 am by cj
I see you created another thread.

Same questions,  does your call statement look like this?
> Not seeing unzipped file
It returns a string


FUNCTION PBMAIN

LOCAL sData AS STRING, hFile AS LONG

FileToZip "myzip.zip","test.exe"    'put into myzip.zip,test.exe
sData$ = FileFromZip("myzip.zip",1) 'get first file in zip

END FUNCTION

FUNCTION FileToZip(sZipFile AS STRING, sFileIntoZip AS STRING) AS LONG
LOCAL sZipControlBlock AS STRING
LOCAL sGetBuffer       AS STRING
LOCAL sPutBuffer       AS STRING
LOCAL hFile AS LONG
hfile = FREEFILE
OPEN sFileIntoZip FOR BINARY AS hFile
IF ERR THEN FUNCTION = ERR:EXIT FUNCTION
GET$ hfile,LOF(hFile),sPutBuffer
IF ERR THEN ? "get error":CLOSE #hfile:FUNCTION = ERR:EXIT FUNCTION
CLOSE #hFile
arZipFileInsertOpen sZipFile, sZipControlBlock
arZipFileInsertPut sZipControlBlock, sFileIntoZip, sPutBuffer
arZipFileInsertClose sZipControlBlock
END FUNCTION

FUNCTION FileFromZip(sZipFile AS STRING, FileNumber AS LONG) AS STRING
LOCAL sGetBuffer AS STRING
arZipFileGetFile sZipFile, 1, sGetBuffer
FUNCTION = sGetBuffer
END FUNCTION


cj