Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill-Stewart committed Jun 10, 2021
1 parent a7fe503 commit 9f45b28
Show file tree
Hide file tree
Showing 14 changed files with 770 additions and 714 deletions.
64 changes: 35 additions & 29 deletions EditPath.iss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
[Setup]
AppId={{A17D2D05-C729-4F2A-9CC7-E04906C5A842}
AppName=EditPath
AppVersion=4.0.2.0
AppVersion=4.0.3.0
UsePreviousAppDir=false
DefaultDirName={autopf}\EditPath
Uninstallable=true
Expand Down Expand Up @@ -64,7 +64,7 @@ const
MODIFY_PATH_TASK_NAME = 'modifypath'; // Specify name of task
var
PathIsModified: boolean; // Cache task selection from previous installs
PathIsModified: Boolean; // Cache task selection from previous installs
// Import AddDirToPath() at setup time ('files:' prefix)
function DLLAddDirToPath(DirName: string; PathType, AddType: DWORD): DWORD;
Expand All @@ -76,75 +76,81 @@ function DLLRemoveDirFromPath(DirName: string; PathType: DWORD): DWORD;
// Wrapper for AddDirToPath() DLL function
function AddDirToPath(const DirName: string): DWORD;
var
PathType, AddType: DWORD;
begin
var
PathType, AddType: DWORD;
begin
// PathType = 0 - use system Path
// PathType = 1 - use user Path
// AddType = 0 - add to end of Path
// AddType = 1 - add to beginning of Path
if IsAdminInstallMode() then PathType := 0 else PathType := 1;
if IsAdminInstallMode() then
PathType := 0
else
PathType := 1;
AddType := 0;
result := DLLAddDirToPath(DirName, PathType, AddType);
end;
end;
// Wrapper for RemoveDirFromPath() DLL function
function RemoveDirFromPath(const DirName: string): DWORD;
var
PathType: DWORD;
begin
var
PathType: DWORD;
begin
// PathType = 0 - use system Path
// PathType = 1 - use user Path
if IsAdminInstallMode() then PathType := 0 else PathType := 1;
if IsAdminInstallMode() then
PathType := 0
else
PathType := 1;
result := DLLRemoveDirFromPath(DirName, PathType);
end;
end;
procedure RegisterPreviousData(PreviousDataKey: integer);
begin
procedure RegisterPreviousData(PreviousDataKey: Integer);
begin
// Store previous or current task selection as custom user setting
if PathIsModified or WizardIsTaskSelected(MODIFY_PATH_TASK_NAME) then
SetPreviousData(PreviousDataKey, MODIFY_PATH_TASK_NAME, 'true');
end;
end;
function InitializeSetup(): boolean;
begin
function InitializeSetup(): Boolean;
begin
result := true;
// Was task selected during a previous install?
PathIsModified := GetPreviousData(MODIFY_PATH_TASK_NAME, '') = 'true';
end;
end;
function InitializeUninstall(): boolean;
begin
function InitializeUninstall(): Boolean;
begin
result := true;
// Was task selected during a previous install?
PathIsModified := GetPreviousData(MODIFY_PATH_TASK_NAME, '') = 'true';
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
begin
if CurStep = ssPostInstall then
begin
begin
// Add app directory to Path at post-install step if task selected
if PathIsModified or WizardIsTaskSelected(MODIFY_PATH_TASK_NAME) then
AddDirToPath(ExpandConstant('{app}'));
end;
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
begin
if CurUninstallStep = usUninstall then
begin
begin
// Remove app directory from path during uninstall if task was selected;
// use variable because we can't use WizardIsTaskSelected() at uninstall
if PathIsModified then
RemoveDirFromPath(ExpandConstant('{app}'));
end;
end;
end;
procedure DeinitializeUninstall();
begin
begin
// Unload and delete PathMgr.dll and remove app dir when uninstalling
UnloadDLL(ExpandConstant('{app}\PathMgr.dll'));
DeleteFile(ExpandConstant('{app}\PathMgr.dll'));
RemoveDir(ExpandConstant('{app}'));
end;
end;
22 changes: 11 additions & 11 deletions EditPath.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ https://github.com/Bill-Stewart/PathMgr/releases/

The system Path is found in the following location in the Windows registry:

Root: `HKEY_LOCAL_MACHINE`
Subkey: `SYSTEM\CurrentControlSet\Control\Session Manager\Environment`
Root: `HKEY_LOCAL_MACHINE`
Subkey: `SYSTEM\CurrentControlSet\Control\Session Manager\Environment`
Value name: `Path`

The current user Path is found in the following location in the registry:

Root: `HKEY_CURRENT_USER`
Subkey: `Environment`
Root: `HKEY_CURRENT_USER`
Subkey: `Environment`
Value name: `Path`

In both cases, the `Path` value is (or should be) the registry type `REG_EXPAND_SZ`, which means that it is a string that can contain values surrounded by `%` characters that Windows will automatically expand to environment variable values. (For example, `%SystemRoot%` will be expanded to `C:\Windows` on most systems.)

The `Path` value contains a `;`-delimited list of directory names that the system should search for executables, library files, scripts, etc. Windows appends the content of the current user Path to the system Path and expands the environment variable references. The resulting string is set as the `Path` environment variable for processes.

EditPath provides an command-line interfacec for managing the `Path` value in the system location (in `HKEY_LOCAL_MACHINE`) and the current user location (in `HKEY_CURRENT_USER`).
EditPath provides a command-line interface for managing the `Path` value in the system location (in `HKEY_LOCAL_MACHINE`) and the current user location (in `HKEY_CURRENT_USER`).

# Usage

The following describes the command-line usage for the program:
The following describes the command-line usage for the program. Parameters are case-sensitive.

**EditPath** [_options_] _type_ _action_

Expand All @@ -51,10 +51,10 @@ You must specify only one of the following _action_ parameters:

| _action_ | Abbreviation | Description
| -------- | ------------ | -----------
| **--list** | **-l "**_dirname_**"** | Lists directories in Path
| **--list** | **-l** | Lists directories in Path
| **--test "**_dirname_**"** | **-t "**_dirname_**"** | Tests if directory exists in Path
| **--add "**_dirname_**"** | **-a "**_dirname_**"** | Adds directory to Path
| **--remove "**_dirname_**"** | **-r "**_dirname_**"** | Remove directory from Path
| **--remove "**_dirname_**"** | **-r "**_dirname_**"** | Removes directory from Path

The following parameters are optional:

Expand Down Expand Up @@ -101,11 +101,11 @@ The following table lists typical exit codes when using **--test** (**-t**).

# Examples

1. `EditPath --expand --system --list`
1. `EditPath --expand --system --list`

This command outputs the directories in the system Path, with environment variables expanded. You can also write this command as `EditPath -e -s -l`.
This command outputs the directories in the system Path, with environment variables expanded. You can also write this command as `EditPath -x -s -l`.

2. `EditPath --user --add "%LOCALAPPDATA%\Programs\MyApp"`
2. `EditPath --user --add "%LOCALAPPDATA%\Programs\MyApp"`

Adds the specified directory name to the user Path.

Expand Down
Loading

0 comments on commit 9f45b28

Please # to comment.