Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSI: Shouldn't silently associate file extensions with voxedit without asking the user first #521

Open
Metadorius opened this issue Sep 15, 2024 · 4 comments
Labels
OS: Windows Microsoft Windows

Comments

@Metadorius
Copy link

No description provided.

@mgerhardy
Copy link
Collaborator

mgerhardy commented Sep 15, 2024

This only happens if the user doesn't given an extension at all and selected All Formats in the filter, no?

EDIT: misunderstood - I thought this was about the file dialog - but this is about the MSI installer writing stuff into the registry.

@Metadorius
Copy link
Author

I installed it using an MSI, I don't think it asked me for association of the files at any point.

@mgerhardy mgerhardy added the OS: Windows Microsoft Windows label Sep 16, 2024
@mgerhardy mgerhardy changed the title VOXEDIT: Shouldn't silently associate file extensions with voxedit without asking the user first MSI: Shouldn't silently associate file extensions with voxedit without asking the user first Sep 17, 2024
@mgerhardy
Copy link
Collaborator

To allow the user to choose whether to associate file types with voxedit during installation, you need to introduce a custom dialog in the WiX installer. This dialog will allow users to select the file associations they want to make. You can accomplish this by creating a custom user interface (UI) and using properties to conditionally set registry entries based on the user's choices.

Here’s how to update your WiX file:

1. Add a Custom Dialog for File Associations

You need to add a new dialog in the WiX installer to ask the user whether to associate the file types with your application.

First, define the dialog in your WiX project:

<UI>
  <Dialog Id="DlgFileAssociations" Width="370" Height="270" Title="File Associations">
    <Control Id="FileTypeLabel" Type="Text" X="20" Y="15" Width="330" Height="15" Text="Select the file types you want to associate with Vengi Voxel Editor:" />
    
    <Control Id="VengiCheckBox" Type="CheckBox" X="40" Y="50" Width="200" Height="15" Text=".vengi files" Property="ASSOCIATE_VENGI" CheckBoxValue="1" />
    <Control Id="AsepriteCheckBox" Type="CheckBox" X="40" Y="75" Width="200" Height="15" Text=".aseprite files" Property="ASSOCIATE_ASEPRITE" CheckBoxValue="1" />

    <Control Id="OKButton" Type="PushButton" X="236" Y="243" Width="60" Height="17" Default="yes" Text="OK">
      <Publish Event="EndDialog" Value="Return">1</Publish>
    </Control>
  </Dialog>
</UI>

2. Modify the Registry Entries to be Conditional

The registry keys and ProgIds that associate the file extensions with voxedit need to be created conditionally, based on whether the user has checked the corresponding checkbox.

For the .vengi file association:

<RegistryValue Root="HKLM" Key="Software\vengi-voxedit\Capabilities\FileAssociations" Name=".vengi" Value="vengi-voxedit.vengi" Type="string" Condition="ASSOCIATE_VENGI=1" />
<RegistryValue Root="HKCR" Key="Applications\vengi_voxedit.exe\SupportedTypes" Name=".vengi" Value="" Type="string" Condition="ASSOCIATE_VENGI=1" />
<RegistryValue Root="HKCR" Key=".vengi\OpenWithProgids" Name="vengi-voxedit.vengi" Value="" Type="string" Condition="ASSOCIATE_VENGI=1" />
<ProgId Id="vengi-voxedit.vengi" Description="Vengi" Icon="CM_FP_voxedit.voxedit.vengi_voxedit.exe" Condition="ASSOCIATE_VENGI=1">
  <Extension Id="vengi" ContentType="application/x-vengi">
    <Verb Id="open" TargetFile="CM_FP_voxedit.voxedit.vengi_voxedit.exe" Argument="&quot;%1&quot;" />
  </Extension>
</ProgId>

For the .aseprite file association:

