'//////////////////////////////////////////////////////////////////////////////
'                                                                            
'  IIIIIII    A                                                            
'    II      A A                        InstallAide (R)                  
'    II     A   A      (c) 2000-2006, InstallAide Software 
'    II     AAAAA      Amethyst   
'  IIIIIII AA   AA                        
'                                                                                                                                                  '
'//////////////////////////////////////////////////////////////////////////////
Dim		BACKSTEP
Dim		NEXTSTEP
Dim		EXITSTEP
Dim 	strStep
Dim 	IAParam
Dim		strTemp
Dim 	strSetupImage
Dim 	strSupportDir
Dim		nState

BACKSTEP 	= 1
NEXTSTEP 	= 2
EXITSTEP 	= 3

SM_MODIFY	= 1
SM_RESTORE 	= 2
SM_REMOVE	= 3

Set IAParam 	= Install.CreateIAParam()


If Install.IsInstalled() Then
	OnModify
Else
	OnInstall
End If	

Set IAParam = Nothing

'//////////////////////////////////////////////////////////////////////////////


'--------------------------------------------
' 修改安装
'--------------------------------------------
Sub OnModify()
	strStep 		= "SetModifyType"
	Do While strStep <> "Exit"
		Select Case strStep
			Case "SetModifyType"	
				nState = Install.SdModifySetup( IAParam )
				If nState = NEXTSTEP Then
					If Install.SetupMode = SM_MODIFY Then
						strStep = "SdComponent"
					ElseIf Install.SetupMode = SM_RESTORE Then
						strStep = "SdCopyFile"
					ElseIf Install.SetupMode = SM_REMOVE Then
						Install.UnInstall
						strStep = "Exit"
					Else
						strStep = "Exit"
					End If
				Else 
					strStep = "Exit"
				End If
				
			Case "SdComponent"
	   			nState = Install.SdComponent( IAParam )
				If nState = BACKSTEP Then
					strStep = "SetModifyType"
				ElseIf nState = NEXTSTEP Then
					strStep = "SdCopyFile"
				Else 
					strStep = "Exit"
				End If
				
			Case "SdCopyFile"  
	   			nState = Install.SdCopyFile( IAParam )
				If nState = BACKSTEP Then
					If Install.SetupTypeName = "_Custom" Then
						strStep = "SdComponent"
					Else
						strStep = "SdSetupType"
					End If
				Else 
					strStep = "SdFinish"
				End If
	   		  
	   		Case "SdFinish"  
	   			Install.SdFinish( IAParam )
				strStep = "Exit"
				
	  		Case Else
	  		   	strStep = "Exit"
		End Select
	Loop	
End Sub

'--------------------------------------------
' 安装系统
'--------------------------------------------
Sub OnInstall()
	strStep 		= "SdAppImg"

	Do While strStep <> "Exit"
		Select Case strStep
			Case "SdAppImg"
				nState = Install.SdImage( IAParam )
				If nState = BACKSTEP Then
					strStep = "SdAppImg"
				ElseIf nState = NEXTSTEP Then
					strStep = "SdWelCom"
				Else 
					strStep = "Exit"
				End If
				
			Case "SdWelCom"
				msgbox Install.GetVarTabValue("VAR_S_APPNAME",0)
				nState = Install.SdWelcome(IAParam)
				If nState = BACKSTEP Then
					strStep = "SdWelCom"
				ElseIf nState = NEXTSTEP Then
					strStep = "SdLicense"
				Else 
					strStep = "Exit"
				End If
						
	   		Case "SdLicense"  
	   			nState = Install.SdLicense(IAParam)
				If nState = BACKSTEP Then
					strStep = "SdWelCom"
				ElseIf nState = NEXTSTEP Then
					strStep = "SdSetDestPath"
				Else 
					strStep = "Exit"
				End If
	   			
	   		Case "SdSetDestPath"
	   			nState = Install.SdSetDestPath(IAParam)
				If nState = BACKSTEP Then
					strStep = "SdLicense"
				ElseIf nState= NEXTSTEP Then
					strStep = "SdSetupType"
				Else 
					strStep = "Exit"
				End If
				
			Case "SdSetupType"  
	   			nState = Install.SdSetupType(IAParam)
				If nState = BACKSTEP Then
					strStep = "SdSetDestPath"
				ElseIf nState = NEXTSTEP Then
					If Install.SetupTypeName = "_Custom" Then
						strStep = "SdComponent"
					Else
						strStep = "SdCopyFile"
					End If
				Else 
					strStep = "Exit"
				End If
				
			Case "SdComponent"  
	   			nState = Install.SdComponent(IAParam)
				If nState = BACKSTEP Then
					strStep = "SdSetupType"
				ElseIf nState = NEXTSTEP Then
					strStep = "SdCopyFile"
				Else 
					strStep = "Exit"
				End If
				
			Case "SdCopyFile"  
	   			nState = Install.SdCopyFile( IAParam )
				If nState = BACKSTEP Then
					If Install.SetupTypeName = "_Custom" Then
						strStep = "SdComponent"
					Else
						strStep = "SdSetupType"
					End If
				Else 
					strStep = "SdFinish"
				End If
	   		  
	   		Case "SdFinish"  
	   			Install.SdFinish(IAParam)
				strStep = "Exit"
				
	  		Case Else
	  		   	strStep = "Exit"
		End Select
	Loop
End Sub	