【问题标题】:Choose between source paths for all files在所有文件的源路径之间进行选择
【发布时间】:2017-08-30 20:28:54
【问题描述】:

当我在 Visual Studio 中编译我的项目时,我会自动运行一个混淆器。 混淆的 .dll 文件以相同的文件名保存在子文件夹中。

文件夹结构

FileA_Secure (subfolder)
    FileA.dll
FileA.dll

问题:如果“安全”FileA.dll 存在,我能否确保 Inno Setup 从子文件夹 FileA_Secure 编译 FileA.dll 而不是主文件夹中的 FileA.dll?

【问题讨论】:

  • 我的意思是编译成安装程序,为了更清楚,我修改了我的问题。谢谢

标签: inno-setup


【解决方案1】:

您可以使用Inno Setup preprocessor 有条件地选择来源。特别是,使用#ifexist directive:

[Files]
#ifexist "MyClass_Secure\MyClass.dll"
Source: "MyClass_Secure\MyClass.dll"; DestDir: "{app}"
#else
Source: "MyClass.dll"; DestDir: "{app}"
#endif

将SaveToFile 添加到.iss 的末尾,看看最终的脚本是什么样的:

#expr SaveToFile(AddBackslash(SourcePath) + "Preprocessed.iss")

如果您需要对很多文件执行此操作,您可以定义一个宏:

#define GetDllSource(Name) \
    FileExists(Name + "_Secure\" + Name + ".dll") ? \
        Name + "_Secure\" + Name + ".dll" : Name + ".dll"

[Files]
Source: {#GetDllSource("MyClass")}; DestDir: "{app}"
Source: {#GetDllSource("MyClass2")}; DestDir: "{app}"

如果您想对文件夹及其子文件夹中的所有文件执行此操作,则会变得更加复杂:

#pragma parseroption -p-

; For given DLL, return path to secured DLL, if exists, otherwise return the DLL itself
#define GetDllSource(FileName) \
    Local[0] = ExtractFileName(FileName), \
    Local[1] = Pos(".", Local[0]), \
    Local[2] = Local[1] > 0 ? Copy(Local[0], 1, Local[1] - 1) : Local[0], \
    Local[3] = ExtractFilePath(FileName), \
    Local[4] = Local[3] + "\\" + Local[2] + "_Secure\\" + Local[0], \
    FileExists(Local[4]) ? Local[4] : FileName

; For DLLs, returns [Files] section entry, skip other files
#define FileEntry(Source) \
    (ExtractFileExt(Source) != "dll") ? \
        "" : "Source: " + GetDllSource(Source) + "; DestDir: {app}\n"

; If the directory entry is folder, call ProcessFolder.
; If it is a file, call FileEntry
#define ProcessFile(Source, FindResult, FindHandle) \
    FindResult \
        ? \
            Local[0] = FindGetFileName(FindHandle), \
            Local[1] = Source + "\\" + Local[0], \
            (Local[0] != "." && Local[0] != ".." \
                ? (DirExists(Local[1]) ? ProcessFolder(Local[1]) : FileEntry(Local[1])) \
                : "") + \
            ProcessFile(Source, FindNext(FindHandle), FindHandle) \
        : \
            ""

; If the folder is not _Secure, process its files and subfolders
#define ProcessFolder(Source) \
    (Pos("_Secure", ExtractFileName(Source)) > 0) ? \
        "" : \
        (Local[0] = FindFirst(Source + "\\*", faAnyFile), \
        ProcessFile(Source, Local[0], Local[0]))

#pragma parseroption -p+

[Files]
; Process this folder for DLLs and subfolders (can be changed for a real path)
#emit ProcessFolder(".")

【讨论】:

  • 谢谢,但如果我不想一一列出所有文件并进行此检查,它仍然是可能的。像源 * 。 * 但是对于每个文件 X 检查 X_Secure\X 是否存在,如果存在则选择该文件。
  • 也许您应该向我们展示您的脚本以明确您的实际操作
  • 我明天可以发布它,但我现在基本上只是这样做(并且在编译和删除受保护的子文件夹之前必须手动替换所有具有混淆版本的文件)。我希望将这部分自动化。来源:"*。 *";目标目录:“{app}”标志:递归子目录
  • recursesubdirs 会找到混淆和未混淆的版本,不是吗?子文件夹中真的有 dll 吗?
  • 我明天试试你的宏。如果可以用 * 调用。 * 那么这就是答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-03
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
相关资源
最近更新 更多