代码之家  ›  专栏  ›  技术社区  ›  Johan

在所有文件的源路径之间选择

  •  2
  • Johan  · 技术社区  · 7 年前

    当我在visual studio中编译项目时,我会自动运行模糊处理程序。 混淆了。dll文件以相同的文件名保存在子文件夹中。

    文件夹结构

    FileA_Secure (subfolder)
        FileA.dll
    FileA.dll
    

    问题:我能确保Inno安装程序编译吗 FileA.dll 从子文件夹 FileA_Secure 如果“安全”,则从主文件夹 存在?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Martin Prikryl    4 年前

    您可以使用 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(".")