About Monkey 2 › Forums › Monkey 2 Development › File access API?
Tagged: File API extension
This topic contains 6 replies, has 4 voices, and was last updated by
Diffrenzy
1 year, 5 months ago.
-
AuthorPosts
-
November 17, 2017 at 1:11 am #11758
Anyone made a file access Monkey2 extension for iOS and Android? I for one need to save me some time so would happily pay good money for one here and now.
November 17, 2017 at 6:54 am #11763Do you mean to make Files and Directories on Mobile? Or stuff like CHMOD? Or attrib +s +a?
I haven’t tested LoadString("..") on a mobile device myself yet but it should work just fine.
If for some reason not, maybe look into Local MyDataBuff := DataBuffer.Load("file path") then use MyDataBuff.PokeString and MyDataBuff.PeekStringto write/read the data to the Buffer. And called MyDataBuff.Save("file path")
iOS and Android file paths should follow the POSIX’y file system hierarchy so “/tmp” or “/bin” is the in root directory.
For Windows the root directory is “C:/”For file attributes/permissions you’d need to impliment chmod() or _chmod in the libc.monkey2 module.
November 17, 2017 at 9:48 am #11771LoadString based on DataBuffer.Load
Look at std.filesystem functions. There is an InternalDir() for example. Maybe it’s what you need.
Monkey1234567891011Function LoadStringMobile:String( path:String )Return LoadString( InternalDir()+path )EndFunction SaveStringMobile( text:String,path:String )SaveString( text,InternalDir()+path )End' usage:SaveStringMobile( "hello","text-data.txt" ).....Local str:=LoadStringMobile( "text-data.txt" )Print strI can’t insert link to docs page because docs is dynamically showing by JavaScript, therefore I insert link to source code:
November 17, 2017 at 5:46 pm #11779That looks amazingly promising ! Thanks yes exactly I mean creating files and reading them back for instance.
I don’t have my Android with me to try things so I have to guess a bit, could anyone give an example how
to save a png onto the external memory card or something similar?November 18, 2017 at 12:15 am #11784Didn’t know it was based on DataBuffer. xD Interesting.
Go Monkey!On Android I think an SD card is under a mounted device file. Since it’s based on the Linux Kernel it should be something
like “/mnt/sdcard” mounted from “/dev/sdb” or “dev/sda”
Saving PNG’s is simple using Pixmap.SetPixel and Pixmap.SaveEdit: Or if you already have a loaded image, you can just use CopyFile
November 18, 2017 at 5:23 am #11794Topic about image saving: http://monkeycoder.co.nz/forums/topic/how-to-save-a-image/
There is also ExternalDir() function along with InternalDir.
I’m not sure is it sdcard dir or not.
But if it’s so, you can use something like this:
Monkey12345Function SaveImageMobile( img:Image,path:String )Local path:=ExternalDir()+path(New Canvas(img)).CopyPixmap(New Recti(0,0,img.Width,img.Height)).Save(path)EndNovember 19, 2017 at 2:36 pm #11823I’ve noticed that http://monkeycoder.co.nz/forums/topic/a-simple-applet-framework/ uses SDL_GetPrefPath to find a place for settings.
I think Mark put it in the develop version of MX2
I’m planing to use that for my savegames, and precomputations, across platforms.
-
AuthorPosts
You must be logged in to reply to this topic.