Skip to content

Commit

Permalink
Improve path handling in complex situations
Browse files Browse the repository at this point in the history
  • Loading branch information
johnstevenson committed Mar 24, 2016
1 parent 8f76718 commit 3d273cc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## v4.3.0
2016-03-24

* Improves path handling for existing user path in admin installs (introduced in v4.2.0) and for adding `Composer\vendor\bin` to the user path.


## v4.2.0
2016-03-24

Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -63,10 +63,10 @@ The installer will modify your system path for Admin installs, or your user path

In addition the installer will add the following to the user environment:

* the `COMPOSER_BIN` directory to your path
* the `C:\Users\<user>\AppData\Roaming\Composer\vendor\bin` directory to your path
* an `http_proxy` value, if specified in the installer

The uninstaller will only remove the path to the installation bin directory and the `COMPOSER_BIN` path, leaving the PHP path and any `http_proxy` value intact.
The uninstaller will only remove the path to the installation bin directory and the `Composer\vendor\bin` path, leaving the PHP path and any `http_proxy` value intact.

<a name="License"></a>
## License
Expand Down
50 changes: 33 additions & 17 deletions src/composer.iss
Expand Up @@ -141,6 +141,7 @@ type
System : String;
User : String;
Cmd : String;
Hive : Integer;
Path : String;
end;
Expand Down Expand Up @@ -1610,13 +1611,21 @@ end;
procedure SetPathDataRec(var Rec: TPathRec; Cmd: String);
begin
{A helper function for UpdatePathStatus}
Rec.Cmd := Cmd;
{A helper function for UpdatePathStatus}
Rec.Cmd := Cmd;
if Cmd = '' then
Rec.Path := ''
else
Rec.Path := ExtractFileDir(Cmd);
if Cmd = '' then
Rec.Path := ''
else
Rec.Path := ExtractFileDir(Cmd);
if Rec.System <> '' then
Rec.Hive := HKLM
else if Rec.User <> '' then
Rec.Hive := HKCU
else
Rec.Hive := 0;
end;
Expand All @@ -1637,7 +1646,7 @@ begin
Paths.Php.Data.System := SearchPath(Paths.List, HKLM, '{#CmdPhp}');
{Only check User if we have no System entry}
{Only check user path if we have no system entry, even if we are an admin}
if Paths.Php.Data.System = '' then
Paths.Php.Data.User := SearchPath(Paths.List, HKCU, '{#CmdPhp}');
Expand All @@ -1650,7 +1659,7 @@ begin
Paths.Bin.Data.System := SearchPathBin(HKLM);
{Only check User if we have no System entry}
{Only check user path if we are a User and have no system entry}
if IsUser and (Paths.Bin.Data.System = '') then
Paths.Bin.Data.User := SearchPathBin(HKCU);
Expand All @@ -1663,12 +1672,16 @@ begin
VendorBin := GetVendorBinDir();
{We only check user path because it gets too messy if the value is
found in the system path. More importantly, UpdatePathStatus will
not work correctly with a system value for this type of usage}
{We check both system and user paths, even though it is unlikely
to find an entry in the system path. We only add this path
if the status is PATH_NONE}
if DirectoryInPath(VendorBin, Paths.List, HKLM) then
Paths.VendorBin.Data.System := VendorBin;
if DirectoryInPath(VendorBin, Paths.List, HKCU) then
Paths.VendorBin.Data.User := VendorBin;
UpdatePathStatus(Paths.VendorBin);
end;
Expand Down Expand Up @@ -1815,20 +1828,20 @@ end;
procedure CheckPathPhp(Rec: TPathStatus; Config: TConfigRec);
var
PhpPath: String;
Hive: Integer;
FixedHive: Integer;
begin
Debug('Checking php path');
PhpPath := ExtractFileDir(Config.PhpExe);
Hive := GetRegHive();
FixedHive := GetRegHive();
if Rec.Status = PATH_NONE then
begin
{Path empty, so add PhpPath}
PathChange(Hive, ENV_ADD, PhpPath, True);
PathChange(FixedHive, ENV_ADD, PhpPath, True);
end
else if Rec.Status = PATH_OK then
Expand All @@ -1838,8 +1851,11 @@ begin
the new one and remove the existing one}
if CompareText(Rec.Data.Path, PhpPath) <> 0 then
begin
PathChange(Hive, ENV_ADD, PhpPath, True);
PathChange(Hive, ENV_REMOVE, Rec.Data.Path, True);
PathChange(FixedHive, ENV_ADD, PhpPath, True);
{We might need to remove an existing user path in an admin
install, so we use the specific hive}
PathChange(Rec.Data.Hive, ENV_REMOVE, Rec.Data.Path, True);
end;
end;
Expand Down
Binary file modified src/userdata/userdata.dll
Binary file not shown.

0 comments on commit 3d273cc

Please sign in to comment.