// Copyright © 1995 by Apple Computer, Inc.  All rights reserved.

DefConst('kRemoveThisPackageFunc, func(objRef) RemovePackage(ObjectPkgRef(objRef)));

partData := { fInstaller:
{
	fModemSetup:
		{	modemName:		kModemName,
			version:		kVersion,
			organization:	kOrganization,
			
			modemPrefs: 
			{
				idModem:				kIdModem,
				useHardwareCD:			kuseHardwareCD,
				useConfigString:		kuseConfigString,
				useDialOptions:			kuseDialOptions,
				hangUpAtDisconnect:		khangUpAtDisconnect,
			},
			
			modemProfile: 
			{
				supportsEC:				ksupportsEC,
				supportsLCS:			ksupportsLCS,
				directConnectOnly:		kdirectConnectOnly,
				connectSpeeds:			kconnectSpeeds,
				configSpeed:			kconfigSpeed,
				commandTimeout:			kcommandTimeout,
				maxCharsPerLine:		kmaxCharsPerLine,
				interCmdDelay:			kinterCmdDelay,
				modemIdStr:				kModemIdStr,
				configStrNoEC:			kconfigStrNoEC,
				configStrECOnly:		kconfigStrECOnly,
				configStrECAndFallback:	kconfigStrECAndFallback,
				configStrDirectConnect:	kconfigStrDirectConnect,
			},
			
			faxProfile:
			{
				serviceClass:			kServiceClass,
				transmitDataMod:		kTransmitDataMod,
				receiveDataMod:			kReceiveDataMod,
				transmitHDLCDataMod:	kTransmitHDLCDataMod,
				receiveHDLCDataMod:		kReceiveHDLCDataMod,
			},
		},
	
	
	MInstall:
		func()
		begin
			// This function is called from the package's InstallScript and executes from pseudo-ROM.
			// We need a RAM-based frame to hold temporary variables during installation.
			
			local RamBasedSelf :=
				{	_proto:			self,
					fEntry:			GetModemSetup(kModemName),
			 	};
			
			if RamBasedSelf.fEntry <> nil then
			 	begin
			 		// if one is installed, check the setup version number
					local versionInstalled := RamBasedSelf.fEntry.version;
					local message;
					
					if kVersion <> versionInstalled then 
						if kVersion > versionInstalled then
							message := LocObj("You are about to install a NEWER version of the \"" & kModemName & "\" modem setup.  Continue?", 'fConfirmNewer);
						else
							message := LocObj("You are about to install an OLDER version of the \"" & kModemName & "\" modem setup.  Continue?", 'fConfirmOlder);
					else
						message := LocObj("The \"" & kModemName & "\" modem setup is already installed.  Reinstall?", 'fConfirmSame);
					
					GetRoot():Confirm(kAppName, message, RamBasedSelf, 'MInstallConfirmScript);
				end;
			
			else	// there is no modem setup currently installed for this modem, so add one
		 		RamBasedSelf:MInstallConfirmScript(true);
		end,
	
	
	MInstallConfirmScript:
		func(confirmed)			// self is the RamBasedSelf frame
		begin
			if confirmed then
				begin
					RemoveModemSetup(kModemName);		// remove the old one
					AddModemSetup(Clone(fModemSetup));	// add the new one
				end;
			
			AddDeferredCall(EnsureInternal(kRemoveThisPackageFunc), [kModemName]);
		end,
}, };


SetPartFrameSlot(	'DoNotInstall,
					func()
					begin
						if not GlobalFnExists('AddModemSetup)
						or not GlobalFnExists('RemoveModemSetup)
						or not GlobalFnExists('GetModemSetup) then
							begin
								GetRoot():Notify(kNotifyAlert, kAppName, LocObj("The \"" & kModemName & "\" modem setup is not compatible with this unit.", 'fNotifyIncompatible));
								return true;
							end;
						
						nil;
					end	);

InstallScript	:=	func(partFrame, removeFrame)
					AddDeferredCall(	func(base) base:MInstall(),
										[partFrame.partData.fInstaller]	);

RemoveScript	:=	nil;
