Skip to content
⌘ NSIS Forum Archive

Get zip archive unziped size without extracting

3 posts

eugene25#

Get zip archive unziped size without extracting

It's techincally possibe to calc ZIP arch size without extracting it any idea how to do it with NSIS?
aerDNA#
You can use this library: http://www.csdinc.co.jp/archiver/lib/7-zip32.html
To save you the trouble of finding your way around a Japanese site, this is the dl link and this is the link to (pretty awful) English documentation.
The functions of interest in your case are SevenZipGetOriginalSize / SevenZipGetArcOriginalSize. They both return uncompressed size for an individual file; the first returns actual file size and the latter returns cumulative size. There's no function that would simply return the size of the whole archive, at least none that I could find.
An example, using SevenZipGetArcOriginalSize; it finds the last file in the archive and queries its cumulative size (which equals total size):

!define ArcName "test.zip"
InitPluginsDir
File /oname=$PLUGINSDIR\7-zip32.dll 7-zip32.dll
File /oname=$PLUGINSDIR\${ArcName} ${ArcName}
System::Call "$PLUGINSDIR\7-zip32::SevenZipGetFileCount(t '$PLUGINSDIR\${ArcName}') i.R0"
IntCmp $R0 0 0 +2 +3
MessageBox MB_OK|MB_ICONINFORMATION "Empty archive." IDOK ArcSizeEnd
MessageBox MB_OK|MB_ICONSTOP "Can't open archive" IDOK ArcSizeEnd
System::Call "$PLUGINSDIR\7-zip32::SevenZipOpenArchive(i 0, t '$PLUGINSDIR\${ArcName}', i 0) i.R1"
StrCmp $R1 0 0 +2
MessageBox MB_OK|MB_ICONSTOP "Can't open archive" IDOK ArcSizeEnd
System::Call "$PLUGINSDIR\7-zip32::SevenZipFindFirst(i R1, t '', i 0) i."
FileLoop:
IntOp $R0 $R0 - 1
StrCmp $R0 0 +3
System::Call "$PLUGINSDIR\7-zip32::SevenZipFindNext(i R1, i 0) i."
Goto FileLoop
System::Call "$PLUGINSDIR\7-zip32::SevenZipGetArcOriginalSize(i R1) i.R2"
System::Call "$PLUGINSDIR\7-zip32::SevenZipCloseArchive(i R1) i."
MessageBox MB_OK|MB_ICONINFORMATION "Uncompressed archive size: $R2 B"
ArcSizeEnd: