【发布时间】:2016-01-27 13:16:04
【问题描述】:
在我的 Inno Setup 脚本中,有一个任务可以在由代码确定的特定条件下使用。在其他情况下,不应执行此任务。事实上,整个任务页面都会被跳过。不幸的是,Inno Setup 会记住任务选择,并在每次后续更新设置时恢复,即使页面根本不可见。
我现在需要在每次设置初始化时取消选中该任务,以便忘记上次选择的状态。但我无法让它工作。这是我最近的尝试:
[Tasks]
Name: DeleteConfig; Description: "{cm:Task_DeleteConfig}"; Flags: unchecked
#define Task_DeleteConfig_Index 0
[InstallDelete]
; Delete user configuration files if the task is selected
Type: files; Name: "{userappdata}\...\App.conf"; Tasks: DeleteConfig
[Code]
var
IsDowngradeSetup: Boolean;
function InitializeSetup: Boolean;
begin
// More code not shown here, but the following may be set under certain conditions
IsDowngradeSetup := true;
end;
procedure InitializeWizard;
begin
// Clear possibly remembered value from previous downgrade install
WizardForm.TasksList.Checked[{#Task_DeleteConfig_Index}] := false;
end;
function ShouldSkipPage(PageID: Integer): Boolean;
begin
// Make upgrade install quicker
Result := ((PageID = wpSelectTasks) or ((PageID = wpReady) and (GetArrayLength(products) = 0))) and PrevInstallExists;
end;
procedure CurPageChanged(CurPageID: Integer);
begin
if CurPageID = wpWelcome then
begin
if PrevInstallExists then
begin
// Change "Next" button to "Upgrade" on the first page, because it won't ask any more
WizardForm.NextButton.Caption := ExpandConstant('{cm:Upgrade}');
WizardForm.FinishedHeadingLabel.Caption := ExpandConstant('{cm:UpdatedHeadingLabel}');
end;
end;
if CurPageID = wpSelectTasks then
begin
if IsDowngradeSetup then
begin
// Pre-select task to delete existing configuration on downgrading (user can deselect it again)
// (Use the zero-based index of all rows in the tasks list GUI)
// Source: http://stackoverflow.com/a/10490352/143684
WizardForm.TasksList.Checked[{#Task_DeleteConfig_Index}] := true;
end;
end;
end;
这给了我一个
运行时错误(在 85:77):列表索引超出范围 (0)。
我不知道“85:77”应该在哪里,但从最近的唯一变化来看,它只能是上面引用的代码。
我首先在 InitializeSetup 函数中使用了它,但它也不起作用。
我应该把这段代码放在哪里,这样它才能工作并找到一个完全初始化的任务列表?任务页面可能不会显示,所以我认为等待页面可见为时已晚。事实上,代码曾经在那里,并且在页面被跳过时没有被调用。
【问题讨论】:
-
您可以从标准任务中辞职并为此编写检查,然后在需要时将它们显示为特定 WizardPage 上的复选框。就您目前的情况而言,当 CurPage 是任务列表页面时,您可能必须调用 TaskList。
-
我在我的问题中添加了更多代码,因为似乎需要理解我为什么要这样做。不幸的是,当任务列表显示时我无法重置任务,因为它可能不会显示。
-
原来如此。因此,请使用我的答案中概述的解决方案。我已将其更新为您的最新修订。
-
顺便说一句,请注意,在最新版本的 Inno Setup 中,默认情况下会跳过欢迎页面。所以
CurPageChanged中的代码不会被触发。