procedure SetSharedLibCountAtEnd;
// gds32 and fbclient get registered twice as shared libraries.
// This appears to be a bug in InnoSetup. It only appears to affect
// libraries the first time they are registered, and it only seems
// to affect stuff in the {sys} directory. To work around this we
// check the count before install and after install.
var

dw: cardinal;

begin

if RegQueryDWordValue(HKEY_LOCAL_MACHINE,
'SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs','C:\WINNT\System32\fbclient.dll', dw) then begin

//Look for a running version of Firebird
i:=FindWindowByClassName('FB_Disabled');
if ( i=0 ) then
i:=FindWindowByClassName('FB_Server');
if ( i<>0 ) then begin
result := false;
MsgBox('An existing Firebird Server is running. You must close the '+
'application or stop the service before continuing.', mbError, MB_OK);
end;
//Check the shared library count.
if ( result=true ) then
GetSharedLibCountAtStart;

end;

procedure DeInitializeSetup();
var

ErrCode: Integer;

begin

// Did the install fail because winsock 2 was not installed?
if Winsock2Failure then
// Ask user if they want to visit the Winsock2 update web page.
if MsgBox(sWinsock2Web, mbInformation, MB_YESNO) = idYes then
// User wants to visit the web page
InstShellExec(sMSWinsock2Update, , , SW_SHOWNORMAL, ErrCode);

// Try to find the value of "RootDirectory" in the Firebird
// registry settings. This is either where Fb 1.0 exists or Fb 1.5
InterBaseRootDir:=GetInterBaseDir;
FirebirdRootDir:=GetFirebirdDir;
if (FirebirdRootDir <> ) and ( FirebirdRootDir = InterBaseRootDir ) then //Fb 1.0 must be installed so don't overwrite it.
InstallRootDir := Default;
if (( InstallRootDir = ) and
( FirebirdRootDir = Default )) then // Fb 1.5 is already installed,
InstallRootDir := Default; // so we offer to install over it

// if we haven't found anything then try the FIREBIRD env var
// User may have preferred location for Firebird, but has possibly
// uninstalled previous version
if (InstallRootDir = ) then
InstallRootDir:=getenv('FIREBIRD');
//if no existing locations found make sure we default to the default.
if (InstallRootDir = ) then
InstallRootDir := Default;

result := false;
if ShouldProcessEntry('ServerComponent', 'UseApplicationTask')= srYes then
if ShouldProcessEntry('ServerComponent', 'UseGuardianTask')= srYes then
result := true;

end;

function InstallServerIcon(): Boolean;
begin

result := false;
if ShouldProcessEntry('ServerComponent', 'UseApplicationTask')= srYes then
if ShouldProcessEntry('ServerComponent', 'UseGuardianTask')= srNo then
result := true;

end;

function StartApp(Default: String): String;
var

AppPath: String;

begin

AppPath:=ExpandConstant('{app}');
//Now start the app as
if ShouldProcessEntry('ServerComponent', 'UseGuardianTask')= srYes then
Result := AppPath+'\bin\fbguard.exe'
else

ifdef classic_server_install

Result := AppPath+'\bin\fb_inet_server.exe';

else

Result := AppPath+'\bin\fbserver.exe';

endif

end;

procedure CurStepChanged(CurStep: Integer);
var

AppStr: String;

begin

if ( CurStep=csFinished ) then begin
//If user has chosen to install an app and run it automatically set up the registry accordingly
//so that the server or guardian starts evertime they login.
if (ShouldProcessEntry('ServerComponent', 'AutoStartTask')= srYes) and
( ShouldProcessEntry('ServerComponent', 'UseApplicationTask')= srYes ) then begin
AppStr := StartApp()+' -a';