#!/usr/local/bin/tclsh8.4

# JStrack:  copyright 1997/2008 by Jim Graham, N5IAL, all rights reserved.


set reftime {16Aug08 09:06:00}
set reftimesecs [clock scan $reftime]
set reftimetext [clock format $reftimesecs -format "%d%h%y %H:%M:%S %Z"]
set standalone_ftp_mode 1
catch { destroy .ftpmsg }
if {[catch {toplevel .ftpmsg}]} {
   set notk 1
} else {
   set notk 0
   wm protocol .ftpmsg WM_DELETE_WINDOW { exit }
   text .ftpmsg.text -relief sunken -bd 2 -width 80 -height 25 \
      -yscrollcommand ".ftpmsg.scroll set" -font {Courier 12}
   scrollbar .ftpmsg.scroll -command ".ftpmsg.text yview"
   pack .ftpmsg.scroll -side right -fill y
   pack .ftpmsg.text -side top -expand yes -fill both
   .ftpmsg.text tag configure jdgmsg -font {Courier 10} -foreground #000000
   if {$standalone_ftp_mode} { wm withdraw . }
}

source ftplib.tcl

usrmsg {Creating timestamp files to match the data files that you installed.}
usrmsg {These files control what is downloaded from the NHC FTP server---any}
usrmsg {data files (for the four product types that JStrack uses) that are}
usrmsg {NEWER than the timestamp files will be downloaded and processed.}
usrmsg ""
usrmsg "Each timestamp file will have its creation time set to $reftimetext."

set error 0
if {[catch { package require Tcl 8.2 }]} { set error 1 }
if {[catch { package require fileutil 1.4 }]} { incr error 2 }

if {$error} {
   if {$error == 1} {
      usrmsg {You must have Tcl/Tk 8.2 or 8.3 installed!}
   }
   if {$error == 2} {
      usrmsg {You must have Tcllib 1.3 or higher installed!}
   }
   if {$error == 3} {
      usrmsg {You must have Tcl/Tk 8.2 or 8.3 AND Tcllib 1.3 or higher installed!}
   }
   usrmsg {Until these are fixed, you can't use the ftp updates anyways.}
   tk_finish
}

foreach fn [list timestamp.disc timestamp.marine timestamp.public timestamp.strike] {
   set f [open $fn w]
   close $f
   ::fileutil::touch -c -t $reftimesecs $fn
}

usrmsg {DONE!}

if {$notk && $standalone_ftp_mode} { exit }
if {$notk} { return }
button .ftpmsg.done -text "Dismiss" -command { exit }
pack .ftpmsg.done -side top


