Tuesday 17 January 2012

Inno Setup: a better software installer

So you've written an application, written supporting documentation, designed ini, XML files or a Registry key hierarchy to store your program settings.

How do you get it all out to your users?




That question is more practically split into two separate enquiries:
  1. In what format do you supply your files so that they can be transferred for use on another PC
  2. How do you transfer your files to another PC
~
  
The Linux world largely addressed these issues with a single combined solution, the Advanced Packaging Tool (APT), first released in 1998. APT operates according to the idea of a software “repository”, an indexed list of software available for download (over a network, the Internet, or on local media, like a CD-ROM or USB drive).
The user browses the repository to identify software that they wish to install, then provides APT with the application (or “package” to use the colloquial terminology) name.

APT acquires a copy of the package, and installs it on the system. That's it.

APT is a console tool, but there are graphical front-ends (such as the Synaptic Package Manager) to drive these processes.

 Synaptic package manager in Ubuntu

It's all very simple and straight-forward:
  • Any application the user might wish to install is listed in a single central repository (Apple and Andriod users and developers will be familiar with this idea and its benefits from the Appstore and Andriod Market)

  • APT includes a very sophisticated “conflict resolution system” which takes care of transparently installing any resource dependencies listed by a package. If an application requires additional shared libraries that are provided by another vendor, APT will download these – and take care of figuring out which revision is most appropriate – before proceeding with the installation.


The Windows environment has had a more varied history. Until the advent of Office 2000 there was no operating system level support for managing software installs beyond components of the OS itself (adding or removing elements such as Windows Media Player, Notepad, Networking support etc.).

Publicly available from June 1999, Office 2000 was the first shipping product to make use of a new Microsoft technology called Microsoft Installer 1.0. This was pushed to the target PC first, and then assumed control of the installation procedure for the main office suite, remaining on the host machine once this had run to completion.

Version 1.1 followed in February 2000 as an integral part of Windows 2000. This minor version update was also compatible with the Windows 9x line.
More recently version 5.0 was delivered as a component of the Windows 7 and Windows Server 2008 R2 operating systems.

 Windows Installer versions, courtesy of Wikipedia


Windows Installer is a framework for managing software on the Windows platform. It doesn't take the form of an application that, as a computer user, you launch and run independently. Rather it is a set of services that are triggered in response to user interaction with a Microsoft Installer file (a file with a .msi extension), e.g., a double-click in Explorer, or passed as an argument to the msiexec Windows Installer Tool.

A Microsoft Installer file, an “installation package”, uses COM Structured Storage: a technique for combining lots of separate files into one contiguous file, and the methods for reading and writing to them in an abstract way – without reference to the true nature of the package file, allowing contained files to be accessed as though they existed individually.
All application files, directories, Registry keys, shortcuts, and other data (“components” in the MSI vernacular) is bound up in an installation package file.

When the file is executed (internally it is passed off to the misexec tool), the user is presented with a graphical “wizard” style interface and steps through a series of consecutive forms of the options made available to them (e.g., destination directory, registration details, language options etc.).
msiexec creates an equivalent “undo” action for every change made to the target PC, so modifications can be “rolled back” in the event of an error, user cancellation, or upon program removal.
It also supports “patching” using .msp files that modify the state of an existing installation.
~

Note, though, that no facility exists to address the second of our two early questions. There is no unified solution to the problem of locating Windows desktop software to install. There is no single Internet hosted repository (or offline catalogue) that users can look to as a guide for identifying applications which fulfil a requirement.

There is no vetting system, no merit system, no robust guarantee of safety from malware – and since Microsoft, with all of the resources at its disposal, does not provide this service to third party developers, no other vendor, lesser enriched, is ever likely to do so (this situation may change over time for Windows 8 Metro applications, which will only be available through the Windows Store).

Users are left in the unenviable position of trying to guess which software might meet their needs. For this they might consult Google, a “ratings” website, or ask some of their friends.
But in an age of ranking wars, search-engine-optimised page results, crowd-sourced “user reviews” and user naivety of best-of-breed applications, these are unlikely to prove reliable measure of usefulness.

