我需要使用 Inno Setup 创建的安装程序在最终用户计算机上安装一组跨越多个文件夹的隐藏文件。我已经提到了Copying hidden files in Inno Setup ,但似乎指定的 DirectoryCopy 函数将文件从同一台计算机复制到同一台计算机。
我需要从 setup.exe 文件中提取隐藏文件,然后将其安装到最终用户计算机上,该计算机与创建安装程序的计算机不同。
最佳答案
当[Files]
部分Source
参数为通配符时,隐藏文件将被忽略。请参阅BuildFileList
in Compile.pas
.
一个简单的解决方案是从源文件中删除隐藏属性。
如果您无法删除隐藏属性(例如,如果您需要在安装时保留它),您可以使用 preprocessor 生成 [Files]
部分条目,避免使用通配符。
#pragma parseroption -p-
; If the file is found by calling FindFirst without faHidden, it's not hidden
#define FileParams(FileName) \
Local[0] = FindFirst(FileName, 0), \
(!Local[0] ? "; Attribs: hidden" : "")
#define FileEntry(Source, DestDir) \
"Source: \"" + Source + "\"; DestDir: \"" + DestDir + "\"" + \
FileParams(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+
使用 ProcessFolder
宏,例如:
[Files]
#emit ProcessFolder("C:\source", "{app}")
它将生成一个如下脚本:
[Files]
Source: "C:\source\file.txt"; DestDir: "{app}"
Source: "C:\source\subfolder\file.jpg"; DestDir: "{app}\subfolder"
Source: "C:\source\subfolder\hidden.txt"; DestDir: "{app}\subfolder"; Attribs: hidden
(参见 Inno Setup: How do I see the output (translation) of the Inno Setup Preprocessor? )
NTB,question, you are referring to ,是关于复制外部文件的,因此它与您的问题无关。
关于inno-setup - 使用 Inno Setup 安装隐藏文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50209033/