Set NewSystem$Dir <Obey$Dir>

If "<System$Dir>"="" Then Error 0 Couldn't find your !System folder - has the machine been booted properly?
If "<Boot$Dir>"="" Then Error 0 Couldn't find your !Boot folder - has the machine been booted properly?

| Drop new !Run / !Boot files in if necessary and create new structure
|

Set NewSysNeeded 0
RMensure UtilityModule 4.00 IfThere <System$Dir>.SysPaths Then Set NewSysNeeded 0 Else Set NewSysNeeded 1
If "<NewSysNeeded>"="1" Then Copy <NewSystem$Dir>.NewSystem <System$Dir> ~A~C~DF~L~N~P~Q~R~S~T~V
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.310
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.350
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.360
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.370
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.310.Modules
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.350.Modules
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.360.Modules
If "<NewSysNeeded>"="1" Then CDir <System$Dir>.370.Modules
If "<NewSysNeeded>"="1" Then Filer_Run <System$Dir>.!Run

| Add UnplugTbox file if not present
Set NewSysUnplugAdd 1
IfThere <Boot$Dir>.utils.UnplugTBox Then Set NewSysUnplugAdd 0
IfThere <Boot$Dir>.Choices.Boot.PreDesk.UnplugTBox Then Set NewSysUnplugAdd 0
RMEnsure UtilityModule 4.00 If "<NewSysUnplugAdd>"="1" Then Copy <NewSystem$Dir>.UnplugTBox <Boot$Dir>.Choices.Boot.PreDesk.UnplugTBox ~A~C~DF~L~N~P~Q~R~S~T~V

| Tidy up wrongly-installed Toolbox modules
|
IfThere <System$Dir>.360.Modules.Toolbox.Toolbox Then Set Movetoolbox360 1 Else Set Movetoolbox360 0
If "<Movetoolbox360>"="1" Then Copy <System$Dir>.360.Modules.Toolbox <System$Dir>.310.Modules.Toolbox A~CDFN~P~QR~S~T~V
If "<Movetoolbox360>"="1" Then Wipe <System$Dir>.360.Modules.Toolbox ~CFR~V

IfThere <System$Dir>.370.Modules.Toolbox.Toolbox  Then Set Movetoolbox370 1 Else Set Movetoolbox370 0
If "<Movetoolbox370>"="1" Then Copy <System$Dir>.370.Modules.Toolbox <System$Dir>.310.Modules.Toolbox A~CDFN~P~QR~S~T~V
If "<Movetoolbox370>"="1" Then Wipe <System$Dir>.370.Modules.Toolbox ~CFR~V

IfThere <System$Dir>.400.Modules.Toolbox.Toolbox  Then Set Movetoolbox400 1 Else Set Movetoolbox400 0
If "<Movetoolbox400>"="1" Then Copy <System$Dir>.400.Modules.Toolbox <System$Dir>.310.Modules.Toolbox A~CDFN~P~QR~S~T~V
If "<Movetoolbox400>"="1" Then Wipe <System$Dir>.400.Modules.Toolbox ~CFR~V

IfThere <System$Dir>.Modules.Toolbox.Toolbox  Then Set MovetoolboxSys 1 Else Set MovetoolboxSys 0
If "<MovetoolboxSys>"="1" Then Copy <System$Dir>.Modules.Toolbox <System$Dir>.310.Modules.Toolbox A~CDFN~P~QR~S~T~V
If "<MovetoolboxSys>"="1" Then Wipe <System$Dir>.Modules.Toolbox ~CFR~V


|Now copy in any toolbox files that need updating - relies on !InstallPC having been seen
Wimpslot -min 320k -max 320k
InstallPCRes:_uz -C -u -o InstallPCRes:Boot Resources/!System/* Choices/Boot/PreDesk/UnplugTBox -d <Boot$Dir> >null:$ 2>null:$

Unset NewSysNeeded
Unset NewSysUnplugAdd
Unset Movetoolbox350
Unset Movetoolbox360
Unset Movetoolbox370
Unset Movetoolbox400
Unset MovetoolboxSys

|Now uplug the toolbox modules in the system ROM for ROS3.6 or 3.70, but not 3.50 (no modules), or 4.00 ('cos they're OK). 
|This is brutal but UnplugTbox doesn't do it half the time....

Set UpdateSysROS350 1
RMEnsure UtilityModule 4.00 Set UpdateSysROS350 0
RMEnsure UtilityModule 3.60 Set UpdateSysROS350 1
If "<UpdateSysROS350>"="0" Then Unplug Toolbox
If "<UpdateSysROS350>"="0" Then Unplug Window
If "<UpdateSysROS350>"="0" Then Unplug Menu
If "<UpdateSysROS350>"="0" Then Unplug Iconbar
If "<UpdateSysROS350>"="0" Then Unplug ColourDbox
If "<UpdateSysROS350>"="0" Then Unplug ColourMenu
If "<UpdateSysROS350>"="0" Then Unplug DCS
If "<UpdateSysROS350>"="0" Then Unplug FileInfo
If "<UpdateSysROS350>"="0" Then Unplug FontDbox
If "<UpdateSysROS350>"="0" Then Unplug FontMenu
If "<UpdateSysROS350>"="0" Then Unplug PrintDbox
If "<UpdateSysROS350>"="0" Then Unplug ProgInfo
If "<UpdateSysROS350>"="0" Then Unplug SaveAs
If "<UpdateSysROS350>"="0" Then Unplug Scale
Unset UpdateSysROS350

Error 0 Your !System structure and toolbox modules are now up to date. Please re-boot for the changes to take effect.
