Access files in Torch iOS - ios

I have an image file and I want to access it in my Lua file. I already put the file in the project folder. However the call
local path = system.pathForFile("xxx", system.DocumentsDirectory) fails to work.
How should I do it?

Related

How do I open a file from disk, in a Flutter app?

In a Flutter app I have a dart file located at FlutterTest\sandbox\lib\my_widget\my_widget.dart.
And I have an image located at FlutterTest\sandbox\lib\my_widget\imgs\myImage.png.
From my_widget.dart how can I point a file to this image, something along the lines of new File("???\my_widget\myImage.png")?
Just to clarify, in Java I could do something like MyClass.class.getResource("myImage.png").toString().
By the way if I print(Directory.current.path) it gives me simply /. And if I try to list the contents of this directory it tells me: "Directory listing failed, path = '/' (OS Error: Permission denied, errno = 13)". So I don't actually know where the current directory is.
You can directly access the file system but due to differences in android and iOS you'll probably end up using the path provider plugin. Also, see this flutter cookbook as they call it.
But if all you're trying to do is access a file from your build, you'll want to define it as an asset in your pubspec, and then access it using Flutter's AssetBundle (or Image.asset) rather than directly using File or Image.file. See the flutter documentation on assets.

How to loading outside .love save file? (love2d+ LUA)

I write editor and game and it requires a save game option.
I Just want use a Save folder in game folder. not inside.love
How to get a bug.
Start game
Enter menu by Escape key
Press save game - this create savegame
Press Load game - you get an error "File not exist" but you write this file seconds ago.
I successful save a game in savesm2k folder but it folder outside .love file and i don't know how correct load saved game.
Used engine: Love2d 0.10.2
OS: Linux Mint 18.1 x64bit
I read many manuals and I'm stuck.
For loading save game i use this commands
lsg=love.filesystem.getSaveDirectory().."/M2k-Saves/m2ksave"
lsg=love.filesystem.getSourceBaseDirectory().."/M2k-Saves/m2ksave";
data, size = love.filesystem.read (lsg);
leveldatacopy=freadbin (data);
Why does the program not try read existing file? and report no exist? I try using another command but using GetSaveDirectory broke function WriteMAP (requires for binary map and data writing) etc. but it write files which cannot be loaded in load section.
Maybe I should use LUA for reading files direct from folder but I don't know how to correct DO it.
example with bug.
https://github.com/dj--alex/m2ktest
file m2ktest-load-savegame-test.love
At this moment on every saving i manually replace saved game inside love archive (!) . This is not normal.
Anybody can tell me how i get and correct open saved file? Not from inside .love file . from outside of course. If levels and configs can be readed from love file inside save files must be outside. I can only can create files outside love file . i know love file is a zip archive.
If required i can post a .love file but is game completely done and have 150kb of clean code.
You should not prefix paths with love.filesystem.getSaveDirectory() or love.filesystem.getSourceBaseDirectory(). This is done automatically, internally to the love.filesystem functions. Saying
lsg = "/M2k-Saves/m2ksave"
data, size = love.filesystem.read (lsg)
leveldatacopy = freadbin (data)
should work, and will place the file in the save directory / outside of the .love file or game directory. (Love forbids writing anywhere except in the save directory.)
Love's filesystem model is like a "stack" of filesystems. For file reading, it first looks in love.filesystem.getSaveDirectory() with whatever path you pass in. If it finds a file, it uses that; otherwise it looks inside the love.filesystem.getSourceBaseDirectory() (or – if packed – inside the .zip / .love file). Writing files always goes to love.filesystem.getSaveDirectory(), you cannot write to love.filesystem.getSourceBaseDirectory() (because it may not be an actual directory but a zip file).

Firefox Addon SDK - How to get a list of files in a directory, and get a file

I am using the SDK to build a Firefox addon. In the addon options, the user can specify a directory of images for my addon to use (these will be added to a webpage).
I cannot figure out how to obtain a list of the files in the directory the user specified (Note that I know how to get this directory using simple-prefs). I also need to know how to get a specific file.
The file I get will be sent to a contentScriptFile to add to a webpage (as a background-image) using pageMod, via worker.port.emit(...).
So my question: How do I obtain a list of files in a directory, and how to get one of those files to send to a contentScriptFile?
I have found out how to do it, using the Low-Level API io/file
After you require() it using var fileIO = require("sdk/io/file"); you can do the following:
List files and directories in a directory using fileIO.list(path), where path is the path to the directory
Read a file using fileIO.read(path), this returns a string with the contents of the file

How to load json file from arbitrary folder inside project?

How to load json file from arbitrary folder inside project ?
I have data folder and inside file user_data.json, but system.DocumentsDirectory points to another ( I have copied from net, I am pretty new to lua and corona)
function custom_load( strFilename )
local path = system.pathForFile( strFilename, system.DocumentsDirectory )
local file = io.open( path, "r" )
if file then
local content = file:read( "*a" )
io.close( file )
return contents
else
return ''
end
end
Your file has to exist before you can read it. Perhaps a brief description of the Corona SDK folder structure will help you understand what's going on.
All apps, regardless of iOS, Android or Corona while running in the simulator are made of up an "Application Bundle". In iOS terms, this is the .app file that Corona SDK produces. In Android, it's the .apk file. The files in the folder with your main.lua and any folders you create there are part of this app bundle. For security purposes, this folder is "Read Only" to your app. Corona SDK allows you to reference files in this folder as system.ResourceDirectory.
Once the app is created and running on the device, Three other folders are created in your App's Sandbox. This is an area that only your app can access. These are:
system.DocumentsDirectory, a readable and writable folder to store things you want to keep around with your app. This is where you would save settings files, files that your users create with your app and so on.
system.TemporaryDirectory, a readable and writeable folder to store things you don't expect to be there. It's where you can download files to that you intend to throw away.
Apple's iOS has a 3rd folder that Corona calls system.CachesDirectory which like system.TemporaryDirectory has not guarantees on now long files that are stored there will last, but the intent from Apple is if you can download it from the net and it gets deleted, you can always download it again. On Android, system.CachesDirectory and system.TemporaryDirectory are the same folders.
Since the assumption is the app is the only thing that can write to it's sandbox, files in system.DocumentsDirectory have to be created by the app. You can't just put a file there (okay there are ways in particular on the simulator, it's just a folder on your Mac or PC if you know where to look, but that's not realistic of a user loading your app) so your app has to create the file in system.DocumentsDirectory.
If the file has not been created, then trying to use io.open() in "read" mode ( the "r" ) to open a file will return nil because the file does not exist.
Dont worry its very simply , just refer this code you will automatically code after reading this.
https://github.com/robmiracle/Simple-Table-Load-Save-Functions-for-Corona-SDK/blob/master/main.lua
In pathForFile use
local path = system.pathForFile( "data/user_data.json", system.ResourceDirectory)

Compare local file to downloaded file

I am using below code to download file from below URI.
File needs to be only downloaded only if it does not exist in Local Machine.
Below code should run only if Application is trying to find the file. It finds on local machine but there is also a updaed version on Server. HOw i can check if file on local machine and server are same.
Or File present on server has been updated. So that below code should download file in two conditions
if File does not exist on local machine
if file on Server has been updated , in this case file also exist on local machine but we need to download newer verion of file and replace order one.
System.Net.WebClient webClient = new System.Net.WebClient();
try
{
webClient.DownloadFile("https://message.com/hello.csv", fieldsFilePath);
}
1 is just file exist
2 You would have to check the header and see if there is size information in there, try the WebRequest class. Then compare that to the size of the local file.

Resources