Conversion UnLZX (LZX decompress ) in C to PB Nativ

Windows specific forum
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Conversion UnLZX (LZX decompress ) in C to PB Nativ

Post by infratec »

You know that you have

Code: Select all

ForEach List()
...
Next
This is much easier than RestList() ... NextElement()
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Conversion UnLZX (LZX decompress ) in C to PB Nativ

Post by infratec »

To extract this file:

https://files.scene.org/get/demos/group ... s-vrtg.lzx

I needed to do:

Code: Select all

Procedure .i  open_output(Filename$, ArchiveName$)
				
		Protected szDestination.s, subdir_count.i, i.i
		
		ReplaceString(Filename$, "?", "_", #PB_String_InPlace)
		ReplaceString(Filename$, "|", "_", #PB_String_InPlace)
		
		szDestination.s = GetPathPart(ArchiveName$) + GetFilePart(ArchiveName$, #PB_FileSystem_NoExtension) + "/"
		CreateDirectory(szDestination)
		
		If FindString(Filename$, "/")
			subdir_count = CountString(Filename$, "/")
			For i = 1 To subdir_count
				szDestination + StringField(Filename$, i, "/") + "/"
				CreateDirectory(szDestination)
			Next i
		EndIf
		
    ProcedureReturn CreateFile(#PB_Any, szDestination + GetFilePart(Filename$))
		
	EndProcedure
else some files were not extracted.
Marty2PB
User
User
Posts: 47
Joined: Thu Mar 13, 2014 4:31 pm

Re: Conversion UnLZX (LZX decompress ) in C to PB Nativ

Post by Marty2PB »

infratec wrote: Mon Feb 13, 2023 8:27 pm You know that you have

Code: Select all

ForEach List()
...
Next
This is much easier than RestList() ... NextElement()
Yes, that's right. I didn't have that on my radar at all. I did the routine this morning before I went to bed. But it's not even final yet. :wink:
infratec wrote: Mon Feb 13, 2023 9:28 pm To extract this file:

https://files.scene.org/get/demos/group ... s-vrtg.lzx

I needed to do:

Code: Select all

Procedure .i  open_output(Filename$, ArchiveName$)
				
		Protected szDestination.s, subdir_count.i, i.i
		
		ReplaceString(Filename$, "?", "_", #PB_String_InPlace)
		ReplaceString(Filename$, "|", "_", #PB_String_InPlace)
		
		szDestination.s = GetPathPart(ArchiveName$) + GetFilePart(ArchiveName$, #PB_FileSystem_NoExtension) + "/"
		CreateDirectory(szDestination)
		
		If FindString(Filename$, "/")
			subdir_count = CountString(Filename$, "/")
			For i = 1 To subdir_count
				szDestination + StringField(Filename$, i, "/") + "/"
				CreateDirectory(szDestination)
			Next i
		EndIf
		
    ProcedureReturn CreateFile(#PB_Any, szDestination + GetFilePart(Filename$))
		
	EndProcedure
else some files were not extracted.
Yes. I already thought so. The Amiga file system allows characters that do not work under Windows.
I had an archive with 2 disk images in it, but they were all "0" in size. CRC is equal to 0 for sum and crc. I initially treated it as an error.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Conversion UnLZX (LZX decompress ) in C to PB Nativ

Post by infratec »

There should be return values:

Code: Select all

Procedure .i  Process_DataContent(*UnLZX.LZX_ARCHIVE )
		
		With *UnLZX
			ResetList(\FileData() )
			ResetList(\ListData() )
			
			While NextElement( \FileData() )
				
				If ( Len( \FileData()\File) > 0 ) 
					AddElement( \ListData() )
					\ListData()\PathFile = \FileData()\File
					\ListData()\Position = ListIndex( \FileData() )
				EndIf	      			      		
			Wend
			
			ResetList(\FileData() )
			ResetList(\ListData() )      	
		EndWith
		
		ProcedureReturn ListSize(*UnLZX\ListData())
		
	EndProcedure

Code: Select all

Procedure .i  Examine_Archive( *UnLZX.LZX_ARCHIVE )    	    	  
	  
	  Protected.i Result
	  
		If ( *UnLZX > 0 )     		
			Result = Process_DataContent(*UnLZX )
			
			Debug_View_Archiv(*UnLZX)
		EndIf
		
		ProcedureReturn Result
		
	EndProcedure
Marty2PB
User
User
Posts: 47
Joined: Thu Mar 13, 2014 4:31 pm

Re: Conversion UnLZX (LZX decompress ) in C to PB Nativ

Post by Marty2PB »

This works now good :)



- Extract to given target directory
- Extract All or
- Extract single files by Name or Position Number
- External Content List usable outside of pbUnLZX

v-0.6
Adding: Verify Archive UnLZX::Verify_Archive(*LzxMemory)
Resault are BAD Crc's Only

Extracting WHDload LZX Archive (543 Files Merged packed)

Image
Image

Extracting Single File
Image

https://github.com/MartyShepard/LHvSyst ... hiveLZX.pb

greetings
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Conversion UnLZX (LZX decompress ) in C to PB Nativ

Post by Fred »

Good work !! Just tried with https://www.purebasic.com/download/PureBasic.lzx and it worked as expected.
Post Reply