⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wizard.pas

📁 源代码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  ComponentEntry: PSetupComponentEntry;
  I: Integer;
begin
  Components.Clear();
  for I := 0 to ComponentsList.Items.Count-1 do begin
    if ComponentsList.Checked[I] then begin
      ComponentEntry := PSetupComponentEntry(ComponentsList.ItemObject[I]);
      Components.Add(GetString(ComponentEntry, Descriptions));
    end;
  end;
end;

procedure TWizardForm.GetSelectedTasks(Tasks: TStringList; const Descriptions, IndentDescriptions, GroupDescriptions: Boolean);

  function GetString(TaskEntry: PSetupTaskEntry; Descriptions, IndentDescriptions: Boolean; IndentLevel: Integer): String;
  begin
    if Descriptions then begin
      Result := RemoveAccelChar(ExpandConst(TaskEntry.Description));
      if IndentDescriptions then
        Result := Format('%*s', [3*IndentLevel, '']) + Result;
    end else
      Result := TaskEntry.Name;
  end;

var
  TaskEntry: PSetupTaskEntry;
  I, IndentLevel: Integer;
  GroupDescription, LastGroupDescription: String;
begin
  Tasks.Clear();
  if GroupDescriptions then
    LastGroupDescription := '';

  for I := 0 to TasksList.Items.Count-1 do begin
    if TasksList.Checked[I] and (TasksList.ItemObject[I] <> nil) then begin
      TaskEntry := PSetupTaskEntry(TasksList.ItemObject[I]);

      if GroupDescriptions then begin
        GroupDescription := ExpandConst(TaskEntry.GroupDescription);

        if GroupDescription <> LastGroupDescription then begin
          if GroupDescription <> '' then
            Tasks.Add(RemoveAccelChar(GroupDescription));
          LastGroupDescription := GroupDescription;
        end;

        IndentLevel := TaskEntry.Level;
        if GroupDescription <> '' then
          Inc(IndentLevel);
      end else
        IndentLevel := TaskEntry.Level;

      Tasks.Add(GetString(TaskEntry, Descriptions, IndentDescriptions, IndentLevel));
    end;
  end;
end;

function TWizardForm.PrepareToInstall: Boolean;
begin
  Result := True;
  PreparingErrorBitmapImage.Visible := False;
  PreparingLabel.Visible := False;
  if PreviousInstallNotCompleted then begin
    PreparingLabel.Caption := ExpandSetupMessage(msgPreviousInstallNotCompleted) +
      SNewLine + SNewLine + SNewLine + SetupMessages[msgCannotContinue];
    AdjustLabelHeight(PreparingLabel);
    PreparingErrorBitmapImage.Visible := True;
    PreparingLabel.Visible := True;
    Result := False;
    Exit;
  end;
end;

