
--Get the root maxscript directory using the MaxUtils plugin.
maxPlugPath = maxUtils.getPluginPath() as stringStream
maxPlugDir = getFilenameFile (maxPlugPath as string)
skipToString maxPlugPath maxPlugDir
dirMarker = filePos maxPlugPath
seek maxPlugPath 0
fsScriptPath = substring (maxPlugPath as string) 1 (dirMarker - maxPlugDir.count)

--Create a macroscript for the attach point tool
macroscript AttachPointTool category:"Tools" tooltip:"Attach Point Tool"
(
	local scriptFileIn = openFile (fsScriptPath + "AttachTool.ms")
	execute scriptFileIn
)

--Create a macroscript for the animation manager
macroscript AnimationManager category:"Tools" tooltip:"Start the FSX Animation Manager"
(
	StartFSXAnimationEditor();
)

--Create a macroscript for the cloud tool
macroscript FSCloudTool category:"Tools" tooltip:"Flight Simulator Cloud Tool"
(
	local scriptFileIn = openFile (fsScriptPath + "CloudTool.ms")
	execute scriptFileIn
)

--Try to remove the FSTools menu if it is found
fsToolsMenu = menuMan.findMenu "FS Tools"
try
(
	menuMan.unregisterMenu fsToolsMenu
)
catch()

--Create a new classID for the tools menu
newMenuID = genClassID returnValue:true

--Recreate the tools menu (this needs to be done on every startup, otherwise the tools will get cached and not update if there is a change
if menuMan.registerMenuContext newMenuID[1] then
(
	mainMenuBar = menuMan.getMainMenuBar ()
	subMenu = menuMan.createMenu "FS Tools"
	attachItem = menuMan.createActionItem "AttachPointTool" "Tools"
	fsxAnimItem = menuMan.createActionItem "AnimationManager" "Tools"
	cloudItem = menuMan.createActionItem "FSCloudTool" "Tools"
	subMenu.addItem attachItem -1
	subMenu.addItem fsxAnimItem -1
	subMenu.addItem cloudItem -1
	subMenuItem = menuMan.createSubMenuItem "FS Tools" subMenu
	subMenuIndex = mainMenuBar.numItems() + 1
	mainMenuBar.addItem subMenuItem subMenuIndex
	menuMan.updateMenuBar()
)