unit MainInfo;

interface

uses
  SysUtils, Classes, Struct, FileClass;

type
  TEntryType = (seLanguage, sePermission, seType, seComponent, seTask, seDir, seKeySig,
    seFile, seFileLocation, seIcon, seIni, seRegistry, seInstallDelete,
    seUninstallDelete, seRun, seUninstallRun, seCustomMessage);

  TMainInfo = class
  private // From Main.pas
    fWizardImages: TStringList;
    fWizardSmallImages: TStringList;
  public // From Main.pas
    SetupLdrOffset0: Int64;
    SetupLdrOffset1: Int64;
    SetupLdrMode: Boolean;
    SetupLdrOriginalFilename: String;
    Entries: array[TEntryType] of TList;
    SetupHeader: TSetupHeader;
    SetupEncryptionHeader: TSetupEncryptionHeader;
    TimeStampsInUTC: Boolean;
    SetUpMinVersion: TSetupVersionData;
    StdOutputHandle: THandle;
    DecompDll: AnsiString;
    property WizardImages: TStringList read fWizardImages;
    property WizardSmallImages: TStringList read fWizardSmallImages;
  public // From Main.pas
    Ver: integer;
    VerIsUnicode: boolean;
    VerIsRT: boolean; // For ResTools custom versions
    VerIsISX: boolean;
  public // From Extract4000.pas
    SourceF: TFile;
    DestF: TFile;
    SourceFOpen: boolean;
  private
    procedure ClearSetupEncryptionHeader;
    procedure ClearSetupHeader;
    procedure ClearEntries;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Clear;
  end;

implementation

uses
  MyTypes;

{ TMainInfo }

procedure TMainInfo.Clear;
begin
  ClearSetupEncryptionHeader;
  ClearSetupHeader;
  ClearEntries;
  SetupLdrMode := True;
  SetupLdrOffset0 := 0;
  SetupLdrOffset1 := 0;
  SetupLdrMode := False;
  SetupLdrOriginalFilename := '';
  FillChar(SetupHeader, Sizeof(SetupHeader), 0);
  FillChar(SetupEncryptionHeader, Sizeof(TSetupEncryptionHeader), 0);
  TimeStampsInUTC := False;
  FillChar(SetUpMinVersion, Sizeof(SetUpMinVersion), 0);
  //StdOutputHandle
  DecompDll := '';
  WizardImages.Clear;
  WizardSmallImages.Clear;
  Ver := 0;
  VerIsUnicode := False;
  VerIsRT := False;
  VerIsISX := False;
  FreeAndNil(SourceF);
  FreeAndNil(DestF);
  SourceFOpen := False;
end;

