Peijen's Programming Thread 1.1

Posts you want to find years later go here.
Post Reply
Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Peijen's Programming Thread 1.1

Post by Peijen »


quantus
Tenth Dan Procrastinator
Posts: 4891
Joined: Fri Jul 18, 2003 3:09 am
Location: San Jose, CA

Post by quantus »

This web site was last updated on 03-11-2003.
Are you sure that's still being updated? I wouldn't touch it anyway of course, but you might be crazy enough to do it...
Have you clicked today? Check status, then: People, Jobs or Roads

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

quantus wrote:
This web site was last updated on 03-11-2003.
Are you sure that's still being updated? I wouldn't touch it anyway of course, but you might be crazy enough to do it...
ha, good point. and yes I am writting programs with it as I am typing this.

binary adder works except it doesn't trim leading zeros(?) yet. if you are wondering why I am looking at sml it's because I am trying to figure out how continuation works (never did get it while taking 212), and I think I got it down.

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

Best error code ever (concerning database transaction)

Code: Select all

Console.WriteLine("Roll back attempt failed, you are screwed!");
:twisted:

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

I promised this long time ago, and I never did get to write about the inner workings of Windows installer, since I don't think I will never write it up I am going to post what I have. There is not really any useful information for most if any of you. Someday I might be bored enough to do a write up of windows installer's inner working.

Remember I wrote this to spit the IT programmers.

=============
Create
MSI Package Using Visual Studio .NET
And
Bootstrapping Program Using dotNetInstaller


CREATE AN INSTALLER FOR THE SOLUTION 1
INTRODUCTION 1
PROCEDURE 1
Add Deployment Project To Solution 1
File System View 3
Registering COM Objects 4
Custom Actions View 5
Build MSI Package 6
NEXT STEP 7
BOOTSTRAPPING INSTALLATION PROCESS 8
INTRODUCTION 8
PROCEDURE 8
Configure Bootstrapper 8


Create An Installer For The Solution
Introduction
Software developed by programmers will not be much use if they cannot be successfully distributed to the end users. One way to address this need is using batch script. Creating a batch file to distribute software is simple but there are problem associated with it, namely we can forget to include a necessary DLL or not register a component. Also, when we need to remove the software from an end user’s computer, we might not be able to safely remove some shared DLLs if other software are also using them. Another consideration we need to taking into account is that some DLLs need to be copied to Windows’ system directory, which might be at different locations, depending on the setup.
Microsoft Installer, or MSI, can be used to address some of these problems. For example, when DLLs are registered with regsvr32.exe it updates the registry but it does not actually copy the DLL to its destination. With batch files we can simple copy the DLL to its destination, but this could cause problems when the DLL we are copying is an older version than the one that already exists on user’s computer. MSI could check for the currently installed DLL’s version and determine if it’s necessary to update. Also, during the uninstall process it de-references usage count, and if usage count is less than one then MSI would delete the DLL from user’s computer. With this method we will less likely to delete the shared DLL when it’s still needed by other software. The MSI also reads the environment variable that points to Windows and the user’s home directory so we can copy necessary files to the correct destination, regardless of Windows’ version.
This paper discusses how to create a Windows Installer to distribute software using Microsoft Visual Studio .NET.
Procedure
Add Deployment Project To Solution
In Visual Studio .NET (VS.NET) a “Solution” is similar to the “Workspace” from the previous version of Visual Studio. However, VS.NET offers a major advantage with Solution through its ability to group projects using different programming languages in the same Solution that Workspace does not provide. This enables the programmer to put all the components for the software together; from DLLs that was written in C++ to GUI that was written in VB.
To create a MSI package, add a new project to the solution and select “Setup and Deployment Project” (Figure 1), and select “Setup Project” from templates.

• Figure 1
The first thing we should do is enter necessary information for the installer into the property window. Manufacture, ProductName, Title, and Version should be entered because they are actually used by the installer for display, and determine if the software has already been installed or not. We can read the value of a property using [PROPERTY], for example [ProductName] would give us ‘Sample’ (Figure 2).

