// shell.inc

// Shell command wrappers

[SystemDate]
	DateList = {} ? $(!LIBHANDLE) GetSystemDate

//
// Shell code error message dialog handler.
//
//		$0 = Title
//		$1 = Text
//
[ShellCodeError]

   read-syms ShellCodeError-$(!STF_LANGUAGE)

	set DlgType = "MessageBox"
	set STF_MB_TITLE = $(ShellCodeErrorTitle)
	set STF_MB_TEXT  = $(ShellCodeErrorText)
	set STF_MB_TYPE  = MB_OK
	set STF_MB_ICON  = MB_ICONSTOP
	set STF_MB_DEF   = MB_DEFBUTTON1
	ui start "Error Message"

	Return

//
// Generic message dialog handler.
//
//		$0 = Type of Dialog
//		$1 = Message
//
//		$R0 = Status (STATUS_*)
//		$R1 = Button pressed
//
[SetupMessage]
	
	set Type = $($0)
	set Message = $($1)
	_Enter("SetupMessage", _Show(Type)_Show(Message))

	set Status = "STATUS_FAILURE"
	set Button = EMPTY_STR

	_SubroutineShell SetupMessage $(!STF_LANGUAGE) $(Type) $(Message)
   _OnShellErrorGoto(Exit)

	set Status = $($R0)
	set Button = $($R1)

Exit = +

	_Exit("SetupMessage", _Show(Status)_Show(Button))
	Return $(Status) $(Button)

//
//	Shows status dialog to user (MB_ICONINFORMATION | MB_OK).
//
//		$0 = Message
//
//		$R0 = Status
//
[StatusMessage]
	_LocalShell SetupMessage "STATUS" $($0)
	Return $($R0)

//
// Shows a message box
//
//		$0 = Title
//		$1 = Text
//		$2 = Type (MB_OK, MB_YESNO, ...)
//		$3 = Icon (MB_INFORMATION, MB_QUESTION, ...)
//		$4 = Default Button (MB_DEFBUTTON1, MB_DEFBUTTON2, ...)
//
//		$R0 = DLGEVENT (which button was pushed)
//
[MessageBox]

   set Title = $($0)
   set Text = $($1)
   set Type = $($2)
   set Icon = $($3)
   set DefButton = $($4)

	_Enter("MessageBox", _Show(Title)_Show(Text)_Show(Type)_Show(Icon)_Show(DefButton))

   ifstr(i) $(Type) == EMPTY_STR
      set Type = MB_OK
   endif

   ifstr(i) $(Icon) == EMPTY_STR
      set Icon = MB_ICONINFORMATION
   endif

   ifstr(i) $(DefButton) == EMPTY_ST
      set DefButton = MB_DEFBUTTON1
   endif

	set DlgType = "MessageBox"
	set STF_MB_TITLE = $(Title)
	set STF_MB_TEXT  = $(Text)
	set STF_MB_TYPE  = $(Type)
	set STF_MB_ICON  = $(Icon)
	set STF_MB_DEF   = $(DefButton)
	ui start "MessageBox"

Exit = +
	_Exit("MessageBox", _Show(DLGEVENT))
	Return $(DLGEVENT)

//
//	Returns registry error string.
//
//		$0 = Registry error index
//
//		$R0 = Registry error string 
//
[GetRegistryErrorString]

	set ErrorString = $(GenericError)

	_UtilityShell RegistryErrorString $($0)
   _OnShellErrorGoto(Exit)

   // Not DO NOT call _UtilityShellError() or _OnUtilityShellErrorGoto() here
   // since that could cause unending recursion!

	set ErrorString = $($R0)

Exit = +

	Return $(ErrorString)

//
//	Returns elapsed time in seconds since Jan 1, 1970.
//
//		$R0 = Elapsed time
//
[GetElapsedTime]
	Detect SystemDate

	_Enter("GetElapsedTime", "")

   _Trace("GetSystemDate returned", _Show(DateList))

	set ElapsedTime = *($(DateList), 1)

	_Exit("GetElapsedTime", _Show(ElapsedTime))
	Return $(ElapsedTime)

//
//	Returns NT version
//
//		$R0 = "3.51" or "4.0"
//
[GetNTVersion]

	_Enter("GetNTVersion", "")

   _GetRegSzByName "SOFTWARE\Microsoft\Windows Nt\CurrentVersion" "CurrentVersion"
   _Assert($($R0))
   set Version = $($R1)

	_Exit("GetNTVersion", _Show(Version))
	Return $(Version)
