Explorar o código

More file association work.

- Add an OpenWithProgids value. The default value of ".iss" is still being set, though it doesn't appear to have an effect on Windows 11 (the association works without it, and changing it doesn't change the default app).

- Remove OpenWithInnoSetup verb (likely predates the "Open with" menu)

- Unregister before registering. This removes the OpenWithInnoSetup verb on existing installations.

Jordan Russell hai 8 meses
pai
achega
5e15dbf450
Modificáronse 1 ficheiros con 20 adicións e 7 borrados
  1. 20 7
      Projects/Src/IDE.FileAssocFunc.pas

+ 20 - 7
Projects/Src/IDE.FileAssocFunc.pas

@@ -67,19 +67,19 @@ begin
   if not Result then
   if not Result then
     Exit;
     Exit;
 
 
+  { Remove any cruft left around from an older/newer version }
+  UnregisterISSFileAssociationDo(Rootkey, False);
+
   SelfName := NewParamStr(0);
   SelfName := NewParamStr(0);
 
 
   SetKeyValue(Rootkey, 'Software\Classes\.iss', nil, 'InnoSetupScriptFile');
   SetKeyValue(Rootkey, 'Software\Classes\.iss', nil, 'InnoSetupScriptFile');
   SetKeyValue(Rootkey, 'Software\Classes\.iss', 'Content Type', 'text/plain');
   SetKeyValue(Rootkey, 'Software\Classes\.iss', 'Content Type', 'text/plain');
+  SetKeyValue(Rootkey, 'Software\Classes\.iss\OpenWithProgids', 'InnoSetupScriptFile', '');
 
 
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile', nil, 'Inno Setup Script');
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile', nil, 'Inno Setup Script');
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\DefaultIcon', nil, SelfName + ',1');
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\DefaultIcon', nil, SelfName + ',1');
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\open\command', nil,
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\open\command', nil,
     '"' + SelfName + '" "%1"');
     '"' + SelfName + '" "%1"');
-  SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\OpenWithInnoSetup', nil,
-    'Open with &Inno Setup');
-  SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\OpenWithInnoSetup\command', nil,
-    '"' + SelfName + '" "%1"');
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\Compile', nil, 'Compi&le');
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\Compile', nil, 'Compi&le');
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\Compile\command', nil,
   SetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\Compile\command', nil,
     '"' + SelfName + '" /cc "%1"');
     '"' + SelfName + '" /cc "%1"');
@@ -112,6 +112,16 @@ procedure UnregisterISSFileAssociationDo(const Rootkey: HKEY;
     end;
     end;
   end;
   end;
 
 
+  procedure DeleteValue(const Rootkey: HKEY; const Subkey, ValueName: PChar);
+  var
+    K: HKEY;
+  begin
+    if RegOpenKeyExView(rvDefault, Rootkey, Subkey, 0, KEY_SET_VALUE, K) = ERROR_SUCCESS then begin
+      RegDeleteValue(K, ValueName);
+      RegCloseKey(K);
+    end;
+  end;
+
 begin
 begin
   if Conditional then begin
   if Conditional then begin
     const ExpectedCommand = '"' + NewParamStr(0) + '" "%1"';
     const ExpectedCommand = '"' + NewParamStr(0) + '" "%1"';
@@ -125,11 +135,14 @@ begin
   RegDeleteKeyIncludingSubkeys(rvDefault, Rootkey,
   RegDeleteKeyIncludingSubkeys(rvDefault, Rootkey,
     'Software\Classes\InnoSetupScriptFile');
     'Software\Classes\InnoSetupScriptFile');
 
 
-  { Leave '.iss' as-is. Other apps may have added their own OpenWithProgids
-    values there, and Microsoft docs recommend against trying to delete the
-    key's default value (which points to a ProgID). See:
+  { As for '.iss', remove only our OpenWithProgids value, not the whole key.
+    Other apps may have added their own OpenWithProgids values there, and
+    Microsoft docs recommend against trying to delete the key's default value
+    (which points to a ProgID). See:
     https://learn.microsoft.com/en-us/windows/win32/shell/fa-file-types
     https://learn.microsoft.com/en-us/windows/win32/shell/fa-file-types
   }
   }
+  DeleteValue(Rootkey, 'Software\Classes\.iss\OpenWithProgids',
+    'InnoSetupScriptFile');
 
 
   { Remove unnecessary key set by previous versions }
   { Remove unnecessary key set by previous versions }
   RegDeleteKeyIncludingSubkeys(rvDefault, Rootkey,
   RegDeleteKeyIncludingSubkeys(rvDefault, Rootkey,