[App.Init]
RunSection(PreLoadCheck);
SetVariable(cgfVar_WUInstKEY,%CustomInstallKey%\%Modelcode%);

[Main.Init]
SetVariable(cgfvar_App4R_NotInstall,false);
SetVariable(cgfVar_OSRequireRunOnce,true);
if CheckOS(9x)
{
	WriteToScript(Install.warsaw,0);
}
#Check if a reboot is necessary after installing the printer. DevInstall sets a reboot registry to notify the need of reboot.
if RegExists(HKLM,%Install_Reg%\%OEM% %ModelName%,Reboot,cgfVar_RebootValue)
{
	if CheckVariable(cgfVar_RebootValue,eq,1)
	{
		#A reboot is necessary. 
		#1.Create registry to run appinst again after reboot.
		if CheckVariable(App4R,eq,true)
		{
			if CheckOS(x64)
			{
				SetVariable(cgfVar_InstCall,$CD_ROOT_DIR$\Install\x64\instgui.exe /d /I:..\app4r.isf /L:%IS_LANG% /R:appinst);
			} else
			{
				SetVariable(cgfVar_InstCall,$CD_ROOT_DIR$\Install\x86\instgui.exe /d /I:..\app4r.isf /L:%IS_LANG% /R:appinst);
			}
		} else
		{
			if CheckOS(x64)
			{
				SetVariable(cgfVar_InstCall,$CD_ROOT_DIR$\Install\x64\instgui.exe /d /I:..\appinst.isf /L:%IS_LANG% /R:appinst);
			} else
			{
				SetVariable(cgfVar_InstCall,$CD_ROOT_DIR$\Install\x86\instgui.exe /d /I:..\appinst.isf /L:%IS_LANG% /R:appinst);
			}
		}
		RunInstallAction(cgfVar_RunOnce,RegistryEntry,Add,HKLM,Software\Microsoft\Windows\CurrentVersion\RunOnce,%OEM% %ModelName%,STR,!cgfVar_InstCall);
		#2. Delete the reboot registry.
		RunInstallAction(cgfVar_RegActionReturn,RegistryEntry,Delete,HKLM,%Install_Reg%\%OEM% %ModelName%,Reboot);
		#3. Display the correct dialog.
		ChangeWindow(InstallationComplete,mainSplitter.top);
	} else
	{
		ChangeWindow(LanguageMismatch,mainSplitter.top);
		ChangeWindow(Navigation,mainSplitter.bottom,capture);
		if CheckOS(9X)
		{
			RunSection(CheckMismatch);
		} else
		{
			if CheckVariable(cgfVar_ShowLicenseValue,eq,1)
			{
				ChangeWindow(License,mainSplitter.top);
			} else
			{
				RunSection(CheckMismatch);
			}
		}
	}
} else
{
	ChangeWindow(LanguageMismatch,mainSplitter.top);
	ChangeWindow(Navigation,mainSplitter.bottom,capture);
	if CheckOS(9X)
	{
		RunSection(CheckMismatch);
	} else
	{
		if CheckVariable(cgfVar_ShowLicenseValue,eq,1)
		{
			ChangeWindow(License,mainSplitter.top);
		} else
		{
			RunSection(CheckMismatch);
		}
	}
}

####################
# Navigation Dialog
####################
[Navigation.Init]
ShowWindow(Back,false);
ShowWindow(Continue,false);
ShowWindow(Exit,false);
ShowWindow(BigExit,false);
if CheckOS(9X)
{
	ShowWindow(Cancel,true);
	ShowWindow(Install,true);
	ShowWindow(Done,false);
	ShowWindow(Agree,false);
	ShowWindow(Disagree,false);
	SetFocus(Install);
}

[Navigation.Install.ButtonClick]
RunSection(App4R_2kInstall);
WriteGridLangToScript(LanguageGrid);
HideMainFrame();
StartInstall(ProgressScreen,ProgressBar,ProgressText,,,ComponentProgressBar);
RunSection(RemoveWUInstallRegKEY);
ExitApp(noPrompt);
if CheckVariable(cgfVar_bewTasks,eq,TRUE)
{
	if CheckOS(9x)
	{
		RunProgram($CD_ROOT_DIR$\Install\x86\instgui.exe,NOWAIT,/L:%IS_LANG% /R:bewTasks);
	} else if CheckOS(x64)
	{
		RunProgram($CD_ROOT_DIR$\Install\x64\instgui.exe,NOWAIT,!bewTasksParms);
	} else
	{
		RunProgram($CD_ROOT_DIR$\Install\x86\instgui.exe,NOWAIT,!bewTasksParms);
	}
}

