public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* looking for shell program to retrieve property info from windows files
@ 2005-01-19  2:30 Jaye Speaks
  2005-01-19 13:41 ` Jason Tishler
  0 siblings, 1 reply; 5+ messages in thread
From: Jaye Speaks @ 2005-01-19  2:30 UTC (permalink / raw)
  To: cygwin

does anyone know of a shell program to retrieve the property info from windows files.  I need info like the fileversion or prodversion.



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: looking for shell program to retrieve property info from windows files
  2005-01-19  2:30 looking for shell program to retrieve property info from windows files Jaye Speaks
@ 2005-01-19 13:41 ` Jason Tishler
  2005-01-19 20:02   ` DePriest, Jason R.
  2005-01-19 20:26   ` Igor Pechtchanski
  0 siblings, 2 replies; 5+ messages in thread
From: Jason Tishler @ 2005-01-19 13:41 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 944 bytes --]

Jaye,

On Tue, Jan 18, 2005 at 07:15:09PM -0500, Jaye Speaks wrote:
> does anyone know of a shell program to retrieve the property info from
> windows files.  I need info like the fileversion or prodversion.

No, so I wrote my own:

    $ version 'C:\Program Files\Microsoft Office\OFFICE11\WINPROJ.EXE'
    Required Information:
        ProductVersion = 11.0.2003.816
        FileVersion = 11.0.2003.816
    Optional Information:

    $ cygversion /mnt/c/Program\ Files/Microsoft\ Office/OFFICE11/WINPROJ.EXE 
    Required Information:
        ProductVersion = 11.0.2003.816
        FileVersion = 11.0.2003.816
    Optional Information:

See attached for the source and Makefile.

Note the Makefile builds two executables:

    version.exe:    Mingw executable
    cygversion.exe: Cygwin executable

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6

