安装后,我想将一个字符串保存到4个文件中的3个,但是当前它正在将字符串保存到所有文件。如何排除名为network的文件?我在考虑另一条if
语句,但不确定如何。该文件为{app}\configs\network.config
procedure MyBeforeInstall;
begin
if(FileExists(ExpandConstant(CurrentFileName))) then
begin
Exists := True;
end
else
begin
Exists := False;
end;
end;
procedure MyAfterInstall;
begin
if not(Exists) then
SaveStringToFile(ExpandConstant(CurrentFileName), #13#10 + 'SettingEnv ' + SettingEnv.Values[0] + #13#10, True);
MsgBox(ExpandConstant(CurrentFileName), mbInformation, MB_OK);
end;
答案 0 :(得分:0)
假设您像这样使用MyBeforeInstall
和MyAfterInstall
:
[Files]
Source: "*.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
然后您可以执行以下操作:
[Files]
Source: "one.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "two.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "three.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "but_not_this_one.txt"; DestDir: "{app}"
这也可以:
[Files]
Source: "*.txt"; Excludes: "but_no_this_one.txt"; DestDir: "{app}"; \
BeforeInstall: MyBeforeInstall; AfterInstall: MyAfterInstall
Source: "but_not_this_one.txt"; DestDir: "{app}"
另一个选择是:
procedure MyAfterInstall;
begin
if CompareText(ExtractFileName(CurrentFileName), 'but_not_this_one.txt') <> 0 then
begin
if not Exists then
SaveStringToFile(
CurrentFileName,
#13#10 + 'SettingEnv ' + SettingEnv.Values[0] + #13#10, True);
end;
MsgBox(CurrentFileName, mbInformation, MB_OK);
end;
(ntb,ExpandConstant
上使用CurrentFileName
是没有意义的,因为它的返回值不包含任何常量)