'Setup', MessageBoxButtons.OK,

   MessageBoxIcon.Error);

  return String.Empty;

 } else return ceAppPath;

}

This function locates the Windows CE Application Manager by checking the registry of the computer using the KeyExists() function, which is defined as follows:

private string KeyExists() {

 //---get the path to the Windows CE App Manager from the registry---

 RegistryKey key =

  Registry.LocalMachine.OpenSubKey(

   @'SOFTWAREMicrosoftWindowsCurrentVersionApp PathsCEAPPMGR.EXE');

 if (key == null) return String.Empty;

 else

  return key.GetValue(String.Empty, String.Empty).ToString();

}

The location of the Windows CE Application Manager can be obtained via the registry key: 'SOFTWAREMicrosoftWindowsCurrentVersionApp PathsCEAPPMGR.EXE', so querying the value of this key provides the location of this application.

The next function to define is GetIniPath(), which returns the location of the .ini file that is needed by the Windows CE Application Manager:

private string GetIniPath() {

 //---get the path of the .ini file---

 return ''' +

  Path.Combine(Path.GetDirectoryName(

   System.Reflection.Assembly.GetExecutingAssembly().Location),

   INI_FILE) + ''';

}

By default, the .ini file is saved in the same location as the application (you will learn how to accomplish this in the next section). The GetIniPath() function uses reflection to find the location of the custom installer, and then return the path of the .ini file as a string, enclosed by a pair of double quotation marks (the Windows CE Application requires the path of the .ini file to be enclosed by a pair of double quotation marks).

Finally, you can now code the AfterInstall event handler, like this:

void RSSReaderInstaller_AfterInstall(object sender, InstallEventArgs e) {

 //---to be executed when the application is installed---

 string ceAppPath = GetWindowsCeApplicationManager();

 if (ceAppPath == String.Empty) return;

 Process.Start(ceAppPath, GetIniPath());

}

Here, you get the location of the Windows CE Application Manager and then use the Process.Start () method to invoke the Windows CE Application Manager, passing it the path of the .ini file.

Likewise, when the application has been uninstalled, you simply invoke the Windows CE Application Manager and let the user choose the application to remove from the device. This is done in the AfterUninstall event handler:

void RSSReaderInstaller_AfterUninstall(object sender, InstallEventArgs e) {

 //---to be executed when the application is uninstalled---

 string ceAppPath = GetWindowsCeApplicationManager();

 if (ceAppPath == String.Empty) return;

 Process.Start(ceAppPath, String.Empty);

}

The last step in this section is to add the setup.ini file that the Windows CE Application Manager needs to install the application onto the device. Add a text file to the project and name it setup.ini. Populate the file with the following:

[CEAppManager]

Version = 1.0

Component = RSSReader

[RSSReader]

Description = RSSReader Application

Uninstall = RSSReader

CabFiles = RSSReader.cab

For more information about the various components in an .ini file, refer to the documentation at http://msdn.microsoft.com/en-us/library/ms889558.aspx.

To build the project, right-click on RSSReaderInstaller in Solution Explorer and select Build.

Set the SmartDeviceCab1 project's properties as shown in the following table.

Property Value
Manufacturer Developer Learning Solutions
ProductName RSS Reader v1.0
Creating a MSI File

You can now create the MSI installer to install the application onto the user's computer and then invoke the custom installer built in the previous section to instruct the Windows CE Application Manager to install the application onto the device.

Using the same solution, add a new Setup Project (see Figure 18-38). Name the project RSSReaderSetup.

Figure 18-38

Using the newly created project, you can now add the various components and files that you have been building in the past few sections. Right-click on the RSSReaderSetup project in Solution Explorer, and select Add→File (see Figure 18-39).

Figure 18-39

Add the following files (see Figure 18-40):

SmartDeviceCab1ReleaseRSSReader.CAB

RSSReaderInstallerinReleaseRSSReaderInstaller.dll

RSSReaderInstallersetup.ini

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату