;/****************************************************************************/
;/* Copyright (c) 1995 Madge Networks Ltd                                    */
;/****************************************************************************/
;
; OEMSETUP.INF
;
;       Madge LAN Emulation Client INF file.
;       v1.00
;
; History:
;       ACLC            25-Apr-1995     Created, based on OEMNADE2.INF
;       ACLC            12-May-1995     Extensive additions to create extra
;                                       service keys - they aren't perfect, but
;                                       they will do for now.
;       ACLC            23-May-1995     Added Ethernet option
;       ACLC            10-Oct-1995     Replaced all my hacks with calls into
;                                       external library functions, cleaning
;                                       up the code greatly!
;       ACLC            20-Nov-1995     Release!
;       ACLC            17-Jun-1996     New mod's for bugs in driver
;                                       dependencies and medium type changes.
;
;/****************************************************************************/

;/****************************************************************************/
;/*                                                                          */
;/* Support sections for - Identify                                          */
;/*                                                                          */
;/****************************************************************************/

[Identification]
    OptionType = NetAdapter


;/****************************************************************************/
;/*                                                                          */
;/* Mandatory section - Identify                                             */
;/*                                                                          */
;/****************************************************************************/

[Identify]
    read-syms Identification

    set Status     = STATUS_SUCCESSFUL
    set Identifier = $(OptionType)
    set Media      = #("Source Media Descriptions", 1, 1)

    Return $(Status) $(Identifier) $(Media)


;/****************************************************************************/
;/*                                                                          */
;/* Support sections for - ReturnOptions                                     */
;/*                                                                          */
;/****************************************************************************/

[LanguagesSupported]
    ENG


[PlatformsSupported]
    PCI


[Options]
    LEC


; OptionsTextENG - see language dependent sections


;/****************************************************************************/
;/*                                                                          */
;/* Mandatory section - ReturnOptions                                        */
;/*                                                                          */
;/****************************************************************************/

[ReturnOptions]
    set Status         = STATUS_FAILED
    set OptionList     = {}
    set OptionTextList = {}

    ; Check if the language requested is supported

    set LanguageList = ^(LanguagesSupported, 1)

    Ifcontains(i) $($0) in $(LanguageList)
        ; Check if the platforms requested is supported

        ifstr(i) $($1) == ""
            goto returnoptions
        endif

        set PlatformList = ^(PlatformsSupported, 1)

        Ifcontains(i) $($1) in $(PlatformList)
            goto returnoptions
        else
            set Status = STATUS_NOTSUPPORTED
            goto finish_ReturnOptions
        endif
    else
        set Status = STATUS_NOLANGUAGE
        goto finish_ReturnOptions
    endif

    ; form a list of all the options and another of the text representing

returnoptions = +
    set OptionList     = ^(Options, 1)
    set OptionTextList = ^(OptionsText$($0), 1)
    set Status         = STATUS_SUCCESSFUL

finish_ReturnOptions = +
    Return $(Status) $(OptionList) $(OptionTextList)


;/****************************************************************************/
;/*                                                                          */
;/* Support sections for - InstallOption                                     */
;/*                                                                          */
;/****************************************************************************/

[GeneralConstants]
;
;  Program flow control variables.
;
from      = ""
to        = ""
;
;  Return codes; Exit_Code is set to one of these
;
ExitCodeOk     = 0
ExitCodeCancel = 1
ExitCodeFatal  = 2

KeyNull            = ""
MAXIMUM_ALLOWED    = 33554432
RegistryErrorIndex = NO_ERROR
KeyProduct         = ""
KeyParameters      = ""

TRUE    = 1
FALSE   = 0
NoTitle = 0

ExitState = "Active"
OldVersionExisted = $(FALSE)

DriverPath      = $(!STF_NTPATH)\drivers


[FileConstants]
;
;  File names, etc.
;
UtilityInf      = "UTILITY.INF"
ParamInf        = "NCPARAM.INF"
subroutineinf   = "SUBROUTN.INF"
SoftwareType    = "driver"
Exit_Code       = 0

;
; EventLog Message File
;
NetEventDLL     = "%SystemRoot%\System32\netevent.dll;%SystemRoot%\System32\atmcfg.dll"

