安装前获取功能部件安装成本 [英] Get feature installation cost prior to installation

查看:105
本文介绍了安装前获取功能部件安装成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在为我们的安装制作一个自定义的boostrapper/外部UI.

We're making a custom boostrapper / external UI for our installation.

我们要提供一个自定义安装"对话框(如MSI中的对话框),以允许用户选择他们想要安装或删除的功能.

We want to provide a "Custom Installation" dialog (like in MSI) to allow the user to choose feature(s) they want to install or remove.

当前,我们能够从MSI数据库本身读取功能(以及其他功能详细信息,如描述)(通过在Feature表上运行SQL查询).

Currently, we are able to read the features (and other feature details like description) from the MSI database itself (by running an SQL query on the Feature table).

但是,我们还希望显示安装功能的成本. Windows Installer的自定义安装"对话框可以执行此操作.

However, we also want to display the cost of installing a feature. Windows Installer "Custom Installation" dialog is capable of doing this.

我认为我们可以通过执行以下操作来模仿行为:

I think we can mimic the behavior by doing the following:

  1. 选择要获取费用的Feature
  2. 使用FeatureComponents表,从1获取与功能关联的Component
  3. 使用File表,添加与2中标识的组件关联的文件的FileSize
  4. 3的总和是功能安装的费用
  1. Pick a Feature that you want to get the cost
  2. Using the FeatureComponents table, get the Component associated with the feature from 1
  3. Using the File table, add the FileSize of the files associated with the component identified in 2
  4. The sum from 3 is the cost of the feature installation

问题:

  1. 是否有一个API(来自DTF或MSI.DLL)可用于获取安装之前的功能成本? (DTF中有一个FeatureInfo.GetCost方法,但是您不能直接使用它.必须先安装该产品,然后才能从ProductInstallation调用FeatureInfo.GetCost)
  2. 如果没有API,上述步骤是否正确或正确地计算了功能安装的成本?
  1. Is there an API (either from DTF or MSI.DLL) that we can use to get the cost of a feature PRIOR to installation? (There is a FeatureInfo.GetCost method in DTF but you can't use that directly. The product must be installed first before you can call FeatureInfo.GetCost from ProductInstallation)
  2. If there is no API, is the procedure given above appropriate or correct to calculate the cost of a feature installation?

谢谢! :)

更新#1

我认为,甚至在开始安装之前,就有一种方法可以通过API获得功能安装的费用.这是我的操作方式:

I think there's a way to get the cost of a feature installation through the API even PRIOR to starting installation. Here's how I did it:

Installer.SetInternalUI(InstallUIOptions.Silent);

Session s = Installer.OpenPackage(@"C:\a.msi", false);

foreach (FeatureInfo info in s.Features)
{
    MessageBox.Show(info.Name);
    MessageBox.Show(info.GetCost(false, false, InstallState.Unknown).ToString());
}
s.Close();

调用info.name成功返​​回该功能的名称.但是,调用info.GetCost会返回InvalidHandlerException并显示消息:选择管理器未初始化".

calling info.name successfully returns the name of the feature. However, calling info.GetCost will return an InvalidHandlerException with a message: "selection manager not initialized".

我现在在这里.

更新#2:

我得到了InvalidHandlerException,因为我没有调用所需的文件成本估算程序,然后再调用info.GetCost.这是我修改后的代码:

I was getting the InvalidHandlerException because I am not invoking the needed file costing routines before I call info.GetCost. Here's my modified code:

  Installer.SetInternalUI(InstallUIOptions.Silent);

  Session s = Installer.OpenPackage(@"C:\1.msi", false);
  s["ROOTDRIVE"] = @"C:\";
  s.DoAction("CostInitialize");
  s.DoAction("FileCost");
  s.DoAction("CostFinalize");

  foreach (FeatureInfo info in s.Features)
  {
       long cost = info.GetCost(false, false, InstallState.Local);
       MessageBox.Show(info.Title + " " + cost);
  }
  s.Close();

我不再收到InvalidHandlerException,但返回的所有文件费用为-1099511627776.

I am no longer getting the InvalidHandlerException but all file cost being returned is -1099511627776.

推荐答案

是的,有一个API.您需要通过调用OpenPackage获得MSI会话.这样,您将可以访问功能"列表,该列表将使您可以访问GetCost方法.

Yes, there is an API. You need to get an MSI Session by calling OpenPackage. By doing so, you will have access to the Feature list which will give you access to the GetCost method.

1个问题:您需要执行4个标准操作才能计算费用: CostInitialize FileCost CostFinalize >和 InstallValidate .

1 Gotcha: You need to perform 4 standard actions before calculating the cost: CostInitialize, FileCost, CostFinalize and InstallValidate.

    Installer.SetInternalUI(InstallUIOptions.Silent);

    Session s = Installer.OpenPackage(@"C:\1.msi", false);
    s.DoAction("CostInitialize");
    s.DoAction("FileCost");
    s.DoAction("CostFinalize");
    s.DoAction("InstallValidate");

    foreach (FeatureInfo info in s.Features)
    {
        long cost = info.GetCost(false, false, InstallState.Local);
        MessageBox.Show(info.Title + " " + cost);
    }
    s.Close();

这篇关于安装前获取功能部件安装成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