Generating Inno Setup file flags programmatically

后端 未结 1 1410
温柔的废话
温柔的废话 2020-12-11 12:06

Is it possible in Inno Setup to generate the file flags programmatically? My installer source contains a large number of files within a sizeable directory structure. Curre

相关标签:
1条回答
  • 2020-12-11 12:32

    Your solution is not bad. We might help you with finding a solution that does not require "change in several places each time", if you give us details.


    Anyway, it's possible to generate the [Files] section using preprocessor. This way you can alter the Flags per file type. But the code is complex too. And due to limits of the preprocessor, it won't work with really large directory structures (I've managed to make it working with up to 3500 files).

    #pragma parseroption -p-
    
    #define FileFlags(FileName) \
        Local[0] = Lowercase(ExtractFileExt(FileName)), \
        (Local[0] == "jpg" || Local[0] == "dds" ? "nocompression" : "")
    
    #define FileEntry(Source, DestDir) \
        "Source: \"" + Source + "\"; DestDir: \"" + DestDir + "\"; " + \
        "Flags: " + FileFlags(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+
    

    Modify the FileFlags macro as you need. And use the ProcessFolder macro like:

    [Files]
    
    #emit ProcessFolder(MySrc, MyDst)
    

    It will generate a code like:

    Source: "C:\source\file.txt"; DestDir: "{app}"; Flags: 
    Source: "C:\source\subfolder\file.jpg"; DestDir: "{app}\subfolder"; Flags: nocompression
    Source: "C:\source\subfolder\another.txt"; DestDir: "{app}\subfolder"; Flags: 
    

    (with MySrc = C:\source and MyDst = {app})

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


    Inspired by the answer by @Zlatko Karakaš to Use Inno Setup PreProcessor to get the files and size of the source path and its subdirs.

    0 讨论(0)
提交回复
热议问题