Archive: Duplication in NSIS archives


Duplication in NSIS archives
I've been looking inside my NSIS installer executable with 7-Zip.

In our project there are is one program that can be called using either of two names -- it inspects argv[0] to find out how it was called and behaves accordingly. This is done to save space in the archive, as the program contains a lot of library code that would be duplicated if the functionality was provided by two separate programs.

This is similar in concept to the old unix trick of having a single program that provides two functions, and calling it through a symlink to access the second function -- in unix that means the whole program is only stored once even after it has been installed.

In the NSIS installer for our programs we have something like:

  File prog1.exe
File /oname=prog2.exe prog1.exe

I expected that this would lead to prog1.exe being stored in the archive, and being unpacked twice during the install, once as prog1.exe and once as prog2.exe. It appears, though, that it doesn't work like that and that both prog1.exe and prog2.exe are stored in the archive (so the archive contains duplicate copies of the same file, and so is bigger).

Am I understanding this correctly?

Is there a good reason for NSIS to work this way, or is it just that nobody has ever needed to install two identical files in this way before.

I now think that the best thing to do would be to copy prog1.exe to prog2.exe after installing it (but still within the NSIS script). Is there a better way? It feels wrong to have to do that.

No. The data for that file isn't in the installer twice, because NSIS uses datablock optimizations.

You can use "SetDatablockOptimize off" in your script to disable the datablock optimizations and see how big the installer would be without it.


Originally posted by {_trueparuex^}
No. The data for that file isn't in the installer twice, because NSIS uses datablock optimizations.
OK, thanks for that. Is this an optimization specific to NSIS? to 7-Zip? I'd like to learn more about it.