'**************************************************************************
'*                       Anim Pro SetUp
'**************************************************************************

'$DEFINE DEBUG  ''Define for script development/debugging

'$INCLUDE 'setupapi.inc'
'$INCLUDE 'msdetect.inc'

CONST CURVER$= "Release 1.1"

'' Buttons and Checks

CONST IDB_Install =              2000
CONST IDB_Continue =             2001
CONST IDB_Exit =                 2002

''      Dialog IDs

CONST IDD_AnimProInstall =         101
CONST IDD_Welcome =                102
CONST IDD_ReWelcome =              103
CONST IDD_Insufficient_Memory =    104
CONST IDD_AskQuit =                105
CONST IDD_AppHelp =                106
CONST IDD_Finished =               107
CONST IDD_Update=                  108

''Bitmap ID's
CONST IDBM_BackGrnd = 999
 
''Bitmap ID
CONST LOGO = IDBM_BackGrnd

GLOBAL DEST$        ''Default destination directory.
GLOBAL OPTCUR$      ''Option selection from option dialog.
GLOBAL WinDir$      ''Windows home directory
GLOBAL WinSysDir$   ''Window's System's directory

GLOBAL TempMscuistf$  '' We copy mscuistf.dll over temporary so we know where it is...

REM GLOBAL CURVER$      ''Current version

DECLARE SUB Install
DECLARE FUNCTION MakePath (szDir$, szFile$) AS STRING
DECLARE FUNCTION VflatdPresent LIB "iniupd.DLL" AS INTEGER
DECLARE fUNCTION ExitWindowsExec  LIB "User" (Exec$, Param$) AS INTEGER

REM   Initialization of global variables and operations
INIT:
    CUIDLL$ = "mscuistf.dll"            ''Custom user interface dll
    HELPPROC$ = "FHelpDlgProc"          ''Help dialog procedure

    REM SetBitmap CUIDLL$, LOGO
    SetTitle "Animator Studio Setup"

    SrcDir$ = GetSymbolValue("STF_SRCDIR")
    SetSymbolValue "SIZEINI", MakePath ( SrcDir$, "size.ini" )
    SetSymbolValue "SourcePath", SrcDir$
    
    szInf$ = GetSymbolValue("STF_SRCINFPATH")
    WinDir$ = GetWindowsDir()
    WinSysDir$ = GetWindowsSysDir()

    IF szInf$ = "" THEN
        szInf$ = GetSymbolValue("STF_CWDDIR") + "aas.INF"
    END IF
    ReadInfFile szInf$

    DEST$ = "C:\animator"      '' Destination drive string.

'$IFDEF DEBUG
    i% = SetSizeCheckMode(scmOnIgnore)    '' could use scmOff; def = scmOnFatal
    WinDrive$ = MID$(GetWindowsDir, 1, 1)
    IF IsDriveValid(WinDrive$) = 0 THEN
        i% = DoMsgBox("Windows drive ('"+WinDrive$+"') is not a valid drive.", "DEBUG", MB_TASKMODAL+MB_ICONHAND+MB_OK)
        GOTO QUIT
    END IF
'$ENDIF ''DEBUG

    REM /* Check for previous installation */
    if DoesIniSectionExist ("WIN.INI", "AnimatorStudio") = 0 THEN
      GOTO WELCOME_INSTALL
    ENDIF
      
