1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#!/usr/bin/env escript
%% SPDX-License-Identifier: Apache-2.0
%% SPDX-FileCopyrightText: 2021 The Elixir Team
%%! -noinput
%% This file is used by the Elixir installer and uninstaller.
main(["add", ";" ++ PathsToAdd]) ->
{ok, Reg} = win32reg:open([read, write]),
ok = win32reg:change_key(Reg, "\\hkey_current_user\\environment"),
{ok, SystemPath} = win32reg:value(Reg, "path"),
NewSystemPath =
lists:foldl(
fun(Elem, Acc) ->
Elem ++ ";" ++
binary_to_list(
iolist_to_binary(
string:replace(Acc, Elem ++ ";", "", all)))
end,
SystemPath,
string:split(PathsToAdd, ";", all)
),
ok = win32reg:set_value(Reg, "Path", NewSystemPath),
ok;
main(["remove", ";" ++ PathsToRemove]) ->
{ok, Reg} = win32reg:open([read, write]),
ok = win32reg:change_key(Reg, "\\hkey_current_user\\environment"),
{ok, SystemPath} = win32reg:value(Reg, "path"),
NewSystemPath =
lists:foldl(
fun(Elem, Acc) ->
binary_to_list(
iolist_to_binary(
string:replace(Acc, Elem ++ ";", "", all)))
end,
SystemPath,
string:split(PathsToRemove, ";", all)
),
ok = win32reg:set_value(Reg, "Path", NewSystemPath),
ok.
|