<RegistryValue Root="HKLM" Key="Software\vengi-voxedit\Capabilities\FileAssociations" Name=".aseprite" Value="vengi-voxedit.aseprite" Type="string" Condition="ASSOCIATE_ASEPRITE=1" />
<RegistryValue Root="HKCR" Key="Applications\vengi_voxedit.exe\SupportedTypes" Name=".aseprite" Value="" Type="string" Condition="ASSOCIATE_ASEPRITE=1" />
<RegistryValue Root="HKCR" Key=".aseprite\OpenWithProgids" Name="vengi-voxedit.aseprite" Value="" Type="string" Condition="ASSOCIATE_ASEPRITE=1" />
<ProgId Id="vengi-voxedit.aseprite" Description="aseprite" Icon="CM_FP_voxedit.voxedit.vengi_voxedit.exe" Condition="ASSOCIATE_ASEPRITE=1">
  <Extension Id="aseprite" ContentType="application/x-aseprite">
    <Verb Id="open" TargetFile="CM_FP_voxedit.voxedit.vengi_voxedit.exe" Argument="&quot;%1&quot;" />
  </Extension>
</ProgId>

3. Integrate the Dialog into the Install Sequence

To display the file association dialog during installation, insert it into the sequence:

<InstallUISequence>
  <Show Dialog="DlgFileAssociations" Before="ProgressDlg">NOT Installed</Show>
</InstallUISequence>

4. Set Default Values for the Properties

By default, the file associations will be enabled (i.e., checkboxes checked), but users can uncheck them if they don't want the associations:

<Property Id="ASSOCIATE_VENGI" Value="1" />
<Property Id="ASSOCIATE_ASEPRITE" Value="1" />

5. Finalize the CMake WiX Patch

This example assumes you’ll modify your WiX patch XML accordingly. Ensure you generate the proper fragment or include it as part of the installation project so that the CPackWiX tool can pick it up properly.

With these changes, during installation, users will be prompted with a dialog to accept or decline file type associations with voxedit, and the registry entries will be created conditionally based on their choices.

@mgerhardy
Copy link
Collaborator

<?xml version="1.0" encoding="UTF-8"?>
<CPackWiXPatch>
  <!-- Your previous fragment entries here -->
  
  <!-- Fragment to include a custom UI dialog -->
  <CPackWiXFragment Id="CM_CP_CustomFileAssociationsDialog">
    <!-- Define the custom dialog -->
    <UI>
      <Dialog Id="FileAssociationsDlg" Width="370" Height="270" Title="File Associations">
        <Control Id="FileTypeLabel" Type="Text" X="20" Y="15" Width="330" Height="15" Text="Select the file types you want to associate with Vengi Voxel Editor:" />
        
        <!-- Checkbox for file associations -->
        <Control Id="VengiCheckBox" Type="CheckBox" X="40" Y="50" Width="200" Height="15" Text=".vengi files" Property="ASSOCIATE_VENGI" CheckBoxValue="1" />
        <Control Id="AsepriteCheckBox" Type="CheckBox" X="40" Y="75" Width="200" Height="15" Text=".aseprite files" Property="ASSOCIATE_ASEPRITE" CheckBoxValue="1" />
        
        <!-- OK button -->
        <Control Id="OKButton" Type="PushButton" X="236" Y="243" Width="60" Height="17" Default="yes" Text="OK">
          <Publish Event="EndDialog" Value="Return">1</Publish>
        </Control>
      </Dialog>

      <!-- Integrate dialog into the UI flow -->
      <InstallUISequence>
        <!-- Show the file associations dialog before the install progress -->
        <Show Dialog="FileAssociationsDlg" Before="ProgressDlg">NOT Installed</Show>
      </InstallUISequence>
      
      <!-- Default property values -->
      <Property Id="ASSOCIATE_VENGI" Value="1" />
      <Property Id="ASSOCIATE_ASEPRITE" Value="1" />
    </UI>
  </CPackWiXFragment>
</CPackWiXPatch>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS: Windows Microsoft Windows
Projects
None yet
Development

No branches or pull requests

2 participants