Skip to content

Commit

Permalink
Use config.json since setting environment variables is legacy and is …
Browse files Browse the repository at this point in the history
…not recommended any more. https://github.com/ScoopInstaller/Install?tab=readme-ov-file#advanced-installation (#186)

(Introduces inconsistent indentation, which will be fixed in a subsequent commit.)
  • Loading branch information
raisercostin authored May 23, 2024
1 parent 29ee37e commit 898141c
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions scoop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,55 @@ local function get_home_dir()
return os.getenv("home") or os.getenv("USERPROFILE")
end

local function scoop_folder()
local folder = os.getenv("SCOOP")
local function scoop_load_config() -- luacheck: no unused args
local file = io.open(get_home_dir() .. "\\.config\\scoop\\config.json")
-- If there is no such file, then close handle and return
if file == nil then
return w()
end

if not folder then
folder = get_home_dir() .. "\\scoop"
end
-- Read the whole file contents
local contents = file:read("*a")
file:close()

return folder
end
-- strip UTF-8-BOM
local utf8_len = contents:len()
local pat_start, _ = string.find(contents, "{")
contents = contents:sub(pat_start, utf8_len)

local function scoop_global_folder()
local folder = os.getenv("SCOOP_GLOBAL")
local data = JSON:decode(contents)

if not folder then
folder = os.getenv("ProgramData") .. "\\scoop"
end
if data == nil then
return w()
end

return folder
return data
end

local function scoop_load_config() -- luacheck: no unused args
local file = io.open(get_home_dir() .. "\\.config\\scoop\\config.json")
-- If there is no such file, then close handle and return
if file == nil then
return w()
end

-- Read the whole file contents
local contents = file:read("*a")
file:close()

-- strip UTF-8-BOM
local utf8_len = contents:len()
local pat_start, _ = string.find(contents, "{")
contents = contents:sub(pat_start, utf8_len)

local data = JSON:decode(contents)

if data == nil then
return w()
end
local function scoop_folder()
local folder = os.getenv("SCOOP")
if not folder then
local config = scoop_load_config()
if config and config.root_path then
folder = config.root_path
else
folder = get_home_dir() .. "\\scoop"
end
end
return folder
end

return data
local function scoop_global_folder()
local folder = os.getenv("SCOOP_GLOBAL")
if not folder then
local config = scoop_load_config()
if config and config.global_path then
folder = config.global_path
else
folder = os.getenv("ProgramData") .. "\\scoop"
end
end
return folder
end

local function scoop_alias_list(token) -- luacheck: no unused args
Expand Down

0 comments on commit 898141c

Please sign in to comment.