Saturday, 4 August 2012

Windows File Versioning Rules

Suppose your installation source contains a file named newstuff.dll, and the
Installer finds a copy of newstuff.dll already on the user’s hard drive. How
would you decide whether to overwrite the existing copy on the hard drive with a new copy from the source media? Your first idea might be to compare file dates; you would then overwrite if the copy in the source media was newer. A more sophisticated version of this technique is to look at the internal file version information, and overwrite if the copy in the source media has a higher version.

The Windows Installer uses an even more complex algorithm when deciding
whether to keep an existing file or install a new copy. It takes into account not just the file dates and the version, but the languages involved as well. Here’s the set of rules the Windows Installer follows:

Highest version wins: All other things being equal, the file with the highest
version number wins, whether that’s the file on the hard drive or the file in the
source media.

Any version is higher than no version at all: If the copy in the source media
contains version information, and the copy on the hard drive has no version
information, Windows Installer chooses the one with the version information.

Favor the new language: All other things being equal, if the file being
installed is localized for a different language than the file on the computer, Windows Installer uses the copy with the language that matches the product being installed.

Meet the product’s needs for multiple languages: If both copies support
multiple languages, Windows Installer ignores the common languages and uses the copy that supports the most languages out of the set of languages that the product uses.

Keep the maximum number of languages: If the copies differ in the number
of languages they support and both support all the languages that the product
needs, Windows Installer keeps the copy that supports the most languages.

Treat non-versioned files as user data: If there is no version information for
either copy, Windows Installer compares the file creation date and the last modification date for the file on the computer. If the modification date is later than the creation date, Windows Installer assumes this file has been customized by the user and does not overwrite it. Otherwise, it installs a new copy.

Companion files go along with the versioned file: It’s possible to mark a
file within the Installer database that does not include version information as a companion file to a file that does include version information. In this case, the companion file is installed if the other file is installed. There is one exception to this rule, though. If the companion file is not present on the target machine, it’s installed even if the versioned file is not installed.

It’s a good thing that these rules match the way most developers would like
installations to behave because there’s no way for you to change them. Of course, you can pervert their intention if you feel you must. One way to guarantee that a file from the source media is installed is to set its version string in the File table to 65535.65535.65535.65535, which is the maximum version number that the Windows Installer accommodates. Beware, though: if you do this, you’ll never be able to use the Windows Installer to replace that copy of the file with a new version.

No comments:

Post a Comment