procedure TWizardForm.UpdatePage(const PageID: Integer);

  procedure ReadyMemoAppend(const Lines: String);
  begin
    if Lines <> '' then begin
      if ReadyMemo.Lines.Count > 0 then
        ReadyMemo.Lines.Append('');
      ReadyMemo.Lines.Append(Lines);
    end;
  end;

  procedure UpdateReadyPage;
  var
    TypeEntry: PSetupTypeEntry;
    SelectedComponents, SelectedTasks: TStringList;
    Space, S, MemoUserInfoInfo, MemoDirInfo, MemoGroupInfo, MemoTypeInfo, MemoComponentsInfo, MemoTasksInfo: String;
    I: Integer;
  begin
    Space := Format('%6s', ['']);

    ReadyMemo.Visible := False;
    if not (shDisableReadyMemo in SetupHeader.Options) then begin
      ReadyMemo.Lines.Clear();

      if shUserInfoPage in SetupHeader.Options then begin
        MemoUserInfoInfo := SetupMessages[msgReadyMemoUserInfo];
        MemoUserInfoInfo := MemoUserInfoInfo+SNewLine+Space+UserInfoNameEdit.Text;
        if UserInfoOrgEdit.Text <> '' then
          MemoUserInfoInfo := MemoUserInfoInfo+SNewLine+Space+UserInfoOrgEdit.Text;
      end;

      if (shAlwaysShowDirOnReadyPage in SetupHeader.Options) or
         (not(shDisableDirPage in SetupHeader.Options) and
          (shCreateAppDir in SetupHeader.Options)) then begin
        MemoDirInfo := SetupMessages[msgReadyMemoDir];
        MemoDirInfo := MemoDirInfo+SNewLine+Space+DirEdit.Text;
      end else
        MemoDirInfo := '';

      if HasComponents then begin
        TypeEntry := GetSetupType();
        if TypeEntry <> nil then begin
          MemoTypeInfo := SetupMessages[msgReadyMemoType];
          MemoTypeInfo := MemoTypeInfo+SNewLine+Space+ExpandConst(TypeEntry.Description);
        end else
          MemoTypeInfo := '';  { can get here if all types failed their Check }

        SelectedComponents := TStringList.Create();
        GetSelectedComponents(SelectedComponents, True, True);
        if SelectedComponents.Count > 0 then begin
          MemoComponentsInfo := SetupMessages[msgReadyMemoComponents];
          for I := 0 to SelectedComponents.Count-1 do
            MemoComponentsInfo := MemoComponentsInfo+SNewLine+Space+SelectedComponents[I];
        end else
          MemoComponentsInfo := '';
        SelectedComponents.Free();
      end;

      if HasIcons and not NoIconsCheck.Checked and
         ((shAlwaysShowGroupOnReadyPage in SetupHeader.Options) or
          not(shDisableProgramGroupPage in SetupHeader.Options)) then begin
        MemoGroupInfo := SetupMessages[msgReadyMemoGroup];
        MemoGroupInfo := MemoGroupInfo+SNewLine+Space+GroupEdit.Text;
      end else
        MemoGroupInfo := '';

      SelectedTasks := TStringList.Create();
      GetSelectedTasks(SelectedTasks, True, True, True);
      if SelectedTasks.Count > 0 then begin
        MemoTasksInfo := SetupMessages[msgReadyMemoTasks];
        for I := 0 to SelectedTasks.Count-1 do
          MemoTasksInfo := MemoTasksInfo+SNewLine+Space+SelectedTasks[I];
      end else
        MemoTasksInfo := '';
      SelectedTasks.Free();

      if (CodeRunner <> nil) and (CodeRunner.FunctionExists('UpdateReadyMemo')) then begin
        try
          ReadyMemo.Lines.Text := CodeRunner.RunStringFunction('UpdateReadyMemo',
            [Space, SNewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo,
             MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo], True, '');
        except
          Application.HandleException(Self);
        end;
      end else begin
        ReadyMemoAppend(MemoUserInfoInfo);
        ReadyMemoAppend(MemoDirInfo);
        ReadyMemoAppend(MemoTypeInfo);
        ReadyMemoAppend(MemoComponentsInfo);
        ReadyMemoAppend(MemoGroupInfo);
        ReadyMemoAppend(MemoTasksInfo);
      end;

      ReadyMemo.SelStart := 0;
      ReadyMemo.SelLength := 0;
    end;

    if ReadyMemo.Lines.Count > 0 then begin
      S := SetupMessages[msgReadyLabel2a];
      ChangeReadyLabel(S);
      ReadyMemo.Visible := True;
    end else begin
      S := SetupMessages[msgReadyLabel2b];
      ChangeReadyLabel(S);
    end;
  end;

begin
  case PageID of
    wpSelectTasks: begin
        if NeedSelectTasksPageUpdate then begin
          UpdateSelectTasksPage();
          NeedSelectTasksPageUpdate := False;
        end;
      end;
    wpReady: UpdateReadyPage;
  end;
end;

procedure TWizardForm.AdjustFocus;
var
  NewActiveControl: TWinControl;
begin
  case CurPageID of
    wpReady: NewActiveControl := NextButton;
    wpPreparing: NewActiveControl := CancelButton;
  else
    NewActiveControl := FindNextControl(nil, True, True, False);
  end;
  if (NewActiveControl = BackButton) and NextButton.CanFocus then
    NewActiveControl := NextButton;
  ActiveControl := NewActiveControl;
end;

function TWizardForm.GetPreviousPageID: Integer;
{ Finds ID of previous page (not counting skipped pages), or -1 if there is
  no previous page to return to. }
var
  CurPageIndex, I: Integer;
begin
  CurPageIndex := PageIndexFromID(CurPageID);
  for I := CurPageIndex-1 downto 0 do begin
    Result := TWizardPage(FPageList[I]).ID;
    { Never go back to wpInstalling }
    if Result = wpInstalling then
      Break;
    if not ShouldSkipPage(Result) then
      Exit;
  end;
  Result := -1;
