Uploaded image for project: 'Qt Installer Framework'
  1. Qt Installer Framework
  2. QTIFW-1251

Windows file association example is misleading

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 3.0.4
    • General
    • None
    • Windows 10 desktop PC
    • Windows

    Description

      Brief:

      I have an installer project that needs to create a file association. By following the template in the 'registerfileextension' example, I was able to create an installer that associates a file type with my program. However, double-clicking on files with my file extension causes my program to launch, but it does not pass the filename to my program as an argument, because the argument is surrounded by the wrong type of quotes.

      I believe that by changing the quotes in this example, the headaches / frustrations / hours of lost work that I experienced can be easily avoided by future users.

      Detail:

      The code in question, in 'registerfileextension/meta/installscript.qs', is here, on the third line:

      component.addOperation("RegisterFileType",
                                     component.unusualFileType,
                                     notepadPath + " '%1'",
                                     "QInstaller Framework example file type",
                                     "text/plain",
                                     notepadPath + "," + iconId,
                                     "ProgId=QtProject.QtInstallerFramework." + component.unusualFileType);
      

      This code makes a file association that launches Notepad.exe with a filename as an argument. When you double-click on a file with the unusualFileType extension, it generates a call that on the command line would look like this:

       

      c:\Windows\System32\notepad.exe 'file.ext'
      

       

      By default, my project installs to the 'C:\Program Files (x86)\prog_dir' directory. Because this is a Windows installation, and there are spaces in the directory name, I have to surround this directory name with double quotes. Because of this, when I follow the template as closely as I reasonably can, I get a command line call that looks like this:

       

      "C:\Program Files (x86)\prog_dir\program.exe" 'file.ext'
      

       

      This call will launch my program with no arguments, so it will not open the file. We did not see this behavior with the notepad.exe example, because the program path was not surrounded by quotes.

      To get the program to open the file, we need a command line call that looks like this:

       

      "C:\Program Files (x86)\prog_dir\program.exe" "file.ext"
      

      Because the argument is now surrounded by double quotes, it is not ignored.

      If the third line in the code snippet above from 'registerfileextension/meta/installscript.qs' had been written with double quotes, instead of single quotes, I never would have had this problem.

      Solution:

      This is not technically a bug, because the registerfileextension example technically works. However, it fails in its purpose to educate the user on how to register file associations with their own programs in Windows. I can think of two solutions to the problem: 1) surround the parameter in double quotes instead of single quotes, or 2) replace the registerfileextension example with a more realistic example that installs a program and associates a file extension with that program.

      I intend to submit a pull request that implements solution 1 in a few minutes, and that PR will reference this bug report. This solution would modify the third line of the code snippet above from 'registerfileextension/meta/installscript.qs' with:

       

      notepadPath + ' "%1"',
      

      If you think solution 2 would be preferable, I am willing to implement something like that as well.

      Attachments

        For Gerrit Dashboard: QTIFW-1251
        # Subject Branch Project Status CR V

        Activity

          People

            installerteam Installer Team
            ddalcino David Dalcino
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews