//===========================================================================
//
//  File Name:    Setup.rul
//
//  Description:  Blank setup main script file
//
//  Comments:     Blank setup is an empty setup project. If you want to
//				  create a new project via. step-by step instructions use the
//				  Project Assistant.
//
//===========================================================================

// Included header files ----------------------------------------------------
#include "ifx.h"  
#include "decl.h"   
#include "PreRequiset.rul"  
#include "featureevents.rul"
#include "setuputil.rul"  
//#include "FeatureQumranetToolsDlg.rul"     
#include "SdFinish.rul"



//---------------------------------------------------------------------------                                                                        
// OnFirstUIBefore
//
// First Install UI Sequence - Before Move Data
//
// The OnFirstUIBefore event is called by OnShowUI when the setup is
// running in first install mode. By default this event displays UI allowing
// the end user to specify installation parameters.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnFirstUIBefore()
    number  nResult, nLevel, nSize, nSetupType;
    string  szTitle, szMsg, szOpt1, szOpt2, szLicenseFile;
    string  msg,szName, szCompany, szTargetPath, szDir, szFeatures;
    BOOL    bLicenseAccepted;	
    STRING szBmpPath;  
    number ret;
begin	
   
           
   if (IsSilentMode) then
      Disable( DIALOGCACHE );
   endif;      
   
   // AmIUpgrade();   //Check If is upgrade 
   
    nSetupType = COMPLETE;	
    szDir = TARGETDIR;
    szName = "";
    szCompany = "";
    bLicenseAccepted = FALSE;

 

// Beginning of UI Sequence
Dlg_Start:
    nResult = 0;   
   if !(IsSilentMode) then 
   	 DialogSetInfo (DLG_INFO_ALTIMAGE, szBmpPath, TRUE); 
   endif;	 
Dlg_SdWelcome:
    szTitle = "";
    szMsg = "";
    //{{IS_SCRIPT_TAG(Dlg_SdWelcome)
    
    if(IsUpgrade) then
      szTitle = @WelcomeUpgradeMsg1;
      szMsg   = @WelcomeUpgradeMsg2;
    endif; 
    if !(IsSilentMode) then  
      if !(MAINTENANCE)then
    	nResult = SdWelcome( szTitle, szMsg );
    	//}}IS_SCRIPT_TAG(Dlg_SdWelcome)
    	if (nResult = BACK) goto Dlg_Start;  
      endif;	
    endif;
    szBmpPath = FULL_BMP_PATH;   
 if !(IsSilentMode) then   
    DialogSetInfo (DLG_INFO_ALTIMAGE, szBmpPath, TRUE);  
 endif;
 
Dlg_DriverStatus:   
	if !(IsSilentMode) then	    
	    // benny - old dialog 
    	//nResult = FeatureQumranetToolsDlg(); 
    	 nResult = SdFeatureTree("","",TARGETDIR,"",1);  
    	 
    	 if (nResult = BACK) goto Dlg_SdWelcome;
    	 if (FeatureIsItemSelected ( MEDIA, "Network_Driver" )= 1) then   
	    	 if !(AmIRunningFromLocalDrive()) then   
	    			MessageBox(@RUNFROMNETWORK,SEVERE);
	    			abort;
	 		 endif;
	 	 endif;	 
	else 
		//CheckFeatureTOInstallOnSilentMode();
	endif;
	//WriteToLogFile("OnFirstUIBefore FeatureQumranetTools  dialog - Select the drivers  you wish to use install" ,nResult,3);
     
Dlg_SdStartCopy2:
    WriteToLogFile("OnFirstUIBefore Dlg_SdStartCopy2 dialog" ,0,2);
    szTitle = "";
    szMsg = "";
    if !(IsSilentMode) then	
	    nResult = SdStartCopy2( szTitle, szMsg );	   
	    if (nResult = BACK) goto Dlg_DriverStatus;
    endif;
       
if !(IsSilentMode) then	  
     if !(MAINTENANCE)then  
         
		SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_FIRSTUI ) ); 
	 else
	 	SetStatusExStaticText( "The InstallShield Wizard is modifying installation" );
	 endif; 	

	SetStatusWindow(0, "");
    StatusUpdate(ON, 100); 
    Disable(CANCELBUTTON);
    SetDialogTitle ( STATUSEX, "" );
    Enable(STATUSEX); 
    Disable( DIALOGCACHE );

	//return 0;
