Test events example

From ISXKB

Jump to: navigation, search

This example is a copy of an article in the old ISXKB. It logs all Setup events into the file C:\Log_IS_Events.txt. The original author is Jeff Weir.

[Setup]
OutputBaseFilename=TestEventsSetup
AppName=TestEvents
AppVerName=TestEvents V1
DefaultDirName={pf}\TestEvents
AppID=TestEevents
ShowTasksTreeLines=false
RestartIfNeededByRun=false
UserInfoPage=true
DefaultGroupName=TestEvents
InfoAfterFile=.\InfoAfterFile.txt
InfoBeforeFile=.\InfoBeforeFile.txt
LicenseFile=.\LicenseFile.txt
OutputDir=.\


[Files]
Source: Test Events.iss; DestDir: {app}


[Icons]
Name: {group}\Uninstall Test Events; Filename: {uninstallexe}
Name: {group}\Test Events; Filename: {app}\Test Events.iss; WorkingDir: {app}; Comment: Test Events; Flags: createonlyiffileexists


[_ISTool]
EnableISX=true
UseAbsolutePaths=false


[Code]
var
	mcLogFile: String;


function InitializeSetup(): Boolean;
// return False to abort Setup
begin
	mcLogFile := 'C:\Log_IS_Events.txt';
	DeleteFile( mcLogFile);
	SaveStringToFile(mcLogFile, 'In function InitializeSetup' + Chr(13), True);
	Result := True;
end;


procedure InitializeWizard();
// Use this event function to make changes to the wizard or wizard pages at startup.
// You can't use the InitializeSetup event function for this since at the time it is triggered,
// the wizard form does not yet exist.
begin
	SaveStringToFile(mcLogFile, 'In procedure InitializeWizard' + Chr(13), True);
end;


procedure DeInitializeSetup();
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In procedure DeInitializeSetup' + Chr(13), True);
end;


procedure CurStepChanged(CurStep: TSetupStep);
// return False to abort Setup
begin
	case CurStep of
		ssInstall :
		  SaveStringToFile(mcLogFile, ' : ssInstall' + Chr(13), True);
		ssPostInstall :
		  SaveStringToFile(mcLogFile, ' : ssPostInstall' + Chr(13), True);
		ssDone :
		  SaveStringToFile(mcLogFile, ' : ssDone' + Chr(13), True);
	else
		SaveStringToFile(mcLogFile, ' : no idea' + Chr(13), True);
	end;
end;


function NextButtonClick(CurPage: Integer): Boolean;
// return False to surpress the click on the Next button
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In function NextButtonClick ' + IntToStr(CurPage), True);
	case CurPage of
		wpWelcome :
		  SaveStringToFile(mcLogFile, ' : wpWelcome' + Chr(13), True);
		wpLicense :
		  SaveStringToFile(mcLogFile, ' : wpLicense' + Chr(13), True);
		wpPassword :
		  SaveStringToFile(mcLogFile, ' : wpPassword' + Chr(13), True);
		wpInfoBefore :
		  SaveStringToFile(mcLogFile, ' : wpInfoBefore' + Chr(13), True);
		wpUserInfo :
		  SaveStringToFile(mcLogFile, ' : wpUserInfo' + Chr(13), True);
		wpSelectDir :
		  SaveStringToFile(mcLogFile, ' : wpSelectDir' + Chr(13), True);
		wpSelectComponents :
		  SaveStringToFile(mcLogFile, ' : wpSelectComponents' + Chr(13), True);
		wpSelectProgramGroup :
		  SaveStringToFile(mcLogFile, ' : wpSelectProgramGroup' + Chr(13), True);
		wpSelectTasks :
		  SaveStringToFile(mcLogFile, ' : wpSelectTasks' + Chr(13), True);
		wpReady :
		  SaveStringToFile(mcLogFile, ' : wpReady' + Chr(13), True);
		wpPreparing :
		  SaveStringToFile(mcLogFile, ' : wpPreparing' + Chr(13), True);
		wpInstalling :
		  SaveStringToFile(mcLogFile, ' : wpInstalling' + Chr(13), True);
		wpInfoAfter :
		  SaveStringToFile(mcLogFile, ' : wpInfoAfter' + Chr(13), True);
		wpFinished :
		  SaveStringToFile(mcLogFile, ' : wpFinished' + Chr(13), True);
	else
		SaveStringToFile(mcLogFile, ' : no idea' + Chr(13), True);
	end;
	Result := True;
end;


