addFileAssociationv2 method

void addFileAssociationv2()

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 addFileAssociationv2() {
  // create a ProgID for dcli 'noojee.dcli'
  regSetString(HKEY_CLASSES_ROOT, '.dart', defaultRegistryValueName, 'dcli');

  // When you create or change a file association, it is important to notify
  //the system that you have made a change. Do so by calling SHChangeNotify
  // and specifying the SHCNE_ASSOCCHANGED event. If you do not call
  //SHChangeNotify, the change may not be recognized until after the system
  //is rebooted.
  // computer\hkey_classes_root\.dart\OpenWithProgids => default (not set),
  // VSCode.dart

  // create a ProgID for dcli 'noojee.dcli'
  regSetString(HKEY_CURRENT_USER, r'\Software\Classes\noojee.dcli',
      defaultRegistryValueName, 'dcli');

  // associate the .dart extension with dcli's prog id
  regSetString(HKEY_CURRENT_USER, r'\Software\Classes\.dart',
      defaultRegistryValueName, 'noojee.dcli');

  // regSetString(HKEY_CLASSES_ROOT, r'.dart\OpenWithProgids', 'dcli.bat', '');

  // computer\hkey_current_user\software\classes\.dart -> default (not set)
  regSetString(HKEY_CURRENT_USER, r'SOFTWARE\Classes\.dart\OpenWithProgids',
      'noojee.dcli.dart', '');

// computer\hkey_current_user\software\classes\.dart -> default (not set)
  regSetString(HKEY_LOCAL_MACHINE, r'SOFTWARE\Classes\.dart',
      defaultRegistryValueName, 'dcli');

  //computer\hkey_classes_root\dcli\shell\open\command
  //   -> Default C:\Users\Brett\AppData\Local\Pub\Cache\bin\dcli.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
  regSetExpandString(
      HKEY_CURRENT_USER,
      r'dcli\shell\open\command',
      defaultRegistryValueName,
      '${DCliPaths().pathToDCli}  %1 %2 %3 %4 %5 %6 %7 %8 %9');

  // computer\hkey_classes_root\.dart => dcli
  // regSetString(HKEY_CURRENT_USER, '.dart', defaultRegistryValueName
  //, 'dcli');

  // [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithList]
  regSetString(
      HKEY_CURRENT_USER,
      r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithList',
      'a',
      'dcli.bat');

  /// to do check if there is any existing MRUentries
  /// and move them down unless
  /// they are for dcli
  regSetString(
      HKEY_CURRENT_USER,
      r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart',
      'MRUList',
      'a');

  // [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithProgids]
  // "dcli"
  regSetNone(
      HKEY_CURRENT_USER,
      r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dart\OpenWithProgids',
      'dcli');
}