endif; 
      
   return 0; 
 // endif; //end  isSilentMode
   
end;
//---------------------------------------------------------------------------
// OnFirstUIAfter
//
// First Install UI Sequence - After Move Data
//
// The OnFirstUIAfter event called by OnShowUI after the file transfer
// of the setup when the setup is running in first install mode. By default
// this event displays UI that informs the end user that the setup has been
// completed successfully.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnFirstUIAfter()
    STRING msg,szTitle, szMsg1, szMsg2, szOpt1, szOpt2;
    NUMBER nResult,bvOpt1, bvOpt2;
	NUMBER bShowUpdateServiceDlg;
begin  
    Disable(STATUSEX);

    Sprintf(msg," ----------------------  OnFirstUIAfter()");
	WriteToLogFile(msg,0,2);
    //UninstallFeatures();
    if !(IsSilentMode) then
    	ShowObjWizardPages(NEXT);
    	Disable (STATUSEX);     
    endif;
    szTitle = "";
    szMsg1 = ""; 
    szMsg2 = "";
    szOpt1 = "";
    szOpt2 = "";
	bvOpt1   = FALSE;
    bvOpt2   = FALSE;    

	// Set this to true if you have the update service enabled, and if you want to check for updates.
	// Note: the ISUS Starter Edition does not support checking for updates programatically.  So, 
	// only set this to true if you have at least the ISUS Professional Edition.
	bShowUpdateServiceDlg = FALSE;
    
    //{{IS_SCRIPT_TAG(Dlg_SdDinishEx)	
   // SetComponentRegisryInfo("RedHat","DriversTools","1");     //Value = 1 then Drivers_Tools is installed
    //check if any of the drivers requested reboot
    DoIneedReboot();   
    if (IsSilentMode) then  
       if ( BATCH_INSTALL ) then 
       	  nResult = System( SYS_BOOTMACHINE );
       endif;
    else
	    if ( BATCH_INSTALL ) then
	    	SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
	    else
			
			// If the update service is enabled, show finish dialog that includes
			// update check option.
			if( bShowUpdateServiceDlg && ( ENABLED_ISERVICES & SERVICE_ISUPDATE ) ) then
	   	
			if( SdFinishUpdateEx( szTitle, szMsg1, szMsg2, szOpt1, szOpt2, TRUE ) ) then
	
					// Don't check for updates in silent mode.
					if( MODE != SILENTMODE ) then
						UpdateServiceCheckForUpdates( "", FALSE );
					endif;
	
				endif;
	
			else   
			    if !(IsSilentMode) then
					SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 );
				endif;
			endif;
	
	    endif;  
	endif;    
    //}}IS_SCRIPT_TAG(Dlg_SdDinishEx)	
end;
//---------------------------------------------------------------------------
// OnBegin
//
// The OnBegin event is called directly by the framework after the setup
// initializes. Note that this event will be called AFTER "Initialization"
// events (i.e.) OnSetTARGETDIR, OnCheckMediaPassword.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnBegin()
   BOOL Skip;
   string szIsData,szMsg,szUpgrade; 
   int ret;
begin  

 // check if user is part of the administrator group - has local admin rights
 if !(Is ( USER_INADMINGROUP, szIsData )) then     
      MessageBox(@NOTADMIN,SEVERE);  
      abort;
 endif ;
 
 Init(); 
 InitGlobal();
 AmIUpgrade(); 
 WhoAmI(); 
 
 //if (!IsUpgrade) then     
 	ClearListOfDriverToInstall();
    GetListOfDriversToInstall();
 //endif; 
 
 if (IsSilentMode)then 
 
 
 endif;
 
 Skip = FALSE; 
	//if (MAINTENANCE)then
	   // Skip = TRUE; 
	   // WriteToLogFile("OnBegin : MAINTENANCE Mode",0,2); 
	//else
	   // WriteToLogFile("OnBegin : First time",0,2);   
	//endif;
		if !(IsSilentMode)then   
			SdShowMsg ( "Checking Requirements ", TRUE );
		endif;	
		ret = CheckForBiosManufacturer();
		if !(IsSilentMode)then 	
	    	SdShowMsg ( "Checking Requirements ", FALSE );	
	    endif;
	    if(!ret) then 
            if(IsUpgrade) then
            	szUpgrade = "Upgrade";
            else
                szUpgrade = "Installation";
            endif;
            Sprintf(szMsg,"%s of RHEV-Tools on the Guest should be performed only when running on RHEL 6 type Host (RHEV-H or RHEL). %s aborted.",szUpgrade,szUpgrade);
	    	WriteToLogFile(szMsg,0,4);  
	    	if !(IsSilentMode)then
	    		MessageBox(szMsg,SEVERE);  
	    	endif;	
	    	abort;
	    endif;
    ParseProductVersion();   
    
 end;
  