function BackButtonClick(CurPage: Integer): Boolean;
// return False to surpress the click on the Back button
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In function BackButtonClick ' + IntToStr(CurPage), True);
	case CurPage of
		wpWelcome :
		  SaveStringToFile(mcLogFile, ' : wpWelcome' + Chr(13), True);
		wpLicense :
		  SaveStringToFile(mcLogFile, ' : wpLicense' + Chr(13), True);
		wpPassword :
		  SaveStringToFile(mcLogFile, ' : wpPassword' + Chr(13), True);
		wpInfoBefore :
		  SaveStringToFile(mcLogFile, ' : wpInfoBefore' + Chr(13), True);
		wpUserInfo :
		  SaveStringToFile(mcLogFile, ' : wpUserInfo' + Chr(13), True);
		wpSelectDir :
		  SaveStringToFile(mcLogFile, ' : wpSelectDir' + Chr(13), True);
		wpSelectComponents :
		  SaveStringToFile(mcLogFile, ' : wpSelectComponents' + Chr(13), True);
		wpSelectProgramGroup :
		  SaveStringToFile(mcLogFile, ' : wpSelectProgramGroup' + Chr(13), True);
		wpSelectTasks :
		  SaveStringToFile(mcLogFile, ' : wpSelectTasks' + Chr(13), True);
		wpReady :
		  SaveStringToFile(mcLogFile, ' : wpReady' + Chr(13), True);
		wpPreparing :
		  SaveStringToFile(mcLogFile, ' : wpPreparing' + Chr(13), True);
		wpInstalling :
		  SaveStringToFile(mcLogFile, ' : wpInstalling' + Chr(13), True);
		wpInfoAfter :
		  SaveStringToFile(mcLogFile, ' : wpInfoAfter' + Chr(13), True);
		wpFinished :
		  SaveStringToFile(mcLogFile, ' : wpFinished' + Chr(13), True);
	else
		SaveStringToFile(mcLogFile, ' : no idea' + Chr(13), True);
	end;
	Result := True;
end;


function ShouldSkipPage(CurPage: Integer): Boolean;
// return True to skip the CurPage page
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In function SkipCurPage ' + IntToStr(CurPage), True);
	case CurPage of
		wpWelcome :
		  SaveStringToFile(mcLogFile, ' : wpWelcome' + Chr(13), True);
		wpLicense :
		  SaveStringToFile(mcLogFile, ' : wpLicense' + Chr(13), True);
		wpPassword :
		  SaveStringToFile(mcLogFile, ' : wpPassword' + Chr(13), True);
		wpInfoBefore :
		  SaveStringToFile(mcLogFile, ' : wpInfoBefore' + Chr(13), True);
		wpUserInfo :
		  SaveStringToFile(mcLogFile, ' : wpUserInfo' + Chr(13), True);
		wpSelectDir :
		  SaveStringToFile(mcLogFile, ' : wpSelectDir' + Chr(13), True);
		wpSelectComponents :
		  SaveStringToFile(mcLogFile, ' : wpSelectComponents' + Chr(13), True);
		wpSelectProgramGroup :
		  SaveStringToFile(mcLogFile, ' : wpSelectProgramGroup' + Chr(13), True);
		wpSelectTasks :
		  SaveStringToFile(mcLogFile, ' : wpSelectTasks' + Chr(13), True);
		wpReady :
		  SaveStringToFile(mcLogFile, ' : wpReady' + Chr(13), True);
		wpPreparing :
		  SaveStringToFile(mcLogFile, ' : wpPreparing' + Chr(13), True);
		wpInstalling :
		  SaveStringToFile(mcLogFile, ' : wpInstalling' + Chr(13), True);
		wpInfoAfter :
		  SaveStringToFile(mcLogFile, ' : wpInfoAfter' + Chr(13), True);
		wpFinished :
		  SaveStringToFile(mcLogFile, ' : wpFinished' + Chr(13), True);
	else
		SaveStringToFile(mcLogFile, ' : no idea' + Chr(13), True);
	end;
	Result := False;
end;


