Unzip/unrar on Big Sur

Mac OSX specific forum
CoopsOz
User
User
Posts: 11
Joined: Mon Jul 12, 2021 9:39 am

Unzip/unrar on Big Sur

Post by CoopsOz »

I want to uncompress files, but UncompressPackFile doesn't work on Big Sur. The same code is fine on Windows, so I've posted this as a bug http://forums.purebasic.com/english/vie ... e9#p572561.
Does anyone have a way of unzipping files on Big Sur?

Here's the code that works on Windows but not on Big Sur.

Code: Select all

zipfilelocation$  = OpenFileRequester("Choose a Zip", "", "", 0)

If zipfilelocation$ =""
  Text$ + "No File Chosen"
  MessageRequester("Information", Text$)
Else
  
  UseZipPacker()
  
  destfolder$ = GetCurrentDirectory()+ "test_unzip/"
  
  CreateDirectory(destfolder$ )
  Debug zipfilelocation$
  Debug destfolder$
  
  OpenPack(0, zipfilelocation$)
  
  ExaminePack(0) 
  
  While NextPackEntry(0)
    Result = UncompressPackFile(0, destfolder$ + PackEntryName(0)  )
    n=n+1
    Test$=StrF(n) +" Name " +PackEntryName(0) + " Size "+ PackEntrySize(0) + " Type "+ PackEntryType(0) +" D&F "+destfolder$ + filename$ 
    Debug Test$
  Wend
  
  ClosePack(0)
EndIf
Mac Mini M1, 2020
Mac Mini i7 2018
Acer Nitro i5, RTX 3050
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Unzip/unrar on Big Sur

Post by collectordave »

Tried this on bigger as well and did not work.

Each pack entry name was repeaters W

Changed one line to

If OpenPack(0, zipfilelocation$,#PB_PackerPlugin_Zip )

and the pack entry names are reported correctly.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Unzip/unrar on Big Sur

Post by collectordave »

Tried a little more and it seems you need the folder created ready for any file to be uncompressed.

Sorry about the scrappy code but this works for me on BigSur:

Code: Select all

zipfilelocation$  = OpenFileRequester("Choose a Zip", "", "", 0)

If zipfilelocation$ =""
  Text$ + "No File Chosen"
  MessageRequester("Information", Text$)
Else
  
  UseZipPacker()
  
  destfolder$ = GetUserDirectory(#PB_Directory_Documents) + "test_unzip/"
  
  CreateDirectory(destfolder$ )
  ;Debug zipfilelocation$
  ;Debug destfolder$
  
  OpenPack(0, zipfilelocation$,#PB_PackerPlugin_Zip )
  
  ExaminePack(0) 
  
  While NextPackEntry(0)
    
     Debug PackEntryName(0)
    Debug GetPathPart(PackEntryName(0))
    
    
      CreateDirectory(destfolder$ + GetPathPart(PackEntryName(0)) )   
    
    
    
    Result = UncompressPackFile(0, destfolder$ + PackEntryName(0)) ;,PackEntryName(0) )
    Debug ""
    Debug Result

    
    Debug destfolder$ + PackEntryName(0)
    
    
    n=n+1
    Test$=StrF(n) +" Name " +PackEntryName(0) + " Size "+ PackEntrySize(0) + " Type "+ PackEntryType(0) +" D&F "+destfolder$ + filename$ 
    Debug Test$
  Wend
  
  ClosePack(0)
EndIf
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
CoopsOz
User
User
Posts: 11
Joined: Mon Jul 12, 2021 9:39 am

Re: Unzip/unrar on Big Sur

Post by CoopsOz »

Cheers,

That works for me too. Oddly, if I change

Code: Select all

destfolder$ = GetUserDirectory(#PB_Directory_Documents) + "test_unzip/"
to my working directory - it fails. I assume some permissions issue. I didn't want iCloud backing up many scraps* of files, so my PureBasic directory is top level. If I change the one line below it fails.

Code: Select all

destfolder$ = GetUserDirectory(#PB_Directory_Documents) + "test_unzip/"
I'm finding that I don't need to have the directory created; I even commented out the 2nd CreateDirectory (within the loop) and that works OK, too.

Thanks

* We all write scrappy code, no apologies required.
Mac Mini M1, 2020
Mac Mini i7 2018
Acer Nitro i5, RTX 3050
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Unzip/unrar on Big Sur

Post by collectordave »

If you are trying to use:

Code: Select all

 destfolder$ = GetCurrentDirectory()+ "test_unzip/"
That can fail as the current directory can be inside the application always best to use absolute addressing.

It is also not the same as the executable directory there are a few posts on the forum that explain that very well.

You mention iCloud the way I do it is to have a folder in documents for each app to hold the zip files I then have a small xcopy application that copies these to iCloud or anywhere else I tell it to but copies only the newer files.

Good luck with it all.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Post Reply