TOOLS/lua/autoload: fix operation outside of working dir

Fixes #1222. (This commit is based on a patch posted there.)
This commit is contained in:
wm4 2014-10-26 14:34:46 +01:00
parent dd91c09a71
commit 078f5f300d
1 changed files with 7 additions and 3 deletions

View File

@ -26,6 +26,9 @@ function find_and_add_entries()
end
local files = mputils.readdir(dir, "files")
table.sort(files)
if dir == "." then
dir = ""
end
local pl = mp.get_property_native("playlist", {})
local pl_current = mp.get_property_number("playlist-pos", 0) + 1
-- Find the current pl entry (dir+"/"+filename) in the sorted dir list
@ -47,20 +50,21 @@ function find_and_add_entries()
if file == nil or file[1] == "." then
break
end
local filepath = dir .. file
if pl_e then
-- If there's a playlist entry, and it's the same file, stop.
if pl_e.filename == file then
if pl_e.filename == filepath then
break
end
end
if direction == -1 then
if pl_current == 1 then -- never add additional entries in the middle
mp.msg.info("Prepending " .. file)
table.insert(append[-1], 1, file)
table.insert(append[-1], 1, filepath)
end
else
mp.msg.info("Adding " .. file)
table.insert(append[1], file)
table.insert(append[1], filepath)
end
end
end