//---------------------------------------------------------------------------
// OnEnd
//
// The OnEnd event is called at the end of the setup. This event is not
// called if the setup is aborted.
//---------------------------------------------------------------------------
function OnEnd()
HWND hMSI;
begin 
  WriteToLogFile("OnBegin : OnEnd ",0,2);   
  CopyInstalationLogs();
  if (IsForceReboot)then 
   		 ExFn_System(hMSI);
  		   
  endif;  
  if !(gUninst) then
      ChangeDisplayName();
  endif;
  
end;
//---------------------------------------------------------------------------
// OnMaintUIAfter
//
// The OnMaintUIAfter event called by OnShowUI after the file transfer
// of the setup when the setup is running in maintenance mode. By default
// this event displays UI that informs the end user that the maintenance setup
// has been completed successfully.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnMaintUIAfter()
    STRING msg,szTitle, szMsg1, szMsg2, szOpt1, szOpt2;
    NUMBER bvOpt1, bvOpt2;
begin
    Disable(STATUSEX);
    
    if !(IsSilentMode) then
    	ShowObjWizardPages(NEXT);
    endif;
    // Added - Version 9.5 - Use appropriate strings for complete
    // uninstall.
    if( REMOVEALLMODE ) then
        szTitle = SdLoadString(IFX_SDFINISH_REMOVE_TITLE);
        szMsg1 = SdLoadString(IFX_SDFINISH_REMOVE_MSG1);
        szMsg2 = "";    
    	szOpt1 = "";
    	szOpt2 = "";
		bvOpt1   = FALSE;
    	bvOpt2   = FALSE;  
    	gUninst = TRUE;  
        BATCH_INSTALL = TRUE;
    	if ( BATCH_INSTALL ) then
    		SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
    	else    
       		SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bvOpt1 , bvOpt2 );
    	endif;
    else
        //szTitle = SdLoadString(IFX_SDFINISH_MAINT_TITLE);    
       // szMsg1  = SdLoadString(IFX_SDFINISH_MAINT_MSG1); 
       Sprintf(msg," ----------------------  OnMaintUIAfter() calling OnFirstUIAfter();");
	   WriteToLogFile(msg,0,2);  
       OnFirstUIAfter();
    endif;

	
end;
//---------------------------------------------------------------------------
// OnMaintUIBefore
//
// Maintenance UI Sequence - Before Move Data
//
// The OnMaintUIBefore event is called by OnShowUI when the setup is
// running in maintenance mode. By default this event displays UI that
// allows the end user to add or remove features, repair currently
// installed features or uninstall the application.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnMaintUIBefore()
    number	nResult, nType, nMediaFlags;
    string	szBmpPath,szTitle, szMsg, szIgnore;
begin
GetInstalledToolsList();	
	// nType defaults to MODIFY.
	nType = MODIFY;

    //Initialize SQL
    OnSQLServerInitializeMaint();
szBmpPath = FULL_BMP_PATH;   
if !(IsSilentMode) then
	DialogSetInfo (DLG_INFO_ALTIMAGE, szBmpPath, TRUE); 