; Product Info
;
Manufacturer        = "Madge"
ProductMajorVersion = "3"
ProductMinorVersion = "5"
ProductVersion      = $(ProductMajorVersion)"."$(ProductMinorVersion)
;
; Software
;
ProductSoftwareName      = "NtLec"
ProductSoftwareImagePath = "%SystemRoot%\System32\drivers\NtLec.SYS"
NetRuleSoftwareType      = "ntlecSys ndisDriver lecDriver"
NetRuleSoftwareUse       = $(SoftwareType)
NetRuleSoftwareBindForm  = """NtLec"" yes no container"
NetRuleSoftwareClass     = {"lecDriver basic"}
NetRuleSoftwareBindable  = {"lecDriver lecAdapter non exclusive 100"}
;
; Support drivers (well, actually, these do most of the work)
;
;AMUXSoftwareName      = AMUX
;AMUXSoftwareTitle     = "Madge ATM Multiplexer"
;AMUXSoftwareImagePath = %SystemRoot%\System32\drivers\AMUX.SYS
;AALSoftwareName       = SOKMAAL
;AALSoftwareTitle      = "Madge AAL Driver (SOK)"
;AALSoftwareImagePath  = %SystemRoot%\System32\drivers\SOKMAAL.SYS

;
; Hardware
;
ProductHardwareName      = "NtLec"
NetRuleHardwareType      = "ntlec lecAdapter"
NetRuleHardwareBindForm  = " yes yes container"
NetRuleHardwareClass     = {"lecAdapter basic"}
;
; Registry Key
;
ProductKeyName  = $(!NTN_SoftwareBase)"\"$(Manufacturer)"\"$(ProductSoftwareName)"\CurrentVersion"
ParamKeyName    = $(!NTN_ServiceBase)"\"$(ProductHardwareName)"\Parameters"
LinkageKeyName  = $(!NTN_ServiceBase)"\"$(ProductHardwareName)"\Linkage"

[date]
    ; Now is a list which contains { Sec from 1-1-1970, Year, Month, Day, Hour,
    ; Minute, Second }
    Now = {} ? $(!LIBHANDLE) GetSystemDate


;/****************************************************************************/
;/*                                                                          */
;/* Mandatory section - InstallOption                                        */
;/*                                                                          */
;/****************************************************************************/

[InstallOption]

    ; set !DebugOutputControl = 1

    set Status   = STATUS_FAILED

    ; extract parameters

    set Option   = $($1)
    set SrcDir   = $($2)
    set AddCopy  = $($3)
    set DoCopy   = $($4)
    set DoConfig = $($5)

    ; Check if the language requested is supported

    set LanguageList = ^(LanguagesSupported, 1)

    Ifcontains(i) $($0) NOT-IN $(LanguageList)
        Return STATUS_NOLANGUAGE
    endif

    set-subst LF = "\n"

    read-syms GeneralConstants
    read-syms FileConstants
    read-syms FileConstants$(!STF_LANGUAGE)
    read-syms DialogConstants$(!STF_LANGUAGE)

    detect date

    set-title  $(FunctionTitle)

    set to   = Begin
    set from = Begin
;
;  Assume all is well.
;
    set CommonStatus = STATUS_SUCCESSFUL

    EndWait

;
;   Set up the operation-mode-based variables and gaily welcome
;   the user.  If the "install mode" variable is improperly set,
;   assume this is a new installation.
;

Begin = +
    Set ActivateDetection = FALSE

    Ifstr(i) $(!NTN_InstallMode) == deinstall
        set StartLabel = removeadapter
    else-Ifstr(i) $(!NTN_InstallMode) == update
        set StartLabel = UpgradeSoftware
    else-Ifstr(i) $(!NTN_InstallMode) == bind
        set StartLabel = bindingadapter
    else-Ifstr(i) $(!NTN_InstallMode) == configure
        set CommonStatus = STATUS_REBOOT
        ; set ActivateDetection = TRUE
        set StartLabel = configureadapter
        ;
        ;   You cannot config the software component
        ;
        Ifstr(i) $(ProductKeyName) == $(!NTN_RegBase)
            Debug-Output "Cannot configure the LEC driver software."
            Shell $(UtilityInf),RegistryErrorString,CANNOT_CONFIGURE_SOFTWARE
            ifint $($ShellCode) != $(!SHELL_CODE_OK)
                Debug-Output "ShellCode error: cannot get an error string."
                goto ShellCodeError
            endif
            set Error = $($R0)
            set from = end
            set to = end
            goto nonfatalinfo
        endif
    else
        ; set ActivateDetection = TRUE
        set StartLabel = installadapter
        set OEM_ABANDON_OPTIONS = {}
        set OEM_ABANDON_SOFTWARE = FALSE
        set OEM_ABANDON_ON = TRUE
    endif


    ;===================================================
    ;  Netcard Detection logic
    ;
    ;  Initialize use of netcard detection;
    ;  Construct require global parameter variables
    ;
    Debug-Output "OEMSETUP.INF: =================================================="
    Debug-Output "OEMSETUP.INF: STF_CWDIR is: "$(!STF_CWDIR)
    Debug-Output "OEMSETUP.INF: STF_LANGUAGE is: "$(!STF_LANGUAGE)
    Debug-Output "OEMSETUP.INF: Option is: "$(Option)
    Debug-Output "OEMSETUP.INF: !STF_NCDETECT  is: "$(!STF_NCDETECT)
    Debug-Output "OEMSETUP.INF: !STF_NCOPTION  is: "$(!STF_NCOPTION)
    Debug-Output "OEMSETUP.INF: !STF_NCDETCARD is: "$(!STF_NCDETCARD)
    Debug-Output "OEMSETUP.INF: !STF_NCDETINFO is: "$(!STF_NCDETINFO)
    Debug-Output "OEMSETUP.INF: =================================================="

    Set DetectedCard = FALSE

    Ifstr(i) $(ActivateDetection) != TRUE
        Goto $(StartLabel)
    Endif
    ;
    ;  Set !STF_NC_PARAMS and !STF_NC_PNAMES by calling
    ;    PARAM.INF!Param_BuildTypeLists.
    ;   Pass it a list of the form:
    ;
    ;   {  { <param name>,
    ;        <name of choice list var>,
    ;        <name of default var> },
    ;      ...
    ;   }
    ;
    Set TypeList = {{IRQ, IRQ_List, IRQ_Level},+
                    {IOADDR, IOADDR_Addr_List, IOBaseAddrValue},+
                    {MEMADDR, MemBaseAddrDecList, MemBaseAddrDec},+
                    {TRANSCEIVER, TranceiverValueList, TransceiverValue}}

    Debug-Output "OEMNADE2.INF: Calling Param_BuildTypeLists"
    Shell $(ParamInf) Param_BuildTypeLists $(Option) $(TypeList)
    Set Status = $($R0)
    ifstr(i) $(Status) != STATUS_SUCCESSFUL
        Goto fataldetect
    Endif

    Debug-Output "OEMNADE2.INF: Calling Param_SetDefaults"
    Shell $(ParamInf) Param_SetDefaults {}

    ;  Establish presentation versions of choice lists.

    Shell $(ParamInf) HexListFromDecList $(IOADDR_Addr_List)
    Set IOADDR_Hex_List = $($R0)

    Shell $(UtilityInf) SortList $(IRQ_List) TRUE FALSE
    Set IRQ_List = $($R0)

    ;  If this is a detected card, set the flag.

    Ifstr(i) $(!STF_NCDETECT) == YES
        Ifstr(i) $(!STF_NCOPTION) == $(Option)
           Set DetectedCard = TRUE
           Debug-Output "OEMNADE2.INF: Setting DetectedCard to TRUE"
        Endif
    Endif
    ;
    ;  End Netcard Detection logic
    ;===================================================

    Set MappedValue = 1
    Ifint $(MemBaseAddrDec) == 0
       Set MappedValue = 0
    Endif

    Set from = $(fatal)
    Set to = $(fatal)
    Goto $(StartLabel)


;/****************************************************************************/
;/* InstallOption - install section                                          */
;/****************************************************************************/

installadapter = +

    ; First, check whether the same version of the software exists

    OpenRegKey $(!REG_H_LOCAL) "" $(ProductKeyName) $(MAXIMUM_ALLOWED) KeyProduct

    Ifstr $(KeyProduct) != $(KeyNull)

        ; Same version already existed in the local machine
        ; Popup the dialog and ask the user whether he wants to continue

        CloseRegKey $(KeyProduct)

        ifstr(i) !(NTN_RegBase) == $(ProductKeyName)

           ; Cannot Install the same software again

           Shell $(UtilityInf), VerExistedDlg, $(ProductSoftwareTitle),+
               $(ProductVersion)

           ifint $($ShellCode) != $(!SHELL_CODE_OK)
               Debug-Output "ShellCode error: cannot get an error string."
               goto ShellCodeError
           endif

           goto end

        else

           ; Add a new adapter card?

           Shell $(UtilityInf), CardExistedDlg

           ifint $($ShellCode) != $(!SHELL_CODE_OK)
               Debug-Output "ShellCode error: cannot get an error string."
               goto ShellCodeError
           endif

           ifstr(i) $($R1) != "OK"
               set CommonStatus = STATUS_USERCANCEL
               goto end
           endif
           set OldVersionExisted = $(TRUE)
        endif
    endif

    ;===================================================
    ;  Netcard Detection logic
    ;
    ;   If this is a detected card, query its parameters
    ;   and merge them into the default list.
    ;

    ;  Indicate that there are no old parameter settings.

    Set CurrParamSettings = {}

    Ifstr(i) $(DetectedCard) != TRUE
        Goto adaptersetup
    Endif
    ;
    ;   Get the detected parameters
    ;
    StartWait
    Shell $(ParamInf) Param_QueryCard $(!STF_NCDETCARD)
    EndWait
    Ifstr(i) $($R0) != STATUS_SUCCESSFUL
        Goto adaptersetup
    Endif
    ;
    ;   Merge the detected values in.
    ;
    Set DetectedParams = $($R1)
    Debug-Output "OEMNADE2.INF: Calling Param_SetDefaults to merge detected params"
    Shell $(ParamInf) Param_SetDefaults $(DetectedParams)
    ;
    ;  End Netcard Detection logic
    ;===================================================

    goto adaptersetup


;/****************************************************************************/
;/* InstallOption - configure section                                        */
;/****************************************************************************/

configureadapter = +

    ; Get the current values of all the parameters

    Ifstr $(KeyProduct) == $(KeyNull)
        OpenRegKey $(!REG_H_LOCAL) "" $(!NTN_RegBase) $(MAXIMUM_ALLOWED) KeyProduct
        Ifstr $(KeyProduct) == $(KeyNull)
            set RegistryErrorIndex = CANNOT_FIND_COMPONENT_SERVICE
            Debug-Output "Cannot find component product key"
            goto fatalregistry
        Endif
    Endif

    ; Get the other parameters;  they're attached to the service parameters key

    Debug-Output "INF: Shelling to FindService"

    Shell $(UtilityInf) FindService, $(KeyProduct)
    Ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "INF: FindService shell failure"
        Goto ShellCodeError
    Endif
    Ifstr(i) $($R0) != NO_ERROR
        Debug-Output "INF: FindService Shell error: "$($R0)
        Goto fatalregistry
    endif

    Set KeyParameters = $($R2)

    ;  We don't need the services key, so close it.

    CloseRegKey $($R1)

    Ifstr $(KeyParameters) == $(KeyNull)
        set RegistryErrorIndex = CANNOT_FIND_COMPONENT_SERVICE
        Debug-Output "Cannot find component service"
        goto fatalregistry
    endif

    set OldVersionExisted = $(TRUE)

    set ValueName = ""
    set ValueData = ""
    set ValueStr  = ""
    set ValueList = {}

    ; Get the old values

    EnumRegValue $(KeyParameters) ValueList

    ForListDo $(ValueList)
        set ValueItem = $($)
        set ValueName = *($(ValueItem),1)
        set ValueData = *($(ValueItem),4)
        Ifstr(i) $(ValueName) == "Name"
            set LecName = $(ValueData)
        else-ifstr(i) $(ValueName) == "MediaType"
            ifint $(ValueData) == 1
                set MediumType = 1
            else
                set MediumType = 0
            endif
        endif

    EndForListDo

    ;  Save the settings as they were read from the Registry.

    Shell $(ParamInf) Param_SaveValues
    Set CurrParamSettings = $($R0)

    ; Put up the adapter configuration dialog if necessary.
    ; Note that $(CurrParamSettings) has the old known parameter values.

adaptersetup = +

    Set from = adapteroptions

    ;===================================================
    ;  Netcard Detection logic
    ;
    ;   Check that this card's parameters can be
    ;   fully detected.
    ;
    Shell $(ParamInf) Param_ParameterConfidence
    Ifstr(i) $($R0) != STATUS_SUCCESSFUL
        Debug-Output "OEMNADE2.INF: parameter confidence too low to bypass configuration"
        Goto adapteroptions
    Endif
    ;
    ;   If this is a detected card and we're in EXPRESS mode,
    ;   see if the parameters as they currently exist are
    ;   verifiably correct.
    ;
    Ifstr(i) $(DetectedCard) == TRUE
        Ifstr(i) $(!STF_INSTALL_MODE) != CUSTOM
            Goto adapterverify
        Endif
    Endif
    ;
    ;  End Netcard Detection logic
    ;===================================================

adapteroptions = +

    ifstr(i) $(!STF_GUI_UNATTENDED) == "YES"
        ifstr(i) $(!AutoNetInterfaceType) != ""
            set BusInterfaceType = $(!AutoNetInterfaceType)
        else
            set BusInterfaceType = 1    ;ISA
        endif
        ifstr(i) $(!AutoNetBusNumber) != ""
            set BusNumber = $(!AutoNetBusNumber)
        else
            set BusNumber = 0
        endif
        goto adapterverify
    endif

;    read-syms FileDependentDlg$(!STF_LANGUAGE)

    ifint $(OldVersionExisted) != $(TRUE)
        ifstr(i) $(!NTN_InstallMode) == install
            Shell $(UtilityInf) DoAskSource $(!STF_CWDDIR) $(SrcDir) NO

            ifint $($ShellCode) != $(!SHELL_CODE_OK)
                goto ShellCodeError
            else-ifstr(i) $($R0) == STATUS_FAILED

                Shell $(UtilityInf) RegistryErrorString ASK_SOURCE_FAIL

                ifint $($ShellCode) != $(!SHELL_CODE_OK)
                    goto ShellCodeError
                endif

                set Error = $($R0)
                goto fatal
            else-ifstr(i) $($R0) == STATUS_USERCANCEL
                goto successful
            endif

            Set SrcDir = $($R1)

            Install Install-Helper

            ifstr(i) $(STF_INSTALL_OUTCOME) != STF_SUCCESS
               Shell $(UtilityInf) RegistryErrorString "UNABLE_COPY_FILE"
               ifint $($ShellCode) != $(!SHELL_CODE_OK)
                   goto ShellCodeError
               endif
               set Error = $($R0)
               goto fatal
            endif

            ; Only when we install this, make sure it's event logging is enabled

            LoadLibrary "" $(!STF_WINDOWSSYSPATH)\atmcfg.dll NtLecDll

            LibraryProcedure Result $(NtLecDll) NCPARegisterEventLog

            FreeLibrary $(NtLecDll)
        endif
    endif

    LoadLibrary "" $(!STF_WINDOWSSYSPATH)\atmcfg.dll NtLecDll

    ; Set FLibraryErrCtl = 1

    ifstr(i) $(!NTN_InstallMode) == install

        LibraryProcedure Result $(NtLecDll) NCPAAddAdapter $(!STF_HWND)

    else-ifstr(i) $(!NTN_InstallMode) == configure

        LibraryProcedure Result $(NtLecDll) NCPAConfigAdapter $(!STF_HWND) $(LecName)

    endif

    ; Set FLibraryErrCtl = 0

    ifstr(i) $(Result) == ERROR
        goto end
    endif

    ifstr(i) *($(Result), 1) == "CANCEL"
        set CommonStatus = STATUS_USERCANCEL
        goto end
    else
        set Dependencies = *($(Result), 2)
        set MediumType   = *($(Result), 3)

        ifstr(i) $(!NTN_InstallMode) == install
            set LecName = *($(Result), 4)
        endif
    endif

; Used to request the Bus type and number, but we don't need it for now - with
; only PCI cards, the system can find all the information without our help!

    ifstr(i) $(!STF_NCDETINFO) == {}
        ; not detect. popup dialog.
        Shell $(UtilityInf),GetBusTypeDialog,$(ProductHardware$(Option)Description) $(BusInterfaceType) $(BusNumber)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error."
            goto ShellCodeError
        endif

        set BusInterfaceType = $($R1)
        set BusNumber        = $($R2)
    else
        ; use the STF_NCDETINFO information
        set BusInterfaceType = *($(!STF_NCDETINFO),5)
        set BusNumber = *($(!STF_NCDETINFO),6)
    endif

;    Set FLibraryErrCtl = 1
;
;    LibraryProcedure Result $(NtLecDll) NCPAAddAdapterBusInfo +
;        $(LecName) $(BusInterfaceType) $(BusNumber)
;
;    Set FLibraryErrCtl = 0

adapterverify = +

    ;===================================================
    ;  Netcard Detection logic
    ;
    ;   If this is a detected card, attempt to validate the options
    ;   If just a normal card, try to claim the resources which have
    ;     changed.
    ;
    Ifstr(i) $(DetectedCard) != TRUE

        ;  Build the current parameter list.  If this is an installation,
        ;  (indicated by the fact that the current settings list is empty)
        ;  claim all the parameters; otherwise, just claim those which
        ;  have changed.

        Shell $(ParamInf) Param_SaveValues
        Set NewParamSettings = $($R0)
        Ifstr(i) $(CurrParamSettings) == {}
            Set DiffParamSettings = $(NewParamSettings)
        Else
            Shell $(ParamInf) Param_DiffValues $(CurrParamSettings)
            Set DiffParamSettings = $($R0)
        Endif

        Debug-Output "OEMNADE2.INF: Calling Param_VerifyResources"
        Shell $(ParamInf) Param_VerifyResources $(DiffParamSettings)
        Ifstr(i) $($R0) == STATUS_SUCCESSFUL
            Debug-Output "OEMNADE2.INF: Param_VerifyResources succeeded"
            Goto skipoptions
        Endif
    Else
        Set CardVerifyIndex = $(!STF_NCDETCARD)
        Debug-Output "OEMNADE2.INF: Calling Param_VerifyCard"
        Shell $(ParamInf) Param_VerifyCard $(!STF_NCDETCARD)
        Ifstr(i) $($R0) == STATUS_SUCCESSFUL
            Debug-Output "OEMNADE2.INF: Param_VerifyCard succeeded"
            Goto skipoptions
        Endif
    Endif
    ;
    ;   Give the user a chance to retry or force the options given.
    ;
    Set from = adapteroptions
    Set to   = skipoptions
    Shell $(UtilityInf),RegistryErrorString,VERIFY_WARNING
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "ShellCode error: cannot get an error string."
        goto ShellCodeError
    endif
    set Error = $($R0)
    Goto Warning
    ;
    ;  End Netcard Detection logic
    ;===================================================

;
;   If installing, go create the necessary keys;
;   if configuring, they're already open.
;
skipoptions =+

    ifint $(OldVersionExisted) == $(TRUE)
        ifstr(i) $(!NTN_InstallMode) == configure
            goto writeparameters
        endif
    endif
    StartWait
    ;
    ; Add Software Component
    ;
    ifint $(OldVersionExisted) == $(FALSE)
        ifstr(i) $(!NTN_InstallMode) == "install"

           install "Install-Option"

           ifstr(i) $(STF_INSTALL_OUTCOME) != STF_SUCCESS
              Shell $(UtilityInf) RegistryErrorString "UNABLE_COPY_FILE"
              ifint $($ShellCode) != $(!SHELL_CODE_OK)
                  goto ShellCodeError
              endif
              set Error = $($R0)
              goto fatal
           endif
        endif

        Shell $(UtilityInf), AddSoftwareComponent, $(Manufacturer), +
            $(ProductSoftwareName), +
            $(ProductSoftwareName), +
            $(ProductSoftwareTitle), $(STF_CONTEXTINFNAME), +
            $(ProductSoftwareImagePath), "kernel", "NDIS", +
            {}, "", $(NetEventDLL)

        Set OEM_ABANDON_SOFTWARE = TRUE

        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error"
            goto ShellCodeError
        endif
        ;
        ;   At this point:
        ;     $R1 contains the product version key handle;
        ;     $R2 contains the NetRules subkey handle;
        ;     $R3 contains the new Services key handle; and
        ;     $R4 contains the Parameters key
        ;     $R5 contains the Linkage Key
        ;
        set RegistryErrorIndex = $($R0)
        set KeyProduct      = $($R1)
        set SoftNetRulesKey = $($R2)
        set LinkageKey      = $($R5)
        CloseRegKey $($R3)
        CloseRegKey $($R4)

        Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
            EndWait
            Debug-Output "Registry error: add software components"
            CloseRegKey $(KeyProduct)
            CloseRegKey $(SoftNetRulesKey)
            CloseRegKey $(LinkageKey)
            goto fatalregistry
        endif

        set NewValueList = {{SoftwareType,$(NoTitle),$(!REG_VT_SZ),$(SoftwareType)},+
                           {MajorVersion,$(NoTitle),$(!REG_VT_DWORD),$(ProductMajorVersion)},+
                           {MinorVersion,$(NoTitle),$(!REG_VT_DWORD),$(ProductMinorVersion)},+
                           {Title,$(NoTitle),$(!REG_VT_SZ),$(ProductSoftwareTitle)},+
                           {Description,$(NoTitle),$(!REG_VT_SZ),$(ProductSoftwareDescription)},+
                           {ServiceName,$(NoTitle),$(!REG_VT_SZ),$(ProductSoftwareName)},+
                           {InstallDate,$(NoTitle),$(!REG_VT_DWORD),*($(Now),1)}}

        Shell  $(UtilityInf), AddValueList, $(KeyProduct), $(NewValueList)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error."
            goto ShellCodeError
        endif

        set RegistryErrorIndex = $($R0)

        Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
            EndWait
            Debug-Output "Registry error: add value list."
            CloseRegKey $(KeyProduct)
            CloseRegKey $(SoftNetRulesKey)
            CloseRegKey $(LinkageKey)
            goto fatalregistry
        endif

        set NewValueList = {{type,$(NoTitle),$(!REG_VT_SZ),$(NetRuleSoftwareType)},+
                            {use,$(NoTitle),$(!REG_VT_SZ),$(NetRuleSoftwareUse)}, +
                            {bindform,$(NoTitle),$(!REG_VT_SZ),$(NetRuleSoftwareBindForm)}, +
                            {class,$(NoTitle),$(!REG_VT_MULTI_SZ),$(NetRuleSoftwareClass)}, +
                            {bindable,$(NoTitle),$(!REG_VT_MULTI_SZ),$(NetRuleSoftwareBindable)}, +
                            {InfOption,$(NoTitle),$(!REG_VT_SZ),$(Option)}}

        Shell  $(UtilityInf), AddValueList, $(SoftNetRulesKey), $(NewValueList)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error."
            goto ShellCodeError
        endif

        set RegistryErrorIndex = $($R0)

        CloseRegKey $(KeyProduct)
        CloseRegKey $(SoftNetRulesKey)
        CloseRegKey $(LinkageKey)

        Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
            EndWait
            Debug-Output "Resgitry error: add value list."
            CloseRegKey $(LinkageKey)
            goto fatalregistry
        endif
    endif
;
;   Create the HARDWARE\Netcard region and its corresponding service
;
    Shell $(UtilityInf), AddHardwareComponent, $(ProductHardwareName),$(STF_CONTEXTINFNAME),$(ProductKeyName)

    ifint $($R4) != -1
        Set OEM_ABANDON_OPTIONS = >($(OEM_ABANDON_OPTIONS), $(!NTN_SoftwareBase)"\Microsoft\Windows NT\CurrentVersion\NetworkCards\"$($R4))
    endif

    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "Cannot add hardware component"
        goto ShellCodeError
    endif

    set RegistryErrorIndex = $($R0)

    Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
        EndWait
        Debug-Output "Registry error: add hardware component"
        CloseRegKey $($R1)
        CloseRegKey $($R2)
        CloseRegKey $($R3)
        goto fatalregistry
    endif

;
;   At this point:
;     $R1  Registry key variable for HARDWARE\Netcard\(n)
;     $R2  Registry key variable for HARDWARE\Netcard\(n)\\NetRules
;     $R3  Registry key handle for <service>\Parameters key
;     $R4  Adapter number assigned to adapter
;     $R5  Service name generated by combining svc name with adapter number
;
    set KeyParameters = $($R3)
    set KeyAdapterRules = $($R2)
    set AdapterNumber = $($R4)

    set NewValueList = {{Manufacturer,$(NoTitle),$(!REG_VT_SZ),$(Manufacturer)},+
                       {Title,$(NoTitle),$(!REG_VT_SZ),"["$($R4)"] "$(ProductHardware$(Option)Title)},+
                       {Description,$(NoTitle),$(!REG_VT_SZ),$(ProductHardware$(Option)Description)},+
                       {ProductName,$(NoTitle),$(!REG_VT_SZ),$(ProductHardwareName)},+
                       {ServiceName,$(NoTitle),$(!REG_VT_SZ),$($R5)},+
                       {InstallDate,$(NoTitle),$(!REG_VT_DWORD),*($(Now),1)}}

    Shell  $(UtilityInf), AddValueList, $($R1), $(NewValueList)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "ShellCode error"
        goto ShellCodeError
    endif

    CloseRegKey $($R1)

    set TempProdName = """"$(ProductHardwareName)$(AdapterNumber)""""
    set TempBindForm = $(TempProdName)$(NetRuleHardwareBindForm)

    set NewValueList = {{type,$(NoTitle),$(!REG_VT_SZ),$(NetRuleHardwareType)},+
                        {bindform,$(NoTitle),$(!REG_VT_SZ),$(TempBindForm)}, +
                        {class,$(NoTitle),$(!REG_VT_MULTI_SZ),$(NetRuleHardwareClass)}, +
                        {InfOption,$(NoTitle),$(!REG_VT_SZ),$(Option)}}

    Shell  $(UtilityInf), AddValueList, $(KeyAdapterRules), $(NewValueList)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "ShellCode error."
        goto ShellCodeError
    endif

    set RegistryErrorIndex = $($R0)

    Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
        EndWait
        Debug-Output "Resgitry error: add value list."
        CloseRegKey $(KeyParameters)
        CloseRegKey $(KeyAdapterRules)
        goto fatalregistry
    endif

    CloseRegKey $(KeyAdapterRules)

    goto writeparameters
;
;   REQUIRED:   $(KeyParameters) contains service Parameters key handle
;
writeparameters = +
;
;   Add the service dependency key
;

    OpenRegKey $(!REG_H_LOCAL) "" $(LinkageKeyName) $(MAXIMUM_ALLOWED) KeyLinkage

    Ifstr $(KeyLinkage) == $(KeyNull)
        Debug-Output "Cannot find service linkage subkey"
        set RegistryError = CANNOT_FIND_COMPONENT_SERVICE
        goto fatalregistry
    Endif

    SetRegValue $(KeyLinkage) +
        {OtherDependencies, $(NoTitle), $(!REG_VT_MULTI_SZ), $(Dependencies)}

    CloseRegKey $(KeyLinkage)

    ifint $(RegLastError) != 0
        Debug-Output "Failed to set OtherDependencies"
        set Error = "Failed to write OtherDependencies value"
        goto fatal
    endif

; Add the rest of the parameters to the Services area

    Set NewValueList = {{Name,$(NoTitle),$(!REG_VT_SZ),$(LecName)}, +
        {BusType,$(NoTitle),$(!REG_VT_DWORD),$(BusInterfaceType)}, +
        {BusNumber,$(NoTitle),$(!REG_VT_DWORD),$(BusNumber)}}
                        
    ifint $(MediumType) != 0
        ; Set MediaType = Ethernet
        Set NewValueList = >($(NewValueList), +
            {MediaType,$(NoTitle),$(!REG_VT_DWORD),1})
    else
        ; Set MediaType = Token Ring
        Set NewValueList = >($(NewValueList), +
            {MediaType,$(NoTitle),$(!REG_VT_DWORD),2})
    endif

    Shell  $(UtilityInf), AddValueList, $(KeyParameters), $(NewValueList)

    ifstr(i) $(!STF_GUI_UNATTENDED) == "YES"
        Shell $(UtilityInf),AddDefaultNetCardParameters,$(KeyParameters)
    endif

    CloseRegKey $(KeyParameters)

    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "ShellCode error. (Add Value List)"
        goto ShellCodeError
    endif

    set RegistryErrorIndex = $($R0)

    Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
        Debug-Output "Registry error: Add value list"
        goto fatalregistry
    endif

    goto successful


;/****************************************************************************/
;/* InstallOption - bind section                                             */
;/****************************************************************************/

bindingadapter = +
    set Error = "Binding: Sorry, not yet implemented."
    goto fatal


;/****************************************************************************/
;/* InstallOption - deinstall section                                        */
;/****************************************************************************/

removeadapter = +
    Ifstr(i) $(ProductKeyName) == $(!NTN_RegBase)
        ; Remove Software Component
        Shell $(UtilityInf), RemoveSoftwareComponent, $(Manufacturer), +
            $(ProductSoftwareName)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error"
            goto ShellCodeError
        endif

        set RegistryErrorIndex = $($R0)

        Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
            goto fatalregistry
        endif
    else
        ; Call our support routine to update the INFO file etc.
        ; We MUST do this before calling RemoveHardwareComponent, because we
        ; need to use $(!NTN_RegBase)

        LoadLibrary "" $(!STF_WINDOWSSYSPATH)\atmcfg.dll NtLecDll

;        Set FLibraryErrCtl = 1

        LibraryProcedure Result $(NtLecDll) NCPARemoveAdapter +
            $(!STF_HWND) $(!NTN_RegBase)

;        Set FLibraryErrCtl = 0

        ifstr(i) *($(Result),1) != SUCCESS
            goto end
        endif

        ; Before we remove the LEC, we need to update the MAAL dependencies...

        OpenRegKey $(!REG_H_LOCAL) "" $(LinkageKeyName) $(MAXIMUM_ALLOWED) KeyLinkage

        Ifstr $(KeyLinkage) == $(KeyNull)
            Debug-Output "Cannot find service linkage subkey"
            set RegistryError = CANNOT_FIND_COMPONENT_SERVICE
            goto fatalregistry
        Endif

        SetRegValue $(KeyLinkage) +
            {OtherDependencies, $(NoTitle), $(!REG_VT_MULTI_SZ), *($(Result), 2)}

        CloseRegKey $(KeyLinkage)

        ifint $(RegLastError) != 0
            Debug-Output "Failed to set OtherDependencies"
            set Error = "Failed to write OtherDependencies value"
            goto fatal
        endif

        Shell $(UtilityInf), RemoveHardwareComponent, $(Manufacturer), +
            $(ProductSoftwareName), $(!NTN_RegBase)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error"
            goto ShellCodeError
        endif

        set RegistryErrorIndex = $($R0)

        Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
            goto fatalregistry
        endif
    endif

    goto end


;/****************************************************************************/
;/* InstallOption - update section                                           */
;/****************************************************************************/

UpgradeSoftware = +
    ; Upgrade software component
    ;
    OpenRegKey $(!REG_H_LOCAL) "" $(ProductKeyName) $(MAXIMUM_ALLOWED) KeyProduct

    Ifstr $(KeyProduct) != $(KeyNull)

        install "Install-Update"
        ifstr(i) $(STF_INSTALL_OUTCOME) != STF_SUCCESS
            goto fatal
        endif

        ; Upgrade the version number
        ;
        SetRegValue $(KeyProduct) {MajorVersion,$(NoTitle),$(!REG_VT_SZ),$(ProductMajorVersion)}
        SetRegValue $(KeyProduct) {MinorVersion,$(NoTitle),$(!REG_VT_SZ),$(ProductMinorVersion)}

        ;
        ; do nothing for update
        ;
        CloseRegKey $(KeyProduct)
    else
        ;
        ; Cannot Open software key, goto ERROR
        ;
        goto fatalregistry
    endif

    goto end


;/****************************************************************************/
;/* InstallOption - exit routes                                              */
;/****************************************************************************/

;  Escape hatches

successful = +
    goto end

abandon = +
    ForListDo $(OEM_ABANDON_OPTIONS)
        Shell $(UtilityInf), RemoveHardwareComponent, $(Manufacturer), +
            $(ProductSoftwareName), $($)
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error"
            goto ShellCodeError
        endif

        set RegistryErrorIndex = $($R0)

        Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
            goto fatalregistry
        endif
    EndForListDo

    Ifstr(i) $(OEM_ABANDON_SOFTWARE) == TRUE
        ; Remove Software Component
        Shell $(UtilityInf), RemoveSoftwareComponent, $(Manufacturer), +
            $(ProductSoftwareName), FALSE
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            Debug-Output "ShellCode error"
            goto ShellCodeError
        endif

        set RegistryErrorIndex = $($R0)

        Ifstr(i) $(RegistryErrorIndex) != NO_ERROR
            goto fatalregistry
        endif
    endif

    goto end

;
; warning display
;
warning = +
    Shell $(subroutineinf) SetupMessage, $(!STF_LANGUAGE), "WARNING", $(Error)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        goto ShellCodeError
    endif
    ifstr(i) $($R1) == "OK"
        goto $(to)
    else-ifstr(i) $($R1) == "CANCEL"
        goto $(from)
    else
        goto "end"
    endif
;
; non fatal error display
;
nonfatalinfo = +
    Set Severity = STATUS
    Set CommonStatus = STATUS_USERCANCEL
    goto nonfatalmsg
nonfatal = +
    Set Severity = NONFATAL
    goto nonfatalmsg
nonfatalmsg = +
    ifstr(i) $(Error) == ""
        Set Severity = NONFATAL
        Shell $(UtilityInf) RegistryErrorString "SETUP_FAIL"
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            goto ShellCodeError
        endif
        set Error = $($R0)
    endif
    Shell $(subroutineinf) SetupMessage, $(!STF_LANGUAGE), $(Severity), $(Error)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        goto ShellCodeError
    endif
    ifstr(i) $($R1) == "OK"
        goto $(from)
    else
        goto "end"
    endif

;
;  Registry is broken
;
fatalregistry = +
    Shell $(UtilityInf) RegistryErrorString $(RegistryErrorIndex)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        goto ShellCodeError
    endif
    set Error = $($R0)
    goto fatal
;
;  Netcard detection failure
;
fataldetect = +
    Shell $(UtilityInf),RegistryErrorString,CANNOT_DETECT
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        Debug-Output "ShellCode error: cannot get an error string."
        goto ShellCodeError
    endif
    set Error = $($R0)
    Goto fatal
;
; fatal error display
;
fatal = +
    ifstr(i) $(Error) == ""
        Shell $(UtilityInf) RegistryErrorString "SETUP_FAIL"
        ifint $($ShellCode) != $(!SHELL_CODE_OK)
            goto ShellCodeError
        endif
        set Error = $($R0)
    endif
    Shell $(subroutineinf) SetupMessage, $(!STF_LANGUAGE), "FATAL", $(Error)
    ifint $($ShellCode) != $(!SHELL_CODE_OK)
        goto ShellCodeError
    endif

    goto setfailed

;
;  Shelling error
;
ShellCodeError = +
    set DlgType      = "MessageBox"
    set STF_MB_TITLE = $(ShellCodeErrorTitle)
    set STF_MB_TEXT  = $(ShellCodeErrorText)
    set STF_MB_TYPE  = 1
    set STF_MB_ICON  = 3
    set STF_MB_DEF   = 1
    ui start "Error Message"
    goto setfailed

setfailed = +
    set CommonStatus = STATUS_FAILED
    ;
    ; if OEM_ABANDON_ON == TRUE, then remove the registry entries
    ;
    ifstr(i) $(OEM_ABANDON_ON) == TRUE
        set OEM_ABANDON_ON = FALSE
        goto abandon
    endif
    goto end

end = +
    ifstr $(NtLecDll) != $(KeyNull)
        FreeLibrary $(NtLecDll)
    endif

    EndWait

    goto term

term = +

    Return $(CommonStatus)


;/****************************************************************************/
;/*                                                                          */
;/* Mandatory section - Source Media Descriptions                            */
;/*                                                                          */
;/****************************************************************************/

[Source Media Descriptions]
;    1 = "Madge ATM Drivers - NDIS3", TAGFILE = disk4
     1 = "Windows NT DRVLIB"

[Signature]
    FileType = MICROSOFT_DRVLIB_FILE
[GetSignature]
    read-syms Signature
    return $(FileType)

;/****************************************************************************/
;/*                                                                          */
;/* Install sections                                                         */
;/*                                                                          */
;/****************************************************************************/

[Files-Helper]
    1, ATMCFG.DLL
    1, ATMCFG.HLP


[Files-LEC]
    1, AMUX.SYS
    1, COL25.SYS
    1, COL155.SYS
    1, NTLEC.SYS

[Install-Helper]
    set STF_VITAL = ""
    AddSectionFilesToCopyList Files-Helper $(SrcDir) $(!STF_WINDOWSSYSPATH)
    set !STF_NCPA_FLUSH_COPYLIST = TRUE
    CopyFilesInCopyList
    Exit


[Install-Option]
    set STF_VITAL = ""
    ifstr(i) $(AddCopy) == "YES"
        AddSectionFilesToCopyList Files-$(Option) $(SrcDir) $(!STF_WINDOWSSYSPATH)\drivers
    endif
    ifstr(i) $(DoCopy) == "YES"
       set !STF_NCPA_FLUSH_COPYLIST = TRUE
       CopyFilesInCopyList
    endif
    exit


[Install-Update]
    set STF_VITAL        = ""
    set STF_OVERWRITE    = "VERIFYSOURCEOLDER"
    ;set STF_VERSION     = "YES"
    AddSectionFilesToCopyList Files-$(Option) $(SrcDir) $(!STF_WINDOWSSYSPATH)\drivers
    AddSectionFilesToCopyList Files-Helper    $(SrcDir) $(!STF_WINDOWSSYSPATH)
    CopyFilesInCopyList
    exit


;/****************************************************************************/
;/*                                                                          */
;/* Language dependent sections                                              */
;/*                                                                          */
;/****************************************************************************/

[OptionsTextENG]
    LEC = "Madge ATM LAN Emulation Client"


[FileConstantsENG]
    
    ; General setup title string

    FunctionTitle = "Madge NDIS3 LEC Configuration"

    ; Software text strings

    ProductSoftwareTitle          = "Madge NDIS3 LEC Driver"
    ProductSoftwareDescription    = "Madge NDIS3 LEC Driver for ATM"

    ; Hardware text strings

    ProductHardwareLECTitle       = "Madge Lan Emulation Client"
    ProductHardwareLECDescription = "Madge Lan Emulation Client for ATM"

    ; "Copy files" dialog box text strings

    ProCaption   = "Windows NT Setup"
    ProCancel    = "Cancel"
    ProCancelMsg = "Windows NT Networking is not correctly installed."+
                   "Are you sure you want to cancel copying files?"
    ProCancelCap = "Network Setup Message"
    ProText1     = "Copying:"
    ProText2     = "To:"

    ; Shell code error message box text strings

    ShellCodeErrorTitle = "Error: "$(FunctionTitle)
    ShellCodeErrorText  = "Shell Code Error"


[DialogConstantsENG]
    Cancel   = "Cancel"
    Continue = "Continue"
    Exit     = "Cancel"
    Help     = "Help"
    Ok       = "Ok"


;/****************************************************************************/
;/*                                                                          */
;/* End of file                                                              */
;/*                                                                          */
;/****************************************************************************/
