Version 1 of reading win32 exectuable version information

Updated 2003-05-10 17:32:41

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 {FileDescription OriginalFilename CompanyName FileVersion LegalCopyright ProductName ProductVersion} {
        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 {"File Description" "Original Filename" "Company Name" "File  Version" "Legal Copyright" "Product Name" "Product Version"}

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

File Description: Tclkit, a standalone runtime for Tcl/Tk Original Filename: tclkit.exe Company Name: Equi4 Software File Version: 8.4.2 Legal Copyright: Copyright � 1989-2003 by J.Ousterhout et al. Product Name: Tclkit 8.4 for Windows Product Version: 8.4.2