26.8 Building CAB Files for Application Distribution

 <  Day Day Up  >  

You want to create an installation for mobile devices.


Technique

Installing an application to a mobile device is understandably more difficult than installing a desktop computer. You create the main packaging for a Smart Device Application using cabinet (CAB) files, which contain not only the program itself but also a device information file (INF) specifying the installation steps to take on the device.

Because devices can all use different processors, you must create CAB files for each supported processor. The .NET Framework was built with support for five processors, which means you need CAB files for each one. The Visual Studio .NET IDE has this support automatically built in. To create the necessary CAB file, highlight the project name within Solution Explorer and select Build, Build Cab File from the main menu. This step launches the CAB file creation tool named cabwiz.exe . After the process completes, the corresponding CAB files are placed in the CAB subdirectory of your project's main directory.

Although the ability to automatically generate CAB files for distribution is a nice feature added to the IDE, it creates only the necessary defaults without allowing you to customize the device installation. The default behavior is to place your application in the location specified in your project properties and to create a shortcut to that application in the Programs program group . To customize the application further, you have to edit the INF file that cabwiz.exe uses and then directly run cabwiz.exe to generate the CAB files again.

The following technique demonstrates a possible INF edit you can make and how to rerun the cabwiz.exe tool to regenerate the CAB files. To begin, find the folder named obj/Debug or obj/Release depending on which build mode you are in. In that folder, you find the INF file as well as a .bat file used to launch cabwiz.exe . You are going to edit the INF file to add a new Registry entry on the device.

Within the INF file, locate the recipe labeled [DefaultInstall] and add a new entry named AddReg , setting its value equal to RegSettings . The DefaultInstall recipe should appear as follows :

 
 [DefaultInstall] CEShortcuts=Shortcuts CopyFiles=Files.Common AddReg = RegSettings 

Next, create a new section named [RegSettings] . When the device parses the INF file, it looks for the AddReg section and adds any Registry entries found within the corresponding section that you are about to create. The format for a Registry entry in the INF file uses the following syntax:

 
 <registry key>, <registry subkey>, <value name>, <value type>, <value data> 

The Registry key is a root Registry key, which you can specify using an acronym. For example, you can abbreviate HKEY_LOCAL_MACHINE using HKLM . The name for the value can be any string, and if you leave it empty, the default Registry value is filled in. Finally, the value type is an integer value specifying whether the value data is a string, DWORD , byte data, or multiple string value. The following example creates three Registry entries, one of which is a string and the other two DWORD values:

 
 [RegSettings] HKLM, Software\My Company\My Application,, 0x00010003, Copyright (c) 2003 My Company HKLM, Software\My Company\My Application, VersionMajor, 0x00010001, 1 HKLM, Software\My Company\My Application, VersionMinor, 0x00010001, 0 

Registry entries are not created in the generated INF file that Visual Studio .NET creates, which is why we focused on them in this recipe. The INF file is logically organized, and determining the method to create shortcuts or additional files is a matter of following the same methods already present in the INF file.

When you finish editing the INF file, you can double-click on the BuildCab.bat file to regenerate the CAB files. One word of caution: If you use the Build Cab File menu item within Visual Studio .NET after editing the INF file, the changes you make are lost. Therefore, either back up the INF file after the changes are made or move the BuildCab.bat and INF file to another location and fix the path information before running it in the new location.

Comments

CAB files are created using an INF file. This INF file serves two purposes. The first is to tell the CAB file creation utility, cabwiz.exe , where the binary files for your application exist. This INF file is then placed within the CAB file itself when they are created to serve a secondary purpose. When the mobile device unpacks the CAB file when it's finished downloading, the INF file determines where the files go, which Registry settings to create, and whether any shortcuts need to be made.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net