endif;	
// Beginning of UI Sequence
Dlg_Start:

    // Added in Version 9.5 - Support for REMOVEONLY option.
    if( !REMOVEONLY ) then
    	// In standard mode show maintenance dialog   
    	if (IsSilentMode) then 
    	    nType =  REPAIR; 
    	    Disable( DIALOGCACHE );
    	else
		    Disable( BACKBUTTON );
		    nType = SdWelcomeMaint( szTitle, szMsg, nType );
		    Enable( BACKBUTTON );
	        nResult = NEXT;  
	    endif;    
    else
        // Hide the initial progress dialog as otherwise the user can
        // click on it, and hide the MessageBox.
        Disable( DIALOGCACHE );

        // In RemoveOnly mode, set to remove.
        nType = REMOVEALL;
    endif;

	// Show Uninstall Confirmation Dialog
    if ( nType = REMOVEALL ) then
		nResult = MessageBox( SdLoadString( IFX_MAINTUI_MSG ), MB_YESNO );
		if (nResult != IDYES ) then
            
            if( REMOVEONLY ) then
                // In REMOVEONLY mode, abort the setup.
                abort;
            else
                // In non-REMOVEONLY mode, redisplay the previous dialog.
			    goto Dlg_Start;
            endif;

		endif;
	endif;

Dlg_SdFeatureTree:
	if ( nType = MODIFY ) then
		szTitle = "";
		szMsg = SdLoadString( SD_STR_COMPONENT_MAINT_MSG );
		nResult = SdFeatureTree( szTitle, szMsg, TARGETDIR, "", -1 );
		if ( nResult = BACK ) goto Dlg_Start;
    endif;

Dlg_ObjDialogs:   
if !(IsSilentMode) then
    nResult = ShowObjWizardPages( nResult );
    if ( ( nResult = BACK ) && ( nType != MODIFY ) ) goto Dlg_Start;
    if ( ( nResult = BACK ) && ( nType = MODIFY ) ) goto Dlg_SdFeatureTree;
endif;
	switch(nType)

        case REMOVEALL:
						
			// Ensure that all previously installed features are removed
			// for media that supports updating.
			MediaGetData( MEDIA, MEDIA_FIELD_MEDIA_FLAGS, nMediaFlags, szIgnore );
			
			if( nMediaFlags & MEDIA_FLAG_UPDATEMODE_SUPPORTED ) then
				FeatureRemoveAllInMediaAndLog();
			else
				FeatureRemoveAllInMedia();
			endif;

            // Added in 11.0 - Set appropriate StatusEx static text.
            SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REMOVEALL ) );

        case REPAIR:
				
			// Changed for DevStudio 9, Disk1 files are now always updated when installed
			// so when running from ADDREMOVE we need to prevent these files from being
			// updated since this will result in files being updated that are locked by the setup.
			// Updating these files when running from ADDREMOVE should not be needed since updates
			// are not run directly from Add/Remove.
            if( ADDREMOVE ) then
                // Reinstall all previously installed features, except
                // disk1 features.
                FeatureUpdate( "" );
            else
                // Reinstall all previously installed features.
                FeatureReinstall();
            endif;

            // Added in 11.0 - Set appropriate StatusEx static text.
            SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_REPAIR ) );

        case MODIFY:
            
            // Added in 11.0 - Set appropriate StatusEx static text.
            SetStatusExStaticText( SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_MAINTUI_MODIFY ) );

    endswitch;
    
    SetStatusWindow(0, "");
    StatusUpdate(ON, 100); 
    Disable(CANCELBUTTON);
    SetDialogTitle ( STATUSEX, "" );
    Enable(STATUSEX); 
    Disable( DIALOGCACHE );

end;