Even when a suitable software titled has been successfully isolated, many unscrupulous websites simply re-package popular existing software in adware-laden containers (viz. VLC http://bit.ly/ohpD4b), booby traps for the unwary, luring them away from canonical download sources.
Not to mention the confusing world of trialware, freeware, open source, for-personal-use-only or other licensing variations that can confuse the uninitiated.

In fact, we can abandon any idea of coming to a resolution for this problem – there simply isn't one – and instead focus entirely on ways of dealing with the first portion of our original question: the format in which application files are supplied to end users.


Leveraging the tools

So as of Windows 2000, the Microsoft Installer framework became an integral part of the operating system. However, by that time a host of bespoke and niche tools had sprung up to fill a gap that had existed since the genesis of the Windows shell.

The requirements were simple (consider, also, that this was in an age of narrow-band Internet access):
  • minimize the number of files to be distributed (irrespective of the number of files to be included in the distribution).

  • minimize the size of the file(s) to be distributed.

  • determine a way of incorporating programming logic to orchestrate directory creation, file copying, Registry updating, etc. at the user end.

Other requirements might also be desirable, a mechanism for automatically deleting all components of an installed application when a user decides to remove it, for example, but early efforts had more modest objectives.

Some of the tools that stepped in to try to satisfy these requirements have long since fallen out of favour. It wasn't uncommon – even until recently in the case of web site authoring app KompoZer, for example – to send out an “image” of the full application as a compressed ZIP file.
WinZip later began marketing a standalone tool for “self-extracting” ZIP files, and added the same as a reduced-capability feature to their flagship WinZip product.

Compressed archives were useful for minimizing file sizes and payload, but they offered no help in tackling the other major issue, embedding some kind of scripted control of installation activities on the end user PC. At this point the onus remained with users, other than directions from a help file, it was their responsibility to decide which directories to create, and files to extract. But this was clearly a job best left to the developer, familiar with the intricacies of their own software and the landscape of the operating systems they were targeting.

Several more advanced utilities followed in quick succession towards the end of the 90s, among them Wise, InstallShield, and the Nullsoft Scriptable Install System (from the WinAmp stable).
These were all independent projects, they had overlapping functionality, they were all completely self-contained installation “engines”. None of them used the Microsoft Installer API, they evolved before it had been created, but they all implemented a comparable set of features.

It was into this climate that Jordan Russell released the first iteration of Inno Setup in 1997. Inno Setup is written in Delphi, and in the great tradition of these things, created out of dissatisfaction with the status quo. In common with its contemporaries, Inno Setup is an autonomous installation engine, it has no external dependencies, it doesn't rely upon the presence of an existent set of operating system services, just stock, plain-vanilla WinAPI.

It has maintained this autonomy, building the code base to expand its repertoire of new and unique features (see below), throughout the course of its history: anything you might require of it, as an install builder, is natively supported or easily scriptable.

Contrast this with the approach taken by the two dominant commercial alternatives, Wise and InstallShield. Both moved away from in-house back-end architectures, and retooled their products around the Microsoft Installer framework.
Subsequent years saw a tit-for-tat legal battle between the two companies, with allegations of patent infringement and even espionage (http://bit.ly/xH2OOw and http://lat.ms/ysU7DU). Legal wrangles and buyouts of both companies (Wise by Altiris, and subsequently by Symantec, InstallShield by Macrovision, then Acresso Software Corporation, now called Flexera Software) went ill for Wise, Symantec end-of-lined all products by the close of 2011.
This convergence around a common, generic solution – out-sourcing back-end functionality to the Microsoft framework – saps competitive advantage and innovation.


Going Inno

The Microsoft Installer framework was designed to provide developers with a set of interfaces for publishing their software to Windows. But because it's baked into the OS, and it's seen several updates over time, many of the more advanced features have only become available in recent Windows OS'. The most recently supported MSI for the Win9x family is 2.0; the most recently supported version for Windows 2000 is 3.1.

This page - http://bit.ly/ziwvdS – shows a list of functions unavailable prior to revision 4.0, including the much touted “advertise” feature1, the ability to install 32-bit applications on 64-bit Windows, access to the Restart Manager (which advises of those running applications which should be shut down prior to, or restarted following, updates or installs – as opposed to the entire OS), visual UAC cues, prompting for “files in use”, and a host of others (see also “What's new in Microsoft Installer 4.0” and “What's new in Microsoft Installer 4.5” http://bit.ly/wfzcSp, http://bit.ly/x7y7Nr and http://bit.ly/zv5m8A).

But more pragmatically, vendors with products built around the MSI framework are keeping parity with Microsoft's support schedule for its desktop operating systems, e.g., InstallShield's installation packages require target systems to be running Windows 2000 or later (http://bit.ly/wuzK0p).

Non-standard actions - “Custom Actions” - are complicated to add to a MSI package. MSDN gives a few examples:
  • Launching an executable during installation that is installed on the user's machine or that is being installed with the application

  • Call special functions during an installation that are defined in a dynamic-link library (DLL)

  • Use functions written in the development languages Microsoft Visual Basic Scripting Edition or Microsoft JScript literal script text during an installation

  • Defer the execution of some actions until the time when the installation script is being executed

  • Add time and progress information to a ProgressBar control and a TimeRemaining Text control

These, and other “custom” functionality, must be implemented in separate DLL files (http://bit.ly/AEfg1t).

Further, scripting is only available via VBScript or JScript; users more familiar with other common languages and dialects, the C#, C++, F#, Python, Lua, Delphi et al crowds, are limited to these choices, with as much re-learning of syntax and method libraries as that might entail.
~


With all of this in mind, lets consider why Inno Setup may be a better solution for you, particularly – but not exclusively! - as a Delphi developer.

An installer built with Inno Setup can be deployed to every 32 and 64 bit Windows version. An installer file will run equally well on everything from Windows 95A to Windows 7. It will run happily on unpatched Windows NT and Windows 2000 systems.

Inno Setup is available in ANSI and Unicode flavours. The edition you choose to install (they can be installed side-by-side) will determine which of these formats will be supported in the installation packages you build. The Unicode edition supports Unicode text throughout the IDE and on every form, control and dialog of your installation packages.

 Inno Setup with Hebrew text

Scripting, which isn't required to build an installation package (a fully functional installer can be put together by filling in just a few fields of text), offers tremendous flexibility for customizing the behaviour of your installer. There are, for example, “events” that are fired at various stages of installation (and uninstallation), and you can use any of these to prompt the user (e.g., for registration details), validate user input, show custom forms, download files, show help, cancel or rollback the install, launch an installer for a dependant application (e.g., the .Net framework), register DLLs, or any other task that isn't supported as an option in the IDE or involves more complicated logic.

Inno Setup uses PascalScript (from RemObjects) for this purpose, which implements a large proportion of the functions and classes available in native Delphi, and shares identical syntax and the language's strong typing. In fact, you could conceivably write an entire “application” using only Inno Setup, with custom forms and PascalScript to deal with processing duties – something akin to a “Microsoft Access application”, but with a different emphasis.

Eighteen example script files are included with the distribution, and the Inno Setup Help file is very thorough, with lots of annotated code snippets alongside written explanations.

Inno Setup is both freeware (with no usage restrictions), and open source. The source code is available for Delphi versions 2 through to 2009.

When you start Inno Setup a dialog box appears with several pre-defined options, including a Wizard to help guide through the process of creating a basic installer.
This can be modified later (to flesh out any extra detail that you might want to add), or used as-is: just a few clicks and a handful of fields to fill out and you have a finished install package. The install package is a single .exe file containing everything that you want to include with your distribution. Inno Setup applies compression to all of the files that are bundled into the package with zip, bzip, lzma or lzma2.

Regular updates: Inno Setup is under constant development, Jordan provides access to the very latest sources from CVS and Git repositories, but the stable binary release is updated several times a year and supports the latest operating system features (e.g., Windows 7 taskbar buttons, code signing, UAC considerations).

Third party support: there are quite a few separate tools and add-ons that are available from links on the Inno Setup download page, including:
  • InnoIDE, a graphical alternative to the text editor provided with Inno Setup. A potential time saver in that it leads you through the data gathering process, like filling in a questionnaire, instead of having to read through the documentation to see what options are available. There are also forms for generating code that corresponds to the values set in visual controls: for example a “Message Box Expert” allows the user to define the appearance of a message dialog then provides the PascalScript to invoke a matching dialog at runtime.

     InnoIDE Message Box Expert for dialog design

  • InnoScriptStudio, another graphical script building tool with very similar goals to InnoIDE.

     InnoScriptStudio options form

  • ISSkin, a “skinning” add-on that can be used to change the visual style of your finished installer package. See also Graphical Installer, a commercial (“pay what you want”) product along the same lines.
 One of the 16 or so skins available with the ISSkin extension


Skinning with Graphical Installer

...and half a dozen others that are less ambitious in scope.


Summary

I've been using Inno Setup for several years, and over that time I've made some pretty unusual demands of it but it's always been possible to achieve what I've wanted.
It strikes a perfect balance between ease of use and breadth of features; you can create a fully-functional installer in a couple of minutes, or get deep into the code and bolt on some really creative extensions.

It's a mature, stable, open-source product with regular updates, an active newsgroup and a lot of supporting websites.
If you're a Delphi user you'll be instantly at home with PascalScript, for other users the Pascal syntax is easy to pick up (it was invented as a teaching language, after all), or you can stick to one of the visual editing tools to generate some of your code.


Useful resources:

Inno Setup main page:

Inno Setup Extensions Knowledgebase:

Graphical Installer:

Inno Setup Unpacker (a tool for extracting files from a compiled installer package): http://innounp.sourceforge.net/


1 “Advertising” is a feature available in recent versions of the Microsoft Install that allows an application or feature to be made known to the user – e.g., with a Start Menu shortcut – which has not yet been installed. Clicking the link or activating the feature will cause an “on demand” installation of the item.

6 comments:

  1. This valuable editorial was very useful to read, I savored it completely.
    I'm about now to email it to my colleagues to permit them examine this too.
    Thank you really
    Inno Setup

    ReplyDelete
  2. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. Adobe Premiere Pro CC 2018 v12.0 for Mac

    ReplyDelete
  3. I admit, I have not been on this web page in a long time... however it was another joy to see It is such an important topic and ignored by so many, even professionals. I thank you to help making people more aware of possible issues. Phoenix Heights

    ReplyDelete
  4. Merely a smiling visitant here to share the love (:, btw outstanding style. Chip Eng Seng

    ReplyDelete
  5. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. OKP Holdings Developer

    ReplyDelete