Page 1 of 1
XAD: Get total files size from an archive LHA.
Posted: Wed Sep 18, 2024 12:20 pm
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.
Re: XAD: Get total files size from an archive LHA.
Posted: Wed Sep 18, 2024 1:36 pm
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?
Re: XAD: Get total files size from an archive LHA.
Posted: Wed Sep 18, 2024 9:08 pm
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))
Re: XAD: Get total files size from an archive LHA.
Posted: Thu Sep 19, 2024 8:37 am
by papiosaur
Thanks a lot jPV! i will test them

Re: XAD: Get total files size from an archive LHA.
Posted: Thu Sep 19, 2024 6:31 pm
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