procedure CurPageChanged(CurPage: Integer);
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In procedure CurPageChanged ' + IntToStr(CurPage), True);
	case CurPage of
		wpWelcome :
		  SaveStringToFile(mcLogFile, ' : wpWelcome' + Chr(13), True);
		wpLicense :
		  SaveStringToFile(mcLogFile, ' : wpLicense' + Chr(13), True);
		wpPassword :
		  SaveStringToFile(mcLogFile, ' : wpPassword' + Chr(13), True);
		wpInfoBefore :
		  SaveStringToFile(mcLogFile, ' : wpInfoBefore' + Chr(13), True);
		wpUserInfo :
		  SaveStringToFile(mcLogFile, ' : wpUserInfo' + Chr(13), True);
		wpSelectDir :
		  SaveStringToFile(mcLogFile, ' : wpSelectDir' + Chr(13), True);
		wpSelectComponents :
		  SaveStringToFile(mcLogFile, ' : wpSelectComponents' + Chr(13), True);
		wpSelectProgramGroup :
		  SaveStringToFile(mcLogFile, ' : wpSelectProgramGroup' + Chr(13), True);
		wpSelectTasks :
		  SaveStringToFile(mcLogFile, ' : wpSelectTasks' + Chr(13), True);
		wpReady :
		  SaveStringToFile(mcLogFile, ' : wpReady' + Chr(13), True);
		wpPreparing :
		  SaveStringToFile(mcLogFile, ' : wpPreparing' + Chr(13), True);
		wpInstalling :
		  SaveStringToFile(mcLogFile, ' : wpInstalling' + Chr(13), True);
		wpInfoAfter :
		  SaveStringToFile(mcLogFile, ' : wpInfoAfter' + Chr(13), True);
		wpFinished :
		  SaveStringToFile(mcLogFile, ' : wpFinished' + Chr(13), True);
	else
		SaveStringToFile(mcLogFile, ' : no idea' + Chr(13), True);
	end;
end;


function CheckPassword(Password: String): Boolean;
// If Setup finds the CheckPassword event function in the Pascal script, it automatically
// displays the Password page and calls CheckPassword to check passwords.
// Return True to accept the password and False to reject it.
// When using a password, it's important to keep in mind that since no encryption is used and
// the source code to Inno Setup is freely available, it would not be too difficult for an experienced
// individual to remove the password protection from an installation.
// Use this only as a 'deterrent' to keep unauthorized people out of your installations.
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In function CheckPassword ' + Password + Chr(13), True);
	Result := True;
end;


function NeedRestart(): Boolean;
// return True to instruct Setup to prompt the user to restart the system at the end of a successful installation.
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In function NeedRestart' + Chr(13), True);
	Result := False;
end;


function UpdateReadyMemo(Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo, MemoGroupInfo, MemoTasksInfo: String): String;
// If Setup finds the UpdateReadyMemo event function in the Pascal script, it is called automatically
//  when the Ready to Install wizard page becomes the active page.
// It should return the text to be displayed in the settings memo on the Ready to Install wizard page
// as a single string with lines separated by the NewLine parameter.
// Parameter Space contains a string with spaces. Setup uses this string to indent settings.
// The other parameters contain the (possibly empty) strings that Setup would have used as the setting sections.
// The MemoDirInfo parameter for example contains the string for the Selected Directory section.
// return False to abort Setup
var
	cTemp: String;
begin
	SaveStringToFile(mcLogFile, 'In function UpdateReadyMemo' + Chr(13), True);
	cTemp := MemoUserInfoInfo + NewLine;
	cTemp := cTemp + MemoDirInfo + NewLine;
	cTemp := cTemp + MemoTypeInfo + NewLine;
	cTemp := cTemp + MemoComponentsInfo + NewLine;
	cTemp := cTemp + MemoGroupInfo + NewLine;
	cTemp := cTemp + MemoTasksInfo + NewLine;
	Result := cTemp;
end;


procedure RegisterPreviousData(PreviousDataKey: Integer);
// To store user settings entered on custom wizard pages, place a RegisterPreviousData event function
// in the Pascal script and call SetPreviousData(PreviousDataKey, ...) inside it, once per setting.
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In procedure PreviousDataKey' + Chr(13), True);
end;


function CheckSerial(Serial: String): Boolean;
// If Setup finds the CheckSerial event function in the Pascal script, a serial number field
// with automatically appear on the User Info wizard page (which must be enabled using
// UserInfoPage=yes in your [Setup] section!).
// Return True to accept the serial number and False to reject it.
// When using serial numbers, it's important to keep in mind that since no encryption is used and
// the source code to Inno Setup is freely available, it would not be too difficult for an
// experienced individual to remove the serial number protection from an installation.
// Use this only as a convienience to the end user and double check the entered serial number
// (stored in the {userinfoserial} constant) in your application.
// return False to abort Setup
begin
	SaveStringToFile(mcLogFile, 'In function CheckSerial ' + Serial + Chr(13), True);
	Result := True;
end;


// Here's the list of constants used by these functions:

// CurStep values
// ssInstall, ssPostInstall, ssDone

// CurPage values
// wpWelcome, wpLicense, wpPassword, wpInfoBefore, wpUserInfo, wpSelectDir,
// wpSelectComponents, wpSelectProgramGroup, wpSelectTasks, wpReady, wpPreparing,
// wpInstalling, wpInfoAfter, wpFinished

// None of these functions are required to be present in a Pascal script.

// SkipCurPage isn't called if Setup already determined that the page should be skipped or
// for the Welcome page or for the Installing page.

See Also

Test events example including Uninstall events

Personal tools
Ads: