[vlc-commits] VLSub: Use vlc.io instead of lua's io module

2018-04-12 Thread Hugo Beauzée-Luyssen
vlc/vlc-3.0 | branch: master | Hugo Beauzée-Luyssen  | Wed Apr 
 4 16:05:04 2018 +0200| [681a2f60e21ca5617ed03d543a57a938ce16c5fe] | committer: 
Hugo Beauzée-Luyssen

VLSub: Use vlc.io instead of lua's io module

Otherwise any IO operation on path with contain any non-ascii character
will fail on windows.

(cherry picked from commit 23a7f3cab7aa900773a2d9319c033253ae0254e0)
(cherry picked from commit e15d9d230fbee067ba480a314c9dd8a632422bc9)
Signed-off-by: Hugo Beauzée-Luyssen 

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=681a2f60e21ca5617ed03d543a57a938ce16c5fe
---

 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 8f15b90f26..49a9c60f92 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(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(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(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
@@ -1388,7 +1385,7 @@ openSub = {
   file = nil
 else
   vlc.msg.dbg("[VLSub] Read hash data from file")
-  local file = io.open( 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
@@ -1616,7 +1613,7 @@ function download_subtitles()
 
   local stream = vlc.stream(subtitleMrl)
   local data = ""
-  local subfile = io.open(target, "wb")
+  local subfile = vlc.io.open(target, "wb")
 
   while data do
 subfile:write(data)
@@ -1657,11 +1654,10 @@ function dump_zip(url, dir, subfileName)
   if not file_touch(tmpFileName) then
 return false
   end
-  local tmpFile = assert(io.open(tmpFileName, "wb"))
+  local tmpFile = assert(vlc.io.open(tmpFileName, "wb"))
 
   tmpFile:write(resp)
   tmpFile:flush()
-  tmpFile:close()
   tmpFile = nil
   collectgarbage()
 
@@ -2014,9 +2010,8 @@ function file_touch(name) -- test write ability
   if not name or trim(name) == ""
   then return false end
 
-  local f=io.open(name ,"w")
+  local f=vlc.io.open(name, "w")
   if f~=nil then
-io.close(f)
 return true
   else
 return false
@@ -2026,9 +2021,8 @@ end
 function file_exist(name) -- test readability
   if not name or trim(name) == ""
   then return false end
-  local f=io.open(name ,"r")
+  local f=vlc.io.open(name, "r")
   if f~=nil then
-io.close(f)
 return true
   else
 return false
@@ -2040,11 +2034,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(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

___
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits


[vlc-commits] VLSub: Use vlc.io instead of lua's io module

2018-04-09 Thread Hugo Beauzée-Luyssen
vlc | branch: master | Hugo Beauzée-Luyssen  | 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

___
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits