// Update.inc - Update related shell routines

[LegacyFilesList]
// Desc.               Section                Dest. Dir
// ---------------------------------------------------------------------------------
   "SxbDiag Files"   = Files-SxbDiag,        $(!STF_WINDOWSSYSPATH)

//
//	Updates all of the package files
//
//		$0 = Option (Adapter type to update)
//		$1 = Source Dir
//		$2 = $(AddCopy)
//		$3 = $(DoCopy)
//
//    $R0 = Success
//
[UpdateAllFiles]
	read-syms GlobalConstants
	read-syms GlobalRegistryConstants
	read-syms GlobalPathConstants
	read-syms DriverConstants
	read-syms Identification
	read-syms DriverPackageConstants

	set Option = $($0)
	set SrcDir = $($1)
	set AddCopy = $($2)
	set DoCopy = $($3)
	_Enter("UpdateAllFiles", _Show(Option)_Show(SrcDir)_Show(AddCopy)_Show(DoCopy))

   set Success = FALSE

   set FileListSectionsToUpdate = { +
      DetectionFilesList, +
      CoreFilesList, +
#if defined(SUPPORT_HOUSTON)
      CoreFilesList-Houston, +
#endif
#if defined(SUPPORT_LONDON)
      CoreFilesList-London, +
#endif
#if defined(SUPPORT_CHASKA)
      CoreFilesList-Chaska, +
#endif
#if defined(SUPPORT_CLYDESDALE)
      CoreFilesList-Clydesdale, +
#endif
#if defined(SUPPORT_SYNC570)
      CoreFilesList-Sync570, +
#endif
#if defined(SUPPORT_ACCELEPORT_2000)
      CoreFilesList-AccelePort2000, +
#endif
      }

   ForListDo $(FileListSectionsToUpdate)

      set FileListSection = $($)

      set DescList = ^($(FileListSection), 0)
      ForListDo $(DescList)

         set Desc = $($)
         set Section = #($(FileListSection), $(Desc), 1)
         set DstDir = #($(FileListSection), $(Desc), 2)

	      _Trace("Adding "$(Desc)" for update", _Show(Section)_Show(DstDir))
         Install Install-AddFiles

      EndForListDo
   EndForListDo

	read-syms UpdateProgress-Strings-$(!STF_LANGUAGE)
   Install Install-CopyFiles
	ifstr(i) $(STF_INSTALL_OUTCOME) != "STF_SUCCESS"
      _AssertMsg(FALSE, _Show1(STF_INSTALL_OUTCOME))
      _OnUtilityShellErrorGoto("UNABLE_COPY_FILE", Exit)
   endif

   // Delete legacy files
   _LocalShell ClearRemoveList
   set DescList = ^(LegacyFilesList, 0)
   ForListDo $(DescList)

      set Desc = $($)
      set Section = #(LegacyFilesList, $(Desc), 1)
      set DstDir = #(LegacyFilesList, $(Desc), 2)
	   _Trace("Adding "$(Desc)" for deletion", _Show(Section)_Show(DstDir))
      _LocalShell AddSectionFilesToRemoveList $(Section) $(DstDir)

   EndForListDo
	_LocalShell RemoveFilesInRemoveList

	_GetRegSzByName $(PackageKeyName)"\\NetRules" "InfName"
   _AssertGoto($($R0), Exit)
	set InfName = $($R1)
	set InfPath = $(!STF_WINDOWSSYSPATH)"\\"$(InfName)

	_Call("CopySingleFile", _Show(STF_CONTEXTINFNAME)_Show(InfPath))
   ifstr(i) $(!NTVER) == "3.51"
      LibraryProcedure Result $(!LIBHANDLE) CopySingleFile $(STF_CONTEXTINFNAME) $(InfPath)
   else
      LibraryProcedure Result $(!NCPA_HANDLE) CopySingleFile $(!STF_HWND) $(STF_CONTEXTINFNAME) $(InfPath)
   endif
	_Return("CopySingleFile", _Show(Result))

   set Success = TRUE

