#
#
# <20180722.1840.14>
#
# code to handle the Windows recycle bin...
#
# Windows recyle bin files consist of a pair of files,
# the $I file and the $R file (these being the first two
# characters in the file names.
#
# The $R file is the actual file renamed to some arbitrary
# name with the same extension as the orgional.
#
# The $I file with the same name as the $R file, but for the
# I vs R, containes meta data on the file.
# This is a binary file with the following format:
#
# windows 8.1/10 (the two differ if two numbers are given)
# Offset     Length in bytes     Description
# 0              8              Begins with 01/02
# 8              8              File Size in bytes
# 16             8              Deleted Time (In 64 bit Windows timestamp format)
# 24             4              Unknown (windows 10)
# 24/28          520/as needed  File path

# It appears that the file name is in Unicode, however we will test this to
# be sure.

# This code returns the delete time, file size and path/name and the 4 byte field
# if present (nil => windows 8.1 format)
# A total nil return => it is not a recognized $I file
#
proc getRecycleIfileInfo {file} {
  if {![file exists $file] || ![file readable $file]} {
    return -code error "Not a readable \$I file."
  }
  set f [OpenBinaryFile $file]
  set key [BinaryRead 8 $f]
  if {$key ni {1 2}} {
    # we only know about 1 & 2  $I files
    return {}
  }
  set size [BinaryRead 8 $f]
  set deleteTime [BinaryRead 8 $f]
  set fourByte {}
  if {$key == 2} {
    set fourByte [BinaryRead 4 $f]
  }
  set offset [chan tell $f]
  set outFile [GetArbNullTermString $f $offset]
  return [list $deleteTime $size $outFile $fourByte]
}
