Calculate Size of Unpacked 7z Archive
The other day I encountered the #12345 error for exceeding the 2Gb installer file size limit. Searching around the forums I found that the common solution to this problem is to store the data in an archive separate from the installer executable, and unpack it during the install.
I found this works well using the 7zip command line approach (which is detailed in other topics on the forum).
The problem with this solution however is that the "required space" display does not take into account the size of the data in the external archive.
As a solution, I've written a little python script to calculate the size of the archive, and replace a predefined string ("%data_size%") in the nsis script with this value:
os.system( "7z l -slt archive.7z > size_data.txt" )
file_ = open( "size_data.txt", "rt" )
data = file_.read()
file_.close()
os.remove( "size_data.txt" )
l = data.split("\nSize = ")
total = 0
for i in range( len(l) ):
if i > 0: # The first item is useless
total += int(l[i].split("\nPacked Size")[0])
total /= 1024 # Convert to Kilobytes
print total
versionedInstFile = open( "Versioned Installer.nsi", "rt" )
versionedInstStr = versionedInstFile.read()
versionedInstFile.close()
versionedInstStr = versionedInstStr.replace( "%data_size%", str(total) )
f = open( "Versioned Installer.nsi", "wt" )
f.write( versionedInstStr )
f.close()
Here's the relevant part of the nsis script:
Section "yay" SecYay
...
AddSize %data_size%
SectionEnd