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

📄 compwizard.pas

📁 源代码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit CompWizard;

{
  Inno Setup
  Copyright (C) 1997-2004 Jordan Russell
  Portions by Martijn Laan
  For conditions of distribution and use, see LICENSE.TXT.

  Compiler Script Wizard form

  $jrsoftware: issrc/Projects/CompWizard.pas,v 1.32 2004/06/05 16:10:32 mlaan Exp $
}

interface

{$I VERSION.INC}

uses
  Windows, Forms, Classes, Graphics, StdCtrls, ExtCtrls, Controls, Dialogs,
  UIStateForm, NewStaticText, DropListBox;

type
  TWizardPage = (wpWelcome, wpAppInfo, wpAppDir, wpAppFiles, wpAppIcons,
                 wpAppDocs, wpFinished);

  TWizardFormResult = (wrNone, wrEmpty, wrComplete);

  TWizardForm = class(TUIStateForm)
    CancelButton: TButton;
    NextButton: TButton;
    BackButton: TButton;
    Notebook1: TNotebook;
    Notebook2: TNotebook;
    Bevel: TBevel;
    WelcomeImage: TImage;
    WelcomeLabel1: TNewStaticText;
    PnlMain: TPanel;
    Bevel1: TBevel;
    PageNameLabel: TNewStaticText;
    PageDescriptionLabel: TNewStaticText;
    InnerImage: TImage;
    FinishedLabel: TNewStaticText;
    FinishedImage: TImage;
    WelcomeLabel2: TNewStaticText;
    EmptyCheck: TCheckBox;
    WelcomeLabel3: TNewStaticText;
    AppNameLabel: TNewStaticText;
    AppNameEdit: TEdit;
    AppVerNameLabel: TNewStaticText;
    AppVerNameEdit: TEdit;
    AppDirNameLabel: TNewStaticText;
    AppRootDirComboBox: TComboBox;
    AppRootDirEdit: TEdit;
    AppDirNameEdit: TEdit;
    NotDisableDirPageCheck: TCheckBox;
    AppRootDirLabel: TNewStaticText;
    AppPublisherLabel: TNewStaticText;
    AppPublisherEdit: TEdit;
    OtherLabel: TNewStaticText;
    NotCreateAppDirCheck: TCheckBox;
    AppFilesLabel: TNewStaticText;
    AppFilesListBox: TDropListBox;
    AppFilesAddButton: TButton;
    AppFilesEditButton: TButton;
    AppFilesRemoveButton: TButton;
    AppURLLabel: TNewStaticText;
    AppURLEdit: TEdit;
    AppExeLabel: TNewStaticText;
    AppExeEdit: TEdit;
    AppExeRunCheck: TCheckBox;
    AppExeButton: TButton;
    OpenDialog: TOpenDialog;
    AppGroupNameLabel: TNewStaticText;
    AppGroupNameEdit: TEdit;
    NotDisableProgramGroupPageCheck: TCheckBox;
    AllowNoIconsCheck: TCheckBox;
    Label1: TNewStaticText;
    DesktopIconCheck: TCheckBox;
    QuickLaunchIconCheck: TCheckBox;
    CreateUninstallIconCheck: TCheckBox;
    CreateURLIconCheck: TCheckBox;
    AppLicenseFileLabel: TNewStaticText;
    AppLicenseFileEdit: TEdit;
    AppLicenseFileButton: TButton;
    AppInfoBeforeFileLabel: TNewStaticText;
    AppInfoBeforeFileEdit: TEdit;
    AppInfoBeforeFileButton: TButton;
    AppInfoAfterFileLabel: TNewStaticText;
    AppInfoAfterFileEdit: TEdit;
    AppInfoAfterFileButton: TButton;
    RequiredLabel1: TNewStaticText;
    RequiredLabel2: TNewStaticText;
    AppFilesAddDirButton: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormDestroy(Sender: TObject);
    procedure NextButtonClick(Sender: TObject);
    procedure BackButtonClick(Sender: TObject);
    procedure AppDocsFileButtonClick(Sender: TObject);
    procedure AppRootDirComboBoxChange(Sender: TObject);
    procedure NotCreateAppDirCheckClick(Sender: TObject);
    procedure AppExeButtonClick(Sender: TObject);
    procedure AppFilesListBoxClick(Sender: TObject);
    procedure AppFilesListBoxDblClick(Sender: TObject);
    procedure AppFilesAddButtonClick(Sender: TObject);
    procedure NotDisableProgramGroupPageCheckClick(Sender: TObject);
    procedure AppFilesEditButtonClick(Sender: TObject);
    procedure AppFilesRemoveButtonClick(Sender: TObject);
    procedure AppFilesAddDirButtonClick(Sender: TObject);
    procedure AppFilesListBoxDropFile(Sender: TDropListBox;
      const FileName: String);
  private
    CurPage: TWizardPage;
    FWizardName: String;
    FWizardFiles: TList;
    FResult: TWizardFormResult;
    FResultScript: String;
    function FixLabel(const S: String): String;
    procedure SetWizardName(const WizardName: String);
    procedure CurPageChanged;
    function SkipCurPage: Boolean;
    procedure AddWizardFile(const Source: String; const RecurseSubdirs: Boolean);
    procedure UpdateWizardFiles;
    procedure UpdateWizardFilesButtons;
    procedure GenerateScript;
  public
    property WizardName: String write SetWizardName;
    property Result: TWizardFormResult read FResult;
    property ResultScript: String read FResultScript;
  end;