procedure TMainInfo.ClearEntries;

  procedure ClearLanguageEntry(var Info: TSetupLanguageEntry);
    begin
      Info.Name := '';
      Info.LanguageName := '';
      Info.DialogFontName := '';
      Info.TitleFontName := '';
      Info.WelcomeFontName := '';
      Info.CopyrightFontName := '';
      Info.Data := '';
      Info.LicenseText := '';
      Info.InfoBeforeText := '';
      Info.InfoAfterText := '';
    end;
  procedure ClearTypeEntry(var Info: TSetupTypeEntry);
    begin
      Info.Name := '';
      Info.Description := '';
      Info.Languages := '';
      Info.Check := '';
    end;
  procedure ClearComponentEntry(var Info: TSetupComponentEntry);
    begin
      Info.Name := '';
      Info.Description := '';
      Info.Types := '';
      Info.Languages := '';
      Info.Check := '';
    end;
  procedure ClearTaskEntry(var Info: TSetupTaskEntry);
    begin
      Info.Name := '';
      Info.Description := '';
      Info.GroupDescription := '';
      Info.Components := '';
      Info.Languages := '';
      Info.Check := '';
    end;
  procedure ClearDirEntry(var Info: TSetupDirEntry);
    begin
      Info.DirName := '';
      Info.Components := '';
      Info.Tasks := '';
      Info.Languages := '';
      Info.Check := '';
      Info.AfterInstall := '';
      Info.BeforeInstall := '';
    end;
  procedure ClearFileEntry(var Info: TSetupFileEntry);
    begin
      Info.SourceFilename := '';
      Info.DestName := '';
      Info.InstallFontName := '';
      Info.StrongAssemblyName := '';
      Info.Components := '';
      Info.Tasks := '';
      Info.Languages := '';
      Info.Check := '';
      Info.AfterInstall := '';
      Info.BeforeInstall := '';
      Info.DestDir := '';
    end;
  procedure ClearFileLocationEntry(var Info: TSetupFileLocationEntry);
    begin
      Info.Contents := '';
    end;
  procedure ClearKeySigEntry(var Info: TSetupISSigKeyEntry);
    begin
      Info.PublicX := '';
      Info.PublicY := '';
      Info.RuntimeID := '';
    end;
  procedure ClearIconEntry(var Info: TSetupIconEntry);
    begin
      Info.IconName := '';
      Info.Filename := '';
      Info.Parameters := '';
      Info.WorkingDir := '';
      Info.IconFilename := '';
      Info.Comment := '';
      Info.Components := '';
      Info.Tasks := '';
      Info.Languages := '';
      Info.Check := '';
      Info.AfterInstall := '';
      Info.BeforeInstall := '';
    end;
  procedure ClearIniEntry(var Info: TSetupIniEntry);
    begin
      Info.Filename := '';
      Info.Section := '';
      Info.Entry := '';
      Info.Value := '';
      Info.Components := '';
      Info.Tasks := '';
      Info.Languages := '';
      Info.Check := '';
      Info.AfterInstall := '';
      Info.BeforeInstall := '';
    end;
  procedure ClearRegistryEntry(var Info: TSetupRegistryEntry);
    begin
      Info.Subkey := '';
      Info.ValueName := '';
      Info.ValueData := '';
      Info.Components := '';
      Info.Tasks := '';
      Info.Languages := '';
      Info.Check := '';
      Info.AfterInstall := '';
      Info.BeforeInstall := '';
    end;
  procedure ClearRunEntry(var Info: TSetupRunEntry);
    begin
      Info.Name := '';
      Info.Parameters := '';
      Info.WorkingDir := '';
      Info.RunOnceId := '';
      Info.StatusMsg := '';
      Info.Verb := '';
      Info.Description := '';
      Info.Components := '';
      Info.Tasks := '';
      Info.Languages := '';
      Info.Check := '';
      Info.AfterInstall := '';
      Info.BeforeInstall := '';
    end;
  procedure ClearDeleteEntry(var Info: TSetupDeleteEntry);
    begin
      Info.Name := '';
      Info.Components := '';
      Info.Tasks := '';
      Info.Languages := '';
      Info.Check := '';
      Info.AfterInstall := '';
      Info.BeforeInstall := '';
    end;
  procedure ClearCustomMessageEntry(var Info: TSetupCustomMessageEntry);
    begin
      Info.Name := '';
      Info.Value := '';
    end;

var
  Entry: TEntryType;
  i: integer;
