inno-setup

Installing hidden files using Inno Setup


I need to install a set of hidden files spanning multiple folders, on an end users machine, using a setup created using Inno Setup. I have referred Copying hidden files in Inno Setup, but it seems that the DirectoryCopy function specified there copies files from and to the same machine.

I need the hidden files to be extracted from the setup.exe file and then installed on an end user machine, which will be different from the machine on which the setup has been created.


Solution

  • When [Files] section Source parameter is a wildcard, hidden files are ignored. See BuildFileList in Compile.pas.

    A simple solution is to remove the hidden attribute from source files.


    If you cannot remove the hidden attribute (e.g. if you need to preserve it in installation), you can generate the [Files] section entries using preprocessor, avoiding use a wildcard.

    #pragma parseroption -p-
    
    ; If the file is found by calling FindFirst without faHidden, it's not hidden
    #define FileParams(FileName) \
        Local[0] = FindFirst(FileName, 0), \
        (!Local[0] ? "; Attribs: hidden" : "")
    
    #define FileEntry(Source, DestDir) \
        "Source: \"" + Source + "\"; DestDir: \"" + DestDir + "\"" + \
        FileParams(Source) + "\n"
    
    #define ProcessFile(Source, DestDir, FindResult, FindHandle) \
        FindResult \
            ? \
                Local[0] = FindGetFileName(FindHandle), \
                Local[1] = Source + "\\" + Local[0], \
                (Local[0] != "." && Local[0] != ".." \
                    ? (DirExists(Local[1]) \
                          ? ProcessFolder(Local[1], DestDir + "\\" + Local[0]) \
                          : FileEntry(Local[1], DestDir)) \
                    : "") + \
                ProcessFile(Source, DestDir, FindNext(FindHandle), FindHandle) \
            : \
                ""
    
    #define ProcessFolder(Source, DestDir) \
        Local[0] = FindFirst(Source + "\\*", faAnyFile), \
        ProcessFile(Source, DestDir, Local[0], Local[0])
    
    #pragma parseroption -p+
    

    Use the ProcessFolder macro like:

    [Files]
    
    #emit ProcessFolder("C:\source", "{app}")
    

    It will generate a script like:

    [Files]
    Source: "C:\source\file.txt"; DestDir: "{app}"
    Source: "C:\source\subfolder\file.jpg"; DestDir: "{app}\subfolder"
    Source: "C:\source\subfolder\hidden.txt"; DestDir: "{app}\subfolder"; Attribs: hidden
    

    (See How do I see the output (translation) of the Inno Setup Preprocessor?)


    Ntb, the question, you are referring to, is about copying external files, so it's not relevant for your problem.