Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions scripts/installer-migration.iss
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,31 @@ begin
Result := CompareText(Copy(Command, 1, Length(Prefix)), Prefix) = 0;
end;

function IsSingleCommandVerb(Key: string): Boolean;
var
Children: TArrayOfString;
begin
Result := RegGetSubkeyNames(HKCU, Key, Children);
if Result then
Result := (GetArrayLength(Children) = 1) and
(CompareText(Children[0], 'command') = 0);
if Result then
Result := RegGetSubkeyNames(HKCU, Key + '\command', Children) and
(GetArrayLength(Children) = 0);
end;

function IsOwnedWslVerb(Key, Executable: string): Boolean;
var
Command: string;
begin
Result := IsSingleCommandVerb(Key) and
RegQueryStringValue(HKCU, Key + '\command', '', Command) and
IsOwnedWslCommand(Command, Executable);
end;

function IsOwnedWslMenu(Key, Executable: string): Boolean;
var
Owner, Command: string;
Owner: string;
Children, Subkeys: TArrayOfString;
Index: Integer;
begin
Expand All @@ -337,8 +359,7 @@ begin
if not RegGetSubkeyNames(HKCU, Key + '\shell', Children) then
Exit;
for Index := 0 to GetArrayLength(Children) - 1 do begin
if not RegQueryStringValue(HKCU, Key + '\shell\' + Children[Index] + '\command', '', Command) or
not IsOwnedWslCommand(Command, Executable) then
if not IsOwnedWslVerb(Key + '\shell\' + Children[Index], Executable) then
Exit;
end;
end;
Expand All @@ -347,18 +368,15 @@ end;

procedure RemoveOwnedWslContextMenusAt(Root, Executable: string);
var
Key, Command: string;
Key: string;
Names: TArrayOfString;
NameIndex: Integer;
begin
if RegGetSubkeyNames(HKCU, Root, Names) then
for NameIndex := 0 to GetArrayLength(Names) - 1 do
if Pos('PebrelWsl', Names[NameIndex]) = 1 then begin
Key := Root + '\' + Names[NameIndex];
Command := '';
if IsOwnedWslMenu(Key, Executable) or
(RegQueryStringValue(HKCU, Key + '\command', '', Command) and
IsOwnedWslCommand(Command, Executable)) then
if IsOwnedWslMenu(Key, Executable) or IsOwnedWslVerb(Key, Executable) then
if not RegDeleteKeyIncludingSubkeys(HKCU, Key) then
RaiseException('Unable to remove an owned WSL context menu: ' + Key);
end;
Expand Down
34 changes: 34 additions & 0 deletions scripts/tests/installer-migration-fixture.iss
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,39 @@ begin
Check(FileExists(NewLink), 'shortcut pointing at another program is preserved');
end;

procedure CheckEditedWslVerbs(ShellRoot, Menu, Executable, DirectoryArgument: string;
Distros: TArrayOfString);
var
Depth: Integer;
Verb, Flat, Suffix, Value: string;
Failed: Boolean;
begin
Verb := Menu + '\shell\PebrelWsl0';
Flat := ShellRoot + '\PebrelWslLegacy';
for Depth := 0 to 1 do begin
if Depth = 0 then Suffix := '\Custom' else Suffix := '\command\Custom';
Check(RegWriteStringValue(HKCU, Verb + Suffix, '', 'keep'), 'seed edited cascade verb');
Check(RegWriteStringValue(HKCU, Flat + '\command', '',
'"' + Executable + '" --gpui --shell "wsl:Old" --working-directory "' +
DirectoryArgument + '"'), 'seed legacy verb');
Check(RegWriteStringValue(HKCU, Flat + Suffix, '', 'keep'), 'seed edited legacy verb');
Failed := False;
try
RegisterWslContextMenuAt(ShellRoot, Executable, DirectoryArgument, Distros);
except
Failed := True;
end;
Check(Failed, 'registration must reject an edited WSL verb');
RemoveOwnedWslContextMenusAt(ShellRoot, Executable);
Check(RegQueryStringValue(HKCU, Verb + Suffix, '', Value) and (Value = 'keep'),
'preserve nested user data inside cascading verbs');
Check(RegQueryStringValue(HKCU, Flat + Suffix, '', Value) and (Value = 'keep'),
'preserve nested user data inside legacy verbs');
Check(RegDeleteKeyIncludingSubkeys(HKCU, Verb + Suffix), 'remove cascade fixture edit');
Check(RegDeleteKeyIncludingSubkeys(HKCU, Flat), 'remove legacy fixture edit');
end;
end;

procedure CheckContextMenus(Root: string);
var
RegistryRoot, ShellRoot, Executable, Value, Menu, ForeignCommand: string;
Expand Down Expand Up @@ -212,6 +245,7 @@ begin
Check(not RegKeyExists(HKCU, ShellRoot + '\PebrelWsl0'), 'migrate old flat entry');
Check(RegGetSubkeyNames(HKCU, ShellRoot, Names) and (GetArrayLength(Names) = 3), 'only normal, cascade and foreign roots remain');
Check(RegGetSubkeyNames(HKCU, Menu + '\shell', Names) and (GetArrayLength(Names) = 3), 'three distros live inside cascade');
CheckEditedWslVerbs(ShellRoot, Menu, Executable, Value, Distros);
Check(RegQueryStringValue(HKCU, Menu, 'SubCommands', Value) and (Value = ''), 'enable static cascade');
Check(RegQueryStringValue(HKCU, Menu + '\shell\PebrelWsl1\command', '', Value), 'child command exists');
if Index = 0 then
Expand Down
Loading