“创建快捷方式”复选框

发布于 2024-10-11 09:53:23 字数 141 浏览 10 评论 0原文

我正在使用 WiX Tool 来创建安装程序。

在创建“开始”菜单和桌面快捷方式时,我需要安装程序将其设为可选。

类似于:[   ]您想创建开始菜单快捷方式吗?

这可能吗?

I'm using the WiX Tool to create an installer.

I need the installer to make it optional, when creating Start Menu and Desktop shortcuts.

Something like: [   ] Do you want to create a start menu shortcut?

Is that possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尴尬癌患者 2024-10-18 09:53:23

是的,这绝对是可能的。总体思路是使快捷方式组件以属性为条件,然后自定义 UI 以将复选框连接到该属性。

所有这些都在 Wix 教程 中进行了描述(尽管不是针对您的具体示例),这是一本富有洞察力的读物。但这里有一些适合您的情况的更具体的代码示例:

添加属性

创建一个可以将复选框挂接到的属性。在 .wxs 文件中,添加一个 Property 来存储该值。

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product ...>
    <Property Id="INSTALLSHORTCUT" />
  </Product>
</Wix>

添加一个条件

将一个 Condition 添加到安装快捷方式的组件,因此它以以下值为条件:您的新 INSTALLSHORTCUT 属性。

<Component Id="ProgramFilesShortcut" Guid="*">
  <Condition>INSTALLSHORTCUT</Condition>
  <Shortcut Id="ProductShortcut" ... />
</Component>

添加复选框

您需要自定义一个对话框以将复选框添加到 UI 并将其挂接到 INSTALLSHORTCUT 属性。我不会在这里详细介绍所有细节,但这里有一个很好的教程:用户重新访问界面

您需要下载 wix 源代码树以获取您正在使用的 UI 的 .wxs 文件。例如,要将复选框添加到 WixUI_InstallDir UI 中的 InstallDir 对话框,您需要下载 WixUI_InstallDir.wxsInstallDirDlg.wxs。将它们添加到您的 Wix 项目中并重命名它们(例如,Custom_InstallDir.wxsCustom_InstallDirDlg.wxs)。

编辑 Custom_InstallDirDlg.wxs 以添加复选框。也为

指定一个新的 Id

<Wix ...>
  <Fragment>
    <UI>
      <Dialog Id="InstallDirAndOptionalShortcutDlg" ...>
        <Control Id="InstallShortcutCheckbox" Type="CheckBox" 
                 X="20" Y="140" Width="200" Height="17" 
                 Property="INSTALLSHORTCUT" CheckBoxValue="1" 
                 Text="Do you want to create a start menu shortcut?" />
       </Dialog>
     </UI>
   </Fragment>
 </Wix>

编辑 Custom_InstallDir.wxs 以使用自定义的 InstallDirAndOptionalShortcut 对话框:

<Wix ...>
  <Fragment>
    <UI Id="Custom_InstallDir">

      ** Search & Replace all "InstallDirDlg" with "InstallDirAndOptionalShortcut" **

    </UI>
  </Fragment>
</Wix>

最后,在主 .wxs 文件中引用您的自定义 UI:

<Wix ...>
  ...
  <UIRef Id="Custom_InstallDir" />
  ...
</Wix>

Yes, this is definitely possible. The general idea is to make the shortcut component be conditional on a property, then customize your UI to connect a checkbox to that property.

All of this is described (though not for your specific example) in the Wix Tutorial, an insightful read. But here are some more specific code samples for your case:

Add a Property

Create a property that you can hook the checkbox up to. In your .wxs file, add a Property to store the value in.

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product ...>
    <Property Id="INSTALLSHORTCUT" />
  </Product>
</Wix>

Add a Condition

Add a Condition to the component that installs the shortcut, so it's conditional on the value of your new INSTALLSHORTCUT property.

<Component Id="ProgramFilesShortcut" Guid="*">
  <Condition>INSTALLSHORTCUT</Condition>
  <Shortcut Id="ProductShortcut" ... />
</Component>

Add the Checkbox

You need to customize a dialog to add a checkbox to the UI and hook it up to the INSTALLSHORTCUT property. I won't go into all the details here, but there's a good tutorial here: User Interface Revisited

You'll need to download the wix source tree to get the .wxs files for the UI you are using. To add the checkbox to the InstallDir dialog in the WixUI_InstallDir UI, for example, you would download WixUI_InstallDir.wxs and InstallDirDlg.wxs. Add them to your Wix project and rename them (e.g., Custom_InstallDir.wxs and Custom_InstallDirDlg.wxs).

Edit Custom_InstallDirDlg.wxs to add your checkbox. Give the <Dialog> a new Id too:

<Wix ...>
  <Fragment>
    <UI>
      <Dialog Id="InstallDirAndOptionalShortcutDlg" ...>
        <Control Id="InstallShortcutCheckbox" Type="CheckBox" 
                 X="20" Y="140" Width="200" Height="17" 
                 Property="INSTALLSHORTCUT" CheckBoxValue="1" 
                 Text="Do you want to create a start menu shortcut?" />
       </Dialog>
     </UI>
   </Fragment>
 </Wix>

Edit Custom_InstallDir.wxs to use the customized InstallDirAndOptionalShortcut dialog:

<Wix ...>
  <Fragment>
    <UI Id="Custom_InstallDir">

      ** Search & Replace all "InstallDirDlg" with "InstallDirAndOptionalShortcut" **

    </UI>
  </Fragment>
</Wix>

Finally, reference your customized UI in your main .wxs file:

<Wix ...>
  ...
  <UIRef Id="Custom_InstallDir" />
  ...
</Wix>
梦毁影碎の 2024-10-18 09:53:23

在复选框单击事件或下一个按钮单击上,您可以调用自定义操作来创建快捷方式。

On the checkbox click event or on the next button click you can call an custom action to create shortcuts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文