function OnMaintUIBefore()
NUMBER nResult,nLevel,nType;
STRING szTitle,szMsg,svDir,szComponents,svResult,szCaption;
begin
	
	
    //Maintenance Mode
	SetStatusWindow(0, "");
	Enable(STATUSEX);
	StatusUpdate(ON, 100);
	if (CMDLINE % "UNINSTALL") then
		ComponentRemoveAll();
	else
		SelectNewComponents();  // with this call, newly added components are selected
					// and will be installed
		ComponentReinstall();
	endif;
end;

function SelectNewComponents()
LIST	listCompList, listTemp;
NUMBER	nResult, nItem;
STRING	svString;
begin
	listCompList = ListCreate(STRINGLIST);
	ComponentListItems(MEDIA, "", listCompList); // generate a list of top-level components
	nResult = ListGetFirstString(listCompList, svString);	
	while (nResult != END_OF_LIST)	// traverse through the list of components
		nItem = ComponentIsItemSelected(MEDIA, svString);   
		if (nItem = 0) then	// Component is not selected, so select it
			ComponentSelectItem(MEDIA, svString, TRUE);
		endif;
		nResult = ListGetNextString(listCompList, svString);		
	endwhile;
	ListDestroy(listCompList);
end;
