# Launcher input parameters:
# {1} Log file
# {2} Application to launch
# {3} Media
# {4} Name
# {5} Filename (used only for oConv)

Set LaunchDoc ""
Set LaunchApp "{2}"
If "{2}" == "oConv"
        Set LaunchDoc "REDMCSB:OBJECT:"{3}":"{4}":"{5}
        Set OneClickScript "REDMCSB:SOURCE:CONVERT.TXT"
        Set LaunchApp "REDMCSB:THINK C 4.0.5:Utilities:oConv"
Else
        If ("{2}" == "THINK C") OR "{2}" == "THINK C 5.0"
                If "`Exists -f "{LaunchDoc}"`"
                        Set LaunchDoc "REDMCSB:OBJECT:"{3}":"{4}":"{3}"_"{4}".Project"
                        Set OneClickScript "REDMCSB:SOURCE:BUILD.TXT"
                Else
                        Set OneClickScript "REDMCSB:SOURCE:CREATE.TXT"
                        Duplicate "REDMCSB:SOURCE:{3}:{4}:PROJECT.TXT" "REDMCSB:SOURCE:PROJECT.TXT" -y ˇˇ{1}
                End
                If "{2}" == "THINK C"
                        Set LaunchApp "REDMCSB:THINK C 4.0.5:THINK C"
                Else
                        Set LaunchApp "REDMCSB:THINK C 5.0.2:THINK C 5.0"
                End
                Duplicate "REDMCSB:SOURCE:{3}:{4}:EXEID.H" "REDMCSB:OBJECT:{3}:{4}:EXEID.H" -y ˇˇ{1}
        End
End
If "`Exists -f "{OneClickScript}"`"
        Duplicate "{OneClickScript}" "REDMCSB:SOURCE:{2}.TXT" -y ˇˇ{1}
End

# Opening an alert window before each launch of Think C or oConv is a workaround
# to avoid that MPW remains the front application after launching another
# application, which prevents OneClick from performing its automation
# OneClick is also used to close this alert window
Set LaunchInfo "Launcher - Script: {OneClickScript}śnApp: {LaunchApp}śnDoc: {LaunchDoc}"
Echo {LaunchInfo}
Echo {LaunchInfo} ˇˇ{1}
Alert {LaunchInfo}

If "{LaunchDoc}" == ""
        "{LaunchApp}" -wait
Else
        "{LaunchApp}" "{LaunchDoc}" -wait
End If
If "`Exists -f "REDMCSB:SOURCE:{2}.TXT"`"
        Delete "REDMCSB:SOURCE:{2}.TXT" ˇˇ{1}
End
