Skip to content
Open
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
36 changes: 36 additions & 0 deletions editenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
////////////////////////////////////////////////////////////////////////////////

#include <limits>
#define NOMINMAX
#include <windows.h>
#undef NOMINMAX

#include "editenv.hpp"

Expand Down Expand Up @@ -100,6 +103,39 @@ void pathAdd (env_scope scope, char const *path)
}
}

void pathAddImmediate (env_scope scope, char const *path)
{
size_t const sizeMax = std::numeric_limits<size_t>::max();

size_t length = std::string(path).length();
size_t pos;

char currPath[8096] = {0};
GetEnvironmentVariableA("PATH", currPath, 8096);

std::string value = currPath;
pos = value.find(path, 0);
while (sizeMax != pos) {
if (((0 == pos) ||
(';' == value[pos - 1])) &&
((pos + length == value.length()) ||
(';' == value[pos + length]))) {
// Found the path in the "Path" environment variable already.
return;
}
pos = value.find(path, pos + 1);
}

if (0 != value.length()) {
// Nothing is in the Path environment variable yet.
value.append(";");
}
value.append(path);

// add to local process
SetEnvironmentVariableA("PATH", value.c_str());
}

// Removes all matching instances of the specified path from the Path
// environment variable.
unsigned int pathRemove (env_scope scope, char const *path)
Expand Down
4 changes: 4 additions & 0 deletions editenv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ EDITENV_API char const * envValue (editenv::env_scope scope, char const *name);
// Return Value: Nothing.
EDITENV_API void pathAdd (editenv::env_scope, char const *path);

// Almost the same as pathAdd, but only adds to the local path variable for
// the calling process.
EDITENV_API void pathAddImmediate (editenv::env_scope, char const *path);

// Removes all matching instances of the specified path from the Path
// environment variable.
//
Expand Down
8 changes: 4 additions & 4 deletions editenv.rc
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,9,1,0
PRODUCTVERSION 0,9,1,0
FILEVERSION 0,9,2,0
PRODUCTVERSION 0,9,2,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -70,12 +70,12 @@ BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "Environment Variable Editor DLL"
VALUE "FileVersion", "0, 9, 1, 0"
VALUE "FileVersion", "0, 9, 2, 0"
VALUE "InternalName", "editenv"
VALUE "LegalCopyright", "Copyright (C) 2009"
VALUE "OriginalFilename", "editenv.dll"
VALUE "ProductName", "editenv"
VALUE "ProductVersion", "0, 9, 1, 0"
VALUE "ProductVersion", "0, 9, 2, 0"
END
END
BLOCK "VarFileInfo"
Expand Down