Inno Setup AfterInstall function called for each f

2020-07-09 09:53发布

问题:

I want to call a function after installing a folder, but the InstallEnv function is seems to be called several times, maybe for each file is the folder (to be confirmed). Is there a way to call it only once after it installed all of those files? I can't use the Run section because I want to do error catching with the return code.

Source: "InputFiles\virtualenv-1.8.2\*"; DestDir: "{tmp}/virtualenv"; \
    Flags: recursesubdirs; AfterInstall: InstallEnv; 

回答1:

Yes, it executes once per each file. The reference says about it (emphasized by me):

A BeforeInstall or AfterInstall function for a [Files] section entry using a wildcard is called once per file matching the wildcard. Use CurrentFileName to check for which file the function is called.

And no, there is no way to call it once after all the files are installed. If you were going to run it only once, it wouldn't be a problem, since you might declare a flag variable, indicating that the function was already called, but you want to detect if it's the last call, and for this there is no workaround.

Well, maybe if you would know, which file will be the latest installed from that folder, you might check that against the result of the CurrentFileName function call, but I doubt that you can determine which one will be installed as last at compilation time (since at runtime, there is currently no way to get list of files to be installed).



回答2:

There is no way to call it at the end of the installation of that group of files, from within a single entry. However it is possible to call the function at the appropriate time by making use of a dummy entry:

[Files]
Source: "InputFiles\virtualenv-1.8.2\*"; DestDir: "{tmp}\virtualenv"; Flags: recursesubdirs
Source: dummy.txt; DestDir: {tmp}; AfterInstall: InstallEnv

The Source file must exist but it can be a zero-byte file. As installation is into {tmp} it will be deleted after install anyway so its contents are irrelevant.

This works because [Files] entries are installed in the order specified.