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

📄 setup.dpr

📁 源代码
💻 DPR
字号:
program Setup;

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

  Setup program

  $jrsoftware: issrc/Projects/Setup.dpr,v 1.43 2004/09/02 18:37:25 jr Exp $

  NOTE: This project should only be saved in Delphi 3 or later, otherwise the
  version info may be stripped. I still compile this project in Delphi 2,
  though.
}

uses
  XPTheme,
  Forms,
  Windows,
  SysUtils,
  CmnFunc in 'CmnFunc.pas',
  CmnFunc2 in 'CmnFunc2.pas',
  Main in 'Main.pas' {MainForm},
  Install in 'Install.pas',
  Msgs in 'Msgs.pas',
  MsgIDs in 'MsgIDs.pas',
  Undo in 'Undo.pas',
  Struct in 'Struct.pas',
  NewDisk in 'NewDisk.pas' {NewDiskForm},
  InstFunc in 'InstFunc.pas',
  InstFnc2 in 'InstFnc2.pas',
  Wizard in 'Wizard.pas' {WizardForm},
  ScriptFunc_R in 'ScriptFunc_R.pas',
  ScriptFunc in 'ScriptFunc.pas',
  SetupTypes in 'SetupTypes.pas',
  ScriptRunner in 'ScriptRunner.pas',
  ScriptDlg in 'ScriptDlg.pas',
  ScriptClasses_R in 'ScriptClasses_R.pas',
  SelLangForm in 'SelLangForm.pas' {SelectLanguageForm},
  Extract in 'Extract.pas',
  Int64Em in 'Int64Em.pas',
  SelFolderForm in 'SelFolderForm.pas' {SelectFolderForm},
  Compress in 'Compress.pas',
  zlib in 'zlib.pas',
  bzlib in 'bzlib.pas',
  LZMA in 'LZMA.pas',
  CallOptimizer in 'CallOptimizer.pas',
  FileClass in 'FileClass.pas',
  MD5 in 'MD5.pas',
  Logging in 'Logging.pas',
  DebugClient in 'DebugClient.pas',
  DebugStruct in 'DebugStruct.pas',
  ArcFour in 'ArcFour.pas',
  Uninstall in 'Uninstall.pas',
  UninstProgressForm in 'UninstProgressForm.pas' {UninstProgressForm},
  UninstSharedFileForm in 'UninstSharedFileForm.pas' {UninstSharedFileForm},
  SimpleExpression in 'SimpleExpression.pas',
  UIStateForm in 'UIStateForm.pas',
  SetupForm in 'SetupForm.pas',
  RegSvr in 'RegSvr.pas';

{$R *.RES}
{$R IMAGES.RES}

{$I VERSION.INC}

procedure ShowExceptionMsg;
var
  S: String;
begin
  if ExceptObject is EAbort then begin
    Log('Got EAbort exception.');
    Exit;
  end;
  S := GetExceptMessage;
  Log('Exception message:' + SNewLine + S);
  AppMessageBox(PChar(S), Pointer(SetupMessages[msgErrorTitle]),
    MB_OK or MB_ICONSTOP);
    { ^ use a Pointer cast instead of a PChar cast so that it will use "nil"
      if SetupMessages[msgErrorTitle] is empty due to the messages not being
      loaded yet. MessageBox displays 'Error' as the caption if the lpCaption
      parameter is nil. }
end;

procedure DisableWindowGhosting;
var
  Proc: procedure; stdcall;
begin
  { Note: The documentation claims this function is only available in XP SP1,
    but it's actually available on stock XP too. }
  Proc := GetProcAddress(GetModuleHandle(user32), 'DisableProcessWindowsGhosting');
  if Assigned(Proc) then
    Proc;
end;

procedure SelectMode;
{ Determines whether we should run as Setup or as the uninstaller }
var
  Mode: (smSetup, smUninstaller, smRegSvr);
  F: TFile;
  ID: Longint;
  I: Integer;
begin
  Mode := smSetup;

  for I := 1 to NewParamCount do begin
    if CompareText(NewParamStr(I), '/UNINSTMODE') = 0 then begin
      Mode := smUninstaller;
      Break;
    end;
    if CompareText(NewParamStr(I), '/REGSVRMODE') = 0 then begin
      Mode := smRegSvr;
      Break;
    end;
  end;

  if Mode = smSetup then begin
    { No mode specified on the command line; check the EXE header for one }
    F := TFile.Create(NewParamStr(0), fdOpenExisting, faRead, fsRead);
    try
      F.Seek(SetupExeModeOffset);
      F.ReadBuffer(ID, SizeOf(ID));
    finally
      F.Free;
    end;
    case ID of
      SetupExeModeUninstaller: Mode := smUninstaller;
      SetupExeModeRegSvr: Mode := smRegSvr;
    end;
  end;

  case Mode of
    smUninstaller: begin
        IsUninstaller := True;
        RunUninstaller;
        { Shouldn't get here; RunUninstaller should Halt itself }
        Halt(1);
      end;
    smRegSvr: begin
        try
          RunRegSvr;
        except
          ShowExceptionMsg;
        end;
        Halt;
      end;
  end;
end;

begin
  try
    SetErrorMode(SEM_FAILCRITICALERRORS);
    DisableWindowGhosting;
    SelectMode;
  except
    { Halt on any exception }
    ShowExceptionMsg;
    Halt(ecInitializationError);
  end;

  { Initialize.
    Note: There's no need to localize the following line since it's changed in
    InitializeSetup }
  Application.Title := 'Setup';
  { On Delphi 3+, the application window by default isn't visible until a form
    is shown. Force it visible like Delphi 2. Note that due to the way
    TApplication.UpdateVisible is coded, this should be permanent; if a form
    is shown and hidden, the application window should still be visible. }
  ShowWindow(Application.Handle, SW_SHOW);
  Application.OnException := TMainForm.ShowException;
  try
    Application.Initialize;
    InitializeSetup;
    Application.CreateForm(TMainForm, MainForm);
    MainForm.InitializeWizard;
  except
    { Halt on any exception }
    ShowExceptionMsg;
    try
      DeinitSetup(False, False);
    except
      { don't propogate any exceptions, so that Halt is always called }
      ShowExceptionMsg;
    end;
    Halt(ecInitializationError);
  end;

  { Run }
  try
    Application.Run;
  except
    { Show any exception and continue }
    ShowExceptionMsg;
  end;

  { Deinitialize (clean up) }
  try
    DeinitSetup(False, SetupExitCode = 0);
  except
    { Show any exception and continue }
    ShowExceptionMsg;
  end;

  Halt(SetupExitCode);
end.

⌨️ 快捷键说明

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