DefineVariables
  Text          [ProductName]           := Cyberspeed
  Text          [CompanyName]           := Mindscape
  Text          [MainExeName]           := CYBER.EXE
  Text          [CommandLineArgs1]      := 
  Text          [CommandLineArgs2]      :=
  Text          [ProgGrpName]           := CYBERSPEED
  Text          [ProgGrpFileName]       := CYBER.GRP
  Text          [RegEntryRoot]          := Software
  Text          [RegEntry]              := CybDemo
  Text          [RegAppID]              := Cyberspeed
  Text          [IconName1]             := BIG.ICO
  Text          [UninstallName]         := UNSETUP.EXE
  Text          [UninstallScript]       := UNSETUP.INS
  Text          [ThisWin32sVersion]     := 1.25.142.0
  Text          [LogFile]               := CYBER.LOG
  Text          [TempFile]              :=
  Text          [TempStr]               := 
  Text          [WinVer]                :=
  Text          [WinPlatform]           :=
  Text          [CurrentInstallOpt]     := BlankString
  Text          [Win95DefProgFiles]     := Program Files
  Directory     [PrevInstDir]           := BlankString
  Directory     [SavedGameDir]          := SAVED
  Text          [DefaultDestDir]        := 
;;  Directory     [ExecDir]               := EXECDIR
  Directory     [DefDest]               := CYBER
  Directory     [LogoDir]               := LOGO
  Logical       [Win95Only]             := NoCharacter
  Logical       [TempYes]               := NoCharacter
  Logical       [BailOut]               := NoCharacter
  Logical       [PreviousInstall]       := NoCharacter
  Logical       [DoWin32sSetup]         := NoCharacter
  Logical       [DoReinstall]           := NoCharacter
  Logical       [Multilingual]          := NoCharacter
  Number        [MaxInstallDirLen]      := 60
  Number        [Continue]              := 1012
  Logical       [Root]                  := NoCharacter
  Logical       [CopyAborted]           := NoCharacter
  Directory     [SourceDir]             :=
  Directory     [TempDir]               := BlankString
EndDefineVariables

SetDefaultBitmap Off

;;SetInstallModeTo Install

SetTraceMode Off

SetExitConfirmationPrompt off

SetPopupBorderTo double

;; SetBackgroundColor 0 0 0 0 0 0

SetReplacementInquiry Off

Logging On

Do CheckPreviousInstall

:DoneLanguage

[WinVer] := WindowsVersion
[WinPlatform] := WindowsPlatform

If [PreviousInstall]
	[Number1] := PositionOf [UninstallName] in [CommandLine0]
	If [Number1] > 0
		Do Uninstall
		GoTo Bail
    EndIf
EndIf


;; check for uninstall or  reinstall
;; on the command line. This may be passed by the Win95 autorun
;; program
If [CommandLine2] = Uninstall
	Do Uninstall
	GoTo Bail
Else
	If [CommandLine2] = Reinstall
	[DoReinstall] := YesCharacter
		GoTo SkipPreviousCheck
	EndIf
EndIf

:SkipPreviousCheck

If [Win95Only]
	If .not. [WinPlatform] = Win95
		Dialog
			[ProductName] requires Windows 95.
			You must install Windows 95 and then install
			[ProductName].
		EndDialog
	EndIf
EndIf

If [PreviousInstall]
      QueLogFile "[InstallationDirectory]\[LogFile]"
EndIf

[YesOrNo4] := YesCharacter
;; Product Introduction Screen
Do FirstInstall

If .not. [YesOrNo4]
  GoTo Bail
EndIf

Do InstallSystem
Do InstallWinG
Do InstallRMorph


;; Do the actual copying
[InstallOption] := BlankString
SetCopyAttrTo 00
CopyQuedFiles LOGFILE "[InstallationDirectory]\[LogFile]" SILENTLY
[Number1] := LastErrorCode
If [Number1] = 1
    [CopyAborted] := YesCharacter
	Dialog BlackOnLightGray
		The installation has been aborted.
		You should run the install program again to either
		complete the installation or to uninstall the
	files that have been installed.
	EndDialog
Else
	If [Number1] = 2
			Dialog BlackOnLightGray
				Some files could not be overwritten yet because they are
				in use by other applications. You should restart Windows
				before running [ProductName] to allow the files to be
				overwritten.            
			EndDialog
    	EndIf
EndIf

if [InstallOption] = NoSpace
	Dialog BlackOnLightGray
		You do not have sufficient disk space to run [ProductName].
		You should delete some files on your hard disk and
		then re-insert the CD.
	EndDialog
    GoTo Bail
EndIf

CreateLogFile "[InstallationDirectory]\[LogFile]"
Do FillRegister
DeleteCopyQue

;; run the product
Run [InstallationDirectory]\[MainExeName] 

;; run the slideshow
;;dialog
;;	Run [InstallFromDirectory]\SLIDES\pptview.exe [InstallFromDirectory]\Slides\Cybslide.ppt	
;;enddialog
Run [InstallFromDirectory]\SLIDES\pptview.exe [InstallFromDirectory]\Slides\Cybslide.ppt 

;; Automatically uninstall
Do Uninstall



:Bail
SoLong


Procedure PromptInstallDir
	[InstallationDirectory] := EnvironmentStringFor TEMP
	ValidateInstallDir "[InstallationDirectory]"
	If .not. LastErrorCode = 0
		[TempStr] := FirstFixedDrive
		[InstallationDirectory] := [TempStr]:\TEMP
	EndIf
EndProcedure