[-- Attachment #2: version.cc --]
[-- Type: text/plain, Size: 4267 bytes --]

/*
 * Copyright (c) 2005 Jason Tishler
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * A copy of the GNU General Public License can be found at
 * http://www.gnu.org/
 *
 * Written by Jason Tishler <jason@tishler.net>
 *
 * $Id: version.cc,v 1.6 2005/01/19 14:49:52 jt Exp $
 */

#include <windows.h>
#include <stdio.h>
#ifdef __CYGWIN__
#include <sys/cygwin.h>
#endif

const char* GetVersionString(const void* aVersionInfo,
	const char* aVersionName);
const VS_FIXEDFILEINFO* GetFixedFileInfo(const void* aVersionInfo);
void PrintRequiredVersionInfo(const VS_FIXEDFILEINFO* aFixedFileInfo);
void PrintOptionalVersionInfo(char* aVersionInfo);
bool GetFullPathName(const char* aFileName, char* aPathName,
	unsigned int aSize);
void PrintUsage();

const char* aVersionNames[] =
{
	"Comments",
	"CompanyName",
	"FileDescription",
	"FileVersion",
	"InternalName",
	"LegalCopyright",
	"LegalTrademarks",
	"OriginalFilename",
	"PrivateBuild",
	"ProductName",
	"ProductVersion",
	"SpecialBuild"
};

int
main(int argc, const char* argv[])
{
	if (argc < 2)
	{
		PrintUsage();
		exit(1);
	}

	for (int i = 1; i < argc; i++)
	{
		char aPathName[MAX_PATH + 1];
		const char* aFileName = argv[i];
		GetFullPathName(aFileName, aPathName, sizeof(aPathName));

		if (argc > 2)
		{
			printf("%s%s:\n", (i != 1) ? "\n" : "", aFileName);
		}

		DWORD aHandle = 0;
		DWORD aSize = GetFileVersionInfoSize(aPathName, &aHandle);
		if (aSize == 0)
		{
			exit(2);
		}

		char* aVersionInfo = new char[aSize];
		BOOL aStatus = GetFileVersionInfo(aPathName, aHandle, aSize, aVersionInfo);
		if (!aStatus)
		{
			delete [] aVersionInfo;
			exit(3);
		}

		const VS_FIXEDFILEINFO* aFixedFileInfo = GetFixedFileInfo(aVersionInfo);
		PrintRequiredVersionInfo(aFixedFileInfo);

		PrintOptionalVersionInfo(aVersionInfo);

		delete [] aVersionInfo;
	}

	exit(0);
}

const char*
GetVersionString(const void* aVersionInfo, const char* aVersionName)
{
	const char* aSeparator = "\\";
	const char* aPrefix = "StringFileInfo";
	const char* aLangCodePage = "040904b0";
	char aVersionPath[MAX_PATH + 1];

	strcpy(aVersionPath, aSeparator);
	strcat(aVersionPath, aPrefix);
	strcat(aVersionPath, aSeparator);
	strcat(aVersionPath, aLangCodePage);
	strcat(aVersionPath, aSeparator);
	strcat(aVersionPath, aVersionName);

	void* aBuffer = 0;
	UINT aSize = 0;
	VerQueryValue((void*) aVersionInfo, aVersionPath, &aBuffer, &aSize);
	return (const char*) aBuffer;
}

const VS_FIXEDFILEINFO*
GetFixedFileInfo(const void* aVersionInfo)
{
	void* aBuffer = 0;
	UINT aSize = 0;
	const char* aRootBlock = "\\";
	VerQueryValue((void*) aVersionInfo, (char*) aRootBlock, &aBuffer, &aSize);
	return (const VS_FIXEDFILEINFO*) aBuffer;
}

void
PrintRequiredVersionInfo(const VS_FIXEDFILEINFO* aFixedFileInfo)
{
	if (!aFixedFileInfo)
		return;

	printf("Required Information:\n");
	printf("    ProductVersion = %d.%d.%d.%d\n",
		aFixedFileInfo->dwProductVersionMS >> 16,
		aFixedFileInfo->dwProductVersionMS & 0xffff,
		aFixedFileInfo->dwProductVersionLS >> 16,
		aFixedFileInfo->dwProductVersionLS & 0xffff);
	printf("    FileVersion = %d.%d.%d.%d\n",
		aFixedFileInfo->dwFileVersionMS >> 16,
		aFixedFileInfo->dwFileVersionMS & 0xffff,
		aFixedFileInfo->dwFileVersionLS >> 16,
		aFixedFileInfo->dwFileVersionLS & 0xffff);
}

void
PrintOptionalVersionInfo(char* aVersionInfo)
{
	printf("Optional Information:\n");
	int aNumVersionNames = sizeof(aVersionNames) / sizeof(const char*);
	for (int i = 0; i < aNumVersionNames; i++)
	{
		const char* aVersionName = aVersionNames[i];
		const char* aVersionString =
			GetVersionString(aVersionInfo, aVersionName);
		if (aVersionString)
			printf("    %s: %s\n", aVersionName, aVersionString);
	}
}

bool
GetFullPathName(const char* aFileName, char* aPathName, unsigned int aSize)
{
#ifdef __CYGWIN__
	cygwin_conv_to_full_win32_path(aFileName, aPathName);
	return true;
#else
	char *aDummy;
	DWORD aStatus = GetFullPathName (aFileName, aSize, aPathName, &aDummy);
	return (aStatus > 0);
#endif // __CYGWIN__
}

void
PrintUsage()
{
	printf("usage: version files...\n");
}

[-- Attachment #3: Makefile --]
[-- Type: text/plain, Size: 716 bytes --]

#
# Copyright (c) 2005 Jason Tishler
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# A copy of the GNU General Public License can be found at
# http://www.gnu.org/
#
# Written by Jason Tishler <jason@tishler.net>
#
# $Id: Makefile,v 1.3 2005/01/19 14:50:10 jt Exp $
#

all: version cygversion

CC = g++
CFLAGS = -O2 -s
Files = version.cc
Libs = -lversion

version: $(Files)
	$(CC) $(CFLAGS) -mno-cygwin -o $@ $(Files) $(Libs)

cygversion: $(Files)
	$(CC) $(CFLAGS) -o $@ $(Files) $(Libs)

clean:
	$(RM) *.exe


[-- Attachment #4: Type: text/plain, Size: 218 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: looking for shell program to retrieve property info from windows files
  2005-01-19 13:41 ` Jason Tishler
@ 2005-01-19 20:02   ` DePriest, Jason R.
  2005-01-19 20:26   ` Igor Pechtchanski
  1 sibling, 0 replies; 5+ messages in thread
From: DePriest, Jason R. @ 2005-01-19 20:02 UTC (permalink / raw)
  To: cygwin

I did something similar in perl.

#!/usr/bin/perl

# Version 1.0
# - It does what it does.

use Digest::MD5 qw(md5_hex);
use Win32::File;
use Win32::File::VersionInfo;
use Win32::FileTime;

$fname = $ARGV[0];

print "\nFile: $fname";

if (! -e $fname) {
	print "\n\nI cannot find your file.";
	print "\nError!";
	print "\nperl: $!\nos: $^E\n";
	die;
}

Win32::File::GetAttributes("$fname",$fattr);
#print "\nWin32::File::GetAttrubutes(\"$fname\",\$fattr) -> $fattr";
$finfo = Win32::File::VersionInfo::GetFileVersionInfo("$fname");
#print "\n\$finfo =
Win32::File::VersionInfo::GetFileVersionInfo(\"$fname\") -> $finfo";
$ftime = Win32::FileTime->new("$fname");
#print "\n\$ftime = Win32::FileTime->new(\"$fname\") -> $ftime";

if ($finfo) {
	print "\nFile Version: ", $finfo->{FileVersion};
	print "\nProduct Version: ", $finfo->{ProductVersion};
	%Flags = $finfo->{Flags};
	foreach $key (keys %Flags) {
		if ($Flags{$key}) {
			print "\nFlags: ", $key;
		} # end of if the value exists
	} # end of foreach flag
	print "\nOS: ", $finfo->{OS};
	print "\nType: ", $finfo->{Type};
	print "\nDate: ", $finfo->{Date};
	my $lang = (keys %{$finfo->{Lang}})[0];
	if ($lang) {
		print "\nLanguage: ", $lang;
		print "\nComments: ", $finfo->{Lang}{$lang}{Comments};
		print "\nCompanyName: ", $finfo->{Lang}{$lang}{CompanyName};
		print "\nFileDescription: ", $finfo->{Lang}{$lang}{FileDescription};
		print "\nFileVersion: ", $finfo->{Lang}{$lang}{FileVersion};
		print "\nInternalName: ", $finfo->{Lang}{$lang}{InternalName};
		print "\nCopyright: ", $finfo->{Lang}{$lang}{Copyright};
		print "\nTrademarks: ", $finfo->{Lang}{$lang}{Trademarks};
		print "\nOriginalFilename: ", $finfo->{Lang}{$lang}{OriginalFilename};
		print "\nProductName: ", $finfo->{Lang}{$lang}{ProductName};
		print "\nProductVersion: ", $finfo->{Lang}{$lang}{ProductVersion};
		print "\nPrivateBuild: ", $finfo->{Lang}{$lang}{PrivateBuild};
		print "\nSpecialBuild: ", $finfo->{Lang}{$lang}{SpecialBuild};
	}
} # end of if
else {
	print "\n\nI cannot get the file flags.";
	print "\nError!";
	print "\nAre you sure this is a valid Microsoft Portable Executable
(PE) file with valid version information?\n";
	}

if ($fattr) {
	$#attr = -1;
	if ($fattr & ARCHIVE) { push(@attr,"archive"); }
	if ($fattr & COMPRESSED) { push(@attr,"compressed"); }
	if ($fattr & DIRECTORY) { push(@attr,"directory"); }
	if ($fattr & HIDDEN) { push(@attr,"hidden"); }
	if ($fattr & NORMAL) { push(@attr,"normal"); }
	if ($fattr & OFFLINE) { push(@attr,"offline"); }
	if ($fattr & READONLY) { push(@attr,"readonly"); }
	if ($fattr & SYSTEM) { push(@attr,"system"); }
	if ($fattr & TEMPORARY) { push(@attr,"temporary"); }
	print "\nFile Attributes: ", join(", ",@attr);
}
else {
	print "\n\nI cannot get the file attributes.";
	print "\nError!";
	print "\nperl: $!\nos: $^E\n";
}

if ($ftime) {
	printf(
		"\nCreated : %4d/%02d/%02d %02d:%02d:%02d",
		$ftime->Create(
			'year', 
			'month', 
			'day', 
			'hour', 
			'minute', 
			'second' 
		)
	);
	printf(
		"\nAccessed : %4d/%02d/%02d %02d:%02d:%02d",
		$ftime->Access(
			'year', 
			'month', 
			'day', 
			'hour', 
			'minute', 
			'second' 
		)
	);
	printf(
		"\nModified : %4d/%02d/%02d %02d:%02d:%02d",
		$ftime->Modify(
			'year', 
			'month', 
			'day', 
			'hour', 
			'minute', 
			'second' 
		)
	);
} # end of if
else {
	print "\n\nI cannot get the file times.";
	print "\nError!";
	print "\nperl: $!\nos: $^E\n";
}

print "\nMD5 Checksum: ", md5_hex("$fname");

print "\n";

On Wed, 19 Jan 2005 08:03:00 -0500, Jason Tishler < [REMOVED] > wrote:
> Jaye,
> 
> On Tue, Jan 18, 2005 at 07:15:09PM -0500, Jaye Speaks wrote:
> > does anyone know of a shell program to retrieve the property info from
> > windows files.  I need info like the fileversion or prodversion.
> 
> No, so I wrote my own:
> 
>    $ version 'C:\Program Files\Microsoft Office\OFFICE11\WINPROJ.EXE'
>    Required Information:
>        ProductVersion = 11.0.2003.816
>        FileVersion = 11.0.2003.816
>    Optional Information:
> 
>    $ cygversion /mnt/c/Program\ Files/Microsoft\ Office/OFFICE11/WINPROJ.EXE
>    Required Information:
>        ProductVersion = 11.0.2003.816
>        FileVersion = 11.0.2003.816
>    Optional Information:
> 
> See attached for the source and Makefile.
> 
> Note the Makefile builds two executables:
> 
>    version.exe:    Mingw executable
>    cygversion.exe: Cygwin executable
> 
> Jason
> 
> --
> PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
> Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6
> 
>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: looking for shell program to retrieve property info from windows files
  2005-01-19 13:41 ` Jason Tishler
  2005-01-19 20:02   ` DePriest, Jason R.
@ 2005-01-19 20:26   ` Igor Pechtchanski
  2005-01-20 13:52     ` Jason Tishler
  1 sibling, 1 reply; 5+ messages in thread
From: Igor Pechtchanski @ 2005-01-19 20:26 UTC (permalink / raw)
  To: Jason Tishler; +Cc: cygwin

On Wed, 19 Jan 2005, Jason Tishler wrote:

> Jaye,
>
> On Tue, Jan 18, 2005 at 07:15:09PM -0500, Jaye Speaks wrote:
> > does anyone know of a shell program to retrieve the property info from
> > windows files.  I need info like the fileversion or prodversion.
>
> No, so I wrote my own:
>
>     $ version 'C:\Program Files\Microsoft Office\OFFICE11\WINPROJ.EXE'
>     Required Information:
>         ProductVersion = 11.0.2003.816
>         FileVersion = 11.0.2003.816
>     Optional Information:
>
>     $ cygversion /mnt/c/Program\ Files/Microsoft\ Office/OFFICE11/WINPROJ.EXE
>     Required Information:
>         ProductVersion = 11.0.2003.816
>         FileVersion = 11.0.2003.816
>     Optional Information:
>
> See attached for the source and Makefile.

Jason,

This looks useful.  Feel like proposing this for cygutils?
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: looking for shell program to retrieve property info from windows files
  2005-01-19 20:26   ` Igor Pechtchanski
@ 2005-01-20 13:52     ` Jason Tishler
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Tishler @ 2005-01-20 13:52 UTC (permalink / raw)
  To: cygwin

Igor,

On Wed, Jan 19, 2005 at 03:19:35PM -0500, Igor Pechtchanski wrote:
> On Wed, 19 Jan 2005, Jason Tishler wrote:
> > On Tue, Jan 18, 2005 at 07:15:09PM -0500, Jaye Speaks wrote:
> > > does anyone know of a shell program to retrieve the property info
> > > from windows files.  I need info like the fileversion or
> > > prodversion.
> >
> > No, so I wrote my own:
> >
> > [snip]
> >
> > See attached for the source and Makefile.
> 
> This looks useful.  Feel like proposing this for cygutils?

Sorry, but I can't fit this in right now.  If anyone else is interested,
then feel free to adopt the code and submit it to cygutils.

BTW, I found a bug when I dusted off this code yesterday:

    version.exe should "handle file not found" errors better.

Jason

-- 
PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers
Fingerprint: 7A73 1405 7F2B E669 C19D  8784 1AFD E4CC ECF4 8EF6

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-01-20 13:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-19  2:30 looking for shell program to retrieve property info from windows files Jaye Speaks
2005-01-19 13:41 ` Jason Tishler
2005-01-19 20:02   ` DePriest, Jason R.
2005-01-19 20:26   ` Igor Pechtchanski
2005-01-20 13:52     ` Jason Tishler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).