Distributing a .NET Compact Framework Application


Now that you have packaged your application in a self-extracting CAB file, you will need to make this CAB file available to your customers. Before we move on to discussing ways to distribute your application, let us examine what other files, if any, you need to distribute with your application.

It is not guaranteed that the target device will have the .NET Compact Framework installed. You may need to include the .NET Compact Framework CAB file in your distribution. Also, most commercial programs rely on components, managed or native, that may not be included in the CAB file for your application. You may need to package these other components in their own CAB file.

Now we can discuss the different ways to distribute your application. Any Windows CE application, not just a .NET Compact Framework application, can be distributed through these four different sources:

  • From a Web site

  • From a file share

  • From a memory card

  • Through ActiveSync

In addition to these four distribution strategies, you can distribute your application from one device to another over an infrared connection. This is not a serious distribution strategy and will not be discussed in this chapter.

Distributing Your Application from a Web Site

Distributing your CAB files via a Web site is an easy and efficient solution. Your customers never have to go to the store or order from a catalog. They simply browse your Web site through Pocket Internet Explorer and download the CAB files from your Web server. Once the CAB files are on the device, the user simply clicks the CAB files, and installation begins. Also, you can make updates, service packs , patches, and new releases available on the Web site at any time.

Distributing Your Application from a File Share

Distributing your CAB files via a file share is just as easy and efficient as distributing them from a Web site. This is not a sufficient solution for worldwide deployment of your application, as a Web site would be, but this deployment scenario is very attractive if you are an enterprise developer who is creating a solution for the employees in your company. The employees would have access to some internal file shares from which they could access and download product CAB files.

Distributing Your Application on a Memory Card

The Pocket PC OS provides a special feature that allows applications to be installed and uninstalled when a memory card is inserted and removed from the card slot. You could distribute your application to Pocket PC users on a memory card. When they insert the card into the Pocket PC, the OS will search the root directory for a subdirectory that has the same name as the device's processor. If that subdirectory is found, the OS will search it for an Autorun.exe file. If this file is found, it is copied to the \Windows directory. Next the OS attempts to execute the Autorun.exe file with the install parameter. When the memory card is removed, the OS will execute Autorun.exe with the uninstall parameter. Fortunately, the Windows Platform SDK for Pocket PC provides an example Autorun.exe file. You can use this to install and uninstall your application when you distribute it to your Pocket PC users on a memory card.

Distributing Your Application Through ActiveSync

You can also use the ActiveSync connection between the user's desktop and device to distribute your application. ActiveSync provides a desktop component called the Application Manager to manage the installation of applications on a device.

The Application Manager uses an initialization ( .ini ) file to manage the installation of the application. The Application Manager also requires a desktop setup application that must check whether a current version of Application Manager is installed. If the Application Manager is installed, then the Application Manager is called, passing the .ini file.

Creating an Application Manager Initialization File

Let's examine the initialization file. The .ini file has the following format:

 
 [CEAppManager] Version      =  1.0  Component    = component_name [component_name] Description  =  descriptive_name  [Uninstall   =  uninstall_name  ] [IconFile    =  icon_filename  ] [IconIndex   =  icon_index  ] [DeviceFile  =  device_filename  ] CabFiles     = cab_filename [,cab_filename] 

The key values are now described:

component_name This is the name of the section that contains the application initalization keys.

descriptive_name This is the name that will appear in the Description field of the Application Manager when a user chooses the application.

uninstall_name Identifying the application's Windows Uninstall registry key name, this name must match the key name found in the HKLM\Software\Microsoft\Windows\ CurrentVersion\Uninstall registry key. This allows the Application Manager to remove the application from the desktop computer and the device automatically.

icon_filename This identifies the desktop icon file. This string is used to display the device_filename when the filename is viewed in ActiveSync.

icon_index This numeric index in icon_filename is used to display the device_filename when it is viewed in ActiveSync. If this key is nonexistent, the first icon in icon_filename is used.

device_filename This filename on the device will display the icon specified by icon_filename and icon_index when the device_filename is viewed in ActiveSync.

cab_filename This is the filename of the available CAB files, relative to install_directory . Use commas to separate multiple cab_filenames .

Creating an Application Manager Desktop Setup File

The Application Manager also requires a desktop setup application. This setup application must check to make sure that Application Manager is installed and then calls Application Manager, passing the .ini file. Listing 16.2 presents part of a managed Application Manager desktop setup application written in C#:

Listing 16.2
 static string APPMAN_REGKEY_NAME =   "software\Microsoft\Windows\" +   "CurrentVersion\App Paths\CEAppMgr.exe"; static bool GetAppManPath(out string appManPath) {   appManPath = null;   RegistryKey appManRegKey =     Registry.LocalMachine.OpenSubKey(APPMAN_REGKEY_NAME);   if(appManRegKey != null) {     MessageBox.Show("Application Manager not found");      return false;   }   appManPath = (string)appManRegKey.GetValue(null);   if(appManPath == null) {     MessageBox.Show("Application Manager not found");     return false;   }   return true; } 

The GetAppManPath is used to get the path and filename to the Application Manager. This is done by opening registry key software\Microsoft\Windows\CurrentVersion\App Paths\ CEAppMgr.exe , which is located in the Local Machine registry hive. If this registry key does not exist, the Application Manager is not installed, and the application displays an error message.

Next the function gets the value of the default key under software\Microsoft\Windows\ CurrentVersion\App Paths\CEAppMgr.exe . This value is the path to the Application Manager. If this value does not exist, something must have gone wrong with the Application Manager installation, and we cannot run the Application Manager. In this case an error message is displayed to the user. If the path is found, then it is returned in the appManPath out parameter. Listing 16.3 describes how to launch Application Manager.

Listing 16.3
 static void LaunchAppMan(string appManPath, string iniFilePath) {   string quotedIniFilePath= "\" + iniFilePath + "\"";   ProcessStartInfo processInfo =     new ProcessStartInfo( appManPath,quotedIniFilePath)   processInfo.CreateNoWindow = true;   Process.Start( processInfo ); } 

The LaunchAppMan function is a process that launches the Application Manager with the .ini filename as the sole parameter. The function assumes that the filename is completely qualified. Then, it launches the Application Manager with the fully qualified .ini filename. This function will end after launching the Application Manager without waiting for the Application Manager to end. Listing 16.4 contains the driver function for the Application Manager executable.

Listing 16.4
 static int Main(string[] args) {   string appManPath = null;   if(!AppManInstaller.GetAppManPath(out appManPath)       appManPath == null) {     return 1;   }   if(args.Length > 0)     MessageBox.Show("No initialization file was specified");   LaunchAppMan(appManPath, string.Empty);   return 0; } 

The Main function glues the GetAppManPath method and LaunchAppMan method together. First the path to Application Manager is found using the GetAppManPath method. If the path cannot be found, then an error code of 1 is returned. Then we pull the setup .ini filename from the command line arguments and use it along with the path to Application Manager to call the LaunchAppMan method.

You now have a desktop setup application that you can use to distribute and install your application through ActiveSync.



Microsoft.NET Compact Framework Kick Start
Microsoft .NET Compact Framework Kick Start
ISBN: 0672325705
EAN: 2147483647
Year: 2003
Pages: 206

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