[Navigation.Continue.ButtonClick]
RunSection(CheckMismatch);

[Navigation.Exit.ButtonClick]
RunSection(Navigation.Disagree.ButtonClick);

[Navigation.Cancel.ButtonClick]
ExitApp(NoPrompt);

[Navigation.Done.ButtonClick]
RunSection(RemoveWUInstallRegKEY);
if CheckValue(RebootYes,eq,true)
{
	ExitApp(noPrompt,reboot);
} else
{
	ExitApp(NoPrompt);
}

[Navigation.Agree.ButtonClick]
RunSection(CheckOSRequirement);
if CheckOS(XP|VISTA|X64)
{
	ChangeWindow(FirewallException,mainSplitter.top);
} else
{
	RunSection(CheckMismatch);
}

[Navigation.Disagree.ButtonClick]
ExitApp(NoPrompt);
if CheckOS(x64)
{
	RunProgram($CD_ROOT_DIR$\Install\x64\uninst.exe,NOWAIT,/L:%IS_LANG% /R:Uninst SkipConfirm=true);
} else
{
	RunProgram($CD_ROOT_DIR$\Install\x86\uninst.exe,NOWAIT,/L:%IS_LANG% /R:Uninst SkipConfirm=true);
}


###########################
# FirewallException Dialog
###########################
[FirewallException.Init]
ShowWindow(Agree,false);
ShowWindow(Disagree,false);
ShowWindow(Exit,true);
ShowWindow(Continue,true);
ShowWindow(FWAppsList,false);
ShowWindow(AddInfo,false);

