Version 4 of reading win32 exectuable version information

Updated 2003-05-10 17:53:09

AF 10-05-03

 proc readVersionInfo {file} {
    set fh [open $file r]
    fconfigure $fh -encoding unicode
    set data [read $fh]
    set startchar [string first "FileDescription\000" $data]
    if {$startchar < 0} {
        return {{} {} {} {} {} {} {}}
    }
    foreach x {CompanyName OriginalFilename ProductName ProductVersion FileDescription FileVersion InternalName LegalCopyright LegalTrademarks} {
        set s [string first "$x\000" $data $startchar]
        set e [string first "\000" $data [expr $s + [string length $x] + 2]]
        if {$s < 0 || $e < 0} {
            lappend prop {}
            continue
        }
        lappend prop [string range $data [expr $s + [string length $x] + 1] $e]
    }
    close $fh
    return $prop
 }

 set name {"Company Name" "Original Filename" "Product Name" "Product Version" "File Description" "File Version" "Internal Name" "Copyright" "Trademarks"}

 foreach n $name prop [readVersionInfo tclkit.exe] {
    puts "$n: $prop"
 }