; Copyright (c) uib gmbh (www.uib.de)
; This sourcecode is owned by uib
; and published under the Terms of the General Public License.
; credits: http://www.opsi.org/credits/

[Actions]
requiredWinstVersion >= "4.10.8.6"

DefVar $MsiId$
DefVar $LogDir$
DefVar $ProductId$  
DefVar $MinimumSpace$
DefVar $InstallDir$
DefVar $ExitCode$
DefVar $INST_SystemType$
DefVar $INST_architecture$

Set $INST_SystemType$ = GetSystemType
Set $INST_architecture$ = GetProductProperty("install_architecture","system specific")
Set $LogDir$ = "%SystemDrive%\tmp"

; The token BUILDER_VARIABLES will be replaced by opsi-builder.sh
; and adds the following variables:
;   from builder-product.cfg :  all variables definded by attribute WINST[index]
;   from builder-product.cfg :  VENDOR PN VERSION RELEASE PRIORITY ADVICE TYPE   
;   from opsi-builder.cfg    :  CREATOR_TAG CREATOR_NAME CREATOR_EMAIL           
;   auto generated winst-variables
;         $IconFile$: path to product picture
;
@@BUILDER_VARIABLES@@

; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
;$ProductId$ should be the name of the product in opsi
; therefore please: only lower letters, no umlauts, 
; no white space use '-' as a seperator
Set $ProductId$       = "brother.mfc7360"
Set $MinimumSpace$    = "150 MB"
; the path were we find the product after the installation
Set $InstallDir$      = "%SystemDrive%\Windows\inf"
; ----------------------------------------------------------------

if not(HasMinimumSpace ("%SystemDrive%", $MinimumSpace$))
	LogError "Not enough space on %SystemDrive%, " + $MinimumSpace$ + " on drive %SystemDrive% needed for " + $ProductId$
	isFatalError
	; Stop process and set installation status to failed
else
	comment "Show product picture"
	ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$
	
	if FileExists("%ScriptPath%\delsub32.ins")
		comment "Start uninstall sub section"
		Sub "%ScriptPath%\delsub32.ins"
	endif
	
	Message "Installing " + $ProductId$ + " ..."

	if ($INST_SystemType$ = "64 Bit System") and (($INST_architecture$ = "system specific") or ($INST_architecture$ = "both") or ($INST_architecture$ = "64 only"))
           Files_install_64
           Winbatch_install_64
           Sub_check_exitcode
           Files_Delete_64
        endif

        if (($INST_SystemType$ = "x86 System") and ($INST_architecture$ = "system specific")) or ($INST_architecture$ = "both") or ($INST_architecture$ = "32 only")
           Files_install_32
           Winbatch_install_32
           Sub_check_exitcode
           Files_Delete_32
        endif    	
       
      comment "Reboot"
      ExitWindows /Reboot
	
endif

[Files_install_32]
copy -s "$Drv_Dir32$*.*" "$LogDir$\X86"

[Files_install_64]
copy -s "$Drv_Dir64$*.*" "$LogDir$\X64"

[Winbatch_install_32]
$LogDir$\X86\DPInst.exe /S

[Winbatch_install_64]
$LogDir$\X64\DPInst.exe /S

[Files_Delete_32]
delete -sf $LogDir$\X86

[Files_Delete_64]
delete -sf $LogDir$\X64

[Sub_check_exitcode]
comment "Test for installation success via exit code"
set $ExitCode$ = getLastExitCode
if ($ExitCode$ = "0") or ($ExitCode$ = "768")
        comment "Looks good: setup program gives exitcode zero"
else
        comment "Setup program gives a exitcode unequal zero: "+ $ExitCode$
        isFatalError
endif

