–
– main.lua
–
local lfs = require( “lfs” )
local launchArgs = …
local launchFile = “none”;
local fileName;
display.newText(“File passed to system.DocumentsDirectory:”, display.contentWidth * .5, 50, native.systemFont, 12);
fileName = display.newText(launchFile, 10, 200, display.contentWidth, display.contentHeight * .5, native.systemFont, 12);
fileName:setFillColor( 1, 0, 0)
fileName.anchorX = 0
fileName.anchorY = 0.5
local function muestradirectorios()
local directorios = “”
– Get raw path to the app documents directory
local doc_path = system.pathForFile( “”, system.DocumentsDirectory )
for file in lfs.dir( doc_path ) do
– “file” is the current file or directory name
print( "Found file: " … file )
directorios = directorios … " - documents - " … file … " – "
end
– Get raw path to the app documents directory
local doc_path = system.pathForFile( “”, system.TemporaryDirectory )
for file in lfs.dir( doc_path ) do
– “file” is the current file or directory name
print( "Found file: " … file )
directorios = directorios … " - temporary - " … file … " – "
end
return directorios
end
local function handleFile(argumentos)
if (argumentos and argumentos.url) then
miFile= argumentos.url
--descarga file
if (string.sub(miFile, 1, 7) == “file://”) then – handle custom extension
–it is a file… need to copy it to temporary.directory…
launchFile = "FILE --> " … miFile
fileName.text = launchFile
else – handle URL Scheme
– do something es URL
launchFile = "URL --> " … miFile
fileName.text = launchFile
local function networkListener( event )
if ( event.isError ) then
print( "Network error - download failed: ", event.response )
launchFile = “ERROR”
fileName.text = launchFile
elseif ( event.phase == “began” ) then
print( “Progress Phase: began” )
launchFile = “BEGAN”
fileName.text = launchFile
elseif ( event.phase == “ended” ) then
--listo directorios
launchFile = "URL: " … argumentos.url … " -END- " … muestradirectorios()
fileName.text = launchFile
else
launchFile = “OTRO RARO QUE NO ESTA CONTEMPLADO”
fileName.text = launchFile
end
end
network.download( miFile, “GET”, networkListener, {timeout=10, progress=true}, “archivodescargado.cnk”, system.TemporaryDirectory )
end
end
end
handleFile(launchArgs)