• Figure 2
There are six views (Figure 3) available in the unified deployment editor that one can use to perform necessary actions: File System, Registry, File Types, User Interface, Custom Actions, and Launch Conditions. This document discusses File System view and Custom Actions view. For a more complete explanation on unified deployment editor go here .

• Figure 3
File System View
By default three folders are added to the file system view: Application Folder, User’s Desktop, and User’s Program Menu. Application Folder is where the program will be installed. It’s default to “drive:\Program Files\[Manufacture]\[ProductName]\” and can be changed during installation by user. User’s Desktop points to the desktop, and User’s Program Menu is the menu that user brings up by selecting Start->Programs. We can also add other predefined folders by right click on “File System on Target Computer” (Figure 4). For more information about special folders go here .

• Figure 4
We can add files for the program to be installed on the user’s computer by right clicking on the destination folder, and add project output or files (Figure 5). After we have added all the necessary files make sure to check detected dependencies and exclude any dependencies from other libraries we will be installing during the Bootstrapping Installation Process, and project output we already included.

• Figure 5
Registering COM Objects
If the project includes COM DLLs, they will need to be registered so the software knows where to find them. There are two ways to register a DLLs: as a shared component, or private component. When a DLL is registered as a shared component, it’s usually stored under Windows’ system directory, and one copy of the file is used by every program. Private components are usually stored in the same directory where software’s executables are installed -each software keeps a copy of the private component for their own use.
To register a COM DLL, select the DLL in file system view and open the property window. Change the “Register” property to “vsdrfCOM” for shared component, or “vsdrfCOMRelativePath” for private component (Figure 6).

• Figure 6
Custom Actions View
Sometime we need to perform actions that are beyond MSI package’s capability . We can achieve this by defining a custom action. Custom action involves running a program, or script, that performs extra needed functions. There are four instances in which custom actions can be performed: Install, Commit, Rollback, and Uninstall. We will look at install and uninstall, for more information about custom actions go here .
Let’s say we need to create ODBC datasource names for our program during installation, and remove the datasource name when user uninstalls the program. We write a small program that takes ‘/Install’ or ‘/Uninstall’ as it’s first argument and the path where the databases are located as the second argument. Only files added to the project can be used in custom action so we need to add the program to the project before we can add it to custom actions view. To add programs for custom actions, right click on ‘Custom Actions’ and then select ‘Add Custom Actions’ (Figure 7).

• Figure 7
Once we added the program to custom actions we can pass values to it with command-line arguments. To specify command-line arguments, select the program in custom actions view and go to the property window and enter desired information into ‘Arguments’ property. The default argument is ‘/Install’ for actions during installation, and ‘/Uninstall’ for actions during uninstall process, etc. In our example, we want to pass the directory we install the program to as second argument, so we use [TARGETDIR] as the additional argument (Figure 8).

• Figure 8
Build MSI Package
When creating MSI package with VS.NET, a bootstrapper is automatically created by VS.NET. To remove this bootstrapper right click on the deployment project and bring up the property window. Set the bootstrapper to ‘None’ (Figure 9), build the project and there should be an .msi file in the output directory.

• Figure 9
Next Step
Usually a software will require other libraries to function correctly. For small libraries such as VB 6.0 runtime DLL, we can simply include them with the installer, but some libraries are quite large and if the user already has it installed we can make the installer smaller by not including them. We can have the MSI perform the necessary check and ask the user to download and install the missing libraries themselves, but this method might turn the user away from our software. A more user friendly way is to figure out which libraries are already installed on user’s computer then download and install the missing libraries for the user with minimum interaction. This is where bootstrapper comes into play.