begin
  for i := 0 to Pred(Entries[seLanguage].Count) do ClearLanguageEntry(TSetupLanguageEntry(Pointer(Entries[seLanguage][i])^));
  //for i := 0 to Pred(Entries[sePermission].Count) do ClearPermissionEntry(TSetupPermissionEntry(Pointer(Entries[sePermission][i])^));
  for i := 0 to Pred(Entries[seType].Count) do ClearTypeEntry(TSetupTypeEntry(Pointer(Entries[seType][i])^));
  for i := 0 to Pred(Entries[seComponent].Count) do ClearComponentEntry(TSetupComponentEntry(Pointer(Entries[seComponent][i])^));
  for i := 0 to Pred(Entries[seTask].Count) do ClearTaskEntry(TSetupTaskEntry(Pointer(Entries[seTask][i])^));
  for i := 0 to Pred(Entries[seDir].Count) do ClearDirEntry(TSetupDirEntry(Pointer(Entries[seDir][i])^));
  for i := 0 to Pred(Entries[seFile].Count) do ClearFileEntry(TSetupFileEntry(Pointer(Entries[seFile][i])^));
  for i := 0 to Pred(Entries[seFileLocation].Count) do ClearFileLocationEntry(TSetupFileLocationEntry(Pointer(Entries[seFileLocation][i])^));
  for i := 0 to Pred(Entries[seKeySig].Count) do ClearKeySigEntry(TSetupISSigKeyEntry(Pointer(Entries[seKeySig][i])^));
  for i := 0 to Pred(Entries[seIcon].Count) do ClearIconEntry(TSetupIconEntry(Pointer(Entries[seIcon][i])^));
  for i := 0 to Pred(Entries[seIni].Count) do ClearIniEntry(TSetupIniEntry(Pointer(Entries[seIni][i])^));
  for i := 0 to Pred(Entries[seRegistry].Count) do ClearRegistryEntry(TSetupRegistryEntry(Pointer(Entries[seRegistry][i])^));
  for i := 0 to Pred(Entries[seInstallDelete].Count) do ClearDeleteEntry(TSetupDeleteEntry(Pointer(Entries[seInstallDelete][i])^));
  for i := 0 to Pred(Entries[seUninstallDelete].Count) do ClearDeleteEntry(TSetupDeleteEntry(Pointer(Entries[seUninstallDelete][i])^));
  for i := 0 to Pred(Entries[seRun].Count) do ClearRunEntry(TSetupRunEntry(Pointer(Entries[seRun][i])^));
  for i := 0 to Pred(Entries[seUninstallRun].Count) do ClearRunEntry(TSetupRunEntry(Pointer(Entries[seUninstallRun][i])^));
  for i := 0 to Pred(Entries[seCustomMessage].Count) do ClearCustomMessageEntry(TSetupCustomMessageEntry(Pointer(Entries[seCustomMessage][i])^));
  for Entry := Low(Entries) to High(Entries) do begin
    for i := 0 to Pred(Entries[Entry].Count) do
      FreeMem(Entries[Entry][i]);
    Entries[Entry].Clear;
  end;
end;

procedure TMainInfo.ClearSetupEncryptionHeader;
begin
  // Nothing to do, there are no strings in the header
end;

procedure TMainInfo.ClearSetupHeader;
begin
  // This is done to remove memory leaks in headers
  SetupHeader.AppName := '';
  SetupHeader.AppVerName := '';
  SetupHeader.AppId := '';
  SetupHeader.AppCopyright := '';
  SetupHeader.AppPublisher := '';
  SetupHeader.AppPublisherURL := '';
  SetupHeader.AppSupportURL := '';
  SetupHeader.AppUpdatesURL := '';
  SetupHeader.AppVersion := '';
  SetupHeader.DefaultDirName := '';
  SetupHeader.DefaultGroupName := '';
  SetupHeader.BaseFileName := '';
  SetupHeader.UninstallFilesDir := '';
  SetupHeader.UninstallDisplayName := '';
  SetupHeader.UninstallDisplayIcon := '';
  SetupHeader.AppMutex := '';
  SetupHeader.AppReadmeFile := '';
  SetupHeader.AppContact := '';
  SetupHeader.AppComments := '';
  SetupHeader.AppModifyPath := '';
  SetupHeader.CreateUninstallRegKey := '';
  SetupHeader.Uninstallable := '';
  SetupHeader.LicenseText := '';
  SetupHeader.InfoBeforeText := '';
  SetupHeader.InfoAfterText := '';
  SetupHeader.CompiledCodeText := '';
  FillChar(SetupHeader, Sizeof(SetupHeader), 0);
end;

constructor TMainInfo.Create;
var
  Entry: TEntryType;
begin
  inherited Create;
  fWizardImages := TStringList.Create;
  fWizardSmallImages := TStringList.Create;
  for Entry := Low(Entries) to High(Entries) do
    Entries[Entry] := TList.Create;
  Clear;
end;

destructor TMainInfo.Destroy;
var
  Entry: TEntryType;
begin
  Clear;
  FreeAndNil(fWizardImages);
  FreeAndNil(fWizardSmallImages);
  for Entry := Low(Entries) to High(Entries) do
    FreeAndNil(Entries[Entry]);
  inherited;
end;

end.