SetVariable(cgfVar_IsNull,#:0:FWAppsList);
TimerCheck(Start,true,100,RunSection,CheckForFirewallApps,cgfvar_FWListDelay);

[FirewallException.AddInfo.ButtonClick]
RunProgram($WINDOWS_DIR$\hh.exe,NOWAIT,$CD_ROOT_DIR$\Pubs\%LANG%\%MODELCODE%user.chm);

#######################
# LanguageMismatch
#######################
[LanguageMismatch.EnableControls]
ShowWindow(Cancel,true);
ShowWindow(Install,true);
ShowWindow(Done,false);
ShowWindow(Agree,false);
ShowWindow(Disagree,false);
ShowWindow(Continue,false);
SetFocus(Install);

#######################
# InstallationComplete
#######################
[InstallationComplete.Init]
ShowWindow(Install,false);
ShowWindow(Cancel,false);
ShowWindow(Agree,false);
ShowWindow(Disagree,false);
ShowWindow(Done,true);
SetFocus(Done);
SetValue(RebootYes,true);
SetValue(InstallCompleteInfo,%INSTALL_COMPLETE_INFO_REBOOT%);

###########
# License
###########
[License.Init]
ShowWindow(Cancel,false);
ShowWindow(Install,false);
ShowWindow(Done,false);
ShowWindow(Agree,true);
ShowWindow(Disagree,true);
SetFocus(Agree);

########################
# OSRequirements
########################
[OSRequirements.Init]
SetVariable(cgfvar_App4Roption,Exit);
SetValue(RB_OSReqExit_XP,true);

ShowWindow(Back,false);
ShowWindow(Cancel,true);
ShowWindow(Exit,false);
#ShowWindow(ExitBig,true);
ShowWindow(Continue,true);

[OSRequirements.RB_OSReqExit_XP.RadioSelect]
SetVariable(cgfvar_App4Roption,Exit);
#ShowWindow(Continue,false);
#ShowWindow(BigExit,true);

[OSRequirements.RB_OSReqContinue.RadioSelect]
SetVariable(cgfvar_App4Roption,Continue);
#SetVariable(cgfvar_App4R_NotInstall,true);
#ShowWindow(Continue,true);
#ShowWindow(BigExit,false);

#############################
# ProgressScreen PopupDialog
#############################
[ProgressScreen.Init]
if CheckOS(9X)
{
	ShowWindow(ProgressAVI,false);
}
ShowWindow(Install,false);

###################
# GoTo Section
###################
[CheckMismatch]
# If our language mismatch grid has nothing in it go ahead and start the install.
if CheckSize(LanguageGrid,eq,0)
{
	HideMainFrame();
	# Check if Warsaw COMs Server was installed.
	if RegExists(HKLM,%Install_Reg%\LCS\Local\%ModelCode%\runtime)
	{
		SetVariable(cgfVar_WarsawInstalled,true);
	}
	RunSection(App4R_2kInstall);
	StartInstall(ProgressScreen,ProgressBar,ProgressText,,,ComponentProgressBar);
	RunSection(RemoveWUInstallRegKEY);
	if CheckOS(NT_VISTA)
	{
		if CheckVariable(cgfVar_WarsawInstalled,eq,false)
		{
			RunProgram($SYSTEM_DIR$\%ModelCode%coms.exe,WAIT,-install);
			RunProgram($SYSTEM_DIR$\%ModelCode%coms.exe,WAIT,-addmonitor);
		}
	}
	ExitApp(noPrompt);
	if CheckVariable(cgfVar_bewTasks,eq,TRUE)
	{
		if CheckOS(9x)
		{
			RunProgram($CD_ROOT_DIR$\Install\x86\instgui.exe,NOWAIT,/L:%IS_LANG% /R:bewTasks);
		} else if CheckOS(x64)
		{
			RunProgram($CD_ROOT_DIR$\Install\x64\instgui.exe,NOWAIT,!bewTasksParms);
		} else
		{
			RunProgram($CD_ROOT_DIR$\Install\x86\instgui.exe,NOWAIT,!bewTasksParms);
		}
	}
} else
{
	# This is a refresh technique. ChangeWindow will not replace an old window if its the
	# same as the new window.
	ChangeWindow(License,mainSplitter.top);
	ChangeWindow(LanguageMismatch,mainSplitter.top);
}


[PreLoadCheck]
#This is a check for PreLoad path.
if DoesFileExists($SYSTEM_DIR$\%MODELCODE%PLC.ini)
{
	SetVariable(InstallPath,PreLoad);
	#Read a few keys from this file.
	#(1) - ShowLicense
	if IniSectionKeyExists($SYSTEM_DIR$\%MODELCODE%PLC.ini,OPTIONS,ShowLicence,cgfVar_ShowLicenseValue)
	{
	} else
	{
		SetVariable(cgfVar_ShowLicenseValue,1);
	}
	#(2) - PostInstallDialog
	if IniSectionKeyExists($SYSTEM_DIR$\%MODELCODE%PLC.ini,OPTIONS,PostInstallDialogs,cgfVar_PostInstDlgValue)
	{
	} else
	{
		SetVariable(cgfVar_PostInstDlgValue,1);
	}
	#(3) - PrinterSharingInfo
	if IniSectionKeyExists($SYSTEM_DIR$\%MODELCODE%PLC.ini,OPTIONS,PrinterSharingInfo,cgfVar_PtrSharInfoValue)
	{
	} else
	{
		if CheckVariable(NewPreloadSpec,eq,true)
		{
			SetVariable(cgfVar_PtrSharInfoValue,1);
		} else
		{
			SetVariable(cgfVar_PtrSharInfoValue,2);
		}
	}
	#(4) - ShowOneWeekRegistrationReminder
	if IniSectionKeyExists($SYSTEM_DIR$\%MODELCODE%PLC.ini,OPTIONS,ShowOneWeekRegistrationReminder,cgfVar_RegReminderValue)
	{
	} else
	{
		SetVariable(cgfVar_RegReminderValue,1);
	}

	RunSection(FixDefaultPreloadParameters);
	RunSection(CheckPreloadParameters);
	RunSection(CheckAdditionalApps);
} else
{
	SetVariable(cgfVar_bewTasks,TRUE);
	SetVariable(InstallPath,Local);
	SetVariable(cgfVar_ShowLicenseValue,1);
	SetVariable(cgfVar_PostInstDlgValue,1);
}

#Define the parameters to instgui.exe when invoking bewTasks.
FormatString(/L:%IS_LANG% /R:bewTasks InstallPath=itsValue,itsValue,!InstallPath,bewTasksParms);

[FixDefaultPreloadParameters]
if CheckVariable(cgfVar_ShowLicenseValue,eq,empty)
{
	SetVariable(cgfVar_ShowLicenseValue,1);
}
if CheckVariable(cgfVar_PostInstDlgValue,eq,empty)
{
	SetVariable(cgfVar_PostInstDlgValue,1);
}
if CheckVariable(cgfVar_PtrSharInfoValue,eq,empty)
{
	if CheckVariable(NewPreloadSpec,eq,true)
	{
		SetVariable(cgfVar_PtrSharInfoValue,1);
	} else
	{
		SetVariable(cgfVar_PtrSharInfoValue,2);
	}
}
if CheckVariable(cgfVar_RegReminderValue,eq,empty)
{
	SetVariable(cgfVar_RegReminderValue,1);
}

[CheckPreloadParameters]
#Decide if bewtasks will run at all.
if CheckVariable(cgfVar_PostInstDlgValue,eq,1)
{
	#...PreLoad wants to display PostInstDlg
	SetVariable(cgfVar_bewTasks,TRUE);
	if CheckVariable(cgfVar_PtrSharInfoValue,eq,2)
	{
		#... and PreLoad ask also to display PrinterSharing Dlg.
		SetVariable(InstallPath,PreLoadAllDlg);

	} else if CheckVariable(NewPreloadSpec,eq,true)
	{
		if CheckVariable(cgfVar_PtrSharInfoValue,eq,1)
		{
			SetVariable(InstallPath,PreLoadAllDlg);
		}
	}
} else
{
	#PreLoad does not want the bewtasks dialogs...
	if CheckVariable(cgfVar_PtrSharInfoValue,eq,2)
	{
		#... but it has to run because, it has to ask about sharing printer.
		SetVariable(cgfVar_bewTasks,TRUE);
		SetVariable(InstallPath,PreLoadShareOnly);

	} else if CheckVariable(NewPreloadSpec,eq,true)
	{
		if CheckVariable(cgfVar_PtrSharInfoValue,eq,1)
		{
			SetVariable(cgfVar_bewTasks,TRUE);
			SetVariable(InstallPath,PreLoadShareOnly);
		} else
		{
			SetVariable(cgfVar_bewTasks,FALSE);
			if CheckVariable(cgfVar_RegReminderValue,eq,1)
			{
				#... it also wants to set a registry to show registration reminder weekly.
				RunSection(SetRegistry);
			}
		}
	} else if CheckVariable(cgfVar_PtrSharInfoValue,eq,1)
	{
		#... but it wants to set the printer as sharing.Do it here and do not call BEWTasks.
		SetVariable(cgfVar_bewTasks,FALSE);
		RunSection(MakePrinterShared);

		if CheckVariable(cgfVar_RegReminderValue,eq,1)
		{
			#... it also wants to set a registry to show registration reminder weekly.
			RunSection(SetRegistry);
		}
	} else
	{
		#... no sharing printer, so no BEWTasks.
		SetVariable(cgfVar_bewTasks,FALSE);
		if CheckVariable(cgfVar_RegReminderValue,eq,1)
		{
			#... but it wants to set a registry to show registration reminder weekly.
			RunSection(SetRegistry);
		}
	}
}

[MakePrinterShared]
#Read the latest printer object name
if RegExists(HKLM,%CustomInstallKey%\%ModelCode%,LatestPrinterObject,cgfVar_PtrNameValue)
{
}
#Make Share name.
MakeShareName(!cgfVar_PtrNameValue,cgfVar_PtrShareName,useInstalled);
#Update the current printer object to be shared.
SharePrinter(!cgfVar_PtrNameValue,!cgfVar_PtrShareName);
#Add a Firewall exception.
if CheckOS(x64)
{
	FormatString($CD_ROOT_DIR$\Install\x64\dllName,dllName,NetSupp.dll,cgf_NetSuppDll);
} else
{
	FormatString($CD_ROOT_DIR$\Install\x86\dllName,dllName,NetSupp.dll,cgf_NetSuppDll);
}
RunInstallAction(cgf_ReturnCode,RunLibFunction,!cgf_NetSuppDll,AddFirewallException,Local);


[SetRegistry]
if RegExists(HKLM,%CustomInstallKey%\%ModelCode%,LatestPrinterObject,cgfVar_PtrNameValue)
{
	FormatString(System\CurrentControlSet\Control\Print\Printers\printerName\PrinterDriverData,printerName,!cgfVar_PtrNameValue,cgfVar_OrigFNameKey);
}
#Find registry for the current PrinterObject to get OFN value - This value will be used throughout the BEW tasks.
if RegExists(HKLM,!cgfVar_OrigFNameKey,OriginalFriendlyName,cgfVar_OFNValue)
{
	FormatString(%Install_Reg%\IJPrtSettings\OFNValue,OFNValue,!cgfVar_OFNValue,cgfVar_IJPrtSettingsKey);
}
#Set flag and date for Registration reminder under %Install_Reg%\IJPrtSettings\OFNValue
RunInstallAction(cgfVar_RegActionReturn,RegistryEntry,Add,HKLM,!cgfVar_IJPrtSettingsKey,ShowRegistrationReminder,NUM,1);
RunInstallAction(cgfVar_RegActionReturn,RegistryEntry,Add,HKLM,!cgfVar_IJPrtSettingsKey,InstallTime,STR,$CURRENT_DATE$);


[CheckAdditionalApps]
if CheckVariable(cgfVar_bewTasks,eq,FALSE)
{
	#Read [OtherInstalls] Section to see if there is any additional app installer to run.
	#We are assuming no parameters exist for those programs. If parameter necessary, ProgramParms1 key should be added
	#to the ini file. We should read it and pass it as a 3rd parameter to RunProgram call.
	if IniSectionKeyExists($SYSTEM_DIR$\%MODELCODE%PLC.ini,OtherInstalls,Program1,cgfVar_Program1)
	{
		RunProgram(!cgfVar_Program1,NOWAIT);
	}
	if IniSectionKeyExists($SYSTEM_DIR$\%MODELCODE%PLC.ini,OtherInstalls,Program2,cgfVar_Program2)
	{
		RunProgram(!cgfVar_Program2,NOWAIT);
	}
}
[RemoveWUInstallRegKEY]
if RegExists(HKLM,!cgfVar_WUInstKEY,WUInstall,cgfVar_WUInstallValue)
{	
	RunInstallAction(cgfVar_RegWUInstall,RegistryEntry,Delete,HKLM,!cgfVar_WUInstKEY,WUInstall);
}

[CheckForFirewallApps]
if CheckVariable(cgfVar_IsNull,eq,:0:FWAppsList)
{
	if CheckLength(FWAppsList,gt,0)
	{
		SetValue(FirewallExText,%FirewallExceptions.NewText%);
		TimerCheck(Stop,cgfvar_FWListDelay);
	}
}

[CheckOSRequirement]
if CheckOS(x64)
{
} else if CheckOS(XP)
{
	if CheckOS(XPSP2)
	{
		SetVariable(cgfVar_OSRequireRunOnce,false);
	} else
	{
		if RegExists(HKLM,Software\Microsoft\Updates\Windows XP\SP3\KB893803v2,PackageName,cgfVar_WindowsInstaller31)
		{	
		} else
		{
			RunProgram($CD_ROOT_DIR$\Applications\App4r\tools\WindowsInstaller-KB893803-v2-x86.exe,NOWAIT,/quiet /norestart);
		}
		
		#ChangeWindow(OSRequirements,mainSplitter.top,capture);
		SetVariable(cgfVar_OSRequireRunOnce,false);
		#Break();
	}
} else if CheckOS(2k)
{
	if CheckOS(2kSP4|2kSP3)
	{
		if RegExists(HKLM,Software\Microsoft\Updates\Windows 2000\SP5\KB893803v2,PackageName,cgfVar_WindowsInstaller31)
		{	
		} else
		{
			RunProgram($CD_ROOT_DIR$\Applications\App4r\tools\WindowsInstaller-KB893803-v2-x86.exe,NOWAIT,/quiet /norestart);
		}
		SetVariable(cgfVar_OSRequireRunOnce,false);
	} else
	{
		SetVariable(cgfvar_App4R_NotInstall,true);
		SetVariable(cgfVar_OSRequireRunOnce,false);
	}
} else
{
}

[App4R_2kInstall]
if CheckVariable(cgfvar_App4R_NotInstall,eq,false)
{
	WriteToScript(Install.App4R,1);
} else
{
	WriteToScript(Install.App4R,0);
	FormatString(/L:%IS_LANG% /R:bewTasks InstallPath=itsValue App4RFlag=NotInstalled,itsValue,!InstallPath,bewTasksParms);
}