//---------------------------------------------------------------------------
// OnMoveData
//
// The OnMoveData event is called by OnShowUI to initiate the file
// transfer of the setup.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnMoveData()
number	nResult, nMediaFlags;
begin

	// Don't install the DISK1COMPONENT if MAINT_OPTION_NONE was specified.
	if( MAINT_OPTION = MAINT_OPTION_NONE ) then
		FeatureSelectItem( MEDIA, DISK1COMPONENT, FALSE );
	endif;

    // Updated in 11.5, disable the cancel button during file transfer unless
	// this is non-maintenance mode or repair mode.
    if( MAINTENANCE && ( !REINSTALLMODE || UPDATEMODE ) ) then
        Disable( CANCELBUTTON );
    endif;

    // Show Status
	// Note: Start status window at 1 in case CreateInstallationInfo call
	// is lengthy. 
	if !(IsSilentMode) then	
		SetStatusWindow( 1, "" );
		Enable( STATUSEX );
		StatusUpdate( ON, 100 );
    endif;
	// Create the uninstall infomation (after displaying the progress dialog)
	// Don't create uninstall information if MAINT_OPTION_NONE was specified.
	if( MAINT_OPTION != MAINT_OPTION_NONE ) then
		CreateInstallationInfo();
	endif;

	// Move Data
	nResult = FeatureTransferData( MEDIA );
	
    // Moved in 11.0, Check for failure before creating uninstall key.
    // Handle move data error and abort if error occured.
	if( nResult < ISERR_SUCCESS ) then
		OnComponentError();
		abort;
	endif;	    

	// Update service registration (should be done BEFORE calling FeatureSaveTarget)
	if( !REMOVEALLMODE && ENABLED_ISERVICES & SERVICE_ISUPDATE ) then
		
		// Register the product using the settings specified in the Ide.
		// TODO: If you want to register the product with other settings
        // call UpdateServiceRegisterProduct etc. instead.
		UpdateServiceRegisterProductEx( TRUE );
		
		// TODO: Enable this if you want to create an update check shortcut.
		//UpdateServiceCreateShortcut( "", "", "" );

	endif;

	// Create uninstall key, if DISK1COMPONENT was installed.
	if( IFX_DISK1INSTALLED ) then

		// Store text-subs for maintenance mode later, only do this when
		// disk 1 is installed. Note that any text-subs that are updated after
        // this call will not be remembered during maintenance mode.
		FeatureSaveTarget("");

		// Write uninstall information.
		MaintenanceStart();

		// Customize Uninstall Information
		OnCustomizeUninstInfo();

	endif;
      // Disable Status
	Disable( STATUSEX );

end;
//---------------------------------------------------------------------------
// OnUpdateUIBefore
//
// Update UI Sequence - Before Move Data
//
// The OnUpdateUIBefore event is called when the setup is running in update
// mode. By default this event displays UI that allows the end user to
// update the application to the current version.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnUpdateUIBefore()
	string svVersionInstalled,szTitle, szMsg, szIgnore, szVersionInstalled, szVersionSupported, szVersionUpdate;
	number nVersionInstalled;
	number nIgnore, nId, nMediaFlags;
	number nResult;  
	number nvVersionResult,nvVersionMajor, nvVersionMinor, nvVersionBuild;
begin
    //IFX_INSTALLED_VERSION  
    
    VerProductGetInstalledVersion ( svVersionInstalled ); 
   
    VerProductStrToNum ( nvVersionResult, svVersionInstalled ); 

    VerProductVerPartsFromVer ( nvVersionResult, nvVersionMajor, nvVersionMinor, nvVersionBuild ); 

    if (nvVersionMajor = 4) then
    
        if (nvVersionMinor < 6 ) then
             CheckRestartBeforeUpgradeFlag();
        endif;
        
    endif;
	// Determine the update media type.	
	MediaGetData( MEDIA, MEDIA_FIELD_MEDIA_FLAGS, nMediaFlags, szIgnore );

	// Compare Versions
	nResult = VerProductCompareVersions();

	// Make sure that valid data was returned by VerProductCompareVersions
	if !(IsSilentMode) then
		if( nResult < ISERR_SUCCESS ) then
			szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_VERSION_COMPARE_FAILURE );
			MessageBox( szMsg, SEVERE );
			abort;
		endif;
		

	// Make sure that the product is installed.    
	
	if( nResult = VERSION_COMPARE_RESULT_NOT_INSTALLED ) then
		// Note: This result should occur only for differential media, since OnFirstUIBefore
		// will be called by default for non-differential media in this case.
		szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_PRODUCT_NOT_INSTALLED );
		SdSubstituteProductInfo( szMsg );
		MessageBox( szMsg, SEVERE );
		abort;
	endif;	

	// Check whether the update is older than the currently installed version.
	if( nResult = VERSION_COMPARE_RESULT_OLDER ) then
		szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_NOT_APPROPRIATE );
		SdSubstituteProductInfo( szMsg );
		MessageBox( szMsg, SEVERE );
		abort;
	endif;

	// Verify that this update is appropriate for the version of the application that is installed.
	if( nResult = VERSION_COMPARE_RESULT_NEWER_NOT_SUPPORTED ) then
		szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_NOT_SUPPORTED );
		SdSubstituteProductInfo( szMsg );
		MessageBox( szMsg, SEVERE );
		abort;
	endif;

	// Check whether the update is needed.
	if( nResult = VERSION_COMPARE_RESULT_SAME ) then
		// Note: This result should occur only for differential media, since the setup
		// will display OnMaintUIBefore or OnFirstUIBefore by default if the versions match
		// for full setup media.
		szMsg = SdLoadString( IDS_IFX_WARNING_UPDATE_NOT_NEEDED );
		SdSubstituteProductInfo( szMsg );
		if( MessageBox( szMsg, MB_ICONEXCLAMATION | MB_YESNO ) != IDYES ) then
			abort;
		endif;
	endif; 
	//******************************************************
    endif; // ****************** end silent if not mode 
    
    
	// Automatically select newly added features, do this before UI sequence in case so that
	// if a feature dialog is added, it reflects newly selected features.
	FeatureSelectNew( MEDIA, TRUE );

	// TODO: Enable this line if you want the update to to automatically uninstall
	// any features that are not contained in the media but are listed in the 
	// log file.
	// FeatureRemoveAllInLogOnly();

    // Ensure update service state is set as FeatureSelectNew can select the update
    // service files if ISUS is added during an update.
    UpdateServiceOnEnabledStateChange();

    //Initialize SQL
    OnSQLServerInitializeMaint();

