我用烧录引导程序编写了自己的安装程序 UI。它有一个 WPF 前端。我有一个包含 3 个 MSI 软件包的 EXE。因此,当我尝试将其安装在空间不足的磁盘中时,如何在安装程序 UI 中显示错误消息对话框?如果有足够的磁盘空间,我可以使用回调找到吗?请指教。
问问题
684 次
1 回答
2
我正在考虑做同样的事情。
秘诀是读取和解析 BootstrapperApplicationData.xml。然后,您可以使用 WixPackageProperties 元素中的 InstalledSize 属性。此链接从 PackageID 获取显示名称向您展示了如何在运行时读取该文件。请注意,您必须将 InstalledSize 添加到相关结构中。
与这些数字的总和相比,您可以自行检查磁盘空间,并在安装前将其标记给用户。
这是我的一些代码的复制/粘贴:
using System.Collections.ObjectModel;
using System.Xml.Serialization;
public class PackageInfo
{
[XmlAttribute("Package")]
public string Id { get; set; }
[XmlAttribute("DisplayName")]
public string DisplayName { get; set; }
[XmlAttribute("Description")]
public string Description { get; set; }
[XmlAttribute("InstalledSize")]
public int InstalledSize { get; set; }
}
[XmlRoot("BootstrapperApplicationData", IsNullable = false, Namespace = "http://schemas.microsoft.com/wix/2010/BootstrapperApplicationData")]
public class BundleInfo
{
[XmlElement("WixPackageProperties")]
public Collection<PackageInfo> Packages { get; set; } = new Collection<PackageInfo>();
}
public static class BundleInfoLoader
{
private static readonly string bootstrapperApplicationData = "BootstrapperApplicationData.xml";
public static BundleInfo Load()
{
var bundleFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var path = Path.Combine(bundleFolder, bootstrapperApplicationData);
var xmlSerializer = new XmlSerializer(typeof(BundleInfo));
BundleInfo result;
using (var fileStream = new FileStream(path, FileMode.Open))
{
var xmlReader = XmlReader.Create(fileStream);
result = (BundleInfo)xmlSerializer.Deserialize(xmlReader);
}
return result;
}
}
于 2016-07-06T12:57:03.437 回答