gpt4 book ai didi

inno-setup - Inno Setup - 在安装程序中获取文件信息

转载 作者:行者123 更新时间:2023-12-05 04:34:57 32 4
gpt4 key购买 nike

如何获取有关安装程序中包含的文件的信息(最后修改时间戳、文件大小)?通过使用文件的路径,很容易引用磁盘上的文件。但是当文件没有路径时,如何在安装程序中引用它呢?

当安装程序初始化时,我想检查磁盘上是否已经有任何要安装的文件。对于那些已经在磁盘上的文件(相同的上次修改时间戳和相同的文件大小),我想为用户显示一个窗口,以便能够选择他们想要覆盖的文件。

最佳答案

以下preprocessor代码将生成一个 Pascal 脚本函数,该函数返回给定相对文件路径的时间戳字符串:

#define SourcePath "C:\myappfiles"

function GetSourceFileDateTimeString(FileName: string): string;
begin

#define FileEntry(FileName, SourcePath) \
Local[0] = GetFileDateTimeString(SourcePath, "yyyy/mm/dd hh:nn:ss", "-", ":"),\
" if SameText(FileName, '" + FileName + "') then " + \
"Result := '" + Local[0] + "'" + NewLine + \
" else" + NewLine

#define ProcessFile(Root, Path, FindResult, FindHandle) \
FindResult \
? \
Local[0] = FindGetFileName(FindHandle), \
Local[1] = (Len(Path) > 0 ? Path + "\" : "") + Local[0], \
Local[2] = Root + "\" + Local[1], \
(Local[0] != "." && Local[0] != ".." \
? (DirExists(Local[2]) \
? ProcessFolder(Root, Local[1]) \
: FileEntry(Local[1], Local[2])) \
: "") + \
ProcessFile(Root, Path, FindNext(FindHandle), FindHandle) \
: \
""
#define ProcessFolder(Root, Path) \
Local[0] = FindFirst(Root + "\" + Path + "\*", faAnyFile), \
ProcessFile(Root, Path, Local[0], Local[0])

#emit ProcessFolder(SourcePath, "")
RaiseException(Format('Unexpected file "%s"', [FileName]));
end;

生成的脚本如下:

function GetSourceFileDateTimeString(FileName: string): string;
begin
if SameText(FileName, 'sub1\file1.exe') then Result := '2022-02-16 18:18:11'
else
if SameText(FileName, 'sub2\file2.exe') then Result := '2022-02-16 18:18:11'
else
if SameText(FileName, 'file3.exe') then Result := '2022-02-19 09:50:14'
else
if SameText(FileName, 'file4.exe') then Result := '2022-02-19 09:50:14'
else
RaiseException(Format('Unexpected file "%s"', [FileName]));
end;

(参见 Inno Setup: How do I see the output (translation) of the Inno Setup Preprocessor?)

关于inno-setup - Inno Setup - 在安装程序中获取文件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71140338/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com