' ArcView's startup file, which runs before default.apr is read.
' Check for a valid project workspace -- the directory must be writable.
haveHOMEPath = false
for each var in {"HOME", "TEMP", "CWD", "AVHOME"}
  path = System.GetEnvVar(var)
  if (path <> NIL) then
    if (File.Exists(path.AsFileName) and File.IsWritable(path.AsFileName)) then
      System.SetEnvVar("HOME", path)
      haveHOMEPath = true
      break
    end
  end
end

if (Not haveHOMEPath) then
  MsgBox.Warning("Cannot find a writable project directory. Please set environment variable HOME to a writable directory.", "")
end

' Check for a valid TEMP under Windows -- let user know if it is not set.
' Required for themes based on TXT type annotation and for editing.
if (system.GetOS = #SYSTEM_OS_MSW) then
  haveTEMPPath = false
  for each var in {"TEMP", "HOME", "CWD", "AVHOME"}
    path = System.GetEnvVar(var)
    if (path <> NIL) then
      if (File.Exists(path.AsFileName) and File.IsWritable(path.AsFileName)) then
        System.SetEnvVar("TEMP", path)
        haveTEMPPath = true
        break
      end
    end
  end
  if (Not haveTEMPPath) then
    MsgBox.Warning("Cannot find TEMP directory. Please set environment variable TEMP to a writable directory.", "")
  end
end


MsgBox.Banner("$AVHOME/etc/splash.bmp".AsFileName, 15, "Hocking SSURGO DSS 2.1")
av.SetName("Hocking SSURGO DSS 2.1")

avExt = FN.Make("$AVHOME")
avExt.MergePath("ext")
System.SetEnvVar("AVEXT", avExt.GetFullName)

avBin = FN.Make("$AVHOME")
avBin.MergePath("bin")
System.SetEnvVar("AVBIN", avBin.GetFullName)

'
' The USEREXT variable is used by the extension manager dialog. 
' That dialog looks for additional extensions in the directory specified by 
' it. You can change it's value if you want to keep additional extensions in 
' some other location.
'
if (System.GetEnvVar("USEREXT") = NIL) then
  System.SetEnvVar("USEREXT", System.GetEnvVar("HOME"))
end

'
' The default font size used by ArcView's script editor is approximately
' 14 pt (courier). That font size is identified by the enumeration element
' #SED_FONTSIZE_MEDIUM. You can use the elements #SED_FONTSIZE_SMALL
' or #SED_FONTSIZE_LARGE to make the default font size smaller (12 pt)
' or larger (14 pt).
SEd.SetDefaultFontSize(#SED_FONTSIZE_SMALL)

if (system.GetOS = #SYSTEM_OS_MSW) then
  Script.Make("DDEServer.Start").DoIt(NIL)

  if (system.GetOSVariant = #SYSTEM_OSVARIANT_MSW16) then

    System.SetEnvVar("AVBIN", System.GetEnvVar("AVHOME")+"\bin16")
    System.SetEnvVar("AVEXT", System.GetEnvVar("AVHOME")+"\ext16")

    if (FN.FindInSystemSearchPath("winsock.dll") <> nil) then
      System.LoadLibrary("$AVBIN/avrpc.dll".AsFileName)
    end
    System.LoadLibrary("$AVBIN/avexec.dll".AsFileName)

  else 'for WinNT and Win95

    System.SetEnvVar("AVBIN", System.GetEnvVar("AVHOME")+"\bin32")
    System.SetEnvVar("AVEXT", System.GetEnvVar("AVHOME")+"\ext32")

    if (FN.FindInSystemSearchPath("wsock32.dll") <> nil) then       
      System.LoadLibrary("$AVBIN/avrpc.dll".AsFileName)
    end
  end 'MSW16 case
end 'MSW case

'
' Load the Shapes.dll
if (system.GetOS = #SYSTEM_OS_MSW) then
  System.LoadLibrary("$AVBIN/shapes.dll".AsFileName)
end 'MSW case

'
' Load the dnsgm.dll
if (File.Exists("$AVBIN/dnsgm.dll".AsFileName)) then
  System.LoadLibrary("$AVBIN/dnsgm.dll".AsFileName)
end

'
' Load the avimgexp.dll
if (File.Exists("$AVBIN/avimgexp.dll".AsFileName)) then
  System.LoadLibrary("$AVBIN/avimgexp.dll".AsFileName)
end

'
' Load the avdlog.dll
if (File.Exists("$AVBIN/avdlog.dll".AsFileName)) then
  System.LoadLibrary("$AVBIN/avdlog.dll".AsFileName)
end
