【问题标题】:Uncheck a task checkbox at setup initialisation在设置初始化时取消选中任务复选框
【发布时间】: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 中的代码不会被触发。

标签: inno-setup pascalscript


【解决方案1】:

我不明白,为什么你需要重置任务。我的印象是您有条件地跳过任务执行不正确。

这只是一个猜测,但我假设您使用ShouldSkipPage 跳过任务页面。因此,如果在以前的安装中启用了该任务,则该任务将保持选中状态。

不要为此使用ShouldSkipPage,而是使用Check parameter。如果仅使用Check 参数有条件地禁用了单个任务,则会跳过整个任务页面。

[Tasks]
Name: DeleteConfig; Description: "{cm:Task_DeleteConfig}"; Flags: unchecked; \
  Check: UseDeleteConfig

[Code]

function UseDeleteConfig: Boolean;
begin
  Result := IsDowngradeSetup;
end;

要回答您的实际问题,您可以这样做:

procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageId = wpReady then
  begin
    if PrevInstallExists then
    begin
      { In Inno Setup 6, you can use WizardSelectTasks }
      WizardForm.TasksList.Checked[0] := False;
    end;
  end;
end;

function UpdateReadyMemo(
  Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo,
  MemoGroupInfo, MemoTasksInfo: String): String;
begin
  if PrevInstallExists then
  begin
    MemoTasksInfo := '';
  end;
end;

虽然我不认为这是一个好的解决方案。

或者更简单,使用UsePreviousTasks

[Setup]
UsePreviousTasks=no

或者类似地使用checkedonce flag:

[Tasks]
Name: DeleteConfig; Description: "{cm:Task_DeleteConfig}"; Flags: unchecked checkedonce

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-21
    • 2018-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多