// Beginning of UI Sequence
Dlg_Start:
if !(IsSilentMode) then
Dlg_SdWelcome:
	szTitle = "";
    szMsg = SdLoadString( IDS_IFX_SDWELCOMMESSAGE_UPDATE_WELCOME );
    nResult = SdWelcome( szTitle, szMsg );
    if (nResult = BACK) goto Dlg_Start;

Dlg_ObjDialogs:
    nResult = ShowObjWizardPages( nResult );
    if (nResult = BACK) goto Dlg_SdWelcome; 
endif;
	if( nMediaFlags & MEDIA_FLAG_FORMAT_DIFFERENTIAL ) then
		// Differential installs patch media.
		FeaturePatch();
	else
		// Update reinstalls (updates) all features in media.
		FeatureReinstall();
	endif;

    // Added in 11.0 - Set appropriate StatusEx static text.
  if !(IsSilentMode) then  
    szMsg = SdLoadString( IDS_IFX_STATUSEX_STATICTEXT_UPDATEUI );
	SdSubstituteProductInfo( szMsg );
    SetStatusExStaticText( szMsg );
  endif;
end;
//---------------------------------------------------------------------------
// OnUpdateUIAfter
//
// Update Mode UI Sequence - After Move Data
//
// The OnUpdateUIAfter event called by OnShowUI after the file transfer
// of the setup when the setup is running in update mode. By default
// this event displays UI that informs the end user that the maintenance setup
// has been completed successfully.
//
// Note: This event will not be called automatically in a
// program...endprogram style setup.
//---------------------------------------------------------------------------
function OnUpdateUIAfter()
    string	msg,szTitle, szMsg1, szMsg2, szOpt1, szOpt2;
    BOOL	bOpt1, bOpt2;
begin
    if( REMOVEALLMODE ) then
    ShowObjWizardPages(NEXT);
    
	szTitle = SdLoadString(IDS_IFX_SDFINISH_UPDATE_TITLE);    
    szMsg1  = SdLoadString(IDS_IFX_SDFINISH_UPDATE_MSG1);
	szMsg2 = "";    
    szOpt1 = "";
    szOpt2 = "";
	bOpt1   = FALSE;
    bOpt2   = FALSE;    
    
   if ( BATCH_INSTALL ) then
	    	SdFinishReboot ( szTitle , szMsg1 , SYS_BOOTMACHINE , szMsg2 , 0 );
	    else    
	       	SdFinish ( szTitle , szMsg1 , szMsg2 , szOpt1 , szOpt2 , bOpt1 , bOpt2 );
	    endif;
	else
	   Sprintf(msg," ----------------------  OnUpdateUIAfter() calling OnFirstUIAfter();");
	   WriteToLogFile(msg,0,2);  
	   IsUpgrade = TRUE;
       OnFirstUIAfter();    
    endif;
end;

//-------------------------------------------------------------------------------------------
function AmIRunningFromLocalDrive()
    _DISK_INFO di;  
    
    NUMBER n; // to do: something with function return values 

    NUMBER nResult,nvSizeTargetHigh, nvSizeTargetLow, nUnitsTarget; 

    string msg,svReturnString, szPath;
