Archive: only accept install directory if empty?


only accept install directory if empty?
I'm working on creating an installation package for a program in a community I'm in, first time working with NSIS in awhile. I came across the issue that I have a lot of files and so thus I'm using recursive method for File to install the files, but this creates the problem that I can't single out just the installation files during uninstallation. I've looked at a couple of solutions like Advanced Uninstall Log and it might work, but it does have the problem of some performance problems especially if there's a lot of files in the selected installation directory. I was trying to think of something that would be easy to implement primarily to avoid things like if the user decided to install directly to Programs Files or something as the documentation suggests that if a user did so and your script just used RMDir /r to remove it, it could wipe out all their files. So my idea outside of the logging scripts would be to simply check if a directory was empty before installation, and I'd prefer this method anyway, and prevent installation otherwise. I'm just getting into reviewing if something like this was possible but it doesn't appear to be easily done, anyone have any good examples or solutions for doing this? Any tips for how I can manage to safely handle the uninstallation process in my situation?

BTW, current steps I'm at are trying to find a way to verify if a directory is empty, and finding a way to prevent the installer from advancing passed the directory page (using MUI2) if it's not. I also wonder why NSIS just doesn't have some more stringent safety checks or way of monitoring this built in, it would be extremely useful..


Thank you...


Many ways to do this. A short selection:
1. There shouldn't be much of a performance penalty for using advanced log headers. Just use them.
2. Create a leave function for the DIRECTORY page and do ${IfExists} "$INSTDIR\*.*" abort ${EndIf}
3. Create an (NSIS) exe that lists all filenames in the build directories, then adds 'File ' in front of it etc, at the same time creating the same list with the Delete command. Use !system or !execute to launch that exe during build process. Then !include that exe's output, once in Section, once in unSection.
4. Probably could do the same with a batch file that calls the compiler after building its include lists.


I ended up using ${DirState} which is included in FileFunc.nsh - doing a simply Leave function to check if it's "Full" or not, if so it Aborts.