XAD: Get total files size from an archive LHA.

Discuss about plugins that don't have a dedicated forum
Post Reply
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

XAD: Get total files size from an archive LHA.

Post by papiosaur »

Hello,

i would like to get the total files size from an archive LHA with XAD. It's possible?

Thanks for your help.
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: XAD: Get total files size from an archive LHA.

Post by papiosaur »

ok, i must open the archive and get size of files like it was normal files...

[EDIT] Argggg. it's more difficult i thank...

I must get names files of the archive and get size of each file and do the result at the end of scan?
User avatar
jPV
Posts: 644
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: XAD: Get total files size from an archive LHA.

Post by jPV »

Couple quick tests... the latter seems to be faster. But I'm in really hurry so maybe I didn't think all options :)

Code: Select all

@REQUIRE "xad", {InstallAdapter = True}

Function p_GetUnpackedSizeXad(file$)
	Local size = 0
	If Exists(file$)
		Local xid = xad.OpenArchive(Nil, file$)
		Local xarc = xad.GetObjectType()
		Local xnum = GetAttribute(xarc, xid, #XADATTRNUMENTRIES)
		For Local i = 0 To xnum -1
			Local t = xad.GetFileAttributes(xid, i)
			size = size + t.size
		Next
		xad.CloseArchive(xid)
	EndIf
	Return(size)
EndFunction

StartTimer(1)
DebugPrint("Size:", p_GetUnpackedSizeXad("RAM:test.lha"))
DebugPrint("Time:", GetTimer(1))

Function p_GetUnpackedSizeDir(file$, size)
	Local err, id = ?OpenDirectory(Nil, file$)
	If Not err
		Local e = NextDirectoryEntry(id)
		While e <> Nil
	        	If e.Type = #DOSTYPE_DIRECTORY
				size = p_GetUnpackedSizeDir(FullPath(file$, e.name), size)
	        	Else
				size = size + e.size
	        	EndIf
	    		e = NextDirectoryEntry(id)
		Wend
		CloseDirectory(id)
	EndIf
	Return(size)
EndFunction

StartTimer(1)
DebugPrint("Size:", p_GetUnpackedSizeDir("RAM:test.lha"))
DebugPrint("Time:", GetTimer(1))
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: XAD: Get total files size from an archive LHA.

Post by papiosaur »

Thanks a lot jPV! i will test them :-)
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: XAD: Get total files size from an archive LHA.

Post by papiosaur »

@jPV: i have tested but unfortunally it use many CPU for big archive...

i will found another solution using "lha l" command and get the value of total size with 'STRING' commands.

i get the value with commands from the MorphOS SDK like this syntax:

Code: Select all

lha l ram:archive.lha | tail -4 | head -n 1 | xargs echo | head -n 1" >ram:value.txt
Post Reply