views:

39

answers:

1

I know for dll files you can read an Assembly version, but I was wondering if there's some way to mark or read versions from ANY filetype (jpg for example). I'm making an update program that only updates what's necessary and it'd be better if all files were versioned instead of keeping track of versions in a separate file.

Oh and this is intended for winXP but if I there is a win7/windup solution that'd be awesome.

+1  A: 

The version of an assembly is something that is specific to the assembly file format. A general "file" (such as a JPEG file) is just a bag of bits and the Windows filesystem doesn't have any "version" metadata associated with such a file.

One approach to solve your problem might be to compute a hash (such as using SHA1) over the content of the file. If you have two files and the SHA1 hashes match, then you can be pretty darn sure that the complete contents also match. (You can't be that sure with an embedded file version.)

Greg Hewgill
Is there a way to attach a custom metadata attribute to these files before I distribute them? And then have my updater read that metadata attachment?
myermian
_some_ file formats are designed in such a way that you can inject arbitrary data (eg .gif) This is usually done through the science of steganography (see http://www.garykessler.net/library/steganography.html ). However, this only applies to a very few files there is no general way to achieve this. You'd be better off maintaining your own database, detecting file changes by mis-matched hashes
Basiclife
@myermian: No, not in a portable and robust way. The only way I can think of for Windows is to use NTFS alternate file streams, but such streams are not reliably copied when the file is copied, and aren't even supported on filesystems such as FAT. Besides, what would you do if somebody changed the file content but not the metadata?
Greg Hewgill
@Greg Hewgill: I guess it is what it is then... SHA1 should probably do the job without worrying about false collisions. It's possible, but astronomically improbable, especially since it'd have to collide on the same file name.
myermian