[vlc-commits] VLSub: Use vlc.io instead of lua's io module
Hugo Beauzée-Luyssen
git at videolan.org
Mon Apr 9 17:02:01 CEST 2018
vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Fri Apr 6 17:11:53 2018 +0200| [23a7f3cab7aa900773a2d9319c033253ae0254e0] | committer: Hugo Beauzée-Luyssen
VLSub: Use vlc.io instead of lua's io module
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=23a7f3cab7aa900773a2d9319c033253ae0254e0
---
share/lua/extensions/VLSub.lua | 25 +++++++++----------------
1 file changed, 9 insertions(+), 16 deletions(-)
diff --git a/share/lua/extensions/VLSub.lua b/share/lua/extensions/VLSub.lua
index c7516d71a4..f26d303032 100644
--- a/share/lua/extensions/VLSub.lua
+++ b/share/lua/extensions/VLSub.lua
@@ -762,11 +762,10 @@ end
function load_config()
-- Overwrite default conf with loaded conf
- local tmpFile = io.open(vlc.strings.to_codepage(openSub.conf.filePath), "rb")
+ local tmpFile = vlc.io.open(openSub.conf.filePath, "rb")
if not tmpFile then return false end
local resp = tmpFile:read("*all")
tmpFile:flush()
- tmpFile:close()
local option = parse_xml(resp)
for key, value in pairs(option) do
@@ -794,10 +793,9 @@ end
function load_transl(path)
-- Overwrite default conf with loaded conf
- local tmpFile = assert(io.open(vlc.strings.to_codepage(path), "rb"))
+ local tmpFile = assert(vlc.io.open(path, "rb"))
local resp = tmpFile:read("*all")
tmpFile:flush()
- tmpFile:close()
openSub.option.translation = nil
openSub.option.translation = parse_xml(resp)
@@ -894,11 +892,10 @@ function save_config()
if file_touch(openSub.conf.filePath) then
local tmpFile = assert(
- io.open(vlc.strings.to_codepage(openSub.conf.filePath), "wb"))
+ vlc.io.open(openSub.conf.filePath, "wb"))
local resp = dump_xml(openSub.option)
tmpFile:write(resp)
tmpFile:flush()
- tmpFile:close()
tmpFile = nil
else
return false
@@ -1395,7 +1392,7 @@ openSub = {
file = nil
else
vlc.msg.dbg("[VLSub] Read hash data from file")
- local file = io.open(vlc.strings.to_codepage(openSub.file.path), "rb")
+ local file = vlc.io.open(openSub.file.path, "rb")
if not file then
vlc.msg.dbg("[VLSub] No stream")
return false
@@ -1623,7 +1620,7 @@ function download_subtitles()
local stream = vlc.stream(subtitleMrl)
local data = ""
- local subfile = io.open(vlc.strings.to_codepage(target), "wb")
+ local subfile = vlc.io.open(target, "wb")
while data do
subfile:write(data)
@@ -1664,11 +1661,10 @@ function dump_zip(url, dir, subfileName)
if not file_touch(tmpFileName) then
return false
end
- local tmpFile = assert(io.open(vlc.strings.to_codepage(tmpFileName), "wb"))
+ local tmpFile = assert(vlc.io.open(tmpFileName, "wb"))
tmpFile:write(resp)
tmpFile:flush()
- tmpFile:close()
tmpFile = nil
collectgarbage()
@@ -2021,9 +2017,8 @@ function file_touch(name) -- test write ability
if not name or trim(name) == ""
then return false end
- local f=io.open(vlc.strings.to_codepage(name) ,"w")
+ local f=vlc.io.open(name, "w")
if f~=nil then
- io.close(f)
return true
else
return false
@@ -2033,9 +2028,8 @@ end
function file_exist(name) -- test readability
if not name or trim(name) == ""
then return false end
- local f=io.open(vlc.strings.to_codepage(name), "r")
+ local f=vlc.io.open(name, "r")
if f~=nil then
- io.close(f)
return true
else
return false
@@ -2047,11 +2041,10 @@ function is_dir(path)
then return false end
-- Remove slash at the end or it won't work on Windows
path = string.gsub(path, "^(.-)[\\/]?$", "%1")
- local f, _, code = io.open(vlc.strings.to_codepage(path), "rb")
+ local f, _, code = vlc.io.open(path, "rb")
if f then
_, _, code = f:read("*a")
- f:close()
if code == 21 then
return true
end
More information about the vlc-commits
mailing list