end;

procedure TWizardForm.SetCurPage(const NewPageID: Integer);
{ Changes which page is currently visible }
var
  PageIndex: Integer;
  Page: TWizardPage;
  Flags: UINT;
begin
  PageIndex := PageIndexFromID(NewPageID);
  Page := FPageList[PageIndex];
  CurPageID := NewPageID;

  { Select the page in the notebooks }
  if Assigned(Page.InnerNotebookPage) then
    InnerNotebook.ActivePage := Page.InnerNotebookPage;
  OuterNotebook.ActivePage := Page.OuterNotebookPage;

  { Set button visibility and captions }
  if not(psNoButtons in Page.Style) then begin
    BackButton.Visible := (CurPageID <> wpInstalling) and (GetPreviousPageID <> -1);
    NextButton.Visible := CurPageID <> wpInstalling;
    case CurPageID of
      wpLicense: NextButton.Enabled := LicenseAcceptedRadio.Checked;
      wpPreparing: NextButton.Enabled := False;
    else
      NextButton.Enabled := True;
    end;
    CancelButton.Visible := (PageIndex <= PageIndexFromID(wpInstalling));
    CancelButton.Enabled := (CurPageID <> wpInstalling) or
      ((shAllowCancelDuringInstall in SetupHeader.Options) and not InitNoCancel);
  end
  else begin
    BackButton.Visible := False;
    NextButton.Visible := False;
    CancelButton.Visible := False;
  end;
  { Set the enabled state of the close button to match the Cancel button }
  if CancelButton.CanFocus then
    Flags := 0
  else
    Flags := MF_GRAYED;
  EnableMenuItem(GetSystemMenu(Handle, False), SC_CLOSE, MF_BYCOMMAND or Flags);

  BackButton.Caption := SetupMessages[msgButtonBack];
  case CurPageID of
    wpReady: begin
        NextButton.Caption := SetupMessages[msgButtonInstall];
        CancelButton.Caption := SetupMessages[msgButtonCancel];
      end;
    wpFinished: begin
        NextButton.Caption := SetupMessages[msgButtonFinish];
        CancelButton.Caption := SetupMessages[msgButtonCancel];
      end;
  else
    NextButton.Caption := SetupMessages[msgButtonNext];
    CancelButton.Caption := SetupMessages[msgButtonCancel];
  end;

  { Set the page description }
  Page.SyncCaptionAndDescription;

  BeveledLabel.Visible := (SetupMessages[msgBeveledLabel] <> '') and
    not(CurPageID in [wpWelcome, wpFinished]);

  { Adjust focus }
  AdjustFocus;

  { If on the wpUserInfo page, check the serial now, after the rest of the
    page is initialized in case the event function happens to display a
    message box or raise an exception }
  if CurPageID = wpUserInfo then begin
    try
      NextButton.Enabled := CheckSerialOk();
    except
      NextButton.Enabled := False;
      Application.HandleException(Self);
    end;
  end;

  try
    PageFromID(CurPageID).Activate;
  except
    Application.HandleException(Self);
  end;

  try
    if CodeRunner <> nil then
      CodeRunner.RunProcedure('CurPageChanged', [CurPageID], False);
  except
    Application.HandleException(Self);
  end;
end;

function TWizardForm.ShouldSkipPage(const PageID: Integer): Boolean;

  function SkipSelectTasksPage: Boolean;
  var
    SelectedComponents: TStringList;
    I: Integer;
  begin
    //check if there is a task that has to be processed based on the selected
    //components
    SelectedComponents := TStringList.Create();
    GetSelectedComponents(SelectedComponents, False, False);
    Result := True;
    for I := 0 to Entries[seTask].Count-1 do begin
      with PSetupTaskEntry(Entries[seTask][I])^ do begin
        if ShouldProcessEntry(SelectedComponents, nil, Components, '', Languages, '') then begin
          Result := False;
          Break;
        end;
      end;
    end;
    SelectedComponents.Free();
  end;

begin
  Result :=
    (psAlwaysSkip in PageFromID(PageID).Style) or
    ((PageID = wpLicense) and ((ActiveLicenseText = '') or (InstallMode <> imNormal))) or
    ((PageID = wpPassword) and not NeedPassword) or
    ((PageID = wpInfoBefore) and (ActiveInfoBeforeText = '')) or
    ((PageID = wpUserInfo) and not(shUserInfoPage in SetupHeader.Optio

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -