It looks like you're new here. If you want to get involved, click one of these buttons!
const orxSTRING zSaveFile = orxFile_GetApplicationSaveDirectory("OrxTest/Save.ini");
orxLOG("Dir %s", zSaveFile);
orxFILE *file = orxFile_Open(zSaveFile, orxFILE_KU32_FLAG_OPEN_WRITE);
orxFile_Print(file, (orxCHAR*)"5561111"); //print score to file
orxFile_Close(file); //complete write
orxFILE *fileToReadBack = orxFile_Open(zSaveFile, orxFILE_KU32_FLAG_INFO_READONLY);
orxSTRING readBackString = (orxCHAR*)"1234567";
int numRead = orxFile_Read( readBackString, sizeof(orxCHAR), 7, fileToReadBack );
orxLOG("Read amount %d, back as string: %s", numRead, readBackString);
Read amount 0, back as string: 1234567
Comments
I can now read back something using the correct flag of: orxFILE_KU32_FLAG_OPEN_READ but with this fiddling around, I end up either reading memory from somewhere else or crashing.
I found a good example here: https://bitbucket.org/orx/orx/pull-request/15/update-android-display-plugin-and-demo/diff but it makes use of a struct which it can get the sizeof etc. I just want a simple string (I think).
I am trying to use the sizeof(orxCHAR) which is a single size version of orxSTRING, and I have 7 chars to read.
Does anyone have any insight on this?
Your second problem comes from your call to orxFile_Read(). You try to store 7 bytes to a pointer that is not initialized (readBackString). It can point anywhere in memory, and that will definitely lead to a crash.
What you probably want is 8 bytes (1 extra for the null termination) of storage:
Then it should work just fine.
As a side note, I'd encourage you to use the config system for your save needs. What I do is that I store all my data in properties of a section I usually call "Save". Then I save it to disk with:
I then reload my save with a simple call to orxConfig_Load(zSaveFile) and I can then access all the data through the config API.
It has another little bonus as config save/load support encryption (it's basic but good enough for savegames, I think) using a custom key. Just make sure that if you're using a custom key to set it before calling load or save.
And yes, my first preference was to use the orxConfig to push the value back to the config. And this was working for me, however I didn't know how to use the callback as a filter.
So my entire config (which is fractured in many files) was being pushed out to another file in one big blob.
Thanks for the example of the callback, this is exactly what I really needed after all.
For the filter callback, you can filter by whole section or by key.
Everytime a section will gets serialized, a first call will be made with the section name passed as argument and orxNULL as the key argument. That's where you can reject a full section right away by returning orxFALSE.
If you return orxTRUE, it'll then ask you again for every single key within the section (this time it'll pass both the section name and the key name when calling the filter). You can now return orxFALSE to reject a single key, or orxTRUE to accept it.
Of course you can also make a choice based on the encryption parameter (maybe you want to only write if it's encoded or not, I'm not judging