[Solved] PB 6.12 b1 An error occurred when using UncompressPackMemory or UncompressPackFile to decompress a zip archive

Just starting out? Need help? Post your questions and find answers here.
gltianya
User
User
Posts: 23
Joined: Wed Jul 07, 2021 12:02 pm

[Solved] PB 6.12 b1 An error occurred when using UncompressPackMemory or UncompressPackFile to decompress a zip archive

Post by gltianya »

This is caused by my coding error, not a bug. Please move it to the appropriate region or delete this post. Thank you.
2024-09-14
An error occurred when using UncompressPackMemory or UncompressPackFile to decompress a zip archive containing Chinese characters.
Today, I tested the Packer related functions of version 6.12 B1, mainly to decompress the most common zip archives.
The test samples are: abc123.zip and 测试123.zip
;------
The problems encountered are as follows:

abc123.zip is successfully decompressed, 测试123.zip fails to decompress, the error statement is:

Result = UncompressPackMemory(0, *UnpackID, filelen, fullfilename$)

result is equal to -1.

Code: Select all

;2024-09-14
;Result = UncompressPackMemory(0, *UnpackID, filelen, fullfilename$)
Result = UncompressPackMemory(0, *UnpackID, filelen) 
 
The test code is as follows:

Code: Select all

  UseZipPacker()

  Define file$ = "D:\20240731\测试123.zip" 
  Define filename$ =GetFilePart(file$, #PB_FileSystem_NoExtension)
  Define fullfilename$ = "" , filetext$ = ""
  Define filelen.i = 0 , Result.i = 0
  Define *UnpackID
  ; Open the packed file
  If OpenPack(0, file$, #PB_PackerPlugin_Zip) 
    
    ; List all the entries
    If ExaminePack(0)
      While NextPackEntry(0)
        Debug "Name: " + PackEntryName(0) + ", Size: " + PackEntrySize(0)
        fullfilename$ = PackEntryName(0)
        filelen = PackEntrySize(0)
        
        If filename$ = GetFilePart(fullfilename$, #PB_FileSystem_NoExtension)
          Debug "PathPart: " + GetPathPart(fullfilename$) 
          Debug "FilePart: " + GetFilePart(fullfilename$, #PB_FileSystem_NoExtension)
          Debug "ExtensionPart: " + GetExtensionPart(fullfilename$)
          Debug "filelen: " + filelen
          Debug "---------------"
          *UnpackID = AllocateMemory(filelen)
          Debug "*UnpackID : " + Str(*UnpackID)
          If *UnpackID
            Result = UncompressPackMemory(0, *UnpackID, filelen, fullfilename$)
            ;Result = UncompressPackFile(0, "D:\20240731\" + GetFilePart(fullfilename$), fullfilename$)
            Debug "result: " + result
            If result > 0
              filetext$ = PeekS(*UnpackID, filelen, #PB_Unicode)
              Debug "filetext$ = " + filetext$
              ;CreateFile(0, "D:\20240731\" + GetFilePart(fullfilename$), #PB_Unicode)
              ;WriteString(0, filetext$, #PB_Unicode)
              ;CloseFile(0)
            EndIf
            
          EndIf  
        EndIf
      Wend
    EndIf
    
    ClosePack(0)
  Else
    Debug "open file: " + file$ + " error! "
  EndIf
Last edited by gltianya on Fri Sep 13, 2024 6:36 pm, edited 8 times in total.
gltianya
User
User
Posts: 23
Joined: Wed Jul 07, 2021 12:02 pm

Re: 【PB 6.12 b1】An error occurred when using UncompressPackMemory or UncompressPackFile to decompress a zip archive

Post by gltianya »

This is caused by my coding error, not a bug. Please move it to the appropriate region or delete this post. Thank you.
Last edited by gltianya on Fri Sep 13, 2024 6:31 pm, edited 1 time in total.
gltianya
User
User
Posts: 23
Joined: Wed Jul 07, 2021 12:02 pm

Re: 【PB 6.12 b1】An error occurred when using UncompressPackMemory or UncompressPackFile to decompress a zip archive

Post by gltianya »

This is caused by my coding error, not a bug. Please move it to the appropriate region or delete this post. Thank you.
Last edited by gltianya on Fri Sep 13, 2024 6:32 pm, edited 1 time in total.
gltianya
User
User
Posts: 23
Joined: Wed Jul 07, 2021 12:02 pm

Re: PB 6.12 b1 An error occurred when using UncompressPackMemory or UncompressPackFile to decompress a zip archive

Post by gltianya »

After repeated tests and careful reading of the help file, because the Windows system code page of my computer is not the default English (ASCII) encoding, but the default encoding (unicode) of pb. The Chinese file encoding in the compressed package created by 7zip or winrar uses the system code page by default, so the corresponding matching item cannot be found by specifying the file name in the compression. Using nextpackentry(), the corresponding file item can be located through the pointer, regardless of the encoding method of the file item and the text displayed by the file in the system.

Code: Select all

;Result = UncompressPackMemory(0, *UnpackID, filelen, fullfilename$)
Result = UncompressPackMemory(0, *UnpackID, filelen)
 
Post Reply