Skip to content

Commit

Permalink
Actually we do need to conditionally delete InnoSetupScriptFile in th…
Browse files Browse the repository at this point in the history
…e case of multiple IS installations.
  • Loading branch information
jordanrussell authored Jan 1, 2025
1 parent c45b79d commit 264e565
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Projects/Compil32.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ begin
end
else if CompareText(S, '/UNASSOC') = 0 then begin
try
UnregisterISSFileAssociation;
UnregisterISSFileAssociation(True);
except
MessageBox(0, PChar(GetExceptMessage), nil, MB_OK or MB_ICONSTOP);
Halt(2);
Expand Down
43 changes: 36 additions & 7 deletions Projects/Src/IDE.FileAssocFunc.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface

function RegisterISSFileAssociation(const AllowInteractive: Boolean; var AllUsers: Boolean): Boolean;
procedure UnregisterISSFileAssociation;
procedure UnregisterISSFileAssociation(const Conditional: Boolean);

implementation

Expand All @@ -27,7 +27,8 @@ function GetRootkey: HKEY;
Result := HKEY_CURRENT_USER;
end;

procedure UnregisterISSFileAssociationDo(const Rootkey: HKEY); forward;
procedure UnregisterISSFileAssociationDo(const Rootkey: HKEY;
const Conditional: Boolean); forward;

function RegisterISSFileAssociation(const AllowInteractive: Boolean; var AllUsers: Boolean): Boolean;

Expand Down Expand Up @@ -85,13 +86,41 @@ function RegisterISSFileAssociation(const AllowInteractive: Boolean; var AllUser

{ If we just associated for all users, remove our existing association for the current user if it exists. }
if AllUsers then
UnregisterISSFileAssociationDo(HKEY_CURRENT_USER);
UnregisterISSFileAssociationDo(HKEY_CURRENT_USER, False);

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;

procedure UnregisterISSFileAssociationDo(const Rootkey: HKEY);
procedure UnregisterISSFileAssociationDo(const Rootkey: HKEY;
const Conditional: Boolean);
{ If Conditional is True, no action is taken if the association exists but
doesn't point to the currently-running EXE file. That can happen when there
are multiple Inno Setup installations in different paths. When one of them
is uninstalled, the association shouldn't be unregistered if a different
installation currently "owns" it. }

function GetKeyValue(const Rootkey: HKEY; const Subkey: PChar;
var Data: String): Boolean;
var
K: HKEY;
begin
Result := False;
if RegOpenKeyExView(rvDefault, Rootkey, Subkey, 0, KEY_QUERY_VALUE, K) = ERROR_SUCCESS then begin
if RegQueryStringValue(K, nil, Data) then
Result := True;
RegCloseKey(K);
end;
end;

begin
if Conditional then begin
const ExpectedCommand = '"' + NewParamStr(0) + '" "%1"';
var CurCommand: String;
if GetKeyValue(Rootkey, 'Software\Classes\InnoSetupScriptFile\shell\open\command', CurCommand) and
(PathCompare(CurCommand, ExpectedCommand) <> 0) then
Exit;
end;

{ Remove 'InnoSetupScriptFile' entirely. We own it. }
RegDeleteKeyIncludingSubkeys(rvDefault, Rootkey,
'Software\Classes\InnoSetupScriptFile');
Expand All @@ -107,11 +136,11 @@ procedure UnregisterISSFileAssociationDo(const Rootkey: HKEY);
'Software\Classes\Applications\Compil32.exe');
end;

procedure UnregisterISSFileAssociation;
procedure UnregisterISSFileAssociation(const Conditional: Boolean);
begin
UnregisterISSFileAssociationDo(HKEY_CURRENT_USER);
UnregisterISSFileAssociationDo(HKEY_CURRENT_USER, Conditional);
if IsAdminLoggedOn then
UnregisterISSFileAssociationDo(HKEY_LOCAL_MACHINE);
UnregisterISSFileAssociationDo(HKEY_LOCAL_MACHINE, Conditional);

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
Expand Down

0 comments on commit 264e565

Please sign in to comment.