implementation

{$R *.DFM}

uses
  SysUtils, ShlObj, {$IFNDEF Delphi3orHigher} Ole2, {$ELSE} ActiveX, {$ENDIF}
  PathFunc, CmnFunc, CmnFunc2,
  CompMsgs, CompWizardFile, CompForm;

type
  TConstant = record
    Constant, Description: String;
  end;

const
  NotebookPages: array[TWizardPage, 0..1] of Integer =
    ((0, -1), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (2, -1));

  PageCaptions: array[TWizardPage] of String =
    (SWizardWelcome, SWizardAppInfo, SWizardAppDir, SWizardAppFiles,
     SWizardAppIcons, SWizardAppDocs, SWizardFinished);

  PageDescriptions: array[TWizardPage] of String =
    ('', SWizardAppInfo2, SWizardAppDir2, SWizardAppFiles2,
         SWizardAppIcons2, SWizardAppDocs2, '');

  AppRootDirs: array[0..0] of TConstant =
  (
    ( Constant: '{pf}'; Description: 'Program Files directory')
  );

function TWizardForm.FixLabel(const S: String): String;
begin
  Result := S;
  {don't localize these}
  StringChange(Result, '[name]', FWizardName);
end;

procedure TWizardForm.SetWizardName(const WizardName: String);
begin
  FWizardName := WizardName;
end;

{ --- }

procedure TWizardForm.FormCreate(Sender: TObject);
var
  I: Integer;
begin
  FResult := wrNone;

  FWizardName := SWizardDefaultName;
  FWizardFiles := TList.Create;

  InitFormFont(Self);
  if FontExists('Verdana') then
    WelcomeLabel1.Font.Name := 'Verdana';

  FinishedImage.Picture := WelcomeImage.Picture;

  RequiredLabel2.Left := RequiredLabel1.Left + RequiredLabel1.Width;

  { AppInfo }
  AppNameEdit.Text := 'My Program';
  AppVerNameEdit.Text := 'My Program 1.5';
  AppPublisherEdit.Text := 'My Company, Inc.';
  AppURLEdit.Text := 'http://www.mycompany.com';

  { AppDir }
  for I := Low(AppRootDirs) to High(AppRootDirs) do
    AppRootDirComboBox.Items.Add(AppRootDirs[I].Description);
  AppRootDirComboBox.Items.Add('(Custom)');
  AppRootDirComboBox.ItemIndex := 0;
  AppRootDirEdit.Enabled := False;
  AppRootDirEdit.Color := clBtnFace;
  NotDisableDirPageCheck.Checked := True;

  { AppFiles }
  AppExeEdit.Text := PathExtractPath(Application.ExeName) + 'Examples\MyProg.exe';
  AppExeRunCheck.Checked := True;
  UpdateWizardFilesButtons;

  { AppIcons }
  NotDisableProgramGroupPageCheck.Checked := True;
  DesktopIconCheck.Checked := True;

  CurPage := Low(TWizardPage);
  CurPageChanged;
end;

procedure TWizardForm.FormShow(Sender: TObject);
begin
  Caption := FWizardName;
  WelcomeLabel1.Caption := FixLabel(WelcomeLabel1.Caption);
  FinishedLabel.Caption := FixLabel(FinishedLabel.Caption);
end;

procedure TWizardForm.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  if ModalResult = mrCancel then
    CanClose := MsgBox(FixLabel(SWizardCancelMessage), FWizardName, mbConfirmation, MB_YESNO) = idYes;
end;

procedure TWizardForm.FormDestroy(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to FWizardFiles.Count-1 do
    Dispose(FWizardFiles[i]);
  FWizardFiles.Free;
end;

{ --- }

procedure TWizardForm.CurPageChanged;
{ Call this whenever the current page is changed }
begin
  Notebook1.PageIndex := NotebookPages[CurPage, 0];
  if NotebookPages[CurPage, 1] <> -1 then
    Notebook2.PageIndex := NotebookPages[CurPage, 1];

  { Set button visibility and captions }
  BackButton.Visible := not (CurPage = wpWelcome);
  if CurPage = wpFinished then
    NextButton.Caption := SWizardFinishButton
  else
    NextButton.Caption := SWizardNextButton;

  RequiredLabel1.Visible := not (CurPage in [wpWelcome, wpFinished]);
  RequiredLabel2.Visible := RequiredLabel1.Visible;

  { Set the Caption to match the current page's title }
  PageNameLabel.Caption := PageCaptions[CurPage];
  PageDescriptionLabel.Caption := PageDescriptions[CurPage];
  if CurPage in [wpWelcome, wpFinished] then
    Notebook1.Color := clWindow
  else
    Notebook1.Color := clBtnFace;

  { Adjust focus }
  case CurPage of
    wpAppInfo: ActiveControl := AppNameEdit;
    wpAppDir:
      begin
        if AppRootDirComboBox.Enabled then
          ActiveControl := AppRootDirComboBox
        else
          ActiveControl := NotCreateAppDirCheck;
      end;
    wpAppFiles:
      begin
        if AppExeEdit.Enabled then
          ActiveControl := AppExeEdit
        else
          ActiveControl := AppFilesListBox;
      end;
    wpAppIcons: ActiveControl := AppGroupNameEdit;
    wpAppDocs: ActiveControl := AppLicenseFileEdit;
  end;
end;

function TWizardForm.SkipCurPage: Boolean;
begin
  if ((CurPage = wpAppIcons) and NotCreateAppDirCheck.Checked) or
     (not (CurPage in [wpWelcome, wpFinished]) and EmptyCheck.Checked) then
    Result := True
  else
    Result := False;
end;

procedure TWizardForm.NextButtonClick(Sender: TObject);

  function CheckAppInfoPage: Boolean;
  begin
    Result := False;

    if AppNameEdit.Text = '' then begin
      MsgBox(SWizardAppNameError, '',  mbError, MB_OK);
      ActiveControl := AppNameEdit;
    end else if AppVerNameEdit.Text = '' then begin
      MsgBox(SWizardAppVerNameError, '',  mbError, MB_OK);
      ActiveControl := AppVerNameEdit;
    end else
      Result := True;
  end;

  function CheckAppDirPage: Boolean;
  begin
    Result := False;

    if not NotCreateAppDirCheck.Checked and
       (AppRootDirComboBox.ItemIndex = AppRootDirComboBox.Items.Count-1) and
       (AppRootDirEdit.Text = '') then begin
      MsgBox(SWizardAppRootDirError, '',  mbError, MB_OK);
      ActiveControl := AppRootDirEdit;
    end else if not NotCreateAppDirCheck.Checked and (AppDirNameEdit.Text = '') then begin
      MsgBox(SWizardAppDirNameError, '', mbError, MB_OK);
      ActiveControl := AppDirNameEdit;
    end else
      Result := True;
  end;

  function CheckAppFilesPage: Boolean;
  begin
    Result := False;

    if AppExeEdit.Enabled and (AppExeEdit.Text = '') then begin
      MsgBox(SWizardAppExeError, '', mbError, MB_OK);
      ActiveControl := AppExeEdit;
    end else
      Result := True;
  end;

  function CheckAppIconsPage: Boolean;
  begin
    Result := False;

    if AppGroupNameEdit.Text = '' then begin
      MsgBox(SWizardAppGroupNameError, '', mbError, MB_OK);
      ActiveControl := AppGroupNameEdit;
    end else
      Result := True;
  end;

begin
  case CurPage of
    wpAppInfo: if not CheckAppInfoPage then Exit;
    wpAppDir: if not CheckAppDirPage then Exit;
    wpAppFiles: if not CheckAppFilesPage then Exit;
    wpAppIcons: if not CheckAppIconsPage then Exit;
  end;

  repeat
    if CurPage = wpFinished then begin
      GenerateScript;
      ModalResult := mrOk;
      Exit;
    end;
    Inc(CurPage);

    { Even if we're skipping a page, we should still update it }
    case CurPage of
      wpAppDir: if AppDirNameEdit.Text = '' then AppDirNameEdit.Text := AppNameEdit.Text;
      wpAppIcons:
        begin
          if AppGroupNameEdit.Text = '' then AppGroupNameEdit.Text := AppNameEdit.Text;
          CreateURLIconCheck.Enabled := AppURLEdit.Text <> '';

⌨️ 快捷键说明

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