Exit = +

	_Exit("UpdateAllFiles", _Show(Success))
	Return $(Success)

//
//	Updates an adapter
//
//		$0 = Option (Adapter type to update)
//		$1 = Source Dir
//		$2 = $(AddCopy)
//		$3 = $(DoCopy)
//		$4 = $(DoConfig)
//
//		$R0 = Status (STATUS_*)
//
[UpdateMode]
	read-syms GlobalConstants
	read-syms GlobalRegistryConstants
	read-syms GlobalPathConstants
	read-syms DriverConstants
	read-syms Identification
	read-syms DriverPackageConstants
	read-syms InstallMessages-$(!STF_LANGUAGE)
	read-syms UpdateMessages-$(!NTVER)-$(!STF_LANGUAGE)

	set Option = $($0)
	set SrcDir = $($1)
	set AddCopy = $($2)
	set DoCopy = $($3)
	set DoConfig = $($4)
	_Enter("UpdateMode", _Show(Option)_Show(SrcDir)_Show(AddCopy)_Show(DoCopy)_Show(DoConfig))

	set Status = "STATUS_USERCANCEL"

	_LocalShell GetExistingSoftwareVersion
	set OnDiskVersion = $($R1)

	// Convert version strings to integers for comparison.
	_LocalShell NumericVersion $(OnDiskVersion)
	set IntOnDiskVersion = $($R0)
	_LocalShell NumericVersion $(InstallVersion)
	set IntInstallVersion = $($R0)

	ifint $(IntInstallVersion) == $(IntOnDiskVersion)
		_LocalShell StatusMessage $(AlreadyUpdated)
		goto Exit
	endif

	ifint $(IntInstallVersion) < $(IntOnDiskVersion)
		_LocalShell StatusMessage $(NewerInstalled)
		goto Exit
	endif

   _LocalShell MessageBox $(UpdateWarningTitle) $(UpdateWarning) MB_YESNO MB_ICONINFORMATION MB_DEFBUTTON1
   ifstr(i) $($R0) != "YES"
		_LocalShell StatusMessage $(UpdateLater)
      set Status = "STATUS_USERCANCEL"
		goto Exit
   endif

	set Status = "STATUS_FAILED"
	_LocalShell UpdateAllFiles $(Option) $(SrcDir) $(AddCopy) $(DoCopy)
   _AssertGoto($($R0), Exit)

   _LocalShell WriteConfigData

	// Install the PAMA service here during the update since it was added sometime
	// after the first couple of releases.  This isn't going to hurt anything if it
	// is already installed since the AddServer functions first to see if it's already
	// installed.
	_LocalShell AddService "PAMA"
   _AssertGoto($($R0), Error)
	set InstalledDriverList = >($(InstalledDriverList), "PAMA")

	_SubroutineShell PopBillboard
	read-syms UpdateConstants
	LoadLibrary "x" $(UPDATEDLL_PATH) DIGIHANDLE
	_Call("LibraryProcedure Update", _Show(!STF_HWND)_Show(Option))
	LibraryProcedure Result $(DIGIHANDLE) Update $(!STF_HWND) $(Option)
	_Return("LibraryProcedure Update", _Show(Result))
	FreeLibrary $(DIGIHANDLE)

   ifstr(i) $(Result) != "OK"
		_LocalShell SetupMessage "FATAL" $(UpdateFailed)
   else
		_LocalShell InstallDiags $(Option) $(SrcDir) $(AddCopy) $(DoCopy)
		_AssertGoto($($R0), Error)
		_LocalShell StatusMessage $(UpdateSucceded)
   endif

   set Status = "STATUS_SUCCESSFUL"

Exit = +

	_Exit("UpdateMode", _Show(Status))
	Return $(Status)
