# install.mscr - Used for post processing of a cab installation
# Notes:
# - Requires MortScript's setup.dll to be used by the cab.
# - MortScript.exe must be installed in the %installDir% along with this script
# 

# what is our path?
instPath = SystemPath( "ScriptPath" )

# check if icon resource needs updating?
iconFile = "ScriptIcons.dll"
iconVersReq = 5
iconVers = 0
iconRefCount = 0

If ( FileExists( instPath \ iconFile ) )
   If ( FileExists( "\Windows" \ iconFile ) )
      If ( RegValueExists( "HKLM", "Software\Mort's MortScript", "ScriptIconsVersion" ) )
         iconVers = RegRead( "HKLM", "Software\Mort's MortScript", "ScriptIconsVersion" )
         iconRefCount = RegRead( "HKLM", "Software\Mort's MortScript", "ScriptIconsRefCount" )
      EndIf

      If ( iconVers < iconVersReq )
         Copy( instPath \ iconFile , "\Windows" \ iconFile, 125 )
         RegWriteString( "HKLM", "Software\Mort's MortScript", "ScriptIconsVersion", iconVersReq )
      EndIf

      iconRefCount = iconRefCount + 1
      RegWriteDWord( "HKLM", "Software\Mort's MortScript", "ScriptIconsRefCount", iconRefCount )
   Else
      Copy( instPath \ iconFile , "\Windows" \ iconFile, 1 )
      RegWriteString( "HKLM", "Software\Mort's MortScript", "ScriptIconsVersion", iconVersReq 
      RegWriteDWord( "HKLM", "Software\Mort's MortScript", "ScriptIconsRefCount", 1 )
   EndIf
EndIf

Delete( instPath \ iconFile )


ShowWaitCursor

# Make sure there is a MortScript.exe on the device for this app
# even if installing to the storage card
If ( Find( instPath, "\Storage Card" ) = 1 )
   msPath = SubStr( instPath, 14 )
   If ( NOT DirExists( msPath ) )
      MkDir( msPath )
   EndIf
   Copy( instPath \ "MortScript.exe", msPath \ "MortScript.exe", 1 )
Else
   msPath = instPath
EndIf 

# remove previous version's reg settings
If ( RegKeyExists( "HKLM", "Software\Mort's MortScript\IE Toggle" ) )
   RegDeleteKey( "HKLM", "Software\Mort's MortScript\IE Toggle", YES, NO )
EndIf 

# install the app shortcut. Use the MortScript.exe on the device

CreateShortcut( "\Windows\Start Menu\Programs\IE Toggle.lnk",\
      """" & msPath \ "MortScript.exe"" /wait=15 """ & instPath \ "IE Toggle.mscr""?ScriptIcons.dll,-122" )
