我有一个InnoSetup项目,我希望能够根据发送到setup exe的命令行参数设置InfoAfterFile。 有没有办法这样做?有什么像“检查”参数在这种情况下会起作用吗?
答案 0 :(得分:2)
您无法在运行时为InfoAfterFile
指令赋值。它的值指定编译到输出设置中的文件,因此必须在编译时知道该指令值。但是,您可以手动将文件加载到InfoAfterMemo
控件中。以下示例显示了仅当该参数存在且文件存在时,如何加载命令行参数-iaf
指定的文件:
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
InfoAfterFile=c:\DefaultFileToBeDisplayed.txt
[Code]
const
InfoAfterFileParam = '-iaf';
function TryGetInfoAfterFileParam(var FileName: string): Boolean;
var
S: string;
I: Integer;
Index: Integer;
begin
// initialize result
Result := False;
// iterate all the command line parameters
for I := 1 to ParamCount do
begin
// store the current parameter to the local variable
S := ParamStr(I);
// try to find the position of the substring specified by the
// InfoAfterFileParam constant; in this example we're looking
// for the "-iaf" string in the current parameter
Index := Pos(InfoAfterFileParam, S);
// if the InfoAfterFileParam constant string was found in the
// current parameter, then...
if Index = 1 then
begin
// strip out the InfoAfterFileParam constant string from the
// parameter string, so we get only file name
Delete(S, Index, Length(InfoAfterFileParam));
// now trim the spaces from rest of the string, which is the
// file name
S := Trim(S);
// check if the file pointed by the file name we got exists;
// if so, then return True for this function call and assign
// the output file name to the output parameter
if FileExists(S) then
begin
Result := True;
FileName := S;
end;
// we've found the parameter starting with InfoAfterFileParam
// constant string, so let's exit the function
Exit;
end;
end;
end;
procedure InitializeWizard;
var
FileName: string;
begin
// when the parameter was found and the file to be loaded exists,
// then load it to the InfoAfterMemo control
if TryGetInfoAfterFileParam(FileName) then
WizardForm.InfoAfterMemo.Lines.LoadFromFile(FileName);
end;
请注意,您必须指定InfoAfterFile
指令,否则页面将不会显示。另请注意,我正在寻找以-iaf
开头的命令行参数,因此如果您希望使用例如,您需要实际修改此代码。 -iafx
参数。以下是从命令行调用此类设置的示例:
Setup.exe -iaf"C:\SomeFolder\SomeFileToBeShownAsInfoAfter.txt"