Bootstrapping Installation Process
Introduction
Often programmer uses third party libraries such as .NET framework, MDAC, or Jet Database Engine, in their software because it’s convenient and cuts down development time. Problems arises when the user does not have the library install on their computer, and the programmer cannot simply bundle it with their software. For example .NET framework redistribution is 20 megabytes in size, MDAC requires restart on Windows 9x computer but not Windows NT based computer, and Jet Database Engine have different installer for different version of Windows.
One way to address this problem is to use a program that gets executed before our MSI package and install necessary libraries, AKA bootstrapper. Most installation package comes with a bootstrapper because Microsoft Windows Installer has to be present for the MSI package to work and the bootstrapper will install the MSI if it’s not present before it installs the actual package. Our bootstrapper works in a similar fashion by detecting installed component version and install components as necessary.
Instead of creating our own bootstrapper this document uses a freeware called dotNetInstaller created by DevAge Software.
Procedure
Create Bootstrapper Configuration
Download the dotNetInstaller from their web site, you will need these three files: dotNetInstaller.exe, InstallerEditor.exe, SourceLibrary.dll (comes with InstallerEditor.exe). Start InstallerEditor.exe and create a new configuration file. Right click on ‘Config File’ and add a setup configuration (Figure 10). Set focus to install and update ‘dialog_caption’, ‘dialog_message’, and ‘installation_completed’ properties as necessary (Figure 11).

• Figure 10

• Figure 11
Add Component
Next add a component to install MSI installer by right clicking on install->Add->Command Component (Figure 12), update ‘description’ and ‘installmessage’ as desired.

• Figure 12
We want to make sure we only install the component if current or newer version of the component is not already installed. To do this we add a file check to our component by right clicking on the component->Add->Installed Check Registry (Figure 13). Select Installed Check set ‘comparison’ to version, ‘filename’ to #SYSTEMPATH\msiexec.exe, and ‘fileversion’ to 2.0 (Figure 14).

• Figure 13

• Figure 14
There are two setup programs for MSI: one for Win9X system (InstMsiA.exe) and one for WinNT system (InstMsiW.exe). To make sure we use the correct version of the installer, we perform an OS version check using ‘os_filter_greater’ and ‘os_filter_smaller’. For Win9X install, select Microsoft Windows Installer 2.0 component and set ‘os_filter_smaller’ to 35 and ‘command’ to “#TEMPPATH\InstMsiA.exe” /q. To account for WinNT systems we create a second components as before but instead of setting ‘os_filter_smaller’ we set ‘os_filter_greater’ to 25, and ‘command’ to “#TEMPPATH\InstMsiW.exe” /q.
Install Components
Now we have the component setup we need to physically distribut the file. We add a download dialog to our component (). You probably want to edit ‘dialog_caption’ and ‘dialog_message’ ().

• Figure 15

• Figure 16
Next we add download file to the download dialog (). Edit ‘componentname’ and set ‘destinationpath’ to #TEMPPATH\. Assume the WinNT systems’ installation file is available for download at http://www.transamericaworksite.com/MSI2.0/InstMsiW.exe we enter that into ‘sourceurl’ property ().

• Figure 17

• Figure 18
Do the same for Win9X component of Micorsoft Windows Installer setup file.
Install Our Package
Some more text goes here.

Guns, lots of guns
Introduction
VS.NET’s deployment project is somewhat limited in capability for example it doesn’t create or update ini file. By using software included in Microsoft Platform SDK we will be able to perform additional functionality not supported by VS.NET’s deployment project. The program we are interested in is ORCA.

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

hahahaha, so true
In the old days, just having the ability to call subroutines was a great advance. Then libraries of code became popular -- everything had to be library. Nowadays, libraries aren't good enough. You've got to have a framework to be taken seriously.

Peijen
Minion to the Exalted Pooh-Bah
Posts: 2790
Joined: Fri Jul 18, 2003 2:28 pm
Location: Irvine, CA

Post by Peijen »

This is to remind myself to write up how to encrypt and sign xml documents.

Post Reply