Skip to content
Open
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
59 changes: 41 additions & 18 deletions coreutils.iss
Original file line number Diff line number Diff line change
Expand Up @@ -239,32 +239,52 @@ begin
g_HasUsablePowerShell := g_HasUsablePowerShell and (g_PowerShellExecutionPolicy <> '');
end;

procedure RunPwshScript(const ExtraParams: String);
function RunPwshScript(const ExtraParams: String; IgnoreFailure: Boolean): Boolean;
var
Output: TExecOutput;
Params, Detail: String;
ResultCode: Integer;
begin
Result := False;
Params := '-NoProfile -NonInteractive -ExecutionPolicy Bypass -File ' + AddQuotes(g_AppDirPath + 'pwsh-install.ps1') + ' ' + ExtraParams;
if not ExecAndCaptureOutput('pwsh.exe', Params, '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode, Output) then
Exit;
begin
if IgnoreFailure then
begin
Log('Skipping PowerShell profile update because pwsh.exe could not be executed');
Exit;
end;
RaiseException('Failed to execute pwsh.exe');
Comment on lines +252 to +257

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error cannot occur, because on installation we first check if pwsh.exe is installed and works. RunPwshScript is not called otherwise.

end;

if ResultCode <> 0 then
if ResultCode = 0 then
begin
Detail := '';
if GetArrayLength(Output.StdErr) > 0 then
Detail := Output.StdErr[0]
else if GetArrayLength(Output.StdOut) > 0 then
Detail := Output.StdOut[0];
Result := True;
Exit;
end;

Detail := '';
if GetArrayLength(Output.StdErr) > 0 then
Detail := Output.StdErr[0]
else if GetArrayLength(Output.StdOut) > 0 then
Detail := Output.StdOut[0];

if IgnoreFailure then
begin
if Detail <> '' then
RaiseException('Failed to update PowerShell profiles: ' + Detail)
Log('Failed to update PowerShell profiles: ' + Detail)
else
RaiseException('Failed to update PowerShell profiles');
Log('Failed to update PowerShell profiles');
Exit;
end;

if Detail <> '' then
RaiseException('Failed to update PowerShell profiles: ' + Detail)
else
RaiseException('Failed to update PowerShell profiles');
end;

procedure InstallPowerShellProfiles(Scope: Integer);
procedure InstallPowerShellProfiles(Scope: Integer; IgnoreFailure: Boolean);
var
Params: String;
begin
Expand All @@ -279,7 +299,7 @@ begin
Params := Params + ' -CmdDir ' + AddQuotes(RemoveBackslashUnlessRoot(g_AppCmdDirPath));
end;

RunPwshScript(Params);
RunPwshScript(Params, IgnoreFailure);
end;

// #### Event Handlers ####
Expand Down Expand Up @@ -363,11 +383,10 @@ begin
ModifyPath(WizardIsTaskSelected('addtopath'));

if g_HasUsablePowerShell then
Scope := g_PowerShellPage.SelectedValueIndex
else
Scope := PWSH_SCOPE_NONE;

InstallPowerShellProfiles(Scope);
begin
Scope := g_PowerShellPage.SelectedValueIndex;
InstallPowerShellProfiles(Scope, False);
end;
end;
end;

Expand All @@ -376,7 +395,11 @@ begin
if CurUninstallStep = usUninstall then
begin
InitializeGlobals;
InstallPowerShellProfiles(PWSH_SCOPE_NONE);
DetectPowerShell;
if g_HasUsablePowerShell then
InstallPowerShellProfiles(PWSH_SCOPE_NONE, True)
else
Log('Skipping PowerShell profile cleanup because pwsh.exe is unavailable or unsupported');
ModifyPath(False);
DelTree(g_AppDirPath, True, True, True);
end;
Expand Down