以编程方式生成Inno Setup文件标志 [英] Generating Inno Setup file flags programmatically

查看:70
本文介绍了以编程方式生成Inno Setup文件标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Inno Setup中是否可以以编程方式生成文件标志?我的安装程序源在相当大的目录结构中包含大量文件.目前,通过一次添加整个文件夹,我已将脚本的复杂性降至最低.效果很好,但是,在整个层次结构中散布了许多文件,这些文件没有从压缩中受益(例如* .jpg),并且极大地增加了安装程序的构建时间.理想情况下,我想执行以下操作:

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. Currently I've minimized the complexity of the script by adding entire folders at a time. This works fine, however, there are numerous files sprinkled throughout the hierarchy that aren't benefiting from compression (e.g. *.jpg) and are significantly increasing the installer build time. Ideally, I'd like to do something like:

Source: "{#MySrc}\*"; DestDir: "{#MyDst}"; Flags: {code:GetFlags};

GetFlags将检查当前文件的扩展名,并为我不想压缩的文件类型返回"nocompression".那可能吗?我似乎无法在文档或在线中找到任何表明它的信息.如果没有,还有其他直接方法可以实现这一目标吗?

Where GetFlags would check the extension of the current file and return "nocompression" for file types that I don't want to compress. Is that possible? I can't seem to find anything in the docs or online that would indicate that it is. If not, is there any other straight forward way to achieve this?

我想到的唯一的另一种方法是为每种类型创建一个额外的文件行,像这样

The only other way I can think of to do this is to create an additional file line for each type, like this

Source: "{#MySrc}\*"; DestDir: "{#MyDst}"; Excludes: "*.jpg,*.dds"; Flags: "ignoreversion recursesubdirs";
Source: "{#MySrc}\*.jpg"; DestDir: "{#MyDst}"; Flags: "ignoreversion recursesubdirs nocompression";
Source: "{#MySrc}\*.dds"; DestDir: "{#MyDst}"; Flags: "ignoreversion recursesubdirs nocompression";

虽然这是可行的,但每次遇到我决定不压缩的文件类型时,我都需要在几个地方进行此更改.因此,如果可能的话,我宁愿将逻辑放在一个地方.

While this is doable, I'd need to make this change in several places each time I came across a file type that I decided not to compress. So I'd rather keep the logic in a single place, if possible.

推荐答案

您的解决方案还不错.如果您向我们提供详细信息,我们可能会帮助您找到不需要每次更改多个位置"的解决方案.

无论如何,可以使用预处理器生成[Files]部分.这样,您可以更改每种文件类型的Flags.但是代码也很复杂.而且由于预处理器的限制,它不能用于非常大的目录结构(我设法使其可以处理多达3500个文件).

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+

根据需要修改FileFlags宏.并使用ProcessFolder宏,例如:

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

[Files]

#emit ProcessFolder(MySrc, MyDst)

它将生成如下代码:

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: 

(带有MySrc = C:\sourceMyDst = {app})

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

请参见 Inno设置:如何查看Inno设置预处理器的输出(翻译)?

由@ZlatkoKarakaš答复为 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