Inno Setup会记住下次安装时的自定义复选框状态

时间:2014-10-22 23:07:42

标签: inno-setup

当用户下次运行安装程序或重新安装时,有没有办法记住自定义页面上的自定义复选框的状态(已选中/已取消选中)?类似经典的ComponentsList。

安装程序有cca。 7个自定义页面上的100个选项(自定义复选框/单选按钮)。如果用户已经从之前的安装预先选择了他们的选择,那将是很好

我的代码如下所示:

[Setup]
AppName=My Program
AppVerName=My Program version 1.5
DefaultDirName={pf}\My Program

[Files]
Source: ReadMe1.rtf; Flags: dontcopy
Source: ReadMe2.rtf; Flags: dontcopy
Source: ReadMe3.rtf; Flags: dontcopy

Source: Image1.bmp; Flags: dontcopy
Source: Image2.bmp; Flags: dontcopy
Source: Image3.bmp; Flags: dontcopy

Source: Files\*; DestDir: {app}\add; Flags: ignoreversion recursesubdirs createallsubdirs; Check: CheckedBox(2)

[Code]
var
  Page: TWizardPage;
  ListBox: TNewCheckListBox;
  Memo: TRichEditViewer;
  CheckLabel: TLabel;
  MouseY: integer;
  BitmapImage: TBitmapImage;
  InfoBmp: array of TBitmap;

function CheckedBox(ItemNumber: integer): Boolean;
begin                                    
  Result:= ListBox.Checked[ItemNumber];  
end;

procedure CheckOnClick (Sender: TObject); 
begin
  if MouseY < ListBox.Items.Count then
    begin 
      ListBox.Checked[MouseY]:= Not(ListBox.Checked[MouseY]);
    end;
end;

procedure CheckMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin                                       
  MouseY:= Y/ScaleY(16);
  if MouseY < ListBox.Items.Count then
    begin  
      Memo.RTFText:= TStrings(ListBox.ItemObject[MouseY]).Text;
      BitmapImage.Bitmap:= InfoBmp[MouseY];
    end;
end;

procedure InitializeWizard();
var
  i: integer;
begin
  ExtractTemporaryFile('ReadMe1.rtf'); ˙
  ExtractTemporaryFile('ReadMe2.rtf');
  ExtractTemporaryFile('ReadMe3.rtf');
  ExtractTemporaryFile('Image1.bmp');  
  ExtractTemporaryFile('Image2.bmp');
  ExtractTemporaryFile('Image3.bmp');

  Page:=CreateCustomPage(wpWelcome, 'Title', 'Description')

  ListBox:= TNewCheckListBox.Create(Page); 
  with ListBox do
    begin
      Left   := 15
      Top    := 0
      Width  := 200
      Height := 149
      Parent := Page.Surface
      AddCheckBox('Global', '', 0, True, True, True, True, TStringList.Create);
      AddCheckBox('Option 1', '', 1, True, True, False, True, TStringList.Create);
      AddCheckBox('Option 2', '', 1, True, True, False, True, TStringList.Create);

      TStrings(ItemObject[0]).LoadFromFile(ExpandConstant('{tmp}\ReadMe1.rtf'));
      TStrings(ItemObject[1]).LoadFromFile(ExpandConstant('{tmp}\ReadMe2.rtf'));
      TStrings(ItemObject[2]).LoadFromFile(ExpandConstant('{tmp}\ReadMe3.rtf'));
    end;

  Memo:= TRichEditViewer.Create(Page); 
  with Memo do
    begin
      Left        := ListBox.Left + ListBox.Width + 8;
      Top         := ListBox.Top;
      Width       := ListBox.Width;
      Height      := ListBox.Height;
      Color       := clBtnFace;
      Enabled     := False;
      BorderStyle := bsNone;
      Parent      := Page.Surface;
    end;

  CheckLabel:= TLabel.Create(Page);  
  with CheckLabel do
    begin
      Width       :=ListBox.Width;
      Height      :=ListBox.Height;
      Autosize    :=False;
      Transparent :=True;
      OnMouseMove :=@CheckMouseMove;
      OnClick     :=@CheckOnClick;
      Parent      :=ListBox;
      Cursor      := 1;
    end;

  BitmapImage := TBitmapImage.Create(Page);
  with BitmapImage do                       
    begin                                   
      AutoSize := True;
      Left        := ListBox.Left;
      Top         := ListBox.Top + ListBox.Height + 8;
      Width       := ListBox.Width;
      Height      := 32;
      Parent := Page.Surface;
    end;

  for i:=0 to ListBox.Items.Count - 1 do  
    begin                                
      SetArrayLength(InfoBmp, i+1);
      InfoBmp[i]:= TBitmap.Create;
    end;

  InfoBmp[0].LoadFromFile(ExpandConstant('{tmp}\Image1.bmp'));
  InfoBmp[1].LoadFromFile(ExpandConstant('{tmp}\Image2.bmp'));
  InfoBmp[2].LoadFromFile(ExpandConstant('{tmp}\Image3.bmp'));
end;