simplify and rename the init function

This commit is contained in:
2023-07-03 15:54:57 -04:00
parent 1f407569f1
commit 1d5e908b77

View File

@ -37,6 +37,22 @@ local function logwrite(string)
end
end
local function openlog()
if opts.logging.log then -- log if asked to
-- get our logfile's full path
fn = mp.command_native({'expand-path', opts.logging.logfile})
f = io.open(fn, 'a') -- open file buffer
io.output(f) -- set it as default
end
end
local function closelog()
if opts.logging.log then
io.close(f)
end
end
-- get the requested git repos
local function clonegit(i)
logwrite('downloading ' .. plugins[i][1])
@ -127,15 +143,8 @@ local function startinstall()
end
end
local function init()
if opts.logging.log then -- log if asked to
-- get our logfile's full path
local fn = mp.command_native({'expand-path', opts.logging.logfile})
os.remove(fn) -- remove logfile so that we start fresh
f = io.open(fn, 'a') -- open file buffer
io.output(f) -- set it as default
end
local function initupdate()
openlog()
logwrite('# of plugins defined in table: ' .. tablelength(plugins))
os.execute('mkdir -p ' .. opts.dl.dir) -- make download dir
@ -146,9 +155,9 @@ local function init()
logwrite('powerwashing the tmp dir (' .. opts.dl.dir .. ')')
os.execute('rm -rf ' .. opts.dl.dir)
end
if opts.logging.log then
io.close(f)
closelog()
end
end
mp.add_key_binding('U', 'UpdatePlugins', init)
mp.add_key_binding('U', 'UpdatePlugins', initupdate)