Skip to content

Commit

Permalink
Improve environment change logging
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstevenson committed Nov 17, 2021
1 parent 56d1d57 commit 9b530e2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 12 deletions.
31 changes: 22 additions & 9 deletions src/composer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ type
Value : String;
Masked : String;
Show : Boolean;
Done : Boolean;
Changed : Boolean;
end;
type
Expand Down Expand Up @@ -2803,27 +2803,40 @@ end;
procedure EnvDebugChanges(List: TEnvChangeList; IsRevoke: Boolean);
var
I: Integer;
Count: Integer;
Action: String;
Changes: String;
begin
Count := Length(List);
if IsRevoke then
Action := 'Revoking'
begin
Action := 'Revoking';
Count := 0;
for I := 0 to Length(List) -1 do
begin
if List[I].Changed then
Inc(Count);
end;
end
else
begin
Action := 'Making';
Count := Length(List);
end;
case Count of
0: Changes := 'no changes required';
0: Changes := 'no changes';
1: Changes := '1 change'
else
Changes := Format('%d changes', [Count]);
end;
Debug(Format('%s changes to the environment: %s required', [Action, Changes]));
Debug(Format('%s changes to the environment: %s registered', [Action, Changes]));
end;
Expand Down Expand Up @@ -2937,7 +2950,7 @@ begin
{Check the result}
if Status = ENV_CHANGED then
begin
List[I].Done := True;
List[I].Changed := True;
GFlags.EnvChanged := True;
end
else if Status = ENV_FAILED then
Expand Down Expand Up @@ -2971,7 +2984,7 @@ begin
GEnvChanges[Next].Value := Value;
GEnvChanges[Next].Masked := EnvGetMasked(Name, Value);
GEnvChanges[Next].Show := Show;
GEnvChanges[Next].Done := False;
GEnvChanges[Next].Changed := False;
Debug('Registering: ' + EnvChangeToString(GEnvChanges[Next], ''));
Expand All @@ -2994,7 +3007,7 @@ begin
begin
{Ignore entries that haven't been processed}
if not List[I].Done then
if not List[I].Changed then
Continue;
{Reverse the action}
Expand Down
36 changes: 33 additions & 3 deletions src/environment.iss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function SearchPath(SafeList: TSafeList; const Cmd: String): String; forward;
function SearchPathEx(SafeList: TSafeList; const Cmd: String; var Index: Integer): String; forward;
procedure DbgEnv(Action, Hive: Integer; Name, Value, Masked: String); forward;
procedure DbgPath(Action, Hive: Integer; Value: String); forward;
procedure DbgPathEx(Action, Hive: Integer; Value: String; Skipped: Boolean); forward;
procedure DbgError(Name: String); forward;
procedure NotifyEnvironmentChange; forward;
Expand Down Expand Up @@ -159,6 +160,7 @@ begin
if DirectoryInPath(SafeDirectory, SafeList) then
begin
Result := ENV_NONE;
DbgPathEx(ENV_ADD, Hive, SafeDirectory, True);
Exit;
end;
Expand Down Expand Up @@ -215,6 +217,7 @@ begin
if not GetRawPath(Hive, CurrentPath) then
begin
Result := ENV_NONE;
DbgPathEx(ENV_REMOVE, Hive, SafeDirectory, True);
Exit;
end;
Expand All @@ -241,7 +244,10 @@ begin
{See if we found the entry we want to remove}
if not FoundEntry then
Result := ENV_NONE
begin
Result := ENV_NONE;
DbgPathEx(ENV_REMOVE, Hive, SafeDirectory, True);
end
else
Result := WriteRegistryPath(Hive, Key, NewPath);
Expand Down Expand Up @@ -583,18 +589,42 @@ end;
procedure DbgPath(Action, Hive: Integer; Value: String);
begin
DbgPathEx(Action, Hive, Value, False);
end;
procedure DbgPathEx(Action, Hive: Integer; Value: String; Skipped: Boolean);
var
Path: String;
Entry: String;
Prefix: String;
Info: String;
begin
Path := Format('%s\%s\%s', [GetHiveName(Hive), GetPathKeyForHive(Hive), ENV_KEY_PATH]);
Entry := Format('%s%s%s', [#39, Value, #39]);
if Action = ENV_ADD then
Prefix := Format('Adding %s%s%s to', [#39, Value, #39])
begin
if not Skipped then
Info := 'Adding'
else
Info := 'Skipped adding';
Prefix := Format('%s %s to', [Info, Entry]);
end
else
Prefix := Format('Removing %s%s%s from', [#39, Value, #39]);
begin
if not Skipped then
Info := 'Removing'
else
Info := 'Skipped removing';
Prefix := Format('%s %s from', [Info, Entry]);
end;
Debug(Format('%s [%s]', [Prefix, Path]));
Expand Down

0 comments on commit 9b530e2

Please sign in to comment.