Procedure FirstInstall
	Do PromptInstallDir
	[Dir1] := [InstallationDirectory]
    Do SecondInstall
EndProcedure


Procedure Uninstall
	[InstallationDirectory] := RegQueryValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\InstallDir"
	If LastErrorCode = 0
		QueLogFile "[InstallationDirectory]\[LogFile]"
		if LastErrorCode = 0
		;; uninstall all saved games
			[Number1] := 1
			[Array5] := Reg32EnumValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\SavedGames"
			While [Array5][[Number1]] <> BlankString
				[TempStr] := [Array5][[Number1]]
				[String1] := SubStringOf [TempStr] from 1 to 1
				[String2] := SubStringOf [TempStr] from 4 to End
				QueCopyFiles from [String1]: DELETE
					"[String2]"	SavedGame
				EndQueCopyFiles
				IncrementNumber [Number1]
			EndWhile
			
			[Number1] := 1
			[Array5] := Reg32EnumValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\Misc"
			While [Array5][[Number1]] <> BlankString
				[TempStr] := [Array5][[Number1]]
				[String1] := SubStringOf [TempStr] from 1 to 1
				[String2] := SubStringOf [TempStr] from 4 to End
				QueCopyFiles from [String1]: DELETE
					"[String2]"
				EndQueCopyFiles
				IncrementNumber [Number1]
			EndWhile

			CopyQuedFiles LOGFILE "[InstallationDirectory]\[LogFile]" Uninstall SILENTLY
		
        Endif
	EndIf

	Do EmptyRegister
EndProcedure

Procedure SecondInstall
	QueCopyFiles from "[InstallFromDirectory]" to "[InstallationDirectory]"
		CYBER\*.* as *.*
		DATA\SAVEGAME\*.* as SAVEGAME\*.*
		DATA\CYBER.PRF as CYBER.PRF
	EndQueCopyFiles
EndProcedure


Procedure InstallWinG
	QueCopyFiles from "[InstallFromDirectory]" to "[WindowsSystemDirectory]"
			 WING\*.*      as    *.*        SharedDLL
	EndQueCopyFiles
EndProcedure

Procedure InstallSystem
		QueCopyFiles from "[InstallFromDirectory]" to "[WindowsSystemDirectory]"
			SYSTEM\*.*      as    *.*               SharedDLL
		EndQueCopyFiles
EndProcedure

Procedure InstallMSVC20
		If .not. [WinPlatform] = Win95
			If ([WinPlatform] = Win16) .or. ([WinPlatform] = Win32s)
				QueCopyFiles from "[InstallFromDirectory]" to "[WindowsSystemDirectory]"
					MSVCRT20\Win32s\*.*      as    *.*      SharedDLL
				EndQueCopyFiles
			Else
				QueCopyFiles from "[InstallFromDirectory]" to "[WindowsSystemDirectory]"
					MSVCRT20\Win32\*.*      as    *.*   SharedDLL
				EndQueCopyFiles
			Endif
		EndIf
EndProcedure

Procedure InstallRMorph
		QueCopyFiles from "[InstallFromDirectory]" to "[WindowsSystemDirectory]"
		   RMORPH\*.*         as    *.*                         SharedDLL
		   RMORPH\RL\*.*      as    RL\*.*          SharedDLL
		   RMORPH\RL\SOFT\*.* as    RL\SOFT\*.*     SharedDLL
		EndQueCopyFiles
EndProcedure


Procedure CheckPreviousInstall
	[PrevInstDir] := RegQueryValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\InstallDir"
	If LastErrorCode = 0
		[PreviousInstall] := YesCharacter
		[InstallationDirectory] := [PrevInstDir]
		[TempStr] := RegQueryValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\Language"
		If LastErrorCode = 0
;;                [Language] := [TempStr]
	    EndIf
	EndIf
EndProcedure

Procedure FillRegister
	;; Used by the program
;;	RegSetValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\ExecDir" "[InstallationDirectory]\[ExecDir]"
		RegSetValue ClassesRoot [RegEntryRoot]\[CompanyName]\[RegEntry]\RootDir "[InstallationDirectory]"
		RegSetValue ClassesRoot [RegEntryRoot]\[CompanyName]\[RegEntry]\BinDir "[InstallationDirectory]\CYBER"
		RegSetValue ClassesRoot [RegEntryRoot]\[CompanyName]\[RegEntry]\LocalDir "[InstallationDirectory]"
		RegSetValue ClassesRoot [RegEntryRoot]\[CompanyName]\[RegEntry]\RemoteDir "[InstallFromDirectory]\DATA"
	;; Windows 95 only
	;; Used by Install
	RegSetValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\InstallOption" "[InstallOption]"
	RegSetValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\Language" "[Language]"
	RegSetValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\InstallDir" "[InstallationDirectory]"
;;      RegSetValue ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]\UnInstallScript" "[InstallationDirectory]\[UninstallScript]"
EndProcedure


Procedure EmptyRegister
;;      RegDeleteKey ClassesRoot [RegAppID]
		RegDeleteKey ClassesRoot "[RegEntryRoot]\[CompanyName]\[RegEntry]"

		;; check to see if there are any other products under this company name
		;; if not, then delete this entry too
		[Array5] := RegEnumKey ClassesRoot "[RegEntryRoot]\[CompanyName]"
		If .not. LastErrorCode = 0
			RegDeleteKey ClassesRoot "[RegEntryRoot]\[CompanyName]"
		EndIf
EndProcedure

EndScript
