addFileAssociation method

void addFileAssociation(
  1. String dcliPath
)

Add a file association so that typing the name of a dart script on the cli launches dcli which in turn launches the script.

main.dart
> hello world

https://docs.microsoft.com/en-us/windows/win32/shell/fa-file-types

Implementation

void addFileAssociation(String dcliPath) {
  const progIdPath = r'Software\Classes\.dart\OpenWithProgids';

  if (regKeyExists(HKEY_CURRENT_USER, progIdPath)) {
    regDeleteKey(HKEY_CURRENT_USER, progIdPath);
  }

  regCreateKey(HKEY_CURRENT_USER, progIdPath);

  regSetString(HKEY_CURRENT_USER, progIdPath, 'onepub.dcli', '');

  const commandPath = r'Software\Classes\onepub.dcli\shell\open\command';
  if (regKeyExists(HKEY_CURRENT_USER, commandPath)) {
    regDeleteKey(HKEY_CURRENT_USER, commandPath);
  }

  regCreateKey(HKEY_CURRENT_USER, commandPath);
  regSetString(
      HKEY_CURRENT_USER,
      commandPath,
      defaultRegistryValueName,
      '"${DCliPaths().pathToDCli}" '
      // the %* is meant to represent all parameters even if more than
      // 9 are passed. In my experiments it doesn't appear to pass more than
      // 8 (as %1 is already consumed)  and if fact makes no difference
      // to just using %1 in the following line. I have left it
      // in for now and may follow up later.
      '"%1"%*');
}