
! script name: filing.d/safetystore
! topic: safety save file backup

!A
!A NAME:
!A
!A 	Safety Store
!A
!A DESCRIPTION:
!A
!A	NOTE: THIS DOES NOT STORE THE FILE BEING WORKED ON IN THE STORAGE
!A		 DIRECTORY. IT IS SAVED IN THE USERS DIRECTORY.
!A
!A 	This script will save a file in the users working directory. The
!A	script can be called manually or from a script such as typecontrol.
!A	There is an elapsed time control involved.  The time is controlled
!A	by the system variable "time check".  This time is in seconds and
!A	can be accessed in the settings menu.
!A	The script is accessed when "time check" or more seconds have elapsed.
!A	The ascrpt typecontrol calls this function. BUT the safety store
!A	ONLY occurs when typecontrol is loaded.  typecontrol is the script
!A	that is loaded when a blank line appears in the question line.
!A	IF this script IS NEVER ACCESSED then no safetystore will occur.
!A	
!B INSTRUCTIONS:
!B	The user can control this function by setting the variable
!B	"use safetystore".  It is either 1 for on or 0 for off.
!B	Change the "time check" variable if the function is not occurring
!B	enough or if it is occurring too often.  The defaults for these
!B	switches can be set in the startup script. "time check" will only
!B	be effective for values greater than 10 (lowest time allowable)
!B

DIM Answer$[256],Header$[4000],A$[256]
DIM Descr$[256],Datestr$[256],Sdevice$[256],Jobname$[256]
DIM Tmp$[256],Space$[25],Jobs$[25],Unit$[256]
DIM Dir$[256],Mask$[256],Namelist$[5000],Filelist$(100)[100]

DeActivateUndo
Jobname$="safetystore"
Stat= CurrentHeader(Header$)
IF LEN(Header$) THEN Head=ReadUserData(WsGeneralString,"HEADER",Header$)
Stat= DisplayMessage("SAFETY STORING FILE ")

IF ValidGeometry(Head) THEN
	Stat= DateString(Datestr$)
	Stat= PutUserString(Head,"Revision date:",Datestr$)
        Units= CurrentUnits
        Unit$= RPT$("METRIC",Units= WsMetric)&RPT$("INCHES",Units=WsInch)
        Stat=PutUserString(Head,"Units:",Unit$)
	AccTime = TIMEDATE-NamedVarVal("job start time",WsSystemVars,0.0)
	AccTimer = NamedVarVal("accumulated time",WsSystemVars,0.0)
	AccTime=AccTime/60+AccTimer
	Stat=PutUserString(Head,"Accumulated Time:"," "&VAL$(PROUND(AccTime,-2))&" minutes")
END IF
UnSelectAll

IF ValidGeometry(Head) THEN
	Stat= PutUserString(Head,"Component files 1:","Geometry")
	I= 2
	WHILE CheckUserField(Head,"Component files "&VAL$(I)&":",1)
		Stat= PutUserString(Head,"Component files "&VAL$(I)&":","EMPTY")
		I= I+1
	END WHILE
	Enti= UserDataString(Head,Header$)
	Stat= FileHeader(Header$)
	Stat= DeleteEntity(Head)
END IF

Stat= UpdateSettings("CadSettings",WsCadSettings)
Stat=StoreFile(Jobname$,1.0)
IF Stat THEN
   IF Stat= 2 THEN
      Stat=SetInputFormat("a99","")
      Stat=GetValue("WARNING -- NOT SAVED: file not synergy file",Answer$)
   ELSE
      Stat=SetInputFormat("a99","")
      Stat=GetValue("WARNING -- FILE NOT STORED: cannot open file",Answer$)
   END IF
   IF (ExitScript(Destination$)) THEN Leave
   GOTO Leave
END IF

Leave:!
V1= CreateVariable("job time",WsSystemVars,TIMEDATE)
IF ValidGeometry(Head) THEN Stat= DeleteEntity(Head)
Stat=SetInputFormat("n4","")
LOAD "typecontrol"
END