begin    

//driverInstaller.exe  find "*VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00*" 

nResult = ParsePath ( svReturnString, PACKAGE_LOCATION, DISK ); 

di.szDiskPath = svReturnString; 

di.nInfoToQuery = DISK_INFO_QUERY_DRIVE_TYPE; 


n = GetDiskInfo(&di);
//Sprintf(msg,"Drive type is  %d  .",di.nDriveType);
//MessageBox(msg,1);
switch (di.nDriveType)

case DRIVE_REMOTE:
      return 0;

endswitch;
return 1;	
end;

//---------------------------------------------------------------------------
// OnAbort
//
// The OnAbort is called when a setup is aborted via the abort keyword.
//---------------------------------------------------------------------------
function OnAbort()
begin 
	 WriteToLogFile("The installation is aborted",0,2);
	 //UninstallFeatures(); ???
end;
//---------------------------------------------------------------------------
// OnSetUpdateMode
//
// OnSetUpdateMode is called directly by the framework to set the UPDATEMODE
// InstallShield system variable appropriately to control which UI events
// are called by OnShowUI.
//
// Note: This event is called for all setups.
//---------------------------------------------------------------------------
function OnSetUpdateMode()
	number	nIgnore, nMediaFlags, nInstalledVersion, nUpdateVersion, nResult;
	string	szVersion, szIgnore, szMsg;
begin
	
	UPDATEMODE = FALSE; // Non-update mode by default.

	// Added 11.5 - Don't set UPDATEMODE when running from Add/Remove
	if( ADDREMOVE ) then
		return ISERR_SUCCESS;
	endif;

	// Added 11.5 - Don't set UPDATEMODE when REMOVEONLY is specified
	if( REMOVEONLY ) then
		return ISERR_SUCCESS;
	endif;

	// Get the media flags.
	MediaGetData( MEDIA, MEDIA_FIELD_MEDIA_FLAGS, nMediaFlags, szIgnore );

	// TODO: If you are updating an application that was installed by a previous
	// version of InstallShield, IFX_INSTALLED_VERSION will be empty, and
	// VERSION_COMPARE_RESULT_NOT_INSTALLED will be returned by
	// VerProductCompareVersions. Change the value of IFX_INSTALLED_VERSION (and
	// IFX_INSTALLED_DISPLAY_VERSION) here based on application specific version
	// information determined by the setup. Only do this if IFX_INSTALLED_VERSION
	// is empty.
	//if ( !StrLengthChars( IFX_INSTALLED_VERSION ) && MAINTENANCE ) then
	//	IFX_INSTALLED_VERSION = "X.XX.XXX";
	//	IFX_INSTALLED_DISPLAY_VERSION = IFX_INSTALLED_VERSION;
	//endif;

	// Verify that the installed version is valid.
	if( !StrLengthChars( IFX_INSTALLED_VERSION ) && MAINTENANCE ) then
		// If this error occurs, IFX_INSTALLED_VERSION needs to be set manually.
		szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_NO_INSTALLED_VERSION );
		MessageBox( szMsg, SEVERE );
		abort;
	endif;

	// Verify that the product version is valid.
	if( !StrLengthChars( IFX_PRODUCT_VERSION ) ) then
		// If this error occures, IFX_PRODUCT_VERSION was not initialized correctly.
		szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_NO_PRODUCT_VERSION );
		MessageBox( szMsg, SEVERE );
		abort;
	endif;

	// Do the version comparison.
	nResult = VerProductCompareVersions();

	// Make sure that valid data was returned by VerProductCompareVersions
	if( nResult < ISERR_SUCCESS ) then
		szMsg = SdLoadString( IDS_IFX_ERROR_UPDATE_VERSION_COMPARE_FAILURE );
		MessageBox( szMsg, SEVERE );
		abort;
	endif;

	// Set update mode if this is a differential media or the product is already installed and the versions do not match.
	UPDATEMODE = ( nMediaFlags & MEDIA_FLAG_FORMAT_DIFFERENTIAL || ( MAINTENANCE && ( nResult != VERSION_COMPARE_RESULT_SAME ) ) );

end;
