在所有文件的源路径之间选择 [英] Choose between source paths for all files

查看:41
本文介绍了在所有文件的源路径之间选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中编译项目时,我会自动运行混淆器. 混淆的.dll文件使用相同的文件名保存,但保存在子文件夹中.

I automatically run an obfuscator when I compile my project in visual studio. The obfuscated .dll files are saved with the same filename but in subfolders.

文件夹结构

FileA_Secure (subfolder)
    FileA.dll
FileA.dll

问题:如果存在受保护的" FileA.dll,我是否可以确保Inno Setup从子文件夹FileA_Secure编译FileA.dll,而不从主文件夹中的FileA.dll编译?

Question: Can I make sure that Inno Setup compiles FileA.dll from the subfolder FileA_Secure and not the FileA.dll from the main folder if the "secured" FileA.dll exists?

推荐答案

您可以使用 Inno Setup预处理器有条件地选择一个来源.特别是,使用 #ifexist指令:

You can use Inno Setup preprocessor to conditionally select a source. Particularly, use the #ifexist directive:

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


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


Add SaveToFile to the end of your .iss, to see what is the final script like:

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


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


If you need to do this for many files, you can define a macro:

#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}"


如果要对文件夹及其子文件夹中的所有文件执行此操作,它将变得更加复杂:


If you want to do this for all files in a folder and its subfolders, it gets way more complicated:

#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(".")

这篇关于在所有文件的源路径之间选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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