stream, binary file

About Monkey 2 Forums Monkey 2 Programming Help stream, binary file

This topic contains 12 replies, has 4 voices, and was last updated by  medi 2 years ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #7531

    medi
    Participant

    I need help on this, I want to write this c code in mx2:

    I wrote this which I am extremely doubtful about and is not working:

    The program compiles but seems not working because “data” is not created and is not read.

    After the text file version of it didn’t work either, I used LoadString, which worked. I like both binary and text version works to learn mx2.

    #7534

    abakobo
    Participant

    use FileStream to write to a file (FileStream extends Stream)

    [/crayon]
    #7537

    impixi
    Participant

    Monkey 2’s file streaming capabilities have some “quirks” depending on the target platform. (eg The “rw” mode is not working for me on MacOS). You’re also limited to the file types you can “#Import”.

    You can, however, create, load and save files at runtime. The location of the created files will depend on the target platform and the chosen target directory.

    Here’s an example that creates, saves and loads one text and one binary file to your desktop (tested on MacOS, might encounter file permission issues on other platforms?)

    [/crayon]
    #7538

    medi
    Participant

    To impixi, it works perfect in my Windows 8 machine. Thanks a bunch! I will study your code to correct mine.

    #7539

    medi
    Participant

    I said perfectly? May be not, but not your fault. It gives me strange behavior for different read and write locations. HOWEVER, I am using the binary version of mx2, which is very old. I will compile the latest version tomorrow to test my codes again.

    for write:

    for read:

    Nevertheless, it seems I am progressing.

    #7546

    medi
    Participant

    Yes impixi, for the text file version, I get memoey access error when I use anything other than DesktopDir(). Unlike the above simplified binary examples, using AssetsDir() fails. There is a CurrectDir() as well, same problem. Don’t know what is going on. Do I doubt myself or Monekey2 😉

    No project can begin without io system. Buying and using veterans’ libraries or frameworks, no way. Fundamentals must work and clearly documented first. Double thanks to you impixi

    #7548

    abakobo
    Participant

    using absolute path returned by

    [/crayon]

    I could save where I want on W7 except my sys root dir (C:\ –> no error but no files)

    on OSX I can only save on user dir if on sys drive (memory acces violation if not user dir), everywhere on other drives

    the filter is not working on OSX so

    [/crayon]

    will crash too

    never used assetsdir(), desktopdir(),…

    all this should be reported on github when we have a clearer idea of where it actually crashes/not-working.

    #7549

    medi
    Participant

    Thanks abakobo, I keep in mind.

    #7550

    impixi
    Participant

    I think we need to expose a few additional folders so we can do our file handling in a more “appropriate” manner, ie according to modern expectations.

    Here’s a good link for iOS / MacOS X:

    https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html

    I don’t have time right now, but later I’ll have a crack at exposing the Documents and Library folders via a wrapper or maybe a modification to std.filesystem (if nobody else does it first).

    I haven’t looked into the other target platforms yet, but the principles are the same IIRC. In any case I need the functionality for Mac OS X and Windows 10, so minimally that’s what I need to get working at some point…

    IIRC Brucey had a “bah.volumes” BlitzMax module that exposed appropriate folders/directories on the various platforms – I wonder if any of that c/c++ native code would be useful for us…

    #7551

    impixi
    Participant

    Actually, it would be nice if I could do this on MacOS X to access/read/write to the user’s Documents directory:

    [/crayon]

    But, alas, it’s not that simple. 😉

    #7552

    impixi
    Participant

    Well, that was simpler than I thought. Works on MacOSX, untested on Windows. It pays to poke around monkey2’s source code (I merely copied and modified the DesktopDir function). 😉

    [/crayon]

    EDIT: And it works in place of the DesktopDir() function in my earlier file creation/reading/writing test code. Just remember to import libc..

    #7561

    Mark Sibly
    Keymaster

    Hi,

    AssetsDir() is working OK here (see below) although you can’t depend on it being present on all targets (eg: there is no AssetsDir on android).

    I’m happy to add more of these BlahDir()s though if people let me know what they want.

    #7579

    medi
    Participant

    Thanks for all your help. This was for my Premier League software. Since PL will end soon, I got to finish it very soon. As my learning Monkey2 is slow, I will go back to Java or BlitzMax. I will convert my codes to Monkey2 in summer (for the next season of PL).

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.