WELCOME_REINSTALL:
    REM /* Check which components have been installed.  Assume they want to
    REM    those components they didn't install last time.  Load previous
    REM    destination drive. */

    if DoesiniKeyExist ("WIN.INI", "AnimatorStudio", "Location") THEN 
        DEST$= GetiniKeyString("WIN.INI", "AnimatorStudio", "Location")
    ENDIF

    invert%= 0         

    IF DoesiniKeyExist ("WIN.INI", "AnimatorStudio", "Version") THEN
        IF GetiniKeyString("WIN.INI", "AnimatorStudio", "Version") < curver$ THEN
            GOTO update_dlg
        ELSE
            GOTO reinstall_dlg
        END IF
    END IF

 update_dlg:     
    sz$ = UIStartDlg(CUIDLL$, IDD_ReWelcome, "FInfoDlgProc", IDD_AppHelp, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
        UIPop 1
    ELSE
      IF sz$ = "CANCEL" THEN
          GOSUB ASKQUIT
          GOTO  update_dlg
      ELSE
          GOTO  update_dlg
      END IF
    END IF
    GOTO checkcorrupted

 reinstall_dlg:
    sz$ = UIStartDlg(CUIDLL$, IDD_ReWelcome, "FInfoDlgProc", IDD_AppHelp, HELPPROC$)
    IF sz$ = "CONTINUE" THEN
        UIPop 1
    ELSE
      IF sz$ = "CANCEL" THEN
          GOSUB ASKQUIT
          GOTO  reinstall_dlg
      ELSE
          GOTO  reinstall_dlg
      END IF
    END IF

 checkcorrupted:
    REM /* Check if previous installation was interrupted.  If so, assume they
    REM    they want to reinstall those components they tried to install before */
    IF GetIniKeyString("WIN.INI", "AnimatorStudio", "Setup Note")= "Incomplete Installation" THEN
      i%= DoMsgBox("Recommend reinstall all components.  Partial installations can corrupt functioning of Animator Studio", "Last Installation was aborted before completion", MB_OK+MB_TASKMODAL+MB_ICONHAND )
    ENDIF

    GOTO PARAMETERSCREEN
    
WELCOME_INSTALL:
    REM /* No previous installation detected.  Display introductory dialog. */
    
    sz$ = UIStartDlg(CUIDLL$, IDD_Welcome, "FInfoDlgProc", IDD_AppHelp, HELPPROC$)
    IF sz$ <> "CANCEL" THEN
        UIPop 1
    ELSE
        GOSUB ASKQUIT
        GOTO WELCOME_INSTALL
    END IF


PARAMETERSCREEN:
    REM /* This dialog is the main dialog box.  It is passed */
    SetSymbolValue "DestinationDrive", DEST$
    SetSymbolValue "SelectedComponents", OPTCUR$
    SetSymbolValue "VersionNumber", CURVER$
OPTL1:
        
    sz$ = UIStartDlg(CUIDLL$, IDD_AnimProInstall, "FCheckDlgProc", IDD_AppHelp, HELPPROC$)
    DEST$ = GetSymbolValue("DestinationDrive")
    OPTCUR$ = GetSymbolValue("SelectedComponents")
    
    IF sz$ = "INSTALL" THEN
        UIPop(1)
    ELSEIF sz$ = "REACTIVATE" THEN
        GOTO OPTL1
    ELSE
       GOSUB ASKQUIT
       GOTO OPTL1
    END IF

    IF OPTCUR$="NNNNNN" THEN
        i%= DoMsgBox("Nothing to install.", "Error", MB_OK+MB_TASKMODAL+MB_ICONHAND )
        GOTO OPTL1
    ENDIF
     
    REM /* Run install routine.  This copies all of the selected files and
    REM    of the system parameters */
     
    Install
    
    REM /* Run concluding dialog box */

    RESTRT% = RestartListEmpty ()
    Exe$ = WinDir$ + "\_msrstrt.exe"
    Batch$ = WinDir$ + "\_mssetup.bat"
    empty$ = ""
RESTART:
     sz$= UIStartDlg(TempMscuistf$, IDD_Finished, "FInfoDlgProc", IDD_AppHelp, HELPROC$)
     IF sz$ = "CONTINUE" THEN
         I% = ExitWindowsExec (Exe$, empty$)
         IF I% = 0 THEN
            GOTO RESTART
         ELSE
            UIPopAll
         ENDIF
     ELSEIF sz$ = "EXIT" THEN
         UIPopAll
     ELSEIF sz$ = "REACTIVATE" THEN
         GOTO RESTART
     ELSE
         UIPop 1
     ENDIF

     END

QUIT:
    ON ERROR GOTO ERRQUIT

    IF ERR = 0 THEN
        dlg% = EXITSUCCESS
    ELSEIF ERR = STFQUIT THEN
        dlg% = EXITQUIT
    ELSE
        dlg% = EXITFAILURE
    END IF
 
    END

ERRQUIT:
    i% = DoMsgBox("Setup sources were corrupted.  Contact Autodesk's Product Support.", "Error", MB_OK+MB_TASKMODAL+MB_ICONHAND)
    END

BADPATH:
    i%= DoMsgBox("Unable to establish target directory"+ DEST$, "Bad Path", MB_OK+MB_TASKMODAL+MB_ICONHAND )
    RETURN

ASKQUIT:
    sz$ = UIStartDlg(CUIDLL$, IDD_AskQuit, "FQuitDlgProc", 0, "")

    IF sz$ = "CANCEL" THEN
          UIPopAll
          ERROR STFQUIT
    ELSEIF sz$ = "REACTIVATE" THEN
          GOTO ASKQUIT
    ELSE
          UIPop 1
    END IF
    RETURN

'**
'** Purpose:
'**     Builds the copy list and performs all installation operations.
'** Arguments:
'**     none.
'** Returns:
'**     none.
'*************************************************************************
SUB Install STATIC

    SrcDir$ = GetSymbolValue("STF_SRCDIR")
    CreateDir DEST$, cmoNone
    
    OpenLogFile MakePath(DEST$, "LOGFILE.OUT"), 1
    WriteToLogFile "----------------------------------------------------------"
    WriteToLogFile "An AutoDesk Inc. Product"
    WriteToLogFile "Animator Studio Installation Record - " + CURVER$ + "'"
    WriteToLogFile "  Destination directory: '" + DEST$ + "'"
    WriteToLogFile ""
      
    ini$= MakePath( GetWindowsDir (), "WIN.INI" )
    animini$= MakePath(DEST$, "ANIMPRO.INI")
    
    TempMscuistf$ = MakePath( DEST$, "mscuistf.dll" )
    CopyFile GetSymbolValue("STF_CWDDIR") + "mscuistf.dll", TempMscuistf$, 0, 0

    CreateIniKeyValue ini$, "AnimatorStudio", "Location", DEST$ , cmoOverwrite
    CreateIniKeyValue ini$, "AnimatorStudio", "Version", CURVER$ , cmoOverwrite
    CreateIniKeyValue ini$, "AnimatorStudio", "Setup Note", "Incomplete Installation", cmoOverwrite

    SetRestartDir WinDir$
    CopyFilesInCopyList

    RemoveIniKey ini$, "AnimatorStudio", "Setup Note", cmoNone

    CreateProgmanGroup "Autodesk Multimedia", "", cmoNone
    ShowProgmanGroup  "Autodesk Multimedia", 1, cmoNone
REM The following line is for Live Demo Version only
REM Don't remove ... comment out only if not needed - this is not documented in
REM Microsoft's idiotic Setup manual 
REM    CreateProgmanItem "Autodesk Multimedia", "Product Info", "notepad.exe "+DEST$+"\prodinfo.txt", "", cmoOverwrite
    CreateProgmanItem "Autodesk Multimedia", "Animator Studio Readme", "write.exe "+DEST$+"\readme.wri", "", cmoOverwrite
    IF MID$(OPTCUR$, 1, 1)= "Y" THEN
        CreateProgmanItem "Autodesk Multimedia", "Animator Studio", MakePath(DEST$, "animator.exe"), "" ,cmoOverwrite
         REM clean up this old file from c0     
         IF DoesFileExist (DEST$ + "\flash.exe", femExists) THEN
             RemoveFile DEST$ + "\flash.exe", cmoForce
         ENDIF
         IF DoesFileExist (DEST$ + "\traptxen.gge", femExists) THEN
             RemoveFile DEST$ + "\traptxen.gge", cmoForce
         ENDIF
         IF DoesFileExist (DEST$ + "\fotrap.gge", femExists) THEN
             RemoveFile DEST$ + "\fotrap.gge", cmoForce
         ENDIF
    END IF
    IF MID$(OPTCUR$, 2, 1)= "Y" THEN
        CreateProgmanItem "Autodesk Multimedia", "Animator SoundLab", MakePath(DEST$, "soundlab.exe"), "", cmoOverwrite
    END IF
    IF MID$(OPTCUR$, 3, 1)= "Y" THEN
        CreateProgmanItem "Autodesk Multimedia", "Animator Scriptor", MakePath(DEST$, "scriptor.exe"), "", cmoOverwrite
    END IF
    IF MID$(OPTCUR$, 4, 1)= "Y" THEN
        CreateProgmanItem "Autodesk Multimedia", "Animator Player", MakePath(DEST$, "player.exe"), "", cmoOverwrite
    END IF

    REM ************** Window Video .ini setup **************
   WinVidSet:
    IF VflatdPresent() = 0 THEN
       CreateSysIniKeyValue WinDir$ + "system.ini", "386Enh", "device", "dva.386", cmoOverwrite
    END IF
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.IV32", "ir32.dll", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.IV31", "ir32.dll", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.RT21", "ir21.dll", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.YVU9", "iyvu9.dll", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.CVID", "iccvid.drv", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.MSVC", "msvidc.drv", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.MRLE", "MSRLE.drv", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "mci", "AVIVideo", "mciavi.drv", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "WaveMapper", "msacm.drv", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "MSACM.msadpcm", "msadpcm.acm", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "MSACM.imaadpcm", "imaadpcm.acm", cmoOverwrite
CreateIniKeyValue WinDir$ + "WIN.INI", "mci extensions", "avi", "AVIVideo", cmoOverwrite
CreateIniKeyValue WinDir$ + "control.ini", "drivers.desc", "ir21.dll", "Intel Indeo(TM) Video R2.1", cmoOverwrite
CreateIniKeyValue WinDir$ + "control.ini", "drivers.desc", "msacm.drv", "Microsoft Sound Mapper V2.00", cmoOverwrite
CreateIniKeyValue WinDir$ + "control.ini", "drivers.desc", "msadpcm.acm", "Microsoft ADPCM Codec V2.00", cmoOverwrite
CreateIniKeyValue WinDir$ + "control.ini", "drivers.desc", "imaadpcm.acm", "Microsoft IMA ADPCM Codec V2.00", cmoOverwrite


CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.AASC", "AASC.drv", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.AFLC", "flccodec.drv", cmoOverwrite
CreateIniKeyValue WinDir$ + "system.ini", "Drivers", "VIDC.AFLI", "flccodec.drv", cmoOverwrite

    CloseLogFile

END SUB



'**
'** Purpose:
'**     Appends a file name to the end of a directory path,
'**     inserting a backslash character as needed.
'** Arguments:
'**     szDir$  - full directory path (with optional ending "\")
'**     szFile$ - filename to append to directory
'** Returns:
'**     Resulting fully qualified path name.
'*************************************************************************
FUNCTION MakePath (szDir$, szFile$) STATIC AS STRING
    IF szDir$ = "" THEN
        MakePath = szFile$
    ELSEIF szFile$ = "" THEN
        MakePath = szDir$
    ELSEIF MID$(szDir$, LEN(szDir$), 1) = "\" THEN
        MakePath = szDir$ + szFile$
    ELSE
        MakePath = szDir$ + "\" + szFile$
    END IF
END FUNCTION

