仅当文件由于 onlyifdoesntexist 标志而未被跳过时才调用 Inno Setup AfterInstall 函数
Call Inno Setup AfterInstall function only when the file is not skipped due to onlyifdoesntexist flag
AfterInstall
函数总是被调用,即使文件已经存在:
[Files]
Source: "myfile.txt"; DestDir: "{app}"; Flags: onlyifdoesntexist; \
AfterInstall: MyAfterInstall('{app}\myfile.txt')
如果 "myfile.txt" 已经存在,它不会被覆盖(未安装)并且在这种情况下不应调用 AfterInstall
(我认为)。
您可以使用 Check
parameter 代替 onlyifdoesntexist
标志。
[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Check: OnlyIfDoesntExist; \
AfterInstall: MyAfterInstall
[Code]
function OnlyIfDoesntExist: Boolean;
var
FileName: string;
begin
FileName := ExpandConstant(CurrentFilename);
Result := not FileExists(FileName);
if Result then
begin
Log(Format('Installing "%s" as the file does not exists yet.', [FileName]));
end
else
begin
Log(Format('Skipping "%s" as the files exists already.', [FileName]));
end;
end;
procedure MyAfterInstall;
begin
Log(Format('Installed "%s".', [ExpandConstant(CurrentFilename)]));
end;
请注意,Check
函数被调用了多次,因此您会在日志中多次看到相应的消息。如果你碰巧把检查变成了一个昂贵的函数,你最好把结果缓存起来。
另请注意,您不必将文件名传递给 AfterInstall
过程,因为您可以使用 CurrentFilename
function.
检索名称
AfterInstall
函数总是被调用,即使文件已经存在:
[Files]
Source: "myfile.txt"; DestDir: "{app}"; Flags: onlyifdoesntexist; \
AfterInstall: MyAfterInstall('{app}\myfile.txt')
如果 "myfile.txt" 已经存在,它不会被覆盖(未安装)并且在这种情况下不应调用 AfterInstall
(我认为)。
您可以使用 Check
parameter 代替 onlyifdoesntexist
标志。
[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Check: OnlyIfDoesntExist; \
AfterInstall: MyAfterInstall
[Code]
function OnlyIfDoesntExist: Boolean;
var
FileName: string;
begin
FileName := ExpandConstant(CurrentFilename);
Result := not FileExists(FileName);
if Result then
begin
Log(Format('Installing "%s" as the file does not exists yet.', [FileName]));
end
else
begin
Log(Format('Skipping "%s" as the files exists already.', [FileName]));
end;
end;
procedure MyAfterInstall;
begin
Log(Format('Installed "%s".', [ExpandConstant(CurrentFilename)]));
end;
请注意,Check
函数被调用了多次,因此您会在日志中多次看到相应的消息。如果你碰巧把检查变成了一个昂贵的函数,你最好把结果缓存起来。
另请注意,您不必将文件名传递给 AfterInstall
过程,因为您可以使用 CurrentFilename
function.